Skip to content

Commit fdcab41

Browse files
authored
Merge pull request #3348 from magento-tango/PR-2.2-1
Fixed issues: - MAGETWO-95721: Removing Special Price changes final_price, min_price, max_price to 0.00 - MAGETWO-94988: Image downsampling to 80% on the product page
2 parents a2130b2 + dea360c commit fdcab41

File tree

15 files changed

+236
-32
lines changed

15 files changed

+236
-32
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Backend\Block\DataProviders;
9+
10+
use Magento\Framework\View\Element\Block\ArgumentInterface;
11+
12+
/**
13+
* Provides additional data for image uploader
14+
*/
15+
class UploadConfig implements ArgumentInterface
16+
{
17+
/**
18+
* @var \Magento\Framework\App\Config\ScopeConfigInterface
19+
*/
20+
private $config;
21+
22+
/**
23+
* @param \Magento\Framework\App\Config\ScopeConfigInterface $config
24+
*/
25+
public function __construct(\Magento\Framework\App\Config\ScopeConfigInterface $config)
26+
{
27+
$this->config = $config;
28+
}
29+
30+
/**
31+
* Get image resize configuration
32+
*
33+
* @return int
34+
*/
35+
public function getIsResizeEnabled(): int
36+
{
37+
return (int)$this->config->getValue('system/upload_configuration/enable_resize');
38+
}
39+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Backend\Test\Unit\Block\DataProviders;
7+
8+
use Magento\Framework\App\Config\ScopeConfigInterface as ScopeConfig;
9+
use Magento\Backend\Block\DataProviders\UploadConfig;
10+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
11+
12+
class UploadConfigTest extends \PHPUnit\Framework\TestCase
13+
{
14+
/**
15+
* @var ScopeConfig|\PHPUnit_Framework_MockObject_MockObject
16+
*/
17+
private $config;
18+
19+
/**
20+
* @var ObjectManagerHelper
21+
*/
22+
private $objectManagerHelper;
23+
24+
/**
25+
* @var UploadConfig
26+
*/
27+
private $uploadConfig;
28+
29+
protected function setUp()
30+
{
31+
$this->config = $this->getMockBuilder(ScopeConfig::class)
32+
->setMethods(['getValue'])
33+
->getMockForAbstractClass();
34+
$this->objectManagerHelper = new ObjectManagerHelper($this);
35+
$this->uploadConfig = $this->objectManagerHelper->getObject(
36+
UploadConfig::class,
37+
[
38+
'config' => $this->config
39+
]
40+
);
41+
}
42+
43+
/**
44+
* @dataProvider configValuesDataProvider()
45+
* @param int $configValue
46+
* @param int $expectedValue
47+
* @return void
48+
*/
49+
public function testGetIsResizeEnabled(int $configValue, int $expectedValue)
50+
{
51+
$this->config->expects($this->once())
52+
->method('getValue')
53+
->with('system/upload_configuration/enable_resize')
54+
->willReturn($configValue);
55+
$this->assertEquals($expectedValue, $this->uploadConfig->getIsResizeEnabled());
56+
}
57+
58+
public function configValuesDataProvider(): array
59+
{
60+
return [
61+
[1, 1],
62+
[0, 0]
63+
];
64+
}
65+
}

app/code/Magento/Backend/etc/adminhtml/system.xml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,15 +322,26 @@
322322
</group>
323323
<group id="upload_configuration" translate="label" type="text" sortOrder="1000" showInDefault="1" showInWebsite="1" showInStore="1">
324324
<label>Images Upload Configuration</label>
325-
<field id="max_width" translate="label comment" type="text" sortOrder="100" showInDefault="1" showInWebsite="0" showInStore="0" canRestore="1">
325+
<field id="enable_resize" translate="label" type="select" sortOrder="200" showInDefault="1" showInWebsite="0" showInStore="0" canRestore="1">
326+
<label>Enable Frontend Resize</label>
327+
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
328+
<comment>Resize performed via javascript before file upload.</comment>
329+
</field>
330+
<field id="max_width" translate="label comment" type="text" sortOrder="300" showInDefault="1" showInWebsite="0" showInStore="0" canRestore="1">
326331
<label>Maximum Width</label>
327332
<validate>validate-greater-than-zero validate-number required-entry</validate>
328333
<comment>Maximum allowed width for uploaded image.</comment>
334+
<depends>
335+
<field id="enable_resize">1</field>
336+
</depends>
329337
</field>
330-
<field id="max_height" translate="label comment" type="text" sortOrder="200" showInDefault="1" showInWebsite="0" showInStore="0" canRestore="1">
338+
<field id="max_height" translate="label comment" type="text" sortOrder="400" showInDefault="1" showInWebsite="0" showInStore="0" canRestore="1">
331339
<label>Maximum Height</label>
332340
<validate>validate-greater-than-zero validate-number required-entry</validate>
333341
<comment>Maximum allowed height for uploaded image.</comment>
342+
<depends>
343+
<field id="enable_resize">1</field>
344+
</depends>
334345
</field>
335346
</group>
336347
</section>

app/code/Magento/Backend/etc/config.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
<enable_charts>1</enable_charts>
3030
</dashboard>
3131
<upload_configuration>
32+
<enable_resize>1</enable_resize>
3233
<max_width>1920</max_width>
3334
<max_height>1200</max_height>
3435
</upload_configuration>

app/code/Magento/Backend/view/adminhtml/templates/media/uploader.phtml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
"Magento_Backend/js/media-uploader" : {
1515
"maxFileSize": <?= /* @escapeNotVerified */ $block->getFileSizeService()->getMaxFileSize() ?>,
1616
"maxWidth":<?= /* @escapeNotVerified */ $block->getImageUploadMaxWidth() ?> ,
17-
"maxHeight": <?= /* @escapeNotVerified */ $block->getImageUploadMaxHeight() ?>
17+
"maxHeight": <?= /* @escapeNotVerified */ $block->getImageUploadMaxHeight() ?>,
18+
"isResizeEnabled": <?= /* @noEscape */ $block->getImageUploadConfigData()->getIsResizeEnabled() ?>
1819
}
1920
}'
2021
>

app/code/Magento/Backend/view/adminhtml/web/js/media-uploader.js

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,20 @@ define([
2525
* @private
2626
*/
2727
_create: function () {
28-
var
29-
self = this,
30-
progressTmpl = mageTemplate('[data-template="uploader"]');
28+
var self = this,
29+
progressTmpl = mageTemplate('[data-template="uploader"]'),
30+
isResizeEnabled = this.options.isResizeEnabled,
31+
resizeConfiguration = {
32+
action: 'resize',
33+
maxWidth: this.options.maxWidth,
34+
maxHeight: this.options.maxHeight
35+
};
36+
37+
if (!isResizeEnabled) {
38+
resizeConfiguration = {
39+
action: 'resize'
40+
};
41+
}
3142

3243
this.element.find('input[type=file]').fileupload({
3344
dataType: 'json',
@@ -44,8 +55,7 @@ define([
4455
* @param {Object} data
4556
*/
4657
add: function (e, data) {
47-
var
48-
fileSize,
58+
var fileSize,
4959
tmpl;
5060

5161
$.each(data.files, function (index, file) {
@@ -115,11 +125,9 @@ define([
115125
process: [{
116126
action: 'load',
117127
fileTypes: /^image\/(gif|jpeg|png)$/
118-
}, {
119-
action: 'resize',
120-
maxWidth: this.options.maxWidth,
121-
maxHeight: this.options.maxHeight
122-
}, {
128+
},
129+
resizeConfiguration,
130+
{
123131
action: 'save'
124132
}]
125133
});

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,16 @@
1717
use Magento\Framework\View\Element\AbstractBlock;
1818
use Magento\Framework\App\Filesystem\DirectoryList;
1919
use Magento\Framework\Exception\FileSystemException;
20+
use Magento\Framework\App\ObjectManager;
21+
use Magento\Backend\Block\DataProviders\UploadConfig as ImageUploadConfigDataProvider;
2022

2123
class Content extends \Magento\Backend\Block\Widget
2224
{
25+
/**
26+
* @var ImageUploadConfigDataProvider
27+
*/
28+
private $imageUploadConfigDataProvider;
29+
2330
/**
2431
* @var string
2532
*/
@@ -45,24 +52,32 @@ class Content extends \Magento\Backend\Block\Widget
4552
* @param \Magento\Framework\Json\EncoderInterface $jsonEncoder
4653
* @param \Magento\Catalog\Model\Product\Media\Config $mediaConfig
4754
* @param array $data
55+
* @param ImageUploadConfigDataProvider $imageUploadConfigDataProvider
4856
*/
4957
public function __construct(
5058
\Magento\Backend\Block\Template\Context $context,
5159
\Magento\Framework\Json\EncoderInterface $jsonEncoder,
5260
\Magento\Catalog\Model\Product\Media\Config $mediaConfig,
53-
array $data = []
61+
array $data = [],
62+
ImageUploadConfigDataProvider $imageUploadConfigDataProvider = null
5463
) {
5564
$this->_jsonEncoder = $jsonEncoder;
5665
$this->_mediaConfig = $mediaConfig;
5766
parent::__construct($context, $data);
67+
$this->imageUploadConfigDataProvider = $imageUploadConfigDataProvider
68+
?: ObjectManager::getInstance()->get(ImageUploadConfigDataProvider::class);
5869
}
5970

6071
/**
6172
* @return AbstractBlock
6273
*/
6374
protected function _prepareLayout()
6475
{
65-
$this->addChild('uploader', \Magento\Backend\Block\Media\Uploader::class);
76+
$this->addChild(
77+
'uploader',
78+
\Magento\Backend\Block\Media\Uploader::class,
79+
['image_upload_config_data' => $this->imageUploadConfigDataProvider]
80+
);
6681

6782
$this->getUploader()->getConfig()->setUrl(
6883
$this->_urlBuilder->addSessionParam()->getUrl('catalog/product_gallery/upload')

app/code/Magento/Catalog/Model/Product/Image.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class Image extends \Magento\Framework\Model\AbstractModel
3636
*
3737
* @var int
3838
*/
39-
protected $_quality = 80;
39+
protected $_quality = null;
4040

4141
/**
4242
* @var bool
@@ -294,7 +294,8 @@ public function setQuality($quality)
294294
*/
295295
public function getQuality()
296296
{
297-
return $this->_quality;
297+
return $this->_quality === null
298+
? $this->_scopeConfig->getValue('system/upload_configuration/jpeg_quality') : $this->_quality;
298299
}
299300

300301
/**
@@ -471,7 +472,7 @@ public function getImageProcessor()
471472
$this->_processor->keepTransparency($this->_keepTransparency);
472473
$this->_processor->constrainOnly($this->_constrainOnly);
473474
$this->_processor->backgroundColor($this->_backgroundColor);
474-
$this->_processor->quality($this->_quality);
475+
$this->_processor->quality($this->getQuality());
475476
return $this->_processor;
476477
}
477478

@@ -854,7 +855,7 @@ private function getMiscParams()
854855
'constrain_only' => ($this->_constrainOnly ? 'do' : 'not') . 'constrainonly',
855856
'background' => $this->_rgbToString($this->_backgroundColor),
856857
'angle' => $this->_angle,
857-
'quality' => $this->_quality,
858+
'quality' => $this->getQuality(),
858859
];
859860

860861
// if has watermark add watermark params to hash

app/code/Magento/Catalog/Model/ResourceModel/Product/Indexer/Price/Query/BaseFinalPrice.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ public function getQuery(array $dimensions, string $productType, array $entityId
190190
$specialFromExpr = "{$specialFrom} IS NULL OR {$specialFromDate} <= {$currentDate}";
191191
$specialToExpr = "{$specialTo} IS NULL OR {$specialToDate} >= {$currentDate}";
192192
$specialPriceExpr = $connection->getCheckSql(
193-
"{$specialPrice} IS NOT NULL AND {$specialFromExpr} AND {$specialToExpr}",
193+
"{$specialPrice} IS NOT NULL AND ({$specialFromExpr}) AND ({$specialToExpr})",
194194
$specialPrice,
195195
$maxUnsignedBigint
196196
);

app/code/Magento/Catalog/Test/Unit/Model/Product/ImageTest.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Magento\Catalog\Model\View\Asset\PlaceholderFactory;
1010
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
1111
use Magento\Framework\App\Filesystem\DirectoryList;
12+
use Magento\Framework\App\Config\ScopeConfigInterface as ScopeConfig;
1213

1314
/**
1415
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -81,6 +82,11 @@ class ImageTest extends \PHPUnit\Framework\TestCase
8182
*/
8283
private $cacheManager;
8384

85+
/**
86+
* @var ScopeConfig|\PHPUnit_Framework_MockObject_MockObject
87+
*/
88+
private $scopeConfig;
89+
8490
protected function setUp()
8591
{
8692
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
@@ -89,7 +95,6 @@ protected function setUp()
8995
->disableOriginalConstructor()
9096
->getMockForAbstractClass();
9197
$this->context->expects($this->any())->method('getCacheManager')->will($this->returnValue($this->cacheManager));
92-
9398
$this->storeManager = $this->getMockBuilder(\Magento\Store\Model\StoreManager::class)
9499
->disableOriginalConstructor()
95100
->setMethods(['getStore', 'getWebsite'])->getMock();
@@ -98,24 +103,20 @@ protected function setUp()
98103
$store->expects($this->any())->method('getId')->will($this->returnValue(1));
99104
$store->expects($this->any())->method('getBaseUrl')->will($this->returnValue('http://magento.com/media/'));
100105
$this->storeManager->expects($this->any())->method('getStore')->will($this->returnValue($store));
101-
102106
$this->config = $this->getMockBuilder(\Magento\Catalog\Model\Product\Media\Config::class)
103107
->setMethods(['getBaseMediaPath'])->disableOriginalConstructor()->getMock();
104108
$this->config->expects($this->any())->method('getBaseMediaPath')->will($this->returnValue('catalog/product'));
105109
$this->coreFileHelper = $this->getMockBuilder(\Magento\MediaStorage\Helper\File\Storage\Database::class)
106110
->setMethods(['saveFile', 'deleteFolder'])->disableOriginalConstructor()->getMock();
107-
108111
$this->mediaDirectory = $this->getMockBuilder(\Magento\Framework\Filesystem\Directory\Write::class)
109112
->disableOriginalConstructor()
110113
->setMethods(['create', 'isFile', 'isExist', 'getAbsolutePath'])
111114
->getMock();
112-
113115
$this->filesystem = $this->createMock(\Magento\Framework\Filesystem::class);
114116
$this->filesystem->expects($this->once())->method('getDirectoryWrite')
115117
->with(DirectoryList::MEDIA)
116118
->will($this->returnValue($this->mediaDirectory));
117119
$this->factory = $this->createMock(\Magento\Framework\Image\Factory::class);
118-
119120
$this->viewAssetImageFactory = $this->getMockBuilder(ImageFactory::class)
120121
->disableOriginalConstructor()
121122
->setMethods(['create'])
@@ -141,6 +142,10 @@ function ($value) {
141142
return json_decode($value, true);
142143
}
143144
);
145+
$this->scopeConfig = $this->getMockBuilder(ScopeConfig::class)
146+
->setMethods(['getValue'])->getMockForAbstractClass();
147+
$this->scopeConfig->expects($this->any())->method('getValue')
148+
->with('system/upload_configuration/jpeg_quality')->willReturn(80);
144149

145150
$this->image = $objectManager->getObject(
146151
\Magento\Catalog\Model\Product\Image::class,
@@ -153,7 +158,8 @@ function ($value) {
153158
'imageFactory' => $this->factory,
154159
'viewAssetImageFactory' => $this->viewAssetImageFactory,
155160
'viewAssetPlaceholderFactory' => $this->viewAssetPlaceholderFactory,
156-
'serializer' => $this->serializer
161+
'serializer' => $this->serializer,
162+
'scopeConfig' => $this->scopeConfig
157163
]
158164
);
159165

app/code/Magento/Catalog/etc/adminhtml/system.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,5 +185,19 @@
185185
</field>
186186
</group>
187187
</section>
188+
<section id="system" translate="label" type="text" sortOrder="900" showInDefault="1" showInWebsite="1" showInStore="1">
189+
<class>separator-top</class>
190+
<label>System</label>
191+
<tab>advanced</tab>
192+
<resource>Magento_Config::config_system</resource>
193+
<group id="upload_configuration" translate="label" type="text" sortOrder="1000" showInDefault="1" showInWebsite="1" showInStore="1">
194+
<label>Images Upload Configuration</label>
195+
<field id="jpeg_quality" translate="label comment" type="text" sortOrder="100" showInDefault="1" showInWebsite="0" showInStore="0" canRestore="1">
196+
<label>Quality</label>
197+
<validate>validate-digits validate-digits-range digits-range-1-100 required-entry</validate>
198+
<comment>Jpeg quality for resized images 1-100%.</comment>
199+
</field>
200+
</group>
201+
</section>
188202
</system>
189203
</config>

0 commit comments

Comments
 (0)