6 declare(strict_types=1);
27 private $getProductSalableQty;
32 private $getSkusByProductIds;
37 private $stockResolver;
42 private $storeManager;
47 private $getStockItemConfiguration;
64 $this->getProductSalableQty = $getProductSalableQty;
65 $this->getSkusByProductIds = $getSkusByProductIds;
66 $this->stockResolver = $stockResolver;
68 $this->getStockItemConfiguration = $getStockItemConfiguration;
96 $websiteCode = $this->storeManager->getWebsite()->getCode();
98 $stockId = (int)
$stock->getStockId();
100 $stockItemConfiguration = $this->getStockItemConfiguration->execute($productSku, $stockId);
101 $qtyIncrements = $stockItemConfiguration->getQtyIncrements();
103 if ($qty <= 0 || $stockItemConfiguration->isManageStock() ===
false || $qtyIncrements < 2) {
107 $minQty = max($stockItemConfiguration->getMinSaleQty(), $qtyIncrements);
108 $divisibleMin = ceil($minQty / $qtyIncrements) * $qtyIncrements;
110 $this->getProductSalableQty->execute($productSku, $stockId),
111 $stockItemConfiguration->getMaxSaleQty()
113 $divisibleMax = floor($maxQty / $qtyIncrements) * $qtyIncrements;
115 if ($qty < $minQty || $qty > $maxQty || $divisibleMin > $divisibleMax) {
119 $closestDivisibleLeft = floor($qty / $qtyIncrements) * $qtyIncrements;
120 $closestDivisibleRight = $closestDivisibleLeft + $qtyIncrements;
121 $acceptableLeft = min(max($divisibleMin, $closestDivisibleLeft), $divisibleMax);
122 $acceptableRight = max(min($divisibleMax, $closestDivisibleRight), $divisibleMin);
124 return abs($acceptableLeft - $qty) < abs($acceptableRight - $qty) ? $acceptableLeft : $acceptableRight;
foreach($websiteCodes as $websiteCode) $skus
__construct(GetProductSalableQtyInterface $getProductSalableQty, GetSkusByProductIdsInterface $getSkusByProductIds, StockResolverInterface $stockResolver, StoreManagerInterface $storeManager, GetStockItemConfigurationInterface $getStockItemConfiguration)
if(!isset($_GET['website_code'])) $websiteCode
aroundSuggestQty(StockStateInterface $subject, \Closure $proceed, $productId, $qty, $scopeId=null)