From f275c10bd532763d0984a7e2f5ad162463da434a Mon Sep 17 00:00:00 2001 From: Jonathan Lelievre Date: Mon, 27 May 2024 12:16:57 +0200 Subject: [PATCH] Integrate attribute texture image in combination generator --- .../combination/generator/AttributesSelector.vue | 8 +++++++- .../js/pages/product/combination/types.d.ts | 1 + .../AbstractAttributeGroupQueryHandler.php | 3 ++- .../Attribute/QueryResult/Attribute.php | 14 +++++++++++++- .../Sell/Catalog/Product/CombinationController.php | 3 +++ .../Domain/AttributeGroupFeatureContext.php | 3 +++ 6 files changed, 29 insertions(+), 3 deletions(-) diff --git a/admin-dev/themes/new-theme/js/pages/product/combination/generator/AttributesSelector.vue b/admin-dev/themes/new-theme/js/pages/product/combination/generator/AttributesSelector.vue index f3768df3baab6..3768dfd1c5e51 100644 --- a/admin-dev/themes/new-theme/js/pages/product/combination/generator/AttributesSelector.vue +++ b/admin-dev/themes/new-theme/js/pages/product/combination/generator/AttributesSelector.vue @@ -111,6 +111,11 @@ v-if="attribute.color" :style="`background-color: ${attribute.color}`" /> + {{ attribute.name }} @@ -406,7 +411,8 @@ display: none; } - &-color { + &-color, + &-texture { display: block; width: 15px; height: 15px; diff --git a/admin-dev/themes/new-theme/js/pages/product/combination/types.d.ts b/admin-dev/themes/new-theme/js/pages/product/combination/types.d.ts index a463da241ad8d..e65983e1dc8a3 100644 --- a/admin-dev/themes/new-theme/js/pages/product/combination/types.d.ts +++ b/admin-dev/themes/new-theme/js/pages/product/combination/types.d.ts @@ -47,5 +47,6 @@ export interface Attribute { group_id: number; group_name: string; name: string; + texture: string|null; } /* eslint-enable camelcase */ diff --git a/src/Adapter/AttributeGroup/QueryHandler/AbstractAttributeGroupQueryHandler.php b/src/Adapter/AttributeGroup/QueryHandler/AbstractAttributeGroupQueryHandler.php index a1014c568f910..6ac8dfe1ecaee 100644 --- a/src/Adapter/AttributeGroup/QueryHandler/AbstractAttributeGroupQueryHandler.php +++ b/src/Adapter/AttributeGroup/QueryHandler/AbstractAttributeGroupQueryHandler.php @@ -77,7 +77,8 @@ protected function formatAttributeGroupsList( $attributeId, $attribute->position, $attribute->color, - $attribute->name + $attribute->name, + file_exists(_PS_COL_IMG_DIR_ . $attributeId . '.jpg') ? _THEME_COL_DIR_ . $attributeId . '.jpg' : null ); } } diff --git a/src/Core/Domain/AttributeGroup/Attribute/QueryResult/Attribute.php b/src/Core/Domain/AttributeGroup/Attribute/QueryResult/Attribute.php index 4aeb87b8f0495..2fac5bbd012fe 100644 --- a/src/Core/Domain/AttributeGroup/Attribute/QueryResult/Attribute.php +++ b/src/Core/Domain/AttributeGroup/Attribute/QueryResult/Attribute.php @@ -50,6 +50,11 @@ class Attribute */ private $localizedNames; + /** + * @var string|null + */ + private $textureFilePath; + /** * @param int $attributeId * @param int $position @@ -60,12 +65,14 @@ public function __construct( int $attributeId, int $position, string $color, - array $localizedNames + array $localizedNames, + string $textureFilePath = null ) { $this->attributeId = $attributeId; $this->position = $position; $this->color = $color; $this->localizedNames = $localizedNames; + $this->textureFilePath = $textureFilePath; } /** @@ -99,4 +106,9 @@ public function getLocalizedNames(): array { return $this->localizedNames; } + + public function getTextureFilePath(): ?string + { + return $this->textureFilePath; + } } diff --git a/src/PrestaShopBundle/Controller/Admin/Sell/Catalog/Product/CombinationController.php b/src/PrestaShopBundle/Controller/Admin/Sell/Catalog/Product/CombinationController.php index 8ed70e77c62a5..aa82b49bd6c39 100644 --- a/src/PrestaShopBundle/Controller/Admin/Sell/Catalog/Product/CombinationController.php +++ b/src/PrestaShopBundle/Controller/Admin/Sell/Catalog/Product/CombinationController.php @@ -603,6 +603,9 @@ private function formatAttributeGroupsForPresentation(array $attributeGroups): a if (null !== $attribute->getColor()) { $attributeData['color'] = $attribute->getColor(); } + if (null !== $attribute->getTextureFilePath()) { + $attributeData['texture'] = $attribute->getTextureFilePath(); + } $attributes[] = $attributeData; } diff --git a/tests/Integration/Behaviour/Features/Context/Domain/AttributeGroupFeatureContext.php b/tests/Integration/Behaviour/Features/Context/Domain/AttributeGroupFeatureContext.php index 0d18a72a9a816..fd8bf5e8bdd42 100644 --- a/tests/Integration/Behaviour/Features/Context/Domain/AttributeGroupFeatureContext.php +++ b/tests/Integration/Behaviour/Features/Context/Domain/AttributeGroupFeatureContext.php @@ -410,6 +410,9 @@ private function performAttributesInGroupAssertion(?TableNode $tableNode, array $attribute = $attributes[$index]; Assert::assertEquals($attributesDatum['color'], $attribute->getColor(), 'Unexpected color'); Assert::assertEquals($attributesDatum['position'], $attribute->getPosition(), 'Unexpected position'); + if ($attribute->getTextureFilePath()) { + Assert::assertEquals(_THEME_COL_DIR_ . $attribute->getAttributeId() . '.jpg', $attribute->getTextureFilePath()); + } $attributeNames = $attribute->getLocalizedNames(); foreach ($attributesDatum['name'] as $langId => $name) {