9 use Magento\Catalog\Model\ProductFactory;
105 $result = $this->objectFactory->create();
115 $result->setHasQtyOptionUpdate(
true);
122 $origQty = intval($origQty);
128 ->setMessage(
__(
'The fewest you may purchase is %1.',
$stockItem->getMinSaleQty() * 1))
129 ->setErrorCode(
'qty_min')
130 ->setQuoteMessage(
__(
'Please correct the quantity for some products.'))
131 ->setQuoteMessageIndex(
'qty');
137 ->setMessage(
__(
'The most you may purchase is %1.',
$stockItem->getMaxSaleQty() * 1))
138 ->setErrorCode(
'qty_max')
139 ->setQuoteMessage(
__(
'Please correct the quantity for some products.'))
140 ->setQuoteMessageIndex(
'qty');
155 ->setMessage(
__(
'This product is out of stock.'))
156 ->setQuoteMessage(
__(
'Some of the products are out of stock.'))
157 ->setQuoteMessageIndex(
'stock');
158 $result->setItemUseOldQty(
true);
162 if (!$this->
checkQty($stockItem, $summaryQty) || !$this->
checkQty($stockItem, $qty)) {
163 $message =
__(
'The requested qty is not available');
171 if ($backOrderQty > $qty) {
172 $backOrderQty = $qty;
175 $result->setItemBackorders($backOrderQty);
177 $orderedItems = (int)
$stockItem->getOrderedItems();
180 $qtyAvailable = (
$stockItem->getQty() - ($summaryQty - $qty)) * 1;
181 if ($qtyAvailable > 0) {
182 $backOrderQty = $qty * 1 - $qtyAvailable;
184 $backOrderQty = $qty * 1;
187 if ($backOrderQty > 0) {
188 $result->setItemBackorders($backOrderQty);
190 $stockItem->setOrderedItems($orderedItems + $qty);
197 'We don\'t have as many "%1" as you requested, ' 198 .
'but we\'ll back order the remaining %2.',
206 'We don\'t have "%1" in the requested quantity, ' 207 .
'so we\'ll back order the remaining %2.',
215 __(
'The requested qty is not available')
238 if (!$this->qtyCheckApplicable) {
246 case \Magento\CatalogInventory\Model\Stock::BACKORDERS_YES_NONOTIFY:
247 case \Magento\CatalogInventory\Model\Stock::BACKORDERS_YES_NOTIFY:
267 if ($qty <= 0 || !$stockItem->getManageStock()) {
271 $qtyIncrements = (int)
$stockItem->getQtyIncrements();
273 if ($qtyIncrements < 2) {
277 $minQty = max(
$stockItem->getMinSaleQty(), $qtyIncrements);
278 $divisibleMin = ceil($minQty / $qtyIncrements) * $qtyIncrements;
281 $divisibleMax = floor($maxQty / $qtyIncrements) * $qtyIncrements;
283 if ($qty < $minQty || $qty > $maxQty || $divisibleMin > $divisibleMax) {
289 $closestDivisibleLeft = floor($qty / $qtyIncrements) * $qtyIncrements;
290 $closestDivisibleRight = $closestDivisibleLeft + $qtyIncrements;
291 $acceptableLeft = min(max($divisibleMin, $closestDivisibleLeft), $divisibleMax);
292 $acceptableRight = max(min($divisibleMax, $closestDivisibleRight), $divisibleMin);
293 return abs($acceptableLeft - $qty) < abs($acceptableRight - $qty) ? $acceptableLeft : $acceptableRight;
303 $result = new \Magento\Framework\DataObject();
304 if (
$stockItem->getSuppressCheckQtyIncrements()) {
308 $qtyIncrements =
$stockItem->getQtyIncrements() * 1;
310 if ($qtyIncrements && $this->mathDivision->getExactDivision($qty, $qtyIncrements) != 0) {
312 ->setQuoteMessage(
__(
'Please correct the quantity for some products.'))
313 ->setErrorCode(
'qty_increments')
314 ->setQuoteMessageIndex(
'qty');
318 'You can buy %1 only in quantities of %2 at a time.',
324 $result->setMessage(
__(
'You can buy this product only in quantities of %1 at a time.', $qtyIncrements));
342 $product = $this->productFactory->create();
349 $productsByGroups =
$product->getTypeInstance()->getProductsToPurchaseByReqGroups(
$product);
350 foreach ($productsByGroups as $productsInGroup) {
355 if (
null === $stockQty || $qty < $stockQty) {
360 $stockQty = (float)$stockQty;
361 if ($stockQty < 0 || !$stockItem->getManageStock() || !
$stockItem->getIsInStock()
368 return (
float)
$stockItem->getData(
'stock_qty');
377 if (!is_numeric($qty)) {
378 $qty = $this->localeFormat->getNumber($qty);
elseif(isset( $params[ 'redirect_parent']))
checkQuoteItemQty(StockItemInterface $stockItem, $qty, $summaryQty, $origQty=0)
suggestQty(StockItemInterface $stockItem, $qty)
verifyNotification(StockItemInterface $stockItem)
verifyStock(StockItemInterface $stockItem)
const BACKORDERS_YES_NOTIFY
getStockQty(StockItemInterface $stockItem)
checkQty(StockItemInterface $stockItem, $qty)
__construct(MathDivision $mathDivision, FormatInterface $localeFormat, ObjectFactory $objectFactory, ProductFactory $productFactory, $qtyCheckApplicable=true)
checkQtyIncrements(StockItemInterface $stockItem, $qty)