Page 1 of 1

Google Customer Reviews - Accessing Unset Variables on Success.php

Posted: Mon Oct 09, 2017 11:02 pm
by rhorne
Hello,

I'm trying to add Google Customer Reviews to our web shop.

It's quite simple in that you just add the following script to the end of your success.php page.

Code: Select all

<script src="https://apis.google.com/js/platform.js?onload=renderOptIn" async defer></script>			
			<script>
			  window.renderOptIn = function() {
				window.gapi.load('surveyoptin', function() {
				  window.gapi.surveyoptin.render(
					{
					  "merchant_id": MERCHANT ID,
					  "order_id": "ORDER ID",
					  "email": "CUSTOMER EMAILS",
					  "delivery_country": "COUNTRY ID",
					  "estimated_delivery_date": "ESTIMATED DELIVERY DATE"
					});
				});
			  }
			</script>
However, I'm having problems accessing the Order ID, Customer Email and Country ID variables as they're all unset at this point.

I've looked at a few other similar posts and they've suggested making changes to the base success.php code but I'm trying to make this a VQMOD that is added to the end of the success.php page. I know there are paid extensions out there, but I don't want to pay $49.99 just to capture 4 variables.

Any help would be gratefully received. I did consider setting these to session variables from the checkout.php page and then unsetting them on success.php but this seems a messy solution.

Re: Google Customer Reviews - Accessing Unset Variables on Success.php

Posted: Mon Oct 09, 2017 11:30 pm
by straightlight
Hi,

this free tutorial may greatly help you: viewtopic.php?f=24&t=191768 . You can create a VQMod version of the JS code above.

Re: Google Customer Reviews - Accessing Unset Variables on Success.php

Posted: Wed Oct 18, 2017 9:07 pm
by rhorne
That all seems a lot of unnecessary work just to capture a couple of variables.

I was hoping to just create a few session variables that I could call on the success page then unset.

Re: Google Customer Reviews - Accessing Unset Variables on Success.php

Posted: Wed Oct 18, 2017 9:20 pm
by straightlight
In this case, better to use VQMod, OCMod or the override engine to make those captures. It will be way easier for you to handle parts of lines than having to play with core files. ;)

Re: Google Customer Reviews - Accessing Unset Variables on Success.php

Posted: Wed Oct 18, 2017 11:11 pm
by Qphoria
The way I do it is to add code the checkout/success.php controller within the

Code: Select all

if (isset($this->session->data['order_id'])) {
conditional, and append it to the $data['text_message'] variable later in the code if it was set.
Prevents the need to edit the tpl file

Alternatively, you can pass that session order id as a variable within the success.php controller, and then add a check for that variable in the common/success.tpl file. But keep in mind that the common/success.tpl file is common so you'll want to add some additional variable to ensure you are handling the checkout success and not the registration success or some other success call that shares this file.

Re: Google Customer Reviews - Accessing Unset Variables on Success.php

Posted: Wed Oct 18, 2017 11:19 pm
by straightlight
I do have an already example developed for those requests: viewtopic.php?f=24&t=191768