Skip to content

Commit 238cd3d

Browse files
committed
MAGETWO-66698: [Performance] Quotes Optimization
1 parent a9bd85b commit 238cd3d

File tree

6 files changed

+58
-22
lines changed

6 files changed

+58
-22
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,7 @@ public function getCurrency()
507507
->setStoreToQuoteRate($this->getStoreToQuoteRate())
508508
->setBaseToGlobalRate($this->getBaseToGlobalRate())
509509
->setBaseToQuoteRate($this->getBaseToQuoteRate());
510+
$this->setData(self::KEY_CURRENCY, $currency);
510511
}
511512
return $currency;
512513
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ class Item extends \Magento\Quote\Model\Quote\Item\AbstractItem implements \Mage
171171

172172
/**
173173
* @var \Magento\CatalogInventory\Api\StockRegistryInterface
174+
* @deprecated
174175
*/
175176
protected $stockRegistry;
176177

@@ -433,8 +434,8 @@ public function setProduct($product)
433434
->setTaxClassId($product->getTaxClassId())
434435
->setBaseCost($product->getCost());
435436

436-
$stockItem = $this->stockRegistry->getStockItem($product->getId(), $product->getStore()->getWebsiteId());
437-
$this->setIsQtyDecimal($stockItem->getIsQtyDecimal());
437+
$stockItem = $product->getExtensionAttributes()->getStockItem();
438+
$this->setIsQtyDecimal($stockItem ? $stockItem->getIsQtyDecimal() : false);
438439

439440
$this->_eventManager->dispatch(
440441
'sales_quote_item_set_product',

app/code/Magento/Quote/Model/ResourceModel/Quote/Item/Collection.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,9 @@ protected function _assignProducts()
213213
$this->_productIds
214214
)->addAttributeToSelect(
215215
$this->_quoteConfig->getProductAttributes()
216-
)->addOptionsToResult()->addStoreFilter()->addUrlRewrite()->addTierPriceData();
216+
)->addOptionsToResult()->addStoreFilter()->addUrlRewrite();
217+
218+
$productCollection = $this->addTierPriceData($productCollection);
217219

218220
$this->_eventManager->dispatch(
219221
'prepare_catalog_product_collection_prices',
@@ -270,4 +272,20 @@ protected function _assignProducts()
270272

271273
return $this;
272274
}
275+
276+
/**
277+
* Add tier prices to product collection.
278+
*
279+
* @param \Magento\Catalog\Model\ResourceModel\Product\Collection $productCollection
280+
* @return \Magento\Catalog\Model\ResourceModel\Product\Collection
281+
*/
282+
private function addTierPriceData(\Magento\Catalog\Model\ResourceModel\Product\Collection $productCollection)
283+
{
284+
if (empty($this->_quote)) {
285+
$productCollection->addTierPriceData();
286+
} else {
287+
$productCollection->addTierPriceDataByGroupId($this->_quote->getCustomerGroupId());
288+
}
289+
return $productCollection;
290+
}
273291
}

app/code/Magento/Quote/Test/Unit/Model/Quote/Address/Total/SubtotalTest.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,14 @@ public function testCollect($price, $originalPrice, $itemHasParent, $expectedPri
116116
$store->expects($this->any())->method('getWebsiteId')->willReturn(10);
117117
$product->expects($this->any())->method('getStore')->willReturn($store);
118118
$product->expects($this->any())->method('isVisibleInCatalog')->will($this->returnValue(true));
119-
119+
$extensionAttribute = $this->getMockBuilder(\Magento\Catalog\Api\Data\ProductExtensionInterface::class)
120+
->setMethods(['getStockItem'])
121+
->disableOriginalConstructor()
122+
->getMockForAbstractClass();
123+
$extensionAttribute->expects($this->atLeastOnce())
124+
->method('getStockItem')
125+
->will($this->returnValue($this->stockItemMock));
126+
$product->expects($this->atLeastOnce())->method('getExtensionAttributes')->willReturn($extensionAttribute);
120127
$quote->expects($this->any())->method('getStore')->will($this->returnValue($store));
121128
$quoteItem->setProduct($product)->setQuote($quote);
122129

app/code/Magento/Quote/Test/Unit/Model/Quote/ItemTest.php

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,6 @@ class ItemTest extends \PHPUnit_Framework_TestCase
5656
/** @var \PHPUnit_Framework_MockObject_MockObject */
5757
protected $stockItemMock;
5858

59-
/**
60-
* @var \PHPUnit_Framework_MockObject_MockObject
61-
*/
62-
protected $stockRegistry;
63-
6459
/**
6560
* @var \Magento\Framework\Serialize\Serializer\Json
6661
*/
@@ -131,14 +126,6 @@ protected function setUp()
131126
false
132127
);
133128

134-
$this->stockRegistry = $this->getMockBuilder(\Magento\CatalogInventory\Model\StockRegistry::class)
135-
->disableOriginalConstructor()
136-
->setMethods(['getStockItem', '__wakeup'])
137-
->getMock();
138-
$this->stockRegistry->expects($this->any())
139-
->method('getStockItem')
140-
->will($this->returnValue($this->stockItemMock));
141-
142129
$this->serializer = $this->getMockBuilder(\Magento\Framework\Serialize\Serializer\Json::class)
143130
->setMethods(['unserialize'])
144131
->getMockForAbstractClass();
@@ -151,7 +138,6 @@ protected function setUp()
151138
'statusListFactory' => $statusListFactory,
152139
'itemOptionFactory' => $this->itemOptionFactory,
153140
'quoteItemCompare' => $this->compareHelper,
154-
'stockRegistry' => $this->stockRegistry,
155141
'serializer' => $this->serializer
156142
]
157143
);
@@ -383,9 +369,6 @@ public function testSetProductWithQuoteAndStockItem()
383369
->with('sales_quote_item_set_product', ['product' => $productMock, 'quote_item' => $this->model]);
384370

385371
$isQtyDecimal = true;
386-
$this->stockItemMock->expects($this->any())
387-
->method('getStockId')
388-
->will($this->returnValue(99));
389372
$this->stockItemMock->expects($this->once())
390373
->method('getIsQtyDecimal')
391374
->will($this->returnValue($isQtyDecimal));
@@ -424,6 +407,18 @@ public function testSetProductWithQuoteAndStockItem()
424407
$this->assertEquals($isQtyDecimal, $this->model->getIsQtyDecimal());
425408
}
426409

410+
/**
411+
* Generate product mock.
412+
*
413+
* @param int $productId
414+
* @param string $productType
415+
* @param string $productSku
416+
* @param string $productName
417+
* @param string $productWeight
418+
* @param int $productTaxClassId
419+
* @param float $productCost
420+
* @return \PHPUnit_Framework_MockObject_MockObject
421+
*/
427422
private function generateProductMock(
428423
$productId,
429424
$productType,
@@ -449,6 +444,7 @@ private function generateProductMock(
449444
'getTypeInstance',
450445
'getStickWithinParent',
451446
'getCustomOptions',
447+
'getExtensionAttributes',
452448
'toArray',
453449
'__wakeup',
454450
'getStore',
@@ -485,7 +481,14 @@ private function generateProductMock(
485481
$productMock->expects($this->any())
486482
->method('getStore')
487483
->will($this->returnValue($store));
488-
484+
$extensionAttribute = $this->getMockBuilder(\Magento\Catalog\Api\Data\ProductExtensionInterface::class)
485+
->setMethods(['getStockItem'])
486+
->disableOriginalConstructor()
487+
->getMockForAbstractClass();
488+
$extensionAttribute->expects($this->atLeastOnce())
489+
->method('getStockItem')
490+
->will($this->returnValue($this->stockItemMock));
491+
$productMock->expects($this->atLeastOnce())->method('getExtensionAttributes')->willReturn($extensionAttribute);
489492
return $productMock;
490493
}
491494

@@ -784,6 +787,7 @@ public function testGetQtyOptions()
784787
self::PRODUCT_COST
785788
);
786789

790+
$this->model->setProduct($productMock);
787791
$this->model->setProduct($productMock2);
788792
$this->model->setOptions([$optionCode1 => $optionMock1, $optionCode2 => $optionMock2]);
789793

app/code/Magento/Tax/Model/Config/Notification.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313
*/
1414
class Notification extends \Magento\Framework\App\Config\Value
1515
{
16+
/**
17+
* @var string
18+
*/
19+
protected $_eventPrefix = 'tax_config_notification';
20+
1621
/**
1722
* @var \Magento\Config\Model\ResourceModel\Config
1823
*/

0 commit comments

Comments
 (0)