@@ -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
+ public 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,26 @@ 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
+ if (isset ($ this ->isSaleableBySku [$ storeId ][$ product ->getSku ()])) {
771
+ return $ this ->isSaleableBySku [$ storeId ][$ product ->getSku ()];
772
+ }
773
+
747
774
$ salable = parent ::isSalable ($ product );
748
775
749
776
if ($ salable !== false ) {
750
- $ collection = $ this ->getUsedProductCollection ($ product );
751
- $ collection ->addStoreFilter ($ this -> getStoreFilter ( $ product ) );
777
+ $ collection = $ this ->getLinkedProductCollection ($ product );
778
+ $ collection ->addStoreFilter ($ storeId );
752
779
$ collection = $ this ->salableProcessor ->process ($ collection );
753
780
$ salable = 0 !== $ collection ->getSize ();
754
781
}
755
782
783
+ $ this ->isSaleableBySku [$ storeId ][$ product ->getSku ()] = $ salable ;
784
+
756
785
return $ salable ;
757
786
}
758
787
0 commit comments