-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #352 from magento-nord/develop
Bugs: MAGETWO-56534 Price in cart does not update correctly when price is changed in admin. - for Mainline MAGETWO-57135 Product import with images not working MAGETWO-56054 [GitHub] Admin >New order: 'Recently Viewed Products' has 0 price value #5810
- Loading branch information
Showing
8 changed files
with
215 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
app/code/Magento/Quote/Model/Product/Plugin/UpdateQuoteItems.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
/** | ||
* Copyright © 2016 Magento. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Quote\Model\Product\Plugin; | ||
|
||
class UpdateQuoteItems | ||
{ | ||
/** | ||
* @var \Magento\Quote\Model\ResourceModel\Quote | ||
*/ | ||
private $resource; | ||
|
||
/** | ||
* @param \Magento\Quote\Model\ResourceModel\Quote $resource | ||
*/ | ||
public function __construct( | ||
\Magento\Quote\Model\ResourceModel\Quote $resource | ||
) { | ||
$this->resource = $resource; | ||
} | ||
|
||
/** | ||
* @param \Magento\Catalog\Model\ResourceModel\Product $subject | ||
* @param \Magento\Catalog\Model\ResourceModel\Product $result | ||
* @param \Magento\Framework\Model\AbstractModel $product | ||
* @return \Magento\Catalog\Model\ResourceModel\Product | ||
* @SuppressWarnings(PHPMD.UnusedFormalParameter) | ||
*/ | ||
public function afterSave( | ||
\Magento\Catalog\Model\ResourceModel\Product $subject, | ||
\Magento\Catalog\Model\ResourceModel\Product $result, | ||
\Magento\Framework\Model\AbstractModel $product | ||
) { | ||
$originalPrice = $product->getOrigData('price'); | ||
if (!empty($originalPrice) && ($originalPrice != $product->getPrice())) { | ||
$this->resource->markQuotesRecollect($product->getId()); | ||
} | ||
return $result; | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
app/code/Magento/Quote/Test/Unit/Model/Product/Plugin/UpdateQuoteItemsTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
/** | ||
* Copyright © 2016 Magento. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Quote\Test\Unit\Model\Product\Plugin; | ||
|
||
class UpdateQuoteItemsTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @var \Magento\Quote\Model\Product\Plugin\UpdateQuoteItems | ||
*/ | ||
private $model; | ||
|
||
/** | ||
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Quote\Model\ResourceModel\Quote | ||
*/ | ||
private $quoteResource ; | ||
|
||
protected function setUp() | ||
{ | ||
$this->quoteResource = $this->getMockBuilder(\Magento\Quote\Model\ResourceModel\Quote::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
$this->model = new \Magento\Quote\Model\Product\Plugin\UpdateQuoteItems($this->quoteResource); | ||
} | ||
|
||
/** | ||
* @dataProvider aroundUpdateDataProvider | ||
* @param int $originalPrice | ||
* @param int $newPrice | ||
* @param bool $callMethod | ||
*/ | ||
public function testAfterUpdate($originalPrice, $newPrice, $callMethod) | ||
{ | ||
$productResourceMock = $this->getMock(\Magento\Catalog\Model\ResourceModel\Product::class, [], [], '', false); | ||
$productMock = $this->getMockBuilder(\Magento\Framework\Model\AbstractModel::class) | ||
->disableOriginalConstructor() | ||
->setMethods(['getOrigData', 'getPrice', 'getId']) | ||
->getMockForAbstractClass(); | ||
$productId = 1; | ||
$productMock->expects($this->any())->method('getOrigData')->with('price')->willReturn($originalPrice); | ||
$productMock->expects($this->any())->method('getPrice')->willReturn($newPrice); | ||
$productMock->expects($this->any())->method('getId')->willReturn($productId); | ||
$this->quoteResource->expects($this->$callMethod())->method('markQuotesRecollect')->with($productId); | ||
$result = $this->model->afterSave($productResourceMock, $productResourceMock, $productMock); | ||
$this->assertEquals($result, $productResourceMock); | ||
} | ||
|
||
public function aroundUpdateDataProvider() | ||
{ | ||
return [ | ||
[10, 20, 'once'], | ||
[null, 10, 'never'], | ||
[10, 10, 'never'] | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
app/code/Magento/Sales/Test/Unit/Block/Adminhtml/Order/Create/AbstractCreateTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
/** | ||
* Copyright © 2016 Magento. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Sales\Test\Unit\Block\Adminhtml\Order\Create; | ||
|
||
use Magento\Catalog\Pricing\Price\FinalPrice; | ||
|
||
class AbstractCreateTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @var \Magento\Sales\Block\Adminhtml\Order\Create\AbstractCreate|\PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
protected $model; | ||
|
||
/** | ||
* @var \Magento\Catalog\Model\Product|\PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
protected $productMock; | ||
|
||
/** | ||
* @var \Magento\Framework\Pricing\PriceInfo\Base|\PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
protected $priceInfoMock; | ||
|
||
/** | ||
* @var \Magento\Downloadable\Pricing\Price\LinkPrice|\PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
protected $linkPriceMock; | ||
|
||
protected function setUp() | ||
{ | ||
$this->model = $this->getMockBuilder(\Magento\Sales\Block\Adminhtml\Order\Create\AbstractCreate::class) | ||
->setMethods(['convertPrice']) | ||
->disableOriginalConstructor() | ||
->getMockForAbstractClass(); | ||
$this->priceInfoMock = $this->getMockBuilder(\Magento\Framework\Pricing\PriceInfo\Base::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
$this->productMock = $this->getMockBuilder(\Magento\Catalog\Model\Product::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
$this->linkPriceMock = $this->getMockBuilder(\Magento\Downloadable\Pricing\Price\LinkPrice::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
$this->productMock->expects($this->any()) | ||
->method('getPriceInfo') | ||
->willReturn($this->priceInfoMock); | ||
} | ||
|
||
public function testGetItemPrice() | ||
{ | ||
$price = 5.6; | ||
$resultPrice = 9.3; | ||
|
||
$this->linkPriceMock->expects($this->once()) | ||
->method('getValue') | ||
->willReturn($price); | ||
$this->priceInfoMock->expects($this->once()) | ||
->method('getPrice') | ||
->with(FinalPrice::PRICE_CODE) | ||
->willReturn($this->linkPriceMock); | ||
$this->model->expects($this->once()) | ||
->method('convertPrice') | ||
->with($price) | ||
->willReturn($resultPrice); | ||
$this->assertEquals($resultPrice, $this->model->getItemPrice($this->productMock)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters