8
8
9
9
use Magento \Eav \Model \Entity \Attribute \AbstractAttribute ;
10
10
use Magento \Framework \EntityManager \EntityMetadataInterface ;
11
+ use Magento \Framework \Exception \NoSuchEntityException ;
11
12
use Magento \Store \Api \Data \StoreInterface ;
12
13
use Magento \Store \Model \Store ;
13
14
use Magento \Store \Model \StoreManagerInterface ;
14
- use Magento \Catalog \Model \ResourceModel \Eav \Attribute as CatalogEavAttribute ;
15
15
use Magento \Store \Model \Website ;
16
16
use Magento \Framework \Model \Entity \ScopeInterface ;
17
17
18
18
/**
19
19
* Builds scope-related conditions for catalog attributes
20
20
*
21
21
* Class ConditionBuilder
22
- * @package Magento\Catalog\Model\ResourceModel\Attribute
23
22
*/
24
23
class ConditionBuilder
25
24
{
@@ -45,6 +44,7 @@ public function __construct(StoreManagerInterface $storeManager)
45
44
* @param ScopeInterface[] $scopes
46
45
* @param string $linkFieldValue
47
46
* @return array
47
+ * @throws NoSuchEntityException
48
48
*/
49
49
public function buildExistingAttributeWebsiteScope (
50
50
AbstractAttribute $ attribute ,
@@ -56,7 +56,7 @@ public function buildExistingAttributeWebsiteScope(
56
56
if (!$ website ) {
57
57
return [];
58
58
}
59
- $ storeIds = $ website ->getStoreIds ();
59
+ $ storeIds = $ this ->getStoreIds ($ website );
60
60
61
61
$ condition = [
62
62
$ metadata ->getLinkField () . ' = ? ' => $ linkFieldValue ,
@@ -81,6 +81,7 @@ public function buildExistingAttributeWebsiteScope(
81
81
* @param ScopeInterface[] $scopes
82
82
* @param string $linkFieldValue
83
83
* @return array
84
+ * @throws NoSuchEntityException
84
85
*/
85
86
public function buildNewAttributesWebsiteScope (
86
87
AbstractAttribute $ attribute ,
@@ -92,7 +93,7 @@ public function buildNewAttributesWebsiteScope(
92
93
if (!$ website ) {
93
94
return [];
94
95
}
95
- $ storeIds = $ website ->getStoreIds ();
96
+ $ storeIds = $ this ->getStoreIds ($ website );
96
97
97
98
$ condition = [
98
99
$ metadata ->getLinkField () => $ linkFieldValue ,
@@ -109,8 +110,11 @@ public function buildNewAttributesWebsiteScope(
109
110
}
110
111
111
112
/**
113
+ * Get website for website scope
114
+ *
112
115
* @param array $scopes
113
116
* @return null|Website
117
+ * @throws NoSuchEntityException
114
118
*/
115
119
private function getWebsiteForWebsiteScope (array $ scopes )
116
120
{
@@ -119,8 +123,11 @@ private function getWebsiteForWebsiteScope(array $scopes)
119
123
}
120
124
121
125
/**
126
+ * Get store from scopes
127
+ *
122
128
* @param ScopeInterface[] $scopes
123
129
* @return StoreInterface|null
130
+ * @throws NoSuchEntityException
124
131
*/
125
132
private function getStoreFromScopes (array $ scopes )
126
133
{
@@ -132,4 +139,20 @@ private function getStoreFromScopes(array $scopes)
132
139
133
140
return null ;
134
141
}
142
+
143
+ /**
144
+ * Get storeIds from the website
145
+ *
146
+ * @param Website $website
147
+ * @return array
148
+ */
149
+ private function getStoreIds (Website $ website ): array
150
+ {
151
+ $ storeIds = $ website ->getStoreIds ();
152
+
153
+ if (empty ($ storeIds ) && $ website ->getCode () === Website::ADMIN_CODE ) {
154
+ $ storeIds [] = Store::DEFAULT_STORE_ID ;
155
+ }
156
+ return $ storeIds ;
157
+ }
135
158
}
0 commit comments