Skip to content

[Forwardport] fixed Quote Item Prices are NULL in cart related events. #18685 #23839

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/code/Magento/Quote/Model/Quote/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Quote\Model\Quote;

use Magento\Framework\Api\AttributeValueFactory;
Expand Down
3 changes: 2 additions & 1 deletion app/code/Magento/Quote/Model/Quote/Item/Processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ public function __construct(
/**
* Initialize quote item object
*
* @param DataObject $request
* @param Product $product
* @param DataObject $request
*
* @return Item
*/
Expand Down Expand Up @@ -97,6 +97,7 @@ public function prepare(Item $item, DataObject $request, Product $candidate): vo
$item->addQty($candidate->getCartQty());

$customPrice = $request->getCustomPrice();
$item->setPrice($candidate->getFinalPrice());
if (!empty($customPrice)) {
$item->setCustomPrice($customPrice);
$item->setOriginalCustomPrice($customPrice);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Quote\Test\Unit\Model\Quote\Item;

use Magento\Catalog\Model\Product;
Expand Down Expand Up @@ -68,16 +70,20 @@ protected function setUp()
['create']
);

$this->itemMock = $this->createPartialMock(\Magento\Quote\Model\Quote\Item::class, [
$this->itemMock = $this->createPartialMock(
\Magento\Quote\Model\Quote\Item::class,
[
'getId',
'setOptions',
'__wakeup',
'setProduct',
'addQty',
'setCustomPrice',
'setOriginalCustomPrice',
'setData'
]);
'setData',
'setprice'
]
);
$this->quoteItemFactoryMock->expects($this->any())
->method('create')
->will($this->returnValue($this->itemMock));
Expand All @@ -98,7 +104,13 @@ protected function setUp()

$this->productMock = $this->createPartialMock(
\Magento\Catalog\Model\Product::class,
['getCustomOptions', '__wakeup', 'getParentProductId', 'getCartQty', 'getStickWithinParent']
[
'getCustomOptions',
'__wakeup',
'getParentProductId',
'getCartQty',
'getStickWithinParent',
'getFinalPrice']
);
$this->objectMock = $this->createPartialMock(
\Magento\Framework\DataObject::class,
Expand Down Expand Up @@ -239,13 +251,17 @@ public function testPrepare()
$customPrice = 400000000;
$itemId = 1;
$requestItemId = 1;
$finalPrice = 1000000000;

$this->productMock->expects($this->any())
->method('getCartQty')
->will($this->returnValue($qty));
$this->productMock->expects($this->any())
->method('getStickWithinParent')
->will($this->returnValue(false));
$this->productMock->expects($this->once())
->method('getFinalPrice')
->will($this->returnValue($finalPrice));

$this->itemMock->expects($this->once())
->method('addQty')
Expand All @@ -255,6 +271,9 @@ public function testPrepare()
->will($this->returnValue($itemId));
$this->itemMock->expects($this->never())
->method('setData');
$this->itemMock->expects($this->once())
->method('setPrice')
->will($this->returnValue($this->itemMock));

$this->objectMock->expects($this->any())
->method('getCustomPrice')
Expand Down Expand Up @@ -282,13 +301,17 @@ public function testPrepareWithResetCountAndStick()
$customPrice = 400000000;
$itemId = 1;
$requestItemId = 1;
$finalPrice = 1000000000;

$this->productMock->expects($this->any())
->method('getCartQty')
->will($this->returnValue($qty));
$this->productMock->expects($this->any())
->method('getStickWithinParent')
->will($this->returnValue(true));
$this->productMock->expects($this->once())
->method('getFinalPrice')
->will($this->returnValue($finalPrice));

$this->itemMock->expects($this->once())
->method('addQty')
Expand All @@ -298,6 +321,9 @@ public function testPrepareWithResetCountAndStick()
->will($this->returnValue($itemId));
$this->itemMock->expects($this->never())
->method('setData');
$this->itemMock->expects($this->once())
->method('setPrice')
->will($this->returnValue($this->itemMock));

$this->objectMock->expects($this->any())
->method('getCustomPrice')
Expand Down Expand Up @@ -325,13 +351,17 @@ public function testPrepareWithResetCountAndNotStickAndOtherItemId()
$customPrice = 400000000;
$itemId = 1;
$requestItemId = 2;
$finalPrice = 1000000000;

$this->productMock->expects($this->any())
->method('getCartQty')
->will($this->returnValue($qty));
$this->productMock->expects($this->any())
->method('getStickWithinParent')
->will($this->returnValue(false));
$this->productMock->expects($this->once())
->method('getFinalPrice')
->will($this->returnValue($finalPrice));

$this->itemMock->expects($this->once())
->method('addQty')
Expand All @@ -341,6 +371,9 @@ public function testPrepareWithResetCountAndNotStickAndOtherItemId()
->will($this->returnValue($itemId));
$this->itemMock->expects($this->never())
->method('setData');
$this->itemMock->expects($this->once())
->method('setPrice')
->will($this->returnValue($this->itemMock));

$this->objectMock->expects($this->any())
->method('getCustomPrice')
Expand Down Expand Up @@ -368,6 +401,7 @@ public function testPrepareWithResetCountAndNotStickAndSameItemId()
$customPrice = 400000000;
$itemId = 1;
$requestItemId = 1;
$finalPrice = 1000000000;

$this->objectMock->expects($this->any())
->method('getResetCount')
Expand All @@ -386,10 +420,16 @@ public function testPrepareWithResetCountAndNotStickAndSameItemId()
$this->productMock->expects($this->any())
->method('getStickWithinParent')
->will($this->returnValue(false));
$this->productMock->expects($this->once())
->method('getFinalPrice')
->will($this->returnValue($finalPrice));

$this->itemMock->expects($this->once())
->method('addQty')
->with($qty);
$this->itemMock->expects($this->once())
->method('setPrice')
->will($this->returnValue($this->itemMock));

$this->objectMock->expects($this->any())
->method('getCustomPrice')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Catalog\Api;

use Magento\TestFramework\TestCase\WebapiAbstract;
use Magento\Catalog\Api\Data\ProductCustomOptionInterface;
use Magento\ConfigurableProduct\Model\Product\Type\Configurable;

/**
* Class \Magento\Catalog\Api\CartItemRepositoryTest
*/
class CartItemRepositoryTest extends WebapiAbstract
{
const SERVICE_NAME = 'quoteCartItemRepositoryV1';
Expand Down Expand Up @@ -62,7 +67,7 @@ public function testAddProductToCartWithCustomOptions()
'sku' => $item->getSku(),
'qty' => $item->getQty(),
'name' => $item->getName(),

'price' => $item->getPrice(),
'product_type' => $item->getProductType(),
'quote_id' => $item->getQuoteId(),
'product_option' => [
Expand Down