|
| 1 | +diff --git a/vendor/magento/module-inventory-configurable-product/Pricing/Price/Indexer/StockStatusBaseSelectProcessor.php b/vendor/magento/module-inventory-configurable-product/Pricing/Price/Indexer/StockStatusBaseSelectProcessor.php |
| 2 | +new file mode 100644 |
| 3 | +index 00000000000..68cb883c79a |
| 4 | +--- /dev/null |
| 5 | ++++ b/vendor/magento/module-inventory-configurable-product/Pricing/Price/Indexer/StockStatusBaseSelectProcessor.php |
| 6 | +@@ -0,0 +1,138 @@ |
| 7 | ++<?php |
| 8 | ++/** |
| 9 | ++ * Copyright © Magento, Inc. All rights reserved. |
| 10 | ++ * See COPYING.txt for license details. |
| 11 | ++ */ |
| 12 | ++declare(strict_types=1); |
| 13 | ++ |
| 14 | ++namespace Magento\InventoryConfigurableProduct\Pricing\Price\Indexer; |
| 15 | ++ |
| 16 | ++use Magento\Catalog\Api\Data\ProductInterface; |
| 17 | ++use Magento\Catalog\Model\ResourceModel\Product\BaseSelectProcessorInterface; |
| 18 | ++use Magento\CatalogInventory\Api\StockConfigurationInterface; |
| 19 | ++use Magento\Framework\App\ResourceConnection; |
| 20 | ++use Magento\Framework\DB\Select; |
| 21 | ++use Magento\Framework\EntityManager\MetadataPool; |
| 22 | ++use Magento\Framework\Exception\NoSuchEntityException; |
| 23 | ++use Magento\InventoryCatalogApi\Api\DefaultStockProviderInterface; |
| 24 | ++use Magento\InventoryIndexer\Model\StockIndexTableNameResolverInterface; |
| 25 | ++use Magento\InventorySalesApi\Api\Data\SalesChannelInterface; |
| 26 | ++use Magento\InventorySalesApi\Api\StockResolverInterface; |
| 27 | ++use Magento\Store\Model\StoreManagerInterface; |
| 28 | ++ |
| 29 | ++/** |
| 30 | ++ * Base select processor. |
| 31 | ++ */ |
| 32 | ++class StockStatusBaseSelectProcessor implements BaseSelectProcessorInterface |
| 33 | ++{ |
| 34 | ++ /** |
| 35 | ++ * @var StockIndexTableNameResolverInterface |
| 36 | ++ */ |
| 37 | ++ private $stockIndexTableNameResolver; |
| 38 | ++ |
| 39 | ++ /** |
| 40 | ++ * @var StockConfigurationInterface |
| 41 | ++ */ |
| 42 | ++ private $stockConfig; |
| 43 | ++ |
| 44 | ++ /** |
| 45 | ++ * @var StoreManagerInterface |
| 46 | ++ */ |
| 47 | ++ private $storeManager; |
| 48 | ++ |
| 49 | ++ /** |
| 50 | ++ * @var StockResolverInterface |
| 51 | ++ */ |
| 52 | ++ private $stockResolver; |
| 53 | ++ |
| 54 | ++ /** |
| 55 | ++ * @var DefaultStockProviderInterface |
| 56 | ++ */ |
| 57 | ++ private $defaultStockProvider; |
| 58 | ++ |
| 59 | ++ /** |
| 60 | ++ * @var ResourceConnection |
| 61 | ++ */ |
| 62 | ++ private $resourceConnection; |
| 63 | ++ |
| 64 | ++ /** |
| 65 | ++ * @var MetadataPool |
| 66 | ++ */ |
| 67 | ++ private $metadataPool; |
| 68 | ++ |
| 69 | ++ /** |
| 70 | ++ * @param StockIndexTableNameResolverInterface $stockIndexTableNameResolver |
| 71 | ++ * @param StockConfigurationInterface $stockConfig |
| 72 | ++ * @param StoreManagerInterface $storeManager |
| 73 | ++ * @param StockResolverInterface $stockResolver |
| 74 | ++ * @param ResourceConnection $resourceConnection |
| 75 | ++ * @param DefaultStockProviderInterface $defaultStockProvider |
| 76 | ++ * @param MetadataPool $metadataPool |
| 77 | ++ */ |
| 78 | ++ public function __construct( |
| 79 | ++ StockIndexTableNameResolverInterface $stockIndexTableNameResolver, |
| 80 | ++ StockConfigurationInterface $stockConfig, |
| 81 | ++ StoreManagerInterface $storeManager, |
| 82 | ++ StockResolverInterface $stockResolver, |
| 83 | ++ ResourceConnection $resourceConnection, |
| 84 | ++ DefaultStockProviderInterface $defaultStockProvider, |
| 85 | ++ MetadataPool $metadataPool |
| 86 | ++ ) { |
| 87 | ++ $this->stockIndexTableNameResolver = $stockIndexTableNameResolver; |
| 88 | ++ $this->stockConfig = $stockConfig; |
| 89 | ++ $this->storeManager = $storeManager; |
| 90 | ++ $this->stockResolver = $stockResolver; |
| 91 | ++ $this->resourceConnection = $resourceConnection; |
| 92 | ++ $this->defaultStockProvider = $defaultStockProvider; |
| 93 | ++ $this->metadataPool = $metadataPool; |
| 94 | ++ } |
| 95 | ++ |
| 96 | ++ /** |
| 97 | ++ * Improves the select with stock status sub query. |
| 98 | ++ * |
| 99 | ++ * @param Select $select |
| 100 | ++ * @return Select |
| 101 | ++ * @throws NoSuchEntityException |
| 102 | ++ */ |
| 103 | ++ public function process(Select $select) |
| 104 | ++ { |
| 105 | ++ if (!$this->stockConfig->isShowOutOfStock()) { |
| 106 | ++ return $select; |
| 107 | ++ } |
| 108 | ++ |
| 109 | ++ $websiteCode = $this->storeManager->getWebsite()->getCode(); |
| 110 | ++ $stock = $this->stockResolver->execute(SalesChannelInterface::TYPE_WEBSITE, $websiteCode); |
| 111 | ++ $stockId = (int)$stock->getStockId(); |
| 112 | ++ if ($stockId === $this->defaultStockProvider->getId()) { |
| 113 | ++ return $select; |
| 114 | ++ } |
| 115 | ++ |
| 116 | ++ $metadata = $this->metadataPool->getMetadata(ProductInterface::class); |
| 117 | ++ $linkField = $metadata->getLinkField(); |
| 118 | ++ |
| 119 | ++ $select->joinInner( |
| 120 | ++ ['le2' => $this->resourceConnection->getTableName('catalog_product_entity')], |
| 121 | ++ 'le2.' . $linkField . ' = l.product_id', |
| 122 | ++ [] |
| 123 | ++ )->joinInner( |
| 124 | ++ ['stock' => $this->stockIndexTableNameResolver->execute($stockId)], |
| 125 | ++ 'stock.sku = le2.sku', |
| 126 | ++ [] |
| 127 | ++ )->joinInner( |
| 128 | ++ ['stock_parent' => $this->stockIndexTableNameResolver->execute($stockId)], |
| 129 | ++ 'stock_parent.sku = le.sku', |
| 130 | ++ [] |
| 131 | ++ )->where( |
| 132 | ++ 'stock.is_salable = ?', |
| 133 | ++ 1 |
| 134 | ++ )->orWhere( |
| 135 | ++ 'stock.is_salable = ?', |
| 136 | ++ 0 |
| 137 | ++ )->where( |
| 138 | ++ 'stock_parent.is_salable = ?', |
| 139 | ++ 0 |
| 140 | ++ ); |
| 141 | ++ |
| 142 | ++ return $select; |
| 143 | ++ } |
| 144 | ++} |
| 145 | +diff --git a/vendor/magento/module-inventory-configurable-product/etc/di.xml b/vendor/magento/module-inventory-configurable-product/etc/di.xml |
| 146 | +index 77358c2d991..3fe63f887b6 100644 |
| 147 | +--- a/vendor/magento/module-inventory-configurable-product/etc/di.xml |
| 148 | ++++ b/vendor/magento/module-inventory-configurable-product/etc/di.xml |
| 149 | +@@ -26,4 +26,9 @@ |
| 150 | + <type name="Magento\CatalogInventory\Observer\ParentItemProcessorInterface"> |
| 151 | + <plugin name="adapt_parent_stock_processor" type="Magento\InventoryConfigurableProduct\Plugin\CatalogInventory\Observer\ParentItemProcessor\AdaptParentItemProcessorPlugin"/> |
| 152 | + </type> |
| 153 | ++ <type name="Magento\ConfigurableProduct\Model\ResourceModel\Product\Indexer\Price\Configurable"> |
| 154 | ++ <arguments> |
| 155 | ++ <argument name="baseSelectProcessor" xsi:type="object">Magento\InventoryConfigurableProduct\Pricing\Price\Indexer\StockStatusBaseSelectProcessor</argument> |
| 156 | ++ </arguments> |
| 157 | ++ </type> |
| 158 | + </config> |
0 commit comments