mirror of
https://github.com/retailcrm/opencart-module.git
synced 2024-11-22 05:06:07 +03:00
v3.2.4 Добавлена возможность передачи фкционных цен нескольких групп пользователей
This commit is contained in:
parent
24c6de76ec
commit
6443e10330
@ -1,3 +1,6 @@
|
||||
## v.3.2.4
|
||||
* Изменена передача типов цен с учетом групп пользователей на сайте
|
||||
|
||||
## v.3.2.2
|
||||
* Убрана генерация externalId покупателя при заказе без регистрации на сайте.
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
@ -27,7 +28,7 @@ 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)
|
||||
@ -44,6 +45,7 @@ class ModelExtensionRetailcrmPrices extends Model
|
||||
$retailcrmApiClient->storePricesUpload($priceUpload);
|
||||
}
|
||||
|
||||
|
||||
return $pricesUpload;
|
||||
}
|
||||
|
||||
@ -59,9 +61,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;
|
||||
}
|
||||
|
||||
@ -72,12 +72,14 @@ class ModelExtensionRetailcrmPrices extends Model
|
||||
continue;
|
||||
}
|
||||
|
||||
$productPrice = array();
|
||||
|
||||
if (is_array($specials) && count($specials)) {
|
||||
$productPrice = $this->getSpecialPrice($specials);
|
||||
|
||||
if (!$productPrice) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (empty($productPrice)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$offers = $this->retailcrm->getOffers($product);
|
||||
@ -109,17 +111,23 @@ class ModelExtensionRetailcrmPrices extends Model
|
||||
}
|
||||
|
||||
$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 + $optionsValues['price']
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$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' => $price
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -131,23 +139,29 @@ class ModelExtensionRetailcrmPrices extends Model
|
||||
*
|
||||
* @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($groupId) && $groupId == $special['customer_group_id']) || !isset($groupId)) {
|
||||
if ((isset($priority) && $priority > $special['priority'])
|
||||
|| !isset($priority)
|
||||
) {
|
||||
$productPrice = $special['price'];
|
||||
$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'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -135,19 +135,24 @@
|
||||
<fieldset>
|
||||
<legend><?php echo $special_price_settings; ?></legend>
|
||||
<div class="form-group retailcrm_unit">
|
||||
<label class="col-sm-2 control-label"><?php echo $special_price_settings; ?></label>
|
||||
<?php foreach ($customerGroups as $customerGroup) :?>
|
||||
<?php $cid = $customerGroup['customer_group_id']?>
|
||||
<div class="row retailcrm_unit">
|
||||
<label class="col-sm-2 control-label" style="text-align:right!important;" for="opencart_customer_group_<?php echo $customerGroup['customer_group_id']; ?>"><?php echo $customerGroup['name']; ?></label>
|
||||
<div class="col-md-4 col-sm-10">
|
||||
<select id="retailcrm_special" name="retailcrm_special" class="form-control">
|
||||
<?php foreach ($priceTypes as $priceType) :?>
|
||||
<select id="retailcrm_special_<?php echo $uid; ?>" name="retailcrm_special_<?php echo $uid; ?>" class="form-control">
|
||||
<?php foreach ($priceTypes as $k => $priceType): ?>
|
||||
<?php if ($priceType['active'] == true) :?>
|
||||
<option value="<?php echo $priceType['code']; ?>" <?php if(isset($saved_settings['retailcrm_special']) && $saved_settings['retailcrm_special'] == $priceType['code']):?>selected="selected"<?php endif;?>>
|
||||
<?php echo $priceType['name']; ?>
|
||||
<option value="<?php echo $priceType['code'];?>" <?php if(isset($saved_settings['retailcrm_special_' . $cid]) && $priceType['code'] == $saved_settings['retailcrm_special_' . $cid]):?>selected="selected"<?php endif;?>>
|
||||
<?php echo $priceType['name'];?>
|
||||
</option>
|
||||
<?php endif; ?>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
</fieldset>
|
||||
<?php endif; ?>
|
||||
<fieldset>
|
||||
|
@ -134,12 +134,15 @@
|
||||
<fieldset>
|
||||
<legend>{{ special_price_settings }}</legend>
|
||||
<div class="form-group retailcrm_unit">
|
||||
<label class="col-sm-2 control-label">{{ 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">
|
||||
<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 %}
|
||||
{% 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 %}>
|
||||
<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 %}
|
||||
@ -147,6 +150,8 @@
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</fieldset>
|
||||
{% endif %}
|
||||
<fieldset>
|
||||
|
@ -17,7 +17,8 @@ class ModelRetailcrmPricesAdminTest extends OpenCartTest
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(array(
|
||||
'storePricesUpload',
|
||||
'sitesList'
|
||||
'sitesList',
|
||||
'isSuccessful'
|
||||
))
|
||||
->getMock();
|
||||
|
||||
@ -28,13 +29,23 @@ class ModelRetailcrmPricesAdminTest extends OpenCartTest
|
||||
$this->retailcrm->getModuleTitle(),
|
||||
array(
|
||||
$this->retailcrm->getModuleTitle() . '_apiversion' => 'v5',
|
||||
$this->retailcrm->getModuleTitle() . '_special' => 'special'
|
||||
$this->retailcrm->getModuleTitle() . '_special_1' => 'special1',
|
||||
$this->retailcrm->getModuleTitle() . '_special_2' => 'special2'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function testUploadPrices()
|
||||
{
|
||||
|
||||
$response = new \RetailcrmApiResponse(
|
||||
201,
|
||||
json_encode(
|
||||
$this->sites()
|
||||
)
|
||||
);
|
||||
|
||||
$this->apiClientMock->expects($this->any())->method('sitesList')->willReturn($response);
|
||||
$productModel = $this->loadModel('catalog/product');
|
||||
$products = $productModel->getProducts();
|
||||
$prices = $this->pricesModel->uploadPrices($products, $this->apiClientMock);
|
||||
@ -48,4 +59,30 @@ class ModelRetailcrmPricesAdminTest extends OpenCartTest
|
||||
$this->assertArrayHasKey('prices', $price);
|
||||
$this->assertInternalType('array', $price['prices']);
|
||||
}
|
||||
|
||||
private function sites(){
|
||||
return array(
|
||||
"success"=> true,
|
||||
"sites"=> array(
|
||||
"BitrixMod"=> array(
|
||||
"name"=> "site",
|
||||
"url"=> "http://site.ru",
|
||||
"code"=> "site",
|
||||
"defaultForCrm"=> false,
|
||||
"ymlUrl"=> "http://site.ru/retailcrm.xml",
|
||||
"loadFromYml"=> false,
|
||||
"catalogUpdatedAt"=> "2019-02-08 13:30:37",
|
||||
"catalogLoadingAt"=> "2019-02-11 09:12:18",
|
||||
"contragent"=> array(
|
||||
"contragentType"=> "legal-entity",
|
||||
"legalName"=> "code",
|
||||
"code"=> "code",
|
||||
"countryIso"=> "RU",
|
||||
"vatRate"=> "",
|
||||
),
|
||||
"countryIso"=> "",
|
||||
)
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user