Skip to content
This repository was archived by the owner on Apr 29, 2019. It is now read-only.

Commit 5c30670

Browse files
author
Stanislav Idolov
committed
1 parent 49ae5fa commit 5c30670

File tree

4 files changed

+26
-18
lines changed

4 files changed

+26
-18
lines changed

app/code/Magento/Eav/Model/Entity/AbstractEntity.php

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -463,21 +463,15 @@ public function getAttribute($attribute)
463463
* Adding attribute to entity
464464
*
465465
* @param AbstractAttribute $attribute
466-
* @param DataObject|null $object
467466
* @return $this
468467
*/
469-
public function addAttribute(AbstractAttribute $attribute, $object = null)
468+
public function addAttribute(AbstractAttribute $attribute)
470469
{
471470
$attribute->setEntity($this);
472471
$attributeCode = $attribute->getAttributeCode();
473472

474473
$this->_attributesByCode[$attributeCode] = $attribute;
475474

476-
if ($object !== null) {
477-
$suffix = $this->getAttributesCacheSuffix($object);
478-
$this->attributesByScope[$suffix][$attributeCode] = $attribute;
479-
}
480-
481475
if ($attribute->isStatic()) {
482476
$this->_staticAttributes[$attributeCode] = $attribute;
483477
} else {
@@ -487,14 +481,29 @@ public function addAttribute(AbstractAttribute $attribute, $object = null)
487481
return $this;
488482
}
489483

484+
/**
485+
* Adding attribute to entity by scope.
486+
*
487+
* @param AbstractAttribute $attribute
488+
* @param DataObject|null $entity
489+
* @return $this
490+
*/
491+
public function addAttributeByScope(AbstractAttribute $attribute, $entity = null)
492+
{
493+
$suffix = $entity !== null ? $this->getAttributesCacheSuffix($entity) : '0-0';
494+
$attributeCode = $attribute->getAttributeCode();
495+
$this->attributesByScope[$suffix][$attributeCode] = $attribute;
496+
return $this->addAttribute($attribute);
497+
}
498+
490499
/**
491500
* Get attributes by scope
492501
*
493502
* @return array
494503
*/
495504
private function getAttributesByScope($suffix)
496505
{
497-
return (isset($this->attributesByScope[$suffix]) && !empty($this->attributesByScope[$suffix]))
506+
return !empty($this->attributesByScope[$suffix])
498507
? $this->attributesByScope[$suffix]
499508
: $this->getAttributesByCode();
500509
}

app/code/Magento/Eav/Model/Entity/AttributeLoader.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,13 @@ public function __construct(
5151
* Retrieve configuration for all attributes
5252
*
5353
* @param AbstractEntity $resource
54-
* @param DataObject|null $object
54+
* @param DataObject|null $entity
5555
* @return AbstractEntity
5656
* @throws LocalizedException
5757
*/
58-
public function loadAllAttributes(AbstractEntity $resource, DataObject $object = null)
58+
public function loadAllAttributes(AbstractEntity $resource, DataObject $entity = null)
5959
{
60-
$attributes = $this->config->getEntityAttributes($resource->getEntityType(), $object);
60+
$attributes = $this->config->getEntityAttributes($resource->getEntityType(), $entity);
6161
$attributeCodes = array_keys($attributes);
6262
/**
6363
* Check and init default attributes
@@ -67,10 +67,10 @@ public function loadAllAttributes(AbstractEntity $resource, DataObject $object =
6767
$resource->unsetAttributes();
6868

6969
foreach ($defaultAttributesCodes as $attributeCode) {
70-
$resource->addAttribute($this->_getDefaultAttribute($resource, $attributeCode), $object);
70+
$resource->addAttributeByScope($this->_getDefaultAttribute($resource, $attributeCode), $entity);
7171
}
7272
foreach ($attributes as $attributeCode => $attribute) {
73-
$resource->addAttribute($attribute, $object);
73+
$resource->addAttributeByScope($attribute, $entity);
7474
}
7575
return $resource;
7676
}

app/code/Magento/Eav/Model/Entity/AttributeLoaderInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ interface AttributeLoaderInterface
1717
* Retrieve configuration for all attributes
1818
*
1919
* @param AbstractEntity $resource
20-
* @param DataObject|null $object
20+
* @param DataObject|null $entity
2121
* @return AbstractEntity
2222
*/
23-
public function loadAllAttributes(AbstractEntity $resource, DataObject $object = null);
23+
public function loadAllAttributes(AbstractEntity $resource, DataObject $entity = null);
2424
}

app/code/Magento/Eav/Test/Unit/Model/Entity/AttributeLoaderTest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public function testLoadAllAttributes()
7878
$attributeMock->expects($this->once())->method('setIsGlobal')->with(1)->willReturnSelf();
7979
$attributeMock->expects($this->once())->method('setEntityType')->with($this->entityTypeMock)->willReturnSelf();
8080
$attributeMock->expects($this->once())->method('setEntityTypeId')->with($entityTypeId)->willReturnSelf();
81-
$this->entityMock->expects($this->once())->method('addAttribute')->with($attributeMock)->willReturnSelf();
81+
$this->entityMock->expects($this->once())->method('addAttributeByScope')->willReturnSelf();
8282
$this->attributeLoader->loadAllAttributes($this->entityMock, $dataObject);
8383
}
8484

@@ -102,8 +102,7 @@ public function testLoadAllAttributesAttributeCodesPresentInDefaultAttributes()
102102
->method('getEntityAttributes')->willReturn($attributeCodes);
103103
$this->entityMock->expects($this->once())->method('getDefaultAttributes')->willReturn($defaultAttributes);
104104
$this->entityMock->expects($this->once())->method('unsetAttributes')->willReturnSelf();
105-
$this->entityMock->expects($this->atLeastOnce())
106-
->method('addAttribute')->with($attributeMock)->willReturnSelf();
105+
$this->entityMock->expects($this->atLeastOnce())->method('addAttributeByScope')->willReturnSelf();
107106
$this->objectManagerMock->expects($this->never())->method('create');
108107
$this->attributeLoader->loadAllAttributes($this->entityMock, $dataObject);
109108
}

0 commit comments

Comments
 (0)