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)
-   -   Use Smarty variable in product_details.tpl (https://forum.x-cart.com/showthread.php?t=64798)

MAPerformance 09-06-2012 01:59 PM

Use Smarty variable in product_details.tpl
 
I am trying to edit the skin\customer\main\product_details.tpl to display a button/link. The code I'm trying to implement needs the PRODUCTID to call the appropriate item, but I'm not sure how to call that in HTML. Here's the code snippet I'm trying to put the PRODUCTID in ("SKU" after the UA-XXXX part):

<param name="flashvars" value="video=http://website.com/video/get/UA-XXXX/SKU&amp;backcolor=0x000000&amp;frontcolor=0xCCCCCC &amp;
lightcolor=0x557722&amp;allowfullscreen=false&amp; auto-play=false&amp;ShowLogo=1&amp;play_on_click=true" />

totaltec 09-07-2012 05:48 AM

Re: Use Smarty variable in product_details.tpl
 
Hiyah MAPerformance,

Banged out a quick tutorial to show you how to determine all these variables, I've covered it before, but this gave me a chance to record a quick tip on the subject.

http://youtu.be/lSb0dBP6I98 Duration: 3:04

MAPerformance 09-07-2012 06:41 AM

Re: Use Smarty variable in product_details.tpl
 
You know, I knew all of that but couldn't seem to get it to work. Tried again this morning and it worked fine. Thanks!

MAPerformance 09-07-2012 10:21 AM

Re: Use Smarty variable in product_details.tpl
 
OK, here's one for you :)

I'm doing a similar thing for catching the product bought for conversion tracking. The code is like this:

function initTracking () {ldelim}
try {ldelim} Tracking.getProduct('UA-XXXX','{$orders.0.products.0.productid}').logAddTo Cart(); {rdelim} catch (e) {ldelim}{rdelim}
{rdelim}

As you can see I've already done some work here, and it does work fine as is. My question is how do you work it so multiple items can be tracked this way? The suggestion from the conversion tracking company is to duplicate the "try { Tracking...catch (e) {}" line and filling the SKU/PRODUCTID spot with each different item. What's the cleanest way to have each PRODUCTID populate these based on how many products the customer buys? Is this right to make sure I cover up to 10 items?

function initTracking () {ldelim}
try {ldelim} Tracking.getProduct('UA-XXXX','{$orders.0.products.0.productid}').logAddTo Cart(); {rdelim} catch (e) {ldelim}{rdelim}
try {ldelim} Tracking.getProduct('UA-XXXX','{$orders.0.products.1.productid}').logAddTo Cart(); {rdelim} catch (e) {ldelim}{rdelim}
try {ldelim} Tracking.getProduct('UA-XXXX','{$orders.0.products.2.productid}').logAddTo Cart(); {rdelim} catch (e) {ldelim}{rdelim}
try {ldelim} Tracking.getProduct('UA-XXXX','{$orders.0.products.3.productid}').logAddTo Cart(); {rdelim} catch (e) {ldelim}{rdelim}
try {ldelim} Tracking.getProduct('UA-XXXX','{$orders.0.products.4.productid}').logAddTo Cart(); {rdelim} catch (e) {ldelim}{rdelim}
try {ldelim} Tracking.getProduct('UA-XXXX','{$orders.0.products.5.productid}').logAddTo Cart(); {rdelim} catch (e) {ldelim}{rdelim}
try {ldelim} Tracking.getProduct('UA-XXXX','{$orders.0.products.6.productid}').logAddTo Cart(); {rdelim} catch (e) {ldelim}{rdelim}
try {ldelim} Tracking.getProduct('UA-XXXX','{$orders.0.products.7.productid}').logAddTo Cart(); {rdelim} catch (e) {ldelim}{rdelim}
try {ldelim} Tracking.getProduct('UA-XXXX','{$orders.0.products.8.productid}').logAddTo Cart(); {rdelim} catch (e) {ldelim}{rdelim}
try {ldelim} Tracking.getProduct('UA-XXXX','{$orders.0.products.9.productid}').logAddTo Cart(); {rdelim} catch (e) {ldelim}{rdelim}
{rdelim}

totaltec 09-07-2012 11:50 AM

Re: Use Smarty variable in product_details.tpl
 
What you want to do here is run through a foreach loop.

For example (untested):
PHP Code:

function initTracking () {ldelim}
  {foreach 
from=$orders.0.products item=prod/* This gets the products array from the order, and assigns each to a new variable named "prod"*/
    
try {ldelimTracking.getProduct('UA-XXXX','{$prod.productid}').logAddTo Cart(); {rdelim} catch (e) {ldelim}{rdelim}
  {/foreach}
{
rdelim


Just so you understand better how loops work, consider this annotated code:
PHP Code:

{foreach from=$orders item=order/* Start a foreach loop through the orders array and assign to new variable order */
  
{foreach from=$order.products item=product/* Uses the newly assigned $order variable and accesses its sub-array called products to start a new loop with each instance named product /*
    {$product.productid} /* Prints the product id for the current product from the current order */
  
{/foreach} /* closes the products loop */
{/foreach} /* closes the orders loop */ 

The above example should print each product from each order. It will print all the products from the first order, then all the products from the second order, and so on.

MAPerformance 09-12-2012 07:59 AM

Re: Use Smarty variable in product_details.tpl
 
This worked great! Thanks again for your help!


All times are GMT -8. The time now is 07:27 AM.

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