Skip to content

Commit c3cd4eb

Browse files
committed
MAGETWO-52974: Configurable product options not saved when editing
2 parents 3e07006 + c614b9c commit c3cd4eb

File tree

43 files changed

+395
-163
lines changed

Some content is hidden

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

43 files changed

+395
-163
lines changed

app/code/Magento/Catalog/view/base/web/js/price-box.js

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* Copyright © 2016 Magento. All rights reserved.
33
* See COPYING.txt for license details.
44
*/
5+
56
define([
67
'jquery',
78
'Magento_Catalog/js/price-utils',
@@ -29,6 +30,7 @@ define([
2930
*/
3031
_init: function initPriceBox() {
3132
var box = this.element;
33+
3234
box.trigger('updatePrice');
3335
this.cache.displayPrices = utils.deepClone(this.options.prices);
3436
},
@@ -70,7 +72,8 @@ define([
7072
updatePrice: function updatePrice(newPrices) {
7173
var prices = this.cache.displayPrices,
7274
additionalPrice = {},
73-
pricesCode = [];
75+
pricesCode = [],
76+
priceValue, origin, finalPrice;
7477

7578
this.cache.additionalPriceObject = this.cache.additionalPriceObject || {};
7679

@@ -89,19 +92,19 @@ define([
8992
pricesCode = _.keys(additional);
9093
}
9194
_.each(pricesCode, function (priceCode) {
92-
var priceValue = additional[priceCode] || {};
95+
priceValue = additional[priceCode] || {};
9396
priceValue.amount = +priceValue.amount || 0;
9497
priceValue.adjustments = priceValue.adjustments || {};
9598

9699
additionalPrice[priceCode] = additionalPrice[priceCode] || {
97-
'amount': 0,
98-
'adjustments': {}
99-
};
100-
additionalPrice[priceCode].amount = 0 + (additionalPrice[priceCode].amount || 0)
101-
+ priceValue.amount;
100+
'amount': 0,
101+
'adjustments': {}
102+
};
103+
additionalPrice[priceCode].amount = 0 + (additionalPrice[priceCode].amount || 0) +
104+
priceValue.amount;
102105
_.each(priceValue.adjustments, function (adValue, adCode) {
103-
additionalPrice[priceCode].adjustments[adCode] = 0
104-
+ (additionalPrice[priceCode].adjustments[adCode] || 0) + adValue;
106+
additionalPrice[priceCode].adjustments[adCode] = 0 +
107+
(additionalPrice[priceCode].adjustments[adCode] || 0) + adValue;
105108
});
106109
});
107110
});
@@ -110,23 +113,24 @@ define([
110113
this.cache.displayPrices = utils.deepClone(this.options.prices);
111114
} else {
112115
_.each(additionalPrice, function (option, priceCode) {
113-
var origin = this.options.prices[priceCode] || {},
114-
final = prices[priceCode] || {};
116+
origin = this.options.prices[priceCode] || {};
117+
finalPrice = prices[priceCode] || {};
115118
option.amount = option.amount || 0;
116119
origin.amount = origin.amount || 0;
117120
origin.adjustments = origin.adjustments || {};
118-
final.adjustments = final.adjustments || {};
121+
finalPrice.adjustments = finalPrice.adjustments || {};
119122

120-
final.amount = 0 + origin.amount + option.amount;
123+
finalPrice.amount = 0 + origin.amount + option.amount;
121124
_.each(option.adjustments, function (pa, paCode) {
122-
final.adjustments[paCode] = 0 + (origin.adjustments[paCode] || 0) + pa;
125+
finalPrice.adjustments[paCode] = 0 + (origin.adjustments[paCode] || 0) + pa;
123126
});
124127
}, this);
125128
}
126129

127130
this.element.trigger('reloadPrice');
128131
},
129132

133+
/*eslint-disable no-extra-parens*/
130134
/**
131135
* Render price unit block.
132136
*/
@@ -135,16 +139,19 @@ define([
135139
priceTemplate = mageTemplate(this.options.priceTemplate);
136140

137141
_.each(this.cache.displayPrices, function (price, priceCode) {
138-
price.final = _.reduce(price.adjustments, function(memo, amount) {
142+
price.final = _.reduce(price.adjustments, function (memo, amount) {
139143
return memo + amount;
140144
}, price.amount);
141145

142146
price.formatted = utils.formatPrice(price.final, priceFormat);
143147

144-
$('[data-price-type="' + priceCode + '"]', this.element).html(priceTemplate({data: price}));
148+
$('[data-price-type="' + priceCode + '"]', this.element).html(priceTemplate({
149+
data: price
150+
}));
145151
}, this);
146152
},
147153

154+
/*eslint-enable no-extra-parens*/
148155
/**
149156
* Overwrites initial (default) prices object.
150157
* @param {Object} prices
@@ -177,6 +184,7 @@ define([
177184
var box = this.element,
178185
priceHolders = $('[data-price-type]', box),
179186
prices = this.options.prices;
187+
180188
this.options.productId = box.data('productId');
181189

182190
if (_.isEmpty(prices)) {
@@ -199,10 +207,7 @@ define([
199207
_setDefaultsFromPriceConfig: function _setDefaultsFromPriceConfig() {
200208
var config = this.options.priceConfig;
201209

202-
if (config) {
203-
if (+config.productId !== +this.options.productId) {
204-
return;
205-
}
210+
if (config && config.prices) {
206211
this.options.prices = config.prices;
207212
}
208213
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,8 @@ public function move($fileName, $renameFileOff = false)
155155

156156
$filePath = $this->_directory->getRelativePath($this->getTmpDir() . '/' . $fileName);
157157
$this->_setUploadFile($filePath);
158-
$result = $this->save($this->getDestDir());
158+
$destDir = $this->_directory->getAbsolutePath($this->getDestDir());
159+
$result = $this->save($destDir);
159160
$result['name'] = self::getCorrectFileName($result['name']);
160161
return $result;
161162
}
@@ -305,11 +306,10 @@ protected function _moveFile($tmpPath, $destPath)
305306
$tmpRealPath = $this->_directory->getDriver()->getRealPath(
306307
$this->_directory->getAbsolutePath($tmpPath)
307308
);
308-
$destinationRealPath = $this->_directory->getDriver()->getRealPath(
309-
$this->_directory->getAbsolutePath($destPath)
310-
);
309+
$destinationRealPath = $this->_directory->getDriver()->getRealPath($destPath);
310+
$relativeDestPath = $this->_directory->getRelativePath($destPath);
311311
$isSameFile = $tmpRealPath === $destinationRealPath;
312-
return $isSameFile ?: $this->_directory->copyFile($tmpPath, $destPath);
312+
return $isSameFile ?: $this->_directory->copyFile($tmpPath, $relativeDestPath);
313313
} else {
314314
return false;
315315
}

app/code/Magento/CatalogImportExport/Test/Unit/Model/Import/UploaderTest.php

Lines changed: 24 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,11 @@ protected function setUp()
6868

6969
$this->readFactory = $this->getMockBuilder(\Magento\Framework\Filesystem\File\ReadFactory::class)
7070
->disableOriginalConstructor()
71+
->setMethods(['create'])
7172
->getMock();
7273

7374
$this->directoryMock = $this->getMockBuilder(\Magento\Framework\Filesystem\Directory\Writer::class)
74-
->setMethods(['writeFile', 'getRelativePath'])
75+
->setMethods(['writeFile', 'getRelativePath', 'isWritable', 'getAbsolutePath'])
7576
->disableOriginalConstructor()
7677
->getMock();
7778

@@ -92,6 +93,7 @@ protected function setUp()
9293
$this->filesystem,
9394
$this->readFactory,
9495
])
96+
->setMethods(['_setUploadFile', 'save', 'getTmpDir'])
9597
->getMock();
9698
}
9799

@@ -100,10 +102,14 @@ protected function setUp()
100102
*/
101103
public function testMoveFileUrl($fileUrl, $expectedHost, $expectedFileName)
102104
{
105+
$destDir = 'var/dest/dir';
103106
$expectedRelativeFilePath = $this->uploader->getTmpDir() . '/' . $expectedFileName;
107+
$this->directoryMock->expects($this->once())->method('isWritable')->with($destDir)->willReturn(true);
104108
$this->directoryMock->expects($this->any())->method('getRelativePath')->with($expectedRelativeFilePath);
109+
$this->directoryMock->expects($this->once())->method('getAbsolutePath')->with($destDir)
110+
->willReturn($destDir . '/' . $expectedFileName);
105111
// Check writeFile() method invoking.
106-
$this->directoryMock->expects($this->any())->method('writeFile')->will($this->returnValue(null));
112+
$this->directoryMock->expects($this->any())->method('writeFile')->will($this->returnValue($expectedFileName));
107113

108114
// Create adjusted reader which does not validate path.
109115
$readMock = $this->getMockBuilder(\Magento\Framework\Filesystem\File\Read::class)
@@ -113,59 +119,37 @@ public function testMoveFileUrl($fileUrl, $expectedHost, $expectedFileName)
113119
// Check readAll() method invoking.
114120
$readMock->expects($this->once())->method('readAll')->will($this->returnValue(null));
115121

116-
$this->readFactory = $this->getMockBuilder(\Magento\Framework\Filesystem\File\ReadFactory::class)
117-
->disableOriginalConstructor()
118-
->setMethods(['create'])
119-
->getMock();
120122
// Check create() method invoking with expected argument.
121123
$this->readFactory->expects($this->once())
122124
->method('create')
123125
->will($this->returnValue($readMock))->with($expectedHost);
124-
125-
$uploaderMock = $this->getMockBuilder(\Magento\CatalogImportExport\Model\Import\Uploader::class)
126-
->setConstructorArgs([
127-
$this->coreFileStorageDb,
128-
$this->coreFileStorage,
129-
$this->imageFactory,
130-
$this->validator,
131-
$this->filesystem,
132-
$this->readFactory,
133-
])
134-
->setMethods(['_setUploadFile', 'save', 'getTmpDir'])
135-
->getMock();
136-
137126
//Check invoking of getTmpDir(), _setUploadFile(), save() methods.
138-
$uploaderMock->expects($this->any())->method('getTmpDir')->will($this->returnValue(''));
139-
$uploaderMock->expects($this->once())->method('_setUploadFile')->will($this->returnSelf());
140-
$uploaderMock->expects($this->once())->method('save')->will($this->returnValue(['name' => null]));
127+
$this->uploader->expects($this->any())->method('getTmpDir')->will($this->returnValue(''));
128+
$this->uploader->expects($this->once())->method('_setUploadFile')->will($this->returnSelf());
129+
$this->uploader->expects($this->once())->method('save')->with($destDir . '/' . $expectedFileName)
130+
->willReturn(['name' => $expectedFileName]);
141131

142-
$uploaderMock->move($fileUrl);
132+
$this->uploader->setDestDir($destDir);
133+
$this->assertEquals(['name' => $expectedFileName], $this->uploader->move($fileUrl));
143134
}
144135

145136
public function testMoveFileName()
146137
{
138+
$destDir = 'var/dest/dir';
147139
$fileName = 'test_uploader_file';
148140
$expectedRelativeFilePath = $this->uploader->getTmpDir() . '/' . $fileName;
141+
$this->directoryMock->expects($this->once())->method('isWritable')->with($destDir)->willReturn(true);
149142
$this->directoryMock->expects($this->any())->method('getRelativePath')->with($expectedRelativeFilePath);
150-
151-
$uploaderMock = $this->getMockBuilder(\Magento\CatalogImportExport\Model\Import\Uploader::class)
152-
->setConstructorArgs([
153-
$this->coreFileStorageDb,
154-
$this->coreFileStorage,
155-
$this->imageFactory,
156-
$this->validator,
157-
$this->filesystem,
158-
$this->readFactory,
159-
])
160-
->setMethods(['_setUploadFile', 'save', 'getTmpDir'])
161-
->getMock();
162-
143+
$this->directoryMock->expects($this->once())->method('getAbsolutePath')->with($destDir)
144+
->willReturn($destDir . '/' . $fileName);
163145
//Check invoking of getTmpDir(), _setUploadFile(), save() methods.
164-
$uploaderMock->expects($this->once())->method('getTmpDir')->will($this->returnValue(''));
165-
$uploaderMock->expects($this->once())->method('_setUploadFile')->will($this->returnSelf());
166-
$uploaderMock->expects($this->once())->method('save')->will($this->returnValue(['name' => null]));
146+
$this->uploader->expects($this->once())->method('getTmpDir')->will($this->returnValue(''));
147+
$this->uploader->expects($this->once())->method('_setUploadFile')->will($this->returnSelf());
148+
$this->uploader->expects($this->once())->method('save')->with($destDir . '/' . $fileName)
149+
->willReturn(['name' => $fileName]);
167150

168-
$uploaderMock->move($fileName);
151+
$this->uploader->setDestDir($destDir);
152+
$this->assertEquals(['name' => $fileName], $this->uploader->move($fileName));
169153
}
170154

171155
public function moveFileUrlDataProvider()

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,7 @@ define([
9797
addToCartCalls++;
9898
self.isLoading(true);
9999
});
100-
101-
if (cartData().websiteId !== window.checkout.websiteId) {
100+
if (cartData().website_id !== window.checkout.websiteId) {
102101
customerData.reload(['cart'], false);
103102
}
104103

app/code/Magento/Payment/Model/Method/Cc.php

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -127,28 +127,25 @@ public function validate()
127127
//Solo, Switch or Maestro. International safe
128128
'SO' => '/(^(6334)[5-9](\d{11}$|\d{13,14}$))|(^(6767)(\d{12}$|\d{14,15}$))/',
129129
'SM' => '/(^(5[0678])\d{11,18}$)|(^(6[^05])\d{11,18}$)|(^(601)[^1]\d{9,16}$)|(^(6011)\d{9,11}$)' .
130-
'|(^(6011)\d{13,16}$)|(^(65)\d{11,13}$)|(^(65)\d{15,18}$)' .
131-
'|(^(49030)[2-9](\d{10}$|\d{12,13}$))|(^(49033)[5-9](\d{10}$|\d{12,13}$))' .
132-
'|(^(49110)[1-2](\d{10}$|\d{12,13}$))|(^(49117)[4-9](\d{10}$|\d{12,13}$))' .
133-
'|(^(49118)[0-2](\d{10}$|\d{12,13}$))|(^(4936)(\d{12}$|\d{14,15}$))/',
130+
'|(^(6011)\d{13,16}$)|(^(65)\d{11,13}$)|(^(65)\d{15,18}$)' .
131+
'|(^(49030)[2-9](\d{10}$|\d{12,13}$))|(^(49033)[5-9](\d{10}$|\d{12,13}$))' .
132+
'|(^(49110)[1-2](\d{10}$|\d{12,13}$))|(^(49117)[4-9](\d{10}$|\d{12,13}$))' .
133+
'|(^(49118)[0-2](\d{10}$|\d{12,13}$))|(^(4936)(\d{12}$|\d{14,15}$))/',
134134
// Visa
135135
'VI' => '/^4[0-9]{12}([0-9]{3})?$/',
136136
// Master Card
137-
'MC' => '/^5[1-5][0-9]{14}$/',
137+
'MC' => '/^(?:5[1-5][0-9]{2}|222[1-9]|22[3-9][0-9]|2[3-6][0-9]{2}|27[01][0-9]|2720)[0-9]{12}$/',
138138
// American Express
139139
'AE' => '/^3[47][0-9]{13}$/',
140140
// Discover
141-
'DI' => '/^(30[0-5][0-9]{13}|3095[0-9]{12}|35(2[8-9][0-9]{12}|[3-8][0-9]{13})' .
142-
'|36[0-9]{12}|3[8-9][0-9]{14}|6011(0[0-9]{11}|[2-4][0-9]{11}|74[0-9]{10}|7[7-9][0-9]{10}' .
143-
'|8[6-9][0-9]{10}|9[0-9]{11})|62(2(12[6-9][0-9]{10}|1[3-9][0-9]{11}|[2-8][0-9]{12}' .
144-
'|9[0-1][0-9]{11}|92[0-5][0-9]{10})|[4-6][0-9]{13}|8[2-8][0-9]{12})|6(4[4-9][0-9]{13}' .
145-
'|5[0-9]{14}))$/',
141+
'DI' => '/^(6011((0|9|[2-4])[0-9]{11,14}|(74|7[7-9]|8[6-9])[0-9]{10,13})|6(4[4-9][0-9]{13,16}|' .
142+
'5[0-9]{14,17}))/',
143+
'DN' => '/^3(0[0-5][0-9]{13,16}|095[0-9]{12,15}|(6|[8-9])[0-9]{14,17})/',
144+
// UnionPay
145+
'UN' => '/^622(1(2[6-9][0-9]{10,13}|[3-9][0-9]{11,14})|[3-8][0-9]{12,15}|9([[0-1][0-9]{11,14}|' .
146+
'2[0-5][0-9]{10,13}))|62[4-6][0-9]{13,16}|628[2-8][0-9]{12,15}/',
146147
// JCB
147-
'JCB' => '/^(30[0-5][0-9]{13}|3095[0-9]{12}|35(2[8-9][0-9]{12}|[3-8][0-9]{13})|36[0-9]{12}' .
148-
'|3[8-9][0-9]{14}|6011(0[0-9]{11}|[2-4][0-9]{11}|74[0-9]{10}|7[7-9][0-9]{10}' .
149-
'|8[6-9][0-9]{10}|9[0-9]{11})|62(2(12[6-9][0-9]{10}|1[3-9][0-9]{11}|[2-8][0-9]{12}' .
150-
'|9[0-1][0-9]{11}|92[0-5][0-9]{10})|[4-6][0-9]{13}|8[2-8][0-9]{12})|6(4[4-9][0-9]{13}' .
151-
'|5[0-9]{14}))$/',
148+
'JCB' => '/^35(2[8-9][0-9]{12,15}|[3-8][0-9]{13,16})/',
152149
'MI' => '/^(5(0|[6-9])|63|67(?!59|6770|6774))\d*$/',
153150
'MD' => '/^(6759(?!24|38|40|6[3-9]|70|76)|676770|676774)\d*$/',
154151
];
@@ -215,6 +212,8 @@ public function getVerificationRegEx()
215212
'MC' => '/^[0-9]{3}$/',
216213
'AE' => '/^[0-9]{4}$/',
217214
'DI' => '/^[0-9]{3}$/',
215+
'DN' => '/^[0-9]{3}$/',
216+
'UN' => '/^[0-9]{3}$/',
218217
'SS' => '/^[0-9]{3,4}$/',
219218
'SM' => '/^[0-9]{3,4}$/',
220219
'SO' => '/^[0-9]{3,4}$/',

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@
2828
<group id="other_paypal_payment_solutions" translate="label" sortOrder="3" showInDefault="1" showInWebsite="1" showInStore="1">
2929
<label>Other PayPal Payment Solutions:</label>
3030
<fieldset_css>paypal-top-section paypal-other-header</fieldset_css>
31-
<frontend_model>Magento\Paypal\Block\Adminhtml\System\Config\Fieldset\Expanded</frontend_model>
31+
<frontend_model>\Magento\Config\Block\System\Config\Form\Fieldset</frontend_model>
3232
</group>
3333
<group id="other_payment_methods" translate="label" sortOrder="4" showInDefault="1" showInWebsite="1" showInStore="1">
3434
<label>Other Payment Methods:</label>
3535
<fieldset_css>paypal-top-section payments-other-header</fieldset_css>
36-
<frontend_model>Magento\Paypal\Block\Adminhtml\System\Config\Fieldset\Expanded</frontend_model>
36+
<frontend_model>\Magento\Config\Block\System\Config\Form\Fieldset</frontend_model>
3737
</group>
3838
</section>
3939
<section id="payment_all_paypal" showInDefault="0" showInWebsite="0" showInStore="0">

0 commit comments

Comments
 (0)