Skip to content

Instantly share code, notes, and snippets.

@inogo
Last active December 27, 2016 09:00
Show Gist options
  • Save inogo/caa38e6396ce3c5ccbcd13a1413fc493 to your computer and use it in GitHub Desktop.
Save inogo/caa38e6396ce3c5ccbcd13a1413fc493 to your computer and use it in GitHub Desktop.
<?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