diff --git a/retailcrm/job/sync.php b/retailcrm/job/sync.php index 7688268..9a07559 100644 --- a/retailcrm/job/sync.php +++ b/retailcrm/job/sync.php @@ -364,10 +364,11 @@ if ($history->isSuccessful() && count($history->history) > 0) { $ptype = $order['paymentType']; if ($payments[$ptype] != null) { + $paymentType = Module::getModuleName($payments[$ptype]); if ($payments[$ptype] != $orderToUpdate->payment) { Db::getInstance()->execute(' UPDATE `' . _DB_PREFIX_ . 'orders` - SET `payment` = \'' . $payments[$ptype] . '\' + SET `payment` = \'' . ($paymentType != null ? $paymentType : $payments[$ptype]). '\' WHERE `id_order` = ' . (int)$order['externalId'] ); Db::getInstance()->execute(' @@ -411,7 +412,6 @@ if ($history->isSuccessful() && count($history->history) > 0) { */ foreach ($orderToUpdate->getProductsDetail() as $orderItem) { foreach ($order['items'] as $key => $item) { - if (isset($item['discount']) || isset($item['discountPercent'])) $ItemDiscount = true; if(strpos($item['offer']['externalId'], '#') !== false) { $itemId = explode('#', $item['offer']['externalId']); $product_id = $itemId[0]; @@ -439,7 +439,6 @@ if ($history->isSuccessful() && count($history->history) > 0) { $productPrice = $prodPrice - $item['discount']; $productPrice = $productPrice - ($prodPrice / 100 * $item['discountPercent']); - $ItemDiscount = true; $productPrice = round($productPrice , 2); @@ -460,6 +459,7 @@ if ($history->isSuccessful() && count($history->history) > 0) { ); } + $ItemDiscount = true; unset($order['items'][$key]); } } @@ -480,7 +480,6 @@ if ($history->isSuccessful() && count($history->history) > 0) { VALUES'; foreach ($order['items'] as $key => $newItem) { - if ($newItem['discount'] || $newItem['discountPercent']) $ItemDiscount = true; $product_id = $newItem['offer']['externalId']; $product_attribute_id = 0; if(strpos($product_id, '#') !== false) { diff --git a/retailcrm/retailcrm.php b/retailcrm/retailcrm.php index 92efa8d..99e02bd 100644 --- a/retailcrm/retailcrm.php +++ b/retailcrm/retailcrm.php @@ -36,6 +36,7 @@ class RetailCRM extends Module if ($this->version == '1.6') { $this->bootstrap = true; + $this->use_new_hooks = false; } if ($this->validateCrmAddress($this->apiUrl) && !empty($this->apiKey)) { @@ -53,7 +54,9 @@ class RetailCRM extends Module $this->registerHook('newOrder') && $this->registerHook('actionOrderStatusPostUpdate') && $this->registerHook('actionPaymentConfirmation') && - $this->registerHook('actionCustomerAccountAdd') + $this->registerHook('actionCustomerAccountAdd') && + $this->registerHook('actionOrderEdited') && + ($this->use_new_hooks ? $this->registerHook('actionCustomerAccountUpdate') : true) ); } @@ -298,6 +301,20 @@ class RetailCRM extends Module ); } + // this hook added in 1.7 + public function hookActionCustomerAccountUpdate($params) + { + $this->api->customersEdit( + array( + 'externalId' => $params['customer']->id, + 'firstName' => $params['customer']->firstname, + 'lastName' => $params['customer']->lastname, + 'email' => $params['customer']->email, + 'birthday' => $params['customer']->birthday + ) + ); + } + public function hookNewOrder($params) { return $this->hookActionOrderStatusPostUpdate($params); @@ -315,6 +332,38 @@ class RetailCRM extends Module return $this->hookActionOrderStatusPostUpdate($params); } + public function hookActionOrderEdited($params) + { + $order = array( + 'externalId' => $params['order']->id, + 'firstName' => $params['customer']->firstname, + 'lastName' => $params['customer']->lastname, + 'email' => $params['customer']->email, + 'discount' => $params['order']->total_discounts, + 'createdAt' => $params['order']->date_add, + 'delivery' => array('cost' => $params['order']->total_shipping) + ); + + $orderdb = new Order($params['order']->id); + foreach ($orderdb->getProducts() as $item) { + if(isset($item['product_attribute_id']) && $item['product_attribute_id'] > 0) { + $productId = $item['product_id'] . '#' . $item['product_attribute_id']; + } else { + $productId = $item['product_id']; + } + + $order['items'][] = array( + 'initialPrice' => $item['unit_price_tax_incl'], + 'quantity' => $item['product_quantity'], + 'offer' => array('externalId' => $productId), + 'productName' => $item['product_name'], + ); + } + + $order['customer']['externalId'] = $params['order']->id_customer; + $this->api->ordersEdit($order); + } + public function hookActionOrderStatusPostUpdate($params) { $delivery = json_decode(Configuration::get('RETAILCRM_API_DELIVERY'), true);