From b8653ad18bbbb7e0893e00ef0eb5c9a3fc89e7d5 Mon Sep 17 00:00:00 2001 From: Almira Krdzic Date: Wed, 8 Aug 2018 12:21:26 +0200 Subject: [PATCH] Work on wiaas orders --- .../wiaas/includes/class-wiaas-customer.php | 25 ++ .../wiaas/includes/class-wiaas-db-update.php | 3 +- .../wiaas/includes/class-wiaas-order.php | 115 ++++++++ .../wiaas/includes/class-wiaas-user.php | 19 ++ .../db-updates/wiaas-db-update-functions.php | 8 + .../user/class-wiaas-user-organization.php | 254 ++++++++++++++++++ backend/app/plugins/wiaas/wiaas.php | 4 + backend/composer.json | 19 ++ backend/composer.lock | 73 ++++- frontend/src/actions/cart/cartActions.js | 6 +- .../src/actions/dashboard/dashboardActions.js | 13 +- .../actions/dashboard/nextActionsActions.js | 2 +- .../src/actions/dashboard/ordersActions.js | 6 +- frontend/src/actions/login/authActions.js | 64 ++++- frontend/src/actions/orders/ordersActions.js | 12 +- frontend/src/constants/ordersConstants.js | 6 +- .../containers/orders/OrdersDataContainer.jsx | 4 +- .../orders/components/ActiveOrderItem.jsx | 18 +- .../orders/components/HistoryOrderButtons.jsx | 2 +- .../orders/components/HistoryOrderItem.jsx | 18 +- .../orders/components/OrderList.jsx | 6 +- .../orders/components/OrderListHeader.jsx | 2 +- .../orders/components/OrderPackage.jsx | 32 +-- .../orders/components/SupportMail.jsx | 8 +- .../src/containers/orders/style/Orders.scss | 6 +- 25 files changed, 644 insertions(+), 81 deletions(-) create mode 100644 backend/app/plugins/wiaas/includes/class-wiaas-customer.php create mode 100644 backend/app/plugins/wiaas/includes/class-wiaas-user.php create mode 100644 backend/app/plugins/wiaas/includes/user/class-wiaas-user-organization.php diff --git a/backend/app/plugins/wiaas/includes/class-wiaas-customer.php b/backend/app/plugins/wiaas/includes/class-wiaas-customer.php new file mode 100644 index 0000000..3fc2635 --- /dev/null +++ b/backend/app/plugins/wiaas/includes/class-wiaas-customer.php @@ -0,0 +1,25 @@ + '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() { diff --git a/backend/app/plugins/wiaas/includes/class-wiaas-order.php b/backend/app/plugins/wiaas/includes/class-wiaas-order.php index b62e181..fcf8db7 100644 --- a/backend/app/plugins/wiaas/includes/class-wiaas-order.php +++ b/backend/app/plugins/wiaas/includes/class-wiaas-order.php @@ -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(); \ No newline at end of file diff --git a/backend/app/plugins/wiaas/includes/class-wiaas-user.php b/backend/app/plugins/wiaas/includes/class-wiaas-user.php new file mode 100644 index 0000000..bada6dd --- /dev/null +++ b/backend/app/plugins/wiaas/includes/class-wiaas-user.php @@ -0,0 +1,19 @@ +add_cap('read_private_shop_orders'); + $customer_role->add_cap('read_shop_order'); } \ No newline at end of file diff --git a/backend/app/plugins/wiaas/includes/user/class-wiaas-user-organization.php b/backend/app/plugins/wiaas/includes/user/class-wiaas-user-organization.php new file mode 100644 index 0000000..d14570a --- /dev/null +++ b/backend/app/plugins/wiaas/includes/user/class-wiaas-user-organization.php @@ -0,0 +1,254 @@ + __('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); + } +} \ No newline at end of file diff --git a/backend/app/plugins/wiaas/wiaas.php b/backend/app/plugins/wiaas/wiaas.php index cd9f5b4..2dda5d7 100644 --- a/backend/app/plugins/wiaas/wiaas.php +++ b/backend/app/plugins/wiaas/wiaas.php @@ -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'; diff --git a/backend/composer.json b/backend/composer.json index 5900c23..621d8a0 100644 --- a/backend/composer.json +++ b/backend/composer.json @@ -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": [ diff --git a/backend/composer.lock b/backend/composer.lock index cda3cd2..12e0018 100644 --- a/backend/composer.lock +++ b/backend/composer.lock @@ -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": [ diff --git a/frontend/src/actions/cart/cartActions.js b/frontend/src/actions/cart/cartActions.js index 8005745..2d64e1b 100644 --- a/frontend/src/actions/cart/cartActions.js +++ b/frontend/src/actions/cart/cartActions.js @@ -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); - }); + });*/ } } diff --git a/frontend/src/actions/dashboard/dashboardActions.js b/frontend/src/actions/dashboard/dashboardActions.js index 14aaad5..8e6c26e 100644 --- a/frontend/src/actions/dashboard/dashboardActions.js +++ b/frontend/src/actions/dashboard/dashboardActions.js @@ -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)) } } diff --git a/frontend/src/actions/dashboard/nextActionsActions.js b/frontend/src/actions/dashboard/nextActionsActions.js index 5716e97..e9e6edf 100644 --- a/frontend/src/actions/dashboard/nextActionsActions.js +++ b/frontend/src/actions/dashboard/nextActionsActions.js @@ -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 => { diff --git a/frontend/src/actions/dashboard/ordersActions.js b/frontend/src/actions/dashboard/ordersActions.js index d4a1371..9a6419e 100644 --- a/frontend/src/actions/dashboard/ordersActions.js +++ b/frontend/src/actions/dashboard/ordersActions.js @@ -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); - }); + });*/ } } diff --git a/frontend/src/actions/login/authActions.js b/frontend/src/actions/login/authActions.js index 18867ad..9a1a937 100644 --- a/frontend/src/actions/login/authActions.js +++ b/frontend/src/actions/login/authActions.js @@ -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); - }); + });**/ } } diff --git a/frontend/src/actions/orders/ordersActions.js b/frontend/src/actions/orders/ordersActions.js index d123387..02dd0c0 100644 --- a/frontend/src/actions/orders/ordersActions.js +++ b/frontend/src/actions/orders/ordersActions.js @@ -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); diff --git a/frontend/src/constants/ordersConstants.js b/frontend/src/constants/ordersConstants.js index 6b1f69d..474cdcf 100644 --- a/frontend/src/constants/ordersConstants.js +++ b/frontend/src/constants/ordersConstants.js @@ -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' diff --git a/frontend/src/containers/orders/OrdersDataContainer.jsx b/frontend/src/containers/orders/OrdersDataContainer.jsx index 2cd81a3..d150f7d 100644 --- a/frontend/src/containers/orders/OrdersDataContainer.jsx +++ b/frontend/src/containers/orders/OrdersDataContainer.jsx @@ -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 { } { - ((orders && orders.length === 0 && !isLoading) || (orders && this.checkIfOrdersExistForUser(orders))) && + ((orders && orders.length === 0 && !isLoading) || (orders && !this.checkIfOrdersExistForUser(orders))) && {orderTexts.labels.NO_RECORDS} } diff --git a/frontend/src/containers/orders/components/ActiveOrderItem.jsx b/frontend/src/containers/orders/components/ActiveOrderItem.jsx index 850731e..d04a589 100644 --- a/frontend/src/containers/orders/components/ActiveOrderItem.jsx +++ b/frontend/src/containers/orders/components/ActiveOrderItem.jsx @@ -37,28 +37,28 @@ class ActiveOrderItem extends Component { {!this.state.showPackages && } {this.state.showPackages && }