diff --git a/InventoryBundleProduct/Model/GetBundleProductStockStatus.php b/InventoryBundleProduct/Model/GetBundleProductStockStatus.php index d99449f503e5..e1dbf7304ae4 100644 --- a/InventoryBundleProduct/Model/GetBundleProductStockStatus.php +++ b/InventoryBundleProduct/Model/GetBundleProductStockStatus.php @@ -10,7 +10,6 @@ use Magento\Bundle\Api\Data\OptionInterface; use Magento\Catalog\Api\Data\ProductInterface; use Magento\Catalog\Model\Product; -use Magento\Catalog\Model\Product\Attribute\Source\Status; use Magento\Framework\Exception\LocalizedException; use Magento\InventoryConfigurationApi\Api\GetStockItemConfigurationInterface; use Magento\InventoryConfigurationApi\Exception\SkuIsNotAssignedToStockException; @@ -136,14 +135,12 @@ private function getAreSalableSelections(ProductInterface $product, OptionInterf $bundleSelections = $this->getProductSelection->execute($product, $option); $skuRequests = []; foreach ($bundleSelections->getItems() as $selection) { - if ((int)$selection->getStatus() === Status::STATUS_ENABLED) { - $skuRequests[] = $this->isProductSalableForRequestedQtyRequestFactory->create( - [ - 'sku' => (string)$selection->getSku(), - 'qty' => $this->getRequestedQty($selection, $stockId), - ] - ); - } + $skuRequests[] = $this->isProductSalableForRequestedQtyRequestFactory->create( + [ + 'sku' => (string)$selection->getSku(), + 'qty' => $this->getRequestedQty($selection, $stockId), + ] + ); } return $this->areProductsSalableForRequestedQty->execute($skuRequests, $stockId); diff --git a/InventoryBundleProduct/Model/GetProductSelection.php b/InventoryBundleProduct/Model/GetProductSelection.php index 04e16baee82f..f9e2fc6f07b5 100644 --- a/InventoryBundleProduct/Model/GetProductSelection.php +++ b/InventoryBundleProduct/Model/GetProductSelection.php @@ -12,7 +12,9 @@ use Magento\Bundle\Model\ResourceModel\Selection\Collection\FilterApplier; use Magento\Bundle\Model\ResourceModel\Selection\CollectionFactory; use Magento\Catalog\Api\Data\ProductInterface; +use Magento\Catalog\Model\Product\Attribute\Source\Status; use Magento\Framework\EntityManager\MetadataPool; +use Magento\Store\Model\StoreManagerInterface; /** * Retrieve bundle product selection service. @@ -34,19 +36,27 @@ class GetProductSelection */ private $selectionCollectionFilterApplier; + /** + * @var StoreManagerInterface + */ + private $storeManager; + /** * @param CollectionFactory $collectionFactory * @param MetadataPool $metadataPool * @param FilterApplier $selectionCollectionFilterApplier + * @param StoreManagerInterface $storeManager */ public function __construct( CollectionFactory $collectionFactory, MetadataPool $metadataPool, - FilterApplier $selectionCollectionFilterApplier + FilterApplier $selectionCollectionFilterApplier, + StoreManagerInterface $storeManager ) { $this->collectionFactory = $collectionFactory; $this->metadataPool = $metadataPool; $this->selectionCollectionFilterApplier = $selectionCollectionFilterApplier; + $this->storeManager = $storeManager; } /** @@ -61,7 +71,8 @@ public function execute(ProductInterface $product, OptionInterface $option): Col { $metadata = $this->metadataPool->getMetadata(ProductInterface::class); $selectionsCollection = $this->collectionFactory->create(); - $selectionsCollection->addAttributeToSelect('status'); + $selectionsCollection->addStoreFilter($this->storeManager->getStore()); + $selectionsCollection->addAttributeToFilter(ProductInterface::STATUS, Status::STATUS_ENABLED); $selectionsCollection->setFlag('product_children', true); $selectionsCollection->addFilterByRequiredOptions(); $selectionsCollection->setOptionIdsFilter([$option->getId()]); diff --git a/InventoryBundleProduct/Plugin/Bundle/Model/Product/Type/AdaptIsSalablePlugin.php b/InventoryBundleProduct/Plugin/Bundle/Model/Product/Type/AdaptIsSalablePlugin.php index 481881e3cd66..561f7433a18e 100644 --- a/InventoryBundleProduct/Plugin/Bundle/Model/Product/Type/AdaptIsSalablePlugin.php +++ b/InventoryBundleProduct/Plugin/Bundle/Model/Product/Type/AdaptIsSalablePlugin.php @@ -11,8 +11,6 @@ use Magento\Catalog\Model\Product; use Magento\Catalog\Model\Product\Attribute\Source\Status; use Magento\InventoryBundleProduct\Model\GetBundleProductStockStatus; -use Magento\InventoryCatalogApi\Api\DefaultStockProviderInterface; -use Magento\InventorySalesApi\Api\IsProductSalableInterface; use Magento\InventorySalesApi\Model\StockByWebsiteIdResolverInterface; use Magento\Store\Model\StoreManagerInterface; @@ -21,11 +19,6 @@ */ class AdaptIsSalablePlugin { - /** - * @var IsProductSalableInterface - */ - private $isProductSalable; - /** * @var StoreManagerInterface */ @@ -42,38 +35,28 @@ class AdaptIsSalablePlugin private $getBundleProductStockStatus; /** - * @var DefaultStockProviderInterface - */ - private $defaultStockProvider; - - /** - * @param IsProductSalableInterface $isProductSalable * @param StoreManagerInterface $storeManager * @param StockByWebsiteIdResolverInterface $stockByWebsiteIdResolver * @param GetBundleProductStockStatus $getBundleProductStockStatus - * @param DefaultStockProviderInterface $defaultStockProvider */ public function __construct( - IsProductSalableInterface $isProductSalable, StoreManagerInterface $storeManager, StockByWebsiteIdResolverInterface $stockByWebsiteIdResolver, - GetBundleProductStockStatus $getBundleProductStockStatus, - DefaultStockProviderInterface $defaultStockProvider + GetBundleProductStockStatus $getBundleProductStockStatus ) { - $this->isProductSalable = $isProductSalable; $this->storeManager = $storeManager; $this->stockByWebsiteIdResolver = $stockByWebsiteIdResolver; $this->getBundleProductStockStatus = $getBundleProductStockStatus; - $this->defaultStockProvider = $defaultStockProvider; } /** - * Verify, is product salable in multi stock environment. + * Verify is bundle product salable in multi stock environment. * * @param Type $subject * @param \Closure $proceed * @param Product $product * @return bool + * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function aroundIsSalable(Type $subject, \Closure $proceed, Product $product): bool { @@ -92,9 +75,6 @@ public function aroundIsSalable(Type $subject, \Closure $proceed, Product $produ $website = $this->storeManager->getWebsite(); $stock = $this->stockByWebsiteIdResolver->execute((int)$website->getId()); - if ($this->defaultStockProvider->getId() === $stock->getStockId()) { - return $proceed($product); - } $options = $subject->getOptionsCollection($product); $isSalable = $this->getBundleProductStockStatus->execute($product, $options->getItems(), $stock->getStockId()); $product->setData('all_items_salable', $isSalable);