Skip to content

Commit

Permalink
ENGCOM-3271: fixed Quote Item Prices are NULL in cart related events. #…
Browse files Browse the repository at this point in the history
  • Loading branch information
VladimirZaets authored Nov 21, 2018
2 parents 0b9017c + 541bc69 commit 4afa4d1
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 6 deletions.
36 changes: 33 additions & 3 deletions app/code/Magento/ConfigurableProduct/Setup/UpgradeData.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@

use Magento\Catalog\Model\Product;
use Magento\ConfigurableProduct\Model\Product\Type\Configurable;
use Magento\Framework\Setup\UpgradeDataInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Eav\Setup\EavSetup;
use Magento\Eav\Setup\EavSetupFactory;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\Setup\UpgradeDataInterface;

/**
* Upgrade Data script
Expand Down Expand Up @@ -62,6 +62,10 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface
}
}

if (version_compare($context->getVersion(), '2.2.2', '<')) {
$this->upgradeQuoteItemPrice($setup);
}

$setup->endSetup();
}

Expand Down Expand Up @@ -97,4 +101,30 @@ private function updateRelatedProductTypes(string $attributeId, array $relatedPr
implode(',', $relatedProductTypes)
);
}

/**
* Update 'price' value for quote items without price of configurable products subproducts.
*
* @param ModuleDataSetupInterface $setup
*/
private function upgradeQuoteItemPrice(ModuleDataSetupInterface $setup)
{
$connection = $setup->getConnection();
$quoteItemTable = $setup->getTable('quote_item');
$select = $connection->select();
$select->joinLeft(
['qi2' => $quoteItemTable],
'qi1.parent_item_id = qi2.item_id',
['price']
)->where(
'qi1.price = 0'
. ' AND qi1.parent_item_id IS NOT NULL'
. ' AND qi2.product_type = "' . Configurable::TYPE_CODE . '"'
);
$updateQuoteItem = $setup->getConnection()->updateFromSelect(
$select,
['qi1' => $quoteItemTable]
);
$setup->getConnection()->query($updateQuoteItem);
}
}
2 changes: 1 addition & 1 deletion app/code/Magento/ConfigurableProduct/etc/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Magento_ConfigurableProduct" setup_version="2.2.1">
<module name="Magento_ConfigurableProduct" setup_version="2.2.2">
<sequence>
<module name="Magento_Catalog"/>
<module name="Magento_Msrp"/>
Expand Down
1 change: 1 addition & 0 deletions app/code/Magento/Quote/Model/Quote/Item/Processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ public function prepare(Item $item, DataObject $request, Product $candidate)
$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 @@ -76,7 +76,8 @@ protected function setUp()
'addQty',
'setCustomPrice',
'setOriginalCustomPrice',
'setData'
'setData',
'setprice'
]);
$this->quoteItemFactoryMock->expects($this->any())
->method('create')
Expand All @@ -98,7 +99,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 +246,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 +266,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 +296,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 +316,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 +346,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 +366,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 +396,7 @@ public function testPrepareWithResetCountAndNotStickAndSameItemId()
$customPrice = 400000000;
$itemId = 1;
$requestItemId = 1;
$finalPrice = 1000000000;

$this->objectMock->expects($this->any())
->method('getResetCount')
Expand All @@ -386,10 +415,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 @@ -70,6 +70,7 @@ public function testAddProductToCartWithCustomOptions()
'custom_options' => $this->getOptions(),
],
],
'price' => $item->getPrice(),
],
$response
);
Expand Down

0 comments on commit 4afa4d1

Please sign in to comment.