Last active
December 27, 2016 09:00
-
-
Save inogo/caa38e6396ce3c5ccbcd13a1413fc493 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// usage: | |
// [[!metrikaPurchase? &orderId=`[[!+fi.orderID]]`]] | |
$orderId = intval($modx->getOption('orderId', $scriptProperties, 0)); | |
$modx->addPackage('shopkeeper', MODX_CORE_PATH . 'components/shopkeeper/model/'); | |
$order = $modx->getObject('SHKorder', $orderId); | |
if ($order == null) { | |
return; | |
} | |
$orderData = $order->toArray(); | |
$products = array(); | |
foreach (unserialize($orderData['content']) as $item) { | |
$products[] = array( | |
'id' => $item['id'], | |
'name' => $item['name'], | |
'quantity' => $item['count'], | |
'price' => $item['price'] | |
); | |
} | |
$contacts = unserialize($orderData['contacts']); | |
$json = array( | |
'order_id' => $orderData['id'], | |
'revenue' => $contacts['payment_price'], | |
'products' => $products | |
); | |
$json = json_encode($json); | |
return "<script>window.ecommOrderData = $json</script>"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment