Skip to content

Commit 7776ccb

Browse files
author
Oleksii Korshenko
committed
MAGETWO-65353: [GitHub][PR] Fix product option files not copying to order dir. #8462
- Merge Pull Request #8462 from evktalo/magento2:fix-copyQuoteToOrder
2 parents 5aca8ee + 00dd57d commit 7776ccb

File tree

2 files changed

+22
-17
lines changed
  • app/code/Magento/Catalog

2 files changed

+22
-17
lines changed

app/code/Magento/Catalog/Model/Product/Option/Type/File.php

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ class File extends \Magento\Catalog\Model\Product\Option\Type\DefaultType
3232
protected $_formattedOptionValue = null;
3333

3434
/**
35-
* @var \Magento\Framework\Filesystem\Directory\ReadInterface
35+
* @var \Magento\Framework\Filesystem\Directory\Write
3636
*/
37-
protected $_rootDirectory;
37+
protected $_mediaDirectory;
3838

3939
/**
4040
* Core file storage database
@@ -114,7 +114,7 @@ public function __construct(
114114
$this->_escaper = $escaper;
115115
$this->_coreFileStorageDatabase = $coreFileStorageDatabase;
116116
$this->filesystem = $filesystem ?: \Magento\Framework\App\ObjectManager::getInstance()->get(Filesystem::class);
117-
$this->_rootDirectory = $this->filesystem->getDirectoryRead(DirectoryList::MEDIA);
117+
$this->_mediaDirectory = $this->filesystem->getDirectoryWrite(DirectoryList::MEDIA);
118118
$this->validatorInfo = $validatorInfo;
119119
$this->validatorFile = $validatorFile;
120120
$this->serializer = $serializer ? $serializer : ObjectManager::getInstance()->get(Json::class);
@@ -473,13 +473,18 @@ public function copyQuoteToOrder()
473473
$quotePath = $value['quote_path'];
474474
$orderPath = $value['order_path'];
475475

476-
if (!$this->_rootDirectory->isFile($quotePath) || !$this->_rootDirectory->isReadable($quotePath)) {
476+
if (!$this->_mediaDirectory->isFile($quotePath) || !$this->_mediaDirectory->isReadable($quotePath)) {
477477
throw new \Exception();
478478
}
479-
$this->_coreFileStorageDatabase->copyFile(
480-
$this->_rootDirectory->getAbsolutePath($quotePath),
481-
$this->_rootDirectory->getAbsolutePath($orderPath)
482-
);
479+
480+
if ($this->_coreFileStorageDatabase->checkDbUsage()) {
481+
$this->_coreFileStorageDatabase->copyFile(
482+
$this->_mediaDirectory->getAbsolutePath($quotePath),
483+
$this->_mediaDirectory->getAbsolutePath($orderPath)
484+
);
485+
} else {
486+
$this->_mediaDirectory->copyFile($quotePath, $orderPath);
487+
}
483488
} catch (\Exception $e) {
484489
return $this;
485490
}

app/code/Magento/Catalog/Test/Unit/Model/Product/Option/Type/FileTest.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use Magento\Catalog\Model\Product\Configuration\Item\Option\OptionInterface;
99
use Magento\Framework\App\Filesystem\DirectoryList;
1010
use Magento\Framework\Filesystem;
11-
use Magento\Framework\Filesystem\Directory\ReadInterface;
11+
use Magento\Framework\Filesystem\Directory\WriteInterface;
1212
use Magento\Framework\Filesystem\DriverPool;
1313

1414
/**
@@ -24,9 +24,9 @@ class FileTest extends \PHPUnit_Framework_TestCase
2424
protected $objectManager;
2525

2626
/**
27-
* @var ReadInterface|\PHPUnit_Framework_MockObject_MockObject
27+
* @var WriteInterface|\PHPUnit_Framework_MockObject_MockObject
2828
*/
29-
protected $rootDirectory;
29+
protected $mediaDirectory;
3030

3131
/**
3232
* @var \Magento\MediaStorage\Helper\File\Storage\Database|\PHPUnit_Framework_MockObject_MockObject
@@ -61,13 +61,13 @@ protected function setUp()
6161
->disableOriginalConstructor()
6262
->getMock();
6363

64-
$this->rootDirectory = $this->getMockBuilder(ReadInterface::class)
64+
$this->mediaDirectory = $this->getMockBuilder(WriteInterface::class)
6565
->getMock();
6666

6767
$this->filesystemMock->expects($this->any())
68-
->method('getDirectoryRead')
68+
->method('getDirectoryWrite')
6969
->with(DirectoryList::MEDIA, DriverPool::FILE)
70-
->willReturn($this->rootDirectory);
70+
->willReturn($this->mediaDirectory);
7171

7272
$this->serializer = $this->getMockBuilder(\Magento\Framework\Serialize\Serializer\Json::class)
7373
->disableOriginalConstructor()
@@ -158,17 +158,17 @@ function ($value) {
158158
->method('getValue')
159159
->will($this->returnValue($quoteValue));
160160

161-
$this->rootDirectory->expects($this->any())
161+
$this->mediaDirectory->expects($this->any())
162162
->method('isFile')
163163
->with($this->equalTo($quotePath))
164164
->will($this->returnValue(true));
165165

166-
$this->rootDirectory->expects($this->any())
166+
$this->mediaDirectory->expects($this->any())
167167
->method('isReadable')
168168
->with($this->equalTo($quotePath))
169169
->will($this->returnValue(true));
170170

171-
$this->rootDirectory->expects($this->any())
171+
$this->mediaDirectory->expects($this->any())
172172
->method('getAbsolutePath')
173173
->will($this->returnValue('/file.path'));
174174

0 commit comments

Comments
 (0)