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

标签 jquery ajax magento

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

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

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

以最快且最相关的方式。

我可以创建外部 php 文件,该文件将从用户的 session 中收集这些信息,然后创建 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();

?>

不确定这是否是处理迷你购物车功能的最佳方式,但它过去对我来说非常有效,并且高度可定制。

关于jquery - AJAX - 购物车 Magento 总计和购物车中的商品,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18106133/

相关文章:

jquery - 如何从 td 中仅删除文本?

javascript - SQL 查询插入值并显示,无需重新加载页面

magento - 允许国家/地区 - 这是什么意思?

mysql 删除语句 --

Magento 2.3.5-p1 由于内容安全策略,前端为空白

javascript - jQuery html() 与其他函数链接时序问题

javascript - 居中和隐藏图像,适合 div 大小

javascript - 按照 SlideDown() 的方式计算元素高度

javascript - 更改 p 标签中单行的颜色,然后将其改回

jquery - 如何从FLASK中的GET请求获取Json对象