问题
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