Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Function to return the JavaScript representation of a TransactionData object.
- function getTransactionJs($transId,$subtotal,$shipping,$tax) {
- return <<<HTML
- 'transaction_id': '{$transId}',
- 'affiliation': 'Model1',
- 'value': '{$subtotal}',
- 'currency': 'PLN',
- 'tax': '{$tax}'
- 'shipping': '{$shipping}',
- HTML;
- }
- // Function to return the JavaScript representation of an ItemData object.
- function getItemJs($transId, $items) {
- return <<<HTML
- {
- 'id': '{$items->getItemId()}',
- 'name': '{$items['name']}',
- 'sku': '{$items['sku']}',
- 'category': '{$items['category']}',
- 'quantity': '{$items->getQtyOrdered()}'
- 'price': '{$items->getPriceInclTax()}',
- },
- HTML;
- }
- ?>
- <!-- Begin HTML -->
- <script type="text/javascript">
- gtag('event', 'purchase', {
- <?php
- echo getTransactionJs($block->getOrderId(),round($order->getGrandTotal(),2)-round($order->getShippingAmount(),2),round($order->getShippingAmount(),2), round($order->getGrandTotal(),2)-round($order->getSubTotal(),2));
- ?>
- "items": [
- <?php
- foreach ($orderItems as $item) {
- echo getItemJs($block->getOrderId(), $item);
- }
- ?>
- ]
- });
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement