Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions InventoryBundleProduct/Model/GetBundleProductStockStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
15 changes: 13 additions & 2 deletions InventoryBundleProduct/Model/GetProductSelection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;
}

/**
Expand All @@ -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()]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -21,11 +19,6 @@
*/
class AdaptIsSalablePlugin
{
/**
* @var IsProductSalableInterface
*/
private $isProductSalable;

/**
* @var StoreManagerInterface
*/
Expand All @@ -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
{
Expand All @@ -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);
Expand Down