Exemplo n.º 1
0
 /**
  * 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);
     }
 }
Exemplo n.º 2
0
 /**
  * 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;
 }
Exemplo n.º 3
0
 /**
  * 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);
 }
Exemplo n.º 4
0
 /**
  * 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);
 }
Exemplo n.º 6
0
 /**
  * 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);
     }
 }