Skip to content

Commit 5bfe78b

Browse files
committed
Merge remote-tracking branch 'origin/B2B-2060' into B2B-2022
2 parents 0027975 + 55696fa commit 5bfe78b

File tree

2 files changed

+29
-11
lines changed
  • app/code/Magento/Catalog/Model/Webapi/Product/Option/Type/File
  • dev/tests/integration/testsuite/Magento/Catalog/Model/Webapi/Product/Option/Type/File

2 files changed

+29
-11
lines changed

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,11 @@ public function __construct(
4040
}
4141

4242
/**
43+
* Saves file
44+
*
4345
* @param ImageContentInterface $imageContent
4446
* @return string
47+
* @throws \Magento\Framework\Exception\InputException
4548
*/
4649
protected function saveFile(ImageContentInterface $imageContent)
4750
{
@@ -50,6 +53,8 @@ protected function saveFile(ImageContentInterface $imageContent)
5053
}
5154

5255
/**
56+
* Save file content and return file details
57+
*
5358
* @param ImageContentInterface $imageContent
5459
* @return array
5560
* @throws \Magento\Framework\Exception\LocalizedException
@@ -58,16 +63,19 @@ public function processFileContent(ImageContentInterface $imageContent)
5863
{
5964
$filePath = $this->saveFile($imageContent);
6065

61-
$fileAbsolutePath = $this->filesystem->getDirectoryRead(DirectoryList::MEDIA)->getAbsolutePath($filePath);
62-
$fileHash = hash('sha256', $this->filesystem->getDirectoryRead(DirectoryList::MEDIA)->readFile($filePath));
63-
$imageSize = getimagesize($fileAbsolutePath);
66+
$mediaDirectory = $this->filesystem->getDirectoryRead(DirectoryList::MEDIA);
67+
$fileAbsolutePath = $mediaDirectory->getAbsolutePath($filePath);
68+
$fileContent = $mediaDirectory->readFile($filePath);
69+
$fileHash = hash('sha256', $fileContent);
70+
$imageSize = getimagesizefromstring($fileContent);
71+
$stat = $mediaDirectory->stat($fileAbsolutePath);
6472
$result = [
6573
'type' => $imageContent->getType(),
6674
'title' => $imageContent->getName(),
6775
'fullpath' => $fileAbsolutePath,
6876
'quote_path' => $filePath,
6977
'order_path' => $filePath,
70-
'size' => filesize($fileAbsolutePath),
78+
'size' => $stat['size'],
7179
'width' => $imageSize ? $imageSize[0] : 0,
7280
'height' => $imageSize ? $imageSize[1] : 0,
7381
'secret_key' => substr($fileHash, 0, 20),

dev/tests/integration/testsuite/Magento/Catalog/Model/Webapi/Product/Option/Type/File/ProcessorTest.php

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,33 @@ public function testProcessFileContent($pathConfig)
2929
$imageContent = $this->objectManager->create(
3030
\Magento\Framework\Api\Data\ImageContentInterface::class
3131
);
32+
$fileExpectedParams = [
33+
'type' => 'image/png',
34+
'title' => 'my_file',
35+
'size' => 212,
36+
'width' => 10,
37+
'height' => 10,
38+
'secret_key' => 'bc9577055da436b9c116',
39+
];
3240
$imageContent->setName('my_file');
3341
$imageContent->setType('image/png');
3442
$imageContent->setBase64EncodedData($this->getImageContent());
3543
$result = $model->processFileContent($imageContent);
3644

37-
$this->assertArrayHasKey('fullpath', $result);
38-
$this->assertFileExists($result['fullpath']);
39-
4045
/** @var $filesystem \Magento\Framework\Filesystem */
4146
$filesystem = $this->objectManager->get(\Magento\Framework\Filesystem::class);
47+
$directory = $filesystem->getDirectoryRead(DirectoryList::MEDIA);
48+
$this->assertArrayHasKey('fullpath', $result);
49+
$this->assertEmpty(array_diff_assoc($fileExpectedParams, $result), 'Some file parameters are not correct');
50+
$this->assertTrue($directory->isExist($result['fullpath']));
51+
4252
$this->assertArrayHasKey('quote_path', $result);
43-
$filePath = $filesystem->getDirectoryRead(DirectoryList::MEDIA)->getAbsolutePath($result['quote_path']);
44-
$this->assertFileExists($filePath);
53+
$filePath = $directory->getAbsolutePath($result['quote_path']);
54+
$this->assertTrue($directory->isExist($filePath));
4555

4656
$this->assertArrayHasKey('order_path', $result);
47-
$filePath = $filesystem->getDirectoryRead(DirectoryList::MEDIA)->getAbsolutePath($result['order_path']);
48-
$this->assertFileExists($filePath);
57+
$filePath = $directory->getAbsolutePath($result['order_path']);
58+
$this->assertTrue($directory->isExist($filePath));
4959
}
5060

5161
public function pathConfigDataProvider()

0 commit comments

Comments
 (0)