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

Extra Fields if statement

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design
 
Thread Tools Search this Thread
  #1  
Old 10-30-2012, 02:34 AM
  David-Allan's Avatar 
David-Allan David-Allan is offline
 

eXpert
  
Join Date: Oct 2011
Location: Scotland, UK
Posts: 313
 

Default Extra Fields if statement

Hi guys,

I am trying to stop the display of the contact us pop up on the product page if the extra field "Sample Request" is set to "NO"

Here is what I have done so far but can't get it to work. Can someone have a quick look at my code and see if I am doing something wrong.

Code:
{foreach from=$product.extra_fields item=v} {if $v.field eq "Sample Request" && $v.value ne "NO"} <div class="ask-question"> {include file="customer/buttons/button.tpl" button_title=$lng.lbl_ask_question_about_product style="link" href="javascript: return !popupOpen(xcart_web_dir + '/popup_ask.php?productid=`$product.productid`')"} </div> <div class="clearing"></div> </li> {/if} {/foreach}

I have inserted this in product_details.tpl but its not showing the ask question part no matter what the "Sample Request" is set to.

any one got any ideas?
__________________
Live Version : 4.5.2
Licensed Products:
X-Cart Gold
Ability Theme
CDSEO
xCMS
Abandoned Cart
Food Packaging Scotland
Reply With Quote
  #2  
Old 10-30-2012, 07:10 AM
 
carpeperdiem carpeperdiem is offline
 

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

Default Re: Extra Fields if statement

Can you simplify this and do this in css?

Possibly use css, 'display:none;" for the popup ? Or if you don't want to disrupt the layout, use "visibility:hidden;"

Not saying this is better - but it may get you there with minimum code. Maybe?
__________________
xcart 4.5.4 gold+ w/x-payments 1.0.6; xcart gold 4.4.4
Reply With Quote

The following user thanks carpeperdiem for this useful post:
David-Allan (10-30-2012)
  #3  
Old 11-01-2012, 01:02 AM
  David-Allan's Avatar 
David-Allan David-Allan is offline
 

eXpert
  
Join Date: Oct 2011
Location: Scotland, UK
Posts: 313
 

Default Re: Extra Fields if statement

Thanks Mate,

I am unfortunately not great with CSS, it is something I really need to sit down and teach myself. I wouldn't have a clue how to do what you are suggesting. Any tips?
__________________
Live Version : 4.5.2
Licensed Products:
X-Cart Gold
Ability Theme
CDSEO
xCMS
Abandoned Cart
Food Packaging Scotland
Reply With Quote
  #4  
Old 11-01-2012, 04:55 AM
 
carpeperdiem carpeperdiem is offline
 

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

Default Re: Extra Fields if statement

THIS is NOT TESTED SPECIFICALLY, but based on code that works. This should get you started.

1. verify the extra field content is available on your page (use webmaster mode)
2. define a variable, $test for the extra field, "testing". The if code makes sure there is something there, else it ignores.

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

3. place your variable in a div with inline css. The if makes sure something is there, else it ignores. If $test is empty, nothing happens. If test has something in it, it will display the <div> - which is set to not display anything using css, style="display:none;"

Code:
{if $test ne ""} <div style="display:none;">TESTING CONTENT GOES HERE</div> {/if}

The logic is: "is there anything in the test field? If so, do not display the content.

Hope this helps in some way.

J
__________________
xcart 4.5.4 gold+ w/x-payments 1.0.6; xcart gold 4.4.4
Reply With Quote

The following 2 users thank carpeperdiem for this useful post:
David-Allan (11-02-2012), Steel (11-01-2012)
  #5  
Old 11-02-2012, 01:54 AM
  David-Allan's Avatar 
David-Allan David-Allan is offline
 

eXpert
  
Join Date: Oct 2011
Location: Scotland, UK
Posts: 313
 

Default Re: Extra Fields if statement

Thanks mate that looks like a good way of doing it. I'll give it a bash and see how I get on. thanks for your help.

Time I really spent some time learning CSS.
__________________
Live Version : 4.5.2
Licensed Products:
X-Cart Gold
Ability Theme
CDSEO
xCMS
Abandoned Cart
Food Packaging Scotland
Reply With Quote
  #6  
Old 11-02-2012, 02:22 AM
  David-Allan's Avatar 
David-Allan David-Allan is offline
 

eXpert
  
Join Date: Oct 2011
Location: Scotland, UK
Posts: 313
 

Default Re: Extra Fields if statement

Quote:
Originally Posted by carpeperdiem
THIS is NOT TESTED SPECIFICALLY, but based on code that works. This should get you started.

1. verify the extra field content is available on your page (use webmaster mode)
2. define a variable, $test for the extra field, "testing". The if code makes sure there is something there, else it ignores.

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

3. place your variable in a div with inline css. The if makes sure something is there, else it ignores. If $test is empty, nothing happens. If test has something in it, it will display the <div> - which is set to not display anything using css, style="display:none;"

Code:
{if $test ne ""} <div style="display:none;">TESTING CONTENT GOES HERE</div> {/if}

The logic is: "is there anything in the test field? If so, do not display the content.

Hope this helps in some way.

J

J your some man that works a treat with some tweaking.

Here is what I did incase it helps anyone else.

Code:
{section name=field loop=$extra_fields} {if $extra_fields[field].field eq "Sample Request" && $extra_fields[field].field_value ne ""} {assign var="test" value=$extra_fields[field].field_value} {/if} {/section} {if $test ne ""} <div style="display:none;"> {include file="customer/buttons/button.tpl" button_title=$lng.lbl_ask_question_about_product style="link" href="javascript: return !popupOpen(xcart_web_dir + '/popup_ask.php?productid=`$product.productid`')"} </div> {else} <div class="ask-question"> {include file="customer/buttons/button.tpl" button_title=$lng.lbl_ask_question_about_product style="link" href="javascript: return !popupOpen(xcart_web_dir + '/popup_ask.php?productid=`$product.productid`')"} </div> {/if}
__________________
Live Version : 4.5.2
Licensed Products:
X-Cart Gold
Ability Theme
CDSEO
xCMS
Abandoned Cart
Food Packaging Scotland
Reply With Quote
  #7  
Old 11-02-2012, 04:33 AM
 
carpeperdiem carpeperdiem is offline
 

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

Default Re: Extra Fields if statement

Glad to know you were able to work it out!
PS-- the var, $test was only used as an example -- I would imagine you will change the var to $samplereq or something related to the field -- imagine troubleshooting this 3 years from now -- try to backtrace the $test var?

Best,
Jeremy
__________________
xcart 4.5.4 gold+ w/x-payments 1.0.6; xcart gold 4.4.4
Reply With Quote

The following user thanks carpeperdiem for this useful post:
David-Allan (11-02-2012)
  #8  
Old 11-02-2012, 04:50 AM
  David-Allan's Avatar 
David-Allan David-Allan is offline
 

eXpert
  
Join Date: Oct 2011
Location: Scotland, UK
Posts: 313
 

Default Re: Extra Fields if statement

Quote:
Originally Posted by carpeperdiem
Glad to know you were able to work it out!
PS-- the var, $test was only used as an example -- I would imagine you will change the var to $samplereq or something related to the field -- imagine troubleshooting this 3 years from now -- try to backtrace the $test var?

Best,
Jeremy

Thanks for the tip Jeremy i'll change that now. smart thinking
__________________
Live Version : 4.5.2
Licensed Products:
X-Cart Gold
Ability Theme
CDSEO
xCMS
Abandoned Cart
Food Packaging Scotland
Reply With Quote
  #9  
Old 01-18-2013, 09:14 AM
  drheath's Avatar 
drheath drheath is offline
 

Advanced Member
  
Join Date: Nov 2010
Location: Wisconsin
Posts: 53
 

Default Re: Extra Fields if statement

I'm trying to do something similar, but I want it to display on the products list. I have tried products_t.tpl and products_list.tp[ in the skin directory but I am not having any luck. Would this behave differently if I were to make the changes in the "common" or "2 column" section?
__________________
Business Edition 5.2.10
Gold Plus 4.6.1
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 04:20 AM.

   

 
X-Cart forums © 2001-2020