Skip to content

Commit 7b5bd77

Browse files
author
Ji Lu
committed
Merge remote-tracking branch 'upstream/develop' into MAGETWO-52332-FT-pagecache
2 parents 3e2dd3c + c790670 commit 7b5bd77

File tree

50 files changed

+1958
-1344
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+1958
-1344
lines changed

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

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -122,21 +122,40 @@ public function getAddImagesButton()
122122
*/
123123
public function getImagesJson()
124124
{
125-
if (is_array($this->getElement()->getImages())) {
126-
$value = $this->getElement()->getImages();
125+
$value = $this->getElement()->getImages();
126+
if (is_array($value) &&
127+
array_key_exists('images', $value) &&
128+
is_array($value['images']) &&
129+
count($value['images'])
130+
) {
127131
$directory = $this->_filesystem->getDirectoryRead(DirectoryList::MEDIA);
128-
if (is_array($value['images']) && count($value['images']) > 0) {
129-
foreach ($value['images'] as &$image) {
130-
$image['url'] = $this->_mediaConfig->getMediaUrl($image['file']);
131-
$fileHandler = $directory->stat($this->_mediaConfig->getMediaPath($image['file']));
132-
$image['size'] = $fileHandler['size'];
133-
}
134-
return $this->_jsonEncoder->encode($value['images']);
132+
$images = $this->sortImagesByPosition($value['images']);
133+
foreach ($images as &$image) {
134+
$image['url'] = $this->_mediaConfig->getMediaUrl($image['file']);
135+
$fileHandler = $directory->stat($this->_mediaConfig->getMediaPath($image['file']));
136+
$image['size'] = $fileHandler['size'];
135137
}
138+
return $this->_jsonEncoder->encode($images);
136139
}
137140
return '[]';
138141
}
139142

143+
/**
144+
* Sort images array by position key
145+
*
146+
* @param array $images
147+
* @return array
148+
*/
149+
private function sortImagesByPosition($images)
150+
{
151+
if (is_array($images)) {
152+
usort($images, function ($imageA, $imageB) {
153+
return ($imageA['position'] < $imageB['position']) ? -1 : 1;
154+
});
155+
}
156+
return $images;
157+
}
158+
140159
/**
141160
* @return string
142161
*/

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

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -82,37 +82,59 @@ public function testGetImagesJson()
8282
['file_1.jpg', 'catalog/product/image_1.jpg'],
8383
['file_2.jpg', 'catalog/product/image_2.jpg']
8484
];
85-
// @codingStandardsIgnoreStart
86-
$encodedString = '[{"value_id":"1","file":"image_1.jpg","media_type":"image","url":"http:\/\/magento2.dev\/pub\/media\/catalog\/product\/image_1.jpg","size":879394},{"value_id":"2","file":"image_2.jpg","media_type":"image","url":"http:\/\/magento2.dev\/pub\/media\/catalog\/product\/image`_2.jpg","size":399659}]';
87-
// @codingStandardsIgnoreEnd
85+
86+
$sizeMap = [
87+
['catalog/product/image_1.jpg', ['size' => 399659]],
88+
['catalog/product/image_2.jpg', ['size' => 879394]]
89+
];
90+
91+
$imagesResult = [
92+
[
93+
'value_id' => '2',
94+
'file' => 'file_2.jpg',
95+
'media_type' => 'image',
96+
'position' => '0',
97+
'url' => 'url_to_the_image/image_2.jpg',
98+
'size' => 879394
99+
],
100+
[
101+
'value_id' => '1',
102+
'file' => 'file_1.jpg',
103+
'media_type' => 'image',
104+
'position' => '1',
105+
'url' => 'url_to_the_image/image_1.jpg',
106+
'size' => 399659
107+
]
108+
];
109+
88110
$images = [
89111
'images' => [
90112
[
91113
'value_id' => '1',
92114
'file' => 'file_1.jpg',
93115
'media_type' => 'image',
116+
'position' => '1'
94117
] ,
95118
[
96119
'value_id' => '2',
97120
'file' => 'file_2.jpg',
98121
'media_type' => 'image',
122+
'position' => '0'
99123
]
100124
]
101125
];
102-
$firstStat = ['size' => 879394];
103-
$secondStat = ['size' => 399659];
126+
104127
$this->content->setElement($this->galleryMock);
105-
$this->galleryMock->expects($this->any())->method('getImages')->willReturn($images);
128+
$this->galleryMock->expects($this->once())->method('getImages')->willReturn($images);
106129
$this->fileSystemMock->expects($this->once())->method('getDirectoryRead')->willReturn($this->readMock);
107130

108131
$this->mediaConfigMock->expects($this->any())->method('getMediaUrl')->willReturnMap($url);
109-
$this->mediaConfigMock->expects($this->any())->method('getMediaPath')->willReturn($mediaPath);
132+
$this->mediaConfigMock->expects($this->any())->method('getMediaPath')->willReturnMap($mediaPath);
110133

111-
$this->readMock->expects($this->at(0))->method('stat')->willReturn($firstStat);
112-
$this->readMock->expects($this->at(1))->method('stat')->willReturn($secondStat);
113-
$this->jsonEncoderMock->expects($this->once())->method('encode')->willReturn($encodedString);
134+
$this->readMock->expects($this->any())->method('stat')->willReturnMap($sizeMap);
135+
$this->jsonEncoderMock->expects($this->once())->method('encode')->willReturnCallback('json_encode');
114136

115-
$this->assertSame($encodedString, $this->content->getImagesJson());
137+
$this->assertSame(json_encode($imagesResult), $this->content->getImagesJson());
116138
}
117139

118140
public function testGetImagesJsonWithoutImages()

app/code/Magento/CatalogImportExport/Model/Import/Product.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1270,7 +1270,7 @@ protected function _saveProductCategories(array $categoriesData)
12701270
);
12711271
}
12721272
if ($categoriesIn) {
1273-
$this->_connection->insertOnDuplicate($tableName, $categoriesIn, ['position']);
1273+
$this->_connection->insertOnDuplicate($tableName, $categoriesIn, ['product_id', 'category_id']);
12741274
}
12751275
}
12761276
return $this;

app/code/Magento/Checkout/view/frontend/web/js/model/shipping-rates-validator.js

Lines changed: 50 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,19 @@ define(
1111
'../model/address-converter',
1212
'../action/select-shipping-address',
1313
'./postcode-validator',
14-
'mage/translate'
14+
'mage/translate',
15+
'uiRegistry'
1516
],
16-
function ($, ko, shippingRatesValidationRules, addressConverter, selectShippingAddress, postcodeValidator, $t) {
17+
function (
18+
$,
19+
ko,
20+
shippingRatesValidationRules,
21+
addressConverter,
22+
selectShippingAddress,
23+
postcodeValidator,
24+
$t,
25+
uiRegistry
26+
) {
1727
'use strict';
1828

1929
var checkoutConfig = window.checkoutConfig,
@@ -45,26 +55,52 @@ define(
4555
});
4656
},
4757

58+
/**
59+
* Perform postponed binding for fieldset elements
60+
*
61+
* @param {String} formPath
62+
*/
63+
initFields: function (formPath) {
64+
var self = this,
65+
elements = shippingRatesValidationRules.getObservableFields();
66+
67+
$.each(elements, function (index, field) {
68+
uiRegistry.async(formPath + '.' + field)(self.doElementBinding.bind(self));
69+
});
70+
},
71+
72+
/**
73+
* Bind shipping rates request to form element
74+
*
75+
* @param {Object} element
76+
* @param {Boolean} force
77+
* @param {Number} delay
78+
*/
79+
doElementBinding: function (element, force, delay) {
80+
var observableFields = shippingRatesValidationRules.getObservableFields();
81+
82+
if (element && (observableFields.indexOf(element.index) !== -1 || force)) {
83+
if (element.index !== 'postcode') {
84+
this.bindHandler(element, delay);
85+
}
86+
}
87+
88+
if (element.index === 'postcode') {
89+
this.bindHandler(element, delay);
90+
postcodeElement = element;
91+
}
92+
},
93+
4894
/**
4995
* @param {*} elements
5096
* @param {Boolean} force
5197
* @param {Number} delay
5298
*/
5399
bindChangeHandlers: function (elements, force, delay) {
54-
var self = this,
55-
observableFields = shippingRatesValidationRules.getObservableFields();
100+
var self = this;
56101

57102
$.each(elements, function (index, elem) {
58-
if (elem && (observableFields.indexOf(elem.index) !== -1 || force)) {
59-
if (elem.index !== 'postcode') {
60-
self.bindHandler(elem, delay);
61-
}
62-
}
63-
64-
if (elem.index === 'postcode') {
65-
self.bindHandler(elem, delay);
66-
postcodeElement = elem;
67-
}
103+
self.doElementBinding(elem, force, delay);
68104
});
69105
},
70106

app/code/Magento/Checkout/view/frontend/web/js/view/shipping.js

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,11 @@ define(
7575
*/
7676
initialize: function () {
7777
var self = this,
78-
hasNewAddress;
78+
hasNewAddress,
79+
fieldsetName = 'checkout.steps.shipping-step.shippingAddress.shipping-address-fieldset';
7980

8081
this._super();
82+
shippingRatesValidator.initFields(fieldsetName);
8183

8284
if (!quote.isVirtual()) {
8385
stepNavigator.registerStep(
@@ -130,15 +132,6 @@ define(
130132
//load data from server for shipping step
131133
},
132134

133-
/**
134-
* @param {Object} element
135-
*/
136-
initElement: function (element) {
137-
if (element.index === 'shipping-address-fieldset') {
138-
shippingRatesValidator.bindChangeHandlers(element.elems(), false);
139-
}
140-
},
141-
142135
/**
143136
* @return {*}
144137
*/

app/code/Magento/CheckoutAgreements/Model/Checkout/Plugin/Validation.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ class Validation
3232
* @param \Magento\Checkout\Api\AgreementsValidatorInterface $agreementsValidator
3333
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfiguration
3434
* @param \Magento\CheckoutAgreements\Api\CheckoutAgreementsRepositoryInterface $checkoutAgreementsRepository
35-
* @codeCoverageIgnore
3635
*/
3736
public function __construct(
3837
\Magento\Checkout\Api\AgreementsValidatorInterface $agreementsValidator,
@@ -48,15 +47,15 @@ public function __construct(
4847
* @param \Magento\Checkout\Api\PaymentInformationManagementInterface $subject
4948
* @param int $cartId
5049
* @param \Magento\Quote\Api\Data\PaymentInterface $paymentMethod
51-
* @param \Magento\Quote\Api\Data\AddressInterface $billingAddress
50+
* @param \Magento\Quote\Api\Data\AddressInterface|null $billingAddress
5251
* @return void
5352
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
5453
*/
5554
public function beforeSavePaymentInformationAndPlaceOrder(
5655
\Magento\Checkout\Api\PaymentInformationManagementInterface $subject,
5756
$cartId,
5857
\Magento\Quote\Api\Data\PaymentInterface $paymentMethod,
59-
\Magento\Quote\Api\Data\AddressInterface $billingAddress
58+
\Magento\Quote\Api\Data\AddressInterface $billingAddress = null
6059
) {
6160
if ($this->isAgreementEnabled()) {
6261
$this->validateAgreements($paymentMethod->getExtensionAttributes()->getAgreementIds());
@@ -67,15 +66,15 @@ public function beforeSavePaymentInformationAndPlaceOrder(
6766
* @param \Magento\Checkout\Api\PaymentInformationManagementInterface $subject
6867
* @param int $cartId
6968
* @param \Magento\Quote\Api\Data\PaymentInterface $paymentMethod
70-
* @param \Magento\Quote\Api\Data\AddressInterface $billingAddress
69+
* @param \Magento\Quote\Api\Data\AddressInterface|null $billingAddress
7170
* @return void
7271
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
7372
*/
7473
public function beforeSavePaymentInformation(
7574
\Magento\Checkout\Api\PaymentInformationManagementInterface $subject,
7675
$cartId,
7776
\Magento\Quote\Api\Data\PaymentInterface $paymentMethod,
78-
\Magento\Quote\Api\Data\AddressInterface $billingAddress
77+
\Magento\Quote\Api\Data\AddressInterface $billingAddress = null
7978
) {
8079
if ($this->isAgreementEnabled()) {
8180
$this->validateAgreements($paymentMethod->getExtensionAttributes()->getAgreementIds());

app/code/Magento/Newsletter/Block/Adminhtml/Queue/Edit.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,12 @@ protected function _prepareLayout()
161161
*/
162162
public function getPreviewUrl()
163163
{
164-
return $this->getUrl('*/*/preview');
164+
if ($this->getTemplateId()) {
165+
$params = ['template_id' => $this->getTemplateId()];
166+
} else {
167+
$params = ['id' => $this->getRequest()->getParam('id')];
168+
}
169+
return $this->getUrl('*/*/preview', $params);
165170
}
166171

167172
/**

app/code/Magento/Newsletter/Block/Adminhtml/Queue/Preview/Form.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ protected function _prepareForm()
3535
if ($data = $this->getFormData()) {
3636
$mapper = ['preview_store_id' => 'store_id'];
3737

38+
if (empty($data['id']) && !empty($data['text'])) {
39+
$this->_backendSession->setPreviewData($data);
40+
}
41+
3842
foreach ($data as $key => $value) {
3943
if (array_key_exists($key, $mapper)) {
4044
$name = $mapper[$key];

app/code/Magento/Newsletter/Block/Adminhtml/Template/Edit.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ public function getSaveUrl()
238238
*/
239239
public function getPreviewUrl()
240240
{
241-
return $this->getUrl('*/*/preview');
241+
return $this->getUrl('*/*/preview', ['id' => $this->getRequest()->getParam('id')]);
242242
}
243243

244244
/**

app/code/Magento/Newsletter/Block/Adminhtml/Template/Preview.php

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,11 @@ protected function _toHtml()
5858
if ($id = (int)$this->getRequest()->getParam('id')) {
5959
$this->loadTemplate($template, $id);
6060
} else {
61-
$template->setTemplateType($this->getRequest()->getParam('type'));
62-
$template->setTemplateText($this->getRequest()->getParam('text'));
63-
$template->setTemplateStyles($this->getRequest()->getParam('styles'));
61+
$previewData = $this->getPreviewData();
62+
63+
$template->setTemplateType($previewData['type']);
64+
$template->setTemplateText($previewData['text']);
65+
$template->setTemplateStyles($previewData['styles']);
6466
}
6567

6668
\Magento\Framework\Profiler::start($this->profilerName);
@@ -88,6 +90,32 @@ protected function _toHtml()
8890
return $templateProcessed;
8991
}
9092

93+
/**
94+
* Return template preview data
95+
*
96+
* @return array
97+
*/
98+
private function getPreviewData()
99+
{
100+
$previewData = [];
101+
$previewParams = ['type', 'text', 'styles'];
102+
103+
$sessionData = [];
104+
if ($this->_backendSession->hasPreviewData()) {
105+
$sessionData = $this->_backendSession->getPreviewData();
106+
}
107+
108+
foreach ($previewParams as $param) {
109+
if (isset($sessionData[$param])) {
110+
$previewData[$param] = $sessionData[$param];
111+
} else {
112+
$previewData[$param] = $this->getRequest()->getParam($param);
113+
}
114+
}
115+
116+
return $previewData;
117+
}
118+
91119
/**
92120
* Get Store Id from request or default
93121
*

0 commit comments

Comments
 (0)