Skip to content
This repository was archived by the owner on Apr 29, 2019. It is now read-only.

Commit 317d266

Browse files
Merge remote-tracking branch 'jackalopes/MAGETWO-70837-cart' into BundledPR-Sep7b
2 parents c8706fd + 30f44a6 commit 317d266

File tree

12 files changed

+103
-56
lines changed

12 files changed

+103
-56
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),

app/code/Magento/Quote/Model/Product/Plugin/UpdateQuoteItems.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ public function afterSave(
3434
\Magento\Framework\Model\AbstractModel $product
3535
) {
3636
$originalPrice = $product->getOrigData('price');
37-
if (!empty($originalPrice) && ($originalPrice != $product->getPrice())) {
37+
$tierPriceChanged = $product->getData('tier_price_changed');
38+
if ((!empty($originalPrice) && ($originalPrice != $product->getPrice())) || $tierPriceChanged) {
3839
$this->resource->markQuotesRecollect($product->getId());
3940
}
4041
return $result;

app/code/Magento/Quote/Model/Quote.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2374,8 +2374,9 @@ public function merge(Quote $quote)
23742374
protected function _afterLoad()
23752375
{
23762376
// collect totals and save me, if required
2377-
if (1 == $this->getData('trigger_recollect')) {
2377+
if (1 == $this->getTriggerRecollect()) {
23782378
$this->collectTotals()->save();
2379+
$this->setTriggerRecollect(0);
23792380
}
23802381
return parent::_afterLoad();
23812382
}

app/code/Magento/Quote/Test/Unit/Model/Product/Plugin/UpdateQuoteItemsTest.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,20 @@ protected function setUp()
3030
* @param int $originalPrice
3131
* @param int $newPrice
3232
* @param bool $callMethod
33+
* @param bool $tierPriceChanged
3334
*/
34-
public function testAfterUpdate($originalPrice, $newPrice, $callMethod)
35+
public function testAfterUpdate($originalPrice, $newPrice, $callMethod, $tierPriceChanged = false)
3536
{
3637
$productResourceMock = $this->createMock(\Magento\Catalog\Model\ResourceModel\Product::class);
3738
$productMock = $this->getMockBuilder(\Magento\Framework\Model\AbstractModel::class)
3839
->disableOriginalConstructor()
39-
->setMethods(['getOrigData', 'getPrice', 'getId'])
40+
->setMethods(['getOrigData', 'getPrice', 'getId', 'getData'])
4041
->getMockForAbstractClass();
4142
$productId = 1;
4243
$productMock->expects($this->any())->method('getOrigData')->with('price')->willReturn($originalPrice);
4344
$productMock->expects($this->any())->method('getPrice')->willReturn($newPrice);
4445
$productMock->expects($this->any())->method('getId')->willReturn($productId);
46+
$productMock->expects($this->any())->method('getData')->willReturn($tierPriceChanged);
4547
$this->quoteResource->expects($this->$callMethod())->method('markQuotesRecollect')->with($productId);
4648
$result = $this->model->afterSave($productResourceMock, $productResourceMock, $productMock);
4749
$this->assertEquals($result, $productResourceMock);
@@ -52,7 +54,8 @@ public function aroundUpdateDataProvider()
5254
return [
5355
[10, 20, 'once'],
5456
[null, 10, 'never'],
55-
[10, 10, 'never']
57+
[10, 10, 'never'],
58+
[10, 10, 'once', true],
5659
];
5760
}
5861
}

0 commit comments

Comments
 (0)