/** * Show message about wrong product amount * * @param \XLite\Model\OrderItem $item Order item * * @return void */ protected function processInvalidAmountError(\XLite\Model\OrderItem $item) { \XLite\Core\TopMessage::addWarning('You tried to buy more items of "{{product}}" product {{description}} than are in stock. We have {{amount}} item(s) only. Please adjust the product quantity.', array('product' => $item->getProduct()->getName(), 'description' => $item->getExtendedDescription(), 'amount' => $item->getProductAvailableAmount())); }
/** * Return false if order item amount exceeds maximum allowed value * * @param \XLite\Model\OrderItem $entity Order item entity * * @return boolean */ protected function isItemHasWrongAmount($entity) { $oldAmount = $this->orderItemsData[$entity->getItemId()]['amount']; $maxAmount = $entity->getProductAvailableAmount(); return $oldAmount + $maxAmount < $entity->getAmount(); }
/** * Get available amount for the product * * @return integer */ public function getProductAvailableAmount() { return $this->getVariant() && !$this->getVariant()->getDefaultAmount() ? $this->getVariant()->getAvailableAmount() : parent::getProductAvailableAmount(); }
/** * Assemble recalculate item event * * @param \XLite\Model\OrderItem $item Order item * * @return array */ protected function assembleRecalculateItemEvent(\XLite\Model\OrderItem $item) { $maxAmount = $item->getProductAvailableAmount(); if ($item->isPersistent() && \XLite\Core\Request::getInstance()->oldAmount) { $maxAmount += \XLite\Core\Request::getInstance()->oldAmount; \XLite\Core\Request::getInstance()->oldAmount = null; } return array('item_id' => $item->getItemId(), 'requestId' => \XLite\Core\Request::getInstance()->requestId, 'price' => $item->getNetPrice(), 'max_qty' => $maxAmount); }
/** * {@inheritDoc} */ public function getProductAvailableAmount() { $this->__initializer__ && $this->__initializer__->__invoke($this, 'getProductAvailableAmount', array()); return parent::getProductAvailableAmount(); }