Skip to content

Commit

Permalink
ref #95242 Support for services in ICML (#329)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kocmonavtik authored Apr 24, 2024
1 parent 90d7e1f commit 8627548
Show file tree
Hide file tree
Showing 17 changed files with 84 additions and 8 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 2024-04-23 4.7.7
* Added transfer of services via ICML catalog

## 2024-04-22 4.7.6
* Support WP 6.5

Expand Down
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,3 @@ coverage:

build_archive:
zip -r $(ARCHIVE_NAME) ./src/*

2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.7.6
4.7.7
8 changes: 7 additions & 1 deletion resources/pot/retailcrm-es_ES.pot
Original file line number Diff line number Diff line change
Expand Up @@ -443,4 +443,10 @@ msgid "API key with one-shop access required"
msgstr "Se requiere clave API con acceso a una tienda"

msgid "The currency of the site differs from the currency of the store in CRM. For the integration to work correctly, the currencies in CRM and CMS must match"
msgstr "La moneda del sitio web es distinto a la tienda del CRM. Para el funcionamiento correcto de la integración, las monedas del CMS y CRM deben coincid"
msgstr "La moneda del sitio web es distinto a la tienda del CRM. Para el funcionamiento correcto de la integración, las monedas del CMS y CRM deben coincid"

msgid "Uploading services"
msgstr "Descarga de servicios"

msgid "Goods with the 'virtual' option enabled will be uploaded to Simla as services"
msgstr "Los bienes con la opción 'virtual' activada se cargarán en Simla como servicios"
6 changes: 6 additions & 0 deletions resources/pot/retailcrm-ru_RU.pot
Original file line number Diff line number Diff line change
Expand Up @@ -453,3 +453,9 @@ msgstr "Требуется API ключ с доступом к одному ма

msgid "The currency of the site differs from the currency of the store in CRM. For the integration to work correctly, the currencies in CRM and CMS must match"
msgstr "Валюта сайта отличается от валюты магазина в CRM. Для корректной работы интеграции, валюты в CRM и CMS должны совпадать"

msgid "Uploading services"
msgstr "Выгрузка услуг"

msgid "Goods with the 'virtual' option enabled will be uploaded to Simla as services"
msgstr "Товары с включенной опцией 'виртуальные' будут выгружаться в CRM как услуги"
12 changes: 12 additions & 0 deletions src/include/abstracts/class-wc-retailcrm-abstracts-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,18 @@ public function init_form_fields()
),
];

$this->form_fields['icml_unload_services'] = [
'label' => __('Enabled', 'retailcrm'),
'title' => __('Uploading services', 'retailcrm'),
'class' => 'checkbox',
'type' => 'checkbox',
'desc_tip' => true,
'description' => __(
"Goods with the 'virtual' option enabled will be uploaded to Simla as services",
"retailcrm"
),
];

foreach (get_post_statuses() as $statusKey => $statusValue) {
$this->form_fields['p_' . $statusKey] = [
'title' => $statusValue,
Expand Down
9 changes: 8 additions & 1 deletion src/include/class-wc-retailcrm-icml.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class WC_Retailcrm_Icml

protected $icmlWriter;

protected $unloadServices = false;

/**
* WC_Retailcrm_Icml constructor.
*
Expand All @@ -47,6 +49,10 @@ public function __construct()
$this->tmpFile = sprintf('%s.tmp', $this->file);
$this->settings = get_option(WC_Retailcrm_Base::$option_key);
$this->icmlWriter = new WC_Retailcrm_Icml_Writer($this->tmpFile);
$this->unloadServices = (
isset($this->settings['icml_unload_services'])
&& $this->settings['icml_unload_services'] === WC_Retailcrm_Base::YES
);
}

public function changeBindBySku($useXmlId)
Expand Down Expand Up @@ -252,7 +258,8 @@ private function getOffer(array $productAttributes, WC_Product $product, $parent
'categoryId' => $termList,
'dimensions' => $dimensions,
'weight' => $weight,
'tax' => isset($tax) ? $tax['rate'] : 'none'
'tax' => isset($tax) ? $tax['rate'] : 'none',
'type' => ($this->unloadServices && $product->is_virtual()) ? 'service' : 'product',
];

if ($product->get_sku() !== '') {
Expand Down
1 change: 1 addition & 0 deletions src/include/icml/class-wc-retailcrm-icml-writer.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ private function addOffers($offers)
$this->writer->writeAttribute('id', $offer['id']);
$this->writer->writeAttribute('productId', $offer['productId']);
$this->writer->writeAttribute('quantity', (int) $offer['quantity'] ?? 0);
$this->writer->writeAttribute('type', $offer['type']);

if (isset($offer['categoryId'])) {
if (is_array($offer['categoryId'])) {
Expand Down
3 changes: 3 additions & 0 deletions src/languages/retailcrm-es_ES.l10n.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,9 @@
"Se requiere clave API con acceso a una tienda",
"The currency of the site differs from the currency of the store in CRM. For the integration to work correctly, the currencies in CRM and CMS must match" =>
"La moneda del sitio web es distinto a la tienda del CRM. Para el funcionamiento correcto de la integración, las monedas del CMS y CRM deben coincid",
"Uploading services" => "Descarga de servicios",
"Goods with the 'virtual' option enabled will be uploaded to Simla as services" =>
"Los bienes con la opción 'virtual' activada se cargarán en Simla como servicios"
],
"language" => "es",
"x-generator" => "GlotPress/2.4.0-alpha",
Expand Down
Binary file modified src/languages/retailcrm-es_ES.mo
Binary file not shown.
3 changes: 3 additions & 0 deletions src/languages/retailcrm-ru_RU.l10n.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,9 @@
"Требуется API ключ с доступом к одному магазину",
"The currency of the site differs from the currency of the store in CRM. For the integration to work correctly, the currencies in CRM and CMS must match" =>
"Валюта сайта отличается от валюты магазина в CRM. Для корректной работы интеграции, валюты в CRM и CMS должны совпадать",
"Uploading services" => "Выгрузка услуг",
"Goods with the 'virtual' option enabled will be uploaded to Simla as services" =>
"Товары с включенной опцией 'виртуальные' будут выгружаться в CRM как услуги"
],
"language" => "ru",
"x-generator" => "GlotPress/2.4.0-alpha",
Expand Down
Binary file modified src/languages/retailcrm-ru_RU.mo
Binary file not shown.
5 changes: 4 additions & 1 deletion src/readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Tags: Интеграция, Simla.com, simla
Requires PHP: 7.0
Requires at least: 5.3
Tested up to: 6.5
Stable tag: 4.7.6
Stable tag: 4.7.7
License: GPLv1 or later
License URI: http://www.gnu.org/licenses/gpl-1.0.html

Expand Down Expand Up @@ -82,6 +82,9 @@ Asegúrate de tener una clave API específica para cada tienda. Las siguientes i


== Changelog ==
= 4.7.7 =
* Added transfer of services via ICML catalog

= 4.7.6 =
* Support WP 6.5

Expand Down
2 changes: 1 addition & 1 deletion src/retailcrm.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Description: Integration plugin for WooCommerce & Simla.com
* Author: RetailDriver LLC
* Author URI: http://retailcrm.pro/
* Version: 4.7.6
* Version: 4.7.7
* Tested up to: 6.5
* Requires Plugins: woocommerce
* WC requires at least: 5.4
Expand Down
2 changes: 1 addition & 1 deletion src/uninstall.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*
* @link https://wordpress.org/plugins/woo-retailcrm/
*
* @version 4.7.6
* @version 4.7.7
*
* @package RetailCRM
*/
Expand Down
1 change: 1 addition & 0 deletions tests/helpers/class-wc-retailcrm-test-case-helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ protected function setOptions()
'product_description' => 'full',
'stores_for_uploading' => ['woocommerce', 'main'],
'woo_coupon_apply_field' => 'testField',
'icml_unload_services' => 'yes'
];

update_option(WC_Retailcrm_Base::$option_key, $options);
Expand Down
34 changes: 33 additions & 1 deletion tests/test-wc-retailcrm-icml.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ public function setUp()
{
WC_Helper_Product::create_simple_product();
WC_Helper_Product::create_variation_product();

$this->createVirtualProduct();
$this->setOptions();
}

public function testGenerate()
Expand All @@ -35,9 +38,9 @@ public function testGenerate()
$this->assertNotEmpty($xmlArray['shop']['categories']['category']);
$this->assertCount(2, $xmlArray['shop']['categories']['category']);
$this->assertNotEmpty($xmlArray['shop']['offers']['offer']);
$this->assertCount(7, $xmlArray['shop']['offers']['offer']);
$this->assertNotEmpty($xmlArray['shop']['offers']['offer'][0]);
$this->assertNotEmpty($xmlArray['shop']['offers']['offer'][1]);
$this->assertNotEmpty($xmlArray['shop']['offers']['offer'][2]);

foreach ($xmlArray['shop']['offers']['offer'] as $product) {
$this->assertNotEmpty($product['name']);
Expand All @@ -48,6 +51,35 @@ public function testGenerate()
$this->assertNotEmpty($product['vatRate']);
$this->assertEquals('none', $product['vatRate']);
$this->assertContains('Dummy', $product['productName']);
$this->assertNotEmpty($product['@attributes']['type']);
}

$attributesList = array_column($xmlArray['shop']['offers']['offer'], '@attributes');
$typeList = array_column($attributesList, 'type');

$this->assertContains('service', $typeList);
}

private function createVirtualProduct()
{
$product = wp_insert_post([
'post_title' => 'Dummy Product',
'post_type' => 'product',
'post_status' => 'publish',
]);

update_post_meta($product, '_price', '10');
update_post_meta($product, '_regular_price', '10');
update_post_meta($product, '_sale_price', '');
update_post_meta($product, '_sku', 'DUMMY SKU');
update_post_meta($product, '_manage_stock', 'no');
update_post_meta($product, '_tax_status', 'taxable');
update_post_meta($product, '_downloadable', 'no');
update_post_meta($product, '_virtual', 'yes');
update_post_meta($product, '_stock_status', 'instock');
update_post_meta($product, '_weight', '1.1');
wp_set_object_terms($product, 'simple', 'product_type');

return new WC_Product_Simple($product);
}
}

0 comments on commit 8627548

Please sign in to comment.