Skip to content

Commit b189309

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-57862' into 2.0-develop-pr6
2 parents 82ba844 + d0f5baf commit b189309

File tree

4 files changed

+107
-0
lines changed

4 files changed

+107
-0
lines changed

app/code/Magento/Checkout/Model/TotalsInformationManagement.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ public function calculate(
5656
$addressInformation->getShippingCarrierCode() . '_' . $addressInformation->getShippingMethodCode()
5757
);
5858
}
59+
60+
if ($quote->getShippingAddress()->dataHasChangedFor('shipping_method')) {
61+
$quote->setTotalsCollectedFlag(false);
62+
}
5963
$quote->collectTotals();
6064

6165
return $this->cartTotalRepository->get($cartId);
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Quote\Model\Product\Plugin;
7+
8+
/**
9+
* BeforeSave plugin for product resource model to update quote items prices if product price is changed
10+
*/
11+
class UpdateQuoteItems
12+
{
13+
/**
14+
* @var \Magento\Quote\Model\ResourceModel\Quote
15+
*/
16+
private $resource;
17+
18+
/**
19+
* @param \Magento\Quote\Model\ResourceModel\Quote $resource
20+
*/
21+
public function __construct(
22+
\Magento\Quote\Model\ResourceModel\Quote $resource
23+
) {
24+
$this->resource = $resource;
25+
}
26+
27+
/**
28+
* @param \Magento\Catalog\Model\ResourceModel\Product $subject
29+
* @param \Magento\Framework\Model\AbstractModel $product
30+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
31+
*/
32+
public function beforeSave(
33+
\Magento\Catalog\Model\ResourceModel\Product $subject,
34+
\Magento\Framework\Model\AbstractModel $product
35+
) {
36+
$originalPrice = $product->getOrigData('price');
37+
if (!empty($originalPrice) && ($originalPrice != $product->getPrice())) {
38+
$this->resource->markQuotesRecollect($product->getId());
39+
}
40+
}
41+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Quote\Test\Unit\Model\Product\Plugin;
7+
8+
use Magento\Catalog\Model\Product;
9+
10+
class UpdateQuoteItemsTest extends \PHPUnit_Framework_TestCase
11+
{
12+
/**
13+
* @var \Magento\Quote\Model\Product\Plugin\UpdateQuoteItems
14+
*/
15+
private $model;
16+
17+
/**
18+
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Quote\Model\ResourceModel\Quote
19+
*/
20+
private $quoteResource ;
21+
22+
protected function setUp()
23+
{
24+
$this->quoteResource = $this->getMockBuilder(\Magento\Quote\Model\ResourceModel\Quote::class)
25+
->disableOriginalConstructor()
26+
->getMock();
27+
$this->model = new \Magento\Quote\Model\Product\Plugin\UpdateQuoteItems($this->quoteResource);
28+
}
29+
30+
/**
31+
* @dataProvider aroundUpdateDataProvider
32+
* @param int $originalPrice
33+
* @param int $newPrice
34+
* @param bool $callMethod
35+
*/
36+
public function testBeforeUpdate($originalPrice, $newPrice, $callMethod)
37+
{
38+
$productResourceMock = $this->getMock(\Magento\Catalog\Model\ResourceModel\Product::class, [], [], '', false);
39+
$productMock = $this->getMockBuilder(Product::class)
40+
->disableOriginalConstructor()
41+
->getMock();
42+
$productId = 1;
43+
$productMock->expects($this->any())->method('getOrigData')->with('price')->willReturn($originalPrice);
44+
$productMock->expects($this->any())->method('getPrice')->willReturn($newPrice);
45+
$productMock->expects($this->any())->method('getId')->willReturn($productId);
46+
$this->quoteResource->expects($this->$callMethod())->method('markQuotesRecollect')->with($productId);
47+
$result = $this->model->beforeSave($productResourceMock, $productMock);
48+
$this->assertEquals($result, NULL);
49+
}
50+
51+
public function aroundUpdateDataProvider()
52+
{
53+
return [
54+
[10, 20, 'once'],
55+
[null, 10, 'never'],
56+
[10, 10, 'never']
57+
];
58+
}
59+
}

app/code/Magento/Quote/etc/di.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,7 @@
8989
<preference for="Magento\Quote\Model\Quote\Address\FreeShippingInterface" type="Magento\Quote\Model\Quote\Address\FreeShipping" />
9090
<preference for="Magento\Quote\Model\GuestCart\GuestShippingMethodManagementInterface" type="Magento\Quote\Model\GuestCart\GuestShippingMethodManagement" />
9191
<preference for="Magento\Quote\Model\ShippingMethodManagementInterface" type="Magento\Quote\Model\ShippingMethodManagement" />
92+
<type name="Magento\Catalog\Model\ResourceModel\Product">
93+
<plugin name="update_quote_items_before_product_save" type="Magento\Quote\Model\Product\Plugin\UpdateQuoteItems"/>
94+
</type>
9295
</config>

0 commit comments

Comments
 (0)