コード例 #1
0
ファイル: Cart.php プロジェクト: sumudinie/hubzero-cms
 /**
  * Get all items in the transaction
  *
  * @param int transaction ID
  * @return array of items in the transaction, false if no items in transaction
  */
 protected static function getTransactionItems($tId)
 {
     $db = App::get('db');
     $sql = "SELECT `sId`, `tiQty`, `tiPrice` FROM `#__cart_transaction_items` ti WHERE ti.`tId` = {$tId}";
     $db->setQuery($sql);
     $db->query();
     if (!$db->getNumRows()) {
         return false;
     }
     $allSkuInfo = $db->loadObjectList('sId');
     $skus = $db->loadColumn();
     include_once JPATH_BASE . DS . 'components' . DS . 'com_storefront' . DS . 'models' . DS . 'Warehouse.php';
     $warehouse = new StorefrontModelWarehouse();
     $skuInfo = $warehouse->getSkusInfo($skus);
     // Update skuInfo with transaction info
     foreach ($skuInfo as $sId => $sku) {
         $transactionInfo = new stdClass();
         $transactionInfo->qty = $allSkuInfo[$sId]->tiQty;
         $transactionInfo->tiPrice = $allSkuInfo[$sId]->tiPrice;
         $skuInfo[$sId]['transactionInfo'] = $transactionInfo;
         unset($transactionInfo);
     }
     if (empty($skuInfo)) {
         return false;
     }
     return $skuInfo;
 }
コード例 #2
0
ファイル: CurrentCart.php プロジェクト: sumudinie/hubzero-cms
 /**
  * Update cart based on current availability (and pricing) and return all items in the cart, update cart's 'lastUpdated' field
  *
  * @param void
  * @return array of items in the cart
  */
 private function getUpdatedItems()
 {
     // Get cart items from the database
     $items = $this->getCartItems();
     $allSkuInfo = $items->allSkuInfo;
     $skus = $items->skus;
     include_once PATH_CORE . DS . 'components' . DS . 'com_storefront' . DS . 'models' . DS . 'Warehouse.php';
     $warehouse = new StorefrontModelWarehouse();
     $skuInfo = $warehouse->getSkusInfo($skus);
     $cartItems = array();
     // Note that some items become unavailable/out of stock or prices may change, need to account for this
     foreach ($allSkuInfo as $sId => $sku) {
         // See if the SKU is available at all
         if (empty($skuInfo[$sId])) {
             // SKU became unavailable, set it as such (there is a difference between unavailable and out of stock)
             $this->markItemUnavailable($sId);
             $this->cart->hasChanges = true;
             continue;
         }
         $inf = $skuInfo[$sId]['info'];
         $cartItems[$sId] = $skuInfo[$sId];
         $updated = false;
         $cartInfo = new stdClass();
         // Check if this item has been already processed by the doItem (i.e. through cart update quantities call)
         if (!empty($sku->crtiOldPrice) && $sku->crtiPrice != $sku->crtiOldPrice) {
             // Set card changed flag
             $this->cart->hasChanges = true;
             // Mark as updated to prevent double updating
             $updated = true;
         }
         // Check if there is enough inventory
         if ($inf->sTrackInventory && $inf->sInventory < $sku->crtiQty && !$updated) {
             if (!$inf->sInventory) {
                 // 'This product is not in stock anymore
                 // remove item, retain value though for changes messaging
                 $this->doItem($sId, 'set', 0, true);
                 $cartInfo->qty = 0;
             } else {
                 // Inventory level dropped for this product, retain value for changes messaging
                 $this->doItem($sId, 'set', $inf->sInventory, true);
                 $cartInfo->qty = $inf->sInventory;
             }
             // Set card changed flag
             $this->cart->hasChanges = true;
             // Mark as updated to prevent double updating
             $updated = true;
         } else {
             $cartInfo->qty = $sku->crtiQty;
         }
         // Check if allowMultiple policy changed
         if (!$inf->sAllowMultiple && $sku->crtiQty > 1 && !$updated) {
             $this->doItem($sId, 'set', 1, true);
             $cartInfo->qty = 1;
             // Set card changed flag
             $this->cart->hasChanges = true;
             // Mark as updated to prevent double updating
             $updated = true;
         }
         // Check if price changed and not yet been updated (through the $this->update call)
         if ($inf->sPrice != $sku->crtiPrice && !$updated) {
             // Product price changed
             $this->doItem($sId, 'sync');
             // Set card changed flag
             $this->cart->hasChanges = true;
         }
         $cartItems[$sId]['info'] = $inf;
         $cartItems[$sId]['cartInfo'] = $cartInfo;
         unset($cartInfo);
     }
     $this->updateSession();
     // update 'lastUpdated
     $sql = "UPDATE `#__cart_carts` SET `crtLastUpdated` = NOW() WHERE `crtId` = {$this->crtId}";
     $this->_db->setQuery($sql);
     $this->_db->query();
     return $cartItems;
 }