// success
$order_id = JRequest::getString('on');
if (!empty($order_id)) {
$db = JFactory::getDBO();
$order_id = addslashes($order_id);
$db->setQuery('SELECT p24.*, ord.order_status, ord.virtuemart_order_id FROM ' . $this->_tablename . ' as p24 JOIN `#__virtuemart_orders` as ord using(virtuemart_order_id) WHERE p24.order_number="' . $order_id . '"');
$payment_db = $db->loadObject();
if(!$payment_db)
return null;
$modelOrder = VmModel::getModel('orders');
$order = $modelOrder->getOrder($payment_db->virtuemart_order_id);
if (!($method = $this->getVmPluginMethod($order['details']['BT']->virtuemart_paymentmethod_id)))
return null;
if ($payment_db->order_status == 'C') {
$ga_script = '';
if (strlen($method->key_ga)) {
$ga_script = $this->generateGoogleAnalyticsTrackingCode($order_id, $order, $method);
}
JFactory::getApplication()->enqueueMessage(JText::_('PLG_PRZLELEWY24_SUCCESS') . $ga_script);
} elseif ($payment_db->order_status == 'X') {
JError::raiseWarning(100, JText::_('PLG_PRZLELEWY24_FAIL'));
JFactory::getApplication()->enqueueMessage(JText::_('PLG_PRZLELEWY24_FAIL'));
} else {
$this->changeOrderStatus($payment_db->virtuemart_order_id, 'I', JText::_('PLG_PRZLELEWY24_WAITING'), $method->mail);
JFactory::getApplication()->enqueueMessage(JText::_('PLG_PRZLELEWY24_WAITING'));
}
}
private function generateGoogleAnalyticsTrackingCode($order_id, $order, $method)
{
$categoryModel = VmModel::getModel('Category');
$currency = $this->getCurrencyCodeById($order['details']['BT']->order_currency, $method);
$shopName = JFactory::getConfig()->get('sitename');
$total = $method->ga_gross_price == 1 ? $order['details']['BT']->order_total : $order['details']['BT']->order_subtotal;
$transaction = <<<HTML
ga('ecommerce:addTransaction', {
'id': '{$order_id}',
'affiliation': '{$shopName}',
'revenue': '{$total}',
'shipping': '{$order['details']['BT']->order_shipment}',
'tax': '{$order['details']['BT']->order_tax}',
'currency': '{$currency}'
});
HTML;
$products = $order['items'];
$items = '';
if (is_array($products)) {
foreach ($products as $product) {
$category = $categoryModel->getCategory($product->virtuemart_category_id);
$productTotal = $method->ga_gross_price == 1 ? $product->product_final_price : $product->product_priceWithoutTax;
$items .= <<<HTML
ga('ecommerce:addItem', {
'id': '{$order_id}',
'name': '{$product->order_item_name}',
'sku': '{$product->order_item_sku}',
'category': '{$category->category_name}',
'price': '{$productTotal}',
'quantity': '{$product->product_quantity}',
'currency': '{$currency}'
});
HTML;
}
}
$ga_script = <<<HTML
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', '{$method->key_ga}', 'auto');
ga('require', 'ecommerce');
{$transaction}
{$items}
ga('ecommerce:send');
</script>
HTML;
return $ga_script;
}
Page created in 0.058 seconds with 13 queries.