magento success page variables

限于喜欢 提交于 2019-12-12 21:22:46

问题


I am trying to capture some magento success page variables to pass to our advertising company.

So far I have got this but the variables are not outputting anything:

<?php 
$items = $order->getItemsCollection();
foreach ($items as $item)
{
    $price="'".$item->getPrice()."', ";
    $qty="'".$item->getQty()."', ";
    $sku="'".$item->getSku()."', ";
}
?>

The data needs to be in the format:

'price1', 'price2', 'price3'
'qty1', 'qty2', 'qty3'
'sku1', 'sku2', 'sku3'

回答1:


Try adding this to Success.phtml

$order = Mage::getModel('sales/order')->loadByIncrementId($this->getOrderId());
$items = $order->getItemsCollection();

$price = $qty = $sku = array();
foreach($items as $item){
  $price[] = $item->getPrice(); 
  $qty[] = $item->getQty();
  $sku[] = $item->getSku();
}

echo "'" . implode("', '", $price) . "'";
echo "'" . implode("', '", $qty) . "'";
echo "'" . implode("', '", $sku) . "'";



回答2:


On your success.phtml page, you can do it:

$order = Mage::getModel('sales/order')->loadByIncrementId($this->getOrderId()); // follow the RS tip.
$items = $order->getItemsCollection();
foreach($items as $item){
    $price = $item->getData('price'); 
    $qty = $item->getData('qty');
    $sku = $item->getData('sku');
}

Gl



来源:https://stackoverflow.com/questions/13229965/magento-success-page-variables

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!