|
7 | 7 |
|
8 | 8 | namespace Magento\InventorySales\Model;
|
9 | 9 |
|
10 |
| -use Magento\Framework\App\ObjectManager; |
11 | 10 | use Magento\Framework\Exception\LocalizedException;
|
12 |
| -use Magento\InventorySalesApi\Api\AreProductsSalableForRequestedQtyInterface; |
13 |
| -use Magento\InventorySalesApi\Api\Data\ProductSalabilityErrorInterface; |
14 |
| -use Magento\InventorySalesApi\Api\Data\ProductSalableForRequestedQtyInfoInterfaceFactory; |
15 | 11 | use Magento\InventorySalesApi\Api\IsProductSalableForRequestedQtyInterface;
|
| 12 | +use Magento\InventorySalesApi\Api\Data\ProductSalableResultInterface; |
| 13 | +use Magento\InventorySalesApi\Api\Data\ProductSalabilityErrorInterface; |
16 | 14 |
|
17 | 15 | /**
|
18 | 16 | * Verify items are salable for requested quantity.
|
19 | 17 | */
|
20 | 18 | class CheckItemsQuantity
|
21 | 19 | {
|
22 | 20 | /**
|
23 |
| - * @var AreProductsSalableForRequestedQtyInterface |
24 |
| - */ |
25 |
| - private $areProductsSalableForRequestedQty; |
26 |
| - |
27 |
| - /** |
28 |
| - * @var ProductSalableForRequestedQtyInfoInterfaceFactory |
| 21 | + * @var IsProductSalableForRequestedQtyInterface |
29 | 22 | */
|
30 |
| - private $salableForRequestedQtyInfoFactory; |
| 23 | + private $isProductSalableForRequestedQty; |
31 | 24 |
|
32 | 25 | /**
|
33 |
| - * @param IsProductSalableForRequestedQtyInterface $isProductSalableForRequestedQty @deprecated |
34 |
| - * @param ProductSalableForRequestedQtyInfoInterfaceFactory|null $salableForRequestedQtyInfoFactory |
35 |
| - * @param AreProductsSalableForRequestedQtyInterface $areProductsSalableForRequestedQty |
36 |
| - * @SuppressWarnings(PHPMD.UnusedFormalParameter) |
| 26 | + * @param IsProductSalableForRequestedQtyInterface $isProductSalableForRequestedQty |
37 | 27 | */
|
38 | 28 | public function __construct(
|
39 |
| - IsProductSalableForRequestedQtyInterface $isProductSalableForRequestedQty, |
40 |
| - ProductSalableForRequestedQtyInfoInterfaceFactory $salableForRequestedQtyInfoFactory = null, |
41 |
| - AreProductsSalableForRequestedQtyInterface $areProductsSalableForRequestedQty = null |
| 29 | + IsProductSalableForRequestedQtyInterface $isProductSalableForRequestedQty |
42 | 30 | ) {
|
43 |
| - $this->areProductsSalableForRequestedQty = $areProductsSalableForRequestedQty ?: ObjectManager::getInstance() |
44 |
| - ->get(AreProductsSalableForRequestedQtyInterface::class); |
45 |
| - $this->salableForRequestedQtyInfoFactory = $salableForRequestedQtyInfoFactory ?: ObjectManager::getInstance() |
46 |
| - ->get(ProductSalableForRequestedQtyInfoInterfaceFactory::class); |
| 31 | + $this->isProductSalableForRequestedQty = $isProductSalableForRequestedQty; |
47 | 32 | }
|
48 | 33 |
|
49 | 34 | /**
|
50 | 35 | * Check whether all items salable
|
51 | 36 | *
|
52 |
| - * @param array $items ['sku' => 'qty', ...] |
| 37 | + * @param array $items [['sku' => 'qty'], ...] |
53 | 38 | * @param int $stockId
|
54 | 39 | * @return void
|
55 | 40 | * @throws LocalizedException
|
56 | 41 | */
|
57 | 42 | public function execute(array $items, int $stockId): void
|
58 | 43 | {
|
59 |
| - $skuRequests = []; |
60 | 44 | foreach ($items as $sku => $qty) {
|
61 |
| - $skuRequests[] = $this->salableForRequestedQtyInfoFactory->create(['sku' => $sku, 'qty' => $qty]); |
62 |
| - } |
63 |
| - $result = $this->areProductsSalableForRequestedQty->execute($skuRequests, $stockId); |
64 |
| - foreach ($result->getSalable() as $isSalable) { |
| 45 | + /** @var ProductSalableResultInterface $isSalable */ |
| 46 | + $isSalable = $this->isProductSalableForRequestedQty->execute((string)$sku, $stockId, (float)$qty); |
65 | 47 | if (false === $isSalable->isSalable()) {
|
66 | 48 | $errors = $isSalable->getErrors();
|
67 | 49 | /** @var ProductSalabilityErrorInterface $errorMessage */
|
|
0 commit comments