Trovaprezzi datalayer script after order confirmation

  • Posts: 117
  • Thank you received: 3
8 years 2 weeks ago #252368

-- HikaShop version -- : 2.6.4
-- Joomla version -- : 3.4
-- PHP version -- : 5.5

I need to integrate this code after a product (or a series of products) is confirmed:

<script type="text/javascript" src=" tracking.trovaprezzi.it/javascripts/tracking.min.js " async="true"></script>

<script type="text/javascript">
window._tt = window._tt || [];
window._tt.push({ event: "setAccount", id: /* chiavemerchant */ });
window._tt.push({ event: "setOrderId", order_id: /* idordine */ });
window._tt.push({ event: "setEmail", email: /* emailcliente */ });
window._tt.push({ event: "addItem", sku: /* sku */, product_name: /* nomeprodotto */ });
window._tt.push({ event: "setAmount", amount: /* totalecarrello */ });
window._tt.push({ event: "orderSubmit"});
</script>

Where the string "window._tt.push({ event: "addItem", sku: /* sku */, product_name: /* nomeprodotto */ });" is repeated for each product of the order.
If i have 3 product on order confirmed, i have to generate a string for each of these.

Is it possible to create? Contact us please.

Please Log in or Create an account to join the conversation.

  • Posts: 82683
  • Thank you received: 13337
  • MODERATOR
8 years 2 weeks ago #252372

Hi,

Yes, it's possible to do that. You can edit the file "after_end" via the menu Display>Views in order to add your custom code.

If you need someone to work on that for you, you can contact our partners:
www.hikashop.com/home/our-partners.html

The following user(s) said Thank You: crealiagroup

Please Log in or Create an account to join the conversation.

  • Posts: 117
  • Thank you received: 3
8 years 2 weeks ago #252564

I found a script for virtuemart. Do you think i can use even for hikashop, changing the db fields?

//TPtpi implemntation –Start 
$TPtpi['chiaveMerchant']="yourMerchantKey"; 
$TPtpi['email']=$order['details']['BT']->email; 
$TPtpi['orderid']=$order['details']['BT']->virtuemart_order_id; 
//array of elemets for scrippt -End 
//Printing Script 
echo "<script type=\"text/javascript\" src=\"https://tracking.trovaprezzi.it/javascripts/tracking.min.js\"></script>"; 
echo "<script type=\"text/javascript\">"; 
echo "window._tt = window._tt || [];"; 
echo "window._tt.push({ event: \"setAccount\", id: '". $TPtpi['chiaveMerchant'] ."' });"; 
echo "window._tt.push({ event: \"setOrderId\", order_id: " . $TPtpi['orderid'] . " });"; 
echo "window._tt.push({ event: \"setEmail\", email: '" . $TPtpi['email'] . "' });"; 
foreach( $order['items'] as $p ) { 
$name=str_replace("'", "", $ p->order_item_name); 
        echo "window._tt.push({ event: \"addItem\", sku: '" . $p->order_item_sku . "', product_name: '" . $name . "' });"; } 
echo "window._tt.push({ event: \"orderSubmit\"});"; 
echo "</script>"; 
//TPtpi implemntation -End

Last edit: 8 years 2 weeks ago by nicolas.

Please Log in or Create an account to join the conversation.

  • Posts: 82683
  • Thank you received: 13337
  • MODERATOR
8 years 2 weeks ago #252591

Hi,

If you change all the variables to use HikaShop's then yes.
For example,

$order['details']['BT']->virtuemart_order_id
is $this->order->order_id and
$order['details']['BT']->email
is $this->order->customer->user_email
The variables available in $this->order are listed here:
www.hikashop.com/support/documentation/156

Please Log in or Create an account to join the conversation.

  • Posts: 117
  • Thank you received: 3
8 years 1 week ago #252888

Thanks for reply Nicolas,

I would ask you if the "after_end" view will be always loaded (and user redirected) with every payment method. For example if user pays with PayPal or Credit card, will this page displayed before or after the payment?

This is necessary to execute the script for every transaction.

Please Log in or Create an account to join the conversation.

  • Posts: 12953
  • Thank you received: 1778
8 years 1 week ago #252902

Hello,

The 'after_end' view will only be called after the return of your customer from a payment platform like PayPal (you'll have to make sure that payment methods like PayPal don't have any "Return Url" through your payment methods configuration page).
But the "after_end" view won't be called if you use payment methods like "HikaShop check payment plugin" instead the "check_end" view of the payment plugin will be called.

Please Log in or Create an account to join the conversation.

  • Posts: 117
  • Thank you received: 3
8 years 1 week ago #253008

Maybe we should work on a different way. Maybe a plugin that fires the trigger and generate the script when the order is created (or confirmed and so on...), right?

Please Log in or Create an account to join the conversation.

  • Posts: 12953
  • Thank you received: 1778
8 years 1 week ago #253020

Hello,
Sure, that's a good idea, the solution will be to create a plugin based on the "onAfterOrderCreate" function :
www.hikashop.com/support/documentation/6...l#onAfterOrderCreate

Please Log in or Create an account to join the conversation.

Time to create page: 0.079 seconds
Powered by Kunena Forum