Advertisement
Guest User

Untitled

a guest
Jun 25th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. <?php
  2. // Function to return the JavaScript representation of a TransactionData object.
  3. function getTransactionJs($transId,$subtotal,$shipping,$tax) {
  4. return <<<HTML
  5.  
  6. 'transaction_id': '{$transId}',
  7. 'affiliation': 'Model1',
  8. 'value': '{$subtotal}',
  9. 'currency': 'PLN',
  10. 'tax': '{$tax}'
  11. 'shipping': '{$shipping}',
  12. HTML;
  13. }
  14.  
  15. // Function to return the JavaScript representation of an ItemData object.
  16. function getItemJs($transId, $items) {
  17. return <<<HTML
  18. {
  19. 'id': '{$items->getItemId()}',
  20. 'name': '{$items['name']}',
  21. 'sku': '{$items['sku']}',
  22. 'category': '{$items['category']}',
  23. 'quantity': '{$items->getQtyOrdered()}'
  24. 'price': '{$items->getPriceInclTax()}',
  25. },
  26. HTML;
  27. }
  28. ?>
  29.  
  30. <!-- Begin HTML -->
  31. <script type="text/javascript">
  32. gtag('event', 'purchase', {
  33. <?php
  34. echo getTransactionJs($block->getOrderId(),round($order->getGrandTotal(),2)-round($order->getShippingAmount(),2),round($order->getShippingAmount(),2), round($order->getGrandTotal(),2)-round($order->getSubTotal(),2));
  35. ?>
  36. "items": [
  37. <?php
  38. foreach ($orderItems as $item) {
  39. echo getItemJs($block->getOrderId(), $item);
  40. }
  41. ?>
  42. ]
  43.  
  44. });
  45.  
  46. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement