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)
-   -   If statement for "State" (https://forum.x-cart.com/showthread.php?t=46306)

photo 03-16-2009 08:49 AM

If statement for "State"
 
Hello
I have states enabled for the USA but for other countries it displays "The selected country doesn't require 'state' field". Does any one know what the best method would be to only show the "States" field when United States is selcted as the country and not show at all, (either on registration page or invoice) when any other country is selected?
I am thinking the following if statement should hide it for all countries but the United States.
Code:

{if $userinfo.b_country and $userinfo.s_country eq "US"} Code that displays states drop down field
{else}
{/if}

Would this code do the trick and which templates would I need to add this if statement to?

Thanks in advance.

photo 03-17-2009 03:16 AM

Re: If statement for "State"
 
I am having problems getting this to work to show the state field for only US users, using the following code in skin1/mail/html/order_invoice.tpl

Code:

{if $userinfo.s_country eq "US"}
{if $_userinfo.default_fields.s_state}
        <tr>
            <td><b>{$lng.lbl_state}:</b> </td>
            <td>{$order.s_statename}</td>
        </tr>
{/if}
{/if}

Using the above code the state field does not show at all. Any idea why or what I need to change?

Thanks

balinor 03-17-2009 03:24 AM

Re: If statement for "State"
 
The problem is, when they are filling out that form, they aren't logged in, so the cart has no idea where they are from :) You would need to use Jquery or some sort of dynamic scripting to hide that row when the country field changes.

photo 03-17-2009 03:36 AM

Re: If statement for "State"
 
I was also thinking that. Nothing can ever be simple I guess. To me it just does not look professional to have a big old "NONE" in the state field on the invoice for those countries that do not have states. :(

balinor 03-17-2009 04:02 AM

Re: If statement for "State"
 
I hear ya - if you dig in to the code I believe you could rework the if statements they use to swap from the drop -down to 'none' to hide the row completely.

photo 03-17-2009 04:09 AM

Re: If statement for "State"
 
Quote:

Originally Posted by balinor
I hear ya - if you dig in to the code I believe you could rework the if statements they use to swap from the drop -down to 'none' to hide the row completely.

Trouble is it can be like digging through this mass of data centre cables trying to find out what goes where! CABLES
:D

balinor 03-17-2009 04:15 AM

Re: If statement for "State"
 
Heh...true, very true.

photo 03-18-2009 04:29 AM

Re: If statement for "State"
 
I got help from the Pro's over at Qualiteam and thanks to them this now works great.
For anyone else interested in only showing the "state" field for only the US (or you could change or add any country you want).
Xcart Version 4.1.10 - change the following two bits of code in skin1/mail/html/order_invoice.tpl

Code:

{if $_userinfo.default_fields.b_state}
        <tr>
            <td><b>{$lng.lbl_state}:</b> </td>
            <td>{$order.b_statename}</td>
        </tr>
{/if}

To
Code:

{if $_userinfo.b_country eq "US"}
{if $_userinfo.default_fields.b_state}
        <tr>
            <td><b>{$lng.lbl_state}:</b> </td>
            <td>{$order.b_statename}</td>
        </tr>
{/if}
{/if}

And
Code:

{if $_userinfo.default_fields.s_state}
        <tr>
            <td><b>{$lng.lbl_state}:</b> </td>
            <td>{$order.s_statename}</td>
        </tr>
{/if}

To
Code:

{if $_userinfo.s_country eq "US"}
{if $_userinfo.default_fields.s_state}
        <tr>
            <td><b>{$lng.lbl_state}:</b> </td>
            <td>{$order.s_statename}</td>
        </tr>
{/if}
{/if}



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

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