ref #90476 Implemented transfer of features to ICML catalog (#216)

This commit is contained in:
Kocmonavtik 2023-09-01 17:17:24 +03:00 committed by GitHub
parent 6b7599ec64
commit 05e332ce76
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 77 additions and 3 deletions

View File

@ -1,3 +1,6 @@
## v3.5.8
* Реализована передача характеристик товара в ICML каталог
## v3.5.7
* Изменены минимально поддерживаемые версии PrestaShop и PHP

View File

@ -1 +1 @@
3.5.7
3.5.8

3
retailcrm/lib/RetailcrmCatalog.php Normal file → Executable file
View File

@ -208,6 +208,7 @@ class RetailcrmCatalog
}
$offers = Product::getProductAttributesIds($product['id_product']);
$features = Product::getFrontFeaturesStatic($id_lang, $product['id_product']);
if (!empty($offers)) {
$offersCount += count($offers);
@ -290,6 +291,7 @@ class RetailcrmCatalog
'weight' => $weight,
'dimensions' => $dimensions,
'vatRate' => $product['rate'],
'features' => $features,
];
if (!empty($combinations)) {
@ -347,6 +349,7 @@ class RetailcrmCatalog
'weight' => $weight,
'dimensions' => $dimensions,
'vatRate' => $product['rate'],
'features' => $features,
],
[
'product' => $product,

30
retailcrm/lib/RetailcrmIcml.php Normal file → Executable file
View File

@ -189,6 +189,7 @@ class RetailcrmIcml
$this->setOffersProperties($offer);
$this->setOffersParams($offer);
$this->setOffersCombinations($offer);
$this->setOffersFeatures($offer);
$this->writer->endElement(); // end </offer>
}
@ -250,6 +251,35 @@ class RetailcrmIcml
}
}
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 </yml_catalog>

2
retailcrm/retailcrm.php Normal file → Executable file
View File

@ -48,7 +48,7 @@ require_once dirname(__FILE__) . '/bootstrap.php';
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';

View File

@ -126,9 +126,47 @@ 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',
],
];
}
}