88
99use Magento \Eav \Model \Entity \Attribute \AbstractAttribute ;
1010use Magento \Framework \EntityManager \EntityMetadataInterface ;
11+ use Magento \Framework \Exception \NoSuchEntityException ;
1112use Magento \Store \Api \Data \StoreInterface ;
1213use Magento \Store \Model \Store ;
1314use Magento \Store \Model \StoreManagerInterface ;
14- use Magento \Catalog \Model \ResourceModel \Eav \Attribute as CatalogEavAttribute ;
1515use Magento \Store \Model \Website ;
1616use Magento \Framework \Model \Entity \ScopeInterface ;
1717
1818/**
1919 * Builds scope-related conditions for catalog attributes
2020 *
2121 * Class ConditionBuilder
22- * @package Magento\Catalog\Model\ResourceModel\Attribute
2322 */
2423class ConditionBuilder
2524{
@@ -45,6 +44,7 @@ public function __construct(StoreManagerInterface $storeManager)
4544 * @param ScopeInterface[] $scopes
4645 * @param string $linkFieldValue
4746 * @return array
47+ * @throws NoSuchEntityException
4848 */
4949 public function buildExistingAttributeWebsiteScope (
5050 AbstractAttribute $ attribute ,
@@ -56,7 +56,7 @@ public function buildExistingAttributeWebsiteScope(
5656 if (!$ website ) {
5757 return [];
5858 }
59- $ storeIds = $ website ->getStoreIds ();
59+ $ storeIds = $ this ->getStoreIds ($ website );
6060
6161 $ condition = [
6262 $ metadata ->getLinkField () . ' = ? ' => $ linkFieldValue ,
@@ -81,6 +81,7 @@ public function buildExistingAttributeWebsiteScope(
8181 * @param ScopeInterface[] $scopes
8282 * @param string $linkFieldValue
8383 * @return array
84+ * @throws NoSuchEntityException
8485 */
8586 public function buildNewAttributesWebsiteScope (
8687 AbstractAttribute $ attribute ,
@@ -92,7 +93,7 @@ public function buildNewAttributesWebsiteScope(
9293 if (!$ website ) {
9394 return [];
9495 }
95- $ storeIds = $ website ->getStoreIds ();
96+ $ storeIds = $ this ->getStoreIds ($ website );
9697
9798 $ condition = [
9899 $ metadata ->getLinkField () => $ linkFieldValue ,
@@ -109,8 +110,11 @@ public function buildNewAttributesWebsiteScope(
109110 }
110111
111112 /**
113+ * Get website for website scope
114+ *
112115 * @param array $scopes
113116 * @return null|Website
117+ * @throws NoSuchEntityException
114118 */
115119 private function getWebsiteForWebsiteScope (array $ scopes )
116120 {
@@ -119,8 +123,11 @@ private function getWebsiteForWebsiteScope(array $scopes)
119123 }
120124
121125 /**
126+ * Get store from scopes
127+ *
122128 * @param ScopeInterface[] $scopes
123129 * @return StoreInterface|null
130+ * @throws NoSuchEntityException
124131 */
125132 private function getStoreFromScopes (array $ scopes )
126133 {
@@ -132,4 +139,20 @@ private function getStoreFromScopes(array $scopes)
132139
133140 return null ;
134141 }
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+ }
135158}
0 commit comments