From b7a821df893b7e5f17525e729908b54ef28d28d0 Mon Sep 17 00:00:00 2001 From: Leonid Poluyanov Date: Mon, 22 Aug 2016 14:44:19 +0300 Subject: [PATCH] MAGETWO-52161: [GitHub] Bug in EAV with group_price attribute #69 --- src/Migration/Step/Eav/Data.php | 2 +- src/Migration/Step/Eav/Helper.php | 19 +++--------- src/Migration/Step/Eav/Volume.php | 2 +- .../Migration/Step/Eav/HelperTest.php | 29 +++++++++++++++++++ .../Migration/Step/Eav/VolumeTest.php | 5 ++-- 5 files changed, 38 insertions(+), 19 deletions(-) diff --git a/src/Migration/Step/Eav/Data.php b/src/Migration/Step/Eav/Data.php index 65576e98e..6f81e5203 100644 --- a/src/Migration/Step/Eav/Data.php +++ b/src/Migration/Step/Eav/Data.php @@ -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(); diff --git a/src/Migration/Step/Eav/Helper.php b/src/Migration/Step/Eav/Helper.php index 886e15bbe..81c83bb34 100644 --- a/src/Migration/Step/Eav/Helper.php +++ b/src/Migration/Step/Eav/Helper.php @@ -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]); } diff --git a/src/Migration/Step/Eav/Volume.php b/src/Migration/Step/Eav/Volume.php index 2a35d2c21..d77edadd0 100644 --- a/src/Migration/Step/Eav/Volume.php +++ b/src/Migration/Step/Eav/Volume.php @@ -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']) diff --git a/tests/unit/testsuite/Migration/Step/Eav/HelperTest.php b/tests/unit/testsuite/Migration/Step/Eav/HelperTest.php index ea17933e3..3e6c3040e 100644 --- a/tests/unit/testsuite/Migration/Step/Eav/HelperTest.php +++ b/tests/unit/testsuite/Migration/Step/Eav/HelperTest.php @@ -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)); + } } diff --git a/tests/unit/testsuite/Migration/Step/Eav/VolumeTest.php b/tests/unit/testsuite/Migration/Step/Eav/VolumeTest.php index d899a7e5b..17550c95b 100644 --- a/tests/unit/testsuite/Migration/Step/Eav/VolumeTest.php +++ b/tests/unit/testsuite/Migration/Step/Eav/VolumeTest.php @@ -60,7 +60,7 @@ public function setUp() 'getSourceRecordsCount', 'getDestinationRecordsCount', 'deleteBackups', - 'clearIgnored' + 'clearIgnoredAttributes' ] )->getMock(); $this->logger = $this->getMockBuilder('\Migration\Logger\Logger')->disableOriginalConstructor() @@ -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();