Skip to content

Commit f80d186

Browse files
committed
MAGETWO-32116: Customer model and tables cleaning
1 parent 42bef9e commit f80d186

File tree

7 files changed

+48
-51
lines changed

7 files changed

+48
-51
lines changed

app/code/Magento/Customer/Model/Address.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,9 @@ public function updateData(AddressInterface $address)
127127
// Need to explicitly set this due to discrepancy in the keys between model and data object
128128
$this->setIsDefaultBilling($address->isDefaultBilling());
129129
$this->setIsDefaultShipping($address->isDefaultShipping());
130-
130+
if (!$this->getAttributeSetId()) {
131+
$this->setAttributeSetId(AddressMetadataInterface::ATTRIBUTE_SET_ID_ADDRESS);
132+
}
131133
$customAttributes = $address->getCustomAttributes();
132134
if (!is_null($customAttributes)) {
133135
foreach ($customAttributes as $attribute) {
@@ -278,4 +280,14 @@ protected function _createCustomer()
278280
{
279281
return $this->_customerFactory->create();
280282
}
283+
284+
/**
285+
* Return Entity Type ID
286+
*
287+
* @return int
288+
*/
289+
public function getEntityTypeId()
290+
{
291+
return $this->getEntityType()->getId();
292+
}
281293
}

app/code/Magento/Customer/Model/Resource/Address/Collection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
* @author Magento Core Team <core@magentocommerce.com>
1111
*/
12-
class Collection extends \Magento\Customer\Model\Resource\Collection\AbstractCollection
12+
class Collection extends \Magento\Eav\Model\Entity\Collection\AbstractCollection
1313
{
1414
/**
1515
* Resource initialization

app/code/Magento/Customer/Model/Resource/Collection/AbstractCollection.php

Lines changed: 0 additions & 43 deletions
This file was deleted.

app/code/Magento/Customer/Model/Resource/Customer/Collection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
* @author Magento Core Team <core@magentocommerce.com>
1111
*/
12-
class Collection extends \Magento\Customer\Model\Resource\Collection\AbstractCollection
12+
class Collection extends \Magento\Eav\Model\Entity\Collection\AbstractCollection
1313
{
1414
/**
1515
* Name of collection model

app/code/Magento/CustomerImportExport/Model/Import/Address.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,6 @@ protected function _saveCustomerDefaults(array $defaults)
581581
{
582582
/** @var $entity \Magento\Customer\Model\Customer */
583583
$entity = $this->_customerFactory->create();
584-
$entityTypeId = $entity->getEntityTypeId();
585584

586585
foreach ($defaults as $tableName => $data) {
587586
$tableData = [];

app/code/Magento/Eav/Model/Entity/Collection/AbstractCollection.php

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,13 @@ abstract class AbstractCollection extends \Magento\Framework\Data\Collection\Db
113113
*/
114114
protected $_universalFactory;
115115

116+
/**
117+
* Specific entity types which not required "entity_type_id" for select
118+
*
119+
* @var array
120+
*/
121+
protected $entityTypes = ['customer', 'customer_address'];
122+
116123
/**
117124
* @param \Magento\Core\Model\EntityFactory $entityFactory
118125
* @param \Magento\Framework\Logger $logger
@@ -191,7 +198,8 @@ protected function _prepareStaticFields()
191198
protected function _initSelect()
192199
{
193200
$this->getSelect()->from(['e' => $this->getEntity()->getEntityTable()]);
194-
if ($this->getEntity()->getTypeId()) {
201+
$entity = $this->getEntity();
202+
if ($entity->getTypeId() && !in_array($entity->getType(), $this->entityTypes)) {
195203
$this->addAttributeToFilter('entity_type_id', $this->getEntity()->getTypeId());
196204
}
197205
return $this;
@@ -1165,16 +1173,21 @@ protected function _getLoadAttributesSelect($table, $attributeIds = [])
11651173
$select = $this->getConnection()->select()->from(
11661174
$table,
11671175
[$entityIdField, 'attribute_id']
1168-
)->where(
1169-
'entity_type_id =?',
1170-
$this->getEntity()->getTypeId()
11711176
)->where(
11721177
"{$entityIdField} IN (?)",
11731178
array_keys($this->_itemsById)
11741179
)->where(
11751180
'attribute_id IN (?)',
11761181
$attributeIds
11771182
);
1183+
1184+
if(!in_array($this->getEntity()->getType(), $this->entityTypes))
1185+
{
1186+
$select->where(
1187+
'entity_type_id =?',
1188+
$this->getEntity()->getTypeId()
1189+
);
1190+
}
11781191
return $select;
11791192
}
11801193

dev/tests/unit/testsuite/Magento/Customer/Model/AddressTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,4 +121,20 @@ public function testRegionId()
121121
$this->address->setRegionId(1);
122122
$this->assertEquals(1, $this->address->getRegionId());
123123
}
124+
125+
public function testGetEntityTypeId()
126+
{
127+
$mockEntityType = $this->getMockBuilder('Magento\Eav\Model\Entity\Type')
128+
->disableOriginalConstructor()
129+
->getMock();
130+
$mockEntityType->expects($this->any())
131+
->method('getId')
132+
->will($this->returnValue(self::ORIG_CUSTOMER_ID));
133+
134+
$this->resource->expects($this->any())
135+
->method('getEntityType')
136+
->will($this->returnValue($mockEntityType));
137+
138+
$this->assertEquals(self::ORIG_CUSTOMER_ID, $this->address->getEntityTypeId());
139+
}
124140
}

0 commit comments

Comments
 (0)