Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
1721551
magento/inventory#3013: [Async Salable Status] Storefront implementat…
May 8, 2020
4bc0e48
Add queues for reservation placed
nuzil May 6, 2020
53a64b2
[Async Salable Status] Create infrastructure for async status update …
novikor May 9, 2020
169e2b3
[Async Salable Status] Create infrastructure for async status update …
novikor May 9, 2020
4e2f0a1
Merge branch '1.2.0-develop' into async-reservation
novikor May 11, 2020
a24043e
[Async Salable Status] Create infrastructure for async status update …
novikor May 11, 2020
8e5c2c1
[Async Salable Status] Create infrastructure for async status update …
novikor May 11, 2020
813617b
[Async Salable Status] Create infrastructure for async status update …
novikor May 13, 2020
a72947b
Merge remote-tracking branch 'origin/Lightweight-Is-Are-Product-s-Sal…
novikor May 13, 2020
9f0b607
Merge remote-tracking branch 'origin/async-reservation' into faster-s…
novikor May 13, 2020
fb43921
Revert "[Async Salable Status] Create infrastructure for async status…
novikor May 14, 2020
749cb4d
Merge branch 'async-reservation' into faster-storefront
novikor May 14, 2020
7663d03
magento/inventory#3013: [Async Salable Status] Storefront implementat…
May 14, 2020
a9ca49f
magento/inventory#3013: [Async Salable Status] Storefront implementat…
May 14, 2020
5a16117
magento/inventory#3013: [Async Salable Status] Storefront implementat…
May 15, 2020
11a7e29
magento/inventory#3013: [Async Salable Status] Storefront implementat…
May 15, 2020
f176c1a
magento/inventory#3013: [Async Salable Status] Storefront implementat…
May 15, 2020
874c152
Merge branch '1.2.0-develop' into Lightweight-Is-Are-Product-s-Salable
swnsma May 15, 2020
6649831
[Async Salable Status] Create infrastructure for async status update …
novikor May 17, 2020
b5c9488
Merge remote-tracking branch 'origin/Lightweight-Is-Are-Product-s-Sal…
novikor May 17, 2020
f4949ba
Merge pull request #3026 from magento/async-reservation
novikor May 17, 2020
067a706
[Async Salable Status] Create infrastructure for async status update …
novikor May 17, 2020
3ae30ea
[Async Salable Status] Create infrastructure for async status update …
novikor May 17, 2020
abe49de
[Async Salable Status] Create infrastructure for async status update …
novikor May 17, 2020
0abdaab
Fix tests.
nmalevanec May 19, 2020
b627df2
Fix static tests.
May 19, 2020
c251753
Remove qty check during setQty method. Move Qty check before persist.
May 19, 2020
e5aaae5
[Async Salable Status] Moved product salability calculation from obse…
novikor May 19, 2020
30cf0af
Merge pull request #3045 from magento/is-product-salable-performance-…
novikor May 19, 2020
9cd6d18
Merge pull request #3044 from magento/case-2-set-qty-event
novikor May 19, 2020
4135e7a
Merge branch '1.2.0-develop' into faster-storefront
nmalevanec May 20, 2020
90c3f0a
[Async Salable Status] Moved plugins to isAvailable only.
novikor May 20, 2020
881d150
Merge branch '1.2.0-develop' into faster-storefront
May 21, 2020
15d5049
Fixed plugin configuration
May 21, 2020
25859d0
Fix tests.
nmalevanec May 22, 2020
e27d74e
Fix tests.
nmalevanec May 22, 2020
372ac73
Fix salable logic
May 23, 2020
f761396
Disable configurable condition
May 24, 2020
a06648d
Fix tests.
nmalevanec May 25, 2020
9aea1b4
Fix tests.
nmalevanec May 25, 2020
b71d884
Fix tests.
nmalevanec May 26, 2020
3c29f98
Fix tests.
nmalevanec May 27, 2020
a6a4d75
Merge branch '1.2.0-develop' into MSI-3054
swnsma May 27, 2020
657ccca
Adapt isProductSalabe for bundle and configurable products.
nmalevanec May 28, 2020
438050a
Merge remote-tracking branch 'origin/MSI-3054' into MSI-3054
nmalevanec May 28, 2020
995d5aa
Remove redundant plugin.
nmalevanec May 28, 2020
74da690
Fix tests
nmalevanec May 29, 2020
4d6eb63
Remove MySQL view. Re-work bundle product indexer.
nmalevanec Jun 1, 2020
7e0e09d
Re-work configurable product indexer. Modify is salable condition.
nmalevanec Jun 4, 2020
7744314
Merge branch '1.2.0-develop' into MSI-3054
nmalevanec Jun 4, 2020
58889f0
Re-work bundle product indexer.
nmalevanec Jun 4, 2020
4f9f97c
Merge branch '1.2.0-develop' into MSI-3054
nmalevanec Jun 5, 2020
8d6a3ec
Fix merge conflicts.
nmalevanec Jun 5, 2020
41fbb07
Fix configurable product is salable verification.
nmalevanec Jun 5, 2020
c0e5cdf
Fis bundle product indexation.
nmalevanec Jun 9, 2020
674df26
Fix website value for IsSalable service.
nmalevanec Jun 10, 2020
ad4ff2e
Rework configurable product salable verification. Rework AreProductsS…
nmalevanec Jun 11, 2020
a1ff326
Fix 'is_salable' and 'is_available' plugins. Make index to consider m…
nmalevanec Jun 12, 2020
5eafe30
Try to remove plugin blocked used events.
nmalevanec Jun 12, 2020
8cffa9e
Fix test.
nmalevanec Jun 15, 2020
53f6bc5
Fix bundle product index. Fix adapt get product stock status plugins.
nmalevanec Jun 16, 2020
5e9bcca
Fix tests.
nmalevanec Jun 17, 2020
0960dd5
Merge branch '1.2.0-develop' into MSI-3054
nmalevanec Jun 18, 2020
b2fae89
Fix adapt get product stock status plugins.
nmalevanec Jun 18, 2020
a42afd3
Fix tests.
nmalevanec Jun 19, 2020
0b5e2a3
Merge branch '1.2.0-develop' into MSI-3054
nmalevanec Jun 19, 2020
7e7f12f
Fix tests.
nmalevanec Jun 22, 2020
a7e548f
Merge branch '1.2.0-develop' into MSI-3054
Nov 11, 2020
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
3 changes: 3 additions & 0 deletions Inventory/Test/Integration/GetSourceCodesBySkusTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
use Magento\TestFramework\Helper\Bootstrap;
use PHPUnit\Framework\TestCase;

/**
* @magentoDbIsolation disabled
*/
class GetSourceCodesBySkusTest extends TestCase
{
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<magentoCLI stepKey="addDownloadableDomain" command="downloadable:domains:add example.com static.magento.com"/>
<!--Create test data.-->
<createData entity="FullSource1" stepKey="source"/>
<createData entity="BasicMsiStock1" stepKey="stock"/>
<createData entity="BasicMsiStockWithMainWebsite1" stepKey="stock"/>
<createData entity="SourceStockLinked1" stepKey="stockSourceLink">
<requiredEntity createDataKey="stock"/>
<requiredEntity createDataKey="source"/>
Expand Down Expand Up @@ -76,7 +76,7 @@

<!--Verify product is not visible on storefront.-->
<actionGroup ref="AssertStorefrontProductAbsentOnCategoryPageActionGroup" stepKey="verifyProductNotVisibleOnStorefront">
<argument name="categoryUrlKey" value="$category.url_key$"/>
<argument name="categoryUrlKey" value="$category.custom_attributes[url_key]$"/>
<argument name="productName" value="$product.name$"/>
</actionGroup>
<!-- Turn off Manage Stock-->
Expand Down
85 changes: 26 additions & 59 deletions InventoryAdvancedCheckout/Plugin/Model/AreProductsSalablePlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,75 +8,46 @@
namespace Magento\InventoryAdvancedCheckout\Plugin\Model;

use Magento\AdvancedCheckout\Model\AreProductsSalableForRequestedQtyInterface;
use Magento\AdvancedCheckout\Model\Data\IsProductsSalableForRequestedQtyResult;
use Magento\AdvancedCheckout\Model\Data\IsProductsSalableForRequestedQtyResultFactory;
use Magento\AdvancedCheckout\Model\Data\ProductQuantity;
use Magento\Catalog\Api\ProductRepositoryInterface;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\ObjectManagerInterface;
use Magento\InventoryCatalogApi\Api\DefaultStockProviderInterface;
use Magento\InventorySalesApi\Api\AreProductsSalableInterface;
use Magento\InventorySalesApi\Api\Data\SalesChannelInterface;
use Magento\InventorySalesApi\Api\StockResolverInterface;
use Magento\Store\Api\WebsiteRepositoryInterface;

/**
* Provides multi-sourcing capabilities for Advanced Checkout Order By SKU feature.
*/
class AreProductsSalablePlugin
{
/**
* @var AreProductsSalableInterface
* @var ProductRepositoryInterface
*/
private $areProductsSalable;
private $productRepository;

/**
* @var StockResolverInterface
* @var IsProductsSalableForRequestedQtyResultFactory
*/
private $stockResolver;
private $isProductsSalableForRequestedQtyResultFactory;

/**
* @var WebsiteRepositoryInterface
*/
private $websiteRepository;

/**
* @var DefaultStockProviderInterface
*/
private $defaultStockProvider;

/**
* @var ObjectManagerInterface
*/
private $objectManager;

/**
* @param AreProductsSalableInterface $areProductsSalable
* @param StockResolverInterface $stockResolver
* @param WebsiteRepositoryInterface $websiteRepository
* @param DefaultStockProviderInterface $defaultStockProvider
* @param ObjectManagerInterface $objectManager
* @param ProductRepositoryInterface $productRepository
* @param IsProductsSalableForRequestedQtyResultFactory $isProductsSalableForRequestedQtyResultFactory
*/
public function __construct(
AreProductsSalableInterface $areProductsSalable,
StockResolverInterface $stockResolver,
WebsiteRepositoryInterface $websiteRepository,
DefaultStockProviderInterface $defaultStockProvider,
ObjectManagerInterface $objectManager
ProductRepositoryInterface $productRepository,
IsProductsSalableForRequestedQtyResultFactory $isProductsSalableForRequestedQtyResultFactory
) {
$this->areProductsSalable = $areProductsSalable;
$this->stockResolver = $stockResolver;
$this->websiteRepository = $websiteRepository;
$this->defaultStockProvider = $defaultStockProvider;
$this->objectManager = $objectManager;
$this->productRepository = $productRepository;
$this->isProductsSalableForRequestedQtyResultFactory = $isProductsSalableForRequestedQtyResultFactory;
}

/**
* Get is product out of stock for given Product id in a given Website id in MSI context.
* Get products salable status for given sku requests.
*
* @param AreProductsSalableForRequestedQtyInterface $subject
* @param callable $proceed
* @param \Magento\AdvancedCheckout\Model\Data\ProductQuantity[] $productQuantities
* @param ProductQuantity[] $productQuantities
* @param int $websiteId
* @return array
* @throws NoSuchEntityException
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function aroundExecute(
Expand All @@ -85,22 +56,18 @@ public function aroundExecute(
array $productQuantities,
int $websiteId
): array {
$website = $this->websiteRepository->getById($websiteId);
$stock = $this->stockResolver->execute(SalesChannelInterface::TYPE_WEBSITE, $website->getCode());
if ($this->defaultStockProvider->getId() === $stock->getStockId()) {
return $proceed($productQuantities, $websiteId);
}

$skus = [];
foreach ($productQuantities as $productQuantity) {
$skus[] = $productQuantity->getSku();
}
$result = [];
foreach ($this->areProductsSalable->execute($skus, $stock->getStockId()) as $productStock) {
$result[] = $this->objectManager->create(
IsProductsSalableForRequestedQtyResult::class,
['sku' => $productStock->getSku(), 'isSalable' => $productStock->isSalable()]
);
foreach ($productQuantities as $productQuantity) {
try {
$product = $this->productRepository->get($productQuantity->getSku());
$result[] = $this->isProductsSalableForRequestedQtyResultFactory->create(
['sku' => $product->getSku(), 'isSalable' => $product->isSalable()]
);
} catch (NoSuchEntityException $e) {
$result[] = $this->isProductsSalableForRequestedQtyResultFactory->create(
['sku' => $productQuantity->getSku(), 'isSalable' => false]
);
}
}

return $result;
Expand Down
4 changes: 1 addition & 3 deletions InventoryAdvancedCheckout/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
"require": {
"php": "~7.3.0||~7.4.0",
"magento/framework": "*",
"magento/module-store": "*",
"magento/module-inventory-catalog-api": "*",
"magento/module-inventory-sales-api": "*"
"magento/module-catalog": "*"
},
"suggest": {
"magento/module-advanced-checkout": "*"
Expand Down
6 changes: 3 additions & 3 deletions InventoryBundleProduct/Model/GetBundleProductStockStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
class GetBundleProductStockStatus
{
/**
* @var GetProductSelection
* @var GetProductSelections
*/
private $getProductSelection;

Expand All @@ -44,13 +44,13 @@ class GetBundleProductStockStatus
private $getStockItemConfiguration;

/**
* @param GetProductSelection $getProductSelection
* @param GetProductSelections $getProductSelection
* @param AreProductsSalableForRequestedQtyInterface $areProductsSalableForRequestedQty
* @param IsProductSalableForRequestedQtyRequestInterfaceFactory $isProductSalableForRequestedQtyRequestFactory
* @param GetStockItemConfigurationInterface $getStockItemConfiguration
*/
public function __construct(
GetProductSelection $getProductSelection,
GetProductSelections $getProductSelection,
AreProductsSalableForRequestedQtyInterface $areProductsSalableForRequestedQty,
IsProductSalableForRequestedQtyRequestInterfaceFactory $isProductSalableForRequestedQtyRequestFactory,
GetStockItemConfigurationInterface $getStockItemConfiguration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
use Magento\Framework\EntityManager\MetadataPool;

/**
* Retrieve bundle product selection service.
* Retrieve bundle product selections service.
*/
class GetProductSelection
class GetProductSelections
{
/**
* @var CollectionFactory
Expand Down Expand Up @@ -65,7 +65,6 @@ public function execute(ProductInterface $product, OptionInterface $option): Col
$selectionsCollection->setFlag('product_children', true);
$selectionsCollection->addFilterByRequiredOptions();
$selectionsCollection->setOptionIdsFilter([$option->getId()]);

$this->selectionCollectionFilterApplier->apply(
$selectionsCollection,
'parent_product_id',
Expand Down
142 changes: 142 additions & 0 deletions InventoryBundleProduct/Model/IsBundleProductSalable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\InventoryBundleProduct\Model;

use Magento\Bundle\Api\Data\OptionInterface;
use Magento\Catalog\Api\Data\ProductInterface;
use Magento\Catalog\Model\Product;
use Magento\Framework\Exception\LocalizedException;
use Magento\InventoryConfigurationApi\Api\GetStockItemConfigurationInterface;
use Magento\InventoryConfigurationApi\Exception\SkuIsNotAssignedToStockException;
use Magento\InventorySalesApi\Api\AreProductsSalableForRequestedQtyInterface;
use Magento\InventorySalesApi\Api\Data\IsProductSalableForRequestedQtyRequestInterfaceFactory;
use Magento\InventorySalesApi\Api\Data\IsProductSalableForRequestedQtyResultInterface;

/**
* Get bundle product salable status considering bundle product selections service.
*/
class IsBundleProductSalable
{
/**
* @var GetProductSelections
*/
private $getProductSelection;

/**
* @var AreProductsSalableForRequestedQtyInterface
*/
private $areProductsSalableForRequestedQty;

/**
* @var IsProductSalableForRequestedQtyRequestInterfaceFactory
*/
private $isProductSalableForRequestedQtyRequestFactory;

/**
* @var GetStockItemConfigurationInterface
*/
private $getStockItemConfiguration;

/**
* @param GetProductSelections $getProductSelection
* @param AreProductsSalableForRequestedQtyInterface $areProductsSalableForRequestedQty
* @param IsProductSalableForRequestedQtyRequestInterfaceFactory $isProductSalableForRequestedQtyRequestFactory
* @param GetStockItemConfigurationInterface $getStockItemConfiguration
*/
public function __construct(
GetProductSelections $getProductSelection,
AreProductsSalableForRequestedQtyInterface $areProductsSalableForRequestedQty,
IsProductSalableForRequestedQtyRequestInterfaceFactory $isProductSalableForRequestedQtyRequestFactory,
GetStockItemConfigurationInterface $getStockItemConfiguration
) {
$this->getProductSelection = $getProductSelection;
$this->areProductsSalableForRequestedQty = $areProductsSalableForRequestedQty;
$this->isProductSalableForRequestedQtyRequestFactory = $isProductSalableForRequestedQtyRequestFactory;
$this->getStockItemConfiguration = $getStockItemConfiguration;
}

/**
* Provides bundle product stock status.
*
* @param ProductInterface $product
* @param OptionInterface[] $bundleOptions
* @param int $stockId
* @return bool
* @throws LocalizedException
* @throws SkuIsNotAssignedToStockException
*/
public function execute(ProductInterface $product, array $bundleOptions, int $stockId): bool
{
$isSalable = false;
foreach ($bundleOptions as $option) {
$hasSalable = false;
$results = $this->getAreSalableSelections($product, $option, $stockId);
foreach ($results as $result) {
if ($result->isSalable()) {
$hasSalable = true;
break;
}
}
if ($hasSalable) {
$isSalable = true;
}

if (!$hasSalable && $option->getRequired()) {
$isSalable = false;
break;
}
}

return $isSalable;
}

/**
* Get are bundle product selections salable.
*
* @param ProductInterface $product
* @param OptionInterface $option
* @param int $stockId
* @return IsProductSalableForRequestedQtyResultInterface[]
* @throws LocalizedException
* @throws SkuIsNotAssignedToStockException
*/
private function getAreSalableSelections(ProductInterface $product, OptionInterface $option, int $stockId): array
{
$bundleSelections = $this->getProductSelection->execute($product, $option);
$skuRequests = [];
foreach ($bundleSelections->getItems() as $selection) {
$skuRequests[] = $this->isProductSalableForRequestedQtyRequestFactory->create(
[
'sku' => (string)$selection->getSku(),
'qty' => $this->getRequestedQty($selection, $stockId),
]
);
}

return $this->areProductsSalableForRequestedQty->execute($skuRequests, $stockId);
}

/**
* Get bundle product selection qty.
*
* @param Product $product
* @param int $stockId
* @return float
* @throws LocalizedException
* @throws SkuIsNotAssignedToStockException
*/
private function getRequestedQty(Product $product, int $stockId): float
{
if ((int)$product->getSelectionCanChangeQty()) {
$stockItemConfiguration = $this->getStockItemConfiguration->execute((string)$product->getSku(), $stockId);
return $stockItemConfiguration->getMinSaleQty();
}

return (float)$product->getSelectionQty();
}
}
Loading