Skip to content

Commit

Permalink
MAGETWO-52161: [GitHub] Bug in EAV with group_price attribute #69
Browse files Browse the repository at this point in the history
  • Loading branch information
le0n4eg committed Aug 22, 2016
1 parent 60a1647 commit b7a821d
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/Migration/Step/Eav/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ protected function migrateAttributes()
$this->map->getDocumentMap($sourceDocName, MapInterface::TYPE_SOURCE)
);
$this->destination->backupDocument($destinationDocument->getName());
$sourceRecords = $this->helper->clearIgnored($this->initialData->getAttributes('source'));
$sourceRecords = $this->helper->clearIgnoredAttributes($this->initialData->getAttributes('source'));
$destinationRecords = $this->initialData->getAttributes('dest');

$recordsToSave = $destinationDocument->getRecords();
Expand Down
19 changes: 4 additions & 15 deletions src/Migration/Step/Eav/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,30 +238,19 @@ public function getDesignAttributeAndGroupsData()
];
}

/**
* @param array $sourceRecords
* @return array
*/
public function clearIgnored($sourceRecords)
{
foreach (array_keys($this->readerAttributes->getGroup('ignore')) as $attributeToClear) {
$sourceRecords = $this->clearIgnoredAttributes($sourceRecords, $attributeToClear);
}
return $sourceRecords;
}

/**
* Remove ignored attributes from source records
*
* @param array $sourceRecords
* @param array $attributeToClear
* @return array
*/
protected function clearIgnoredAttributes($sourceRecords, $attributeToClear)
public function clearIgnoredAttributes($sourceRecords)
{
$ignoredAttributes = array_keys($this->readerAttributes->getGroup('ignore'));
foreach ($sourceRecords as $attrNum => $sourceAttribute) {
if (
isset($sourceAttribute['attribute_code']) && ($sourceAttribute['attribute_code'] == $attributeToClear)
isset($sourceAttribute['attribute_code'])
&& (in_array($sourceAttribute['attribute_code'], $ignoredAttributes))
) {
unset($sourceRecords[$attrNum]);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Migration/Step/Eav/Volume.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ protected function validateCustomConditions(array $attribute, array $conditions)
*/
protected function checkAttributesMismatch($attribute)
{
$sourceAttributes = $this->helper->clearIgnored($this->initialData->getAttributes('source'));
$sourceAttributes = $this->helper->clearIgnoredAttributes($this->initialData->getAttributes('source'));

if (isset($sourceAttributes[$attribute['attribute_id']])
&& ($sourceAttributes[$attribute['attribute_id']]['attribute_code'] != $attribute['attribute_code'])
Expand Down
29 changes: 29 additions & 0 deletions tests/unit/testsuite/Migration/Step/Eav/HelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,4 +226,33 @@ public function testDeleteBackups()
$this->destination->expects($this->once())->method('deleteDocumentBackup')->with('some_dest_document');
$this->helper->deleteBackups();
}

/**
* @return void
*/
public function testClearIgnoredAttributes()
{
$allSourceRecords = [
0 => [
'attribute_code' => 'ignored_attribute'
],
1 => [
'attribute_code' => 'attribute_1'
],
2 => [
'attribute_code' => 'attribute_2'
]
];
$clearedSourceRecords = [
1 => [
'attribute_code' => 'attribute_1'
],
2 => [
'attribute_code' => 'attribute_2'
]
];
$this->readerAttributes->expects($this->once())->method('getGroup')->with('ignore')
->willReturn(['ignored_attribute' => 0]);
$this->assertEquals($clearedSourceRecords, $this->helper->clearIgnoredAttributes($allSourceRecords));
}
}
5 changes: 3 additions & 2 deletions tests/unit/testsuite/Migration/Step/Eav/VolumeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function setUp()
'getSourceRecordsCount',
'getDestinationRecordsCount',
'deleteBackups',
'clearIgnored'
'clearIgnoredAttributes'
]
)->getMock();
$this->logger = $this->getMockBuilder('\Migration\Logger\Logger')->disableOriginalConstructor()
Expand Down Expand Up @@ -154,7 +154,8 @@ public function testPerform()
$this->initialData->expects($this->once())->method('getAttributeGroups')->willReturn(1);
$this->helper->expects($this->any())->method('getDestinationRecordsCount')->willReturn(2);
$this->helper->expects($this->once())->method('deleteBackups');
$this->helper->expects($this->any())->method('clearIgnored')->with($eavAttributes)->willReturn($eavAttributes);
$this->helper->expects($this->any())->method('clearIgnoredAttributes')->with($eavAttributes)
->willReturn($eavAttributes);
$this->logger->expects($this->never())->method('addRecord');

$documentsMap = $this->getDocumentsMap();
Expand Down

0 comments on commit b7a821d

Please sign in to comment.