| ||||||||||
Shopping cart software Solutions for online shops and malls | ||||||||||
|
X-Cart Home | FAQ | Forum rules | Calendar | Mark Forums Read | User manuals | Login |
common if/then modifications I make to x-cart... | ||||
|
|
Thread Tools | Search this Thread |
#1
|
|||||||
|
|||||||
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:
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:
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:
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:
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:
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:
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:
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:
------------------------------------------------- 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:
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:
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. |
|||||||
|
#2
|
|||||||||
|
|||||||||
Instinctual,
Finish this post! It's a good one! |
|||||||||
#3
|
|||||||
|
|||||||
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 |
|||||||
#4
|
|||||||
|
|||||||
Thanks for the post! Number 2 and 3 are GREAT!
__________________
Long time fan, not running any sites at the moment... |
|||||||
#5
|
|||||||
|
|||||||
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:
So I tried this which doesn't seem to be working: Quote:
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 |
|||||||
#6
|
|||||||
|
|||||||
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 |
|||||||
#7
|
|||||||
|
|||||||
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 |
|||||||
#8
|
|||||||
|
|||||||
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 |
|||||||
#9
|
|||||||
|
|||||||
Re: common if/then modifications I make to x-cart...
Quote:
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 |
|||||||
#10
|
|||||||
|
|||||||
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. |
|||||||
|
Thread Tools | Search this Thread |
|
|
|
|||
X-Cart forums © 2001-2020
|