Skip to content

Commit d40a26c

Browse files
author
Shubham Sharma
committed
Merge remote-tracking branch 'upstream/2.2-develop' into 2.2-develop
2 parents 87167e7 + 1e4a9cb commit d40a26c

File tree

30 files changed

+763
-182
lines changed

30 files changed

+763
-182
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/Braintree/Model/Paypal/Helper/QuoteUpdater.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ private function updateBillingAddress(Quote $quote, array $details)
148148
{
149149
$billingAddress = $quote->getBillingAddress();
150150

151-
if ($this->config->isRequiredBillingAddress()) {
151+
if ($this->config->isRequiredBillingAddress() && !empty($details['billingAddress'])) {
152152
$this->updateAddressData($billingAddress, $details['billingAddress']);
153153
} else {
154154
$this->updateAddressData($billingAddress, $details['shippingAddress']);

0 commit comments

Comments
 (0)