diff -Nuar a/vendor/magento/module-catalog-graph-ql/DataProvider/Product/LayeredNavigation/AttributeOptionProvider.php b/vendor/magento/module-catalog-graph-ql/DataProvider/Product/LayeredNavigation/AttributeOptionProvider.php index 320e0adc29b..576281861d3 100644 --- a/vendor/magento/module-catalog-graph-ql/DataProvider/Product/LayeredNavigation/AttributeOptionProvider.php +++ b/vendor/magento/module-catalog-graph-ql/DataProvider/Product/LayeredNavigation/AttributeOptionProvider.php @@ -30,11 +30,20 @@ class AttributeOptionProvider private $resourceConnection; /** + * @var \Magento\Catalog\Model\ResourceModel\ProductFactory + */ + private $productFactory; + + /** * @param ResourceConnection $resourceConnection */ - public function __construct(ResourceConnection $resourceConnection) + public function __construct( + ResourceConnection $resourceConnection, + \Magento\Catalog\Model\ResourceModel\ProductFactory $productFactory + ) { $this->resourceConnection = $resourceConnection; + $this->productFactory = $productFactory; } /** @@ -45,14 +54,14 @@ class AttributeOptionProvider * @return array * @throws \Zend_Db_Statement_Exception */ - public function getOptions(array $optionIds, array $attributeCodes = []): array + public function getOptions(array $optionIds, array $attributeCodes = [], $storeId): array { if (!$optionIds) { return []; } $connection = $this->resourceConnection->getConnection(); - $select = $connection->select() + $select = $connection->select() ->from( ['a' => $this->resourceConnection->getTableName('eav_attribute')], [ @@ -67,24 +76,34 @@ class AttributeOptionProvider [] ) ->joinLeft( + ['attrlabel' => $this->resourceConnection->getTableName('eav_attribute_label')], + 'a.attribute_id = attrlabel.attribute_id', + [ + 'store_label' => 'attrlabel.value', + 'attribute_store_id' => 'attrlabel.store_id' + ] + ) + ->joinLeft( ['option_value' => $this->resourceConnection->getTableName('eav_attribute_option_value')], 'options.option_id = option_value.option_id', [ 'option_label' => 'option_value.value', 'option_id' => 'option_value.option_id', + 'option_store_id' => 'option_value.store_id' ] ); $select->where('option_value.option_id IN (?)', $optionIds); - + + if (!empty($attributeCodes)) { $select->orWhere( 'a.attribute_code in (?) AND a.frontend_input = \'boolean\'', $attributeCodes ); } - - return $this->formatResult($select); + + return $this->formatResult($select, $storeId); } /** @@ -94,23 +113,38 @@ class AttributeOptionProvider * @return array * @throws \Zend_Db_Statement_Exception */ - private function formatResult(\Magento\Framework\DB\Select $select): array - { + private function formatResult(\Magento\Framework\DB\Select $select, $storeId): array + { $statement = $this->resourceConnection->getConnection()->query($select); $result = []; + $poductReource=$this->productFactory->create(); + while ($option = $statement->fetch()) { - if (!isset($result[$option['attribute_code']])) { + + if($poductReource->getAttribute($option['attribute_code'])->getStoreLabel($storeId)){ + $attributeLabel = $poductReource->getAttribute($option['attribute_code'])->getStoreLabel($storeId); + }else{ + $attributeLabel = $option['attribute_label']; + } + + $attribute = $poductReource->getAttribute($option['attribute_code']); + if ($attribute->usesSource()) { + $option_Text = $attribute->getSource()->getOptionText($option['option_id']); + } + + if (!isset($result[$option['attribute_code']])) { $result[$option['attribute_code']] = [ 'attribute_id' => $option['attribute_id'], 'attribute_code' => $option['attribute_code'], - 'attribute_label' => $option['attribute_label'], + 'attribute_label' => $attributeLabel, 'options' => [], ]; - } - $result[$option['attribute_code']]['options'][$option['option_id']] = $option['option_label']; + } + + $result[$option['attribute_code']]['options'][$option['option_id']] = $option_Text; } - + return $result; } } diff -Nuar a/vendor/magento/module-catalog-graph-ql/DataProvider/Product/LayeredNavigation/Builder/Attribute.php b/vendor/magento/module-catalog-graph-ql/DataProvider/Product/LayeredNavigation/Builder/Attribute.php index 0ec65c88024..e550de9cb03 100644 --- a/vendor/magento/module-catalog-graph-ql/DataProvider/Product/LayeredNavigation/Builder/Attribute.php +++ b/vendor/magento/module-catalog-graph-ql/DataProvider/Product/LayeredNavigation/Builder/Attribute.php @@ -71,7 +71,7 @@ class Attribute implements LayerBuilderInterface */ public function build(AggregationInterface $aggregation, ?int $storeId): array { - $attributeOptions = $this->getAttributeOptions($aggregation); + $attributeOptions = $this->getAttributeOptions($aggregation, $storeId); // build layer per attribute $result = []; @@ -136,7 +136,7 @@ class Attribute implements LayerBuilderInterface * @return array * @throws \Zend_Db_Statement_Exception */ - private function getAttributeOptions(AggregationInterface $aggregation): array + private function getAttributeOptions(AggregationInterface $aggregation, $storeId): array { $attributeOptionIds = []; $attributes = []; @@ -154,6 +154,6 @@ class Attribute implements LayerBuilderInterface return []; } - return $this->attributeOptionProvider->getOptions(\array_merge(...$attributeOptionIds), $attributes); + return $this->attributeOptionProvider->getOptions(\array_merge(...$attributeOptionIds), $attributes,$storeId); } }