@@ -102,6 +102,13 @@ class Configurable extends \Magento\Catalog\Model\Product\Type\AbstractType
102
102
*/
103
103
protected $ _canConfigure = true ;
104
104
105
+ /**
106
+ * Local cache
107
+ *
108
+ * @var array
109
+ */
110
+ protected $ isSaleableBySku = [];
111
+
105
112
/**
106
113
* @var \Magento\Framework\App\Config\ScopeConfigInterface
107
114
*/
@@ -585,7 +592,7 @@ protected function getGalleryReadHandler()
585
592
* @param \Magento\Catalog\Model\Product $product
586
593
* @return \Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable\Product\Collection
587
594
*/
588
- public function getUsedProductCollection ($ product )
595
+ protected function getLinkedProductCollection ($ product )
589
596
{
590
597
$ collection = $ this ->_productCollectionFactory ->create ()->setFlag (
591
598
'product_children ' ,
@@ -600,6 +607,17 @@ public function getUsedProductCollection($product)
600
607
return $ collection ;
601
608
}
602
609
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
+
603
621
/**
604
622
* Before save process
605
623
*
@@ -744,15 +762,27 @@ private function saveRelatedProducts(ProductInterface $product)
744
762
*/
745
763
public function isSalable ($ product )
746
764
{
765
+ $ storeId = $ this ->getStoreFilter ($ product );
766
+ if ($ storeId instanceof \Magento \Store \Model \Store) {
767
+ $ storeId = $ storeId ->getId ();
768
+ }
769
+
770
+ $ sku = $ product ->getSku ();
771
+ if (isset ($ this ->isSaleableBySku [$ storeId ][$ sku ])) {
772
+ return $ this ->isSaleableBySku [$ storeId ][$ sku ];
773
+ }
774
+
747
775
$ salable = parent ::isSalable ($ product );
748
776
749
777
if ($ salable !== false ) {
750
- $ collection = $ this ->getUsedProductCollection ($ product );
751
- $ collection ->addStoreFilter ($ this -> getStoreFilter ( $ product ) );
778
+ $ collection = $ this ->getLinkedProductCollection ($ product );
779
+ $ collection ->addStoreFilter ($ storeId );
752
780
$ collection = $ this ->salableProcessor ->process ($ collection );
753
781
$ salable = 0 !== $ collection ->getSize ();
754
782
}
755
783
784
+ $ this ->isSaleableBySku [$ storeId ][$ sku ] = $ salable ;
785
+
756
786
return $ salable ;
757
787
}
758
788
0 commit comments