ref #95381 Support for services in ICML (#265)

This commit is contained in:
Uryvskiy Dima 2024-05-06 09:07:38 +03:00 committed by GitHub
parent d5f29dc5fe
commit c893cf24fb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 121 additions and 57 deletions

View File

@ -1,3 +1,6 @@
## v4.1.16
* Support for services in ICML
## v4.1.15 ## v4.1.15
* Display module version * Display module version

View File

@ -1 +1 @@
4.1.15 4.1.16

View File

@ -2,7 +2,7 @@
class ControllerExtensionModuleRetailcrm extends Controller class ControllerExtensionModuleRetailcrm extends Controller
{ {
const VERSION_MODULE = '4.1.15'; const VERSION_MODULE = '4.1.16';
private $_error = []; private $_error = [];
protected $log, $statuses, $payments, $deliveryTypes, $retailcrmApiClient, $moduleTitle, $tokenTitle; protected $log, $statuses, $payments, $deliveryTypes, $retailcrmApiClient, $moduleTitle, $tokenTitle;
@ -301,7 +301,9 @@ class ControllerExtensionModuleRetailcrm extends Controller
'special_price', 'special_price',
'order_number', 'order_number',
'text_order_number', 'text_order_number',
'text_currency', 'icml_settings',
'icml_service_enabled_label',
'icml_service_description',
'text_currency_label', 'text_currency_label',
'status_changes', 'status_changes',
'text_status_changes', 'text_status_changes',

View File

@ -72,10 +72,12 @@ $_['retailcrm_missing_status'] = 'Status of lost orders';
$_['order_number'] = 'Order number'; $_['order_number'] = 'Order number';
$_['text_order_number'] = 'Upload the order number to RetailCRM'; $_['text_order_number'] = 'Upload the order number to RetailCRM';
$_['text_currency'] = 'Currency setting'; $_['icml_settings'] = 'ICML settings';
$_['text_currency_label'] = 'Currency in ICML'; $_['icml_service_enabled_label'] = 'Upload services in ICML';
$_['icml_service_description'] = 'When the option is enabled, all products for which delivery is disabled will be considered as services and uploaded to CRM as services';
$_['text_currency_label'] = 'Currency of goods';
$_['text_lenght'] = 'Setting of the unit of measurement'; $_['text_lenght'] = 'Setting of the unit of measurement';
$_['text_lenght_label'] = 'Unit of measurement in ICML'; $_['text_lenght_label'] = 'Unit of measurement of goods';
$_['status_changes'] = 'History of changes'; $_['status_changes'] = 'History of changes';
$_['text_status_changes'] = 'Record changes to the order history of Opencart'; $_['text_status_changes'] = 'Record changes to the order history of Opencart';

View File

@ -72,10 +72,13 @@ $_['retailcrm_missing_status'] = 'Estado de pedidos perdidos';
$_['order_number'] = 'Número de pedido'; $_['order_number'] = 'Número de pedido';
$_['text_order_number'] = 'Transferir número de pedido a RetailCRM'; $_['text_order_number'] = 'Transferir número de pedido a RetailCRM';
$_['text_currency'] = 'Ajustes de moneda'; $_['icml_settings'] = 'Ajustes de ICML';
$_['text_currency_label'] = 'Moneda en ICML'; $_['icml_service_enabled_label'] = 'Subir servicios de ICML';
$_['icml_service_description'] = 'Si habilita la opción, todos los productos para los que la entrega está desactivada se tratarán como servicios y se cargarán en CRM como servicios';
$_['text_currency_label'] = 'Moneda de bienes';
$_['text_lenght'] = 'Ajustar unidad de medida'; $_['text_lenght'] = 'Ajustar unidad de medida';
$_['text_lenght_label'] = 'Unidad de medida en ICML'; $_['text_lenght_label'] = 'Unidad de medida de bienes';
$_['status_changes'] = 'Historial de cambios'; $_['status_changes'] = 'Historial de cambios';
$_['text_status_changes'] = 'Registrar los cambios en el historial de pedidos de Opencart'; $_['text_status_changes'] = 'Registrar los cambios en el historial de pedidos de Opencart';

View File

@ -72,10 +72,12 @@ $_['retailcrm_missing_status'] = 'Статус пропавших заказо
$_['order_number'] = 'Номер заказа'; $_['order_number'] = 'Номер заказа';
$_['text_order_number'] = 'Передавать номер заказа в RetailCRM'; $_['text_order_number'] = 'Передавать номер заказа в RetailCRM';
$_['text_currency'] = 'Настройка валюты'; $_['icml_settings'] = 'Настройки ICML';
$_['text_currency_label'] = 'Валюта в ICML'; $_['icml_service_enabled_label'] = 'Выгружать услуги в ICML';
$_['icml_service_description'] = 'При включении опции все товары, для которых отключена доставка, будут рассматриваться как услуги и загружаться в CRM как услуги';
$_['text_currency_label'] = 'Валюта товаров';
$_['text_lenght'] = 'Настройка единицы измерения'; $_['text_lenght'] = 'Настройка единицы измерения';
$_['text_lenght_label'] = 'Единица измерения в ICML'; $_['text_lenght_label'] = 'Единица измерения товаров';
$_['status_changes'] = 'История изменений'; $_['status_changes'] = 'История изменений';
$_['text_status_changes'] = 'Фиксировать изменения в истории заказа Opencart'; $_['text_status_changes'] = 'Фиксировать изменения в истории заказа Opencart';

View File

@ -15,7 +15,7 @@ class ModelExtensionRetailcrmIcml extends Model
/** /**
* Constructor * Constructor
* *
* @param Registry $registry * @param Registry $registry
*/ */
public function __construct($registry) public function __construct($registry)
@ -78,7 +78,7 @@ class ModelExtensionRetailcrmIcml extends Model
*/ */
private function addCategories() private function addCategories()
{ {
$categories = $this->model_catalog_category->getCategories(array()); $categories = $this->model_catalog_category->getCategories([]);
foreach ($categories as $category) { foreach ($categories as $category) {
$category = $this->model_catalog_category->getCategory($category['category_id']); $category = $this->model_catalog_category->getCategory($category['category_id']);
@ -103,7 +103,8 @@ class ModelExtensionRetailcrmIcml extends Model
} }
private function addOffers() { private function addOffers() {
$offerManufacturers = array(); $offerManufacturers = [];
$servicesForIcml = $this->retailcrm->useServicesForIcml();
$currencyForIcml = $this->retailcrm->getCurrencyForIcml(); $currencyForIcml = $this->retailcrm->getCurrencyForIcml();
$defaultCurrency = $this->getDefaultCurrency(); $defaultCurrency = $this->getDefaultCurrency();
$settingLenght = $this->retailcrm->getLenghtForIcml(); $settingLenght = $this->retailcrm->getLenghtForIcml();
@ -122,20 +123,20 @@ class ModelExtensionRetailcrmIcml extends Model
} }
$manufacturers = $this->model_catalog_manufacturer $manufacturers = $this->model_catalog_manufacturer
->getManufacturers(array()); ->getManufacturers([]);
foreach ($manufacturers as $manufacturer) { foreach ($manufacturers as $manufacturer) {
$offerManufacturers[$manufacturer['manufacturer_id']] = $manufacturer['name']; $offerManufacturers[$manufacturer['manufacturer_id']] = $manufacturer['name'];
} }
$products = $this->model_catalog_product->getProducts(array()); $products = $this->model_catalog_product->getProducts([]);
foreach ($products as $product) { foreach ($products as $product) {
$offers = $this->retailcrm->getOffers($product); $offers = $this->retailcrm->getOffers($product);
foreach ($offers as $optionsString => $optionsValues) { foreach ($offers as $optionsString => $optionsValues) {
$optionsString = explode('_', $optionsString); $optionsString = explode('_', $optionsString);
$options = array(); $options = [];
foreach($optionsString as $optionString) { foreach($optionsString as $optionString) {
$option = explode('-', $optionString); $option = explode('-', $optionString);
@ -150,35 +151,43 @@ class ModelExtensionRetailcrmIcml extends Model
'value_id' => $option[1], 'value_id' => $option[1],
'option_id' => $optionIds[1] 'option_id' => $optionIds[1]
); );
} }
} }
} }
ksort($options); ksort($options);
$offerId = array(); $offerId = [];
foreach($options as $optionKey => $optionData) { foreach($options as $optionKey => $optionData) {
$offerId[] = $optionKey.'-'.$optionData['value_id']; $offerId[] = $optionKey.'-'.$optionData['value_id'];
} }
$offerId = implode('_', $offerId); $offerId = implode('_', $offerId);
$e = $this->eOffers->appendChild($this->dd->createElement('offer')); $catalog = $this->eOffers->appendChild($this->dd->createElement('offer'));
if (!empty($offerId)) { if (!empty($offerId)) {
$e->setAttribute('id', $product['product_id'] . '#' . $offerId); $catalog->setAttribute('id', $product['product_id'] . '#' . $offerId);
$e->setAttribute('productId', $product['product_id']); $catalog->setAttribute('productId', $product['product_id']);
$e->setAttribute('quantity', $optionsValues['qty']); $catalog->setAttribute('quantity', $optionsValues['qty']);
} else { } else {
$e->setAttribute('id', $product['product_id']); $catalog->setAttribute('id', $product['product_id']);
$e->setAttribute('productId', $product['product_id']); $catalog->setAttribute('productId', $product['product_id']);
$e->setAttribute('quantity', $product['quantity']); $catalog->setAttribute('quantity', $product['quantity']);
} }
/**
* Set type for offers
*/
$useServices = $servicesForIcml && isset($product['shipping']) && $product['shipping'] == 0;
$catalog->setAttribute('type', $useServices ? 'service' : 'product');
/** /**
* Offer activity * Offer activity
*/ */
$activity = $product['status'] == 1 ? 'Y' : 'N'; $activity = $product['status'] == 1 ? 'Y' : 'N';
$e->appendChild( $catalog->appendChild(
$this->dd->createElement('productActivity') $this->dd->createElement('productActivity')
)->appendChild( )->appendChild(
$this->dd->createTextNode($activity) $this->dd->createTextNode($activity)
@ -190,7 +199,7 @@ class ModelExtensionRetailcrmIcml extends Model
->getProductCategories($product['product_id']); ->getProductCategories($product['product_id']);
if (!empty($categories)) { if (!empty($categories)) {
foreach ($categories as $category) { foreach ($categories as $category) {
$e->appendChild($this->dd->createElement('categoryId')) $catalog->appendChild($this->dd->createElement('categoryId'))
->appendChild( ->appendChild(
$this->dd->createTextNode($category) $this->dd->createTextNode($category)
); );
@ -199,18 +208,18 @@ class ModelExtensionRetailcrmIcml extends Model
/** /**
* Name & price * Name & price
*/ */
$e->appendChild($this->dd->createElement('productName')) $catalog->appendChild($this->dd->createElement('productName'))
->appendChild($this->dd->createTextNode($product['name'])); ->appendChild($this->dd->createTextNode($product['name']));
if (!empty($options)) { if (!empty($options)) {
$optionsString = array(); $optionsString = [];
foreach($options as $option) { foreach($options as $option) {
$optionsString[] = $option['name'].': '.$option['value']; $optionsString[] = $option['name'].': '.$option['value'];
} }
$optionsString = ' ('.implode(', ', $optionsString).')'; $optionsString = ' ('.implode(', ', $optionsString).')';
$e->appendChild($this->dd->createElement('name')) $catalog->appendChild($this->dd->createElement('name'))
->appendChild($this->dd->createTextNode($product['name'].$optionsString)); ->appendChild($this->dd->createTextNode($product['name'].$optionsString));
} else { } else {
$e->appendChild($this->dd->createElement('name')) $catalog->appendChild($this->dd->createElement('name'))
->appendChild($this->dd->createTextNode($product['name'])); ->appendChild($this->dd->createTextNode($product['name']));
} }
@ -224,13 +233,13 @@ class ModelExtensionRetailcrmIcml extends Model
$price = $product['price'] + $optionsValues['price']; $price = $product['price'] + $optionsValues['price'];
} }
$e->appendChild($this->dd->createElement('price')) $catalog->appendChild($this->dd->createElement('price'))
->appendChild($this->dd->createTextNode($price)); ->appendChild($this->dd->createTextNode($price));
/** /**
* Vendor * Vendor
*/ */
if ($product['manufacturer_id'] != 0) { if ($product['manufacturer_id'] != 0) {
$e->appendChild($this->dd->createElement('vendor')) $catalog->appendChild($this->dd->createElement('vendor'))
->appendChild( ->appendChild(
$this->dd->createTextNode( $this->dd->createTextNode(
$offerManufacturers[$product['manufacturer_id']] $offerManufacturers[$product['manufacturer_id']]
@ -271,7 +280,7 @@ class ModelExtensionRetailcrmIcml extends Model
$productHeight $productHeight
); );
$e->appendChild($this->dd->createElement('dimensions')) $catalog->appendChild($this->dd->createElement('dimensions'))
->appendChild($this->dd->createTextNode($dimensions)); ->appendChild($this->dd->createTextNode($dimensions));
} }
@ -280,14 +289,14 @@ class ModelExtensionRetailcrmIcml extends Model
*/ */
if ($product['image']) { if ($product['image']) {
$image = $this->generateImage($product['image']); $image = $this->generateImage($product['image']);
$e->appendChild($this->dd->createElement('picture')) $catalog->appendChild($this->dd->createElement('picture'))
->appendChild($this->dd->createTextNode($image)); ->appendChild($this->dd->createTextNode($image));
} }
/** /**
* Url * Url
*/ */
$this->url = new Url(HTTP_CATALOG, HTTPS_CATALOG); $this->url = new Url(HTTP_CATALOG, HTTPS_CATALOG);
$e->appendChild($this->dd->createElement('url')) $catalog->appendChild($this->dd->createElement('url'))
->appendChild( ->appendChild(
$this->dd->createTextNode( $this->dd->createTextNode(
$this->url->link( $this->url->link(
@ -305,7 +314,7 @@ class ModelExtensionRetailcrmIcml extends Model
$param->setAttribute('code', $optionData['option_id']); $param->setAttribute('code', $optionData['option_id']);
$param->setAttribute('name', $optionData['name']); $param->setAttribute('name', $optionData['name']);
$param->appendChild($this->dd->createTextNode($optionData['value'])); $param->appendChild($this->dd->createTextNode($optionData['value']));
$e->appendChild($param); $catalog->appendChild($param);
} }
} }
if ($product['sku']) { if ($product['sku']) {
@ -313,7 +322,7 @@ class ModelExtensionRetailcrmIcml extends Model
$sku->setAttribute('code', 'article'); $sku->setAttribute('code', 'article');
$sku->setAttribute('name', $this->language->get('article')); $sku->setAttribute('name', $this->language->get('article'));
$sku->appendChild($this->dd->createTextNode($product['sku'])); $sku->appendChild($this->dd->createTextNode($product['sku']));
$e->appendChild($sku); $catalog->appendChild($sku);
} }
if ($product['weight'] != '') { if ($product['weight'] != '') {
$weight = $this->dd->createElement('weight'); $weight = $this->dd->createElement('weight');
@ -330,7 +339,7 @@ class ModelExtensionRetailcrmIcml extends Model
$weightValue = round($weightValue / $coeffWeight, 6); $weightValue = round($weightValue / $coeffWeight, 6);
$weight->appendChild($this->dd->createTextNode($weightValue)); $weight->appendChild($this->dd->createTextNode($weightValue));
$e->appendChild($weight); $catalog->appendChild($weight);
} }
} }
} }
@ -343,7 +352,7 @@ class ModelExtensionRetailcrmIcml extends Model
private function generateImage($image) private function generateImage($image)
{ {
$this->load->model('tool/image'); $this->load->model('tool/image');
$currentTheme = $this->config->get('config_theme'); $currentTheme = $this->config->get('config_theme');
$width = $this->config->get($currentTheme . '_image_related_width') ? $this->config->get($currentTheme . '_image_related_width') : 200; $width = $this->config->get($currentTheme . '_image_related_width') ? $this->config->get($currentTheme . '_image_related_width') : 200;
$height = $this->config->get($currentTheme . '_image_related_height') ? $this->config->get($currentTheme . '_image_related_height') : 200; $height = $this->config->get($currentTheme . '_image_related_height') ? $this->config->get($currentTheme . '_image_related_height') : 200;

View File

@ -1,5 +1,11 @@
.retailcrm_unit {margin-bottom: 10px;} .retailcrm_unit {margin-bottom: 10px;}
.retailcrm_disable_border {border: none !important;}
.retailcrm_unit input {width: 30%;} .retailcrm_unit input {width: 30%;}
.checkbox input{width: auto;} .checkbox input{width: auto;}
.retailcrm_unit input[type=checkbox] {width: 13px;} .retailcrm_unit input[type=checkbox] {width: 13px;}
.retailcrm_unit select {max-width: 500px;} .retailcrm_unit select {max-width: 500px;}
.question-mark {
cursor: help;
position: relative;
}

View File

@ -97,7 +97,22 @@
</div> </div>
</fieldset> </fieldset>
<fieldset> <fieldset>
<legend><?php echo $text_currency; ?></legend> <legend><?php echo $icml_settings; ?></legend>
<div class="form-group retailcrm_unit">
<label class="col-sm-2 control-label question-mark" for="retailcrm_icml_service_enabled" title="When the option is enabled, all products for which delivery is disabled will be considered as services and uploaded to CRM as services"><?php echo $icml_service_enabled_label; ?></label>
<div class="col-sm-10">
<label class="radio-inline">
<input type="radio" name="retailcrm_icml_service_enabled value="1"
<?php if(isset($saved_settings['retailcrm_icml_service_enabled']) && $saved_settings['retailcrm_icml_service_enabled'] == 1): echo 'checked'; endif;?>/>
<?php echo $text_yes; ?>
</label>
<label class="radio-inline">
<input type="radio" name="retailcrm_icml_service_enabled" value="0"
<?php if(!isset($saved_settings['retailcrm_icml_service_enabled']) || $saved_settings['retailcrm_icml_service_enabled'] == 0): echo 'checked'; endif;?>/>
<?php echo $text_no; ?>
</label>
</div>
</div
<div class="form-group retailcrm_unit"> <div class="form-group retailcrm_unit">
<label class="col-sm-2 control-label"><?php echo $text_currency; ?></label> <label class="col-sm-2 control-label"><?php echo $text_currency; ?></label>
<div class="col-md-4 col-sm-10"> <div class="col-md-4 col-sm-10">
@ -112,9 +127,6 @@
</select> </select>
</div> </div>
</div> </div>
</fieldset>
<fieldset>
<legend><?php echo $text_lenght; ?></legend>
<div class="form-group retailcrm_unit"> <div class="form-group retailcrm_unit">
<label class="col-sm-2 control-label"><?php echo $text_lenght_label; ?></label> <label class="col-sm-2 control-label"><?php echo $text_lenght_label; ?></label>
<div class="col-md-4 col-sm-10"> <div class="col-md-4 col-sm-10">

View File

@ -55,7 +55,7 @@
<input class="form-control" id="retailcrm_url" type="text" name="module_retailcrm_url" value="{% if saved_settings.module_retailcrm_url is defined %}{{ saved_settings.module_retailcrm_url }}{% endif %}"> <input class="form-control" id="retailcrm_url" type="text" name="module_retailcrm_url" value="{% if saved_settings.module_retailcrm_url is defined %}{{ saved_settings.module_retailcrm_url }}{% endif %}">
</div> </div>
</div> </div>
<div class="form-group retailcrm_unit"> <div class="form-group retailcrm_unit retailcrm_disable_border">
<label class="col-sm-2 control-label" for="retailcrm_apikey">{{ retailcrm_apikey }}</label> <label class="col-sm-2 control-label" for="retailcrm_apikey">{{ retailcrm_apikey }}</label>
<div class="col-lg-4 col-md-6 col-sm-10"> <div class="col-lg-4 col-md-6 col-sm-10">
<input class="form-control" id="retailcrm_apikey" type="text" name="module_retailcrm_apikey" value="{% if saved_settings.module_retailcrm_apikey is defined %}{{ saved_settings.module_retailcrm_apikey }}{% endif %}"> <input class="form-control" id="retailcrm_apikey" type="text" name="module_retailcrm_apikey" value="{% if saved_settings.module_retailcrm_apikey is defined %}{{ saved_settings.module_retailcrm_apikey }}{% endif %}">
@ -100,8 +100,27 @@
</div> </div>
</fieldset> </fieldset>
<fieldset> <fieldset>
<legend>{{ text_currency }}</legend> <legend>{{ icml_settings }}</legend>
<div class="form-group retailcrm_unit"> <div class="form-group retailcrm_unit retailcrm_disable_border">
<label class="col-sm-2 control-label question-mark" for="module_retailcrm_icml_service_enabled" title="{{ icml_service_description }}">{{ icml_service_enabled_label }}</label>
<div class="col-sm-10">
<label class="radio-inline">
<input type="radio" name="module_retailcrm_icml_service_enabled" value="1"
{% if saved_settings.module_retailcrm_icml_service_enabled is defined and saved_settings.module_retailcrm_icml_service_enabled == 1 %}
checked
{% endif %} />
{{ text_yes }}
</label>
<label class="radio-inline">
<input type="radio" name="module_retailcrm_icml_service_enabled" value="0"
{% if saved_settings.module_retailcrm_icml_service_enabled is not defined or saved_settings.module_retailcrm_icml_service_enabled == 0 %}
checked
{% endif %} />
{{ text_no }}
</label>
</div>
</div>
<div class="form-group retailcrm_unit retailcrm_disable_border">
<label class="col-sm-2 control-label">{{ text_currency_label }}</label> <label class="col-sm-2 control-label">{{ text_currency_label }}</label>
<div class="col-md-4 col-sm-10"> <div class="col-md-4 col-sm-10">
<select id="module_retailcrm_currency" name="module_retailcrm_currency" class="form-control"> <select id="module_retailcrm_currency" name="module_retailcrm_currency" class="form-control">
@ -115,17 +134,14 @@
</select> </select>
</div> </div>
</div> </div>
</fieldset> <div class="form-group retailcrm_unit retailcrm_disable_border">
<fieldset>
<legend>{{ text_lenght }}</legend>
<div class="form-group retailcrm_unit">
<label class="col-sm-2 control-label">{{ text_lenght_label }}</label> <label class="col-sm-2 control-label">{{ text_lenght_label }}</label>
<div class="col-md-4 col-sm-10"> <div class="col-md-4 col-sm-10">
<select id="module_retailcrm_lenght" name="module_retailcrm_lenght" class="form-control"> <select id="module_retailcrm_lenght" name="module_retailcrm_lenght" class="form-control">
{% for lenght in lenghts %} {% for lenght in lenghts %}
<option value="{{ lenght.length_class_id }}" {% if saved_settings.module_retailcrm_lenght is defined and saved_settings.module_retailcrm_lenght == lenght.length_class_id %} selected="selected" {% endif %}> <option value="{{ lenght.length_class_id }}" {% if saved_settings.module_retailcrm_lenght is defined and saved_settings.module_retailcrm_lenght == lenght.length_class_id %} selected="selected" {% endif %}>
{{ lenght.title }} {{ lenght.title }}
</option> </option>
{% endfor %} {% endfor %}
</select> </select>
</div> </div>

View File

@ -242,6 +242,15 @@ class Retailcrm {
return false; return false;
} }
public function useServicesForIcml()
{
$this->load->model('setting/setting');
$setting = $this->model_setting_setting->getSetting($this->getModuleTitle());
return $setting['module_retailcrm_icml_service_enabled'] ?? false;
}
/** /**
* @return mixed * @return mixed
*/ */