mirror of
https://github.com/retailcrm/opencart-module.git
synced 2024-11-25 14:46:06 +03:00
commit
17140b16c5
@ -1,3 +1,8 @@
|
||||
## v.3.1.3
|
||||
* Добавлена возможность передачи акционных цен для нескольких групп пользователей
|
||||
* Добавлена передача нулевой цены для неустановленных акционных цен
|
||||
* Убрана базовая цена retailcrm из настроек соответствия типов цен
|
||||
|
||||
## v.3.1.2
|
||||
* Добавлен перевод на испанский язык
|
||||
* Переделан перевод на английский язык
|
||||
|
@ -95,6 +95,7 @@ class ControllerExtensionModuleRetailcrm extends Controller {
|
||||
$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 @@ class ControllerExtensionModuleRetailcrm extends Controller {
|
||||
$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 @@ class ControllerExtensionModuleRetailcrm extends Controller {
|
||||
->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(
|
||||
|
@ -20,6 +20,7 @@ class ModelExtensionRetailcrmPrices extends Model
|
||||
{
|
||||
$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,78 +47,111 @@ class ModelExtensionRetailcrmPrices extends Model
|
||||
*/
|
||||
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);
|
||||
|
||||
if (!$productPrice) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
$offers = $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' => $settings[\Retailcrm\Retailcrm::MODULE . '_special'],
|
||||
'price' => $productPrice + $optionsValues['price']
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
$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);
|
||||
$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($settings[\Retailcrm\Retailcrm::MODULE . '_special_' . $k])) {
|
||||
$price[] = array(
|
||||
'code' => $settings[\Retailcrm\Retailcrm::MODULE . '_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 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 actual special
|
||||
*
|
||||
@ -129,21 +163,35 @@ class ModelExtensionRetailcrmPrices extends Model
|
||||
{
|
||||
$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;
|
||||
}
|
||||
|
||||
|
@ -114,23 +114,28 @@
|
||||
</div>
|
||||
</fieldset>
|
||||
{% if saved_settings.module_retailcrm_apiversion is defined and saved_settings.module_retailcrm_apiversion != 'v3' %}
|
||||
<fieldset>
|
||||
<legend>{{ special_price_settings }}</legend>
|
||||
<div class="row form-group retailcrm_unit">
|
||||
<label class="col-sm-2 col-form-label" for="module_retailcrm_special">{{ special_price_settings }}</label>
|
||||
<div class="col-md-4 col-sm-10">
|
||||
<select id="module_retailcrm_special" name="module_retailcrm_special" class="form-control">
|
||||
{% for priceType in priceTypes %}
|
||||
{% if priceType.active == true %}
|
||||
<option value="{{priceType.code }}" {% if saved_settings.module_retailcrm_special is defined and saved_settings.module_retailcrm_special == priceType.code %} selected="selected" {% endif %}>
|
||||
{{ priceType.name }}
|
||||
</option>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</select>
|
||||
<fieldset>
|
||||
<legend>{{ special_price_settings }}</legend>
|
||||
<div class="form-group retailcrm_unit">
|
||||
{% 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">
|
||||
<select id="module_retailcrm_special_{{ cud }}" name="module_retailcrm_special_{{ cud }}" class="form-control">
|
||||
{% for priceType in priceTypes %}
|
||||
{% if priceType.active == true and priceType.default == false %}
|
||||
<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 }}
|
||||
</option>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
</fieldset>
|
||||
{% endif %}
|
||||
<fieldset>
|
||||
<legend>{{ order_number }}</legend>
|
||||
|
@ -30,7 +30,9 @@ class ModelRetailcrmPricesAdminTest extends OpenCartTest
|
||||
\Retailcrm\Retailcrm::MODULE,
|
||||
array(
|
||||
\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->assertArrayHasKey('externalId', $price);
|
||||
$this->assertArrayHasKey('site', $price);
|
||||
$this->assertEquals('test_site', $price['site']);
|
||||
$this->assertSame('test_site', $price['site']);
|
||||
$this->assertArrayHasKey('prices', $price);
|
||||
$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()
|
||||
|
@ -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_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 ('2', '0', '1');
|
||||
INSERT INTO `oc_customer_group` (`customer_group_id`, `approval`, `sort_order`) VALUES ('3', '0', '0');
|
||||
|
||||
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 ('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_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 ('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_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`;
|
Loading…
Reference in New Issue
Block a user