diff --git a/CHANGELOG.md b/CHANGELOG.md index 76a68b3..8fe0294 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## v.3.1.3 +* Добавлена возможность передачи акционных цен для нескольких групп пользователей +* Добавлена передача нулевой цены для неустановленных акционных цен +* Убрана базовая цена retailcrm из настроек соответствия типов цен + ## v.3.1.2 * Добавлен перевод на испанский язык * Переделан перевод на английский язык diff --git a/src/upload/admin/controller/extension/module/retailcrm.php b/src/upload/admin/controller/extension/module/retailcrm.php index e72bcd3..da23081 100644 --- a/src/upload/admin/controller/extension/module/retailcrm.php +++ b/src/upload/admin/controller/extension/module/retailcrm.php @@ -95,6 +95,7 @@ public function index() $this->load->model('localisation/country'); $this->load->model('setting/setting'); $this->load->model('extension/retailcrm/references'); + $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'); @@ -235,6 +236,9 @@ public function index() $key = isset($_data['saved_settings'][\Retailcrm\Retailcrm::MODULE . '_apikey']) ? $_data['saved_settings'][\Retailcrm\Retailcrm::MODULE . '_apikey'] : null; + $apiVersion = isset($_data['saved_settings'][\Retailcrm\Retailcrm::MODULE . '_apiversion']) + ? $_data['saved_settings'][\Retailcrm\Retailcrm::MODULE . '_apiversion'] + : null; if (!empty($url) && !empty($key)) { $_data['delivery'] = $this->model_extension_retailcrm_references @@ -245,6 +249,9 @@ public function index() ->getPaymentTypes($retailcrm_api_client); $_data['customFields'] = $this->model_extension_retailcrm_references ->getCustomFields($retailcrm_api_client); + $_data['priceTypes'] = $this->model_extension_retailcrm_references + ->getPriceTypes(); + $_data['customerGroups'] = $this->model_customer_customer_group->getCustomerGroups(); } $config_data = array( diff --git a/src/upload/admin/model/extension/retailcrm/prices.php b/src/upload/admin/model/extension/retailcrm/prices.php index c784184..fe598c5 100644 --- a/src/upload/admin/model/extension/retailcrm/prices.php +++ b/src/upload/admin/model/extension/retailcrm/prices.php @@ -20,6 +20,7 @@ public function uploadPrices($products, $retailcrm_api_client, $retailcrm) { $this->load->model('catalog/option'); $this->load->model('setting/setting'); + $this->load->model('customer/customer_group'); $prices = $this->getPrices($products, $retailcrm_api_client, $retailcrm); @@ -46,76 +47,109 @@ public function uploadPrices($products, $retailcrm_api_client, $retailcrm) */ protected function getPrices($products, $retailcrm_api_client, $retailcrm) { - $settings = $this->model_setting_setting->getSetting(\retailcrm\Retailcrm::MODULE); - $prices = array(); $site = $this->getSite($retailcrm_api_client); - if (!isset($settings[\Retailcrm\Retailcrm::MODULE . '_special']) - || $settings[\Retailcrm\Retailcrm::MODULE . '_apiversion'] == 'v3' - ) { - return false; - } - foreach ($products as $product) { $specials = $this->model_catalog_product->getProductSpecials($product['product_id']); if (!$specials) { + $productPrice = $this->getEmptyPrice(); + $prices[] = $this->getPriceRequest($product, $site, $productPrice, $retailcrm); continue; } + $productPrice = array(); + if (is_array($specials) && count($specials)) { $productPrice = $this->getSpecialPrice($specials); + } + + $prices[] = $this->getPriceRequest($product, $site, $productPrice, $retailcrm); + } + + return $prices; + } - if (!$productPrice) { - continue; + /** + * Get prices for request + * + * @param $product + * @param $site + * @param $productPrice + * @param \Retailcrm\Retailcrm $retailcrm + * + * @return array + */ + private function getPriceRequest($product, $site, $productPrice, $retailcrm) + { + $settings = $this->model_setting_setting->getSetting(\retailcrm\Retailcrm::MODULE); + $offers = $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] + ); } } - $offers = $retailcrm->getOffers($product); + ksort($options); - foreach ($offers as $optionsString => $optionsValues) { - $optionsString = explode('_', $optionsString); - $options = array(); + $offerId = array(); - foreach($optionsString as $optionString) { - $option = explode('-', $optionString); - $optionIds = explode(':', $option[0]); + foreach($options as $optionKey => $optionData) { + $offerId[] = $optionKey.'-'.$optionData['value_id']; + } - 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] - ); - } + $offerId = implode('_', $offerId); + $price = array(); + + foreach($productPrice as $k => $v) { + if (isset($settings[\Retailcrm\Retailcrm::MODULE . '_special_' . $k])) { + $price[] = array( + 'code' => $settings[\Retailcrm\Retailcrm::MODULE . '_special_' . $k], + 'price' => $v == 0 ? $v : $v + $optionsValues['price'] + ); } + } - ksort($options); + $pricesProduct = array( + 'externalId' => $offerId ? $product['product_id'] . '#' . $offerId : $product['product_id'], + 'site' => $site, + 'prices' => $price + ); + } - $offerId = array(); + return $pricesProduct; + } - foreach($options as $optionKey => $optionData) { - $offerId[] = $optionKey.'-'.$optionData['value_id']; - } + /** + * Get price for no special + * + * @return array $productPrice + */ + private function getEmptyPrice() + { + $customerGroups = $this->model_customer_customer_group->getCustomerGroups(); + $productPrice = array(); - $offerId = implode('_', $offerId); - - $prices[] = array( - 'externalId' => $offerId ? $product['product_id'] . '#' . $offerId : $product['product_id'], - 'site' => $site, - 'prices' => array( - array( - 'code' => $settings[\Retailcrm\Retailcrm::MODULE . '_special'], - 'price' => $productPrice + $optionsValues['price'] - ) - ) - ); - } + foreach ($customerGroups as $customerGroup) { + $productPrice[$customerGroup['customer_group_id']] = 0; } - return $prices; + return $productPrice; } /** @@ -129,21 +163,35 @@ 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; } diff --git a/src/upload/admin/view/template/extension/module/retailcrm.twig b/src/upload/admin/view/template/extension/module/retailcrm.twig index 75561c4..53695ec 100644 --- a/src/upload/admin/view/template/extension/module/retailcrm.twig +++ b/src/upload/admin/view/template/extension/module/retailcrm.twig @@ -114,23 +114,28 @@ {% if saved_settings.module_retailcrm_apiversion is defined and saved_settings.module_retailcrm_apiversion != 'v3' %} -