Magento:在成功页面上获取购物车信息

标签 magento

我需要你帮助解决我的 magento 问题。我有一个成功页面的跟踪代码来跟踪订单。这是我的跟踪代码:

<script language="javascript" type="text/javascript">
(function(){
var properties = {};
properties.billing_orderid      = 'PLEASE ADD A UNIQUE ORDER ID'; // this id must be unique otherwise we will count the conversion only once
properties.billing_address      = 'NULL'; // if needed
properties.billing_customerid   = 'NULL'; // if needed
properties.billing_sum          = 'ADD BASKET VALUE HERE, ONLY . SIGN ALLOWED';

// each line represents a product, please add neccassary line for each product and put the right values into it
properties.ec_Event=[
 // Syntax: Action, ProductID, Name, Price, Category, Number of Items, NULL, NULL, NULL
 // please avoid any ' sign in each value especially in the product name or make the right javascript quoting by using \' instead of single '
 ['buy' /* stay fix */ 'YOUR PRODUCT ID', 'PRODUCT NAME', 'PRICE', 'CATEGORY', NUMER OF ITEMS, 'NULL' /* stay fix */, 'NULL' /* stay fix */, 'NULL' /* stay fix */],
 ['buy', 'ABC123', 'Nike shoe ', '50.00', 'shoes/nike', 2,'NULL', 'NULL', 'NULL']];
A3320.trackEvent(properties);
})();
</script>

我知道如何获得总价:

$total = sprintf("%1\$.2f",$grandTotal);

但我不知道如何获取产品列表。你们有人给我建议吗?

非常感谢!

来自德国的问候, 莱西斯

最佳答案

在成功页面您可以访问订单ID:$this->getOrderId();

然后加载您的订单并循环订单项以获取产品:

$_order = Mage::getModel('sales/order')->loadByIncrementId($this->getOrderId());
foreach ($_order->getAllItems() as $item) {
// do stuff with the item or optionally load them to get full product.
}

PS:您可以按SKU加载,也可以按ID加载:$product = Mage::getModel('catalog/product')->loadByAttribute$product = Mage::getModel('catalog/product')->load(<productID>)

关于Magento:在成功页面上获取购物车信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14375873/

相关文章:

php - 从 magento 表结构获取客户信息

php - 翻译如何在 magento 中工作

templates - Magento cms 页面渲染 {{ }} 变量

php - 无法在 Wordpress 中访问 Magento session

xml - 如何在我的 local.xml 中更改 Magento 每页的默认网格?

php - Magento 添加到愿望 list 代码不起作用

Magento - 如何在观察者保存后获取新创建的贷项凭证的 ID?

Magento 在 Topmenu.php 中获取类别属性值

magento - 如何更改magento中产品的显示顺序

php - 跟踪 Google Analytics 目标中的表单输入