Added zeroing promotion price from OpenCart and adjustment of price types for different user groups

This commit is contained in:
Sergey 2019-03-01 10:52:49 +03:00
parent dbb353be03
commit 5e85d9a958
6 changed files with 160 additions and 81 deletions

View File

@ -1,3 +1,8 @@
## v.3.1.3
* Добавлена возможность передачи акционных цен для нескольких групп пользователей
* Добавлена передача нулевой цены для неустановленных акционных цен
* Убрана базовая цена retailcrm из настроек соответствия типов цен
## v.3.1.2 ## v.3.1.2
* Добавлен перевод на испанский язык * Добавлен перевод на испанский язык
* Переделан перевод на английский язык * Переделан перевод на английский язык

View File

@ -95,6 +95,7 @@ class ControllerExtensionModuleRetailcrm extends Controller {
$this->load->model('localisation/country'); $this->load->model('localisation/country');
$this->load->model('setting/setting'); $this->load->model('setting/setting');
$this->load->model('extension/retailcrm/references'); $this->load->model('extension/retailcrm/references');
$this->load->model('customer/customer_group');
$this->load->language('extension/module/retailcrm'); $this->load->language('extension/module/retailcrm');
$this->document->setTitle($this->language->get('heading_title')); $this->document->setTitle($this->language->get('heading_title'));
$this->document->addStyle('/admin/view/stylesheet/retailcrm.css'); $this->document->addStyle('/admin/view/stylesheet/retailcrm.css');
@ -235,6 +236,9 @@ class ControllerExtensionModuleRetailcrm extends Controller {
$key = isset($_data['saved_settings'][\Retailcrm\Retailcrm::MODULE . '_apikey']) $key = isset($_data['saved_settings'][\Retailcrm\Retailcrm::MODULE . '_apikey'])
? $_data['saved_settings'][\Retailcrm\Retailcrm::MODULE . '_apikey'] ? $_data['saved_settings'][\Retailcrm\Retailcrm::MODULE . '_apikey']
: null; : null;
$apiVersion = isset($_data['saved_settings'][\Retailcrm\Retailcrm::MODULE . '_apiversion'])
? $_data['saved_settings'][\Retailcrm\Retailcrm::MODULE . '_apiversion']
: null;
if (!empty($url) && !empty($key)) { if (!empty($url) && !empty($key)) {
$_data['delivery'] = $this->model_extension_retailcrm_references $_data['delivery'] = $this->model_extension_retailcrm_references
@ -245,6 +249,9 @@ class ControllerExtensionModuleRetailcrm extends Controller {
->getPaymentTypes($retailcrm_api_client); ->getPaymentTypes($retailcrm_api_client);
$_data['customFields'] = $this->model_extension_retailcrm_references $_data['customFields'] = $this->model_extension_retailcrm_references
->getCustomFields($retailcrm_api_client); ->getCustomFields($retailcrm_api_client);
$_data['priceTypes'] = $this->model_extension_retailcrm_references
->getPriceTypes();
$_data['customerGroups'] = $this->model_customer_customer_group->getCustomerGroups();
} }
$config_data = array( $config_data = array(

View File

@ -20,6 +20,7 @@ class ModelExtensionRetailcrmPrices extends Model
{ {
$this->load->model('catalog/option'); $this->load->model('catalog/option');
$this->load->model('setting/setting'); $this->load->model('setting/setting');
$this->load->model('customer/customer_group');
$prices = $this->getPrices($products, $retailcrm_api_client, $retailcrm); $prices = $this->getPrices($products, $retailcrm_api_client, $retailcrm);
@ -46,33 +47,48 @@ class ModelExtensionRetailcrmPrices extends Model
*/ */
protected function getPrices($products, $retailcrm_api_client, $retailcrm) protected function getPrices($products, $retailcrm_api_client, $retailcrm)
{ {
$settings = $this->model_setting_setting->getSetting(\retailcrm\Retailcrm::MODULE);
$prices = array(); $prices = array();
$site = $this->getSite($retailcrm_api_client); $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) { foreach ($products as $product) {
$specials = $this->model_catalog_product->getProductSpecials($product['product_id']); $specials = $this->model_catalog_product->getProductSpecials($product['product_id']);
if (!$specials) { if (!$specials) {
continue; $productPrice = $this->getEmptyPrice();
$prices[] = $this->getPriceRequest($product, $site, $productPrice, $retailcrm);
} }
$productPrice = array();
if (is_array($specials) && count($specials)) { if (is_array($specials) && count($specials)) {
$productPrice = $this->getSpecialPrice($specials); $productPrice = ModelExtensionRetailcrmPrices::getSpecialPrice($specials);
}
if (!$productPrice) { if (empty($productPrice)) {
continue; continue;
} }
$prices[] = $this->getPriceRequest($product, $site, $productPrice, $retailcrm);
} }
return $prices;
}
/**
* 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); $offers = $retailcrm->getOffers($product);
$pricesProduct = array();
foreach ($offers as $optionsString => $optionsValues) { foreach ($offers as $optionsString => $optionsValues) {
$optionsString = explode('_', $optionsString); $optionsString = explode('_', $optionsString);
@ -101,21 +117,42 @@ class ModelExtensionRetailcrmPrices extends Model
} }
$offerId = implode('_', $offerId); $offerId = implode('_', $offerId);
$price = array();
$prices[] = array( foreach($productPrice as $k => $v) {
'externalId' => $offerId ? $product['product_id'] . '#' . $offerId : $product['product_id'], if (isset($settings[\Retailcrm\Retailcrm::MODULE . '_special_' . $k])) {
'site' => $site, $price[] = array(
'prices' => array( 'code' => $settings[\Retailcrm\Retailcrm::MODULE . '_special_' . $k],
array( 'price' => $v == 0 ? $v : $v + $optionsValues['price']
'code' => $settings[\Retailcrm\Retailcrm::MODULE . '_special'],
'price' => $productPrice + $optionsValues['price']
)
)
); );
} }
} }
return $prices; $pricesProduct = array(
'externalId' => $offerId ? $product['product_id'] . '#' . $offerId : $product['product_id'],
'site' => $site,
'prices' => $price
);
}
return $pricesProduct;
}
/**
* 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;
} }
/** /**
@ -129,18 +166,32 @@ class ModelExtensionRetailcrmPrices extends Model
{ {
$date = date('Y-m-d'); $date = date('Y-m-d');
$always = '0000-00-00'; $always = '0000-00-00';
$productPrice = 0; $productPrice = array();
foreach ($specials as $special) { foreach ($specials as $special) {
if (($special['date_start'] == $always && $special['date_end'] == $always) if (($special['date_start'] == $always && $special['date_end'] == $always)
|| ($special['date_start'] <= $date && $special['date_end'] >= $date) || ($special['date_start'] <= $date && $special['date_end'] >= $date)
) { ) {
if ((isset($groupId) && $groupId == $special['customer_group_id']) || !isset($groupId)) {
if ((isset($priority) && $priority > $special['priority']) if ((isset($priority) && $priority > $special['priority'])
|| !isset($priority) || !isset($priority)
) { ) {
$productPrice = $special['price']; $productPrice[$special['customer_group_id']] = $special['price'];
$priority = $special['priority']; $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;
} }
} }

View File

@ -116,13 +116,16 @@
{% if saved_settings.module_retailcrm_apiversion is defined and saved_settings.module_retailcrm_apiversion != 'v3' %} {% if saved_settings.module_retailcrm_apiversion is defined and saved_settings.module_retailcrm_apiversion != 'v3' %}
<fieldset> <fieldset>
<legend>{{ special_price_settings }}</legend> <legend>{{ special_price_settings }}</legend>
<div class="row form-group retailcrm_unit"> <div class="form-group retailcrm_unit">
<label class="col-sm-2 col-form-label" for="module_retailcrm_special">{{ special_price_settings }}</label> {% for customerGroup in customerGroups %}
{% set cud = customerGroup.customer_group_id %}
<div class="row retailcrm_unit">
<label class="col-sm-2 control-label" for="opencart_customer_group_{{ cud }}">{{ customerGroup.name }}</label>
<div class="col-md-4 col-sm-10"> <div class="col-md-4 col-sm-10">
<select id="module_retailcrm_special" name="module_retailcrm_special" class="form-control"> <select id="module_retailcrm_special_{{ cud }}" name="module_retailcrm_special_{{ cud }}" class="form-control">
{% for priceType in priceTypes %} {% for priceType in priceTypes %}
{% if priceType.active == true %} {% if priceType.active == true and priceType.default == false %}
<option value="{{priceType.code }}" {% if saved_settings.module_retailcrm_special is defined and saved_settings.module_retailcrm_special == priceType.code %} selected="selected" {% endif %}> <option value ="{{ priceType.code }}" {% if saved_settings['module_retailcrm_special_'~cud] is defined and priceType.code == saved_settings['module_retailcrm_special_'~cud] %} selected="selected" {% endif %}>
{{ priceType.name }} {{ priceType.name }}
</option> </option>
{% endif %} {% endif %}
@ -130,6 +133,8 @@
</select> </select>
</div> </div>
</div> </div>
{% endfor %}
</div>
</fieldset> </fieldset>
{% endif %} {% endif %}
<fieldset> <fieldset>

View File

@ -30,7 +30,9 @@ class ModelRetailcrmPricesAdminTest extends OpenCartTest
\Retailcrm\Retailcrm::MODULE, \Retailcrm\Retailcrm::MODULE,
array( array(
\Retailcrm\Retailcrm::MODULE . '_apiversion' => 'v5', \Retailcrm\Retailcrm::MODULE . '_apiversion' => 'v5',
\Retailcrm\Retailcrm::MODULE . '_special' => 'special' \Retailcrm\Retailcrm::MODULE . '_special_1' => 'special1',
\Retailcrm\Retailcrm::MODULE . '_special_2' => 'special2',
\Retailcrm\Retailcrm::MODULE . '_special_3' => 'special3'
) )
); );
} }
@ -50,9 +52,13 @@ class ModelRetailcrmPricesAdminTest extends OpenCartTest
$this->assertInternalType('array', $price); $this->assertInternalType('array', $price);
$this->assertArrayHasKey('externalId', $price); $this->assertArrayHasKey('externalId', $price);
$this->assertArrayHasKey('site', $price); $this->assertArrayHasKey('site', $price);
$this->assertEquals('test_site', $price['site']); $this->assertSame('test_site', $price['site']);
$this->assertArrayHasKey('prices', $price); $this->assertArrayHasKey('prices', $price);
$this->assertInternalType('array', $price['prices']); $this->assertInternalType('array', $price['prices']);
$this->assertSame('special1', $price['prices'][0]['code']);
$this->assertSame('special2', $price['prices'][1]['code']);
$this->assertSame('special3', $price['prices'][2]['code']);
$this->assertSame(0, $price['prices'][2]['price']);
} }
private function getSites() private function getSites()

View File

@ -4,9 +4,13 @@ INSERT INTO `oc_customer` (`customer_id`, `customer_group_id`, `store_id`, `lang
TRUNCATE TABLE `oc_customer_activity`; TRUNCATE TABLE `oc_customer_activity`;
TRUNCATE TABLE `oc_customer_group`; TRUNCATE TABLE `oc_customer_group`;
INSERT INTO `oc_customer_group` (`customer_group_id`, `approval`, `sort_order`) VALUES ('1', '0', '1'); INSERT INTO `oc_customer_group` (`customer_group_id`, `approval`, `sort_order`) VALUES ('1', '0', '1');
INSERT INTO `oc_customer_group` (`customer_group_id`, `approval`, `sort_order`) VALUES ('2', '0', '1');
INSERT INTO `oc_customer_group` (`customer_group_id`, `approval`, `sort_order`) VALUES ('3', '0', '0');
TRUNCATE TABLE `oc_customer_group_description`; TRUNCATE TABLE `oc_customer_group_description`;
INSERT INTO `oc_customer_group_description` (`customer_group_id`, `language_id`, `name`, `description`) VALUES ('1', '1', 'Default', 'test'); INSERT INTO `oc_customer_group_description` (`customer_group_id`, `language_id`, `name`, `description`) VALUES ('1', '1', 'Default', 'test');
INSERT INTO `oc_customer_group_description` (`customer_group_id`, `language_id`, `name`, `description`) VALUES ('2', '1', 'Test2', 'test2');
INSERT INTO `oc_customer_group_description` (`customer_group_id`, `language_id`, `name`, `description`) VALUES ('3', '1', 'test3', 'test3');
TRUNCATE TABLE `oc_customer_history`; TRUNCATE TABLE `oc_customer_history`;
TRUNCATE TABLE `oc_customer_ip`; TRUNCATE TABLE `oc_customer_ip`;
@ -44,5 +48,6 @@ INSERT INTO `oc_order_total` (`order_total_id`, `order_id`, `code`, `title`, `va
INSERT INTO `oc_order_total` (`order_total_id`, `order_id`, `code`, `title`, `value`, `sort_order`) VALUES ('165', '2', 'shipping', 'Flat Rate', '5.0000', '3'); INSERT INTO `oc_order_total` (`order_total_id`, `order_id`, `code`, `title`, `value`, `sort_order`) VALUES ('165', '2', 'shipping', 'Flat Rate', '5.0000', '3');
INSERT INTO `oc_order_total` (`order_total_id`, `order_id`, `code`, `title`, `value`, `sort_order`) VALUES ('163', '1', 'total', 'Total', '106.0000', '9'); INSERT INTO `oc_order_total` (`order_total_id`, `order_id`, `code`, `title`, `value`, `sort_order`) VALUES ('163', '1', 'total', 'Total', '106.0000', '9');
INSERT INTO `oc_order_total` (`order_total_id`, `order_id`, `code`, `title`, `value`, `sort_order`) VALUES ('166', '2', 'total', 'Total', '85.0000', '9'); INSERT INTO `oc_order_total` (`order_total_id`, `order_id`, `code`, `title`, `value`, `sort_order`) VALUES ('166', '2', 'total', 'Total', '85.0000', '9');
INSERT INTO `oc_product_special` (`product_id`, `customer_group_id`, `priority`, `price`,`date_start`, `date_end`) values ('42', '2', '1', '110.000', CURDATE(), ADDDATE(CURDATE(),INTERVAL 10 DAY));
TRUNCATE TABLE `oc_order_voucher`; TRUNCATE TABLE `oc_order_voucher`;