Skip to content

Commit

Permalink
ref #95381 Support for services in ICML (#265)
Browse files Browse the repository at this point in the history
  • Loading branch information
uryvskiy-dima authored May 6, 2024
1 parent d5f29dc commit c893cf2
Show file tree
Hide file tree
Showing 11 changed files with 121 additions and 57 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## v4.1.16
* Support for services in ICML

## v4.1.15
* Display module version

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.1.15
4.1.16
6 changes: 4 additions & 2 deletions src/upload/admin/controller/extension/module/retailcrm.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class ControllerExtensionModuleRetailcrm extends Controller
{
const VERSION_MODULE = '4.1.15';
const VERSION_MODULE = '4.1.16';

private $_error = [];
protected $log, $statuses, $payments, $deliveryTypes, $retailcrmApiClient, $moduleTitle, $tokenTitle;
Expand Down Expand Up @@ -301,7 +301,9 @@ public function index()
'special_price',
'order_number',
'text_order_number',
'text_currency',
'icml_settings',
'icml_service_enabled_label',
'icml_service_description',
'text_currency_label',
'status_changes',
'text_status_changes',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,12 @@

$_['order_number'] = 'Order number';
$_['text_order_number'] = 'Upload the order number to RetailCRM';
$_['text_currency'] = 'Currency setting';
$_['text_currency_label'] = 'Currency in ICML';
$_['icml_settings'] = 'ICML settings';
$_['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_label'] = 'Unit of measurement in ICML';
$_['text_lenght_label'] = 'Unit of measurement of goods';
$_['status_changes'] = 'History of changes';
$_['text_status_changes'] = 'Record changes to the order history of Opencart';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,13 @@

$_['order_number'] = 'Número de pedido';
$_['text_order_number'] = 'Transferir número de pedido a RetailCRM';
$_['text_currency'] = 'Ajustes de moneda';
$_['text_currency_label'] = 'Moneda en ICML';
$_['icml_settings'] = 'Ajustes de 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_label'] = 'Unidad de medida en ICML';
$_['text_lenght_label'] = 'Unidad de medida de bienes';
$_['status_changes'] = 'Historial de cambios';
$_['text_status_changes'] = 'Registrar los cambios en el historial de pedidos de Opencart';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,12 @@

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

Expand Down
69 changes: 39 additions & 30 deletions src/upload/admin/model/extension/retailcrm/icml.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ModelExtensionRetailcrmIcml extends Model

/**
* Constructor
*
*
* @param Registry $registry
*/
public function __construct($registry)
Expand Down Expand Up @@ -78,7 +78,7 @@ public function generateICML()
*/
private function addCategories()
{
$categories = $this->model_catalog_category->getCategories(array());
$categories = $this->model_catalog_category->getCategories([]);
foreach ($categories as $category) {
$category = $this->model_catalog_category->getCategory($category['category_id']);

Expand All @@ -103,7 +103,8 @@ private function addCategories()
}

private function addOffers() {
$offerManufacturers = array();
$offerManufacturers = [];
$servicesForIcml = $this->retailcrm->useServicesForIcml();
$currencyForIcml = $this->retailcrm->getCurrencyForIcml();
$defaultCurrency = $this->getDefaultCurrency();
$settingLenght = $this->retailcrm->getLenghtForIcml();
Expand All @@ -122,20 +123,20 @@ private function addOffers() {
}

$manufacturers = $this->model_catalog_manufacturer
->getManufacturers(array());
->getManufacturers([]);

foreach ($manufacturers as $manufacturer) {
$offerManufacturers[$manufacturer['manufacturer_id']] = $manufacturer['name'];
}

$products = $this->model_catalog_product->getProducts(array());
$products = $this->model_catalog_product->getProducts([]);

foreach ($products as $product) {
$offers = $this->retailcrm->getOffers($product);

foreach ($offers as $optionsString => $optionsValues) {
$optionsString = explode('_', $optionsString);
$options = array();
$options = [];

foreach($optionsString as $optionString) {
$option = explode('-', $optionString);
Expand All @@ -150,35 +151,43 @@ private function addOffers() {
'value_id' => $option[1],
'option_id' => $optionIds[1]
);
}
}
}
}

ksort($options);

$offerId = array();
$offerId = [];

foreach($options as $optionKey => $optionData) {
$offerId[] = $optionKey.'-'.$optionData['value_id'];
}

$offerId = implode('_', $offerId);
$e = $this->eOffers->appendChild($this->dd->createElement('offer'));
$catalog = $this->eOffers->appendChild($this->dd->createElement('offer'));

if (!empty($offerId)) {
$e->setAttribute('id', $product['product_id'] . '#' . $offerId);
$e->setAttribute('productId', $product['product_id']);
$e->setAttribute('quantity', $optionsValues['qty']);
$catalog->setAttribute('id', $product['product_id'] . '#' . $offerId);
$catalog->setAttribute('productId', $product['product_id']);
$catalog->setAttribute('quantity', $optionsValues['qty']);
} else {
$e->setAttribute('id', $product['product_id']);
$e->setAttribute('productId', $product['product_id']);
$e->setAttribute('quantity', $product['quantity']);
$catalog->setAttribute('id', $product['product_id']);
$catalog->setAttribute('productId', $product['product_id']);
$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
*/
$activity = $product['status'] == 1 ? 'Y' : 'N';
$e->appendChild(
$catalog->appendChild(
$this->dd->createElement('productActivity')
)->appendChild(
$this->dd->createTextNode($activity)
Expand All @@ -190,7 +199,7 @@ private function addOffers() {
->getProductCategories($product['product_id']);
if (!empty($categories)) {
foreach ($categories as $category) {
$e->appendChild($this->dd->createElement('categoryId'))
$catalog->appendChild($this->dd->createElement('categoryId'))
->appendChild(
$this->dd->createTextNode($category)
);
Expand All @@ -199,18 +208,18 @@ private function addOffers() {
/**
* Name & price
*/
$e->appendChild($this->dd->createElement('productName'))
$catalog->appendChild($this->dd->createElement('productName'))
->appendChild($this->dd->createTextNode($product['name']));
if (!empty($options)) {
$optionsString = array();
$optionsString = [];
foreach($options as $option) {
$optionsString[] = $option['name'].': '.$option['value'];
}
$optionsString = ' ('.implode(', ', $optionsString).')';
$e->appendChild($this->dd->createElement('name'))
$catalog->appendChild($this->dd->createElement('name'))
->appendChild($this->dd->createTextNode($product['name'].$optionsString));
} else {
$e->appendChild($this->dd->createElement('name'))
$catalog->appendChild($this->dd->createElement('name'))
->appendChild($this->dd->createTextNode($product['name']));
}

Expand All @@ -224,13 +233,13 @@ private function addOffers() {
$price = $product['price'] + $optionsValues['price'];
}

$e->appendChild($this->dd->createElement('price'))
$catalog->appendChild($this->dd->createElement('price'))
->appendChild($this->dd->createTextNode($price));
/**
* Vendor
*/
if ($product['manufacturer_id'] != 0) {
$e->appendChild($this->dd->createElement('vendor'))
$catalog->appendChild($this->dd->createElement('vendor'))
->appendChild(
$this->dd->createTextNode(
$offerManufacturers[$product['manufacturer_id']]
Expand Down Expand Up @@ -271,7 +280,7 @@ private function addOffers() {
$productHeight
);

$e->appendChild($this->dd->createElement('dimensions'))
$catalog->appendChild($this->dd->createElement('dimensions'))
->appendChild($this->dd->createTextNode($dimensions));
}

Expand All @@ -280,14 +289,14 @@ private function addOffers() {
*/
if ($product['image']) {
$image = $this->generateImage($product['image']);
$e->appendChild($this->dd->createElement('picture'))
$catalog->appendChild($this->dd->createElement('picture'))
->appendChild($this->dd->createTextNode($image));
}
/**
* Url
*/
$this->url = new Url(HTTP_CATALOG, HTTPS_CATALOG);
$e->appendChild($this->dd->createElement('url'))
$catalog->appendChild($this->dd->createElement('url'))
->appendChild(
$this->dd->createTextNode(
$this->url->link(
Expand All @@ -305,15 +314,15 @@ private function addOffers() {
$param->setAttribute('code', $optionData['option_id']);
$param->setAttribute('name', $optionData['name']);
$param->appendChild($this->dd->createTextNode($optionData['value']));
$e->appendChild($param);
$catalog->appendChild($param);
}
}
if ($product['sku']) {
$sku = $this->dd->createElement('param');
$sku->setAttribute('code', 'article');
$sku->setAttribute('name', $this->language->get('article'));
$sku->appendChild($this->dd->createTextNode($product['sku']));
$e->appendChild($sku);
$catalog->appendChild($sku);
}
if ($product['weight'] != '') {
$weight = $this->dd->createElement('weight');
Expand All @@ -330,7 +339,7 @@ private function addOffers() {
$weightValue = round($weightValue / $coeffWeight, 6);

$weight->appendChild($this->dd->createTextNode($weightValue));
$e->appendChild($weight);
$catalog->appendChild($weight);
}
}
}
Expand All @@ -343,7 +352,7 @@ private function addOffers() {
private function generateImage($image)
{
$this->load->model('tool/image');

$currentTheme = $this->config->get('config_theme');
$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;
Expand Down
8 changes: 7 additions & 1 deletion src/upload/admin/view/stylesheet/retailcrm.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
.retailcrm_unit {margin-bottom: 10px;}
.retailcrm_disable_border {border: none !important;}
.retailcrm_unit input {width: 30%;}
.checkbox input{width: auto;}
.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;
}
20 changes: 16 additions & 4 deletions src/upload/admin/view/template/extension/module/retailcrm.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,22 @@
</div>
</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">
<label class="col-sm-2 control-label"><?php echo $text_currency; ?></label>
<div class="col-md-4 col-sm-10">
Expand All @@ -112,9 +127,6 @@
</select>
</div>
</div>
</fieldset>
<fieldset>
<legend><?php echo $text_lenght; ?></legend>
<div class="form-group retailcrm_unit">
<label class="col-sm-2 control-label"><?php echo $text_lenght_label; ?></label>
<div class="col-md-4 col-sm-10">
Expand Down
Loading

0 comments on commit c893cf2

Please sign in to comment.