X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Changing design (https://forum.x-cart.com/forumdisplay.php?f=51)
-   -   XCart removing code from script. How to get code on page? (https://forum.x-cart.com/showthread.php?t=66240)

andrewmattress 02-27-2013 08:12 AM

XCart removing code from script. How to get code on page?
 
I would like to add code (below) to the <head>.

I've tried putting it directly into the page home.tpl. It shows in the template editor, but XCart removes part of the code when loading the page.

I've tried calling it as a separate .tpl (template) file into the page. Xcart removes part of the code when loading the page.

I've tried putting it into the common.js file. The code doesn't load.

I've tried building a new HTML page, pulling that HTML page into the template in a 1x1 iframe. The frame and code loads, but then doesn't do the tracking I want it to because it's loading in a frame.

No matter what I do, XCart is removing everything between

{
and
}

the code that I've highlighted in Dark Green below.

How do I get this full code to show up on the page inside of <head></head> and get XCart to leave it alone?

Thank-you!

Andrew
http://www.MattressInsider.com



Here is the full code (with our ID changed to X's):

<!-- Begin SpringMetrics -->

<script type='text/javascript'>
var _springMetq = _springMetq || [];
_springMetq.push(['id', 'XXXXXXXXXX']);
(
function(){
var s = document.createElement('script');
s.type = 'text/javascript';
s.async = true;
s.src = ('https:' == document.location.protocol ? 'https://d3rmnwi2tssrfx.cloudfront.net/a.js' : 'http://static.springmetrics.com/a.js');
var x = document.getElementsByTagName('script')[0];
x.parentNode.insertBefore(s, x);
}

)();
</script>
<!-- End SpringMetrics -->

gb2world 02-27-2013 11:20 AM

Re: XCart removing code from script. How to get code on page?
 
Probably this: http://help.x-cart.com/index.php?title=X-Cart:Customizing_storefront#JavaScript_in_template s

Javascript and smarty share syntax, so you have to let smarty know not to interpret the javascript.

---

pauldodman 02-28-2013 12:35 AM

Re: XCart removing code from script. How to get code on page?
 
Yes, just put {literal}tags{/literal} around your javascript code.

andrewmattress 03-04-2013 08:43 AM

Re: XCart removing code from script. How to get code on page?
 
Thanks very much for this help.

It works!

Further question...

I have a separate piece of code to track conversions. (This is for SpringMetrics.)

This code is tracking the conversion itself, but not passing the value of that conversion back.

Here are three pieces of code I've tried...

------------
OPTION 1
------------

<!-- SpringMetrics Conversion Code for mattressinsider -->
{literal}
<script type="text/javascript">
_springMetq.push(["setdata", {revenue: "{/literal}{$order.total}{literal}"}]);
_springMetq.push(["setdata", { "orderId": "{/literal}{$order.orderid}{literal}" }]);
_springMetq.push(["setdata", { "email": "{/literal}{$order.email}{literal}" }]);
_springMetq.push(["setdata", { "promoCode": "{/literal}{$order.coupon}{literal}" }]);
_springMetq.push(["convert", "sale" ]);
</script>
{/literal}
<!-- SpringMetrics Conversion Code for mattressinsider -->


------------
OPTION 2
------------

{literal}
<script type="text/javascript">
_springMetq.push(["setdata", {revenue: "{/literal}{$order.order.subtotal}{literal}"}]);
_springMetq.push(["setdata", { "orderId": "{/literal}{$order.orderid}{literal}" }]);
_springMetq.push(["setdata", { "email": "{/literal}{$order.email}{literal}" }]);
_springMetq.push(["setdata", { "promoCode": "{/literal}{$order.coupon}{literal}" }]);
_springMetq.push(["convert", "sale" ]);
</script>
{/literal}
<!-- SpringMetrics Conversion Code for mattressinsider -->



------------
OPTION 3
------------

<script type="text/javascript">{literal}
_springMetq.push(["setdata", {revenue: {/literal}"{$order.order.subtotal}"{literal}}]);
_springMetq.push(["convert", "sale" ]);
</script>

pauldodman 03-04-2013 08:53 AM

Re: XCart removing code from script. How to get code on page?
 
You've got loads of {literal} tags in the actual code itself - where did they come from???
They also seem to close then open as well!

Get rid of all those literal tags - you just need them before and after the <script>, as you have in #1 and #2 - but just without anything in between.

andrewmattress 03-04-2013 09:25 AM

Re: XCart removing code from script. How to get code on page?
 
I've tried that, but it doesn't actually put in the order value. So I thought I would have to turn on and off the {literal} in order to get it to know the difference between the Javascript and the Smarty tag.

What I've got on the site now is:

<!-- SpringMetrics Conversion Code for mattressinsider -->
{literal}
<script type="text/javascript">
_springMetq.push(["setdata", {revenue: "{$order.total}"}]);
_springMetq.push(["setdata", { "orderId": "{$order.orderid}" }]);
_springMetq.push(["setdata", { "email": "{$order.email}" }]);
_springMetq.push(["setdata", { "promoCode": "{$order.coupon}" }]);
_springMetq.push(["convert", "sale" ]);
</script>
{literal}
<!-- SpringMetrics Conversion Code for mattressinsider -->

Any other thoughts?

By the way, thanks so much for your help and your quick reply!

pauldodman 03-04-2013 09:31 AM

Re: XCart removing code from script. How to get code on page?
 
OK, yes, I see what you did now actually.
Are you getting any of the other values through?

andrewmattress 03-04-2013 09:33 AM

Re: XCart removing code from script. How to get code on page?
 
None of the values seem to be coming through. By the way, in the above code, the second {literal} is actually {/literal}

pauldodman 03-04-2013 09:34 AM

Re: XCart removing code from script. How to get code on page?
 
And is all the rest of the code in the right places and working ok?

pauldodman 03-04-2013 09:36 AM

Re: XCart removing code from script. How to get code on page?
 
And did any value come through at all with any of the code you tried?

andrewmattress 03-04-2013 03:34 PM

Re: XCart removing code from script. How to get code on page?
 
Here's the code I get on the confirmation page.

<script type="text/javascript">
_springMetq.push(["setdata", {revenue: ""}]);
_springMetq.push(["setdata", { "orderId": "" }]);
_springMetq.push(["setdata", { "email": "" }]);
_springMetq.push(["setdata", { "promoCode": "" }]);
_springMetq.push(["convert", "sale" ]);
</script>

gb2world 03-04-2013 05:19 PM

Re: XCart removing code from script. How to get code on page?
 
Have you used webmaster mode to ensure that the smarty variables you are using are available and correct for whatever page this is on?

You can also use ldelim if you find it easier: http://www.smarty.net/docsv2/en/language.function.ldelim.tpl

---

---

andrewmattress 03-04-2013 05:42 PM

Re: XCart removing code from script. How to get code on page?
 
Quote:

Originally Posted by gb2world
Have you used webmaster mode to ensure that the smarty variables you are using are available and correct for whatever page this is on?

You can also use ldelim if you find it easier: http://www.smarty.net/docsv2/en/language.function.ldelim.tpl

---

---


I'm not sure what this means - as far as testing it.

I've just now seen Webmaster Mode for the first time, so will check that shortly.

This is on /customer/main/order_message.tpl because it's tracking the conversion of the sale.

Is there somewhere else I would put it to make it work better?

How would I know what the correct smarty variables would be?

Thanks for your help!

gb2world 03-04-2013 05:54 PM

Re: XCart removing code from script. How to get code on page?
 
Webmaster mode tells you all the smarty variables available on whichever page you need the code to be. You can look at the X-Cart documentation for Webmastermode, or you might find the tutorials that Totaltec has created useful. Just search for him on the the forum and follow the links in his signature.

---

andrewmattress 03-05-2013 05:51 AM

Re: XCart removing code from script. How to get code on page?
 
Webmaster Mode doesn't give me a list of variables.

It just gives me a list of templates referenced for the page I'm on.

modules/Fast_Lane_Checkout/home.tpl skin1.conf [] global meta.tpl presets_js.tpl main/include_js.tpl rectangle_top.tpl head.tpl


etc. (X-cart.com doesn't let me post the full list, but it's just a list of templates.)

carpeperdiem 03-05-2013 06:14 AM

Re: XCart removing code from script. How to get code on page?
 
Quote:

Originally Posted by andrewmattress
Webmaster Mode doesn't give me a list of variables.

It just gives me a list of templates referenced for the page I'm on.


Click on "Show Variables" in the debug console.

carpeperdiem 03-05-2013 06:19 AM

Re: XCart removing code from script. How to get code on page?
 
Ah -- you are in version 4.1.x, yes? There's a slightly different way to do it.

See this thread:
http://forum.x-cart.com/viewtopic.php?t=17601

andrewmattress 03-05-2013 06:40 AM

Re: XCart removing code from script. How to get code on page?
 
Here's the code that seems to work to do everthing correctly, except put the variables in.

Here's what's in order_message.tpl:

<!-- SpringMetrics Conversion Code for mattressinsider -->
<script type="text/javascript">
_springMetq.push(["setdata", {literal}{revenue: "{/literal}{$order.order.subtotal}{literal}"}]);
_springMetq.push(["setdata", { "orderId": "{/literal}{$order.orderid}{literal}" }]);
_springMetq.push(["setdata", { "email": "{/literal}{$order.email}{literal}" }]);
_springMetq.push(["setdata", { "promoCode": "{/literal}{$order.coupon}{literal}" }{/literal}]);
_springMetq.push(["convert", "sale" ]);
</script>
<!-- SpringMetrics Conversion Code for mattressinsider -->


Here's what's output on https://www.mattressinsider.com/cart.php?mode=order_message&orderids=12816&keep_ht tps=yes

<!-- SpringMetrics Conversion Code for mattressinsider --> <script type="text/javascript"> _springMetq.push(["setdata", {revenue: ""}]); _springMetq.push(["setdata", { "orderId": "" }]); _springMetq.push(["setdata", { "email": "" }]); _springMetq.push(["setdata", { "promoCode": "" }]); _springMetq.push(["convert", "sale" ]); </script> <!-- SpringMetrics Conversion Code for mattressinsider -->

Except it's spaced properly when I view the code:
<!-- SpringMetrics Conversion Code for mattressinsider -->
<script type="text/javascript">
_springMetq.push(["setdata", {revenue: ""}]);
_springMetq.push(["setdata", { "orderId": "" }]);
_springMetq.push(["setdata", { "email": "" }]);
_springMetq.push(["setdata", { "promoCode": "" }]);
_springMetq.push(["convert", "sale" ]);
</script>
<!-- SpringMetrics Conversion Code for mattressinsider -->



Here are the variables I have tried in revenue:
{$order.total}
{$order.order.subtotal}

What other variables might work there to put in the revenue?

Is there a guide or list of variables somewhere?

Thank-you so much for helping with this.

andrewmattress 03-05-2013 06:49 AM

Re: XCart removing code from script. How to get code on page?
 
Based on this post:
http://forum.x-cart.com/showthread.php?t=62458

I also just tried:

{foreach from=$orders item=order}
... {$order.total} ...
{/foreach}

Which output this:



<!-- SpringMetrics Conversion Code for mattressinsider -->
<script type="text/javascript">
_springMetq.push(["setdata", {revenue: "... ...
"}]);
_springMetq.push(["setdata", { "orderId": "" }]);
_springMetq.push(["setdata", { "email": "" }]);
_springMetq.push(["setdata", { "promoCode": "" }]);
_springMetq.push(["convert", "sale" ]);
</script>
<!-- SpringMetrics Conversion Code for mattressinsider -->

I also just tried it without the ...,
which output this:

<!-- SpringMetrics Conversion Code for mattressinsider -->
<script type="text/javascript">
_springMetq.push(["setdata", {revenue: "... ...
"}]);
_springMetq.push(["setdata", { "orderId": "" }]);
_springMetq.push(["setdata", { "email": "" }]);
_springMetq.push(["setdata", { "promoCode": "" }]);
_springMetq.push(["convert", "sale" ]);
</script>
<!-- SpringMetrics Conversion Code for mattressinsider -->

carpeperdiem 03-05-2013 06:50 AM

Re: XCart removing code from script. How to get code on page?
 
Don't "try" - go get the actual variable. I gave you the link.

andrewmattress 03-05-2013 06:59 AM

Re: XCart removing code from script. How to get code on page?
 
Based on the same post,

I tried this (which I know is putting PHP inside of Javascript, but I'm unsure what else to do here...):

<!-- SpringMetrics Conversion Code for mattressinsider -->
<script type="text/javascript">
_springMetq.push(["setdata", {literal}{revenue: "{/literal}if (<? echo $order.total ?>) {<? echo $order.total ?>;}{literal}"}]);
_springMetq.push(["setdata", { "orderId": "{/literal}{$order.orderid}{literal}" }]);
_springMetq.push(["setdata", { "email": "{/literal}{$order.email}{literal}" }]);
_springMetq.push(["setdata", { "promoCode": "{/literal}{$order.coupon}{literal}" }{/literal}]);
_springMetq.push(["convert", "sale" ]);
</script>
<!-- SpringMetrics Conversion Code for mattressinsider -->

Which output this:
<!-- SpringMetrics Conversion Code for mattressinsider --> <script type="text/javascript"> _springMetq.push(["setdata", {revenue: "if (<? echo $order.total ?>) "}]); _springMetq.push(["setdata", { "orderId": "" }]); _springMetq.push(["setdata", { "email": "" }]); _springMetq.push(["setdata", { "promoCode": "" }]); _springMetq.push(["convert", "sale" ]); </script> <!-- SpringMetrics Conversion Code for mattressinsider -->



I also tried this:

<!-- SpringMetrics Conversion Code for mattressinsider -->
<script type="text/javascript">
_springMetq.push(["setdata", {literal}{revenue: "{/literal}{<? echo $order.total ?>;}{literal}"}]);
_springMetq.push(["setdata", { "orderId": "{/literal}{$order.orderid}{literal}" }]);
_springMetq.push(["setdata", { "email": "{/literal}{$order.email}{literal}" }]);
_springMetq.push(["setdata", { "promoCode": "{/literal}{$order.coupon}{literal}" }{/literal}]);
_springMetq.push(["convert", "sale" ]);
</script>
<!-- SpringMetrics Conversion Code for mattressinsider -->

Which output this:

<!-- SpringMetrics Conversion Code for mattressinsider --> <script type="text/javascript"> _springMetq.push(["setdata", {revenue: ""}]); _springMetq.push(["setdata", { "orderId": "" }]); _springMetq.push(["setdata", { "email": "" }]); _springMetq.push(["setdata", { "promoCode": "" }]); _springMetq.push(["convert", "sale" ]); </script> <!-- SpringMetrics Conversion Code for mattressinsider -->

andrewmattress 03-05-2013 07:09 AM

Re: XCart removing code from script. How to get code on page?
 
Quote:

Originally Posted by carpeperdiem
Don't "try" - go get the actual variable. I gave you the link.


Where is the debug console? I changed smarty.php, and turned on Webmaster mode...

andrewmattress 03-05-2013 07:17 AM

Re: XCart removing code from script. How to get code on page?
 
I switched the code in smarty.php, but it's still showing templates, not variables, in the popup.

carpeperdiem 03-05-2013 07:27 AM

Re: XCart removing code from script. How to get code on page?
 
General settings.

http://help.x-cart.com/index.php?title=X-Cart:Editing_Skin_Files#Using_Debugging_Console

You have to search the docs. 99% of the time, it's there for you!

andrewmattress 03-05-2013 07:50 AM

Re: XCart removing code from script. How to get code on page?
 
Okay... that was a stretch for me, but based on all the help offered in this post, as well as here:
http://forum.x-cart.com/showthread.php?t=44543

I was able to get the variables to display in debug mode.

Here are the relevant variables:

{$orderids}"12817"{$orders}Array (1)
0 => Array (4)
order => Array (77)
orderid => "12817"
login => "anonymous-13353"
membership => ""
total => "329.00"
giftcert_discount => "0.00"
giftcert_ids => ""
subtotal => "329.00"
discount => "0.00"
coupon => ""
coupon_discount => "0.00"
shippingid => "0"
tracking => ""
shipping_cost => "0.00"
tax => "0.00"
taxes_applied => "N;"
date => "1362493877"
status => "Q"
payment_method => "Phone Ordering"
email => "123testing@readingrainbow.com"

So I put in this code:

<!-- SpringMetrics Conversion Code for mattressinsider -->
<script type="text/javascript">
_springMetq.push(["setdata", {literal}{revenue: "{/literal}{$orders.order.total}{literal}"}]);
_springMetq.push(["setdata", { "orderId": "{/literal}{$orderids}{literal}" }]);
_springMetq.push(["setdata", { "email": "{/literal}{$orders.order.email}{literal}" }]);
_springMetq.push(["setdata", { "promoCode": "{/literal}{$orders.order.coupon}{literal}" }{/literal}]);
_springMetq.push(["convert", "sale" ]);
</script>
<!-- SpringMetrics Conversion Code for mattressinsider -->

Which gives this output:

<script type="text/javascript"> _springMetq.push(["setdata", {revenue: ""}]); _springMetq.push(["setdata", { "orderId": "12817" }]); _springMetq.push(["setdata", { "email": "" }]); _springMetq.push(["setdata", { "promoCode": "" }]); _springMetq.push(["convert", "sale" ]); </script> <!-- SpringMetrics Conversion Code for mattressinsider --></div>

Finally the Order ID works. So I assume I'm close now.

How do I get the rest of the fields to work? The email field is at the same level in the tree as the other fields.

Thank-you!

andrewmattress 03-05-2013 07:56 AM

Re: XCart removing code from script. How to get code on page?
 
1 Attachment(s)
Shoot. The tree structure went away. Please see screenshot.

andrewmattress 03-05-2013 08:57 AM

Re: XCart removing code from script. How to get code on page?
 
Solved!

YAY!!!

Thank-you SO much for your help.

Was a much longer process than anticipated, but good to go now!

Here is the XCart code for making Spring Metrics work with the version of XCart we are using.

<!-- SpringMetrics Conversion Code for mattressinsider -->
<script type="text/javascript">
_springMetq.push(["setdata", {literal}{revenue: "{/literal}{$orders.0.order.total}{literal}"}]);
_springMetq.push(["setdata", { "orderId": "{/literal}{$orderids}{literal}" }]);
_springMetq.push(["setdata", { "email": "{/literal}{$orders.0.order.email}{literal}" }]);
_springMetq.push(["setdata", { "promoCode": "{/literal}{$orders.0.order.coupon}{literal}" }{/literal}]);
_springMetq.push(["convert", "sale" ]);
</script>
<!-- SpringMetrics Conversion Code for mattressinsider -->


All times are GMT -8. The time now is 09:57 AM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.