diff --git a/src/upload/admin/controller/extension/module/retailcrm.php b/src/upload/admin/controller/extension/module/retailcrm.php index 1d52ad2..dbb3b4c 100644 --- a/src/upload/admin/controller/extension/module/retailcrm.php +++ b/src/upload/admin/controller/extension/module/retailcrm.php @@ -328,7 +328,11 @@ class ControllerExtensionModuleRetailcrm extends Controller 'text_lenght_label', 'corporate_enabled_label', 'entry_code', - 'entry_status' + 'entry_status', + 'text_retailcrm_discount', + 'text_label_retailcrm_discount', + 'label_retailcrm_discount', + 'default_label_retailcrm_discount' ); $_data = &$data; diff --git a/src/upload/admin/language/en-gb/extension/module/retailcrm.php b/src/upload/admin/language/en-gb/extension/module/retailcrm.php index e72e4c8..b2669d0 100644 --- a/src/upload/admin/language/en-gb/extension/module/retailcrm.php +++ b/src/upload/admin/language/en-gb/extension/module/retailcrm.php @@ -79,6 +79,11 @@ $_['text_status_changes'] = 'Record changes to the order history of Openc $_['column_total'] = 'Total'; $_['product_summ'] = 'Sum'; +$_['text_retailcrm_discount'] = 'RetailCRM discount'; +$_['text_retailcrm_label_discount'] = 'Label of RetailCRM discount in section total of order'; +$_['default_retailcrm_label_discount'] = 'Discount in RetailCRM'; + + $_['article'] = 'Article'; $_['color'] = 'Color'; $_['weight'] = 'Weight'; diff --git a/src/upload/admin/language/es-es/extension/module/retailcrm.php b/src/upload/admin/language/es-es/extension/module/retailcrm.php index 5842fd6..7710f94 100644 --- a/src/upload/admin/language/es-es/extension/module/retailcrm.php +++ b/src/upload/admin/language/es-es/extension/module/retailcrm.php @@ -79,6 +79,10 @@ $_['text_status_changes'] = 'Registrar los cambios en el historial de ped $_['column_total'] = 'Total'; $_['product_summ'] = 'Importe'; +$_['text_retailcrm_discount'] = 'RetailCRM descuento'; +$_['text_retailcrm_label_discount'] = 'Etiqueta de descuento de RetailCRM en la sección total del pedido'; +$_['default_retailcrm_label_discount'] = 'Descuento en RetailCRM'; + $_['article'] = 'Artículo'; $_['color'] = 'Color'; $_['weight'] = 'Peso'; diff --git a/src/upload/admin/language/ru-ru/extension/module/retailcrm.php b/src/upload/admin/language/ru-ru/extension/module/retailcrm.php index bed9017..c50d7ff 100644 --- a/src/upload/admin/language/ru-ru/extension/module/retailcrm.php +++ b/src/upload/admin/language/ru-ru/extension/module/retailcrm.php @@ -79,6 +79,10 @@ $_['text_status_changes'] = 'Фиксировать изменения в $_['column_total'] = 'Итого'; $_['product_summ'] = 'Сумма'; +$_['text_retailcrm_discount'] = 'Скидка RetailCRM'; +$_['text_retailcrm_label_discount'] = 'Подпись для скидки, установленной в RetailCRM, в итоговой секции заказа'; +$_['default_retailcrm_label_discount'] = 'Скидка в RetailCRM'; + $_['article'] = 'Артикул'; $_['color'] = 'Цвет'; $_['weight'] = 'Вес'; diff --git a/src/upload/admin/view/template/extension/module/retailcrm.tpl b/src/upload/admin/view/template/extension/module/retailcrm.tpl index 7567eef..ad866e4 100644 --- a/src/upload/admin/view/template/extension/module/retailcrm.tpl +++ b/src/upload/admin/view/template/extension/module/retailcrm.tpl @@ -213,6 +213,15 @@ +
+ +
+ +
+ +
+
+
diff --git a/src/upload/admin/view/template/extension/module/retailcrm.twig b/src/upload/admin/view/template/extension/module/retailcrm.twig index a29ee26..af9d0e3 100644 --- a/src/upload/admin/view/template/extension/module/retailcrm.twig +++ b/src/upload/admin/view/template/extension/module/retailcrm.twig @@ -220,6 +220,15 @@
+
+ {{ text_retailcrm_discount }} +
+ +
+ +
+
+
diff --git a/src/upload/catalog/model/extension/total/retailcrm_discount.php b/src/upload/catalog/model/extension/total/retailcrm_discount.php new file mode 100644 index 0000000..8137a65 --- /dev/null +++ b/src/upload/catalog/model/extension/total/retailcrm_discount.php @@ -0,0 +1,11 @@ +settings_manager->getSettingByKey($this->data_repository->totalTitles() . 'sub_total'); $total_settings = $this->settings_manager->getSettingByKey($this->data_repository->totalTitles() . 'total'); $shipping_settings = $this->settings_manager->getSettingByKey($this->data_repository->totalTitles() . 'shipping'); + $retailcrm_label_discount = $this->settings_manager->getSetting('label_discount') + ?: $this->data_repository->getLanguage('default_retailcrm_label_discount'); + + $totalDiscount = 0; + foreach ($order['items'] as $item) { + if ($item['discountTotal'] !== 0) { + $totalDiscount += $item['discountTotal'] * $item['quantity']; + } + } $data['total'] = $order['totalSumm']; $data['order_total'] = array( @@ -314,15 +324,41 @@ class Order { ) ); + //TODO подкорректировать логику добавления скидки из RetailCRM + //Если заказ создали со скидкой в RetailCRM, то добавить скидку + if (!empty($totalDiscount)) { + $data['order_total'][] = array( + 'order_total_id' => '', + 'code' => Retailcrm::RETAILCRM_DISCOUNT, + 'title' => $retailcrm_label_discount, + 'value' => -$totalDiscount, + 'sort_order' => Retailcrm::RETAILCRM_DISCOUNT_SORT_ORDER, + ); + } + if (!empty($order['externalId'])) { $orderTotals = $this->order_repository->getOrderTotals($order['externalId']); + foreach ($orderTotals as $orderTotal) { if ($orderTotal['code'] == 'coupon' || $orderTotal['code'] == 'reward' + || $orderTotal['code'] == 'voucher' ) { $data['order_total'][] = $orderTotal; + $totalDiscount -= abs($orderTotal['value']); } } + + //TODO подкорректировать логику добавления скидки из RetailCRM + $keyRetailCrmDiscount = array_search(Retailcrm::RETAILCRM_DISCOUNT, array_map(function ($item) { + return $item['code']; + }, $data['order_total'])); + + if ($totalDiscount > 0 && false !== $keyRetailCrmDiscount) { + $data['order_total'][$keyRetailCrmDiscount]['value'] = -$totalDiscount; + } elseif ($totalDiscount <= 0 && false !== $keyRetailCrmDiscount) { + unset($data['order_total'][$keyRetailCrmDiscount]); + } } } diff --git a/src/upload/system/library/retailcrm/lib/service/RetailcrmOrderConverter.php b/src/upload/system/library/retailcrm/lib/service/RetailcrmOrderConverter.php index 164e693..54172ce 100644 --- a/src/upload/system/library/retailcrm/lib/service/RetailcrmOrderConverter.php +++ b/src/upload/system/library/retailcrm/lib/service/RetailcrmOrderConverter.php @@ -79,6 +79,7 @@ class RetailcrmOrderConverter { $totalCoupon = $this->getTotal('coupon'); $totalReward = $this->getTotal('reward'); $totalVoucher = $this->getTotal('voucher'); + $retailcrmDiscount = $this->getTotal(\retailcrm\Retailcrm::RETAILCRM_DISCOUNT); if (!empty($totalCoupon)) { $discount += abs($totalCoupon); @@ -92,10 +93,12 @@ class RetailcrmOrderConverter { $discount += abs($totalVoucher); } - if ($discount > 0) { - $this->data['discountManualAmount'] = $discount; + if (!empty($retailcrmDiscount)) { + $discount += abs($retailcrmDiscount); } + $this->data['discountManualAmount'] = $discount; + return $this; } diff --git a/src/upload/system/library/retailcrm/retailcrm.php b/src/upload/system/library/retailcrm/retailcrm.php index 0037cc9..d010712 100644 --- a/src/upload/system/library/retailcrm/retailcrm.php +++ b/src/upload/system/library/retailcrm/retailcrm.php @@ -13,11 +13,17 @@ use retailcrm\service\SettingsManager; require_once 'bootstrap.php'; class Retailcrm { + + const RETAILCRM_DISCOUNT = 'retailcrm_discount'; + const RETAILCRM_DISCOUNT_SORT_ORDER = 8; + protected $registry; /** @var bool */ public static $history_run = false; + + public function __construct(\Registry $registry) { $this->registry = $registry;