2013-05-07 91 views
0

我试图将跟踪像素集成到magento成功页面。为了进行测试,我构建了以下代码,并将其在模板文件夹中的success.phtml文件中的line> 45中实现。实际上变量都是空的。怎么了?magento跟踪像素签出

<?php 
<?php 
$lastOrderId = Mage::getSingleton('checkout/session')->getLastOrderId(); 
$order = Mage::getSingleton('sales/order'); 
$order->load($lastOrderId); 
$skus = array(); 
$qtys = array(); 
$amounts = array(); 
foreach ($order->getAllItems() as $item){ 
$skus[$item->getProductId()] = $item->getSku(); 
$names[$item->getProductId()] = $item->getName(); 
$qtys[$item->getProductId()] = $item->getQtyOrdered() * 1; 
$amounts[$item->getProductId()] = $item->getRowTotal() * 100;//or $item->getPrice()*$item->getQtyOrdered();//but this will ignore any applied coupons 
} 
$skuspipe = implode("|", $skus); 
$namespipe = implode("|", $names); 
$qtyspipe = implode("|", $qtys); 
$amountspipe = implode("|", $amounts); 

<!-- 
OrderID: <?php echo $orderID; ?> 
skus: <?php print_r($skus); ?> 
names: <?php print_r($names); ?> 
qtys: <?php print_r($qtys); ?> 
amounts: <?php print_r($amounts); ?> 
skupipe: <?php echo $skupipe; ?> 
namespipe: <?php echo $namespipe; ?> 
qtyspipe: <?php echo $qtyspipe; ?> 
amountspipe: <?php echo $amountspipe; ?> 
--> 

谢谢!

回答

0

在集合中,Magento通常只会为每个项目加载一种存根数据。

您可以通过在每次迭代使用

$item->load($item->getId()); 

加载整个对象。

此外,尝试首先调试输出集合,以查看是否找到任何项目。