Skip to content

Commit

Permalink
ref #90476 Implemented transfer of features to ICML catalog (#216)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kocmonavtik authored Sep 1, 2023
1 parent 6b7599e commit 05e332c
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## v3.5.8
* Реализована передача характеристик товара в ICML каталог

## v3.5.7
* Изменены минимально поддерживаемые версии PrestaShop и PHP

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.5.7
3.5.8
3 changes: 3 additions & 0 deletions retailcrm/lib/RetailcrmCatalog.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -290,6 +291,7 @@ function ($val) use ($inactiveCategories, $categoriesIds) {
'weight' => $weight,
'dimensions' => $dimensions,
'vatRate' => $product['rate'],
'features' => $features,
];

if (!empty($combinations)) {
Expand Down Expand Up @@ -347,6 +349,7 @@ function ($val) use ($inactiveCategories, $categoriesIds) {
'weight' => $weight,
'dimensions' => $dimensions,
'vatRate' => $product['rate'],
'features' => $features,
],
[
'product' => $product,
Expand Down
30 changes: 30 additions & 0 deletions retailcrm/lib/RetailcrmIcml.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ private function addOffers($offers)
$this->setOffersProperties($offer);
$this->setOffersParams($offer);
$this->setOffersCombinations($offer);
$this->setOffersFeatures($offer);

$this->writer->endElement(); // end </offer>
}
Expand Down Expand Up @@ -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 </yml_catalog>
Expand Down
2 changes: 1 addition & 1 deletion retailcrm/retailcrm.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
40 changes: 39 additions & 1 deletion tests/lib/RetailcrmCatalogTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
],
];
}
}

0 comments on commit 05e332c

Please sign in to comment.