From bb23c4cc40484f7ccd72ef62fb8a2de7e125a2ad Mon Sep 17 00:00:00 2001 From: Yura Date: Fri, 4 Dec 2020 14:33:29 +0300 Subject: [PATCH] Handle the promotional price --- .../model/extension/retailcrm/prices.php | 4 ++-- .../lib/service/RetailcrmOrderConverter.php | 22 ++++++++++++++----- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/upload/admin/model/extension/retailcrm/prices.php b/src/upload/admin/model/extension/retailcrm/prices.php index 6a929f1..62656d4 100644 --- a/src/upload/admin/model/extension/retailcrm/prices.php +++ b/src/upload/admin/model/extension/retailcrm/prices.php @@ -171,13 +171,13 @@ class ModelExtensionRetailcrmPrices extends Model ) { $productPrice[$special['customer_group_id']]['price'] = $special['price']; $productPrice[$special['customer_group_id']]['remove'] = false; - $priority = $special['priority']; $groupId = $special['customer_group_id']; + $priority = $special['priority']; } } else { $productPrice[$special['customer_group_id']]['price'] = $special['price']; - $groupId = $special['customer_group_id']; $productPrice[$special['customer_group_id']]['remove'] = false; + $groupId = $special['customer_group_id']; } } } diff --git a/src/upload/system/library/retailcrm/lib/service/RetailcrmOrderConverter.php b/src/upload/system/library/retailcrm/lib/service/RetailcrmOrderConverter.php index d13e9e3..164e693 100644 --- a/src/upload/system/library/retailcrm/lib/service/RetailcrmOrderConverter.php +++ b/src/upload/system/library/retailcrm/lib/service/RetailcrmOrderConverter.php @@ -234,19 +234,29 @@ class RetailcrmOrderConverter { 'quantity' => $product['quantity'] ); + $date = date('Y-m-d'); + $always = '0000-00-00'; $specials = $this->productsRepository->getProductSpecials($product['product_id']); if (!empty($specials)) { $customer = $this->customerRepository->getCustomer($this->order_data['customer_id']); foreach ($specials as $special) { - if (empty($customer['customer_group_id'])) { - continue; - } + if (($special['date_start'] == $always && $special['date_end'] == $always) + || ($special['date_start'] <= $date && $special['date_end'] >= $date) + ) { + if ((isset($priority) && $priority > $special['priority']) + || !isset($priority)) { + if (empty($customer['customer_group_id'])) { + continue; + } - $specialSetting = $this->settingsManager->getSetting('special_' . $customer['customer_group_id']); - if ($special['customer_group_id'] == $customer['customer_group_id'] && !empty($specialSetting)) { - $item['priceType']['code'] = $specialSetting; + $specialSetting = $this->settingsManager->getSetting('special_' . $customer['customer_group_id']); + if ($special['customer_group_id'] == $customer['customer_group_id'] && !empty($specialSetting)) { + $item['priceType']['code'] = $specialSetting; + $priority = $special['priority']; + } + } } } }