diff --git a/CHANGELOG.md b/CHANGELOG.md index df4aeb7..0318268 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## v.3.2.4 +* Добавлена возможность передачи акционных цен для нескольких групп пользователей +* Добавлена передача нулевой цены для неустановленных акционных цен +* Убрана базовая цена retailcrm из настроек соответствия типов цен + ## v.3.2.2 * Убрана генерация externalId покупателя при заказе без регистрации на сайте. diff --git a/VERSION b/VERSION index be94e6f..351227f 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -3.2.2 +3.2.4 diff --git a/src/upload/admin/controller/extension/module/retailcrm.php b/src/upload/admin/controller/extension/module/retailcrm.php index f1725e9..cf7295d 100644 --- a/src/upload/admin/controller/extension/module/retailcrm.php +++ b/src/upload/admin/controller/extension/module/retailcrm.php @@ -119,6 +119,7 @@ class ControllerExtensionModuleRetailcrm extends Controller $this->load->model('setting/setting'); $this->load->model('extension/retailcrm/references'); $this->load->model('localisation/currency'); + $this->load->model('customer/customer_group'); $this->load->language('extension/module/retailcrm'); $this->document->setTitle($this->language->get('heading_title')); $this->document->addStyle('/admin/view/stylesheet/retailcrm.css'); @@ -344,6 +345,7 @@ class ControllerExtensionModuleRetailcrm extends Controller if ($apiVersion != 'v3') { $_data['priceTypes'] = $this->model_extension_retailcrm_references ->getPriceTypes(); + $_data['customerGroups'] = $this->model_customer_customer_group->getCustomerGroups(); } } diff --git a/src/upload/admin/model/extension/retailcrm/prices.php b/src/upload/admin/model/extension/retailcrm/prices.php index 5c6c303..20a0fb1 100644 --- a/src/upload/admin/model/extension/retailcrm/prices.php +++ b/src/upload/admin/model/extension/retailcrm/prices.php @@ -9,7 +9,7 @@ class ModelExtensionRetailcrmPrices extends Model /** * Constructor - * + * * @param Registry $registry */ public function __construct($registry) @@ -18,6 +18,7 @@ class ModelExtensionRetailcrmPrices extends Model $this->load->library('retailcrm/retailcrm'); $this->load->model('catalog/option'); $this->load->model('setting/setting'); + $this->load->model('customer/customer_group'); $this->moduleTitle = $this->retailcrm->getModuleTitle(); $this->settings = $this->model_setting_setting->getSetting($this->moduleTitle); @@ -25,9 +26,9 @@ class ModelExtensionRetailcrmPrices extends Model /** * Upload prices to CRM - * + * * @param array $products - * @param \RetailcrmProxy $retailcrmApiClient + * @param RetailcrmProxy $retailcrmApiClient * @return mixed bool | array */ public function uploadPrices($products, $retailcrmApiClient) @@ -49,9 +50,9 @@ class ModelExtensionRetailcrmPrices extends Model /** * Get prices - * + * * @param array $products - * + * * @return mixed */ protected function getPrices($products, $retailcrmApiClient) @@ -59,9 +60,7 @@ class ModelExtensionRetailcrmPrices extends Model $prices = array(); $site = $this->getSite($retailcrmApiClient); - if (!isset($this->settings[$this->moduleTitle . '_special']) - || $this->settings[$this->moduleTitle . '_apiversion'] == 'v3' - ) { + if ($this->settings[$this->moduleTitle . '_apiversion'] == 'v3') { return false; } @@ -69,98 +68,151 @@ class ModelExtensionRetailcrmPrices extends Model $specials = $this->model_catalog_product->getProductSpecials($product['product_id']); if (!$specials) { + $productPrice = $this->getEmptyPrice(); + $prices[] = $this->getPriceRequest($product, $site, $productPrice); continue; } + $productPrice = array(); + if (is_array($specials) && count($specials)) { $productPrice = $this->getSpecialPrice($specials); - - if (!$productPrice) { - continue; - } } - $offers = $this->retailcrm->getOffers($product); - - foreach ($offers as $optionsString => $optionsValues) { - $optionsString = explode('_', $optionsString); - $options = array(); - - foreach($optionsString as $optionString) { - $option = explode('-', $optionString); - $optionIds = explode(':', $option[0]); - - if ($optionString != '0:0-0') { - $optionData = $this->getOptionData($optionIds[1], $option[1]); - $options[$optionIds[0]] = array( - 'name' => $optionData['optionName'], - 'value' => $optionData['optionValue'], - 'value_id' => $option[1] - ); - } - } - - ksort($options); - - $offerId = array(); - - foreach($options as $optionKey => $optionData) { - $offerId[] = $optionKey.'-'.$optionData['value_id']; - } - - $offerId = implode('_', $offerId); - - $prices[] = array( - 'externalId' => $offerId ? $product['product_id'] . '#' . $offerId : $product['product_id'], - 'site' => $site, - 'prices' => array( - array( - 'code' => $this->settings[$this->moduleTitle . '_special'], - 'price' => $productPrice + $optionsValues['price'] - ) - ) - ); - } + $prices[] = $this->getPriceRequest($product, $site, $productPrice); } return $prices; } + /** + * Get prices for request + * + * @param $product + * @param $site + * @param $productPrice + * + * @return array + */ + private function getPriceRequest($product, $site, $productPrice) + { + $offers = $this->retailcrm->getOffers($product); + $pricesProduct = array(); + + foreach ($offers as $optionsString => $optionsValues) { + $optionsString = explode('_', $optionsString); + $options = array(); + + foreach($optionsString as $optionString) { + $option = explode('-', $optionString); + $optionIds = explode(':', $option[0]); + + if ($optionString != '0:0-0') { + $optionData = $this->getOptionData($optionIds[1], $option[1]); + $options[$optionIds[0]] = array( + 'name' => $optionData['optionName'], + 'value' => $optionData['optionValue'], + 'value_id' => $option[1] + ); + } + } + + ksort($options); + + $offerId = array(); + + foreach($options as $optionKey => $optionData) { + $offerId[] = $optionKey.'-'.$optionData['value_id']; + } + + $offerId = implode('_', $offerId); + $price = array(); + + foreach($productPrice as $k => $v) { + if (isset($this->settings[$this->moduleTitle . '_special_' . $k])) { + $price[] = array( + 'code' => $this->settings[$this->moduleTitle . '_special_' . $k], + 'price' => $v == 0 ? $v : $v + $optionsValues['price'] + ); + } + } + + $pricesProduct = array( + 'externalId' => $offerId ? $product['product_id'] . '#' . $offerId : $product['product_id'], + 'site' => $site, + 'prices' => $price + ); + } + + return $pricesProduct; + } + /** * Get actual special - * + * * @param array $specials - * - * @return float $productPrice + * + * @return array $productPrice */ private function getSpecialPrice($specials) { $date = date('Y-m-d'); $always = '0000-00-00'; - $productPrice = 0; + $productPrice = array(); foreach ($specials as $special) { 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) - ) { - $productPrice = $special['price']; - $priority = $special['priority']; + if ((isset($groupId) && $groupId == $special['customer_group_id']) || !isset($groupId)) { + if ((isset($priority) && $priority > $special['priority']) + || !isset($priority) + ) { + $productPrice[$special['customer_group_id']] = $special['price']; + $priority = $special['priority']; + $groupId = $special['customer_group_id']; + } + } else { + $productPrice[$special['customer_group_id']] = $special['price']; + $groupId = $special['customer_group_id']; } } } + $customerGroups = $this->model_customer_customer_group->getCustomerGroups(); + + foreach ($customerGroups as $customerGroup) { + if (!isset($productPrice[$customerGroup['customer_group_id']])){ + $productPrice[$customerGroup['customer_group_id']] = 0; + } + } + + return $productPrice; + } + + /** + * Get price for no special + * + * @return array $productPrice + */ + private function getEmptyPrice() + { + $customerGroups = $this->model_customer_customer_group->getCustomerGroups(); + $productPrice = array(); + + foreach ($customerGroups as $customerGroup) { + $productPrice[$customerGroup['customer_group_id']] = 0; + } + return $productPrice; } /** * Get data option - * + * * @param int $optionId * @param int $optionValueId - * + * * @return array */ private function getOptionData($optionId, $optionValueId) { diff --git a/src/upload/admin/view/template/extension/module/retailcrm.tpl b/src/upload/admin/view/template/extension/module/retailcrm.tpl index 9ff2d27..af02012 100644 --- a/src/upload/admin/view/template/extension/module/retailcrm.tpl +++ b/src/upload/admin/view/template/extension/module/retailcrm.tpl @@ -5,7 +5,7 @@
- +