Хочу сделать простенький модификатор для отправки конверсий и их ценности в Google Ads.
Возможно это будет первый модификатор который я бесплатно выложу здесь.
Код собрал по частям. Есть больше сомнения что все сделал верно и вообще будет ли он корректно работать.
1.success.php(вторая операция) делал по аналогии с OC2x
2.success.twig переводил из php не уверен правильно ли сделал
Буду очень благодарен за подсказки и исправления.
<?xml version="1.0" encoding="utf-8"?>
<modification>
<name>Google conversion</name>
<code>order-id-google-conversion</code>
<version>1.0.0</version>
<author>Vandeko</author>
<link>https://192.168.0.1</link>
<file path="/catalog/controller/checkout/success.php">
<operation>
<search>
<![CDATA[
if (isset($this->session->data['order_id'])) {
]]>
</search>
<add position="after">
<![CDATA[
$this->load->model('account/order');
$this->data['order_id'] = $this->session->data['order_id'];
$this->data['order_info'] = $this->model_account_order->getOrder($this->session->data['order_id']);
$this->data['order_totals'] = $this->model_account_order->getOrderTotals($this->session->data['order_id']);
$this->data['order_products'] = $this->model_account_order->getOrderProducts($this->session->data['order_id']);
$shipping = 0;
foreach ($this->data['order_totals'] as $row)
{
if ($row['code'] == 'shipping')
{
$shipping = $row['value'];
}
}
$this->data['shipping'] = $shipping;
$tax = 0;
foreach ($this->data['order_products'] as $row)
{
$tax = $tax + $row['tax'];
}
$this->data['tax'] = $tax;
$this->cart->clear();
]]>
</add>
</operation>
<operation>
<search>
<![CDATA[
if ($this->customer->isLogged()) {
$data['text_message'] = sprintf($this->language->get('text_customer'), $this->url->link('account/account', '', true), $this->url->link('account/order', '', true), $this->url->link('account/download', '', true), $this->url->link('information/contact'));
} else {
$data['text_message'] = sprintf($this->language->get('text_guest'), $this->url->link('information/contact'));
}
]]>
</search>
<add position="replace">
<![CDATA[
if ($this->customer->isLogged()) {
$data['text_message'] = sprintf($this->language->get('text_customer'),
$this->language->get('order_info'),
$this->url->link('account/account', '', true),
$this->url->link('account/order', '', true),
$this->url->link('account/download', '', true),
$this->url->link('information/contact'));
} else {
$data['text_message'] = sprintf($this->language->get('text_guest'),
$this->language->get('order_info'),
$this->url->link('information/contact'));
}
]]>
</add>
</operation>
</file>
<file path="/catalog/language/ru-ru/checkout/success.php">
<operation>
<search>
<![CDATA[
$_['text_success'] = 'Заказ принят';
]]>
</search>
<add position="after">
<![CDATA[
$_['order_info'] = 'Номер вашего заказа:';
]]>
</add>
</operation>
</file>
<file path="/catalog/language/uk-ua/checkout/success.php">
<operation>
<search>
<![CDATA[
$_['text_success'] = 'Замовлення прийнято';
]]>
</search>
<add position="after">
<![CDATA[
$_['order_info'] = 'Номер вашого замовлення:';
]]>
</add>
</operation>
</file>
<file path="/catalog/view/theme/tt_sharma1/template/common/success.twig">
<operation>
<search>
<![CDATA[
{{ text_message }}
]]>
</search>
<add position="replace">
<![CDATA[
<p>{{ order_info }} {{ order_id }}</p>{{ text_message }}
]]>
</add>
</operation>
<operation>
<search>
<![CDATA[
{{ footer }}
]]>
</search>
<add position="after">
<![CDATA[
{% if order_id is defined %}
<!-- Google Analytics - Ecommerce Tracking (Universal Analytics) -->
<script type="text/javascript">
gtag('event', 'purchase', {
"transaction_id": {{ order_id }},
"affiliation": {{ order_info.store_name }},
"value": {{ order_info.total }},
"currency": {{ order_info.currency_code }},
"tax": {{ tax }},
"shipping": {{ shipping }},
"items": [
{% for row in order_products %}
"id": {{ row.model }},
"name": {{ row.name }},
"quantity": {{ row.quantity }},
"price": {{ row.price }}
{% endfor %}
]
});
</script>
<!-- End Google Analytics - Ecommerce Tracking (Universal Analytics) -->
<!-- Event snippet for Покупка товара conversion page -->
<script>
gtag('event', 'conversion', {
'send_to': 'Ваше из гугладвордса',
'value': {{ order_info.total }},
'currency': {{ order_info.currency_code }},
'transaction_id': {{ order_id }}
});
</script>
]]>
</add>
</operation>
</file>
</modification>