From 565b70127184999e85c8d7eb5bab4f1f2a793e6d Mon Sep 17 00:00:00 2001 From: Illia Grybkov Date: Wed, 19 Oct 2016 17:52:12 +0300 Subject: [PATCH 1/4] MAGETWO-59050: [GITHUB] Options for Configurable product are merged in one product if Reorder #3654 - Backport fix for 2.0.x --- app/code/Magento/Checkout/Model/Cart.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Checkout/Model/Cart.php b/app/code/Magento/Checkout/Model/Cart.php index 759ce84ce8fc3..bfb8f6be5d022 100644 --- a/app/code/Magento/Checkout/Model/Cart.php +++ b/app/code/Magento/Checkout/Model/Cart.php @@ -261,7 +261,11 @@ public function addOrderItem($orderItem, $qtyFlag = null) if ($orderItem->getParentItem() === null) { $storeId = $this->_storeManager->getStore()->getId(); try { - $product = $this->productRepository->getById($orderItem->getProductId(), false, $storeId); + /** + * We need to reload product in this place, because products + * with the same id may have different sets of order attributes. + */ + $product = $this->productRepository->getById($orderItem->getProductId(), false, $storeId, true); } catch (NoSuchEntityException $e) { return $this; } From 39d2c984ee09405a1fb3ec99662fcdd50e082881 Mon Sep 17 00:00:00 2001 From: Maksym Aposov Date: Wed, 26 Oct 2016 16:41:13 +0300 Subject: [PATCH 2/4] MAGETWO-59829: [Backport] Product import with images not working --- .../Model/Import/Uploader.php | 10 +-- .../Test/Unit/Model/Import/UploaderTest.php | 66 ++++++++----------- 2 files changed, 33 insertions(+), 43 deletions(-) diff --git a/app/code/Magento/CatalogImportExport/Model/Import/Uploader.php b/app/code/Magento/CatalogImportExport/Model/Import/Uploader.php index 4dfde3887df85..fcc544f4cb805 100644 --- a/app/code/Magento/CatalogImportExport/Model/Import/Uploader.php +++ b/app/code/Magento/CatalogImportExport/Model/Import/Uploader.php @@ -155,7 +155,8 @@ public function move($fileName, $renameFileOff = false) $filePath = $this->_directory->getRelativePath($this->getTmpDir() . '/' . $fileName); $this->_setUploadFile($filePath); - $result = $this->save($this->getDestDir()); + $destDir = $this->_directory->getAbsolutePath($this->getDestDir()); + $result = $this->save($destDir); $result['name'] = self::getCorrectFileName($result['name']); return $result; } @@ -305,11 +306,10 @@ protected function _moveFile($tmpPath, $destPath) $tmpRealPath = $this->_directory->getDriver()->getRealPath( $this->_directory->getAbsolutePath($tmpPath) ); - $destinationRealPath = $this->_directory->getDriver()->getRealPath( - $this->_directory->getAbsolutePath($destPath) - ); + $destinationRealPath = $this->_directory->getDriver()->getRealPath($destPath); + $relativeDestPath = $this->_directory->getRelativePath($destPath); $isSameFile = $tmpRealPath === $destinationRealPath; - return $isSameFile ?: $this->_directory->copyFile($tmpPath, $destPath); + return $isSameFile ?: $this->_directory->copyFile($tmpPath, $relativeDestPath); } else { return false; } diff --git a/app/code/Magento/CatalogImportExport/Test/Unit/Model/Import/UploaderTest.php b/app/code/Magento/CatalogImportExport/Test/Unit/Model/Import/UploaderTest.php index ef40216ddf924..238121363d3d6 100644 --- a/app/code/Magento/CatalogImportExport/Test/Unit/Model/Import/UploaderTest.php +++ b/app/code/Magento/CatalogImportExport/Test/Unit/Model/Import/UploaderTest.php @@ -68,10 +68,11 @@ protected function setUp() $this->readFactory = $this->getMockBuilder('\Magento\Framework\Filesystem\File\ReadFactory') ->disableOriginalConstructor() + ->setMethods(['create']) ->getMock(); $this->directoryMock = $this->getMockBuilder('\Magento\Framework\Filesystem\Directory\Writer') - ->setMethods(['writeFile', 'getRelativePath']) + ->setMethods(['writeFile', 'getRelativePath', 'isWritable', 'getAbsolutePath']) ->disableOriginalConstructor() ->getMock(); @@ -92,6 +93,7 @@ protected function setUp() $this->filesystem, $this->readFactory, ]) + ->setMethods(['_setUploadFile', 'save', 'getTmpDir']) ->getMock(); } @@ -100,10 +102,14 @@ protected function setUp() */ public function testMoveFileUrl($fileUrl, $expectedHost, $expectedFileName) { + $destDir = 'var/dest/dir'; $expectedRelativeFilePath = $this->uploader->getTmpDir() . '/' . $expectedFileName; + $this->directoryMock->expects($this->once())->method('isWritable')->with($destDir)->willReturn(true); $this->directoryMock->expects($this->any())->method('getRelativePath')->with($expectedRelativeFilePath); + $this->directoryMock->expects($this->once())->method('getAbsolutePath')->with($destDir) + ->willReturn($destDir . '/' . $expectedFileName); // Check writeFile() method invoking. - $this->directoryMock->expects($this->any())->method('writeFile')->will($this->returnValue(null)); + $this->directoryMock->expects($this->any())->method('writeFile')->will($this->returnValue($expectedFileName)); // Create adjusted reader which does not validate path. $readMock = $this->getMockBuilder('Magento\Framework\Filesystem\File\Read') @@ -113,59 +119,43 @@ public function testMoveFileUrl($fileUrl, $expectedHost, $expectedFileName) // Check readAll() method invoking. $readMock->expects($this->once())->method('readAll')->will($this->returnValue(null)); - $this->readFactory = $this->getMockBuilder('\Magento\Framework\Filesystem\File\ReadFactory') +/* $this->readFactory = $this->getMockBuilder('\Magento\Framework\Filesystem\File\ReadFactory') ->disableOriginalConstructor() ->setMethods(['create']) - ->getMock(); + ->getMock();*/ // Check create() method invoking with expected argument. $this->readFactory->expects($this->once()) - ->method('create') - ->will($this->returnValue($readMock))->with($expectedHost); - - $uploaderMock = $this->getMockBuilder('\Magento\CatalogImportExport\Model\Import\Uploader') - ->setConstructorArgs([ - $this->coreFileStorageDb, - $this->coreFileStorage, - $this->imageFactory, - $this->validator, - $this->filesystem, - $this->readFactory, - ]) - ->setMethods(['_setUploadFile', 'save', 'getTmpDir']) - ->getMock(); + ->method('create') + ->will($this->returnValue($readMock))->with($expectedHost); //Check invoking of getTmpDir(), _setUploadFile(), save() methods. - $uploaderMock->expects($this->any())->method('getTmpDir')->will($this->returnValue('')); - $uploaderMock->expects($this->once())->method('_setUploadFile')->will($this->returnSelf()); - $uploaderMock->expects($this->once())->method('save')->will($this->returnValue(['name' => null])); + $this->uploader->expects($this->any())->method('getTmpDir')->will($this->returnValue('')); + $this->uploader->expects($this->once())->method('_setUploadFile')->will($this->returnSelf()); + $this->uploader->expects($this->once())->method('save')->with($destDir . '/' . $expectedFileName) + ->willReturn(['name' => $expectedFileName]); - $uploaderMock->move($fileUrl); + $this->uploader->setDestDir($destDir); + $this->assertEquals(['name' => $expectedFileName], $this->uploader->move($fileUrl)); } public function testMoveFileName() { + $destDir = 'var/dest/dir'; $fileName = 'test_uploader_file'; $expectedRelativeFilePath = $this->uploader->getTmpDir() . '/' . $fileName; + $this->directoryMock->expects($this->once())->method('isWritable')->with($destDir)->willReturn(true); $this->directoryMock->expects($this->any())->method('getRelativePath')->with($expectedRelativeFilePath); - - $uploaderMock = $this->getMockBuilder('\Magento\CatalogImportExport\Model\Import\Uploader') - ->setConstructorArgs([ - $this->coreFileStorageDb, - $this->coreFileStorage, - $this->imageFactory, - $this->validator, - $this->filesystem, - $this->readFactory, - ]) - ->setMethods(['_setUploadFile', 'save', 'getTmpDir']) - ->getMock(); + $this->directoryMock->expects($this->once())->method('getAbsolutePath')->with($destDir) + ->willReturn($destDir . '/' . $fileName); //Check invoking of getTmpDir(), _setUploadFile(), save() methods. - $uploaderMock->expects($this->once())->method('getTmpDir')->will($this->returnValue('')); - $uploaderMock->expects($this->once())->method('_setUploadFile')->will($this->returnSelf()); - $uploaderMock->expects($this->once())->method('save')->will($this->returnValue(['name' => null])); + $this->uploader->expects($this->once())->method('getTmpDir')->will($this->returnValue('')); + $this->uploader->expects($this->once())->method('_setUploadFile')->will($this->returnSelf()); + $this->uploader->expects($this->once())->method('save')->with($destDir . '/' . $fileName) + ->willReturn(['name' => $fileName]); - $uploaderMock->move($fileName); + $this->uploader->setDestDir($destDir); + $this->assertEquals(['name' => $fileName], $this->uploader->move($fileName)); } public function moveFileUrlDataProvider() From 91020c021165041fadeedff0d1a4c165621ca946 Mon Sep 17 00:00:00 2001 From: Maksym Aposov Date: Wed, 26 Oct 2016 18:25:40 +0300 Subject: [PATCH 3/4] MAGETWO-59829: [Backport] Product import with images not working --- .../Test/Unit/Model/Import/UploaderTest.php | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/app/code/Magento/CatalogImportExport/Test/Unit/Model/Import/UploaderTest.php b/app/code/Magento/CatalogImportExport/Test/Unit/Model/Import/UploaderTest.php index 238121363d3d6..8d94f9f7c7f3e 100644 --- a/app/code/Magento/CatalogImportExport/Test/Unit/Model/Import/UploaderTest.php +++ b/app/code/Magento/CatalogImportExport/Test/Unit/Model/Import/UploaderTest.php @@ -119,10 +119,6 @@ public function testMoveFileUrl($fileUrl, $expectedHost, $expectedFileName) // Check readAll() method invoking. $readMock->expects($this->once())->method('readAll')->will($this->returnValue(null)); -/* $this->readFactory = $this->getMockBuilder('\Magento\Framework\Filesystem\File\ReadFactory') - ->disableOriginalConstructor() - ->setMethods(['create']) - ->getMock();*/ // Check create() method invoking with expected argument. $this->readFactory->expects($this->once()) ->method('create') @@ -135,7 +131,7 @@ public function testMoveFileUrl($fileUrl, $expectedHost, $expectedFileName) ->willReturn(['name' => $expectedFileName]); $this->uploader->setDestDir($destDir); - $this->assertEquals(['name' => $expectedFileName], $this->uploader->move($fileUrl)); + $this->assertEquals(['name' => $expectedFileName], $this->uploader->move($fileUrl)); } public function testMoveFileName() @@ -151,8 +147,11 @@ public function testMoveFileName() //Check invoking of getTmpDir(), _setUploadFile(), save() methods. $this->uploader->expects($this->once())->method('getTmpDir')->will($this->returnValue('')); $this->uploader->expects($this->once())->method('_setUploadFile')->will($this->returnSelf()); - $this->uploader->expects($this->once())->method('save')->with($destDir . '/' . $fileName) - ->willReturn(['name' => $fileName]); + $this->uploader + ->expects($this->once()) + ->method('save') + ->with($destDir . '/' . $fileName) + ->willReturn(['name' => $fileName]); $this->uploader->setDestDir($destDir); $this->assertEquals(['name' => $fileName], $this->uploader->move($fileName)); From aed266f089e15d5f3fe93f2f00c1e00579d6e383 Mon Sep 17 00:00:00 2001 From: Maksym Aposov Date: Wed, 26 Oct 2016 18:35:16 +0300 Subject: [PATCH 4/4] MAGETWO-59829: [Backport] Product import with images not working --- .../Test/Unit/Model/Import/UploaderTest.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/app/code/Magento/CatalogImportExport/Test/Unit/Model/Import/UploaderTest.php b/app/code/Magento/CatalogImportExport/Test/Unit/Model/Import/UploaderTest.php index 8d94f9f7c7f3e..48de57fa0aa10 100644 --- a/app/code/Magento/CatalogImportExport/Test/Unit/Model/Import/UploaderTest.php +++ b/app/code/Magento/CatalogImportExport/Test/Unit/Model/Import/UploaderTest.php @@ -142,15 +142,12 @@ public function testMoveFileName() $this->directoryMock->expects($this->once())->method('isWritable')->with($destDir)->willReturn(true); $this->directoryMock->expects($this->any())->method('getRelativePath')->with($expectedRelativeFilePath); $this->directoryMock->expects($this->once())->method('getAbsolutePath')->with($destDir) - ->willReturn($destDir . '/' . $fileName); + ->willReturn($destDir . '/' . $fileName); //Check invoking of getTmpDir(), _setUploadFile(), save() methods. $this->uploader->expects($this->once())->method('getTmpDir')->will($this->returnValue('')); $this->uploader->expects($this->once())->method('_setUploadFile')->will($this->returnSelf()); - $this->uploader - ->expects($this->once()) - ->method('save') - ->with($destDir . '/' . $fileName) + $this->uploader->expects($this->once())->method('save')->with($destDir . '/' . $fileName) ->willReturn(['name' => $fileName]); $this->uploader->setDestDir($destDir);