/** * Sync amount in stock with remaining pin codes * * @return void */ public function syncAmount() { $remaining = $this->getProduct()->getRemainingPinCodesCount(); if (parent::getAmount() !== $remaining) { $this->setAmount($remaining); \XLite\Core\Database::getEM()->persist($this); } }
/** * Check if product can be purchased * * @return boolean */ public function isOutOfStock() { $result = parent::isOutOfStock(); if (!$result) { $membership = \XLite::getController() instanceof \XLite\Controller\ACustomer ? \XLite::getController()->getCart()->getProfile()->getMembership() : null; $result = $this->getAvailableAmount() < $this->getProduct()->getMinQuantity($membership); } return $result; }
/** * Check if we need to register the record concerning the product inventory change * * @param \XLite\Model\Inventory $inventory * @param integer $delta * * @return boolean */ protected function isAbleToReduceAmount(\XLite\Model\Inventory $inventory, $delta) { // Do record if the product is reserved and we have enough amount in stock for it return $inventory->getPublicAmount() > abs($delta); }
/** * Get inventory * * @return \XLite\Model\Inventory */ public function getInventory() { if (null === $this->inventory) { $this->inventory = new \XLite\Model\Inventory(); $this->inventory->setProduct($this); } return $this->inventory; }
/** * {@inheritDoc} */ public function prepareEntityBeforeCommit($type) { $this->__initializer__ && $this->__initializer__->__invoke($this, 'prepareEntityBeforeCommit', array($type)); return parent::prepareEntityBeforeCommit($type); }
/** * Increase / decrease product inventory amount * * @param integer $delta Amount delta * * @return void */ public function changeAmount($delta) { if (!$this->getProduct() || !$this->getProduct()->hasManualPinCodes()) { parent::changeAmount($delta); } }