From 784677cc9cab4320460f09a08dceac3d4638b459 Mon Sep 17 00:00:00 2001 From: Akolzin Dmitry Date: Mon, 12 Mar 2018 09:34:39 +0300 Subject: [PATCH 1/2] Edit changelog --- Changelog.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Changelog.md b/Changelog.md index 5433943..27e4071 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,6 +1,5 @@ ## v.2.0.4 -* Улучшена механика выгрузки изменений из RetailCRM -* Улучшена механика выборки и настройки способов доставки +* Исправление мелких багов ## v.2.0.3 * Улучшена механика выгрузки изменений из RetailCRM From 98b485cba08b81bb9790de02048c2188e43b4603 Mon Sep 17 00:00:00 2001 From: Akolzin Dmitry Date: Fri, 23 Mar 2018 13:08:01 +0300 Subject: [PATCH 2/2] Bonus points, fix customer group in history --- Changelog.md | 4 +++ admin/model/retailcrm/base_history.php | 1 - admin/model/retailcrm/history.php | 34 ++++++++++++++++++-------- catalog/model/retailcrm/order.php | 16 +++++++++--- 4 files changed, 40 insertions(+), 15 deletions(-) diff --git a/Changelog.md b/Changelog.md index 27e4071..fca17bb 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,3 +1,7 @@ +## v.2.0.5 +* Добавлена проверка группы пользователя в заказе при редактировании +* Добавлена передача скидки по бонусным баллам + ## v.2.0.4 * Исправление мелких багов diff --git a/admin/model/retailcrm/base_history.php b/admin/model/retailcrm/base_history.php index 24c5fc1..a876de1 100644 --- a/admin/model/retailcrm/base_history.php +++ b/admin/model/retailcrm/base_history.php @@ -41,7 +41,6 @@ class ModelRetailcrmBaseHistory extends Model $this->db->query("UPDATE `" . DB_PREFIX . "order` SET customer_id = '" . (int)$order['customer_id'] . "', customer_group_id = '" . (int)$order['customer_group_id'] . "', firstname = '" . $this->db->escape($order['firstname']) . "', lastname = '" . $this->db->escape($order['lastname']) . "', email = '" . $this->db->escape($order['email']) . "', telephone = '" . $this->db->escape($order['telephone']) . "', custom_field = '" . $this->db->escape(json_encode($order['custom_field'])) . "', payment_firstname = '" . $this->db->escape($order['payment_firstname']) . "', payment_lastname = '" . $this->db->escape($order['payment_lastname']) . "', payment_address_1 = '" . $this->db->escape($order['payment_address_1']) . "', payment_address_2 = '" . $this->db->escape($order['payment_address_2']) . "', payment_city = '" . $this->db->escape($order['payment_city']) . "', payment_postcode = '" . $this->db->escape($order['payment_postcode']) . "', payment_country = '" . $this->db->escape($order['payment_country']) . "', payment_country_id = '" . (int)$order['payment_country_id'] . "', payment_zone = '" . $this->db->escape($order['payment_zone']) . "', payment_zone_id = '" . (int)$order['payment_zone_id'] . "', payment_method = '" . $this->db->escape($order['payment_method']) . "', payment_code = '" . $this->db->escape($order['payment_code']) . "', shipping_firstname = '" . $this->db->escape($order['shipping_firstname']) . "', shipping_lastname = '" . $this->db->escape($order['shipping_lastname']) . "', shipping_address_1 = '" . $this->db->escape($order['shipping_address_1']) . "', shipping_address_2 = '" . $this->db->escape($order['shipping_address_2']) . "', shipping_city = '" . $this->db->escape($order['shipping_city']) . "', shipping_postcode = '" . $this->db->escape($order['shipping_postcode']) . "', shipping_country = '" . $this->db->escape($order['shipping_country']) . "', shipping_country_id = '" . (int)$order['shipping_country_id'] . "', shipping_zone = '" . $this->db->escape($order['shipping_zone']) . "', shipping_zone_id = '" . (int)$order['shipping_zone_id'] . "', shipping_method = '" . $this->db->escape($order['shipping_method']) . "', shipping_code = '" . $this->db->escape($order['shipping_code']) . "', comment = '" . $this->db->escape($order['comment']) . "', total = '" . (float)$order['total'] . "', order_status_id = '" . (int)$order['order_status_id'] . "', date_modified = NOW() WHERE order_id = '" . (int)$order_id . "'"); $this->db->query("DELETE FROM " . DB_PREFIX . "order_product WHERE order_id = '" . (int)$order_id . "'"); - $this->db->query("DELETE FROM " . DB_PREFIX . "order_option WHERE order_id = '" . (int)$order_id . "'"); // Products if (isset($order['order_product']) && $order['order_product']) { diff --git a/admin/model/retailcrm/history.php b/admin/model/retailcrm/history.php index 6d9cc97..349ee28 100644 --- a/admin/model/retailcrm/history.php +++ b/admin/model/retailcrm/history.php @@ -141,9 +141,17 @@ class ModelRetailcrmHistory extends ModelRetailcrmBaseHistory $data['telephone'] = $phone; } + if (isset($order['customer']['externalId']) && $order['customer']['externalId']) { + if (version_compare(VERSION, '2.1.0.0', '>=')) { + $customer = $this->model_customer_customer->getCustomer($order['customer']['externalId']); + } else { + $customer = $this->model_sale_customer->getCustomer($order['customer']['externalId']); + } + } + $data['customer'] = $order['firstName']; $data['customer_id'] = (!empty($order['customer']['externalId'])) ? $order['customer']['externalId'] : 0; - $data['customer_group_id'] = 1; + $data['customer_group_id'] = (isset($customer)) ? $customer['customer_group_id'] : 1; $data['firstname'] = $order['firstName']; $data['lastname'] = isset($order['lastName']) ? $order['lastName'] : $order['firstName']; $data['email'] = $mail ? $mail : uniqid() . '@retailrcm.ru'; @@ -225,6 +233,10 @@ class ModelRetailcrmHistory extends ModelRetailcrmBaseHistory } $data['shipping_code'] = $data['shipping']; + } elseif (!isset($this->settings['retailcrm_delivery'][$ocOrder['shipping_code']]) + ) { + $data['shipping_method'] = $ocOrder['shipping_method']; + $data['shipping_code'] = $ocOrder['shipping_code']; } } else { if (!isset($this->settings[$ocOrder['shipping_code']]) @@ -310,15 +322,6 @@ class ModelRetailcrmHistory extends ModelRetailcrmBaseHistory $deliveryCost = !empty($order['delivery']['cost']) ? $order['delivery']['cost'] : 0; - if (isset($order['discount']) && $order['discount'] > 0) { - $orderTotals = $this->model_sale_order->getOrderTotals($order['externalId']); - foreach($orderTotals as $orderTotal) { - if($orderTotal['code'] == 'coupon') { - $data['order_total'][] = $orderTotal; - } - } - } - $data['total'] = $order['totalSumm']; $data['order_total'] = array( array( @@ -347,6 +350,17 @@ class ModelRetailcrmHistory extends ModelRetailcrmBaseHistory ) ); + if (isset($order['discount']) && $order['discount'] > 0) { + $orderTotals = $this->model_sale_order->getOrderTotals($order['externalId']); + foreach($orderTotals as $orderTotal) { + if ($orderTotal['code'] == 'coupon' + || $orderTotal['code'] == 'reward' + ) { + $data['order_total'][] = $orderTotal; + } + } + } + $data['fromApi'] = true; if (array_key_exists($order['status'], $this->status)) { diff --git a/catalog/model/retailcrm/order.php b/catalog/model/retailcrm/order.php index 965b17f..72fda12 100644 --- a/catalog/model/retailcrm/order.php +++ b/catalog/model/retailcrm/order.php @@ -50,6 +50,7 @@ class ModelRetailcrmOrder extends Model { } $deliveryCost = 0; + $couponTotal = 0; $altTotals = isset($order_data['order_total']) ? $order_data['order_total'] : ""; $orderTotals = isset($order_data['totals']) ? $order_data['totals'] : $altTotals ; @@ -59,7 +60,10 @@ class ModelRetailcrmOrder extends Model { $deliveryCost = $totals['value']; } if ($totals['code'] == 'coupon') { - $couponTotal = abs($totals['value']); + $couponTotal += abs($totals['value']); + } + if ($totals['code'] == 'reward') { + $couponTotal += abs($totals['value']); } } } @@ -75,7 +79,7 @@ class ModelRetailcrmOrder extends Model { $order_data['shipping_iso_code_2'] = $shipping_country['iso_code_2']; } - if (isset($couponTotal)) { + if (isset($couponTotal) && $couponTotal > 0) { $order['discount'] = $couponTotal; } @@ -183,6 +187,7 @@ class ModelRetailcrmOrder extends Model { } $deliveryCost = 0; + $couponTotal = 0; $orderTotals = isset($order_data['totals']) ? $order_data['totals'] : $order_data['order_total'] ; foreach ($orderTotals as $totals) { @@ -190,7 +195,10 @@ class ModelRetailcrmOrder extends Model { $deliveryCost = $totals['value']; } if ($totals['code'] == 'coupon') { - $couponTotal = abs($totals['value']); + $couponTotal += abs($totals['value']); + } + if ($totals['code'] == 'reward') { + $couponTotal += abs($totals['value']); } } @@ -199,7 +207,7 @@ class ModelRetailcrmOrder extends Model { $country = (isset($order_data['shipping_country'])) ? $order_data['shipping_country'] : '' ; - if (isset($couponTotal)) { + if (isset($couponTotal) && $couponTotal > 0) { $order['discount'] = $couponTotal; }