AJAX - 购物车Magento总计和购物车中的物品

时间:2013-08-07 14:29:34

标签: jquery ajax magento

我正在为Magento开发AJAX购物车。

我对扩展程序不感兴趣,因为这个购物车必须是作者制作的,这是非常习惯的。

您能否告诉我获取购物车中的盛大商品总数和商品数量等信息的最佳方式是什么?

以最快和最相关的方式。

我可以创建外部php文件,该文件将从用户的会话中收集此信息,然后是每次用户添加或删除产品时将在标题上显示的AJAX脚本。

我能想到这不是最好的解决方案。

是否有一些API,或者最好的方法是什么?

谢谢,

亚当

1 个答案:

答案 0 :(得分:4)

如果您指的是各种迷你车,我已使用以下代码在多个项目中完成此操作:

<?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();

?>

不确定这是否是处理迷你推车功能的最佳方式,但它在过去对我来说非常有用,并且可以高度自定义。

相关问题