3
3
* Copyright © Magento, Inc. All rights reserved.
4
4
* See COPYING.txt for license details.
5
5
*/
6
- declare (strict_types=1 );
7
-
8
6
namespace Magento \ConfigurableProduct \Model \ResourceModel \Attribute ;
9
7
10
- use Magento \Catalog \Api \Data \ProductInterface ;
11
8
use Magento \ConfigurableProduct \Model \ResourceModel \Product \Type \Configurable \Attribute ;
12
9
use Magento \Eav \Model \Entity \Attribute \AbstractAttribute ;
13
- use Magento \Framework \EntityManager \MetadataPool ;
10
+ use Magento \Framework \App \ScopeInterface ;
11
+ use Magento \Framework \DB \Select ;
14
12
15
13
/**
16
14
* Build select object for retrieving configurable options.
17
15
*/
18
16
class OptionSelectBuilder implements OptionSelectBuilderInterface
19
17
{
20
18
/**
19
+ * Configurable Attribute Resource Model.
20
+ *
21
21
* @var Attribute
22
22
*/
23
23
private $ attributeResource ;
24
24
25
25
/**
26
- * @var MetadataPool
26
+ * Option Provider.
27
+ *
28
+ * @var OptionProvider
27
29
*/
28
- private $ metadataPool ;
30
+ private $ attributeOptionProvider ;
29
31
30
32
/**
31
33
* @param Attribute $attributeResource
32
- * @param MetadataPool $metadataPool
34
+ * @param OptionProvider $attributeOptionProvider
33
35
*/
34
- public function __construct (Attribute $ attributeResource , MetadataPool $ metadataPool )
36
+ public function __construct (Attribute $ attributeResource , OptionProvider $ attributeOptionProvider )
35
37
{
36
38
$ this ->attributeResource = $ attributeResource ;
37
- $ this ->metadataPool = $ metadataPool ;
39
+ $ this ->attributeOptionProvider = $ attributeOptionProvider ;
38
40
}
39
41
40
42
/**
41
43
* @inheritdoc
42
44
*/
43
- public function getSelect (AbstractAttribute $ superAttribute , int $ productId )
45
+ public function getSelect (AbstractAttribute $ superAttribute , int $ productId, ScopeInterface $ scope )
44
46
{
45
- $ productLinkField = $ this ->metadataPool ->getMetadata (ProductInterface::class)->getLinkField ();
46
-
47
47
$ select = $ this ->attributeResource ->getConnection ()->select ()->from (
48
48
['super_attribute ' => $ this ->attributeResource ->getTable ('catalog_product_super_attribute ' )],
49
49
[
@@ -55,7 +55,7 @@ public function getSelect(AbstractAttribute $superAttribute, int $productId)
55
55
]
56
56
)->joinInner (
57
57
['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 " ,
59
59
[]
60
60
)->joinInner (
61
61
['product_link ' => $ this ->attributeResource ->getTable ('catalog_product_super_link ' )],
@@ -76,7 +76,8 @@ public function getSelect(AbstractAttribute $superAttribute, int $productId)
76
76
[
77
77
'entity_value.attribute_id = super_attribute.attribute_id ' ,
78
78
'entity_value.store_id = 0 ' ,
79
- "entity_value. $ productLinkField = entity. $ productLinkField " ,
79
+ "entity_value. {$ this ->attributeOptionProvider ->getProductEntityLinkField ()} = "
80
+ . "entity. {$ this ->attributeOptionProvider ->getProductEntityLinkField ()}" ,
80
81
]
81
82
),
82
83
[]
@@ -86,7 +87,7 @@ public function getSelect(AbstractAttribute $superAttribute, int $productId)
86
87
' AND ' ,
87
88
[
88
89
'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 ,
90
91
]
91
92
),
92
93
[]
@@ -105,19 +106,34 @@ public function getSelect(AbstractAttribute $superAttribute, int $productId)
105
106
);
106
107
107
108
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 (
109
118
['option_value ' => $ this ->attributeResource ->getTable ('eav_attribute_option_value ' )],
110
119
implode (
111
120
' AND ' ,
112
121
[
113
122
'option_value.option_id = entity_value.value ' ,
114
- 'option_value.store_id = 0 ' ,
123
+ 'option_value.store_id = ' . $ scope -> getId () ,
115
124
]
116
125
),
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
+ []
121
137
);
122
138
}
123
139
0 commit comments