diff --git a/woo-retailcrm/include/class-wc-retailcrm-customers.php b/woo-retailcrm/include/class-wc-retailcrm-customers.php index bbbb508..819252f 100644 --- a/woo-retailcrm/include/class-wc-retailcrm-customers.php +++ b/woo-retailcrm/include/class-wc-retailcrm-customers.php @@ -40,7 +40,9 @@ if ( ! class_exists( 'WC_Retailcrm_Customers' ) ) : $data_customers = array(); foreach ($users as $user) { - if ($user->roles[0] != 'customer') continue; + if (!in_array('customer', $user->roles)) { + continue; + } $customer = new WC_Customer($user->ID); $firstName = $customer->get_first_name(); @@ -50,11 +52,6 @@ if ( ! class_exists( 'WC_Retailcrm_Customers' ) ) : 'firstName' => $firstName ? $firstName : $customer->get_username(), 'lastName' => $customer->get_last_name(), 'email' => $user->data->user_email, - 'phones' => array( - array( - 'number' => $customer->get_billing_phone() - ) - ), 'address' => array( 'index' => $customer->get_billing_postcode(), 'countryIso' => $customer->get_billing_country(), @@ -64,6 +61,12 @@ if ( ! class_exists( 'WC_Retailcrm_Customers' ) ) : ) ); + if ($customer->get_billing_phone()) { + $data_customer['phones'][] = array( + 'number' => $customer->get_billing_phone() + ); + } + $data_customers[] = $data_customer; } @@ -86,7 +89,6 @@ if ( ! class_exists( 'WC_Retailcrm_Customers' ) ) : $customer = new WC_Customer($customer_id); if ($customer->get_role() == 'customer'){ - $data_customer = $this->processCustomer($customer); $this->retailcrm->customersCreate($data_customer); @@ -105,7 +107,6 @@ if ( ! class_exists( 'WC_Retailcrm_Customers' ) ) : $customer = new WC_Customer($customer_id); if ($customer->get_role() == 'customer'){ - $data_customer = $this->processCustomer($customer); $this->retailcrm->customersEdit($data_customer); @@ -125,15 +126,10 @@ if ( ! class_exists( 'WC_Retailcrm_Customers' ) ) : $firstName = $customer->get_first_name(); $data_customer = array( 'createdAt' => $createdAt->date('Y-m-d H:i:s'), - 'externalId' => $customer_id, + 'externalId' => $customer->get_id(), 'firstName' => $firstName ? $firstName : $customer->get_username(), 'lastName' => $customer->get_last_name(), 'email' => $customer->get_email(), - 'phones' => array( - array( - 'number' => $customer->get_billing_phone() - ) - ), 'address' => array( 'index' => $customer->get_billing_postcode(), 'countryIso' => $customer->get_billing_country(), @@ -143,6 +139,12 @@ if ( ! class_exists( 'WC_Retailcrm_Customers' ) ) : ) ); + if ($customer->get_billing_phone()) { + $data_customer['phones'][] = array( + 'number' => $customer->get_billing_phone() + ); + } + return $data_customer; } } diff --git a/woo-retailcrm/include/class-wc-retailcrm-orders.php b/woo-retailcrm/include/class-wc-retailcrm-orders.php index e5b5e0b..d1603a0 100644 --- a/woo-retailcrm/include/class-wc-retailcrm-orders.php +++ b/woo-retailcrm/include/class-wc-retailcrm-orders.php @@ -48,7 +48,7 @@ if ( ! class_exists( 'WC_Retailcrm_Orders' ) ) : foreach ($orders as $data_order) { $order_data = $this->processOrder($data_order->ID); - $order = new WC_Order($order_id); + $order = new WC_Order($data_order->ID); $customer = $order->get_user(); if ($customer != false) { @@ -89,13 +89,12 @@ if ( ! class_exists( 'WC_Retailcrm_Orders' ) ) : ); $this->retailcrm->customersCreate($customer_data); - } else { $order_data['customer']['externalId'] = $search['customer']['externalId']; } } - $res = $this->retailcrm->ordersCreate($order_data); + $this->retailcrm->ordersCreate($order_data); } /** @@ -106,7 +105,7 @@ if ( ! class_exists( 'WC_Retailcrm_Orders' ) ) : public function orderUpdateShippingAddress($order_id, $address) { $address['externalId'] = $order_id; - $response = $this->retailcrm->ordersEdit($address); + $this->retailcrm->ordersEdit($address); } /** @@ -122,7 +121,7 @@ if ( ! class_exists( 'WC_Retailcrm_Orders' ) ) : 'status' => $this->retailcrm_settings[$order->get_status()] ); - $response = $this->retailcrm->ordersEdit($order_data); + $this->retailcrm->ordersEdit($order_data); } /** @@ -238,7 +237,7 @@ if ( ! class_exists( 'WC_Retailcrm_Orders' ) ) : $order_data['delivery']['cost'] = $shipping_cost; } - $response = $this->retailcrm->ordersEdit($order_data); + $this->retailcrm->ordersEdit($order_data); } /** @@ -369,27 +368,24 @@ if ( ! class_exists( 'WC_Retailcrm_Orders' ) ) : foreach ($order->get_items() as $item) { $uid = ($item['variation_id'] > 0) ? $item['variation_id'] : $item['product_id'] ; - $_product = wc_get_product($uid); $price = round($item['line_subtotal'] + $item['line_subtotal_tax'], 2); - if ($_product) { - $product_price = $item->get_total() ? $item->get_total() / $item->get_quantity() : 0; - $product_tax = $item->get_total_tax() ? $item->get_total_tax() / $item->get_quantity() : 0; - $price_item = $product_price + $product_tax; - $discount_price = $price - $price_item; + $product_price = $item->get_total() ? $item->get_total() / $item->get_quantity() : 0; + $product_tax = $item->get_total_tax() ? $item->get_total_tax() / $item->get_quantity() : 0; + $price_item = $product_price + $product_tax; + $discount_price = $price - $price_item; - $order_item = array( - 'offer' => array('externalId' => $uid), - 'productName' => $item['name'], - 'initialPrice' => (float)$price, - 'quantity' => $item['qty'], - ); + $order_item = array( + 'offer' => array('externalId' => $uid), + 'productName' => $item['name'], + 'initialPrice' => (float)$price, + 'quantity' => $item['qty'], + ); - if ($this->retailcrm_settings['api_version'] == 'v5' && round($discount_price, 2)) { - $order_item['discountManualAmount'] = round($discount_price, 2); - } elseif ($this->retailcrm_settings['api_version'] == 'v4' && round($discount_price, 2)) { - $order_item['discount'] = round($discount_price, 2); - } + if ($this->retailcrm_settings['api_version'] == 'v5' && round($discount_price, 2)) { + $order_item['discountManualAmount'] = round($discount_price, 2); + } elseif ($this->retailcrm_settings['api_version'] == 'v4' && round($discount_price, 2)) { + $order_item['discount'] = round($discount_price, 2); } $order_items[] = $order_item; @@ -497,4 +493,4 @@ if ( ! class_exists( 'WC_Retailcrm_Orders' ) ) : } } } -endif; \ No newline at end of file +endif; diff --git a/woo-retailcrm/retailcrm.php b/woo-retailcrm/retailcrm.php index 708659a..2c31628 100644 --- a/woo-retailcrm/retailcrm.php +++ b/woo-retailcrm/retailcrm.php @@ -1,6 +1,6 @@