我試圖將轉換跟蹤添加到我的magento商店。我知道我需要添加以下代碼並對其進行自定義,以便magento將與CA共享信息。我需要幫助從magento獲取訂單詳細信息
<script type="text/javascript">
var _caq = _caq || [];
var products = [];
products.push({Sku: 'ProductID', UnitPrice: 'item price here', Quantity: 'quantity here'});
products.push({Sku: 'ProductID', UnitPrice: 'item price here', Quantity: 'quantity here'});
_caq.push(["Order", {OrderId: 'OrderID', Revenue: 'oVal', CurrencyCode: '3 letter currency code here', Products: products}]);
到目前爲止,我一直在嘗試用下面的代碼,以獲得從訂單數據:
<?php $orderId = $this->getOrderId();
$order = Mage::getModel('sales/order')->load($orderId);
$items = $order->getAllItems();
$_grand = $order->getGrandTotal();
$custname = $order->getCustomerName();
$itemcount=count($items);
foreach ($items as $itemId => $item)
{
$sObject2->Item_name__c = $item->getName();
$sObject2->Unit_price__c = $item->getPrice();
$sObject2->Sku__c = $item->getSku();
$sObject2->Quantity__c = $item->getQtyToInvoice();
}
echo $_grand;
echo $custname;
?>
當我嘗試呼應客戶的名稱和總計,我得到了一個空白的總數和來賓的客戶名稱。即使我使$ orderId發生了這樣的命令。
這並沒有什麼幫助。我需要此代碼才能進入成功頁面。我需要它來跟蹤某些廣告系列的轉化次數。 –
這在很多層面都是錯誤的。你不應該直接在Magento中使用SQL查詢。您可以通過使用相應的集合對象和過濾器來實現相同的目的。你不應該使用mysql_函數(請參閱http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php) - 他們打開你的代碼來注入sql注入的可能性。 –
是的,這是錯誤的方式..但如果你想做的事情更快,更容易,那麼這是唯一的方法,如果你正在處理1000年的訂單...與mage.php非常慢 –