14 октября 2020

Отправить данные ecommerce datalayer в prestashop

 <Script type = "text / javascript">

dataLayer = ( {
 'transactionId' : '{literal} {$order_id} {/literal}' ,       
 'transactionTotal' : {literal } { $total_a_payment } {/literal } , 
 'transactionTax' : { literal } { $tax } { /literal } , 
 'transactionShipping' : { literal } { $ expenses_envoice } { /literal 
   } , 
   'transactionProducts' : [ { /literal } { foreach from = $ products 
  item = product name = products } { /literal } 
  {
 'Sku' : '{literal}{$producto.id_product}{/literal}' , 
 'Name' : '{literal}{$producto.name}{/literal}' , 
 'Price' : {  literal } { $ product . Price_wt } { /literal } , 
 'Quantity' : {  literal } { $ product . Quantity } { /literal } 
  } {  Literal} {if $ smarty.foreach.productos.iteration! = $ Products 
  | @count} {literal}, {/ literal } { / if } { /literal }
   {  Literal} {/ foreach } ] , { /literal }
  'Event' : 'transactionComplete' 
   } )
  </ Script>
  { / Literal }
Правим файл controllers/front/OrderConfirmationController.php. Находим function displayOrderConfirmation вставляем код:
$order = new Order($this->id_order);
$currency = new Currency($order->id_currency);
/* added part */
$cart = new Cart($order->id_cart);
$products = $cart->getProducts();
$this->context->smarty->assign(array(
 'order_id'=> $this->id_order,
 'total_a_payment'=> $order->total_paid_tax_incl,
 'expenses_envoice'=> $order->total_shipping_tax_incl,
 'tax'=> ($order->total_paid_tax_incl - $order->total_paid_tax_excl),
 'products' => $products
));
/*end of added*/