@@ -73,7 +73,7 @@ class Config implements ResetAfterRequestInterface
73
73
* Initialized attributes
74
74
*
75
75
* [int $website][string $entityTypeCode][string $code] = AbstractAttribute $attribute
76
- * @var array<int, array<string, array<string, AbstractAttribute>>>
76
+ * @var array<int|null , array<string, array<string, AbstractAttribute>>>
77
77
*/
78
78
private $ attributes ;
79
79
@@ -162,6 +162,9 @@ class Config implements ResetAfterRequestInterface
162
162
*/
163
163
private $ attributesForPreload ;
164
164
165
+ /** @var bool[] */
166
+ private array $ isAttributeTypeWebsiteSpecificCache = [];
167
+
165
168
/**
166
169
* @param \Magento\Framework\App\CacheInterface $cache
167
170
* @param Entity\TypeFactory $entityTypeFactory
@@ -249,7 +252,12 @@ protected function _load($id)
249
252
*/
250
253
private function loadAttributes ($ entityTypeCode )
251
254
{
252
- return $ this ->attributes [$ this ->getWebsiteId ()][$ entityTypeCode ] ?? [];
255
+ if ($ this ->isAttributeTypeWebsiteSpecific ($ entityTypeCode )) {
256
+ $ websiteId = $ this ->getWebsiteId ();
257
+ } else {
258
+ $ websiteId = null ;
259
+ }
260
+ return $ this ->attributes [$ websiteId ][$ entityTypeCode ] ?? [];
253
261
}
254
262
255
263
/**
@@ -275,7 +283,12 @@ protected function _save($obj, $id)
275
283
*/
276
284
private function saveAttribute (AbstractAttribute $ attribute , $ entityTypeCode , $ attributeCode )
277
285
{
278
- $ this ->attributes [$ this ->getWebsiteId ()][$ entityTypeCode ][$ attributeCode ] = $ attribute ;
286
+ if ($ this ->isAttributeTypeWebsiteSpecific ($ entityTypeCode )) {
287
+ $ websiteId = $ this ->getWebsiteId ();
288
+ } else {
289
+ $ websiteId = null ;
290
+ }
291
+ $ this ->attributes [$ websiteId ][$ entityTypeCode ][$ attributeCode ] = $ attribute ;
279
292
}
280
293
281
294
/**
@@ -543,7 +556,11 @@ public function getAttributes($entityType)
543
556
*/
544
557
public function getAttribute ($ entityType , $ code )
545
558
{
546
- $ websiteId = $ this ->getWebsiteId ();
559
+ if ($ this ->isAttributeTypeWebsiteSpecific ($ entityType )) {
560
+ $ websiteId = $ this ->getWebsiteId ();
561
+ } else {
562
+ $ websiteId = null ;
563
+ }
547
564
if ($ code instanceof \Magento \Eav \Model \Entity \Attribute \AttributeInterface) {
548
565
return $ code ;
549
566
}
@@ -912,7 +929,7 @@ public function importAttributesData($entityType, array $attributes)
912
929
/**
913
930
* Create attribute by attribute code
914
931
*
915
- * @param string $entityType
932
+ * @param string|Type $entityType
916
933
* @param string $attributeCode
917
934
* @return AbstractAttribute
918
935
* @throws LocalizedException
@@ -1002,17 +1019,45 @@ public function getWebsiteId() : int
1002
1019
return (int )$ websiteId ;
1003
1020
}
1004
1021
1022
+ /**
1023
+ * Returns true if $entityType has website-specific options.
1024
+ *
1025
+ * Most attributes are global, but some can have website-specific options.
1026
+ *
1027
+ * @param string|Type $entityType
1028
+ * @return bool
1029
+ */
1030
+ private function isAttributeTypeWebsiteSpecific (string |Type $ entityType ) : bool
1031
+ {
1032
+ if ($ entityType instanceof Type) {
1033
+ $ entityTypeCode = $ entityType ->getEntityTypeCode ();
1034
+ } else {
1035
+ $ entityTypeCode = $ entityType ;
1036
+ }
1037
+ if (key_exists ($ entityTypeCode , $ this ->isAttributeTypeWebsiteSpecificCache )) {
1038
+ return $ this ->isAttributeTypeWebsiteSpecificCache [$ entityTypeCode ];
1039
+ }
1040
+ $ entityType = $ this ->getEntityType ($ entityType );
1041
+ $ model = $ entityType ->getAttributeModel ();
1042
+ $ returnValue = is_a ($ model , \Magento \Eav \Model \Attribute::class, true );
1043
+ $ this ->isAttributeTypeWebsiteSpecificCache [$ entityTypeCode ] = $ returnValue ;
1044
+ return $ returnValue ;
1045
+ }
1046
+
1005
1047
/**
1006
1048
* @inheritDoc
1007
1049
*/
1008
1050
public function _resetState (): void
1009
1051
{
1052
+ $ this ->isAttributeTypeWebsiteSpecificCache = [];
1010
1053
$ this ->attributesPerSet = [];
1011
1054
$ this ->_attributeData = null ;
1012
- foreach ($ this ->attributes ?? [] as $ attributesGroupedByEntityTypeCode ) {
1013
- foreach ($ attributesGroupedByEntityTypeCode as $ attribute ) {
1014
- if ($ attribute instanceof ResetAfterRequestInterface) {
1015
- $ attribute ->_resetState ();
1055
+ foreach ($ this ->attributes ?? [] as $ attributesGroupedByWebsites ) {
1056
+ foreach ($ attributesGroupedByWebsites ?? [] as $ attributesGroupedByEntityTypeCode ) {
1057
+ foreach ($ attributesGroupedByEntityTypeCode as $ attribute ) {
1058
+ if ($ attribute instanceof ResetAfterRequestInterface) {
1059
+ $ attribute ->_resetState ();
1060
+ }
1016
1061
}
1017
1062
}
1018
1063
}
0 commit comments