【问题标题】:Magento Payment Module: Getting All Items in CartMagento 支付模块:获取购物车中的所有商品
【发布时间】:2014-03-03 04:53:18
【问题描述】:

我正在 Magento 1.8 上创建支付网关模块
在我的模型代码中,我试图以正确的格式构建一个字符串,为 SOAP 请求做好准备。

我需要收集订单产品,我正在使用以下代码:

$order_string = "";
$quote = Mage::getSingleton('checkout/session')->getQuote();
$items = $quote->getAllVisibleItems();
foreach ($items as $item) {
    $order_string .= "prod=" . $item->getName() . ",item_amount=" . $item->getPrice() . 'x' . $item->getQty() . ';';
}

我面临的问题是$items 变量始终为空。 我已经尝试了多种获取此信息的方法:

$items = Mage::getSingleton('checkout/cart')->getAllItems();
$items = Mage::helper('checkout/cart')->getAllItems();
$items = Mage::helper('checkout/cart')->getCart()->getAllItems();
$items = Mage::getSingleton('checkout/session')->getQuote()->getAllItems();

等等

如果我尝试Mage::log 任何此类信息,我将面临错误:

User Error: Some transactions have not been committed or rolled back  in /Users/[Username]/Sites/[Site Name]/lib/Varien/Db/Adapter/Pdo/Mysql.php on line 3865

如果我使用->getItemsCount(); 作为后缀而不是getAllItems()getAllVisibleItems(),我似乎正确地返回了项目数。

我只想返回一组商品,但实际上,我只需要名称、价格和数量,所以如果有其他方法可以返回该信息,我愿意接受。

【问题讨论】:

    标签: php magento payment-gateway


    【解决方案1】:

    我刚才也遇到了同样的问题。

    $cartItems = Mage::getSingleton('checkout/session')->getQuote()->getAllItems();
    foreach ($cartItems as $item) {
        echo Mage::getModel('catalog/product')->load($item->getProduct()->getId())->getShortDescription();
        echo $item->getPrice();
        echo $item->getSku();
        echo $item->getQty();
    }
    

    发现于: http://www.kathirvel.com/magento-custom-attributes-of-products-in-the-cart/

    如果不起作用,那么是您的事件让您失望了。如果您通过控制器运行它,则可以完美运行。

    使用 Magento 社区版本 1.9.0.1

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-18
      • 2019-12-09
      • 1970-01-01
      • 2015-06-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多