33 * Copyright © Magento, Inc. All rights reserved.
44 * See COPYING.txt for license details.
55 */
6- declare (strict_types=1 );
7-
86namespace Magento \ConfigurableProduct \Model \ResourceModel \Attribute ;
97
10- use Magento \Catalog \Api \Data \ProductInterface ;
118use Magento \ConfigurableProduct \Model \ResourceModel \Product \Type \Configurable \Attribute ;
129use Magento \Eav \Model \Entity \Attribute \AbstractAttribute ;
13- use Magento \Framework \EntityManager \MetadataPool ;
10+ use Magento \Framework \App \ScopeInterface ;
11+ use Magento \Framework \DB \Select ;
1412
1513/**
1614 * Build select object for retrieving configurable options.
1715 */
1816class OptionSelectBuilder implements OptionSelectBuilderInterface
1917{
2018 /**
19+ * Configurable Attribute Resource Model.
20+ *
2121 * @var Attribute
2222 */
2323 private $ attributeResource ;
2424
2525 /**
26- * @var MetadataPool
26+ * Option Provider.
27+ *
28+ * @var OptionProvider
2729 */
28- private $ metadataPool ;
30+ private $ attributeOptionProvider ;
2931
3032 /**
3133 * @param Attribute $attributeResource
32- * @param MetadataPool $metadataPool
34+ * @param OptionProvider $attributeOptionProvider
3335 */
34- public function __construct (Attribute $ attributeResource , MetadataPool $ metadataPool )
36+ public function __construct (Attribute $ attributeResource , OptionProvider $ attributeOptionProvider )
3537 {
3638 $ this ->attributeResource = $ attributeResource ;
37- $ this ->metadataPool = $ metadataPool ;
39+ $ this ->attributeOptionProvider = $ attributeOptionProvider ;
3840 }
3941
4042 /**
4143 * @inheritdoc
4244 */
43- public function getSelect (AbstractAttribute $ superAttribute , int $ productId )
45+ public function getSelect (AbstractAttribute $ superAttribute , int $ productId, ScopeInterface $ scope )
4446 {
45- $ productLinkField = $ this ->metadataPool ->getMetadata (ProductInterface::class)->getLinkField ();
46-
4747 $ select = $ this ->attributeResource ->getConnection ()->select ()->from (
4848 ['super_attribute ' => $ this ->attributeResource ->getTable ('catalog_product_super_attribute ' )],
4949 [
@@ -55,7 +55,7 @@ public function getSelect(AbstractAttribute $superAttribute, int $productId)
5555 ]
5656 )->joinInner (
5757 ['product_entity ' => $ this ->attributeResource ->getTable ('catalog_product_entity ' )],
58- "product_entity. $ productLinkField = super_attribute.product_id " ,
58+ "product_entity. { $ this -> attributeOptionProvider -> getProductEntityLinkField ()} = super_attribute.product_id " ,
5959 []
6060 )->joinInner (
6161 ['product_link ' => $ this ->attributeResource ->getTable ('catalog_product_super_link ' )],
@@ -76,7 +76,8 @@ public function getSelect(AbstractAttribute $superAttribute, int $productId)
7676 [
7777 'entity_value.attribute_id = super_attribute.attribute_id ' ,
7878 'entity_value.store_id = 0 ' ,
79- "entity_value. $ productLinkField = entity. $ productLinkField " ,
79+ "entity_value. {$ this ->attributeOptionProvider ->getProductEntityLinkField ()} = "
80+ . "entity. {$ this ->attributeOptionProvider ->getProductEntityLinkField ()}" ,
8081 ]
8182 ),
8283 []
@@ -86,7 +87,7 @@ public function getSelect(AbstractAttribute $superAttribute, int $productId)
8687 ' AND ' ,
8788 [
8889 'super_attribute.product_super_attribute_id = attribute_label.product_super_attribute_id ' ,
89- 'attribute_label.store_id = 0 ' ,
90+ 'attribute_label.store_id = ' . \ Magento \ Store \ Model \Store:: DEFAULT_STORE_ID ,
9091 ]
9192 ),
9293 []
@@ -105,19 +106,34 @@ public function getSelect(AbstractAttribute $superAttribute, int $productId)
105106 );
106107
107108 if (!$ superAttribute ->getSourceModel ()) {
108- $ select ->joinLeft (
109+ $ select ->columns (
110+ [
111+ 'option_title ' => $ this ->attributeResource ->getConnection ()->getIfNullSql (
112+ 'option_value.value ' ,
113+ 'default_option_value.value '
114+ ),
115+ 'default_title ' => 'default_option_value.value ' ,
116+ ]
117+ )->joinLeft (
109118 ['option_value ' => $ this ->attributeResource ->getTable ('eav_attribute_option_value ' )],
110119 implode (
111120 ' AND ' ,
112121 [
113122 'option_value.option_id = entity_value.value ' ,
114- 'option_value.store_id = 0 ' ,
123+ 'option_value.store_id = ' . $ scope -> getId () ,
115124 ]
116125 ),
117- [
118- 'option_title ' => 'option_value.value ' ,
119- 'default_title ' => 'option_value.value ' ,
120- ]
126+ []
127+ )->joinLeft (
128+ ['default_option_value ' => $ this ->attributeResource ->getTable ('eav_attribute_option_value ' )],
129+ implode (
130+ ' AND ' ,
131+ [
132+ 'default_option_value.option_id = entity_value.value ' ,
133+ 'default_option_value.store_id = ' . \Magento \Store \Model \Store::DEFAULT_STORE_ID ,
134+ ]
135+ ),
136+ []
121137 );
122138 }
123139
0 commit comments