2013-08-07 57 views
1

我正在爲Magento購買AJAX購物車。AJAX - 購物車Magento總計和購物車中的物品

我對擴展程序不感興趣,因爲此購物車必須是作者製作的,這是非常自定義的。

您能告訴我什麼是獲取購物車中的盛大物品總數和物品數量的最佳方式?

以最快和最相關的方式。

我可以創建外部php文件,它將從用戶的會話中收集這些信息,然後每次用戶添加或刪除產品時將AJAX腳本顯示在標題上。

我可以想到這不是最好的解決方案。

有沒有一些API,或者有什麼最好的方法來做到這一點?

<?php 

// gets the current session of the user 
Mage::getSingleton('core/session', array('name'=>'frontend')); 

// loads all the products in the current users cart 
$items = Mage::getSingleton('checkout/session')->getQuote()->getAllVisibleItems(); 

// counts the total number of items in cart 
$totalItems = count($items); 

// you can loop through all the products, and load them to get all attributes 
foreach($items as $item) { 
    $_product = Mage::getModel('catalog/product')->loadByAttribute('sku', $item->getSku()); 
    // display code, etc 
} 


// gets the subtotal of the current cart 
$subTotal = Mage::getModel('checkout/cart')->getQuote()->getSubtotal(); 

?> 

如果沒有把握:

感謝,

亞當

回答

3

如果你指的是各種各樣的微型車,我已經通過使用下面的代碼完成了這個在多個項目這是處理迷你購物車功能的最佳方式,但它在過去對我來說非常有用,而且具有很高的可定製性。

+0

謝謝邁克爾,似乎是不錯的解決方案。所以最好的方法是使用外部PHP腳本實現ajax cart?我的意思是AJAX會從這個外部腳本中獲取值。 –

+0

Adam,我發現這是最簡單的方法,只需要在外部PHP腳本中包含Mage.php文件,並且應該很好。但如果您遇到另一種更有效的方法,我很樂意聽到! – miguelpelota