Esempio n. 1
0
 /**
  * Releases locked transaction items back to inventory and marks the transaction status as 'released'
  *
  * @param int Transaction ID
  * @return void
  */
 public static function releaseTransaction($tId)
 {
     $db = App::get('db');
     // Check if the transaction can be released (status is pending)
     // Get info
     $sql = "SELECT t.`tStatus` FROM `#__cart_transactions` t WHERE t.`tId` = {$tId}";
     $db->setQuery($sql);
     $db->query();
     if (!$db->getNumRows()) {
         return false;
     }
     // Get transaction items
     $tItems = self::getTransactionItems($tId);
     /* Go through each item and return the quantity back to inventory if needed */
     require_once JPATH_BASE . DS . 'components' . DS . 'com_storefront' . DS . 'models' . DS . 'Warehouse.php';
     $warehouse = new StorefrontModelWarehouse();
     if (!empty($tItems)) {
         foreach ($tItems as $sId => $itemInfo) {
             $qty = $itemInfo['transactionInfo']->qty;
             $warehouse->updateInventory($sId, $qty, 'add');
         }
     }
     // update status
     self::updateTransactionStatus('released', $tId);
 }
Esempio n. 2
0
 /**
  * Attempts to rebuild a transaction if there is enough inventory and prices have not changed
  *
  * @param void
  * @return bool Success or failure
  */
 private function rebuildTransaction()
 {
     // Go through each item in the transaction and see if it is available in quantity needed and if price has not changed
     $tItems = $this->getTransactionItems($this->cart->tId);
     foreach ($tItems as $item) {
         // Check price
         if ($item['info']->sPrice != $item['transactionInfo']->tiPrice) {
             // price changed
             return false;
         }
         // Check inventory
         if ($item['info']->sInventory < $item['transactionInfo']->qty) {
             // Not enough inventory
             return false;
         }
     }
     // lock transaction items
     include_once PATH_CORE . DS . 'components' . DS . 'com_storefront' . DS . 'models' . DS . 'Warehouse.php';
     $warehouse = new StorefrontModelWarehouse();
     foreach ($tItems as $sId => $item) {
         $warehouse->updateInventory($sId, $item['transactionInfo']->qty, 'subtract');
     }
     parent::updateTransactionStatus('pending', $this->cart->tId);
     return true;
 }