From 0cbd954071dd6389ee285f2b0f3c8aff3ec32259 Mon Sep 17 00:00:00 2001 From: Ivan Chaplygin Date: Fri, 1 Sep 2023 15:53:45 +0300 Subject: [PATCH] ref #90476 Improved features transfer. Tests updated --- retailcrm/lib/RetailcrmIcml.php | 12 ++++++++- tests/lib/RetailcrmCatalogTest.php | 39 +++++++++++++++++++++++++++++- 2 files changed, 49 insertions(+), 2 deletions(-) diff --git a/retailcrm/lib/RetailcrmIcml.php b/retailcrm/lib/RetailcrmIcml.php index dbd3760..ee1b207 100755 --- a/retailcrm/lib/RetailcrmIcml.php +++ b/retailcrm/lib/RetailcrmIcml.php @@ -253,6 +253,8 @@ class RetailcrmIcml private function setOffersFeatures($offer) { + $lastFeaturesNumberCode = []; + foreach ($offer['features'] as $feature) { if ( empty($feature['id_feature']) @@ -262,11 +264,19 @@ class RetailcrmIcml 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']); + $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; } } diff --git a/tests/lib/RetailcrmCatalogTest.php b/tests/lib/RetailcrmCatalogTest.php index 6b84137..7e56e1c 100644 --- a/tests/lib/RetailcrmCatalogTest.php +++ b/tests/lib/RetailcrmCatalogTest.php @@ -126,9 +126,46 @@ class RetailcrmCatalogTest extends RetailcrmTestCase 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', + ] + ]; + } }