Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls
 

extra fields, assigning a variable, using more than one extra field

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design
 
Thread Tools Search this Thread
  #1  
Old 03-05-2009, 04:43 PM
 
carpeperdiem carpeperdiem is offline
 

X-Guru
  
Join Date: Jul 2006
Location: New York City, USA
Posts: 5,399
 

Default extra fields, assigning a variable, using more than one extra field

I am trying to do something that is just beyond my level of expertise. All help is appreciated.

MY ULTIMATE GOAL is to put a bunch of videos on specific product pages. To do this, I have encoded the videos into f4v format using Flash encoder CS4, and will use shadowbox and the JW player. It works great.

Now, to get the videos onto the product.tpl -- I had a few ideas...

A few pieces of info: I am using extra fields to propagate an INGREDIENTS tab (that is the only visible extra field -- I also have hidden extra fields too) -- I use a simple xyz.png for each products' ingredients, saved as an image.

SO -- my questions/problems:

1. HOW can i constrain the extra fields to just a specific extra field in product.tpl?

I thought I could use: {if $extra_fields[field].field eq "videocontent"} --- but that didn't work.

IN my file, /skin1/modules/Extra_Fields/product.tpl

It looks like this:

Code:
{section name=field loop=$extra_fields} {if $extra_fields[field].field eq "Ingredients"} {if $extra_fields[field].field_value ne ""} <img src="/product-images/ingredients/{$extra_fields[field].field_value}" />{/if} {else} {if $extra_fields[field].active eq "Y" && $extra_fields[field].field_value} {$extra_fields[field].field_value} {/if} {/if} {/section}

This allows me to drop this template into the TABS for my ingredients, and the ingredients display, per product.

I tried adding more code to /skin1/modules/Extra_Fields/product.tpl, but that just crashed the tabs. (yes, the tabs have an include for /skin1/modules/Extra_Fields/product.tpl )

HOW CAN I HAVE MORE THAN ONE EXTRA FIELD, and then if for the field name at different locations in product.tpl as well as other templates ?

Additionally, to simplify the content in the extra field, and simplify the amount of code, can someone remind me of the technique to assign the results of an if string to a $variable, so that it can be used multiple times? This way, if my extra field, "videocontent" for product msp is simply "msp" -- then I can use the $msp string a few times, cutting down on code.

Clear as mud?

Thanks in advance for the assistance. Yes, I searched the forum, and even found answers from myself that I thought would be the solution, but it's not working... I must be losing brain cells. Thanks.

Jeremy
__________________
xcart 4.5.4 gold+ w/x-payments 1.0.6; xcart gold 4.4.4
Reply With Quote
  #2  
Old 03-07-2009, 01:29 AM
  gb2world's Avatar 
gb2world gb2world is offline
 

X-Wizard
  
Join Date: May 2006
Location: Austin, TX
Posts: 1,970
 

Default Re: extra fields, assigning a variable, using more than one extra field

Hi Jeremy -
I may not understand exactly what you are trying to do - but I do have a "sandbox" cart where I experiment. I dropped your code in several places in product.tpl and it worked as far as displaying the desired extra field. I don't have a tab mod, so that may be why I can't see the problem you are having.

For your other question - was this what you need?:

Code:
{section name=field loop=$extra_fields} {if $extra_fields[field].field eq "Ingredients"} {if $extra_fields[field].field_value ne ""} {assign var="ingredient" value=$extra_fields[field].field_value} {/if} {/if} {/section}


Then - you can use later:

Code:
<p><b>Ingredient:</b> {$ingredient}</p>

If it helps - you can PM me and I will give you access to my sandbox.
__________________
X-CART (4.1.9,12/4.2.2-3/4.3.1-2/4.4.1-5)-Gold
(CDSEO, Altered-Cart On Sale, BCSE Preorder Backorder, QuickOrder, X-Payments, BCSE DPM Module)
Reply With Quote
  #3  
Old 03-07-2009, 05:35 AM
 
carpeperdiem carpeperdiem is offline
 

X-Guru
  
Join Date: Jul 2006
Location: New York City, USA
Posts: 5,399
 

Default Re: extra fields, assigning a variable, using more than one extra field

Ah. var assign is exactly what I needed. Thanks. I had that code but late night brain cell drain prevented me from finding it.

As for the extra fields, my problem is having multiple extra fields, BUT only putting one on one place on the page, and a different one on another... the template will try to drop all of them at all instances...

Maybe if I load up the template with all the variables, then use var assign code to place it, it will work.... I will try this right now.

Thanks for pointing me in this direction. I will report back.

Jeremy
__________________
xcart 4.5.4 gold+ w/x-payments 1.0.6; xcart gold 4.4.4
Reply With Quote
  #4  
Old 03-07-2009, 07:58 AM
 
carpeperdiem carpeperdiem is offline
 

X-Guru
  
Join Date: Jul 2006
Location: New York City, USA
Posts: 5,399
 

Default Re: extra fields, assigning a variable, using more than one extra field

Not working yet.

--- is the var assign good for the enitre template, and nested templates further down the page?

For example:

the file, modules/Extra_Fields/product.tpl looks like:

Code:
{section name=field loop=$extra_fields} {if $extra_fields[field].field eq "Ingredients"} {if $extra_fields[field].field_value ne ""} {assign var="ingred" value=$extra_fields[field].field_value} {/if} {/if} {/section}

then in product.tpl (toward the top), I include the template:

Code:
{if $active_modules.Extra_Fields ne ""} {include file="modules/Extra_Fields/product.tpl"} {/if}

so then, the var, {$ingred} should be propagated from here on within product.tpl, yes?

Should I be able to use the var like this, somewhere lower on the product.tpl page:

Code:
<img src="/product-images/ingredients/{$ingred}" />

Unfortunately, it's not working. {$ingred) simply comes back blank. Nothing there. AM I MISSING SOMETHING in assigning the var?

Thanks in advance for looking at this.

Jeremy
__________________
xcart 4.5.4 gold+ w/x-payments 1.0.6; xcart gold 4.4.4
Reply With Quote
  #5  
Old 03-07-2009, 08:51 AM
 
carpeperdiem carpeperdiem is offline
 

X-Guru
  
Join Date: Jul 2006
Location: New York City, USA
Posts: 5,399
 

Default Re: extra fields, assigning a variable, using more than one extra field

PS -- if I include the var in the section loop, it appears... such as:

Code:
{section name=field loop=$extra_fields} {if $extra_fields[field].field eq "Ingredients"} {if $extra_fields[field].field_value ne ""} {assign var="ingred" value=$extra_fields[field].field_value} {/if} <img src="/product-images/ingredients/{$ingred}" /> {/if} {/section}

But this doesn't solve the issue of using $ingred in other locations on the page.

Not to mention, trying to assign 2 different vars to be used in different places...

????
__________________
xcart 4.5.4 gold+ w/x-payments 1.0.6; xcart gold 4.4.4
Reply With Quote
  #6  
Old 03-07-2009, 11:26 AM
  gb2world's Avatar 
gb2world gb2world is offline
 

X-Wizard
  
Join Date: May 2006
Location: Austin, TX
Posts: 1,970
 

Default Re: extra fields, assigning a variable, using more than one extra field

I suspect you can't set the variable inside modules/Extra_Fields/product.tpl and it will be applied globally. If you can keep the setting of the variables inside product.tpl - you should be able to use the variables inside the nested templates. To have the variables available globally - I think you would have to set variables in the php files. But before doing that, maybe this will work for you:

At the top of skin1/customer/main/product.tpl - before you call any templates:
Set all the variables:
Code:
{section name=field loop=$extra_fields} {if $extra_fields[field].field eq "Ingredients" && $extra_fields[field].field_value ne ""} {assign var="ingredient" value=$extra_fields[field].field_value} {/if} {if $extra_fields[field].field eq "test exf A" && $extra_fields[field].field_value ne ""} {assign var="exfa" value=$extra_fields[field].field_value} {/if} {if $extra_fields[field].field eq "test exf B" && $extra_fields[field].field_value ne ""} {assign var="exfb" value=$extra_fields[field].field_value} {/if} {/section}


Then, you should be able to use the variables you set above later inside product.tpl and modules/Extra_Fields/product.tpl
Code:
<b>Ingredient:</b> {$ingredient}<br /> <b>Extra Field A:</b> {$exfa}<br /> <b>Extra Field B:</b> {$exfb}<br />
__________________
X-CART (4.1.9,12/4.2.2-3/4.3.1-2/4.4.1-5)-Gold
(CDSEO, Altered-Cart On Sale, BCSE Preorder Backorder, QuickOrder, X-Payments, BCSE DPM Module)
Reply With Quote
  #7  
Old 03-07-2009, 01:41 PM
 
carpeperdiem carpeperdiem is offline
 

X-Guru
  
Join Date: Jul 2006
Location: New York City, USA
Posts: 5,399
 

Default Re: extra fields, assigning a variable, using more than one extra field

This works. Thanks.

IT APPEARS that a variable is only good for the template it is created on, and nested templates.

HOWEVER, you can't use an include to an outside template to make your variables.

For example, this code in the top of product.tpl makes a bunch of variables, that can be used on product.tpl, and any other templates nested in it:

Code:
{section name=field loop=$extra_fields} {if $extra_fields[field].field eq "Ingredients" && $extra_fields[field].field_value ne ""} {assign var="ingred" value=$extra_fields[field].field_value} {/if} {if $extra_fields[field].field eq "videocontent" && $extra_fields[field].field_value ne ""} {assign var="videocon" value=$extra_fields[field].field_value} {/if} {if $extra_fields[field].field eq "videocontenttitle" && $extra_fields[field].field_value ne ""} {assign var="videocontitle" value=$extra_fields[field].field_value} {/if} {if $extra_fields[field].field eq "videocontentdescription" && $extra_fields[field].field_value ne ""} {assign var="videocondesc" value=$extra_fields[field].field_value} {/if} {if $extra_fields[field].field eq "videocontentimage" && $extra_fields[field].field_value ne ""} {assign var="videoconimg" value=$extra_fields[field].field_value} {/if} {/section}

However, if were to extract this code, call it extra_field_vars.tpl, and then do an include from product.tpl, it will not work. CAN SOMEONE VERIFY THIS IS CORRECT? Doesn't make sense, but this is what is happening.

From there, I can go to town. This function allows me to upload about 25 videos via csv instead of manually editing 25 templates (and having to deal with a different template per product, when it's not needed).

Thanks for sticking around to help me on this. I owe you one.

Best,

Jeremy
__________________
xcart 4.5.4 gold+ w/x-payments 1.0.6; xcart gold 4.4.4
Reply With Quote
  #8  
Old 03-07-2009, 02:36 PM
  gb2world's Avatar 
gb2world gb2world is offline
 

X-Wizard
  
Join Date: May 2006
Location: Austin, TX
Posts: 1,970
 

Default Re: extra fields, assigning a variable, using more than one extra field

No problem - I tend to make use of the extra fields frequently - so I want to try and understand them as well.

I did try to set smarty variables in nested templates - and I can confirm that what you state is correct. I guess the compiler considers those variables local and does not pass them back to the calling template (surprisingly to me too).

Your other option is to set the variables in the php - then they are available to you. (This is essentially the same as looping using the existing extra_fields array in the template - except this sets the variables in php).

(This is thoroughly untested) :

In modules/Extra_Fields/extra_fields.php

Code:
if (!empty($extra_fields)) { foreach ($extra_fields as $ef_k=>$ef_v) { if ($ef_v['field'] == "Ingredients") {$ingredients_from_php = $ef_v['field_value'];} if ($ef_v['field'] == "videocontent") {$videocontent_from_php = $ef_v['field_value'];} } } ... $smarty->assign("ingredients_from_php", $ingredients_from_php); $smarty->assign("videocontent_from_php", $videocontent_from_php);

Or - you could stick them in another array where the key is the field name:
Code:
if (!empty($extra_fields)) { foreach ($extra_fields as $ef_k=>$ef_v) { if ($ef_v['field'] == "Ingredients") {$my_display_ef['Ingredients'] = $ef_v['field_value'];} if ($ef_v['field'] == "videocontent") {$my_display_ef['$videocontent'] = $ef_v['field_value'];} } } ... $smarty->assign("my_display_ef", $my_display_ef);

Then in the template:

Code:
php array ingred: <b>{$my_display_ef.Ingredients}</b><br /> php array videocontent: <b>{$my_display_ef.videocontent}</b><br />
__________________
X-CART (4.1.9,12/4.2.2-3/4.3.1-2/4.4.1-5)-Gold
(CDSEO, Altered-Cart On Sale, BCSE Preorder Backorder, QuickOrder, X-Payments, BCSE DPM Module)
Reply With Quote
  #9  
Old 03-08-2009, 05:25 AM
 
carpeperdiem carpeperdiem is offline
 

X-Guru
  
Join Date: Jul 2006
Location: New York City, USA
Posts: 5,399
 

Default Re: extra fields, assigning a variable, using more than one extra field

Thanks for the php code -- a question to php gurus: from a site optimization (speed) point of view -- is there much of a performance hit by using smarty (vs putting into the php) ? Is there a BETTER way to propagate extra fields into the templates? Is the core xcart code for extra fields the best way to do this?

I've learned on lot on this exercise, and my site is better for it. Thanks for the help.

Jeremy
__________________
xcart 4.5.4 gold+ w/x-payments 1.0.6; xcart gold 4.4.4
Reply With Quote
  #10  
Old 03-08-2009, 06:03 AM
 
PhilJ PhilJ is offline
 

X-Guru
  
Join Date: Nov 2002
Posts: 4,094
 

Default Re: extra fields, assigning a variable, using more than one extra field

Here's a mod that saves you using the extra fields...
Uses Shadowbox with FLV player
Up to 5 videos per product
Set video width, height, description, URL and autoplay.
http://www.xcartmods.co.uk/x-cart-shadowbox-v20-integration-v41x-x-cart-mods-pr-54.html
__________________
xcartmods.co.uk
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


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

   

 
X-Cart forums © 2001-2020