コード例 #1
0
 /**
  * @param StockItemInterface $stockItem
  * @param float|int $qty
  * @return \Magento\Framework\DataObject
  */
 public function checkQtyIncrements(StockItemInterface $stockItem, $qty)
 {
     $result = new \Magento\Framework\DataObject();
     if ($stockItem->getSuppressCheckQtyIncrements()) {
         return $result;
     }
     $qtyIncrements = $stockItem->getQtyIncrements() * 1;
     if ($qtyIncrements && $this->mathDivision->getExactDivision($qty, $qtyIncrements) != 0) {
         $result->setHasError(true)->setQuoteMessage(__('Please correct the quantity for some products.'))->setErrorCode('qty_increments')->setQuoteMessageIndex('qty');
         if ($stockItem->getIsChildItem()) {
             $result->setMessage(__('You can buy %1 only in quantities of %2 at a time.', $stockItem->getProductName(), $qtyIncrements));
         } else {
             $result->setMessage(__('You can buy this product only in quantities of %1 at a time.', $qtyIncrements));
         }
     }
     return $result;
 }