From 3f54a8fc893e338f8e314ddea8a23839b63c8931 Mon Sep 17 00:00:00 2001 From: dewalt201 Date: Thu, 24 Aug 2017 08:40:05 +0300 Subject: [PATCH] Some fixes (#11) --- .gitignore | 1 + .../include/class-wc-retailcrm-orders.php | 44 ++++++++++++------- 2 files changed, 28 insertions(+), 17 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..14bc68c --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/nbproject/private/ \ No newline at end of file diff --git a/retailcrm/include/class-wc-retailcrm-orders.php b/retailcrm/include/class-wc-retailcrm-orders.php index a471dba..7e0a27e 100644 --- a/retailcrm/include/class-wc-retailcrm-orders.php +++ b/retailcrm/include/class-wc-retailcrm-orders.php @@ -91,7 +91,7 @@ if ( ! class_exists( 'WC_Retailcrm_Orders' ) ) : $order_data['customer']['externalId'] = $search['customer']['externalId']; } } - + $res = $this->retailcrm->ordersCreate($order_data); } @@ -105,7 +105,7 @@ if ( ! class_exists( 'WC_Retailcrm_Orders' ) ) : $response = $this->retailcrm->ordersEdit($address); } - + /** * Update order status * @@ -158,7 +158,7 @@ if ( ! class_exists( 'WC_Retailcrm_Orders' ) ) : } } } - + /** * Update order payment * @@ -181,7 +181,7 @@ if ( ! class_exists( 'WC_Retailcrm_Orders' ) ) : $this->retailcrm->ordersPaymentsEdit($payment); } - + } /** @@ -234,7 +234,7 @@ if ( ! class_exists( 'WC_Retailcrm_Orders' ) ) : $shipping_cost = str_replace(',', '.', $shipping_cost); $order_data['delivery']['cost'] = $shipping_cost; } - + $response = $this->retailcrm->ordersEdit($order_data); } @@ -285,39 +285,49 @@ if ( ! class_exists( 'WC_Retailcrm_Orders' ) ) : $status = $order->get_status(); $order_data['status'] = $this->retailcrm_settings[$status]; - + $user_data_billing = $order->get_address('billing'); if (!empty($user_data_billing)) { + if (!empty($user_data_billing['phone'])) $order_data['phone'] = $user_data_billing['phone']; if (!empty($user_data_billing['email'])) $order_data['email'] = $user_data_billing['email']; + if (!empty($user_data_billing['first_name'])) $order_data['firstName'] = $user_data_billing['first_name']; + if (!empty($user_data_billing['last_name'])) $order_data['lastName'] = $user_data_billing['last_name']; + if (!empty($user_data_billing['postcode'])) $order_data['delivery']['address']['index'] = $user_data_billing['postcode']; + if (!empty($user_data_billing['city'])) $order_data['delivery']['address']['city'] = $user_data_billing['city']; + if (!empty($user_data_billing['country'])) $order_data['delivery']['address']['countryIso'] = $user_data_billing['country']; + } $user_data = $order->get_address('shipping'); if (!empty($user_data)) { + if (!empty($user_data['phone'])) $order_data['phone'] = $user_data['phone']; + if (!empty($user_data['email'])) $order_data['email'] = $user_data['email']; if (!empty($user_data['first_name'])) $order_data['firstName'] = $user_data['first_name']; - if (!empty($user_data['last_name'])) $order_data['lastName'] = $user_data['last_name']; + if (!empty($user_data['last_name'])) $order_data['lastName'] = $user_data['last_name']; if (!empty($user_data['postcode'])) $order_data['delivery']['address']['index'] = $user_data['postcode']; if (!empty($user_data['city'])) $order_data['delivery']['address']['city'] = $user_data['city']; if (!empty($user_data['country'])) $order_data['delivery']['address']['countryIso'] = $user_data['country']; - $order_data['delivery']['address']['text'] = sprintf( - "%s %s %s %s", - $user_data['postcode'], - $user_data['city'], - $user_data['address_1'], - $user_data['address_2'] - ); } + $order_data['delivery']['address']['text'] = sprintf( + "%s %s %s %s", + !empty($user_data_billing['postcode']) ? $user_data_billing['postcode'] : $user_data['postcode'], + !empty($user_data_billing['city']) ? $user_data_billing['city'] : $user_data['city'], + !empty($user_data_billing['address_1']) ? $user_data_billing['address_1'] : $user_data['address_1'], + !empty($user_data_billing['address_2']) ? $user_data_billing['address_2'] : $user_data['address_2'] + ); + $order_items = array(); foreach ($order->get_items() as $item) { $uid = ($item['variation_id'] > 0) ? $item['variation_id'] : $item['product_id'] ; $_product = wc_get_product($uid); - + if ($_product) { if ($this->retailcrm_settings['api_version'] != 'v3') { $order_item = array( @@ -393,7 +403,7 @@ if ( ! class_exists( 'WC_Retailcrm_Orders' ) ) : $pay_date = $order->get_date_paid(); $payment['paidAt'] = $pay_date->date('Y-m-d H:i:s'); } - + $this->retailcrm->ordersPaymentCreate($payment); } @@ -410,4 +420,4 @@ if ( ! class_exists( 'WC_Retailcrm_Orders' ) ) : } } } -endif; +endif; \ No newline at end of file