Jump to content
Sign in to follow this  
SWORDMAN

[Решено] Настройка ценности конверсии на opencart

Recommended Posts

Здравствуйте. 

 

Хочу настроить ценность конверсии в аналитике. Для этого тег гугла нужно разместить в success.tpl:

<!-- Google Code for Заказ - финиш Conversion Page -->
<script type="text/javascript">
/* <![CDATA[ */
var google_conversion_id = 990568976;
var google_conversion_language = "en";
var google_conversion_format = "3";
var google_conversion_color = "ffffff";
var google_conversion_label = "wKoqCLTiyl4QkMSr2AM";


if (<? echo $totalValue ?>) {
		var google_conversion_value = <? echo $totalValue ?>
		var google_conversion_currency = <? echo $currency ?>
	}

var google_conversion_currency = "UAH";
var google_remarketing_only = false;
/* ]]> */
</script>
<script type="text/javascript" src="//www.googleadservices.com/pagead/conversion.js">
</script>
<noscript>
<div style="display:inline;">
<img height="1" width="1" style="border-style:none;" alt="" src="//www.googleadservices.com/pagead/conversion/990568976/?value=<? echo $totalValue ?>&conversion_currency=<? echo $currency ?>label=wKoqCLTiyl4QkMSr2AM&guid=ON&script=0"/>
</div>
</noscript>

Подскажите пожалуйста как в этом файле получить итоговую сумму заказа $totalValue и валюту $currency?

Edited by SWORDMAN

Share this post


Link to post
Share on other sites

Подозреваю, что заполнить в контроллере catalog\controller\checkout\success.php

Share this post


Link to post
Share on other sites

Подозреваю, что заполнить в контроллере catalog\controller\checkout\success.php

Спасибо.

Share this post


Link to post
Share on other sites

Нашел как на англоязычном сайте:

 

success.php

public function index() {

    $this->data['total'] = 0; // <-- NEW LINE

    if (isset($this->session->data['order_id'])) {
        $this->data['total'] = $this->cart->getTotal(); // <-- NEW LINE

        $this->cart->clear();

        unset($this->session->data['shipping_method']);
        unset($this->session->data['shipping_methods']);
        unset($this->session->data['payment_method']);
        unset($this->session->data['payment_methods']);
        unset($this->session->data['guest']);
        unset($this->session->data['comment']);
        unset($this->session->data['order_id']);    
        unset($this->session->data['coupon']);
        unset($this->session->data['reward']);
        unset($this->session->data['voucher']);
        unset($this->session->data['vouchers']);
    }   

    $this->language->load('checkout/success');

success.tpl

<?php echo $total; ?>

Share this post


Link to post
Share on other sites

А валюту получаю уже в success.tpl:

$this->currency->getCode()

Share this post


Link to post
Share on other sites

Но правильнее конечно перечитать  заказ из базы через getOrder, там будет и сумма и валюта. Корзина все таки косвенный показатель, я бы на нее не завязывался.

$this->load->model('account/order');
$order_info = $this->model_account_order->getOrder($this->session->data['order_id']);
Edited by tabook

Share this post


Link to post
Share on other sites

Может, пожалуйста, кто-то подсказать почему лыжи не едут.

Вырезка с success.tpl

Для проверки вывожу значения переменых, они появляются на странице, но во второй части где данные передаются  в GTM, то пишется:  

"<b>Notice</b>: Uninitialized string offset: 0 in <b>/home/ecoevexm/public_html/catalog/view/theme/default/template/common/success.tpl</b> on line <b>51</b>"

 

<?php echo $order_id; ?>
<?php echo $store_name; ?>
<?php echo $order_info["total"]; ?>
<?php echo $order_info["shipping_country"] . ' ' . $order_info["shipping_zone"]; ?>
 
<?php foreach($order_products as $product) {   
echo $product["model"];
echo $product["name"];
echo $product["price"];
echo $product["quantity"];  } ?>
 
<script>
dataLayer=[{
   'transactionId':'<?php echo $order_id; ?>',
   'transactionAffiliation':'<?php echo $store_name; ?>',
   'transactionTotal':'<?php echo $order_info["total"]; ?>',
   'transactionTax':'0',
   'transactionShipping':'0',
   'transactionProducts':[
  <?php foreach($order_products as $product) { ?>    
                 {'sku':'<?php echo $product["model"]; ?>',
                 'name':'<?php echo $product["name"]; ?>',
                 'price':'<?php echo $product["price"]; ?>',
                 'quantity':'<?php echo $product["quantity"]; ?>'},
           <?php } ?>  ]
                                      }];
</script>  
 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
You are posting as a guest. If you have an account, please sign in.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×

Important Information

On our site, cookies are used and personal data is processed to improve the user interface. To find out what and what personal data we are processing, please go to the link. If you click "I agree," it means that you understand and accept all the conditions specified in this Privacy Notice.