Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
3259aa0
Composite products support for IsProductSaleable.
novikor Jun 14, 2020
5c05bde
Refactoring.
Jul 30, 2020
277444f
Fix static tests.
Jul 30, 2020
449903b
Move product load after type discovery.
Aug 2, 2020
a8fe881
Fix typo.
Aug 2, 2020
07b8b95
Refactoring.
Aug 8, 2020
75d2aa6
Fix static tests, fix integration tests, code review fixes, revert un…
Aug 13, 2020
969d85d
Composite products support for IsProductSaleable.
novikor Sep 18, 2020
634edaa
Composite products support for IsProductSaleable.
novikor Jun 14, 2020
ed96f69
magento/inventory#3140:
Sep 30, 2020
dff2271
Product salability improvements #3202.
novikor Sep 30, 2020
b902536
Product salability improvements #3202.
Oct 2, 2020
b9e33c8
Load product salability data on-demand #3201: Moved product salabilit…
novikor May 19, 2020
dbacea1
Load product salability data on-demand #3201. Moved plugins to isAvai…
novikor May 20, 2020
05d5a9c
Load product salability data on-demand #3201.
nmalevanec May 22, 2020
a977217
Load product salability data on-demand #3201.
May 23, 2020
77ed746
Load product salability data on-demand #3201.
novikor Oct 2, 2020
8765d01
Load product salability data on-demand #3201.
novikor Oct 2, 2020
2340018
Load product salability data on-demand #3201.
Oct 23, 2020
d106eb0
Load product salability data on-demand #3201.
Oct 23, 2020
b22f0d2
Load product salability data on-demand #3201.
Oct 23, 2020
ed7f2a5
Load product salability data on-demand #3201.
Oct 23, 2020
d612570
Load product salability data on-demand #3201.
Oct 24, 2020
9ed24ae
IsProductSalable/AreProdustsSalable composite products support. #3140
novikor Nov 18, 2020
a122e9b
IsProductSalable/AreProdustsSalable composite products support. #3140
novikor Jan 4, 2021
c3f1b3d
IsProductSalable/AreProdustsSalable composite products support. #3140
novikor Jan 19, 2021
b7862fe
Merge branch '1.2-develop' into product-salability-improvements-fork
novikor Jan 20, 2021
640bb78
Merge branch '1.2-develop' into product-salability-improvements-fork
Jan 22, 2021
818b7c6
Merge branch '1.2-develop' into product-salability-improvements-fork
Feb 1, 2021
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

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

declare(strict_types=1);

namespace Magento\InventoryBundleProduct\Plugin\InventorySales;

use Magento\Bundle\Model\Product\Type;
use Magento\Catalog\Api\ProductRepositoryInterface;
use Magento\Framework\Exception\LocalizedException;
use Magento\InventoryBundleProduct\Model\GetBundleProductStockStatus;
use Magento\InventoryCatalogApi\Model\GetProductTypesBySkusInterface;
use Magento\InventorySales\Model\IsProductSalableCondition\IsProductSalableConditionChain;

/**
* Check if bundle product is salable with bundle options.
*/
class IsBundleProductSalable
{
/**
* @var Type
*/
private $bundleProductType;

/**
* @var ProductRepositoryInterface
*/
private $productRepository;

/**
* @var GetBundleProductStockStatus
*/
private $getBundleProductStockStatus;

/**
* @var GetProductTypesBySkusInterface
*/
private $getProductTypesBySkus;

/**
* @param Type $type
* @param ProductRepositoryInterface $repository
* @param GetBundleProductStockStatus $getBundleProductStockStatus
* @param GetProductTypesBySkusInterface $getProductTypesBySkus
*/
public function __construct(
Type $type,
ProductRepositoryInterface $repository,
GetBundleProductStockStatus $getBundleProductStockStatus,
GetProductTypesBySkusInterface $getProductTypesBySkus
) {
$this->bundleProductType = $type;
$this->productRepository = $repository;
$this->getBundleProductStockStatus = $getBundleProductStockStatus;
$this->getProductTypesBySkus = $getProductTypesBySkus;
}

/**
* Get bundle product status based on child statuses.
*
* @param IsProductSalableConditionChain $subject
* @param \Closure $proceed
* @param string $sku
* @param int $stockId
*
* @return bool
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function aroundExecute(
IsProductSalableConditionChain $subject,
\Closure $proceed,
string $sku,
int $stockId
): bool {
try {
$types = $this->getProductTypesBySkus->execute([$sku]);

$isProductSalable = $proceed($sku, $stockId);
if (!isset($types[$sku]) || $types[$sku] !== Type::TYPE_CODE || !$isProductSalable) {
return $isProductSalable;
}

$product = $this->productRepository->get($sku);

if ($product->hasData('all_items_salable')) {
return $product->getData('all_items_salable');
}

/** @noinspection PhpParamsInspection */
$options = $this->bundleProductType->getOptionsCollection($product);
$status = $this->getBundleProductStockStatus->execute(
$product,
$options->getItems(),
$stockId
);
$product->setData('all_items_salable', $status);
} catch (LocalizedException $e) {
$status = false;
}

return $status;
}
}
4 changes: 3 additions & 1 deletion InventoryBundleProduct/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
"magento/module-store": "*"
},
"suggest": {
"magento/module-catalog-inventory": "*"
"magento/module-catalog-inventory": "*",
"magento/module-inventory-sales": "*",
"magento/module-inventory-catalog": "*"
},
"type": "magento2-module",
"license": [
Expand Down
4 changes: 2 additions & 2 deletions InventoryBundleProduct/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
</argument>
</arguments>
</type>
<type name="Magento\CatalogInventory\Helper\Stock">
<plugin name="adapt_assign_stock_status_to_bundle_product" type="Magento\InventoryBundleProduct\Plugin\CatalogInventory\Helper\Stock\AdaptAssignStatusToProductPlugin"/>
<type name="Magento\InventorySales\Model\IsProductSalableCondition\IsProductSalableConditionChain">
<plugin name="is_bundle_product_salable" type="Magento\InventoryBundleProduct\Plugin\InventorySales\IsBundleProductSalable" />
</type>
</config>
63 changes: 63 additions & 0 deletions InventoryCatalog/Model/IsProductSalable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

declare(strict_types=1);

namespace Magento\InventoryCatalog\Model;

use Magento\Catalog\Model\Product;
use Magento\Catalog\Model\Product\Attribute\Source\Status;
use Magento\InventorySalesApi\Api\AreProductsSalableInterface;

/**
* Get salable product status service.
*/
class IsProductSalable
{
/**
* @var GetStockIdForCurrentWebsite
*/
private $getStockIdForCurrentWebsite;

/**
* @var AreProductsSalableInterface
*/
private $areProductsSalable;

/**
* @param GetStockIdForCurrentWebsite $getStockIdForCurrentWebsite
* @param AreProductsSalableInterface $areProductsSalable
*/
public function __construct(
GetStockIdForCurrentWebsite $getStockIdForCurrentWebsite,
AreProductsSalableInterface $areProductsSalable
) {
$this->getStockIdForCurrentWebsite = $getStockIdForCurrentWebsite;
$this->areProductsSalable = $areProductsSalable;
}

/**
* Verify product salable status.
*
* @param Product $product
* @return bool
*/
public function execute(Product $product): bool
{
if (null === $product->getSku() || !((int)$product->getStatus() === Status::STATUS_ENABLED)) {
return false;
}
if ($product->hasData('is_salable')) {
return (bool)$product->getData('is_salable');
}
$stockId = $this->getStockIdForCurrentWebsite->execute();
$result = current($this->areProductsSalable->execute([$product->getData(Product::SKU)], $stockId));
$isSalable = $result->isSalable();
$product->setData('is_salable', $isSalable);

return $isSalable;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\InventoryCatalog\Plugin\Catalog\Model\Product;

use Magento\Catalog\Model\Product;
use Magento\InventoryCatalog\Model\IsProductSalable;

/**
* Is product available in multi stock environment plugin.
*/
class IsAvailablePlugin
{
/**
* @var IsProductSalable
*/
private $isProductSalable;

/**
* @param IsProductSalable $isProductSalable
*/
public function __construct(
IsProductSalable $isProductSalable
) {
$this->isProductSalable = $isProductSalable;
}

/**
* Fetches is salable status from multi-stock and sets it to product is_salable flag.
*
* @param Product $product
*
* @return void
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function beforeIsAvailable(Product $product): void
{
$product->setData('is_salable', $this->isProductSalable->execute($product));
}
}
Loading