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)
-   -   Extra Fields if statement (https://forum.x-cart.com/showthread.php?t=65220)

David-Allan 10-30-2012 02:34 AM

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?

carpeperdiem 10-30-2012 07:10 AM

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?

David-Allan 11-01-2012 01:02 AM

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?

carpeperdiem 11-01-2012 04:55 AM

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

David-Allan 11-02-2012 01:54 AM

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.

David-Allan 11-02-2012 02:22 AM

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}


carpeperdiem 11-02-2012 04:33 AM

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

David-Allan 11-02-2012 04:50 AM

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 :)

drheath 01-18-2013 09:14 AM

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?


All times are GMT -8. The time now is 08:46 AM.

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