Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion src/Model/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Context;
use Manufacturer;
use Tools;
use Product as PrestaShopProduct;

class Product
{
Expand Down Expand Up @@ -208,7 +209,22 @@ public static function fromArray($array): self
$array['id_product_attribute'] = 0;
}

if (true === \is_array($array['attributes'])) {
if (0 !== $array['id_product_attribute'] && true === empty($array['attributes'])) {
$product = new PrestaShopProduct($array['id_product']);
$groups = $product->getAttributesGroups($context->language->id);

$groups = array_filter($groups, function ($group) use ($array) {
return $group['id_product_attribute'] === $array['id_product_attribute'];
});

$attributes = array_map(static function ($group) {
return Tools::strtolower(trim(
sprintf('%s_%s', $group['group_name'], $group['attribute_name'])
));
}, $groups);

$variant = implode('___', $attributes);
} else if(true === \is_array($array['attributes'])) {
$attributes = array_map(static function ($attribute) {
return Tools::strtolower(trim(
sprintf('%s_%s', $attribute['group'], $attribute['name'])
Expand All @@ -220,6 +236,8 @@ public static function fromArray($array): self
$variant = Tools::strtolower(trim(
str_replace([' : ', '- '], ['_', '___'], $array['attributes'])
));

$variant = str_replace(': ', '_', $variant);
}

$calledClass = get_called_class();
Expand Down