簡體   English   中英

Magento付款模塊:將所有物品放入購物車

[英]Magento Payment Module: Getting All Items in Cart

我在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()的后綴,我似乎正確地返回了項目數。

我只想返回一系列商品,但實際上,我需要的只是名稱,價格和數量,因此,如果有另一種返回信息的方法,我可以接受。

我剛才也遇到過同樣的問題。

$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版

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM