/** * Check inventory * * @throws \Doctrine\ORM\OptimisticLockException * * @return boolean */ public function checkInventory() { parent::checkInventory(); $newStatus = $this->getPaymentStatusCode(); $oldStatus = $this->oldPaymentStatus && $this->oldPaymentStatus->getCode() ? $this->oldPaymentStatus->getCode() : ''; $paidStatuses = \XLite\Model\Order\Status\Payment::getPaidStatuses(); if ($newStatus) { $delta = null; if (in_array($newStatus, $paidStatuses) && (!$oldStatus || !in_array($oldStatus, $paidStatuses))) { $delta = 1; } elseif (!in_array($newStatus, $paidStatuses) && $oldStatus && in_array($oldStatus, $paidStatuses)) { $delta = -1; } if (null !== $delta) { foreach ($this->getItems() as $item) { $product = $item->getObject(); if ($product) { $product->setSales($product->getSales() + $delta * $item->getAmount()); } } \XLite\Core\Database::getEM()->flush(); } } }
/** * {@inheritDoc} */ public function checkInventory() { $this->__initializer__ && $this->__initializer__->__invoke($this, 'checkInventory', array()); return parent::checkInventory(); }