Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CheckItemsQuantity.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
14 
16 {
20  private $isProductSalableForRequestedQty;
21 
25  public function __construct(
26  IsProductSalableForRequestedQtyInterface $isProductSalableForRequestedQty
27  ) {
28  $this->isProductSalableForRequestedQty = $isProductSalableForRequestedQty;
29  }
30 
39  public function execute(array $items, int $stockId) : void
40  {
41  foreach ($items as $sku => $qty) {
43  $isSalable = $this->isProductSalableForRequestedQty->execute((string)$sku, $stockId, (float)$qty);
44  if (false === $isSalable->isSalable()) {
45  $errors = $isSalable->getErrors();
47  $errorMessage = array_pop($errors);
48  throw new LocalizedException(__($errorMessage->getMessage()));
49  }
50  }
51  }
52 }
__()
Definition: __.php:13
__construct(IsProductSalableForRequestedQtyInterface $isProductSalableForRequestedQty)
$errors
Definition: overview.phtml:9
$items