Work on wiaas orders

This commit is contained in:
Almira Krdzic
2018-08-08 12:21:26 +02:00
parent c1834f679a
commit b8653ad18b
25 changed files with 644 additions and 81 deletions

View File

@@ -0,0 +1,25 @@
<?php
/**
* Class Wiaas_Customer
*
* Handler integration of Wiaas customer with Woocommerce customer
*/
class Wiaas_Customer {
public static function init() {
add_action('woocommerce_new_customer', array(__CLASS__, 'append_customer_info'));
}
/**
* Appends Wiaas customer info (name, phone)
*
* For now we will generate these, but later will be added to the interface
*/
public static function append_customer_info($customer_id) {
update_user_meta($customer_id, 'wiaas_customer_name', 'Wiaas Customer');
update_user_meta($customer_id, 'wiaas_customer_phone', '+46 (10) 5595148');
}
}
Wiaas_Customer::init();

View File

@@ -7,7 +7,8 @@ class Wiaas_DB_Update {
private static $db_updates = array(
'20180728222206' => 'wiaas_db_update_enable_product_by_user_role',
'20180801222206' => 'wiaas_db_update_setup_gravity',
'20180802222206' => 'wiaas_db_update_add_delivery_process_forms'
'20180802222206' => 'wiaas_db_update_add_delivery_process_forms',
'20180808222206' => 'wiaas_db_update_setup_customer_capabilities'
);
public static function execute() {

View File

@@ -8,8 +8,50 @@
class Wiaas_Order {
private static $object_order_type = 'shop_order';
private static $wiaas_order_status = array(
);
public static function init() {
add_filter('woocommerce_rest_prepare_shop_order_object', array(__CLASS__, 'transform_rest_order'), 10, 3);
add_action('woocommerce_new_order', array( __CLASS__, 'assign_order_to_organization' ));
add_filter('woocommerce_rest_check_permissions', array( __CLASS__, 'check_order_access'), 10, 4);
}
/**
* Checks if current user has access to requested order/{orderId} via woocommerce REST API.
* Endpoint `/orders` is filtered correctly by groups, but endpoint `/orders/{orderId}` will return order even if
* user does not have access to it.
* Groups has general support for this using rest_prepare_{$post_type} but woocommerce api does not
* use this filter anymore. So we will just call the same function just with woocommerce filter.
*
* @param $permission
* @param $context
* @param $object_id
* @param $post_type
* @return bool
*/
public static function check_order_access($permission, $context, $object_id, $post_type) {
if ($post_type === 'shop_order' && $object_id !== 0) {
return Groups_Post_Access::user_can_read_post($object_id);
}
#return Groups_Post_Access::user_can_read_post($object_id);
return $permission;
}
/**
* Assignees order to corresponding user organization when order is created.
*
* @param $order_id
*/
public static function assign_order_to_organization($order_id) {
$user = wp_get_current_user();
Wiaas_User_Organization::assign_post_to_user_organization($order_id, $user->ID);
}
/**
@@ -24,14 +66,81 @@ class Wiaas_Order {
public static function transform_rest_order($response, $order, $request) {
$data = $response->get_data();
$is_customer = wcj_is_user_role('customer');
if ($is_customer || true) {
// Format date values.
$data['date_created'] = self::_format_order_date($order->get_date_created());
$data['date_modified'] = self::_format_order_date($order->get_date_modified());
$data['date_completed'] = self::_format_order_date($order->get_date_completed());
}
# apply overrides
$data = self::_append_products_info($data, $order, $request);
$data = self::_append_order_process($data, $order, $request);
$data = self::_append_customer_info($data, $order, $request);
$data = self::_append_commercial_lead_info($data, $order, $request);
$response->set_data($data);
return $response;
}
private static function _append_commercial_lead_info($data, $order, $request) {
$data['commercial_lead'] = array(
'name' => 'Coor Service Management',
'phone' => '123456789',
'email' => 'rikard@co-ideation.com'
);
return $data;
}
private static function _append_customer_info($data, $order, $request) {
$customer_id = $data['customer_id'];
$customer_user = get_user_by('id', $customer_id);
$data['customer'] = array(
'email' => $customer_user->user_email,
'name' => $customer_user->display_name,
'phone' => get_user_meta($customer_id, 'wiaas_customer_phone', true)
);
return $data;
}
private static function _append_products_info($data, $order, $request) {
foreach ($data['line_items'] as $index => $product_line) {
# lock all products to `Purchase` payment type
$product_line['payment_type'] = 'Purchase';
# lock all products to have no service
$product_line['service_price'] = 0;
$product_line['service_contract_period'] = 0;
$product_line['max_contract_period'] = 36;
$product_line['period_unit'] = 'month';
# simplify payment for all products
$product_line['recurring_price'] = 0;
$product_line['pay_period'] = 0;
# collect status from order
$product_line['status'] = $data['status'];
$product_line['short_desc'] = $product_line['status'];
# collect completion data from order
$product_line['date_completed'] = $data['date_completed'];
$data['line_items'][$index] = $product_line;
}
return $data;
}
/**
* Append order delivery process info if single order is requested
* @param $data
@@ -49,6 +158,12 @@ class Wiaas_Order {
return $data;
}
private static function _format_order_date($date) {
$date = new WC_DateTime( $date, new DateTimeZone( 'UTC' ) );
$date->setTimezone( new DateTimeZone( wc_timezone_string() ) );
return gmdate('jS F, Y', $date->getTimestamp());
}
}
Wiaas_Order::init();

View File

@@ -0,0 +1,19 @@
<?php
add_action('init', 'wiaas_load_user_organization');
function wiaas_load_user_organization() {
if (class_exists('WP_User_Taxonomy')) {
require_once dirname( __FILE__ ) . '/user/class-wiaas-user-organization.php';
new Wiaas_User_Organization();
}
}
add_action('plugins_loaded', 'remove_default_user_groups', 30);
function remove_default_user_groups() {
remove_action( 'init', 'wp_register_default_user_group_taxonomy' );
remove_action( 'init', 'wp_register_default_user_type_taxonomy' );
}

View File

@@ -76,4 +76,12 @@ function wiaas_db_update_add_delivery_process_forms() {
}
do_action('gform_forms_post_import', $created_forms);
}
function wiaas_db_update_setup_customer_capabilities() {
$customer_role = get_role('customer');
$customer_role->add_cap('read_private_shop_orders');
$customer_role->add_cap('read_shop_order');
}

View File

@@ -0,0 +1,254 @@
<?php
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
class Wiaas_User_Organization extends WP_User_Taxonomy {
const TAXONOMY_NAME = 'wiaas-user-organization';
const TAXONOMY_SLUG = 'users/wiaas-organization';
public function __construct()
{
$args = array(
'singular' => __('Organization', 'wp-user-groups'),
'plural' => __('Organizations', 'wp-user-groups'),
'exclusive' => true,
'public' => true,
'show_in_rest' => true,
'rest_base' => 'organization'
);
$labels = array();
$caps = array();
parent::__construct(self::TAXONOMY_NAME, self::TAXONOMY_SLUG, $args, $labels, $caps);
$this->hooks();
}
/**
* Add organization specific hooks
*/
function hooks() {
parent::hooks();
add_action('user_new_form', array( $this, 'show_organizations_selection' ));
add_action('user_register', array( $this, 'save_terms_for_user' ));
add_action( 'created_' . self::TAXONOMY_NAME, array( __CLASS__, 'on_organization_added' ));
add_action( 'pre_delete_term', array( __CLASS__, 'on_taxonomy_term_will_be_deleted' ), 10, 2);
add_action('set_object_terms', array( __CLASS__, 'on_taxonomy_term_assigned' ), 10, 4);
add_action('deleted_term_relationships', array( __CLASS__, 'on_taxonomy_term_unassigned' ), 10, 3);
}
// hooks functions
/**
* Creates corresponding access group for newly created organizational term
*
* @param $organization_id id of the organization term
*/
public static function on_organization_added($organization_id) {
self::_create_organization_access_group($organization_id);
}
/**
* Removes corresponding acces group when organization term is deleted
*
* @param $term_id - term id that will be deleted
* @param $taxonomy - taxonomy to which term belongs (in our case `user-organizations`)
*/
public static function on_taxonomy_term_will_be_deleted($term_id, $taxonomy) {
if ($taxonomy === self::TAXONOMY_NAME) {
$organization_id = $term_id;
self::_remove_organization_access_group($organization_id);
}
}
/**
* Adds user to corresponding access groups when he is assigned to organization.
* User will also be added to child organizations access groups.
*
* @param $object_id - id of object to which term is assigned (in our case $user_id)
* @param $terms - assigned terms (in our case $organizations)
* @param $tt_ids - assigned terms ids (in our case $organizations_ids)
* @param $taxonomy - taxonomy to which term belongs (in our case `user-organizations`)
*/
public static function on_taxonomy_term_assigned($object_id, $terms, $tt_ids, $taxonomy) {
if ($taxonomy === self::TAXONOMY_NAME) {
$user_id = $object_id;
$organization_id = $tt_ids[0];
add_user_meta($user_id, 'organization_id', $organization_id, true);
self::_add_user_to_access_group($user_id, $organization_id);
}
}
/**
* Removes user from corresponding access groups when he is removed from organization.
* User will also be removed from child organizations access groups.
*
* @param $object_id - id of object to which term is assigned (in our case $user_id)
* @param $tt_ids - assigned terms ids (in our case $organizations_ids)
* @param $taxonomy - taxonomy to which term belongs (in our case `user-organizations`)
*/
public static function on_taxonomy_term_unassigned($object_id, $tt_ids, $taxonomy) {
if ($taxonomy === self::TAXONOMY_NAME) {
$user_id = $object_id;
$organization_id = $tt_ids[0];
delete_user_meta($user_id, 'organization_id');
self::_remove_user_from_organization_access_groups($user_id, $organization_id);
}
}
/**
* Retrieves user organization based on user id
*
* @param null $user_id
* @return mixed
*/
public static function get_user_organization($user_id = null) {
if (!isset($user_id)) {
$user = wp_get_current_user();
$user_id = $user->ID;
}
$terms = wp_get_object_terms($user_id, self::TAXONOMY_NAME);
return $terms[0];
}
/**
* Assignees post to user organization. Post will be assigned to corresponding access groups.
* If user organization has parent organizations, staff from parent organizations will also be able
* to access order.
*
* @param $post_id - custom post id (product, order, ...)
* @param $user_id
*/
public static function assign_post_to_user_organization($post_id, $user_id) {
$organization = self::get_user_organization($user_id);
self::_assign_post_to_organization($post_id, $organization->term_id);
}
// private helper functions
/**
* Retrieves organization object based organization id
*
* @param $organization_id
* @return mixed
*/
private static function _get_organization_access_group_id($organization_id) {
return get_term_meta($organization_id, 'group_id', true);
}
/**
* Retrieves all access groups ids for organization. This includes corresponding access group
* for provided organization and also access groups for all of its child organizations.
*
* @param $organization_id
* @return array
*/
private static function _get_organization_all_access_groups_ids($organization_id) {
$access_groups_ids = array();
$access_groups_ids[] = self::_get_organization_access_group_id($organization_id);
$organization_departments_ids = self::_get_organization_departments_ids($organization_id);
foreach ($organization_departments_ids as $organization_department_id) {
$access_groups_ids[] = self::_get_organization_access_group_id($organization_department_id);
}
return $access_groups_ids;
}
/**
* Retrieves all departments of organization
*
* @param $organization_id
* @return array|WP_Error
*/
private static function _get_organization_departments_ids($organization_id) {
return get_term_children($organization_id, self::TAXONOMY_NAME);
}
/**
* Assign custom post to corresponding organizational acccess group.
*
* @param $post_id
* @param $organization_id
*/
private static function _assign_post_to_organization($post_id, $organization_id) {
if (class_exists('Groups_Post_Access')) {
$access_group_id = self::_get_organization_access_group_id($organization_id);
Groups_Post_Access::update( array( 'post_id' => $post_id, 'groups_read' => [$access_group_id] ) );
}
}
/**
* Create corresponding access group for organization
*
* @param $organization_id
*/
private static function _create_organization_access_group($organization_id) {
if (class_exists('Groups_Group')) {
$organization = get_term_by('id', $organization_id, self::TAXONOMY_NAME);
$access_group_id = Groups_Group::create(array(
'name' => $organization->name,
));
add_term_meta($organization_id, 'group_id', $access_group_id);
}
}
/**
* Remove corresponding access group for organization
*
* @param $organization_id
*/
private static function _remove_organization_access_group($organization_id) {
if (class_exists('Groups_Group')) {
$access_group_id = self::_get_organization_access_group_id($organization_id);
Groups_Group::delete($access_group_id);
}
}
/**
* Add user to all access groups found in provided organization.
*
* @param $user_id
* @param $organization_id
*/
private static function _add_user_to_access_group($user_id, $organization_id) {
if (class_exists('Groups_User_Group')) {
$access_groups_ids = self::_get_organization_all_access_groups_ids($organization_id);
foreach ($access_groups_ids as $access_group_id) {
Groups_User_Group::create( array( 'user_id' => $user_id, 'group_id' => $access_group_id ) );
}
}
}
/**
* Remove user from all access groups found in provided organization,
*
* @param $user_id
* @param $organization_id
*/
private static function _remove_user_from_organization_access_groups($user_id, $organization_id) {
if (class_exists('Groups_User_Group')) {
$access_groups_ids = self::_get_organization_all_access_groups_ids($organization_id);
foreach ($access_groups_ids as $access_group_id) {
Groups_User_Group::delete($user_id, $access_group_id);
}
}
}
/**
* Show organizations selection without $user info
*/
function show_organizations_selection() {
$terms = get_terms( array(
'taxonomy' => self::TAXONOMY_NAME,
) );
$taxonomy = get_taxonomy(self::TAXONOMY_NAME);
$this->table_contents(null, $taxonomy, $terms);
}
}

View File

@@ -26,4 +26,8 @@ include_once WIAAS_DIR . '/includes/class-wiaas-delivery-process.php';
include_once WIAAS_DIR . '/includes/class-wiaas-order.php';
include_once WIAAS_DIR . '/includes/class-wiaas-customer.php';
include_once WIAAS_DIR . '/includes/class-wiaas-user.php';
include_once WIAAS_DIR . '/includes/class-wiaas-api.php';

View File

@@ -29,6 +29,18 @@
"reference": "origin/master"
}
}
},
{
"type": "package",
"package": {
"name": "3rdparty/woocommerce-product-vendors",
"type": "wordpress-plugin",
"version": "2.0.27",
"dist": {
"url": "https://github.com/wp-premium/woocommerce-product-vendors/archive/2.0.27.zip",
"type": "zip"
}
}
}
],
"require": {
@@ -47,6 +59,10 @@
"wpackagist-plugin/mailchimp-for-woocommerce": "2.1.7",
"wpackagist-plugin/woocommerce-gateway-paypal-express-checkout": "1.5.6",
"wpackagist-plugin/jwt-authentication-for-wp-rest-api": "1.2.4",
"wpackagist-plugin/woo-product-bundle": "3.1.2",
"wpackagist-plugin/capability-manager-enhanced": "1.5.9",
"wpackagist-plugin/wp-user-groups": "2.2.0",
"3rdparty/woocommerce-product-vendors": "*",
"3rdparty/gravityforms": "*",
"3rdparty/gravityflow": "*"
@@ -75,6 +91,9 @@
"wp plugin activate jwt-authentication-for-wp-rest-api",
"wp plugin activate gravityforms",
"wp plugin activate gravityflow",
"wp plugin activate woo-product-bundle",
"wp plugin activate capability-manager-enhanced",
"wp plugin activate wp-user-groups",
"wp plugin activate wiaas"
],
"update-db": [

73
backend/composer.lock generated
View File

@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "16aac868dbf84d6c3cf7c41703e9085f",
"content-hash": "21ce04695bffdbca2f33154b291dd1dd",
"packages": [
{
"name": "3rdparty/gravityflow",
@@ -26,6 +26,17 @@
},
"type": "wordpress-plugin"
},
{
"name": "3rdparty/woocommerce-product-vendors",
"version": "2.0.27",
"dist": {
"type": "zip",
"url": "https://github.com/wp-premium/woocommerce-product-vendors/archive/2.0.27.zip",
"reference": null,
"shasum": null
},
"type": "wordpress-plugin"
},
{
"name": "composer/installers",
"version": "v1.5.0",
@@ -437,6 +448,26 @@
"type": "wordpress-plugin",
"homepage": "https://wordpress.org/plugins/akismet/"
},
{
"name": "wpackagist-plugin/capability-manager-enhanced",
"version": "1.5.9",
"source": {
"type": "svn",
"url": "https://plugins.svn.wordpress.org/capability-manager-enhanced/",
"reference": "trunk"
},
"dist": {
"type": "zip",
"url": "https://downloads.wordpress.org/plugin/capability-manager-enhanced.zip?timestamp=1532180189",
"reference": null,
"shasum": null
},
"require": {
"composer/installers": "~1.0"
},
"type": "wordpress-plugin",
"homepage": "https://wordpress.org/plugins/capability-manager-enhanced/"
},
{
"name": "wpackagist-plugin/groups",
"version": "2.3.1",
@@ -537,6 +568,26 @@
"type": "wordpress-plugin",
"homepage": "https://wordpress.org/plugins/mailchimp-for-woocommerce/"
},
{
"name": "wpackagist-plugin/woo-product-bundle",
"version": "3.1.2",
"source": {
"type": "svn",
"url": "https://plugins.svn.wordpress.org/woo-product-bundle/",
"reference": "trunk"
},
"dist": {
"type": "zip",
"url": "https://downloads.wordpress.org/plugin/woo-product-bundle.zip?timestamp=1533003376",
"reference": null,
"shasum": null
},
"require": {
"composer/installers": "~1.0"
},
"type": "wordpress-plugin",
"homepage": "https://wordpress.org/plugins/woo-product-bundle/"
},
{
"name": "wpackagist-plugin/woocommerce-gateway-paypal-express-checkout",
"version": "1.5.6",
@@ -576,6 +627,26 @@
},
"type": "wordpress-plugin",
"homepage": "https://wordpress.org/plugins/woocommerce-jetpack/"
},
{
"name": "wpackagist-plugin/wp-user-groups",
"version": "2.2.0",
"source": {
"type": "svn",
"url": "https://plugins.svn.wordpress.org/wp-user-groups/",
"reference": "trunk"
},
"dist": {
"type": "zip",
"url": "https://downloads.wordpress.org/plugin/wp-user-groups.zip?timestamp=1528257156",
"reference": null,
"shasum": null
},
"require": {
"composer/installers": "~1.0"
},
"type": "wordpress-plugin",
"homepage": "https://wordpress.org/plugins/wp-user-groups/"
}
],
"packages-dev": [

View File

@@ -56,14 +56,14 @@ export const receiveCustomerDetails = (json) => ({
export const fetchCartCount = () => {
return dispatch => {
dispatch(requestShopCartCount());
return client.fetch({url: `${API_SERVER}/cart/api/getCartCount`}).then(response => {
dispatch(receiveShopCartCount(0));
/*return client.fetch({url: `${API_SERVER}/cart/api/getCartCount`}).then(response => {
if (typeof response.data !== 'undefined' && 'cartItemsCount' in response.data) {
dispatch(receiveShopCartCount(response.data.cartItemsCount));
}
}).catch(error => {
client.onError(error, dispatch);
});
});*/
}
}

View File

@@ -12,16 +12,7 @@ const recieveGadgets = (json) => ({
export const fetchGadgets = () => {
return dispatch => {
dispatch(requestGadgets());
return htmlClient.fetch({
url: `${API_SERVER}/dashboards/api/getMyDashboard`
})
.then(response => {
if(response.data && response.data.gadgets){
dispatch(recieveGadgets(response.data.gadgets))
}
})
.catch(error => {
htmlClient.onError(error, dispatch);
});
const data = {"info":{"idDashboard":"23","name":"Customer Basic Dashboard","isOwner":"0"},"gadgets":[{"idGadget":"3","name":"Customer Order Central","module":"gadget-order-central","position":"1"},{"idGadget":"5","name":"Customer Next Actions","module":"gadget-next-actions","position":"2"}]};
dispatch(recieveGadgets(data.gadgets))
}
}

View File

@@ -18,7 +18,7 @@ export const fetchNextActions = () => {
return dispatch => {
dispatch(requestNextActions());
return client.fetch({
url: `${API_SERVER}/dashboards/api/getNextActionsInfo`
url: `${API_SERVER}/wp-json/wiaas/next-delivery-steps`
})
.then(response => dispatch(recieveNextActions(response.data)))
.catch(error => {

View File

@@ -19,8 +19,8 @@ export const recieveOrders = (json) => ({
export const fetchOrders = (viewAllOrders) => {
return dispatch => {
dispatch(requestOrders());
return htmlClient.fetch({
dispatch(recieveOrders([]));
/*return htmlClient.fetch({
url: `${API_SERVER}/dashboards/api/getOrderCentralInfo`,
method: 'post',
data: {
@@ -30,6 +30,6 @@ export const fetchOrders = (viewAllOrders) => {
.then(response => dispatch(recieveOrders(response.data)))
.catch(error => {
htmlClient.onError(error, dispatch);
});
});*/
}
}

View File

@@ -160,8 +160,68 @@ const validateRefreshToken = () => {
export const getModules = () => {
return dispatch => {
const data = {
"modules": {
"modules": [
{
"id": "14",
"name": "ProfileSettings",
"menuName": "ProfileSettings",
"url": "profileSettings",
"isInMenu": "0"
},
{
"id": "23",
"name": "OrderProjects",
"menuName": "OrderProjects",
"url": "orderProjects",
"isInMenu": "0"
},
{
"id": "15",
"name": "Terms",
"menuName": "Terms",
"url": "terms",
"isInMenu": "0"
},
{
"id": "19",
"name": "Cart",
"menuName": "Cart",
"url": "cart",
"isInMenu": "0"
},
{
"id": "1",
"name": "Dashboards",
"menuName": "Overview",
"url": "dashboards",
"isInMenu": "1"
},
{
"id": "18",
"name": "CoMarket",
"menuName": "Co-Market",
"url": "co-market",
"isInMenu": "1"
}
],
"subModules": {
"co-market": [
{
"moduleUrl": "co-market",
"menuName": "Orders",
"name": "Orders",
"url": "orders"
}
]
}
}
};
dispatch(recieveModules(data));
dispatch(requestModules());
return htmlClient.fetch({
/**return htmlClient.fetch({
url: `${API_SERVER}/login/api/getModules`,
})
.then(response => {
@@ -169,7 +229,7 @@ export const getModules = () => {
})
.catch(error => {
htmlClient.onError(error, dispatch);
});
});**/
}
}

View File

@@ -23,12 +23,10 @@ export const getActiveOrders = () => {
return dispatch => {
dispatch(requestActiveOrders());
return htmlClient.fetch({
url: `${API_SERVER}/orders/api/getActiveOrders`
url: `${API_SERVER}/wp-json/wc/v2/orders?status=processing`
})
.then(response => {
if (typeof response.data !== 'undefined' && 'orders' in response.data) {
dispatch(recieveActiveOrders(response.data.orders));
}
dispatch(recieveActiveOrders(response.data));
})
.catch(error => {
htmlClient.onError(error, dispatch);
@@ -50,12 +48,10 @@ export const getHistoryOrders = () => {
return dispatch => {
dispatch(requestHistoryOrders());
return htmlClient.fetch({
url: `${API_SERVER}/orders/api/getHistoryOrders`
url: `${API_SERVER}/wp-json/wc/v2/orders?status=completed`
})
.then(response => {
if (typeof response.data !== 'undefined' && 'orders' in response.data) {
dispatch(recieveHistoryOrders(response.data.orders));
}
dispatch(recieveHistoryOrders(response.data));
})
.catch(error => {
htmlClient.onError(error, dispatch);

View File

@@ -186,10 +186,10 @@ export const orderTexts = {
},
statuses: {
open: 'Open',
'in-progress': 'In Progress',
production: 'Completed',
'processing': 'Processing',
completed: 'Completed',
'end-of-life': 'Completed',
canceled: 'Canceled',
cancelled: 'Cancelled',
'not-accepted': 'Not Accepted',
invalid: 'Invalid',
pending: 'Pending'

View File

@@ -15,7 +15,7 @@ class OrdersDataContainer extends Component {
checkIfOrdersExistForUser(orders) {
return orders.every((order) => {
return 'isMyOrder' in order && !order.isMyOrder;
return true;//'isMyOrder' in order && !order.isMyOrder;
})
}
@@ -38,7 +38,7 @@ class OrdersDataContainer extends Component {
<OrderList orders={orders} type={type}/>
}
{
((orders && orders.length === 0 && !isLoading) || (orders && this.checkIfOrdersExistForUser(orders))) &&
((orders && orders.length === 0 && !isLoading) || (orders && !this.checkIfOrdersExistForUser(orders))) &&
<Alert color="info">{orderTexts.labels.NO_RECORDS}</Alert>
}
</WiaasBox>

View File

@@ -37,28 +37,28 @@ class ActiveOrderItem extends Component {
{!this.state.showPackages && <i className={this.getIconClass('down')} aria-hidden="true" onClick={this.toggle}></i>}
{this.state.showPackages && <i className={this.getIconClass('up')} aria-hidden="true" onClick={this.toggle}></i>}
<i className="fa fa-list-alt package-photo" aria-hidden="true" />
<div className="order-number">{order.orderNumber}</div>
<div className="order-number">{order.number}</div>
</WiaasTableCol>
<WiaasTableCol header={orderTexts.labels.REFERENCE}>{order.reference ? order.reference : '-'}</WiaasTableCol>
{isViewAllOrdersChecked['active'] && <WiaasTableCol header={orderTexts.labels.PLACED_BY}>{order.customerName ? order.customerName : ''}</WiaasTableCol>}
<WiaasTableCol header={orderTexts.labels.ORDER_DATE}>{order.orderDate ? order.orderDate : '-'}</WiaasTableCol>
{isViewAllOrdersChecked['active'] && <WiaasTableCol header={orderTexts.labels.PLACED_BY}>{order.customer ? order.customer.name : ''}</WiaasTableCol>}
<WiaasTableCol header={orderTexts.labels.ORDER_DATE}>{order.date_created ? order.date_created : '-'}</WiaasTableCol>
<WiaasTableCol header={orderTexts.labels.EST_DELIVERY}>{order.estimatedDeliveryDate ? order.estimatedDeliveryDate : '-'}</WiaasTableCol>
<WiaasTableCol header="Catalogue">
<div className="order-item-cl">
<img className="cl-photo" src="static/img/man-icon.png" alt="Catalogue" />
<div className="cl-details">
<div className="cl-contact-name">{order.clContactName}</div>
<div className="cl-name">{order.clName}</div>
<div className="cl-contact-name">{order.commercial_lead ? order.commercial_lead.contact_name : ''}</div>
<div className="cl-name">{order.commercial_lead ? order.commercial_lead.name : ''}</div>
</div>
</div>
</WiaasTableCol>
<WiaasTableCol header={orderTexts.labels.AMOUNT}>
{order.orderCurrency && order.orderCurrency.currency
? order.orderTotalPrice.toLocaleString() + ' ' + order.orderCurrency.currency
: parseFloat(order.orderTotalPrice).toLocaleString()}
{order.currency
? order.total.toLocaleString() + ' ' + order.currency
: parseFloat(order.total).toLocaleString()}
</WiaasTableCol>
<WiaasTableCol header={orderTexts.labels.STATUS}>
<div className={'status-icon ' + order.status}></div>{order.status}
<div className={'status-icon ' + order.status}></div>{orderTexts.statuses[order.status]}
</WiaasTableCol>
<WiaasTableCol header="Buttons details">
<Link to={'/orders/' + order.id} className="actions-link">

View File

@@ -42,7 +42,7 @@ class HistoryOrdersButtons extends Component {
],
header: orderTexts.labels.SUPPORT_MESSAGE_HEADER,
TagName: SupportMail,
params: {orderInfo: this.props.order, orderPackages: this.props.order.packages}
params: {orderInfo: this.props.order, orderPackages: this.props.order.line_items}
};
this.props.dispatch(setDialogOpenFlag(true));

View File

@@ -37,30 +37,30 @@ class HistoryOrdersItem extends Component {
{!this.state.showPackages && <i className={this.getIconClass('down')} aria-hidden="true" onClick={this.toggle}></i>}
{this.state.showPackages && <i className={this.getIconClass('up')} aria-hidden="true" onClick={this.toggle}></i>}
<i className="fa fa-list-alt package-photo" aria-hidden="true" />
<div className="order-number">{order.orderNumber}</div>
<div className="order-number">{order.number}</div>
</WiaasTableCol>
<WiaasTableCol header={orderTexts.labels.REFERENCE}>{order.reference ? order.reference : '-'}</WiaasTableCol>
{isViewAllOrdersChecked['history'] && <WiaasTableCol header={orderTexts.labels.PLACED_BY}>{order.customerName ? order.customerName : ''}</WiaasTableCol>}
<WiaasTableCol header={orderTexts.labels.ORDER_DATE}>{order.orderDate ? order.orderDate : '-'}</WiaasTableCol>
{isViewAllOrdersChecked['history'] && <WiaasTableCol header={orderTexts.labels.PLACED_BY}>{order.customer ? order.customer.name : ''}</WiaasTableCol>}
<WiaasTableCol header={orderTexts.labels.ORDER_DATE}>{order.date_created ? order.date_created : '-'}</WiaasTableCol>
<WiaasTableCol header={orderTexts.labels.DELIVERY_DATE}>{order.deliveryDate}</WiaasTableCol>
<WiaasTableCol header="Catalogue">
<div className="order-item-cl">
<img className="cl-photo" src="static/img/man-icon.png" alt="Catalogue" />
<div className="cl-details">
<div className="cl-contact-name">{order.clContactName}</div>
<div className="cl-name">{order.clName}</div>
<div className="cl-contact-name">{order.commercial_lead ? order.commercial_lead.contact_name : ''}</div>
<div className="cl-name">{order.commercial_lead ? order.commercial_lead.name : ''}</div>
</div>
</div>
</WiaasTableCol>
<WiaasTableCol header={orderTexts.labels.AMOUNT}>
{order.orderCurrency && order.orderCurrency.currency
? order.orderTotalPrice.toLocaleString() + ' ' + order.orderCurrency.currency
: parseFloat(order.orderTotalPrice).toLocaleString()}
{order.currency
? order.total.toLocaleString() + ' ' + order.currency
: parseFloat(order.total).toLocaleString()}
</WiaasTableCol>
<WiaasTableCol header={orderTexts.labels.STATUS}>
<div className={'status-icon ' + order.status}></div>{orderTexts.statuses[order.status]}
</WiaasTableCol>
<WiaasTableCol header="End of life">{order.endOfLife}</WiaasTableCol>
<WiaasTableCol header="End of life">{order.date_completed}</WiaasTableCol>
<WiaasTableCol header="Buttons details">
<HistoryOrderButtons order={order}/>
</WiaasTableCol>

View File

@@ -57,8 +57,8 @@ class OrderList extends Component {
{
orders &&
orders.map((order, index) =>
(('isMyOrder' in order && order.isMyOrder) || (isCompanyAdmin && isViewAllOrdersChecked[type])) &&
<TagName key={order.orderNumber} order={order} />
((true) || (isCompanyAdmin && isViewAllOrdersChecked[type])) &&
<TagName key={order.id} order={order} />
)
}
</WiaasTableBody>
@@ -69,7 +69,7 @@ class OrderList extends Component {
}
const mapStateToProps = (state) => ({
isCompanyAdmin: state.auth.isCompanyAdmin,
isCompanyAdmin: true, //state.auth.isCompanyAdmin,
isViewAllOrdersChecked: state.ordersReducer.isViewAllOrdersChecked
});
export default connect(mapStateToProps)(OrderList);

View File

@@ -51,6 +51,6 @@ class OrderListHeader extends Component {
}
const mapStateToProps = (state) => ({
isCompanyAdmin: state.auth.isCompanyAdmin
isCompanyAdmin: true//state.auth.isCompanyAdmin
});
export default connect(mapStateToProps)(OrderListHeader);

View File

@@ -32,23 +32,23 @@ class OrderPackage extends Component {
<div className="order-details-container">
<WiaasTableRow id={'delivery-address-' + order.id}>
<Col lg="4" sm="4" xs="4">{orderTexts.labels.DELIVERY_ADDRESS}:</Col>
<Col lg="8" sm="8" xs="8">{order.deliveryAddress}</Col>
<Col lg="8" sm="8" xs="8">{order.shipping.address_1}, {order.shipping.city}, {order.shipping.country}, {order.shipping.postcode}</Col>
</WiaasTableRow>
<WiaasTableRow id={'phone-' + order.id}>
<Col lg="4" sm="4" xs="4">{orderTexts.labels.PHONE_NUMBER}:</Col>
<Col lg="8" sm="8" xs="8">{order.phone}</Col>
<Col lg="8" sm="8" xs="8">{order.customer.phone}</Col>
</WiaasTableRow>
<WiaasTableRow id={'mail-' + order.id}>
<Col lg="4" sm="4" xs="4">{orderTexts.labels.MAIL}:</Col>
<Col lg="8" sm="8" xs="8">{order.mail}</Col>
<Col lg="8" sm="8" xs="8">{order.customer.email}</Col>
</WiaasTableRow>
<WiaasTableRow id={'commercial-lead-phone-' + order.id}>
<Col lg="4" sm="4" xs="4">{order.clName} {orderTexts.labels.PHONE_NUMBER}:</Col>
<Col lg="8" sm="8" xs="8">{order.commercialLeadPhone}</Col>
<Col lg="4" sm="4" xs="4">{order.commercial_lead ? order.commercial_lead.name : ''} {orderTexts.labels.PHONE_NUMBER}:</Col>
<Col lg="8" sm="8" xs="8">{order.commercial_lead ? order.commercial_lead.phone : ''}</Col>
</WiaasTableRow>
<WiaasTableRow id={'mail-' + order.id}>
<Col lg="4" sm="4" xs="4">{order.clName} {orderTexts.labels.MAIL}:</Col>
<Col lg="8" sm="8" xs="8">{order.commercialLeadMail}</Col>
<Col lg="4" sm="4" xs="4">{order.commercial_lead ? order.commercial_lead.name : ''} {orderTexts.labels.MAIL}:</Col>
<Col lg="8" sm="8" xs="8">{order.commercial_lead ? order.commercial_lead.email : ''}</Col>
</WiaasTableRow>
</div>
</WiaasBox>
@@ -58,24 +58,24 @@ class OrderPackage extends Component {
<WiaasTable>
<WiaasTableHeader headers={this.getHeadersByType(type)}/>
<WiaasTableBody>
{order.packages.map((orderPackage, index) =>
<WiaasTableRow className="order-central-row" key={orderPackage.idOrder + '-' + orderPackage.idPackage}>
{order.line_items.map((orderPackage, index) =>
<WiaasTableRow className="order-central-row" key={orderPackage.id + '-' + orderPackage.product_id}>
<WiaasTableCol header="Package" className="package-info-col">
<div className="package-name">{orderPackage.units} x {orderPackage.packageName}</div>
<div className="package-name">{orderPackage.quantity} x {orderPackage.name}</div>
</WiaasTableCol>
<WiaasTableCol header="Price">
{this.calculateQuantityPrice(orderPackage.units, orderPackage.packageFixedPrice).toLocaleString()} {orderPackage.packageCurrency && orderPackage.packageCurrency.currency} {' '}
({orderPackage.paymentType})
{this.calculateQuantityPrice(orderPackage.quantity, orderPackage.price).toLocaleString()} {orderPackage.packageCurrency && orderPackage.packageCurrency.currency} {' '}
({orderPackage.payment_type})
</WiaasTableCol>
<WiaasTableCol header="Services and support">
{this.calculateQuantityPrice(orderPackage.units, orderPackage.packageServicePrice, orderPackage.packageRecuringPrice).toLocaleString() + ' / ' + orderPackage.periodUnit + ' '}
{orderTexts.labels.EXTEND} {orderPackage.periodUnit} (Max {orderPackage.maxContractPeriod})
{this.calculateQuantityPrice(orderPackage.quantity, orderPackage.service_price, orderPackage.recurring_price).toLocaleString() + ' / ' + orderPackage.period_unit + ' '}
{orderTexts.labels.EXTEND} {orderPackage.period_unit} (Max {orderPackage.max_contract_period})
</WiaasTableCol>
<WiaasTableCol>
{
type === 'active'
? orderPackage.shortDesc ? orderPackage.shortDesc : '-'
: orderPackage.endOfLife ? orderPackage.endOfLife : '-'
? orderPackage.short_desc || '-'
: orderPackage.date_completed || '-'
}
</WiaasTableCol>
</WiaasTableRow>

View File

@@ -48,7 +48,7 @@ class SupportMail extends Component {
<span className="subtitle">{orderTexts.labels.ORDER_NUMBER}:</span>
</Col>
<Col xl="8">
<span>{orderInfo.orderNumber}</span>
<span>{orderInfo.number}</span>
</Col>
</Row>
<Row>
@@ -71,17 +71,17 @@ class SupportMail extends Component {
<Row>
<Col>
<span className="fa fa-shopping-cart subtitle"></span>
<span className="package-name"> {orderPackage.units} x {orderPackage.packageName}</span>
<span className="package-name"> {orderPackage.quantity} x {orderPackage.name}</span>
</Col>
</Row>
{orderPackage.endOfLife &&
{orderInfo.date_modified &&
<Row>
<Col>
<span className="subtitle">{orderTexts.labels.END_OF_LIFE}:</span>
</Col>
<Col xl="8">
<span>{orderPackage.endOfLife}</span>
<span>{orderPackage.date_completed}</span>
</Col>
</Row>
}

View File

@@ -14,7 +14,7 @@ $borderWidth: 3px;
border-left: $borderWidth $open-status-color solid;
}
.order-border-in-progress {
.order-border-processing {
border-left: $borderWidth $in-progress-status-color solid;
}
@@ -72,11 +72,11 @@ $borderWidth: 3px;
background: $open-status-color;
}
.in-progress {
.processing {
background: $in-progress-status-color;
}
.production {
.completed {
background: $production-status-color;
}