Skip to content

Commit ad5c3e4

Browse files
committed
#26065 isSaleable cache
1 parent f540160 commit ad5c3e4

File tree

1 file changed

+32
-3
lines changed

1 file changed

+32
-3
lines changed

app/code/Magento/ConfigurableProduct/Model/Product/Type/Configurable.php

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,13 @@ class Configurable extends \Magento\Catalog\Model\Product\Type\AbstractType
102102
*/
103103
protected $_canConfigure = true;
104104

105+
/**
106+
* Local cache
107+
*
108+
* @var array
109+
*/
110+
protected $isSaleableBySku = [];
111+
105112
/**
106113
* @var \Magento\Framework\App\Config\ScopeConfigInterface
107114
*/
@@ -585,7 +592,7 @@ protected function getGalleryReadHandler()
585592
* @param \Magento\Catalog\Model\Product $product
586593
* @return \Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable\Product\Collection
587594
*/
588-
public function getUsedProductCollection($product)
595+
public function getLinkedProductCollection($product)
589596
{
590597
$collection = $this->_productCollectionFactory->create()->setFlag(
591598
'product_children',
@@ -600,6 +607,17 @@ public function getUsedProductCollection($product)
600607
return $collection;
601608
}
602609

610+
/**
611+
* Retrieve related products collection. Extension point for listing
612+
*
613+
* @param \Magento\Catalog\Model\Product $product
614+
* @return \Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable\Product\Collection
615+
*/
616+
public function getUsedProductCollection($product)
617+
{
618+
return $this->getLinkedProductCollection($product);
619+
}
620+
603621
/**
604622
* Before save process
605623
*
@@ -744,15 +762,26 @@ private function saveRelatedProducts(ProductInterface $product)
744762
*/
745763
public function isSalable($product)
746764
{
765+
$storeId = $this->getStoreFilter($product);
766+
if ($storeId instanceof \Magento\Store\Model\Store) {
767+
$storeId = $storeId->getId();
768+
}
769+
770+
if (isset($this->isSaleableBySku[$storeId][$product->getSku()])) {
771+
return $this->isSaleableBySku[$storeId][$product->getSku()];
772+
}
773+
747774
$salable = parent::isSalable($product);
748775

749776
if ($salable !== false) {
750-
$collection = $this->getUsedProductCollection($product);
751-
$collection->addStoreFilter($this->getStoreFilter($product));
777+
$collection = $this->getLinkedProductCollection($product);
778+
$collection->addStoreFilter($storeId);
752779
$collection = $this->salableProcessor->process($collection);
753780
$salable = 0 !== $collection->getSize();
754781
}
755782

783+
$this->isSaleableBySku[$storeId][$product->getSku()] = $salable;
784+
756785
return $salable;
757786
}
758787

0 commit comments

Comments
 (0)