Wiaas Orders #12
@@ -9,7 +9,9 @@ class Wiaas_DB_Update {
|
|||||||
'20180801222206' => 'wiaas_db_update_setup_gravity',
|
'20180801222206' => 'wiaas_db_update_setup_gravity',
|
||||||
'20180802222206' => 'wiaas_db_update_add_delivery_process_forms',
|
'20180802222206' => 'wiaas_db_update_add_delivery_process_forms',
|
||||||
'20180807222206' => 'wiaas_db_update_setup_customer_capabilities',
|
'20180807222206' => 'wiaas_db_update_setup_customer_capabilities',
|
||||||
'20180809134511' => 'wiaas_db_update_add_customer_read_permission'
|
'20180809134511' => 'wiaas_db_update_add_customer_read_permission',
|
||||||
|
'20180811134511' => 'wiaas_db_update_enable_orders_access_management',
|
||||||
|
'20180813134511' => 'wiaas_db_update_enable_order_numbers'
|
||||||
);
|
);
|
||||||
|
|
||||||
public static function execute() {
|
public static function execute() {
|
||||||
|
|||||||
@@ -8,12 +8,72 @@
|
|||||||
|
|
||||||
class Wiaas_Order {
|
class Wiaas_Order {
|
||||||
|
|
||||||
|
private static $object_order_type = 'shop_order';
|
||||||
|
|
||||||
public static function init() {
|
public static function init() {
|
||||||
|
add_action('woocommerce_new_order', array( __CLASS__, 'assign_order_to_organization' ));
|
||||||
|
|
||||||
|
add_filter('woocommerce_rest_check_permissions', array( __CLASS__, 'check_order_access'), 10, 4);
|
||||||
|
|
||||||
add_filter('woocommerce_rest_prepare_shop_order_object', array(__CLASS__, 'transform_rest_order'), 10, 3);
|
add_filter('woocommerce_rest_prepare_shop_order_object', array(__CLASS__, 'transform_rest_order'), 10, 3);
|
||||||
|
|
||||||
|
add_filter('woocommerce_rest_orders_prepare_object_query', array( __CLASS__, 'wiaas_prepare_rest_orders_query'), 10, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Apply wiaas custome tranformation on retrieved JSON order object
|
* 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 === self::$object_order_type && $object_id !== 0) {
|
||||||
|
return Groups_Post_Access::user_can_read_post($object_id);
|
||||||
|
}
|
||||||
|
return $permission;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles custom wiaas arguments to woocommerce orders api endpoint `wc/v2/orders`
|
||||||
|
* @param $args
|
||||||
|
* @param $request
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public static function wiaas_prepare_rest_orders_query($args, $request) {
|
||||||
|
|
||||||
|
# Handle wiaas_is_active flag
|
||||||
|
if (isset($request['wiaas_is_active'])) {
|
||||||
|
if ($request['wiaas_is_active'] === '1') {
|
||||||
|
$args['post_status'] = array('wc-open', 'wc-processing');
|
||||||
|
}
|
||||||
|
if ($request['wiaas_is_active'] === '0') {
|
||||||
|
$args['post_status'] = array('wc-completed', 'wc-cancelled');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $args;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Apply wiaas custom transformation on retrieved JSON order object
|
||||||
*
|
*
|
||||||
* @param $response
|
* @param $response
|
||||||
* @param $order
|
* @param $order
|
||||||
@@ -25,13 +85,109 @@ class Wiaas_Order {
|
|||||||
$data = $response->get_data();
|
$data = $response->get_data();
|
||||||
|
|
||||||
# apply overrides
|
# apply overrides
|
||||||
|
$data = self::_append_products_info($data, $order, $request);
|
||||||
|
|
||||||
$data = self::_append_order_process($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);
|
$response->set_data($data);
|
||||||
|
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PRIVATE
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Appends additional wiaas customer lead info to order json response
|
||||||
|
* @param $data
|
||||||
|
* @param $order
|
||||||
|
* @param $request
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Appends additional wiaas customer info to order json response
|
||||||
|
* @param $data
|
||||||
|
* @param $order
|
||||||
|
* @param $request
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
private static function _append_customer_info($data, $order, $request) {
|
||||||
|
|
||||||
|
$current_user = wp_get_current_user();
|
||||||
|
|
||||||
|
$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' => '+46 (10) 5595148'
|
||||||
|
);
|
||||||
|
|
||||||
|
$data['is_my_order'] = $customer_id === $current_user->ID;
|
||||||
|
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Appends additional wiaas products info to order json response
|
||||||
|
* @param $data
|
||||||
|
* @param $order
|
||||||
|
* @param $request
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
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
|
||||||
|
if ($data['status'] === 'completed') {
|
||||||
|
$product_line['status'] = 'production';
|
||||||
|
} else if ($data['status'] === 'cancelled') {
|
||||||
|
$product_line['status'] = 'cancelled';
|
||||||
|
} else {
|
||||||
|
$product_line['status'] = 'processing';
|
||||||
|
}
|
||||||
|
$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
|
* Append order delivery process info if single order is requested
|
||||||
* @param $data
|
* @param $data
|
||||||
|
|||||||
29
backend/app/plugins/wiaas/includes/class-wiaas-user.php
Normal file
29
backend/app/plugins/wiaas/includes/class-wiaas-user.php
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
defined( 'ABSPATH' ) || exit;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class Wiaas_User
|
||||||
|
*/
|
||||||
|
class Wiaas_User {
|
||||||
|
|
||||||
|
public static function init() {
|
||||||
|
add_action('init', array(__CLASS__, 'load_user_organization'));
|
||||||
|
add_action('plugins_loaded', array(__CLASS__, 'remove_default_user_groups'), 30);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function load_user_organization() {
|
||||||
|
if (class_exists('WP_User_Taxonomy')) {
|
||||||
|
require_once dirname( __FILE__ ) . '/user/class-wiaas-user-organization.php';
|
||||||
|
|
||||||
|
new Wiaas_User_Organization();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function remove_default_user_groups() {
|
||||||
|
remove_action( 'init', 'wp_register_default_user_group_taxonomy' );
|
||||||
|
remove_action( 'init', 'wp_register_default_user_type_taxonomy' );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Wiaas_User::init();
|
||||||
@@ -84,7 +84,26 @@ function wiaas_db_update_setup_customer_capabilities() {
|
|||||||
$customer_role->add_cap('read_private_shop_orders');
|
$customer_role->add_cap('read_private_shop_orders');
|
||||||
$customer_role->add_cap('read_shop_order');
|
$customer_role->add_cap('read_shop_order');
|
||||||
}
|
}
|
||||||
|
|
||||||
function wiaas_db_update_add_customer_read_permission() {
|
function wiaas_db_update_add_customer_read_permission() {
|
||||||
$role = get_role( 'customer' );
|
$role = get_role( 'customer' );
|
||||||
$role->add_cap( 'read_private_products' );
|
$role->add_cap( 'read_private_products' );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function wiaas_db_update_enable_orders_access_management() {
|
||||||
|
$post_types_option = Groups_Options::get_option( Groups_Post_Access::POST_TYPES, array() );
|
||||||
|
|
||||||
|
$post_types_option['shop_order'] = array(
|
||||||
|
'add_meta_box' => true
|
||||||
|
);
|
||||||
|
|
||||||
|
Groups_Options::update_option(Groups_Post_Access::POST_TYPES, $post_types_option);
|
||||||
|
}
|
||||||
|
|
||||||
|
function wiaas_db_update_enable_order_numbers() {
|
||||||
|
update_option('wcj_order_numbers_enabled', 'yes');
|
||||||
|
update_option('wcj_order_number_sequential_enabled', 'no');
|
||||||
|
update_option('wcj_order_number_counter', '0');
|
||||||
|
update_option('wcj_order_number_counter_reset_enabled', 'no');
|
||||||
|
update_option('wcj_order_number_prefix', '1000000');
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,312 @@
|
|||||||
|
<?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', 'wiaas'),
|
||||||
|
'plural' => __('Organizations', 'wiaas'),
|
||||||
|
'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 on new user form
|
||||||
|
*/
|
||||||
|
function show_organizations_selection() {
|
||||||
|
$terms = get_terms( array(
|
||||||
|
'taxonomy' => self::TAXONOMY_NAME,
|
||||||
|
'hide_empty' => false,
|
||||||
|
) );
|
||||||
|
$taxonomy = get_taxonomy(self::TAXONOMY_NAME);
|
||||||
|
$this->table_contents(null, $taxonomy, $terms);
|
||||||
|
}
|
||||||
|
|
||||||
|
function edit_user_relationships($user = false) {
|
||||||
|
$tax = get_taxonomy( $this->taxonomy );
|
||||||
|
|
||||||
|
// Get the terms of the taxonomy.
|
||||||
|
$terms = get_terms( $this->taxonomy, array(
|
||||||
|
'hide_empty' => false
|
||||||
|
) );
|
||||||
|
|
||||||
|
$this->table_contents( $user, $tax, $terms );
|
||||||
|
}
|
||||||
|
|
||||||
|
function table_contents( $user, $tax, $terms ) {
|
||||||
|
$active_organization_id = -1;
|
||||||
|
if ($user) {
|
||||||
|
$active_organization = self::get_user_organization($user->ID);
|
||||||
|
$active_organization_id = $active_organization ? $active_organization->term_id : -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
|
<table class="form-table">
|
||||||
|
<tbody>
|
||||||
|
<tr class="form-field">
|
||||||
|
<th scope="row">
|
||||||
|
<label for="<?php echo esc_attr( $this->taxonomy ); ?>[]">
|
||||||
|
<?php echo esc_html( $tax->labels->singular_name ); ?>
|
||||||
|
</label>
|
||||||
|
</th>
|
||||||
|
<td>
|
||||||
|
<select name="<?php echo esc_attr( $this->taxonomy ); ?>[]" id="<?php echo esc_attr( $this->taxonomy ); ?>">
|
||||||
|
<?php
|
||||||
|
foreach ( $terms as $term ) :
|
||||||
|
$selected = $active_organization_id === $term->term_id;
|
||||||
|
?>
|
||||||
|
<option
|
||||||
|
value="<?php echo esc_attr( $term->slug ); ?>"
|
||||||
|
<?php selected( $selected ); ?>
|
||||||
|
>
|
||||||
|
<?php echo esc_attr( $term->name ); ?>
|
||||||
|
</option>
|
||||||
|
<?php
|
||||||
|
endforeach;
|
||||||
|
?>
|
||||||
|
</select>
|
||||||
|
<?php
|
||||||
|
wp_nonce_field( $this->taxonomy, $this->get_nonce_key() );
|
||||||
|
?>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
|
||||||
|
private function get_nonce_key() {
|
||||||
|
return "wp_user_taxonomy_{$this->taxonomy}";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -35,6 +35,11 @@ function load_wiaas_test_setup() {
|
|||||||
|
|
||||||
require_once '/tmp/wiaas-backend-test/app/plugins/gravityflow/gravityflow.php';
|
require_once '/tmp/wiaas-backend-test/app/plugins/gravityflow/gravityflow.php';
|
||||||
|
|
||||||
|
require_once '/tmp/wiaas-backend-test/app/plugins/groups/groups.php';
|
||||||
|
|
||||||
|
require_once '/tmp/wiaas-backend-test/app/plugins/wp-user-groups/wp-user-groups.php';
|
||||||
|
_wp_user_groups();
|
||||||
|
|
||||||
require_once '/tmp/wiaas-backend-test/app/plugins/wiaas/wiaas.php';
|
require_once '/tmp/wiaas-backend-test/app/plugins/wiaas/wiaas.php';
|
||||||
|
|
||||||
# Require classes needed for db updates
|
# Require classes needed for db updates
|
||||||
|
|||||||
201
backend/app/plugins/wiaas/tests/unit-tests/test-wiaas-order.php
Normal file
201
backend/app/plugins/wiaas/tests/unit-tests/test-wiaas-order.php
Normal file
@@ -0,0 +1,201 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class Wiaas_Order_Test
|
||||||
|
*/
|
||||||
|
|
||||||
|
class Wiaas_Order_Test extends Wiaas_Unit_Test_Case {
|
||||||
|
|
||||||
|
var $customer_id, $customer_organization_id, $customer_organization_name, $order_id;
|
||||||
|
|
||||||
|
public function setUp() {
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
|
wp_set_current_user(1);
|
||||||
|
|
||||||
|
$this->customer_id = wp_insert_user(array(
|
||||||
|
'user_login' => 'test_customer',
|
||||||
|
'user_pass' => 'test',
|
||||||
|
'user_email' => 'test_customer@mail.com',
|
||||||
|
'role' => 'customer',
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->customer_organization_name = 'test-customer-organization';
|
||||||
|
|
||||||
|
# create customer organization
|
||||||
|
$this->customer_organization_id = wp_insert_term(
|
||||||
|
$this->customer_organization_name,
|
||||||
|
Wiaas_User_Organization::TAXONOMY_NAME
|
||||||
|
)['term_id'];
|
||||||
|
|
||||||
|
# add customer to organization
|
||||||
|
wp_set_terms_for_user(
|
||||||
|
$this->customer_id,
|
||||||
|
Wiaas_User_Organization::TAXONOMY_NAME,
|
||||||
|
[$this->customer_organization_name]);
|
||||||
|
|
||||||
|
wp_set_current_user($this->customer_id);
|
||||||
|
|
||||||
|
$order = wc_create_order(array(
|
||||||
|
'customer_id' => $this->customer_id
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->order_id = $order->get_id();
|
||||||
|
}
|
||||||
|
|
||||||
|
function tearDown() {
|
||||||
|
parent::tearDown();
|
||||||
|
|
||||||
|
wp_set_current_user(1);
|
||||||
|
|
||||||
|
wp_delete_user($this->customer_id);
|
||||||
|
|
||||||
|
wp_delete_term(
|
||||||
|
$this->customer_organization_id,
|
||||||
|
Wiaas_User_Organization::TAXONOMY_NAME);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Wiaas_Order::assign_order_to_organization()
|
||||||
|
*/
|
||||||
|
function test_order_assigned_to_customer_organization() {
|
||||||
|
|
||||||
|
$organization_access_group = Groups_Group::read_by_name($this->customer_organization_name);
|
||||||
|
$access_group_ids = Groups_Post_Access::get_read_group_ids( $this->order_id );
|
||||||
|
|
||||||
|
$this->assertEquals(1, count($access_group_ids));
|
||||||
|
$this->assertNotNull($access_group_ids[0]);
|
||||||
|
$this->assertEquals($organization_access_group->group_id, $access_group_ids[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Wiaas_Order::check_order_access()
|
||||||
|
*/
|
||||||
|
function test_order_customer_can_access_order() {
|
||||||
|
|
||||||
|
$has_access = Wiaas_Order::check_order_access(true, 'view', $this->order_id, 'shop_order');
|
||||||
|
|
||||||
|
$this->assertTrue($has_access);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Wiaas_Order::check_order_access()
|
||||||
|
*/
|
||||||
|
function test_customer_cannot_access_order_when_not_in_organization() {
|
||||||
|
$customer_id = wc_create_new_customer(
|
||||||
|
'test_customer1@mail.com',
|
||||||
|
'test_customer1',
|
||||||
|
'test1');
|
||||||
|
wp_set_current_user($customer_id);
|
||||||
|
|
||||||
|
$this->assertTrue(Groups_Post_Access::handles_post_type('shop_order'));
|
||||||
|
|
||||||
|
$has_access = Wiaas_Order::check_order_access(true, 'view', $this->order_id, 'shop_order');
|
||||||
|
|
||||||
|
$this->assertFalse($has_access);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Wiaas_Order::wiaas_prepare_rest_orders_query()
|
||||||
|
*/
|
||||||
|
function test_valid_order_query_status_for_active_orders() {
|
||||||
|
$args = array();
|
||||||
|
$request = array(
|
||||||
|
'wiaas_is_active' => '1'
|
||||||
|
);
|
||||||
|
|
||||||
|
$args = Wiaas_Order::wiaas_prepare_rest_orders_query($args, $request);
|
||||||
|
|
||||||
|
$this->assertEquals(
|
||||||
|
array('wc-open', 'wc-processing'),
|
||||||
|
$args['post_status']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Wiaas_Order::wiaas_prepare_rest_orders_query()
|
||||||
|
*/
|
||||||
|
function test_valid_order_query_status_for_history_orders() {
|
||||||
|
$args = array();
|
||||||
|
$request = array(
|
||||||
|
'wiaas_is_active' => '0'
|
||||||
|
);
|
||||||
|
|
||||||
|
$args = Wiaas_Order::wiaas_prepare_rest_orders_query($args, $request);
|
||||||
|
|
||||||
|
$this->assertEquals(
|
||||||
|
array('wc-completed', 'wc-cancelled'),
|
||||||
|
$args['post_status']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Wiaas_Order::transform_rest_order()
|
||||||
|
*/
|
||||||
|
function test_order_rest_response_has_process() {
|
||||||
|
$order_response = array(
|
||||||
|
'customer_id' => $this->customer_id,
|
||||||
|
'status' => 'processing',
|
||||||
|
'line_items' => array()
|
||||||
|
);
|
||||||
|
$request = array( 'id' => $this->order_id);
|
||||||
|
|
||||||
|
$order_rest_response = new WP_REST_Response($order_response);
|
||||||
|
|
||||||
|
$order_rest_response = Wiaas_Order::transform_rest_order(
|
||||||
|
$order_rest_response,
|
||||||
|
wc_get_order($this->order_id),
|
||||||
|
$request);
|
||||||
|
|
||||||
|
$transformed_order_response = $order_rest_response->get_data();
|
||||||
|
|
||||||
|
$this->assertNotNull($transformed_order_response['delivery-process']);
|
||||||
|
$this->assertTrue(is_array($transformed_order_response['delivery-process']));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Wiaas_Order::transform_rest_order()
|
||||||
|
*/
|
||||||
|
function test_order_rest_response_has_customer_info() {
|
||||||
|
$order_response = array(
|
||||||
|
'customer_id' => $this->customer_id,
|
||||||
|
'status' => 'processing',
|
||||||
|
'line_items' => array()
|
||||||
|
);
|
||||||
|
|
||||||
|
$order_rest_response = Wiaas_Order::transform_rest_order(
|
||||||
|
new WP_REST_Response($order_response),
|
||||||
|
wc_get_order($this->order_id),
|
||||||
|
array( 'id' => $this->order_id));
|
||||||
|
|
||||||
|
$transformed_order_response = $order_rest_response->get_data();
|
||||||
|
|
||||||
|
$this->assertNotNull($transformed_order_response['customer']);
|
||||||
|
$this->assertTrue(is_array($transformed_order_response['customer']));
|
||||||
|
$this->assertArrayHasKey('name', $transformed_order_response['customer']);
|
||||||
|
$this->assertArrayHasKey('email', $transformed_order_response['customer']);
|
||||||
|
$this->assertArrayHasKey('phone', $transformed_order_response['customer']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Wiaas_Order::transform_rest_order()
|
||||||
|
*/
|
||||||
|
function test_order_rest_response_has_commercial_lead_info() {
|
||||||
|
$order_response = array(
|
||||||
|
'customer_id' => $this->customer_id,
|
||||||
|
'status' => 'processing',
|
||||||
|
'line_items' => array()
|
||||||
|
);
|
||||||
|
|
||||||
|
$order_rest_response = Wiaas_Order::transform_rest_order(
|
||||||
|
new WP_REST_Response($order_response),
|
||||||
|
wc_get_order($this->order_id),
|
||||||
|
array( 'id' => $this->order_id));
|
||||||
|
|
||||||
|
$transformed_order_response = $order_rest_response->get_data();
|
||||||
|
|
||||||
|
$this->assertNotNull($transformed_order_response['commercial_lead']);
|
||||||
|
$this->assertTrue(is_array($transformed_order_response['commercial_lead']));
|
||||||
|
$this->assertArrayHasKey('name', $transformed_order_response['commercial_lead']);
|
||||||
|
$this->assertArrayHasKey('email', $transformed_order_response['commercial_lead']);
|
||||||
|
$this->assertArrayHasKey('phone', $transformed_order_response['commercial_lead']);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -35,9 +35,6 @@ class Wiass_REST_Delivery_Process_Api_Test extends Wiaas_Unit_Test_Case {
|
|||||||
$this->assertNotNull($next_steps);
|
$this->assertNotNull($next_steps);
|
||||||
$this->assertTrue(is_array($next_steps));
|
$this->assertTrue(is_array($next_steps));
|
||||||
|
|
||||||
# check that administrator has one action pending
|
|
||||||
$this->assertEquals(sizeof($next_steps), 1);
|
|
||||||
|
|
||||||
$pending_step = $next_steps[0];
|
$pending_step = $next_steps[0];
|
||||||
|
|
||||||
$this->assertTrue(is_array($pending_step));
|
$this->assertTrue(is_array($pending_step));
|
||||||
|
|||||||
@@ -0,0 +1,174 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class Wiaas_User_Organization_Test
|
||||||
|
*
|
||||||
|
* @package Wiaas
|
||||||
|
*/
|
||||||
|
|
||||||
|
class Wiaas_User_Organization_Test extends Wiaas_Unit_Test_Case {
|
||||||
|
|
||||||
|
var $user_id, $user_organization_name, $user_organization_id, $user_department_name, $user_department_id;
|
||||||
|
|
||||||
|
public function setUp() {
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
|
# set admin as current user
|
||||||
|
wp_set_current_user(1);
|
||||||
|
|
||||||
|
# create testing user
|
||||||
|
$this->user_id = wp_create_user('test', 'test', 'test@mail.com');
|
||||||
|
$this->user_organization_name = 'test_organization';
|
||||||
|
|
||||||
|
$this->user_department_name = 'test_department';
|
||||||
|
|
||||||
|
# create organization
|
||||||
|
$this->user_organization_id = wp_insert_term(
|
||||||
|
$this->user_organization_name,
|
||||||
|
Wiaas_User_Organization::TAXONOMY_NAME
|
||||||
|
)['term_id'];
|
||||||
|
|
||||||
|
# create department
|
||||||
|
$this->user_department_id = wp_insert_term(
|
||||||
|
$this->user_department_name,
|
||||||
|
Wiaas_User_Organization::TAXONOMY_NAME,
|
||||||
|
array(
|
||||||
|
'parent' => $this->user_organization_id
|
||||||
|
)
|
||||||
|
)['term_id'];
|
||||||
|
|
||||||
|
# assign user to organization
|
||||||
|
wp_set_terms_for_user(
|
||||||
|
$this->user_id,
|
||||||
|
Wiaas_User_Organization::TAXONOMY_NAME,
|
||||||
|
[$this->user_organization_name]);
|
||||||
|
}
|
||||||
|
|
||||||
|
function tearDown() {
|
||||||
|
parent::tearDown();
|
||||||
|
|
||||||
|
wp_set_current_user(1);
|
||||||
|
|
||||||
|
wp_delete_user($this->user_id);
|
||||||
|
|
||||||
|
wp_delete_term(
|
||||||
|
$this->user_organization_id,
|
||||||
|
Wiaas_User_Organization::TAXONOMY_NAME);
|
||||||
|
wp_delete_term(
|
||||||
|
$this->user_department_id,
|
||||||
|
Wiaas_User_Organization::TAXONOMY_NAME);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Wiaas_User_Organization::get_user_organization()
|
||||||
|
*/
|
||||||
|
function test_retrieve_user_organization() {
|
||||||
|
$organization = Wiaas_User_Organization::get_user_organization($this->user_id);
|
||||||
|
|
||||||
|
$this->assertNotNull($organization);
|
||||||
|
$this->assertEquals($organization->term_id, $this->user_organization_id);
|
||||||
|
$this->assertEquals($organization->name, $this->user_organization_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Wiaas_User_Organization::on_organization_added()
|
||||||
|
*/
|
||||||
|
function test_access_group_created_when_organization_created() {
|
||||||
|
# check organization access group id saved as term metadata
|
||||||
|
$organization_access_group_id = get_term_meta($this->user_organization_id, 'group_id', true);
|
||||||
|
$this->assertNotNull($organization_access_group_id);
|
||||||
|
|
||||||
|
# check organization access group object exists
|
||||||
|
$organization_access_group = Groups_Group::read_by_name($this->user_organization_name);
|
||||||
|
$this->assertNotFalse($organization_access_group);
|
||||||
|
|
||||||
|
# check created access group object corresponds to this organization
|
||||||
|
$this->assertEquals($organization_access_group->name, $this->user_organization_name);
|
||||||
|
$this->assertEquals($organization_access_group->group_id, $organization_access_group_id);
|
||||||
|
|
||||||
|
# check department access group id saved as term metadata
|
||||||
|
$department_access_group_id = get_term_meta($this->user_department_id, 'group_id', true);
|
||||||
|
$this->assertNotNull($department_access_group_id);
|
||||||
|
|
||||||
|
# check department access group object exists
|
||||||
|
$department_access_group = Groups_Group::read_by_name($this->user_department_name);
|
||||||
|
$this->assertNotFalse($department_access_group);
|
||||||
|
|
||||||
|
# check created access group object corresponds to this department
|
||||||
|
$this->assertEquals($department_access_group->name, $this->user_department_name);
|
||||||
|
$this->assertEquals($department_access_group->group_id, $department_access_group_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Wiaas_User_Organization::on_taxonomy_term_assigned()
|
||||||
|
*/
|
||||||
|
function test_user_added_to_organization_access_groups() {
|
||||||
|
# check user added to organization access group
|
||||||
|
$organization_access_group = Groups_Group::read_by_name($this->user_organization_name);
|
||||||
|
$user_group_relation = Groups_User_Group::read( $this->user_id , $organization_access_group->group_id );
|
||||||
|
|
||||||
|
$this->assertNotFalse($user_group_relation);
|
||||||
|
$this->assertEquals($user_group_relation->user_id, $this->user_id);
|
||||||
|
$this->assertEquals($user_group_relation->group_id, $organization_access_group->group_id);
|
||||||
|
|
||||||
|
# test user added to department access group
|
||||||
|
$department_access_group = Groups_Group::read_by_name($this->user_department_name);
|
||||||
|
$user_group_relation = Groups_User_Group::read( $this->user_id , $department_access_group->group_id );
|
||||||
|
|
||||||
|
$this->assertNotFalse($user_group_relation);
|
||||||
|
$this->assertEquals($user_group_relation->user_id, $this->user_id);
|
||||||
|
$this->assertEquals($user_group_relation->group_id, $department_access_group->group_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Wiaas_User_Organization::on_taxonomy_term_will_be_deleted()
|
||||||
|
*/
|
||||||
|
function test_access_group_deleted_when_organization_deleted() {
|
||||||
|
wp_delete_term($this->user_organization_id, Wiaas_User_Organization::TAXONOMY_NAME);
|
||||||
|
|
||||||
|
$organization_access_group = Groups_Group::read_by_name($this->user_organization_name);
|
||||||
|
$this->assertFalse($organization_access_group);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Wiaas_User_Organization::on_taxonomy_term_unassigned()
|
||||||
|
*/
|
||||||
|
function test_user_removed_from_organization_access_groups() {
|
||||||
|
# remove user from organization
|
||||||
|
wp_set_terms_for_user($this->user_id, Wiaas_User_Organization::TAXONOMY_NAME, null);
|
||||||
|
|
||||||
|
# check user removed from organization access group
|
||||||
|
$organization_access_group = Groups_Group::read_by_name($this->user_organization_name);
|
||||||
|
$user_group_relation = Groups_User_Group::read( $this->user_id , $organization_access_group->group_id );
|
||||||
|
|
||||||
|
$this->assertFalse($user_group_relation);
|
||||||
|
|
||||||
|
# check user removed from department access group
|
||||||
|
$department_access_group = Groups_Group::read_by_name($this->user_department_name);
|
||||||
|
$user_group_relation = Groups_User_Group::read( $this->user_id , $department_access_group->group_id );
|
||||||
|
|
||||||
|
$this->assertFalse($user_group_relation);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Wiaas_User_Organization::assign_post_to_user_organization()
|
||||||
|
*/
|
||||||
|
function test_post_assigned_to_user_organization() {
|
||||||
|
$post_id = wp_insert_post(array(
|
||||||
|
'post_title' => 'Test',
|
||||||
|
'post_content' => 'Test',
|
||||||
|
'post_excerpt' => 'Test'
|
||||||
|
), true);
|
||||||
|
|
||||||
|
Wiaas_User_Organization::assign_post_to_user_organization($post_id, $this->user_id);
|
||||||
|
|
||||||
|
$organization_access_group = Groups_Group::read_by_name($this->user_organization_name);
|
||||||
|
|
||||||
|
$access_group_ids = Groups_Post_Access::get_read_group_ids( $post_id );
|
||||||
|
|
||||||
|
# check post added to organization access group
|
||||||
|
$this->assertEquals(1, count($access_group_ids));
|
||||||
|
$this->assertNotNull($access_group_ids[0]);
|
||||||
|
$this->assertEquals($organization_access_group->group_id, $access_group_ids[0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -13,5 +13,11 @@ class Wiaas_Unit_Test_Case extends WP_UnitTestCase {
|
|||||||
gf_upgrade()->install();
|
gf_upgrade()->install();
|
||||||
|
|
||||||
wiaas_db_update_setup_gravity();
|
wiaas_db_update_setup_gravity();
|
||||||
|
|
||||||
|
wiaas_db_update_enable_orders_access_management();
|
||||||
|
}
|
||||||
|
|
||||||
|
function tearDown() {
|
||||||
|
parent::tearDown();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -26,4 +26,6 @@ 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-order.php';
|
||||||
|
|
||||||
|
include_once WIAAS_DIR . '/includes/class-wiaas-user.php';
|
||||||
|
|
||||||
include_once WIAAS_DIR . '/includes/class-wiaas-api.php';
|
include_once WIAAS_DIR . '/includes/class-wiaas-api.php';
|
||||||
|
|||||||
@@ -48,6 +48,7 @@
|
|||||||
"wpackagist-plugin/woocommerce-gateway-paypal-express-checkout": "1.5.6",
|
"wpackagist-plugin/woocommerce-gateway-paypal-express-checkout": "1.5.6",
|
||||||
"wpackagist-plugin/jwt-authentication-for-wp-rest-api": "1.2.4",
|
"wpackagist-plugin/jwt-authentication-for-wp-rest-api": "1.2.4",
|
||||||
"wpackagist-plugin/capability-manager-enhanced": "1.5.9",
|
"wpackagist-plugin/capability-manager-enhanced": "1.5.9",
|
||||||
|
"wpackagist-plugin/wp-user-groups": "2.2.0",
|
||||||
|
|
||||||
"3rdparty/gravityforms": "*",
|
"3rdparty/gravityforms": "*",
|
||||||
"3rdparty/gravityflow": "*"
|
"3rdparty/gravityflow": "*"
|
||||||
@@ -77,6 +78,8 @@
|
|||||||
"wp plugin activate gravityforms",
|
"wp plugin activate gravityforms",
|
||||||
"wp plugin activate gravityflow",
|
"wp plugin activate gravityflow",
|
||||||
"wp plugin activate capability-manager-enhanced",
|
"wp plugin activate capability-manager-enhanced",
|
||||||
|
"wp plugin activate groups",
|
||||||
|
"wp plugin activate wp-user-groups",
|
||||||
"wp plugin activate wiaas"
|
"wp plugin activate wiaas"
|
||||||
],
|
],
|
||||||
"update-db": [
|
"update-db": [
|
||||||
|
|||||||
24
backend/composer.lock
generated
24
backend/composer.lock
generated
@@ -1,10 +1,10 @@
|
|||||||
{
|
{
|
||||||
"_readme": [
|
"_readme": [
|
||||||
"This file locks the dependencies of your project to a known state",
|
"This file locks the dependencies of your project to a known state",
|
||||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
|
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||||
"This file is @generated automatically"
|
"This file is @generated automatically"
|
||||||
],
|
],
|
||||||
"content-hash": "dca54e67b0185da192f5260baa4c162e",
|
"content-hash": "798e9b8b675248e2b8dbc2bc7dcab511",
|
||||||
"packages": [
|
"packages": [
|
||||||
{
|
{
|
||||||
"name": "3rdparty/gravityflow",
|
"name": "3rdparty/gravityflow",
|
||||||
@@ -596,6 +596,26 @@
|
|||||||
},
|
},
|
||||||
"type": "wordpress-plugin",
|
"type": "wordpress-plugin",
|
||||||
"homepage": "https://wordpress.org/plugins/woocommerce-jetpack/"
|
"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": [
|
"packages-dev": [
|
||||||
|
|||||||
@@ -19,6 +19,8 @@ wp plugin activate jwt-authentication-for-wp-rest-api --allow-root
|
|||||||
wp plugin activate wiaas --allow-root
|
wp plugin activate wiaas --allow-root
|
||||||
wp plugin activate gravityforms --allow-root
|
wp plugin activate gravityforms --allow-root
|
||||||
wp plugin activate gravityflow --allow-root
|
wp plugin activate gravityflow --allow-root
|
||||||
|
wp plugin activate capability-manager-enhanced --allow-root
|
||||||
|
wp plugin activate wp-user-groups --allow-root
|
||||||
|
|
||||||
# Execute database update for updated plugins
|
# Execute database update for updated plugins
|
||||||
# (if no changes detected command will do nothing)
|
# (if no changes detected command will do nothing)
|
||||||
|
|||||||
6236
frontend/package-lock.json
generated
6236
frontend/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -23,7 +23,7 @@ export const fetchOrders = (viewAllOrders) => {
|
|||||||
return dispatch => {
|
return dispatch => {
|
||||||
dispatch(requestOrders());
|
dispatch(requestOrders());
|
||||||
return htmlClient.fetch({
|
return htmlClient.fetch({
|
||||||
url: `${API_SERVER}/wp-json/wc/v2/orders?per_page=${MAX_ORDER_COUNT}`,
|
url: `${API_SERVER}/wp-json/wc/v2/orders?per_page=${MAX_ORDER_COUNT}&wiaas_is_active=1`,
|
||||||
method: 'get',
|
method: 'get',
|
||||||
})
|
})
|
||||||
.then(response => {
|
.then(response => {
|
||||||
|
|||||||
@@ -7,13 +7,14 @@ import {
|
|||||||
RECEIVE_HISTORY_ORDERS,
|
RECEIVE_HISTORY_ORDERS,
|
||||||
SET_VIEW_ALL_ORDERS
|
SET_VIEW_ALL_ORDERS
|
||||||
} from '../../constants/ordersConstants';
|
} from '../../constants/ordersConstants';
|
||||||
|
import {fromWCOrder} from '../../helpers/OrderHelper';
|
||||||
const htmlClient = new HtmlClient();
|
const htmlClient = new HtmlClient();
|
||||||
|
|
||||||
const requestActiveOrders = () => ({
|
const requestActiveOrders = () => ({
|
||||||
type: REQUEST_ACTIVE_ORDERS,
|
type: REQUEST_ACTIVE_ORDERS,
|
||||||
isLoading: true
|
isLoading: true
|
||||||
});
|
});
|
||||||
const recieveActiveOrders = (json) => ({
|
const receiveActiveOrders = (json) => ({
|
||||||
type: RECEIVE_ACTIVE_ORDERS,
|
type: RECEIVE_ACTIVE_ORDERS,
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
activeOrders: json
|
activeOrders: json
|
||||||
@@ -23,12 +24,10 @@ export const getActiveOrders = () => {
|
|||||||
return dispatch => {
|
return dispatch => {
|
||||||
dispatch(requestActiveOrders());
|
dispatch(requestActiveOrders());
|
||||||
return htmlClient.fetch({
|
return htmlClient.fetch({
|
||||||
url: `${API_SERVER}/orders/api/getActiveOrders`
|
url: `${API_SERVER}/wp-json/wc/v2/orders?wiaas_is_active=1`
|
||||||
})
|
})
|
||||||
.then(response => {
|
.then(response => {
|
||||||
if (typeof response.data !== 'undefined' && 'orders' in response.data) {
|
dispatch(receiveActiveOrders(response.data.map(wcOrder => fromWCOrder(wcOrder))));
|
||||||
dispatch(recieveActiveOrders(response.data.orders));
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
htmlClient.onError(error, dispatch);
|
htmlClient.onError(error, dispatch);
|
||||||
@@ -50,12 +49,10 @@ export const getHistoryOrders = () => {
|
|||||||
return dispatch => {
|
return dispatch => {
|
||||||
dispatch(requestHistoryOrders());
|
dispatch(requestHistoryOrders());
|
||||||
return htmlClient.fetch({
|
return htmlClient.fetch({
|
||||||
url: `${API_SERVER}/orders/api/getHistoryOrders`
|
url: `${API_SERVER}/wp-json/wc/v2/orders?wiaas_is_active=0`
|
||||||
})
|
})
|
||||||
.then(response => {
|
.then(response => {
|
||||||
if (typeof response.data !== 'undefined' && 'orders' in response.data) {
|
dispatch(recieveHistoryOrders(response.data.map(wcOrder => fromWCOrder(wcOrder))));
|
||||||
dispatch(recieveHistoryOrders(response.data.orders));
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
htmlClient.onError(error, dispatch);
|
htmlClient.onError(error, dispatch);
|
||||||
|
|||||||
@@ -186,10 +186,10 @@ export const orderTexts = {
|
|||||||
},
|
},
|
||||||
statuses: {
|
statuses: {
|
||||||
open: 'Open',
|
open: 'Open',
|
||||||
'in-progress': 'In Progress',
|
'processing': 'In progress',
|
||||||
production: 'Completed',
|
completed: 'Completed',
|
||||||
'end-of-life': 'Completed',
|
'end-of-life': 'Completed',
|
||||||
canceled: 'Canceled',
|
cancelled: 'Cancelled',
|
||||||
'not-accepted': 'Not Accepted',
|
'not-accepted': 'Not Accepted',
|
||||||
invalid: 'Invalid',
|
invalid: 'Invalid',
|
||||||
pending: 'Pending'
|
pending: 'Pending'
|
||||||
|
|||||||
@@ -14,31 +14,16 @@ const type = 'overview';
|
|||||||
class OrderCentralContainer extends Component {
|
class OrderCentralContainer extends Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
|
|
||||||
this.state = {
|
|
||||||
orders: [],
|
|
||||||
isViewAllOrdersChecked: false
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
this.props.dispatch(fetchOrders());
|
this.props.dispatch(fetchOrders());
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillReceiveProps(nextProps) {
|
|
||||||
if(nextProps.isViewAllOrdersChecked[type] !== this.state.isViewAllOrdersChecked) {
|
|
||||||
this.setState({
|
|
||||||
isViewAllOrdersChecked: nextProps.isViewAllOrdersChecked[type] || false
|
|
||||||
});
|
|
||||||
this.props.dispatch(fetchOrders(nextProps.isViewAllOrdersChecked[type]));
|
|
||||||
}
|
|
||||||
this.setState({
|
|
||||||
orders: nextProps.orders
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const {isLoading} = this.props;
|
const {isLoading, isViewAllOrdersChecked} = this.props;
|
||||||
|
const viewAllOrders = isViewAllOrdersChecked && isViewAllOrdersChecked[type];
|
||||||
|
const orders = viewAllOrders ? this.props.orders : this.props.orders.filter(o => o.isMyOrder);
|
||||||
|
|
||||||
return (<Col xl="8" lg="8" md="12" sm="12" xs="12">
|
return (<Col xl="8" lg="8" md="12" sm="12" xs="12">
|
||||||
<WiaasBox id="order-central-gadget" mainTitle={dashboardTexts.labels.ORDER_CENTRAL} customHeader={OrderListHeader} customHeaderParams={type}>
|
<WiaasBox id="order-central-gadget" mainTitle={dashboardTexts.labels.ORDER_CENTRAL} customHeader={OrderListHeader} customHeaderParams={type}>
|
||||||
@@ -49,8 +34,8 @@ class OrderCentralContainer extends Component {
|
|||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
(this.state.orders && this.state.orders.length > 0 && !isLoading) ?
|
(orders.length > 0 && !isLoading) ?
|
||||||
<OrdersList orders={this.state.orders} isViewAllOrdersChecked={this.props.isViewAllOrdersChecked[type]}/> :
|
<OrdersList orders={orders} showOrderCustomer={viewAllOrders}/> :
|
||||||
<div className="dashborad-message">
|
<div className="dashborad-message">
|
||||||
<Link to='/co-market'>{dashboardTexts.labels.NO_ORDERS}</Link>
|
<Link to='/co-market'>{dashboardTexts.labels.NO_ORDERS}</Link>
|
||||||
</div>
|
</div>
|
||||||
@@ -61,7 +46,7 @@ class OrderCentralContainer extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const mapStateToProps = (state) => ({
|
const mapStateToProps = (state) => ({
|
||||||
orders: state.ordersCentralReducer.orders,
|
orders: state.ordersCentralReducer.orders || [],
|
||||||
isLoading: state.ordersCentralReducer.isLoading,
|
isLoading: state.ordersCentralReducer.isLoading,
|
||||||
isViewAllOrdersChecked: state.ordersReducer.isViewAllOrdersChecked
|
isViewAllOrdersChecked: state.ordersReducer.isViewAllOrdersChecked
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import {dashboardTexts} from '../../../constants/dashboardConstants';
|
|||||||
|
|
||||||
class OrderItem extends Component {
|
class OrderItem extends Component {
|
||||||
render() {
|
render() {
|
||||||
const {order, isViewAllOrdersChecked} = this.props;
|
const {order, showOrderCustomer} = this.props;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<WiaasTableRow className={'order-central-row line-' + order.status}>
|
<WiaasTableRow className={'order-central-row line-' + order.status}>
|
||||||
@@ -16,8 +16,8 @@ class OrderItem extends Component {
|
|||||||
</WiaasTableCol>
|
</WiaasTableCol>
|
||||||
<WiaasTableCol header={dashboardTexts.tableHeaders.ORDER_DATE}>{order.dateCreated}</WiaasTableCol>
|
<WiaasTableCol header={dashboardTexts.tableHeaders.ORDER_DATE}>{order.dateCreated}</WiaasTableCol>
|
||||||
{
|
{
|
||||||
isViewAllOrdersChecked &&
|
showOrderCustomer &&
|
||||||
<WiaasTableCol header={dashboardTexts.tableHeaders.PLACED_BY}>{order.placedBy}</WiaasTableCol>
|
<WiaasTableCol header={dashboardTexts.tableHeaders.PLACED_BY}>{order.customer ? order.customer.name : ''}</WiaasTableCol>
|
||||||
}
|
}
|
||||||
<WiaasTableCol header={dashboardTexts.tableHeaders.REFERENCE}>{order.reference}</WiaasTableCol>
|
<WiaasTableCol header={dashboardTexts.tableHeaders.REFERENCE}>{order.reference}</WiaasTableCol>
|
||||||
<WiaasTableCol header={dashboardTexts.tableHeaders.ON_DELIVERY}>{order.fixedPrice.toLocaleString()} {order.currency}</WiaasTableCol>
|
<WiaasTableCol header={dashboardTexts.tableHeaders.ON_DELIVERY}>{order.fixedPrice.toLocaleString()} {order.currency}</WiaasTableCol>
|
||||||
|
|||||||
@@ -8,13 +8,13 @@ class OrdersList extends Component {
|
|||||||
super(props);
|
super(props);
|
||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
isViewAllOrdersChecked: this.props.isViewAllOrdersChecked || false
|
showOrderCustomer: this.props.showOrderCustomer || false
|
||||||
};
|
};
|
||||||
this.getHeaderForOrders = this.getHeaderForOrders.bind(this);
|
this.getHeaderForOrders = this.getHeaderForOrders.bind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillReceiveProps(nextProps) {
|
componentWillReceiveProps(nextProps) {
|
||||||
this.setState({isViewAllOrdersChecked: nextProps.isViewAllOrdersChecked});
|
this.setState({showOrderCustomer: nextProps.showOrderCustomer});
|
||||||
}
|
}
|
||||||
|
|
||||||
getHeaderForOrders() {
|
getHeaderForOrders() {
|
||||||
@@ -27,7 +27,7 @@ class OrdersList extends Component {
|
|||||||
dashboardTexts.tableHeaders.STATUS,
|
dashboardTexts.tableHeaders.STATUS,
|
||||||
''
|
''
|
||||||
];
|
];
|
||||||
if(this.state.isViewAllOrdersChecked) {
|
if(this.state.showOrderCustomer) {
|
||||||
headers.splice(2, 0, dashboardTexts.tableHeaders.PLACED_BY);
|
headers.splice(2, 0, dashboardTexts.tableHeaders.PLACED_BY);
|
||||||
headers.join();
|
headers.join();
|
||||||
}
|
}
|
||||||
@@ -36,7 +36,7 @@ class OrdersList extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const {orders, isViewAllOrdersChecked} = this.props;
|
const {orders, showOrderCustomer} = this.props;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
@@ -46,7 +46,7 @@ class OrdersList extends Component {
|
|||||||
{
|
{
|
||||||
orders &&
|
orders &&
|
||||||
orders.map((order, index) =>
|
orders.map((order, index) =>
|
||||||
<OrderItem key={'order-' + order.number} order={order} isViewAllOrdersChecked={isViewAllOrdersChecked}/>
|
<OrderItem key={'order-' + order.number} order={order} showOrderCustomer={showOrderCustomer}/>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
</WiaasTableBody>
|
</WiaasTableBody>
|
||||||
|
|||||||
@@ -12,16 +12,14 @@ class OrdersDataContainer extends Component {
|
|||||||
this.props.dispatch(getActiveOrders());
|
this.props.dispatch(getActiveOrders());
|
||||||
this.props.dispatch(getHistoryOrders());
|
this.props.dispatch(getHistoryOrders());
|
||||||
}
|
}
|
||||||
|
|
||||||
checkIfOrdersExistForUser(orders) {
|
|
||||||
return orders.every((order) => {
|
|
||||||
return 'isMyOrder' in order && !order.isMyOrder;
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const {activeOrders, historyOrders, type, isLoading} = this.props;
|
const {activeOrders, historyOrders, type, isLoading, isViewAllOrdersChecked} = this.props;
|
||||||
const orders = type ? type === 'active' ? activeOrders : historyOrders : {};
|
let orders = type ? type === 'active' ? activeOrders : historyOrders : [];
|
||||||
|
const viewAllOrders = isViewAllOrdersChecked && isViewAllOrdersChecked[type];
|
||||||
|
if (!viewAllOrders) {
|
||||||
|
// show only current customer orders
|
||||||
|
orders = orders.filter(o => o.isMyOrder);
|
||||||
|
}
|
||||||
const mainTitleOrder = type.charAt(0).toUpperCase() + type.slice(1);
|
const mainTitleOrder = type.charAt(0).toUpperCase() + type.slice(1);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -35,10 +33,10 @@ class OrdersDataContainer extends Component {
|
|||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
{ (orders && !isLoading) &&
|
{ (orders && !isLoading) &&
|
||||||
<OrderList orders={orders} type={type}/>
|
<OrderList orders={orders} type={type} showOrderCustomer={viewAllOrders}/>
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
((orders && orders.length === 0 && !isLoading) || (orders && this.checkIfOrdersExistForUser(orders))) &&
|
!isLoading && orders.length === 0 &&
|
||||||
<Alert color="info">{orderTexts.labels.NO_RECORDS}</Alert>
|
<Alert color="info">{orderTexts.labels.NO_RECORDS}</Alert>
|
||||||
}
|
}
|
||||||
</WiaasBox>
|
</WiaasBox>
|
||||||
@@ -49,9 +47,10 @@ class OrdersDataContainer extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const mapStateToProps = (state) => ({
|
const mapStateToProps = (state) => ({
|
||||||
activeOrders: state.ordersReducer.activeOrders,
|
activeOrders: state.ordersReducer.activeOrders || [],
|
||||||
historyOrders: state.ordersReducer.historyOrders,
|
historyOrders: state.ordersReducer.historyOrders || [],
|
||||||
isLoading: state.ordersReducer.isLoading
|
isLoading: state.ordersReducer.isLoading,
|
||||||
|
isViewAllOrdersChecked: state.ordersReducer.isViewAllOrdersChecked,
|
||||||
});
|
});
|
||||||
|
|
||||||
export default connect(mapStateToProps)(OrdersDataContainer);
|
export default connect(mapStateToProps)(OrdersDataContainer);
|
||||||
|
|||||||
@@ -1,77 +0,0 @@
|
|||||||
import React, {Component} from 'react';
|
|
||||||
import {connect} from 'react-redux';
|
|
||||||
import {WiaasTableRow, WiaasTableCol} from '../../../mainComponents/table/WiaasTable.jsx';
|
|
||||||
import {orderTexts} from '../../../constants/ordersConstants';
|
|
||||||
import '../style/Orders.css';
|
|
||||||
import OrderPackage from './OrderPackage.jsx';
|
|
||||||
import HistoryOrderButtons from './HistoryOrderButtons.jsx';
|
|
||||||
|
|
||||||
class HistoryOrdersItem extends Component {
|
|
||||||
constructor(props) {
|
|
||||||
super(props);
|
|
||||||
|
|
||||||
this.state = {
|
|
||||||
showPackages: false
|
|
||||||
};
|
|
||||||
|
|
||||||
this.toggle = this.toggle.bind(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
toggle() {
|
|
||||||
this.setState({
|
|
||||||
showPackages: !this.state.showPackages
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
getIconClass(type) {
|
|
||||||
return 'fa fa-angle-' + type + ' toggle-view-packages';
|
|
||||||
}
|
|
||||||
|
|
||||||
render() {
|
|
||||||
const {order, isViewAllOrdersChecked} = this.props;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div>
|
|
||||||
<WiaasTableRow className={"order-central-row order-border-" + order.status}>
|
|
||||||
<WiaasTableCol header="#">
|
|
||||||
{!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>
|
|
||||||
</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>
|
|
||||||
<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>
|
|
||||||
</div>
|
|
||||||
</WiaasTableCol>
|
|
||||||
<WiaasTableCol header={orderTexts.labels.AMOUNT}>
|
|
||||||
{order.orderCurrency && order.orderCurrency.currency
|
|
||||||
? order.orderTotalPrice.toLocaleString() + ' ' + order.orderCurrency.currency
|
|
||||||
: parseFloat(order.orderTotalPrice).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="Buttons details">
|
|
||||||
<HistoryOrderButtons order={order}/>
|
|
||||||
</WiaasTableCol>
|
|
||||||
</WiaasTableRow>
|
|
||||||
{ this.state.showPackages && <OrderPackage order={order} type="history"/> }
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const mapStateToProps = (state) => ({
|
|
||||||
isViewAllOrdersChecked: state.ordersReducer.isViewAllOrdersChecked
|
|
||||||
});
|
|
||||||
export default connect(mapStateToProps)(HistoryOrdersItem);
|
|
||||||
@@ -1,7 +1,5 @@
|
|||||||
import React, {Component} from 'react';
|
import React, {Component} from 'react';
|
||||||
import {connect} from 'react-redux';
|
import OrderListItem from './OrderListItem.jsx';
|
||||||
import ActiveOrderItem from './ActiveOrderItem.jsx';
|
|
||||||
import HistoryOrderItem from './HistoryOrderItem.jsx';
|
|
||||||
import {WiaasTable, WiaasTableHeader, WiaasTableBody} from '../../../mainComponents/table/WiaasTable.jsx';
|
import {WiaasTable, WiaasTableHeader, WiaasTableBody} from '../../../mainComponents/table/WiaasTable.jsx';
|
||||||
import {orderTexts} from '../../../constants/ordersConstants';
|
import {orderTexts} from '../../../constants/ordersConstants';
|
||||||
|
|
||||||
@@ -35,7 +33,7 @@ class OrderList extends Component {
|
|||||||
''
|
''
|
||||||
];
|
];
|
||||||
|
|
||||||
if(this.props.isCompanyAdmin && this.props.isViewAllOrdersChecked[type]) {
|
if(this.props.showOrderCustomer) {
|
||||||
activeOrdersHeader.splice(2, 0, orderTexts.headers.PLACED_BY);
|
activeOrdersHeader.splice(2, 0, orderTexts.headers.PLACED_BY);
|
||||||
activeOrdersHeader.join();
|
activeOrdersHeader.join();
|
||||||
historyOrdersHeader.splice(2, 0, orderTexts.headers.PLACED_BY);
|
historyOrdersHeader.splice(2, 0, orderTexts.headers.PLACED_BY);
|
||||||
@@ -46,8 +44,7 @@ class OrderList extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const {orders, type, isCompanyAdmin, isViewAllOrdersChecked} = this.props;
|
const {orders, type} = this.props;
|
||||||
const TagName = type && type === 'active' ? ActiveOrderItem : HistoryOrderItem;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
@@ -55,11 +52,7 @@ class OrderList extends Component {
|
|||||||
<WiaasTableHeader headers={this.getHeadersByType(type)}/>
|
<WiaasTableHeader headers={this.getHeadersByType(type)}/>
|
||||||
<WiaasTableBody>
|
<WiaasTableBody>
|
||||||
{
|
{
|
||||||
orders &&
|
orders.map(order => <OrderListItem key={order.id} order={order} type={type} />)
|
||||||
orders.map((order, index) =>
|
|
||||||
(('isMyOrder' in order && order.isMyOrder) || (isCompanyAdmin && isViewAllOrdersChecked[type])) &&
|
|
||||||
<TagName key={order.orderNumber} order={order} />
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
</WiaasTableBody>
|
</WiaasTableBody>
|
||||||
</WiaasTable>
|
</WiaasTable>
|
||||||
@@ -67,9 +60,4 @@ class OrderList extends Component {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
export default OrderList;
|
||||||
const mapStateToProps = (state) => ({
|
|
||||||
isCompanyAdmin: state.auth.isCompanyAdmin,
|
|
||||||
isViewAllOrdersChecked: state.ordersReducer.isViewAllOrdersChecked
|
|
||||||
});
|
|
||||||
export default connect(mapStateToProps)(OrderList);
|
|
||||||
|
|||||||
@@ -51,6 +51,6 @@ class OrderListHeader extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const mapStateToProps = (state) => ({
|
const mapStateToProps = (state) => ({
|
||||||
isCompanyAdmin: state.auth.isCompanyAdmin
|
isCompanyAdmin: true//state.auth.isCompanyAdmin
|
||||||
});
|
});
|
||||||
export default connect(mapStateToProps)(OrderListHeader);
|
export default connect(mapStateToProps)(OrderListHeader);
|
||||||
|
|||||||
@@ -6,8 +6,9 @@ import {WiaasTableRow, WiaasTableCol} from '../../../mainComponents/table/WiaasT
|
|||||||
import {orderTexts} from '../../../constants/ordersConstants';
|
import {orderTexts} from '../../../constants/ordersConstants';
|
||||||
import '../style/Orders.css';
|
import '../style/Orders.css';
|
||||||
import OrderPackage from './OrderPackage.jsx';
|
import OrderPackage from './OrderPackage.jsx';
|
||||||
|
import HistoryOrderButtons from './HistoryOrderButtons.jsx';
|
||||||
|
|
||||||
class ActiveOrderItem extends Component {
|
class OrderListItem extends Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
this.state = {
|
this.state = {
|
||||||
@@ -29,6 +30,16 @@ class ActiveOrderItem extends Component {
|
|||||||
|
|
||||||
render() {
|
render() {
|
||||||
const {order, isViewAllOrdersChecked} = this.props;
|
const {order, isViewAllOrdersChecked} = this.props;
|
||||||
|
const isActive = this.props.type === 'active';
|
||||||
|
|
||||||
|
let orderButtons;
|
||||||
|
if (isActive) {
|
||||||
|
orderButtons = ( <Link to={'/orders/' + order.id} className="actions-link">
|
||||||
|
<Button color="secondary" className="actions-button">{orderTexts.buttons.DELIVERY_DETAILS}</Button>
|
||||||
|
</Link>);
|
||||||
|
} else {
|
||||||
|
orderButtons = <HistoryOrderButtons order={order}/>;
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
@@ -37,37 +48,40 @@ 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('down')} aria-hidden="true" onClick={this.toggle}></i>}
|
||||||
{this.state.showPackages && <i className={this.getIconClass('up')} 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" />
|
<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>
|
||||||
<WiaasTableCol header={orderTexts.labels.REFERENCE}>{order.reference ? order.reference : '-'}</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[this.props.type] &&
|
||||||
|
<WiaasTableCol header={orderTexts.labels.PLACED_BY}>{order.customer ? order.customer.name : ''}</WiaasTableCol>
|
||||||
|
}
|
||||||
|
<WiaasTableCol header={orderTexts.labels.ORDER_DATE}>{order.dateCreated ? order.dateCreated : '-'}</WiaasTableCol>
|
||||||
<WiaasTableCol header={orderTexts.labels.EST_DELIVERY}>{order.estimatedDeliveryDate ? order.estimatedDeliveryDate : '-'}</WiaasTableCol>
|
<WiaasTableCol header={orderTexts.labels.EST_DELIVERY}>{order.estimatedDeliveryDate ? order.estimatedDeliveryDate : '-'}</WiaasTableCol>
|
||||||
<WiaasTableCol header="Catalogue">
|
<WiaasTableCol header="Catalogue">
|
||||||
<div className="order-item-cl">
|
<div className="order-item-cl">
|
||||||
<img className="cl-photo" src="static/img/man-icon.png" alt="Catalogue" />
|
<img className="cl-photo" src="static/img/man-icon.png" alt="Catalogue" />
|
||||||
<div className="cl-details">
|
<div className="cl-details">
|
||||||
<div className="cl-contact-name">{order.clContactName}</div>
|
<div className="cl-contact-name">{order.commercialLead ? order.commercialLead.contact : ''}</div>
|
||||||
<div className="cl-name">{order.clName}</div>
|
<div className="cl-name">{order.commercialLead ? order.commercialLead.name : ''}</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</WiaasTableCol>
|
</WiaasTableCol>
|
||||||
<WiaasTableCol header={orderTexts.labels.AMOUNT}>
|
<WiaasTableCol header={orderTexts.labels.AMOUNT}>
|
||||||
{order.orderCurrency && order.orderCurrency.currency
|
{order.currency
|
||||||
? order.orderTotalPrice.toLocaleString() + ' ' + order.orderCurrency.currency
|
? order.fixedPrice.toLocaleString() + ' ' + order.currency
|
||||||
: parseFloat(order.orderTotalPrice).toLocaleString()}
|
: parseFloat(order.fixedPrice).toLocaleString()}
|
||||||
</WiaasTableCol>
|
</WiaasTableCol>
|
||||||
<WiaasTableCol header={orderTexts.labels.STATUS}>
|
<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>
|
||||||
|
{
|
||||||
|
!isActive && <WiaasTableCol header="End of life">{order.dateCompleted}</WiaasTableCol>
|
||||||
|
}
|
||||||
<WiaasTableCol header="Buttons details">
|
<WiaasTableCol header="Buttons details">
|
||||||
<Link to={'/orders/' + order.id} className="actions-link">
|
{orderButtons}
|
||||||
<Button color="secondary" className="actions-button">{orderTexts.buttons.DELIVERY_DETAILS}</Button>
|
|
||||||
</Link>
|
|
||||||
|
|
||||||
</WiaasTableCol>
|
</WiaasTableCol>
|
||||||
</WiaasTableRow>
|
</WiaasTableRow>
|
||||||
{ this.state.showPackages && <OrderPackage order={order} type="active"/> }
|
{ this.state.showPackages && <OrderPackage order={order} type={this.props.type}/> }
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -76,4 +90,4 @@ class ActiveOrderItem extends Component {
|
|||||||
const mapStateToProps = (state) => ({
|
const mapStateToProps = (state) => ({
|
||||||
isViewAllOrdersChecked: state.ordersReducer.isViewAllOrdersChecked
|
isViewAllOrdersChecked: state.ordersReducer.isViewAllOrdersChecked
|
||||||
});
|
});
|
||||||
export default connect(mapStateToProps)(ActiveOrderItem);
|
export default connect(mapStateToProps)(OrderListItem);
|
||||||
@@ -36,19 +36,19 @@ class OrderPackage extends Component {
|
|||||||
</WiaasTableRow>
|
</WiaasTableRow>
|
||||||
<WiaasTableRow id={'phone-' + order.id}>
|
<WiaasTableRow id={'phone-' + order.id}>
|
||||||
<Col lg="4" sm="4" xs="4">{orderTexts.labels.PHONE_NUMBER}:</Col>
|
<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>
|
||||||
<WiaasTableRow id={'mail-' + order.id}>
|
<WiaasTableRow id={'mail-' + order.id}>
|
||||||
<Col lg="4" sm="4" xs="4">{orderTexts.labels.MAIL}:</Col>
|
<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>
|
||||||
<WiaasTableRow id={'commercial-lead-phone-' + order.id}>
|
<WiaasTableRow id={'commercial-lead-phone-' + order.id}>
|
||||||
<Col lg="4" sm="4" xs="4">{order.clName} {orderTexts.labels.PHONE_NUMBER}:</Col>
|
<Col lg="4" sm="4" xs="4">{order.commercialLead ? order.commercialLead.name : ''} {orderTexts.labels.PHONE_NUMBER}:</Col>
|
||||||
<Col lg="8" sm="8" xs="8">{order.commercialLeadPhone}</Col>
|
<Col lg="8" sm="8" xs="8">{order.commercialLead ? order.commercialLead.phone : ''}</Col>
|
||||||
</WiaasTableRow>
|
</WiaasTableRow>
|
||||||
<WiaasTableRow id={'mail-' + order.id}>
|
<WiaasTableRow id={'mail-' + order.id}>
|
||||||
<Col lg="4" sm="4" xs="4">{order.clName} {orderTexts.labels.MAIL}:</Col>
|
<Col lg="4" sm="4" xs="4">{order.commercialLead ? order.commercialLead.name : ''} {orderTexts.labels.MAIL}:</Col>
|
||||||
<Col lg="8" sm="8" xs="8">{order.commercialLeadMail}</Col>
|
<Col lg="8" sm="8" xs="8">{order.commercialLead ? order.commercialLead.email : ''}</Col>
|
||||||
</WiaasTableRow>
|
</WiaasTableRow>
|
||||||
</div>
|
</div>
|
||||||
</WiaasBox>
|
</WiaasBox>
|
||||||
@@ -59,23 +59,23 @@ class OrderPackage extends Component {
|
|||||||
<WiaasTableHeader headers={this.getHeadersByType(type)}/>
|
<WiaasTableHeader headers={this.getHeadersByType(type)}/>
|
||||||
<WiaasTableBody>
|
<WiaasTableBody>
|
||||||
{order.packages.map((orderPackage, index) =>
|
{order.packages.map((orderPackage, index) =>
|
||||||
<WiaasTableRow className="order-central-row" key={orderPackage.idOrder + '-' + orderPackage.idPackage}>
|
<WiaasTableRow className="order-central-row" key={orderPackage.id}>
|
||||||
<WiaasTableCol header="Package" className="package-info-col">
|
<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>
|
||||||
<WiaasTableCol header="Price">
|
<WiaasTableCol header="Price">
|
||||||
{this.calculateQuantityPrice(orderPackage.units, orderPackage.packageFixedPrice).toLocaleString()} {orderPackage.packageCurrency && orderPackage.packageCurrency.currency} {' '}
|
{this.calculateQuantityPrice(orderPackage.quantity, orderPackage.price).toLocaleString()} {order.currency} {' '}
|
||||||
({orderPackage.paymentType})
|
({orderPackage.paymentType})
|
||||||
</WiaasTableCol>
|
</WiaasTableCol>
|
||||||
<WiaasTableCol header="Services and support">
|
<WiaasTableCol header="Services and support">
|
||||||
{this.calculateQuantityPrice(orderPackage.units, orderPackage.packageServicePrice, orderPackage.packageRecuringPrice).toLocaleString() + ' / ' + orderPackage.periodUnit + ' '}
|
{this.calculateQuantityPrice(orderPackage.quantity, orderPackage.servicePrice, orderPackage.recurringPrice).toLocaleString() + ' / ' + orderPackage.periodUnit + ' '}
|
||||||
{orderTexts.labels.EXTEND} {orderPackage.periodUnit} (Max {orderPackage.maxContractPeriod})
|
{orderTexts.labels.EXTEND} {orderPackage.periodUnit} (Max {orderPackage.maxContractPeriod})
|
||||||
</WiaasTableCol>
|
</WiaasTableCol>
|
||||||
<WiaasTableCol>
|
<WiaasTableCol>
|
||||||
{
|
{
|
||||||
type === 'active'
|
type === 'active'
|
||||||
? orderPackage.shortDesc ? orderPackage.shortDesc : '-'
|
? orderPackage.shortDesc || '-'
|
||||||
: orderPackage.endOfLife ? orderPackage.endOfLife : '-'
|
: orderPackage.dateCompleted || '-'
|
||||||
}
|
}
|
||||||
</WiaasTableCol>
|
</WiaasTableCol>
|
||||||
</WiaasTableRow>
|
</WiaasTableRow>
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ class SupportMail extends Component {
|
|||||||
<span className="subtitle">{orderTexts.labels.ORDER_NUMBER}:</span>
|
<span className="subtitle">{orderTexts.labels.ORDER_NUMBER}:</span>
|
||||||
</Col>
|
</Col>
|
||||||
<Col xl="8">
|
<Col xl="8">
|
||||||
<span>{orderInfo.orderNumber}</span>
|
<span>{orderInfo.number}</span>
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
<Row>
|
<Row>
|
||||||
@@ -71,17 +71,17 @@ class SupportMail extends Component {
|
|||||||
<Row>
|
<Row>
|
||||||
<Col>
|
<Col>
|
||||||
<span className="fa fa-shopping-cart subtitle"></span>
|
<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>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
|
|
||||||
{orderPackage.endOfLife &&
|
{orderPackage.dateCompleted &&
|
||||||
<Row>
|
<Row>
|
||||||
<Col>
|
<Col>
|
||||||
<span className="subtitle">{orderTexts.labels.END_OF_LIFE}:</span>
|
<span className="subtitle">{orderTexts.labels.END_OF_LIFE}:</span>
|
||||||
</Col>
|
</Col>
|
||||||
<Col xl="8">
|
<Col xl="8">
|
||||||
<span>{orderPackage.endOfLife}</span>
|
<span>{orderPackage.dateCompleted}</span>
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,11 +14,11 @@ $borderWidth: 3px;
|
|||||||
border-left: $borderWidth $open-status-color solid;
|
border-left: $borderWidth $open-status-color solid;
|
||||||
}
|
}
|
||||||
|
|
||||||
.order-border-in-progress {
|
.order-border-processing {
|
||||||
border-left: $borderWidth $in-progress-status-color solid;
|
border-left: $borderWidth $in-progress-status-color solid;
|
||||||
}
|
}
|
||||||
|
|
||||||
.order-border-production {
|
.order-border-completed {
|
||||||
border-left: $borderWidth $production-status-color solid;
|
border-left: $borderWidth $production-status-color solid;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -26,7 +26,7 @@ $borderWidth: 3px;
|
|||||||
border-left: $borderWidth $end-of-life-status-color solid;
|
border-left: $borderWidth $end-of-life-status-color solid;
|
||||||
}
|
}
|
||||||
|
|
||||||
.order-border-canceled {
|
.order-border-cancelled {
|
||||||
border-left: $borderWidth $canceled-status-color solid;
|
border-left: $borderWidth $canceled-status-color solid;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,11 +72,11 @@ $borderWidth: 3px;
|
|||||||
background: $open-status-color;
|
background: $open-status-color;
|
||||||
}
|
}
|
||||||
|
|
||||||
.in-progress {
|
.processing {
|
||||||
background: $in-progress-status-color;
|
background: $in-progress-status-color;
|
||||||
}
|
}
|
||||||
|
|
||||||
.production {
|
.completed {
|
||||||
background: $production-status-color;
|
background: $production-status-color;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,11 +20,11 @@ $link-line-height: 1.5rem;
|
|||||||
border-left: $border-width $processing-status-color solid;
|
border-left: $border-width $processing-status-color solid;
|
||||||
}
|
}
|
||||||
|
|
||||||
.canceled {
|
.cancelled {
|
||||||
border-left: $border-width $canceled-status-color solid;
|
border-left: $border-width $canceled-status-color solid;
|
||||||
}
|
}
|
||||||
|
|
||||||
.production {
|
.completed {
|
||||||
border-left: $border-width $production-status-color solid;
|
border-left: $border-width $production-status-color solid;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -127,7 +127,7 @@ $link-line-height: 1.5rem;
|
|||||||
background: $end-of-life-status-color;
|
background: $end-of-life-status-color;
|
||||||
}
|
}
|
||||||
|
|
||||||
.canceled {
|
.cancelled {
|
||||||
background: $canceled-status-color;
|
background: $canceled-status-color;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,15 +1,47 @@
|
|||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
|
|
||||||
export const fromWCOrder = (order) => {
|
function formatDate(date) {
|
||||||
|
return date ? moment(date).format("Do MMM, YYYY") : undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatAddress(addressObject) {
|
||||||
|
return `${addressObject.address_1}, ${addressObject.city}, ${addressObject.country}, ${addressObject.postcode}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const fromWCOrder = (WCOrder) => {
|
||||||
return {
|
return {
|
||||||
id: order.id,
|
id: WCOrder.id,
|
||||||
number: order.number,
|
number: WCOrder.number,
|
||||||
dateCreated: moment(order.date_created).format("Do MMM, YYYY"),
|
isMyOrder: WCOrder['is_my_order'],
|
||||||
|
dateCreated: formatDate(WCOrder['date_created']),
|
||||||
|
dateCompleted: formatDate(WCOrder['date_completed']),
|
||||||
|
estimatedDeliveryDate: undefined,
|
||||||
reference: 'reference field',
|
reference: 'reference field',
|
||||||
assignedTo: 'assigned to',
|
assignedTo: 'assigned to',
|
||||||
fixedPrice: order.total,
|
fixedPrice: WCOrder.total,
|
||||||
recurringPrice: 0,
|
recurringPrice: 0,
|
||||||
status: order.status,
|
status: WCOrder.status,
|
||||||
currency: order.currency
|
currency: WCOrder.currency,
|
||||||
|
packages: WCOrder['line_items'].map(packageLine => {
|
||||||
|
return {
|
||||||
|
id: packageLine['product_id'],
|
||||||
|
name: packageLine.name,
|
||||||
|
quantity: packageLine.quantity,
|
||||||
|
price: packageLine.price,
|
||||||
|
status: packageLine.status,
|
||||||
|
paymentType: packageLine['payment_type'],
|
||||||
|
servicePrice: packageLine['service_price'],
|
||||||
|
serviceContractPeriod: packageLine['service_contract_period'],
|
||||||
|
maxContractPeriod: packageLine['max_contract_period'],
|
||||||
|
periodUnit: packageLine['period_unit'],
|
||||||
|
recurringPrice: packageLine['recurring_price'],
|
||||||
|
payPeriod: packageLine['pay_period'],
|
||||||
|
shortDesc: packageLine['short_desc'],
|
||||||
|
dateCompleted: formatDate(packageLine['date_completed']),
|
||||||
|
};
|
||||||
|
}),
|
||||||
|
deliveryAddress: formatAddress(WCOrder.shipping),
|
||||||
|
customer: WCOrder.customer,
|
||||||
|
commercialLead: WCOrder['commercial_lead']
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
Reference in New Issue
Block a user