Skip to content

Commit 3fe2de0

Browse files
author
Oleksii Korshenko
committed
Merge branch 'develop' into API-Bug-Fixes
2 parents 01ebb84 + 63eeefa commit 3fe2de0

File tree

15 files changed

+432
-25
lines changed

15 files changed

+432
-25
lines changed

ISSUE_TEMPLATE.md

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,24 @@
1-
Steps to reproduce
2-
--
3-
1. Install Magento from `develop` branch.
4-
2. [Example] Add Configurable Product to the cart.
5-
3. ...
1+
<!--- Provide a general summary of the issue in the Title above -->
2+
<!--- Before adding new issues, please, check this article https://github.com/magento/magento2/wiki/Issue-reporting-guidelines-->
63

7-
Expected result
8-
--
9-
1. [Example] Configurable product added to the shopping cart.
10-
2. ...
4+
### Preconditions
5+
<!--- Provide a more detailed information of environment you use -->
6+
<!--- Magento version, tag, HEAD, etc., PHP & MySQL version, etc.. -->
7+
1.
8+
2.
119

12-
Actual result
13-
--
14-
1. [Example] Error message appears: "Cannot save quote".
15-
2. [Screenshot, logs]
16-
3. ...
10+
### Steps to reproduce
11+
<!--- Provide a set of unambiguous steps to reproduce this bug include code, if relevant -->
12+
1.
13+
2.
14+
3.
15+
16+
### Expected result
17+
<!--- Tell us what should happen -->
18+
1.
19+
20+
### Actual result
21+
<!--- Tell us what happens instead -->
22+
1. [Screenshot, logs]
23+
24+
<!--- (This may be platform independent comment) -->

app/code/Magento/Catalog/Block/Adminhtml/Product/Helper/Form/Gallery/Content.php

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Magento\Backend\Block\Media\Uploader;
1717
use Magento\Framework\View\Element\AbstractBlock;
1818
use Magento\Framework\App\Filesystem\DirectoryList;
19+
use Magento\Framework\Exception\FileSystemException;
1920

2021
class Content extends \Magento\Backend\Block\Widget
2122
{
@@ -34,6 +35,16 @@ class Content extends \Magento\Backend\Block\Widget
3435
*/
3536
protected $_jsonEncoder;
3637

38+
/**
39+
* @var \Magento\Catalog\Helper\Image
40+
*/
41+
private $imageHelper;
42+
43+
/**
44+
* @var \Magento\Framework\View\Asset\Repository
45+
*/
46+
private $assetRepo;
47+
3748
/**
3849
* @param \Magento\Backend\Block\Template\Context $context
3950
* @param \Magento\Framework\Json\EncoderInterface $jsonEncoder
@@ -128,12 +139,22 @@ public function getImagesJson()
128139
is_array($value['images']) &&
129140
count($value['images'])
130141
) {
131-
$directory = $this->_filesystem->getDirectoryRead(DirectoryList::MEDIA);
142+
$mediaDir = $this->_filesystem->getDirectoryRead(DirectoryList::MEDIA);
132143
$images = $this->sortImagesByPosition($value['images']);
133144
foreach ($images as &$image) {
134145
$image['url'] = $this->_mediaConfig->getMediaUrl($image['file']);
135-
$fileHandler = $directory->stat($this->_mediaConfig->getMediaPath($image['file']));
136-
$image['size'] = $fileHandler['size'];
146+
try {
147+
$fileHandler = $mediaDir->stat($this->_mediaConfig->getMediaPath($image['file']));
148+
$image['size'] = $fileHandler['size'];
149+
} catch (FileSystemException $e) {
150+
$staticDir = $this->_filesystem->getDirectoryRead(DirectoryList::STATIC_VIEW);
151+
$image['url'] = $this->getImageHelper()->getDefaultPlaceholderUrl('thumbnail');
152+
$fileHandler = $staticDir->stat(
153+
$this->getAssetRepo()->createAsset($this->getImageHelper()->getPlaceholder('thumbnail'))->getPath()
154+
);
155+
$image['size'] = $fileHandler['size'];
156+
$this->_logger->warning($e);
157+
}
137158
}
138159
return $this->_jsonEncoder->encode($images);
139160
}
@@ -227,4 +248,31 @@ public function getImageTypesJson()
227248
{
228249
return $this->_jsonEncoder->encode($this->getImageTypes());
229250
}
251+
252+
/**
253+
* @return \Magento\Catalog\Helper\Image
254+
* @deprecated
255+
*/
256+
private function getImageHelper()
257+
{
258+
if ($this->imageHelper === null) {
259+
$this->imageHelper = \Magento\Framework\App\ObjectManager::getInstance()
260+
->get('Magento\Catalog\Helper\Image');
261+
}
262+
return $this->imageHelper;
263+
}
264+
265+
/**
266+
* @return \Magento\Framework\View\Asset\Repository
267+
* @deprecated
268+
*/
269+
private function getAssetRepo()
270+
{
271+
if ($this->assetRepo === null) {
272+
$this->assetRepo = \Magento\Framework\App\ObjectManager::getInstance()
273+
->get('\Magento\Framework\View\Asset\Repository');
274+
}
275+
276+
return $this->assetRepo;
277+
}
230278
}

app/code/Magento/Catalog/Block/Product/ListProduct.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,8 @@ public function getProductPrice(\Magento\Catalog\Model\Product $product)
363363
[
364364
'include_container' => true,
365365
'display_minimal_price' => true,
366-
'zone' => \Magento\Framework\Pricing\Render::ZONE_ITEM_LIST
366+
'zone' => \Magento\Framework\Pricing\Render::ZONE_ITEM_LIST,
367+
'list_category_page' => true
367368
]
368369
);
369370
}

app/code/Magento/Catalog/Model/ResourceModel/Product/Collection.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1858,6 +1858,9 @@ protected function _productLimitationPrice($joinLeft = false)
18581858
return $this;
18591859
}
18601860

1861+
// Preventing overriding price loaded from EAV because we want to use the one from index
1862+
$this->removeAttributeToSelect('price');
1863+
18611864
$connection = $this->getConnection();
18621865
$select = $this->getSelect();
18631866
$joinCond = join(

app/code/Magento/Catalog/Pricing/Render/FinalPriceBox.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,4 +118,26 @@ public function showMinimalPrice()
118118
&& $minimalPriceAValue
119119
&& $minimalPriceAValue < $finalPriceValue;
120120
}
121+
122+
/**
123+
* Get Key for caching block content
124+
*
125+
* @return string
126+
*/
127+
public function getCacheKey()
128+
{
129+
return parent::getCacheKey() . ($this->getData('list_category_page') ? '-list-category-page': '');
130+
}
131+
132+
/**
133+
* {@inheritdoc}
134+
*
135+
* @return array
136+
*/
137+
public function getCacheKeyInfo()
138+
{
139+
$cacheKeys = parent::getCacheKeyInfo();
140+
$cacheKeys['display_minimal_price'] = $this->getDisplayMinimalPrice();
141+
return $cacheKeys;
142+
}
121143
}

app/code/Magento/Catalog/Test/Unit/Block/Adminhtml/Product/Helper/Form/Gallery/ContentTest.php

Lines changed: 113 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
use Magento\Framework\Filesystem;
99
use Magento\Catalog\Block\Adminhtml\Product\Helper\Form\Gallery\Content;
10+
use Magento\Framework\Phrase;
1011

1112
class ContentTest extends \PHPUnit_Framework_TestCase
1213
{
@@ -40,14 +41,30 @@ class ContentTest extends \PHPUnit_Framework_TestCase
4041
*/
4142
protected $galleryMock;
4243

44+
/**
45+
* @var \Magento\Catalog\Helper\Image|\PHPUnit_Framework_MockObject_MockObject
46+
*/
47+
protected $imageHelper;
48+
49+
/**
50+
* @var \Magento\Framework\View\Asset\Repository|\PHPUnit_Framework_MockObject_MockObject
51+
*/
52+
protected $assetRepo;
53+
4354
/**
4455
* @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager
4556
*/
4657
protected $objectManager;
4758

4859
public function setUp()
4960
{
50-
$this->fileSystemMock = $this->getMock('Magento\Framework\Filesystem', [], [], '', false);
61+
$this->fileSystemMock = $this->getMock(
62+
'Magento\Framework\Filesystem',
63+
['stat', 'getDirectoryRead'],
64+
[],
65+
'',
66+
false
67+
);
5168
$this->readMock = $this->getMock('Magento\Framework\Filesystem\Directory\ReadInterface');
5269
$this->galleryMock = $this->getMock(
5370
'Magento\Catalog\Block\Adminhtml\Product\Helper\Form\Gallery',
@@ -56,7 +73,13 @@ public function setUp()
5673
'',
5774
false
5875
);
59-
$this->mediaConfigMock = $this->getMock('Magento\Catalog\Model\Product\Media\Config', [], [], '', false);
76+
$this->mediaConfigMock = $this->getMock(
77+
'Magento\Catalog\Model\Product\Media\Config',
78+
['getMediaUrl', 'getMediaPath'],
79+
[],
80+
'',
81+
false
82+
);
6083
$this->jsonEncoderMock = $this->getMockBuilder('Magento\Framework\Json\EncoderInterface')
6184
->disableOriginalConstructor()
6285
->getMock();
@@ -130,7 +153,6 @@ public function testGetImagesJson()
130153

131154
$this->mediaConfigMock->expects($this->any())->method('getMediaUrl')->willReturnMap($url);
132155
$this->mediaConfigMock->expects($this->any())->method('getMediaPath')->willReturnMap($mediaPath);
133-
134156
$this->readMock->expects($this->any())->method('stat')->willReturnMap($sizeMap);
135157
$this->jsonEncoderMock->expects($this->once())->method('encode')->willReturnCallback('json_encode');
136158

@@ -144,4 +166,92 @@ public function testGetImagesJsonWithoutImages()
144166

145167
$this->assertSame('[]', $this->content->getImagesJson());
146168
}
169+
170+
public function testGetImagesJsonWithException()
171+
{
172+
$this->imageHelper = $this->getMockBuilder('Magento\Catalog\Helper\Image')
173+
->disableOriginalConstructor()
174+
->setMethods(['getDefaultPlaceholderUrl', 'getPlaceholder'])
175+
->getMock();
176+
177+
$this->assetRepo = $this->getMockBuilder('Magento\Framework\View\Asset\Repository')
178+
->disableOriginalConstructor()
179+
->setMethods(['createAsset', 'getPath'])
180+
->getMock();
181+
182+
$this->objectManager->setBackwardCompatibleProperty(
183+
$this->content,
184+
'imageHelper',
185+
$this->imageHelper
186+
);
187+
188+
$this->objectManager->setBackwardCompatibleProperty(
189+
$this->content,
190+
'assetRepo',
191+
$this->assetRepo
192+
);
193+
194+
$placeholderUrl = 'url_to_the_placeholder/placeholder.jpg';
195+
196+
$sizePlaceholder = ['size' => 399659];
197+
198+
$imagesResult = [
199+
[
200+
'value_id' => '2',
201+
'file' => 'file_2.jpg',
202+
'media_type' => 'image',
203+
'position' => '0',
204+
'url' => 'url_to_the_placeholder/placeholder.jpg',
205+
'size' => 399659
206+
],
207+
[
208+
'value_id' => '1',
209+
'file' => 'file_1.jpg',
210+
'media_type' => 'image',
211+
'position' => '1',
212+
'url' => 'url_to_the_placeholder/placeholder.jpg',
213+
'size' => 399659
214+
]
215+
];
216+
217+
$images = [
218+
'images' => [
219+
[
220+
'value_id' => '1',
221+
'file' => 'file_1.jpg',
222+
'media_type' => 'image',
223+
'position' => '1'
224+
],
225+
[
226+
'value_id' => '2',
227+
'file' => 'file_2.jpg',
228+
'media_type' => 'image',
229+
'position' => '0'
230+
]
231+
]
232+
];
233+
234+
$this->content->setElement($this->galleryMock);
235+
$this->galleryMock->expects($this->once())->method('getImages')->willReturn($images);
236+
$this->fileSystemMock->expects($this->any())->method('getDirectoryRead')->willReturn($this->readMock);
237+
$this->mediaConfigMock->expects($this->any())->method('getMediaUrl');
238+
$this->mediaConfigMock->expects($this->any())->method('getMediaPath');
239+
$this->readMock->expects($this->any())->method('stat')->willReturnOnConsecutiveCalls(
240+
$this->throwException(
241+
new \Magento\Framework\Exception\FileSystemException(new \Magento\Framework\Phrase('test'))
242+
),
243+
$sizePlaceholder,
244+
$this->throwException(
245+
new \Magento\Framework\Exception\FileSystemException(new \Magento\Framework\Phrase('test'))
246+
),
247+
$sizePlaceholder
248+
);
249+
$this->imageHelper->expects($this->any())->method('getDefaultPlaceholderUrl')->willReturn($placeholderUrl);
250+
$this->imageHelper->expects($this->any())->method('getPlaceholder');
251+
$this->assetRepo->expects($this->any())->method('createAsset')->willReturnSelf();
252+
$this->assetRepo->expects($this->any())->method('getPath');
253+
$this->jsonEncoderMock->expects($this->once())->method('encode')->willReturnCallback('json_encode');
254+
255+
$this->assertSame(json_encode($imagesResult), $this->content->getImagesJson());
256+
}
147257
}

0 commit comments

Comments
 (0)