MattR Posted October 23, 2020 Posted October 23, 2020 As I'm a kindergarten level coder, could someone let me know if there are any mistakes in the tags I've added to the AWIN code which I guess should be inserted in order-confirmation.tpl? {literal} <!—Image Pixel - Mandatory --> <img src="https://www.awin1.com/sread.img?tt=ns&tv=2&merchant={{advertiserId}}&amount={{order_subtotal}}&cr={{currency_code}}&ref={{order_ref}}&parts=DEFAULT:{{sale_amount}}&vc={{voucher_code}}&ch=aw&testmode=0" border="0" width="0" height="0"> <!-- JavaScript Tracking - Mandatory --> <script type="text/javascript"> //<![CDATA[ /*** Do not change ***/ var AWIN = {}; AWIN.Tracking = {}; AWIN.Tracking.Sale = {}; /*** Set your transaction parameters ***/ AWIN.Tracking.Sale.amount = "<?php echo $getOrderTotal>"; AWIN.Tracking.Sale.orderRef = "<?php echo $id_order>"; AWIN.Tracking.Sale.parts = "DEFAULT:<?php echo $getOrderTotal>"; AWIN.Tracking.Sale.voucher = "<?php echo $getOrderedCartRulesIds>"; AWIN.Tracking.Sale.currency = "<?php echo $isoCodeNum>"; AWIN.Tracking.Sale.test = "0"; AWIN.Tracking.Sale.channel = "aw"; //]]> </script> {/literal}
yaniv14 Posted October 23, 2020 Posted October 23, 2020 Hi, You cannot use php code like you put. Smarty has {php} tag for that, but I think its deprecated and anyway its not recommended. What you have in your code is javascript and you should use only available javascript variables that are coming from the controller (server side). if you look at this you will see all variables that are injected to your template from the controller. So you can use it like that: AWIN.Tracking.Sale.amount = total_paid_tax_incl; if you need additional data that is not presented by the controller you can create your own override of the controller initContent() function. also keep in mind that this controller template will only loads if payment module configure proper usage of payment return and/or redirect success payment to order-confirmation page. Good luck
MattR Posted October 23, 2020 Author Posted October 23, 2020 (edited) Thanks Yaniv! Is this okay? 😬 <!—Image Pixel - Mandatory --> <img src="https://www.awin1.com/sread.img?tt=ns&tv=2&merchant=00000&amount=total_paid_tax_incl&cr=isoCodeNum&ref=id_order&parts=DEFAULT:total_paid_tax_incl&vc=getOrderedCartRulesIds&ch=aw&testmode=0" border="0" width="0" height="0"> <!-- JavaScript Tracking - Mandatory --> <script type="text/javascript"> //<![CDATA[ /*** Do not change ***/ var AWIN = {}; AWIN.Tracking = {}; AWIN.Tracking.Sale = {}; /*** Set your transaction parameters ***/ AWIN.Tracking.Sale.amount = total_paid_tax_incl; AWIN.Tracking.Sale.orderRef = id_order; AWIN.Tracking.Sale.parts = DEFAULT: total_paid_tax_incl; AWIN.Tracking.Sale.voucher = getOrderedCartRulesIds; AWIN.Tracking.Sale.currency = isoCodeNum; AWIN.Tracking.Sale.test = "0"; AWIN.Tracking.Sale.channel = "aw"; //]]> </script> Edited October 23, 2020 by MattR
yaniv14 Posted October 23, 2020 Posted October 23, 2020 this line probably wont work: AWIN.Tracking.Sale.parts = DEFAULT: total_paid_tax_incl; you can try: AWIN.Tracking.Sale.parts = `DEFAULT: ${total_paid_tax_incl}`; also this line should not be inside {literal} tag and it should be like that. <img src="https://www.awin1.com/sread.img?tt=ns&tv=2&merchant=00000&amount={$order->total_paid_tax_incl}&cr={#isoCodeNum#}&ref={$order->id_order}&parts=DEFAULT:{$order->total_paid_tax_incl}&vc={#getOrderedCartRulesIds#}&ch=aw&testmode=0" border="0" width="0" height="0"> some variables as you can see are not available without overriding the controller so you need to create your override and add them like for currency iso code you can do something like $currency = new Currency($order->id_currency); $iso_core = $currency->iso_code;
MattR Posted October 23, 2020 Author Posted October 23, 2020 This is really stretching my elementary knowledge 😂 So this is where I'm at. I added - currency.iso_code; into the Custom code, "add extra JS to the order confirmation page section" So hopefully that will take care of that? Unfortunately vouchers used isn't an available variable. The voucher codes used - do you mean I need to add a few lines to OrderConfirmationController.php to get the vouchers used? Thanks for your help, it's really appreciated! <!—Image Pixel - Mandatory --> <img src="https://www.awin1.com/sread.img?tt=ns&tv=2&merchant=00000&amount={$order->total_paid_tax_incl}&cr={currency.iso_code}&ref={$order->id_order}&parts=DEFAULT:{$order->total_paid_tax_incl}&vc={#getOrderedCartRulesIds#}&ch=aw&testmode=0" border="0" width="0" height="0"> <!-- JavaScript Tracking - Mandatory --> {literal} <script type="text/javascript"> //<![CDATA[ /*** Do not change ***/ var AWIN = {}; AWIN.Tracking = {}; AWIN.Tracking.Sale = {}; /*** Set your transaction parameters ***/ AWIN.Tracking.Sale.amount = total_paid_tax_incl; AWIN.Tracking.Sale.orderRef = id_order; AWIN.Tracking.Sale.parts = 'DEFAULT: total_paid_tax_incl'; AWIN.Tracking.Sale.voucher = getOrderedCartRulesIds; AWIN.Tracking.Sale.currency = currency.iso_code; AWIN.Tracking.Sale.test = "0"; AWIN.Tracking.Sale.channel = "aw"; //]]> </script> {/literal}
yaniv14 Posted October 23, 2020 Posted October 23, 2020 Adding currency code to custom code won't do the trick for you. This section only helps you if you need to add javascript code, like the script you have from AWIN. what you need to do is to add an override. your need to create a new file inside override/controllers/front folder and name that file OrderConfirmationController.php the content of the file should be something like <?php class OrderConfirmationController extends OrderConfirmationControllerCore { public function initContent() { $idCart = (int) Tools::getValue('id_cart'); $idOrder = Order::getOrderByCartId($idCart); $order = new Order($idOrder); $currency = new Currency($order->id_currency); $iso_code = $currency->iso_code; $cart_rules = $order->getCartRules(); $cart_rules_ids = []; foreach ($cart_rules as $cart_rule) { $cart_rules_ids[] = $cart_rule->id_cart_rule; } $cart_rules_ids_str = implode(',', $cart_rules_ids); Media::AddJsDef( [ 'iso_code' => $iso_code, 'cart_rules_ids' => $cart_rules_ids_str, ] ); $this->context->smarty->assign( [ 'iso_code' => $iso_code, 'cart_rules_ids' => $cart_rules_ids_str, ] ); return parent::initContent(); } } this is not tested and also cart_rules_ids is being passed as a comma separated ids, and I am not sure this is correct with AWIN because I am not familiar with it. also in order for the override to work you will need to delete "cache/class_index.php" file. hopes it gives you some direction where to start.
MattR Posted November 10, 2020 Author Posted November 10, 2020 Just an update on this if anybody wants to do the same AWIN integration. Adding the required items to the data layer on the "order complete" page was too much for me. I took the lazy option and used the Google Tag Manager by Reactioncode. That made all of the data available in Google Tag Manager and it was relatively simple to send that data to AWIN. If anyone wants a step by step just let me know. Thanks Yaniv for all your help! Even if I didn't get the solution in the way I'd planned it made me realise it was beyond my ability at the moment. Matt
rena Posted May 5, 2022 Posted May 5, 2022 Hi MattR I have the same problem to integrate awin on my prestashop i wana the Awin integration step by step plz
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now