Skip to content

Commit 2bd4d5a

Browse files
Merge pull request #1471 from magento-okapis/BundledPR-Sep7b
[okapis] MAGETWO-71666: Unable to save product after failed attempt
2 parents 9832b9d + 51e2157 commit 2bd4d5a

File tree

36 files changed

+933
-357
lines changed

36 files changed

+933
-357
lines changed

app/code/Magento/Catalog/Model/Product/Attribute/Backend/GroupPrice/AbstractGroupPrice.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ public function afterSave($object)
479479
}
480480

481481
if (!empty($update)) {
482-
$isChanged = $this->updateValues($update, $old);
482+
$isChanged |= $this->updateValues($update, $old);
483483
}
484484

485485
if ($isChanged) {

app/code/Magento/Catalog/Model/Product/Attribute/Backend/Tierprice.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ protected function updateValues(array $valuesToUpdate, array $oldValues)
180180
{
181181
$isChanged = false;
182182
foreach ($valuesToUpdate as $key => $value) {
183-
if ($oldValues[$key]['price'] != $value['value']
183+
if ((!empty($value['value']) && $oldValues[$key]['price'] != $value['value'])
184184
|| $this->getPercentage($oldValues[$key]) != $this->getPercentage($value)
185185
) {
186186
$price = new \Magento\Framework\DataObject(

app/code/Magento/Checkout/CustomerData/Cart.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,12 @@ public function __construct(
8787
public function getSectionData()
8888
{
8989
$totals = $this->getQuote()->getTotals();
90+
$subtotalAmount = $totals['subtotal']->getValue();
9091
return [
9192
'summary_count' => $this->getSummaryCount(),
93+
'subtotalAmount' => $subtotalAmount,
9294
'subtotal' => isset($totals['subtotal'])
93-
? $this->checkoutHelper->formatPrice($totals['subtotal']->getValue())
95+
? $this->checkoutHelper->formatPrice($subtotalAmount)
9496
: 0,
9597
'possible_onepage_checkout' => $this->isPossibleOnepageCheckout(),
9698
'items' => $this->getRecentItems(),

app/code/Magento/Checkout/Test/Unit/CustomerData/CartTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,8 @@ public function testGetSectionData()
160160
],
161161
'extra_actions' => '<span>Buttons</span>',
162162
'isGuestCheckoutAllowed' => 1,
163-
'website_id' => $websiteId
163+
'website_id' => $websiteId,
164+
'subtotalAmount' => 200,
164165
];
165166
$this->assertEquals($expectedResult, $this->model->getSectionData());
166167
}
@@ -262,7 +263,8 @@ public function testGetSectionDataWithCompositeProduct()
262263
],
263264
'extra_actions' => '<span>Buttons</span>',
264265
'isGuestCheckoutAllowed' => 1,
265-
'website_id' => $websiteId
266+
'website_id' => $websiteId,
267+
'subtotalAmount' => 200,
266268
];
267269
$this->assertEquals($expectedResult, $this->model->getSectionData());
268270
}

app/code/Magento/Checkout/view/frontend/web/js/model/cart/cache.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,19 @@ define([
188188
_isAddressChanged: function (address) {
189189
return JSON.stringify(_.pick(this.get('address'), this.requiredFields)) !==
190190
JSON.stringify(_.pick(address, this.requiredFields));
191+
},
192+
193+
/**
194+
* Compare cached subtotal with provided.
195+
* Custom method for check object equality.
196+
*
197+
* @param {float} subtotal
198+
* @returns {Boolean}
199+
*/
200+
_isSubtotalChanged: function (subtotal) {
201+
var cached = parseFloat(this.get('totals').subtotal);
202+
203+
return subtotal !== cached;
191204
}
192205
};
193206
});

app/code/Magento/Checkout/view/frontend/web/js/model/cart/totals-processor/default.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ define([
9191
!cartCache.isChanged('shippingMethodCode', data.shippingMethodCode) &&
9292
!cartCache.isChanged('shippingCarrierCode', data.shippingCarrierCode) &&
9393
!cartCache.isChanged('address', address) &&
94-
cartCache.get('totals')
94+
cartCache.get('totals') &&
95+
!cartCache.isChanged('subtotal', parseFloat(quote.totals().subtotal))
9596
) {
9697
quote.setTotals(cartCache.get('totals'));
9798
} else {

app/code/Magento/Checkout/view/frontend/web/js/model/totals.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,24 @@
88
*/
99
define([
1010
'ko',
11-
'Magento_Checkout/js/model/quote'
12-
], function (ko, quote) {
11+
'Magento_Checkout/js/model/quote',
12+
'Magento_Customer/js/customer-data'
13+
], function (ko, quote, customerData) {
1314
'use strict';
1415

15-
var quoteItems = ko.observable(quote.totals().items);
16+
var quoteItems = ko.observable(quote.totals().items),
17+
cartData = customerData.get('cart'),
18+
quoteSubtotal = parseFloat(quote.totals().subtotal),
19+
subtotalAmount = parseFloat(cartData().subtotalAmount);
1620

1721
quote.totals.subscribe(function (newValue) {
1822
quoteItems(newValue.items);
1923
});
2024

25+
if (quoteSubtotal !== subtotalAmount) {
26+
customerData.reload(['cart'], false);
27+
}
28+
2129
return {
2230
totals: quote.totals,
2331
isLoading: ko.observable(false),
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Config\Test\Unit\Model\Config\Backend\Email;
7+
8+
use Magento\Config\Model\Config\Backend\Email\Address;
9+
use Magento\Framework\Exception\LocalizedException;
10+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
11+
12+
class AddressTest extends \PHPUnit\Framework\TestCase
13+
{
14+
/**
15+
* @var Address
16+
*/
17+
private $model;
18+
19+
protected function setUp()
20+
{
21+
$objectManager = new ObjectManager($this);
22+
$this->model = $objectManager->getObject(Address::class);
23+
}
24+
25+
/**
26+
* @dataProvider beforeSaveDataProvider
27+
* @param string|null $value
28+
* @param string|bool $expectedValue false if exception to be thrown
29+
* @return void
30+
*/
31+
public function testBeforeSave($value, $expectedValue)
32+
{
33+
$this->model->setValue($value);
34+
35+
if ($expectedValue === false) {
36+
$this->expectException(LocalizedException::class);
37+
}
38+
39+
$this->model->beforeSave();
40+
$this->assertEquals($expectedValue, $this->model->getValue());
41+
}
42+
43+
public function beforeSaveDataProvider()
44+
{
45+
return [
46+
['someone@magento.com', 'someone@magento.com'],
47+
['real+email@magento.com', 'real+email@magento.com'],
48+
['not.a.real.email', false],
49+
[null, false],
50+
['', false]
51+
];
52+
}
53+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Config\Test\Unit\Model\Config\Backend\Email;
7+
8+
use Magento\Config\Model\Config\Backend\Email\Sender;
9+
use Magento\Framework\Exception\LocalizedException;
10+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
11+
12+
class SenderTest extends \PHPUnit\Framework\TestCase
13+
{
14+
/**
15+
* @var Sender
16+
*/
17+
private $model;
18+
19+
protected function setUp()
20+
{
21+
$objectManager = new ObjectManager($this);
22+
$this->model = $objectManager->getObject(Sender::class);
23+
}
24+
25+
/**
26+
* @dataProvider beforeSaveDataProvider
27+
* @param string|null $value
28+
* @param string|bool $expectedValue false if exception to be thrown
29+
* @return void
30+
*/
31+
public function testBeforeSave($value, $expectedValue)
32+
{
33+
$this->model->setValue($value);
34+
35+
if ($expectedValue === false) {
36+
$this->expectException(LocalizedException::class);
37+
}
38+
39+
$this->model->beforeSave();
40+
41+
$this->assertEquals($expectedValue, $this->model->getValue());
42+
}
43+
44+
public function beforeSaveDataProvider()
45+
{
46+
return [
47+
['Mr. Real Name', 'Mr. Real Name'],
48+
[str_repeat('a', 256), false],
49+
[null, false],
50+
['', false],
51+
];
52+
}
53+
}

app/code/Magento/ConfigurableProduct/Controller/Adminhtml/Product/Initialization/Helper/Plugin/Configurable.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -153,17 +153,17 @@ private function setLinkedProducts(ProductInterface $product, ProductExtensionIn
153153
protected function getVariationMatrix()
154154
{
155155
$result = [];
156-
$configurableMatrix = $this->request->getParam('configurable-matrix-serialized', '[]');
157-
if ($configurableMatrix != null && !empty($configurableMatrix)) {
156+
$configurableMatrix = $this->request->getParam('configurable-matrix-serialized', "[]");
157+
if (isset($configurableMatrix) && $configurableMatrix != "") {
158158
$configurableMatrix = json_decode($configurableMatrix, true);
159-
}
160159

161-
foreach ($configurableMatrix as $item) {
162-
if ($item['newProduct']) {
163-
$result[$item['variationKey']] = $this->mapData($item);
160+
foreach ($configurableMatrix as $item) {
161+
if ($item['newProduct']) {
162+
$result[$item['variationKey']] = $this->mapData($item);
164163

165-
if (isset($item['qty'])) {
166-
$result[$item['variationKey']]['quantity_and_stock_status']['qty'] = $item['qty'];
164+
if (isset($item['qty'])) {
165+
$result[$item['variationKey']]['quantity_and_stock_status']['qty'] = $item['qty'];
166+
}
167167
}
168168
}
169169
}

0 commit comments

Comments
 (0)