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

common if/then modifications I make to x-cart...

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design
 
Thread Tools Search this Thread
  #1  
Old 08-12-2004, 09:33 AM
 
instinctual instinctual is offline
 

eXpert
  
Join Date: Nov 2003
Posts: 247
 

Default common if/then modifications I make to x-cart...

Hi all, thought I'd post a short list of if/then modifications I usually make to x-cart out of the box just so others can benefit from it as well...

-------------------------------------------------

1. In skin1/ either rectangle_top.tpl or head.tpl, depending on where you put your store's "header" html code, I usually put this: {if $usertype eq "C"} at the very beginning of my html code. I then put the corresponding {/if} at the end of my "header" html code, right after the last line. What does this do? It takes away your site design from the backend interface, so that you are only looking at the navigation links and x-cart interface. Do this to whichever "footer" file you are using as well - either rectangle_bottom.tpl or bottom.tpl under skin1/. This works in ANY version of x-cart.

-------------------------------------------------

2. In similar fashion, there are some things that I want my store admins to see, and there are some things I want to see as the developer logging in with the username "master". Some of the menu items in the right column I like to have for "master" only, and some for the other admins I create. So...that being said, following the logic in #1 - here's an if/then I usually surround items with in the admin menu files like skin1/admin/menu_admin.tpl and skin1/provider/menu.tpl : {if $login eq "master"} {/if} - you can put that around any item you ONLY want visible to the user "master". This works in ANY version of x-cart.

-------------------------------------------------

3. Sometimes I don't want my "store admins" to be able to create new administrators - - - sounds easy to do with the logic above, but you don't want to just take out the link "users" because that disables the ability for them to administrate their customers as well. So this fix makes it so that the "manage administrators" link dissapears while keeping the "manage customers" link intact. This is a tricky fix... I'm running out the door but will post this fix and more later tonight.

-------------------------------------------------

4. Ugh, onto #4, will dig up #3 again in a bit So..another common one I use is to have different "buy now" buttons for different categories of products. In this case, I am usually working with either products.tpl or products_t.tpl - depending on your site layout. In example, here is a recent if/then I used in products.tpl that will display a different "buy now" button depending on whether or not the category is #5 -

Code:
{if $usertype eq "C" and $config.Appearance.buynow_button_enabled eq "Y" and $products[product].categoryid ne "5"} {include file="customer/main/buy_now.tpl" product=$products[product]} {else} {include file="customer/main/member_buy_now.tpl" product=$products[product]} {/if}

Notice the "and $products[product].categoryid ne "5" part - - this is where you can change the categoryid number you're trying to affect. So above, I'm saying if the category # is not equal to "5" - then display the normal include - if not - and the category DOES equal five, display the special include. Of course, you'll have to copy "buy_now.tpl", make your own, and call it in the tag above. This works in ANY version of x-cart.

-------------------------------------------------

5. Ah, but somebody says, what about if I want to do this same thing on the "product.tpl" template? Same tag doesn't work, you may have noticed. Just use this syntax instead:

Code:
{if $product.categoryid == 4 or $product.categoryid == 5}{/if}

This works in ANY version of x-cart.

-------------------------------------------------

6. Ok, so here is some if/then mods I have made to the skin1/main/register_personal_info.tpl and other "register_" tpl files in that directory. I have mainly used these when I needed to add a custom field to the xcart_customers table and then have it show up in the registration process for the customer as well as the admin.

There are other places in this forum that discuss how to go about adding fields to the registration process, so I won't go in-depth there - but once you've added the fields and you are wanting to make a <select> box or something similar for the answer choices, these if/then's help.

In this next example, I have added a field called "region" to my customer table, and would like to display it, along with the customers' answer, in the profile section.

Code:
<tr valign=middle> <td align=right>Your Area</td> <td></td> <td nowrap> <select name=area {if $usertype eq "C"}disabled{/if}> <option value=""> <option value="area1" {if $userinfo.area eq "area1"}selected{/if}>area1 <option value="area2" {if $userinfo.area eq "area1"}selected{/if}>area2 <option value="area3" {if $userinfo.area eq "area3"}selected{/if}>area3 <option value="area4" {if $userinfo.area eq "area4"}selected{/if}>area4 <option value="area5" {if $userinfo.area eq "area5"}selected{/if}>area5 </select> </td> </tr>

Notice that I have several if/then's going on here - I've "disabled" some of the select boxes if you are a customer, and also provided statements that will correctly display your chosen answer if you have already filled out your profile. Pretty straightforward stuff - - you just put $userinfo. before the name of your new field you added to the customers table.


-------------------------------------------------


7. Ok, so this is also elsewhere on the forums, but have you ever tried to have an "on" state to a button when you were on that particular static page in your x-cart store? So when you're on the "about us" page your About Us graphic is the "over state" of the graphic?

You need a simple if/then to do it:

Code:
{if $smarty.get.pageid eq "22"}[img]button.gif[/img]{/if}

This will obviously show the image if the static page id is "22". I have used this successfully in bottom.tpl, rectangle_bottom.tpl, rectangle_top.tpl, and head.tpl, but I'm sure it would work in others as well.

-------------------------------------------------

8. Similar to the above - what about if you want to show something specific to the category you're on? Well, similar situation:

Code:
{if $cat eq "9"}show this{/if}

So above if the category equals "9" - it will show the "show this" text. Don't know what category # your categories are? Simply click on a category via the frontend in your browser, and in the url string you will see the category # as x-cart has assigned it. I have only successfully used this tag with THIS syntax on the products.tpl template - check above for other syntax that works on other templates.

-------------------------------------------------

9. Ah, one more before I hit the bed - ever wanted to display something based on whether a customer was not only logged in, but whether or not they had a "membership level" as well?

The "if logged in" part is easy:

Code:
{if $login ne ""} display this {/if}

The above tag will display the "display this" text if a person has logged in. If they have not, it will display nothing.

Now, determining whether they have a membership level is a different tag:

Code:
{if $user_membership ne ""} display this {/if}

The above tag will only display the text if a membership level is detected by x-cart. Useful if you have "member-only" pages or messages. I have used this in the past to surround pricing tags in product.tpl and products.tpl, as well as for displaying navigation tabs, etc.

It is also useful for displaying a message such as "become a member for extra savings, click here" if you want non-members to feel like they should check out becoming a member of your store when they are looking at products.

Another useful place for this tag is on your static pages - many people have complained of not having "content protection" on x-cart - well, this is how you do it. Create your static page, make sure you have "parse smarty tags in static pages" checked in your general setting for static pages, and then at the top of your html where your content begins, simply put that tag in there surrounding your "real" content, and then an {else} for your message to people who don't have the membership.

Something like this:

Code:
{if $user_membership ne "Level 1"} I'm sorry, you don't have a membership, so this content is not accessible. Please click here to become a member and get the goodies. {else} Your real html content {/if}

-------------------------------------------------


10. Lol, here's a fun one for a special situation - we had a client that wanted a certain payment method available to just "some" people within a membership level of xcart. As you know xcart doesn't let you specify this "out of the box" per user so we came up with a handy dandy if/then for the checkout.tpl file down where the {section} lists out the payment methods for display. Now obviously this isn't gonna work if you have a huge list of people - this was for a handful, so keep that in mind ;o) - check it out:


Code:
{section name=payment loop=$payment_methods} {if $payment_methods[payment].payment_method eq 'Special Payment Method' and $login ne 'samsmith' and $login ne 'poopybrown' and $login ne 'classclown'}<!---{/if} <TR> <TD width="1"><INPUT type="radio" name="paymentid" value="{$payment_methods[payment].paymentid}"{if $payment_methods[payment].is_default eq "0"} checked{/if}></TD> <TD nowrap>{$payment_methods[payment].payment_method}</TD> <TD>{$payment_methods[payment].payment_details}</TD> </TR>{if $payment_methods[payment].payment_method eq 'Special Payment Method' and $login ne 'samsmith' and $login ne 'poopybrown' and $login ne 'classclown'}--->{/if} {/section}


That lil' segment there only shows the payment method "Special Payment Method" if you are one of those users and are logged in, even though it's activated in xcart for the entire membership level.

Why did I use an html comment instead of a smarty comment to get rid of it? I couldn't get the if/then to work using a smarty comment - it always read the comment regardless of the if/then, leading me to believe it's not possible to write an if/then in order to print a smarty comment. ;o)

-------------------------------------------------

11. Ok, here's one where we had a special need. We needed customers to only be able to order certain products within one of our cateogires with a qty that WE specified, not from a dropdown, and not specifying it themselves in an open text box. We needed a product ordered in increments of 1000 - so you could order 1k, 2k, 3k, 4k, and 5k - and that's it.

Impossible you say...given that xcart controls the qty field, and the math of the cart depends upon that field. You can limit the min qty in the backend, but no way to modify the increments of qty that can be ordered per product.

So...we came up with this if/then on the product.tpl template that does the trick - this should replace the qty dropdown xcart has in there now, after replacing my "regular xcart qty <select> qty code" comment with the standard xcart <select> qty dropdown:

Code:
{if $product.productid == 10 || $product.productid == 12 || $product.productid == 17} <SELECT name="amount"{if $active_modules.Product_Options ne ''} onchange="check_wholesale(this.value);"{/if}> <option value="1000">1000</option> <option value="2000">2000</option> <option value="3000">3000</option> <option value="4000">4000</option> <option value="5000">5000</option> </select> {else} regular xcart qty <select> qty code. {* I would post it but mine is heavily modified and confusing *} {/if}

Again this is for a special situation, and as you can see we've done it by productid - so doing this for 100 products you would want to get fancy with your smarty tag and do a range of productid's.


-------------------------------------------------

Hope somebody finds some peace through this info, I'll keep adding on as I have time - thanks for the nudge!


***EDITED by Balinor to make Sticky *****
__________________
Instinctual
8,000 feet up in the Rocky Mountains of Colorado
X-Cart Versions 3.5.x - 4.0.x

IF you xcart, THEN you prosper, ELSE you fail. ELSEIF xcart fails, THEN you fix it, all the WHILE {loop}\'ing {section}\'s to feed your $smarty mind.
Reply With Quote

The following 6 users thank instinctual for this useful post:
David-Allan (07-19-2012), MAPerformance (02-22-2013), Omron Khan (04-25-2011), Steel (03-21-2010), XBOX4LIFE (06-22-2011), Xel (03-20-2009)
  #2  
Old 09-25-2004, 02:10 PM
  adpboss's Avatar 
adpboss adpboss is offline
 

X-Man
  
Join Date: Feb 2003
Location: Ontario, Canada
Posts: 2,389
 

Default

Instinctual,

Finish this post! It's a good one!
Reply With Quote
  #3  
Old 10-04-2004, 01:21 PM
 
magder magder is offline
 

Advanced Member
  
Join Date: Apr 2004
Posts: 51
 

Default

instinctual, thanks for the post.

I've figured out some of this stuff but the product.tpl will bring me some peace.

It would be great to see more.
__________________
x-cart 3.8
Reply With Quote
  #4  
Old 10-06-2004, 04:14 PM
 
jcaisse jcaisse is offline
 

Member
  
Join Date: Feb 2004
Posts: 21
 

Default

Thanks for the post! Number 2 and 3 are GREAT!
__________________
Long time fan, not running any sites at the moment...
Reply With Quote
  #5  
Old 10-12-2004, 01:52 AM
 
magder magder is offline
 

Advanced Member
  
Join Date: Apr 2004
Posts: 51
 

Default

I've been having some trouble with an {if} statement on a mod for paid membership. I thought this would be fairly simple.

I want to change the cart checkout button to join when it is a membership product.

I found this in the membership sign up script:

Quote:
if (empty($add_to_cart)) {
$amount = ($product_options == "Membership Sign Up") ? 1 : $amount;
$options = "Memberships: " . $product_options;

So I tried this which doesn't seem to be working:

Quote:
{if $products[product].product_options eq "Membership Sign Up"}<td>
{include file="buttons/update.tpl" type="input"}



</td>
<td align=right>
{include file="buttons/checkout.tpl" style="button"}
{else}
{include file="buttons/update.tpl" type="input"}


{include file="buttons/clear_cart.tpl"}
</td>
<td align=right>{include file="buttons/continue_shopping.tpl" style="button"}
<a href="cart.php?mode=checkout">{include file="buttons/checkout.tpl" style="button"}{/if}

I also tried using {if $user_membership ne ""} but that didn't work either. Is there something about the cart that handles these variables differently?
__________________
x-cart 3.8
Reply With Quote
  #6  
Old 10-12-2004, 10:25 AM
 
instinctual instinctual is offline
 

eXpert
  
Join Date: Nov 2003
Posts: 247
 

Default by product id

hmmm...well, not having checked that your variables are in the right syntax, and whether or not they can be used on the cart page like this, I'd say try this instead:

{if $products[product].product_options == "Membership Sign Up"}

See if that does the trick!

I'm almost thinking though that you would need to be using $cart_contents or something like that instead though - checking the cart contents for products with options that match, right now I think this tag is more for the products.tpl and product.tpl templates.

Lemme know!

Instinctual
Colorado
X-Cart Versions 3.5.x - 4.0.4
Reply With Quote
  #7  
Old 10-12-2004, 11:54 AM
 
magder magder is offline
 

Advanced Member
  
Join Date: Apr 2004
Posts: 51
 

Default

It didn't work. I think I'd tried that once before after reading your post.
Is there another variable i might try?
__________________
x-cart 3.8
Reply With Quote
  #8  
Old 10-12-2004, 05:58 PM
 
instinctual instinctual is offline
 

eXpert
  
Join Date: Nov 2003
Posts: 247
 

Default Lemme do some diggin'

Lemme do some diggin' and I'll see what I can come up with

Instinctual
Colorado
X-Cart Versions 3.5.x - 4.0.4
Reply With Quote
  #9  
Old 05-25-2005, 11:10 AM
 
IndieDepot IndieDepot is offline
 

Advanced Member
  
Join Date: May 2005
Posts: 30
 

Default Re: common if/then modifications I make to x-cart...

Quote:
Originally Posted by instinctual
4. Ugh, onto #4, will dig up #3 again in a bit So..another common one I use is to have different "buy now" buttons for different categories of products. In this case, I am usually working with either products.tpl or products_t.tpl - depending on your site layout. In example, here is a recent if/then I used in products.tpl that will display a different "buy now" button depending on whether or not the category is #5 -

{if $usertype eq "C" and $config.Appearance.buynow_button_enabled eq "Y" and $products[product].categoryid ne "5"}
{include file="customer/main/buy_now.tpl" product=$products[product]}
{else}
{include file="customer/main/member_buy_now.tpl" product=$products[product]}
{/if}

Notice the "and $products[product].categoryid ne "5" part - - this is where you can change the categoryid number you're trying to affect. So above, I'm saying if the category # is not equal to "5" - then display the normal include - if not - and the category DOES equal five, display the special include. Of course, you'll have to copy "buy_now.tpl", make your own, and call it in the tag above. This works in ANY version of x-cart.

Unfortunately #4 does not work in 4.0.13. I guess this was a solution for earlier versions of X-Cart. it would have been nice though. I guess now X-Cart doesn't list the 'categoryid' with the product tables anymore. And therefore you can grab the category ID in the products.tpl file anylonger.

I sure wish I knew how to do this. I wish I knew how to do it for manufacturers too. I'd like to list the manufacturers in the sub-categories AND i would like to list the categories in the product profile. Alas, nobody knows how.

- Shannon
__________________
- www.TheShotList.com
X-Cart version 4.0.13
PHP 4.3.10
MySQL 4.0.23
Web server Apache
Operation system Linux
Perl 5.008004
XML parser (expat) 1.95.6
Reply With Quote
  #10  
Old 05-25-2005, 12:47 PM
 
instinctual instinctual is offline
 

eXpert
  
Join Date: Nov 2003
Posts: 247
 

Default try this

Try $product.productid or $products.productid - - - ;o) One of these variations will work, I've done it in the 4.o.x branch - if they don't I'll dig up what WILL work, so lemme know....
__________________
Instinctual
8,000 feet up in the Rocky Mountains of Colorado
X-Cart Versions 3.5.x - 4.0.x

IF you xcart, THEN you prosper, ELSE you fail. ELSEIF xcart fails, THEN you fix it, all the WHILE {loop}\'ing {section}\'s to feed your $smarty mind.
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 06:44 PM.

   

 
X-Cart forums © 2001-2020