diff --git a/CHANGELOG.md b/CHANGELOG.md index 63c3f09d..29f80574 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## v3.5.8 +* Реализована передача характеристик товара в ICML каталог + ## v3.5.7 * Изменены минимально поддерживаемые версии PrestaShop и PHP diff --git a/VERSION b/VERSION index 3cf57515..fa8da207 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -3.5.7 +3.5.8 diff --git a/retailcrm/lib/RetailcrmCatalog.php b/retailcrm/lib/RetailcrmCatalog.php old mode 100644 new mode 100755 index c970268f..bf2178f1 --- a/retailcrm/lib/RetailcrmCatalog.php +++ b/retailcrm/lib/RetailcrmCatalog.php @@ -208,6 +208,7 @@ function ($val) use ($inactiveCategories, $categoriesIds) { } $offers = Product::getProductAttributesIds($product['id_product']); + $features = Product::getFrontFeaturesStatic($id_lang, $product['id_product']); if (!empty($offers)) { $offersCount += count($offers); @@ -290,6 +291,7 @@ function ($val) use ($inactiveCategories, $categoriesIds) { 'weight' => $weight, 'dimensions' => $dimensions, 'vatRate' => $product['rate'], + 'features' => $features, ]; if (!empty($combinations)) { @@ -347,6 +349,7 @@ function ($val) use ($inactiveCategories, $categoriesIds) { 'weight' => $weight, 'dimensions' => $dimensions, 'vatRate' => $product['rate'], + 'features' => $features, ], [ 'product' => $product, diff --git a/retailcrm/lib/RetailcrmIcml.php b/retailcrm/lib/RetailcrmIcml.php old mode 100644 new mode 100755 index 060330a1..57a62224 --- a/retailcrm/lib/RetailcrmIcml.php +++ b/retailcrm/lib/RetailcrmIcml.php @@ -189,6 +189,7 @@ private function addOffers($offers) $this->setOffersProperties($offer); $this->setOffersParams($offer); $this->setOffersCombinations($offer); + $this->setOffersFeatures($offer); $this->writer->endElement(); // end } @@ -250,6 +251,35 @@ private function setOffersCombinations($offer) } } + private function setOffersFeatures($offer) + { + $lastFeaturesNumberCode = []; + + foreach ($offer['features'] as $feature) { + if ( + empty($feature['id_feature']) + || empty($feature['name']) + || null === $feature['value'] + ) { + continue; + } + + $numberCode = 1; + + if (isset($lastFeaturesNumberCode[$feature['id_feature']])) { + $numberCode = 1 + $lastFeaturesNumberCode[$feature['id_feature']]; + } + + $this->writer->startElement('param'); + $this->writer->writeAttribute('code', 'feature_' . $feature['id_feature'] . '_' . $numberCode); + $this->writer->writeAttribute('name', $feature['name']); + $this->writer->text($feature['value']); + $this->writer->endElement(); + + $lastFeaturesNumberCode[$feature['id_feature']] = $numberCode; + } + } + private function writeEnd() { $this->writer->endElement(); // end diff --git a/retailcrm/retailcrm.php b/retailcrm/retailcrm.php old mode 100644 new mode 100755 index be7761d3..f03ba6fd --- a/retailcrm/retailcrm.php +++ b/retailcrm/retailcrm.php @@ -48,7 +48,7 @@ class RetailCRM extends Module { - const VERSION = '3.5.7'; + const VERSION = '3.5.8'; const API_URL = 'RETAILCRM_ADDRESS'; const API_KEY = 'RETAILCRM_API_TOKEN'; diff --git a/tests/lib/RetailcrmCatalogTest.php b/tests/lib/RetailcrmCatalogTest.php index 6b841371..e990a6f6 100644 --- a/tests/lib/RetailcrmCatalogTest.php +++ b/tests/lib/RetailcrmCatalogTest.php @@ -126,9 +126,47 @@ public function testIsPricesWithTax() public function testIcmlGenerate() { $icml = new RetailcrmIcml(Configuration::get('PS_SHOP_NAME'), _PS_ROOT_DIR_ . '/retailcrm.xml'); - $icml->generate($this->data[0], $this->data[1]); + $offers = []; + + foreach ($this->data[1] as $offer) { + $offer['features'] = $this->getFeaturesData(); + $offers[] = $offer; + } + + $icml->generate($this->data[0], $offers); $this->assertFileExists(_PS_ROOT_DIR_ . '/retailcrm.xml'); $xml = simplexml_load_file(_PS_ROOT_DIR_ . '/retailcrm.xml'); $this->assertNotFalse($xml); } + + private function getFeaturesData() + { + return [ + [ + 'id_feature' => 1, + 'name' => 'test', + 'value' => 'value1', + ], + [ + 'id_feature' => 1, + 'name' => 'test', + 'value' => 'value2', + ], + [ + 'id_feature' => 1, + 'name' => 'test', + 'value' => 'value3', + ], + [ + 'id_feature' => 2, + 'name' => 'test', + 'value' => 'value1', + ], + [ + 'id_feature' => 2, + 'name' => 'test', + 'value' => 'value2', + ], + ]; + } }