Skip to content

Commit 39229d6

Browse files
author
Oleksii Korshenko
authored
Merge pull request #548 from magento-dragons/DRAGONS-PR2.0
Fixed issues: - MAGETWO-59050 Portdown MAGETWO-50198 to 2.0 - MAGETWO-59829 [Backport] Product import with images not working
2 parents 572505c + a03ce7d commit 39229d6

File tree

3 files changed

+36
-46
lines changed

3 files changed

+36
-46
lines changed

app/code/Magento/CatalogImportExport/Model/Import/Uploader.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,8 @@ public function move($fileName, $renameFileOff = false)
155155

156156
$filePath = $this->_directory->getRelativePath($this->getTmpDir() . '/' . $fileName);
157157
$this->_setUploadFile($filePath);
158-
$result = $this->save($this->getDestDir());
158+
$destDir = $this->_directory->getAbsolutePath($this->getDestDir());
159+
$result = $this->save($destDir);
159160
$result['name'] = self::getCorrectFileName($result['name']);
160161
return $result;
161162
}
@@ -305,11 +306,10 @@ protected function _moveFile($tmpPath, $destPath)
305306
$tmpRealPath = $this->_directory->getDriver()->getRealPath(
306307
$this->_directory->getAbsolutePath($tmpPath)
307308
);
308-
$destinationRealPath = $this->_directory->getDriver()->getRealPath(
309-
$this->_directory->getAbsolutePath($destPath)
310-
);
309+
$destinationRealPath = $this->_directory->getDriver()->getRealPath($destPath);
310+
$relativeDestPath = $this->_directory->getRelativePath($destPath);
311311
$isSameFile = $tmpRealPath === $destinationRealPath;
312-
return $isSameFile ?: $this->_directory->copyFile($tmpPath, $destPath);
312+
return $isSameFile ?: $this->_directory->copyFile($tmpPath, $relativeDestPath);
313313
} else {
314314
return false;
315315
}

app/code/Magento/CatalogImportExport/Test/Unit/Model/Import/UploaderTest.php

Lines changed: 26 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,11 @@ protected function setUp()
6868

6969
$this->readFactory = $this->getMockBuilder('\Magento\Framework\Filesystem\File\ReadFactory')
7070
->disableOriginalConstructor()
71+
->setMethods(['create'])
7172
->getMock();
7273

7374
$this->directoryMock = $this->getMockBuilder('\Magento\Framework\Filesystem\Directory\Writer')
74-
->setMethods(['writeFile', 'getRelativePath'])
75+
->setMethods(['writeFile', 'getRelativePath', 'isWritable', 'getAbsolutePath'])
7576
->disableOriginalConstructor()
7677
->getMock();
7778

@@ -92,6 +93,7 @@ protected function setUp()
9293
$this->filesystem,
9394
$this->readFactory,
9495
])
96+
->setMethods(['_setUploadFile', 'save', 'getTmpDir'])
9597
->getMock();
9698
}
9799

@@ -100,10 +102,14 @@ protected function setUp()
100102
*/
101103
public function testMoveFileUrl($fileUrl, $expectedHost, $expectedFileName)
102104
{
105+
$destDir = 'var/dest/dir';
103106
$expectedRelativeFilePath = $this->uploader->getTmpDir() . '/' . $expectedFileName;
107+
$this->directoryMock->expects($this->once())->method('isWritable')->with($destDir)->willReturn(true);
104108
$this->directoryMock->expects($this->any())->method('getRelativePath')->with($expectedRelativeFilePath);
109+
$this->directoryMock->expects($this->once())->method('getAbsolutePath')->with($destDir)
110+
->willReturn($destDir . '/' . $expectedFileName);
105111
// Check writeFile() method invoking.
106-
$this->directoryMock->expects($this->any())->method('writeFile')->will($this->returnValue(null));
112+
$this->directoryMock->expects($this->any())->method('writeFile')->will($this->returnValue($expectedFileName));
107113

108114
// Create adjusted reader which does not validate path.
109115
$readMock = $this->getMockBuilder('Magento\Framework\Filesystem\File\Read')
@@ -113,59 +119,39 @@ public function testMoveFileUrl($fileUrl, $expectedHost, $expectedFileName)
113119
// Check readAll() method invoking.
114120
$readMock->expects($this->once())->method('readAll')->will($this->returnValue(null));
115121

116-
$this->readFactory = $this->getMockBuilder('\Magento\Framework\Filesystem\File\ReadFactory')
117-
->disableOriginalConstructor()
118-
->setMethods(['create'])
119-
->getMock();
120122
// Check create() method invoking with expected argument.
121123
$this->readFactory->expects($this->once())
122-
->method('create')
123-
->will($this->returnValue($readMock))->with($expectedHost);
124-
125-
$uploaderMock = $this->getMockBuilder('\Magento\CatalogImportExport\Model\Import\Uploader')
126-
->setConstructorArgs([
127-
$this->coreFileStorageDb,
128-
$this->coreFileStorage,
129-
$this->imageFactory,
130-
$this->validator,
131-
$this->filesystem,
132-
$this->readFactory,
133-
])
134-
->setMethods(['_setUploadFile', 'save', 'getTmpDir'])
135-
->getMock();
124+
->method('create')
125+
->will($this->returnValue($readMock))->with($expectedHost);
136126

137127
//Check invoking of getTmpDir(), _setUploadFile(), save() methods.
138-
$uploaderMock->expects($this->any())->method('getTmpDir')->will($this->returnValue(''));
139-
$uploaderMock->expects($this->once())->method('_setUploadFile')->will($this->returnSelf());
140-
$uploaderMock->expects($this->once())->method('save')->will($this->returnValue(['name' => null]));
128+
$this->uploader->expects($this->any())->method('getTmpDir')->will($this->returnValue(''));
129+
$this->uploader->expects($this->once())->method('_setUploadFile')->will($this->returnSelf());
130+
$this->uploader->expects($this->once())->method('save')->with($destDir . '/' . $expectedFileName)
131+
->willReturn(['name' => $expectedFileName]);
141132

142-
$uploaderMock->move($fileUrl);
133+
$this->uploader->setDestDir($destDir);
134+
$this->assertEquals(['name' => $expectedFileName], $this->uploader->move($fileUrl));
143135
}
144136

145137
public function testMoveFileName()
146138
{
139+
$destDir = 'var/dest/dir';
147140
$fileName = 'test_uploader_file';
148141
$expectedRelativeFilePath = $this->uploader->getTmpDir() . '/' . $fileName;
142+
$this->directoryMock->expects($this->once())->method('isWritable')->with($destDir)->willReturn(true);
149143
$this->directoryMock->expects($this->any())->method('getRelativePath')->with($expectedRelativeFilePath);
150-
151-
$uploaderMock = $this->getMockBuilder('\Magento\CatalogImportExport\Model\Import\Uploader')
152-
->setConstructorArgs([
153-
$this->coreFileStorageDb,
154-
$this->coreFileStorage,
155-
$this->imageFactory,
156-
$this->validator,
157-
$this->filesystem,
158-
$this->readFactory,
159-
])
160-
->setMethods(['_setUploadFile', 'save', 'getTmpDir'])
161-
->getMock();
144+
$this->directoryMock->expects($this->once())->method('getAbsolutePath')->with($destDir)
145+
->willReturn($destDir . '/' . $fileName);
162146

163147
//Check invoking of getTmpDir(), _setUploadFile(), save() methods.
164-
$uploaderMock->expects($this->once())->method('getTmpDir')->will($this->returnValue(''));
165-
$uploaderMock->expects($this->once())->method('_setUploadFile')->will($this->returnSelf());
166-
$uploaderMock->expects($this->once())->method('save')->will($this->returnValue(['name' => null]));
148+
$this->uploader->expects($this->once())->method('getTmpDir')->will($this->returnValue(''));
149+
$this->uploader->expects($this->once())->method('_setUploadFile')->will($this->returnSelf());
150+
$this->uploader->expects($this->once())->method('save')->with($destDir . '/' . $fileName)
151+
->willReturn(['name' => $fileName]);
167152

168-
$uploaderMock->move($fileName);
153+
$this->uploader->setDestDir($destDir);
154+
$this->assertEquals(['name' => $fileName], $this->uploader->move($fileName));
169155
}
170156

171157
public function moveFileUrlDataProvider()

app/code/Magento/Checkout/Model/Cart.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,11 @@ public function addOrderItem($orderItem, $qtyFlag = null)
261261
if ($orderItem->getParentItem() === null) {
262262
$storeId = $this->_storeManager->getStore()->getId();
263263
try {
264-
$product = $this->productRepository->getById($orderItem->getProductId(), false, $storeId);
264+
/**
265+
* We need to reload product in this place, because products
266+
* with the same id may have different sets of order attributes.
267+
*/
268+
$product = $this->productRepository->getById($orderItem->getProductId(), false, $storeId, true);
265269
} catch (NoSuchEntityException $e) {
266270
return $this;
267271
}

0 commit comments

Comments
 (0)