Advertisement
Guest User

Untitled

a guest
Sep 4th, 2015
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. <?php
  2. // Transaction Data
  3. $orderID = $this->getOrderId();
  4. $order = Mage::getModel('sales/order')->loadByIncrementId($orderID);
  5. $orderTotal = $order->getGrandTotal();
  6. // you can also add affiliation, shipping and tax
  7. $trans = array('id' => $orderID,
  8. 'revenue' => $orderTotal);
  9.  
  10. // List of Items Purchased
  11. $items = array();
  12. foreach ($order->getAllItems() as $item){
  13. // you can also add SKU and category
  14. $items[] = array('name' => $item->getName(),
  15. 'price' => $item->getPrice(),
  16. 'quantity' => $item->getQtyOrdered(),
  17. 'sku' => $item->getSku());
  18. }
  19.  
  20.  
  21. // Function to return the JavaScript representation of a TransactionData object.
  22. function getTransactionJs(&$trans) {
  23. return <<<HTML
  24. ga('ecommerce:addTransaction', {
  25. 'id': '{$trans['id']}',
  26. // if you added affiliation, shipping or tax above, include them here as well
  27. 'revenue': '{$trans['revenue']}'
  28. });
  29. HTML;
  30. }
  31.  
  32. // Function to return the JavaScript representation of an ItemData object.
  33. function getItemJs(&$transId, &$item) {
  34. return <<<HTML
  35. ga('ecommerce:addItem', {
  36. 'id': '$transId',
  37. // if you added SKU or category above, include them here as well
  38. 'name': '{$item['name']}',
  39. 'price': '{$item['price']}',
  40. 'quantity': '{$item['quantity']}',
  41. 'sku' : '{$item['sku']}'
  42. });
  43. HTML;
  44. }
  45. ?>
  46.  
  47. <script>
  48. ga('require', 'ecommerce', 'ecommerce.js');
  49.  
  50. <?php
  51. echo getTransactionJs($trans);
  52.  
  53. foreach ($items as &$item) {
  54. echo getItemJs($trans['id'], $item);
  55. }
  56. ?>
  57.  
  58. ga('ecommerce:send');
  59. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement