Fix order organization info
This commit is contained in:
@@ -468,14 +468,25 @@ class Wiaas_Cart {
|
|||||||
|
|
||||||
$order->set_currency($currency);
|
$order->set_currency($currency);
|
||||||
|
|
||||||
// set order commercial lead
|
// get order commercial lead
|
||||||
$shop_owner_id = get_user_meta(get_current_user_id(), '_wiaas_cart_shop_owner_id', true);
|
$shop_owner_id = get_user_meta(get_current_user_id(), '_wiaas_cart_shop_owner_id', true);
|
||||||
$shop_owner_id = absint($shop_owner_id);
|
$shop_owner_id = absint($shop_owner_id);
|
||||||
|
|
||||||
|
// save commercial lead info in case it gets deleted
|
||||||
$order->add_meta_data('_wiaas_commercial_lead_id', $shop_owner_id);
|
$order->add_meta_data('_wiaas_commercial_lead_id', $shop_owner_id);
|
||||||
|
$commercial_lead_organization_info = wiaas_get_organization_info($shop_owner_id);
|
||||||
|
$order->add_meta_data('_wiaas_commercial_lead_info', $commercial_lead_organization_info);
|
||||||
|
|
||||||
|
// save customer organization info in case it gets deleted
|
||||||
|
$customer_user_id = $order->get_customer_id();
|
||||||
|
$customer_organization_id = wiaas_get_user_organization_id($customer_user_id);
|
||||||
|
$order->add_meta_data('_wiaas_customer_id', $customer_organization_id);
|
||||||
|
$customer_organization_info = wiaas_get_organization_info($customer_organization_id);
|
||||||
|
$order->add_meta_data('_wiaas_customer_info', $customer_organization_info);
|
||||||
|
|
||||||
|
|
||||||
// add supplier organizations information to order
|
|
||||||
|
// add supplier organizations information to order in case supplier organizations are deleted
|
||||||
// save installation suppliers separately
|
// save installation suppliers separately
|
||||||
$suppliers_info = array();
|
$suppliers_info = array();
|
||||||
$installation_suppliers_info = array();
|
$installation_suppliers_info = array();
|
||||||
|
|||||||
@@ -463,19 +463,35 @@ class Wiaas_Order {
|
|||||||
/**
|
/**
|
||||||
* Appends additional wiaas customer lead info to order json response
|
* Appends additional wiaas customer lead info to order json response
|
||||||
* @param $data
|
* @param $data
|
||||||
* @param $order
|
* @param WC_Order $order
|
||||||
* @param $request
|
* @param $request
|
||||||
*
|
*
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
private static function _append_commercial_lead_info($data, $order, $request) {
|
private static function _append_commercial_lead_info($data, $order, $request) {
|
||||||
|
|
||||||
$data['commercial_lead'] = array(
|
$commercial_lead_org_id = $order->get_meta('_wiaas_commercial_lead_id', true);
|
||||||
'id' => 1,
|
|
||||||
'name' => 'Coor Service Management',
|
$commercial_lead_organization_info = $order->get_meta('_wiaas_commercial_lead_info', true);
|
||||||
'phone' => '123456789',
|
|
||||||
'email' => 'rikard@co-ideation.com'
|
if (! empty($commercial_lead_org_id) && empty($commercial_lead_organization_info)) {
|
||||||
);
|
|
||||||
|
$commercial_lead_organization_info = wiaas_get_organization_info($commercial_lead_org_id);
|
||||||
|
|
||||||
|
$data['commercial_lead'] = array(
|
||||||
|
'id' => $commercial_lead_org_id,
|
||||||
|
'name' => $commercial_lead_organization_info['name'],
|
||||||
|
'phone' => $commercial_lead_organization_info['phone'],
|
||||||
|
'email' => $commercial_lead_organization_info['email']
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($commercial_lead_organization_info)) {
|
||||||
|
|
||||||
|
$commercial_lead_organization_info['id'] = $commercial_lead_organization_info;
|
||||||
|
|
||||||
|
$data['commercial_lead'] = $commercial_lead_organization_info;
|
||||||
|
}
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
@@ -483,25 +499,34 @@ class Wiaas_Order {
|
|||||||
/**
|
/**
|
||||||
* Appends additional wiaas customer info to order json response
|
* Appends additional wiaas customer info to order json response
|
||||||
* @param $data
|
* @param $data
|
||||||
* @param $order
|
* @param WC_Order $order
|
||||||
* @param $request
|
* @param $request
|
||||||
*
|
*
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
private static function _append_customer_info($data, $order, $request) {
|
private static function _append_customer_info($data, $order, $request) {
|
||||||
|
|
||||||
$current_user = wp_get_current_user();
|
$customer_organization_id = $order->get_meta('_wiaas_customer_id', true);
|
||||||
|
|
||||||
$customer_id = $data['customer_id'];
|
$customer_user_id = $order->get_customer_id();
|
||||||
|
|
||||||
$customer_user = get_user_by('id', $customer_id);
|
if (empty($customer_organization_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;
|
$customer_organization_id = wiaas_get_user_organization_id($customer_user_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
$customer_organization_info = $order->get_meta('_wiaas_customer_info', true);
|
||||||
|
|
||||||
|
if ( !empty($customer_organization_id) && empty($customer_organization_info) ) {
|
||||||
|
|
||||||
|
$customer_organization_info = wiaas_get_organization_info($customer_organization_id);
|
||||||
|
|
||||||
|
$customer_organization_info['id'] = $customer_organization_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
$data['customer'] = $customer_organization_info;
|
||||||
|
|
||||||
|
$data['is_my_order'] = $customer_user_id === get_current_user_id();
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -96,8 +96,6 @@ class Wiaas_Order_Fields {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
error_log($new_value);
|
|
||||||
|
|
||||||
$bundle_item->update_meta_data('wiaas_installation_date', $new_value);
|
$bundle_item->update_meta_data('wiaas_installation_date', $new_value);
|
||||||
$bundle_item->save_meta_data();
|
$bundle_item->save_meta_data();
|
||||||
|
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ export const fromWCOrder = (WCOrder) => {
|
|||||||
isOwner: comment['is_owner']
|
isOwner: comment['is_owner']
|
||||||
})) : [],
|
})) : [],
|
||||||
deliveryAddress: formatAddress(WCOrder.shipping),
|
deliveryAddress: formatAddress(WCOrder.shipping),
|
||||||
customer: WCOrder.customer,
|
customer: WCOrder.customer || {},
|
||||||
commercialLead: WCOrder['commercial_lead'],
|
commercialLead: WCOrder['commercial_lead'] || {},
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
Reference in New Issue
Block a user