| ||||||||||
Shopping cart software Solutions for online shops and malls | ||||||||||
|
X-Cart Home | FAQ | Forum rules | Calendar | User manuals | Login |
Auto-Generated Color or Image Swatches from Product Options | ||||
|
|
Thread Tools | Search this Thread |
#1
|
|||||||
|
|||||||
Auto-Generated Color or Image Swatches from Product Options
This mod was inspired by sstillwell's post: Variant chart in product description
I adapted the code to display all of the variants on a page in a chart as the previous mod detailed, but also to use it to create color (or image) swatches for the items that were product options. A great necessity for anyone who sells items of color, like t-shirts or apparel. Best of all, it can be applied to any of the "tabs" mods to have a dropdown color chart or drawn directly into the product.tpl as I have detailed below. This is a finished mod, but.... I need some help making it loop in two columns as some of my items have 30 color variants and one column is way too long... if you use this mod, please assist me in the correct Smarty syntax of the loop and modifying it to display in two-columns. I used the Product Variants to call an equivalent name in a CSS file so that some swatches could be made from either html hex codes or others (like a patterned or designed apparel item) could use images. You could call anything you wanted really, but automating color /image swatches is key for many stores and a very useful function- on the fly color/swatch charts! In the product.tpl, add an include: Code:
I put it under the product description code. Then your product options must be variant type (not modifiers). If they are, then this will work. I am working the code to allow for modifiers as well and you could script it to also use the html_link command to change the product image (another mod). If you have any ideas or can make improvements, please do so. You can see in the include, that I created a directory (Color_Charts) in the skin1/modules directory and then created the template "Color_Swatches.tpl" in there. You can change this and put it wherever you would like. But, this works to call the "Color_Swatches.tpl". In the Color_Swatches.tpl, I put: Code:
I created the language variable: $lng.lbl_available_colors which just states "Available Colors" and set that as an H2, but you can call it and change the CSS accordingly. Also note: Code:
Also in that code is class="{$item.option_name|replace:" ":""|replace:"/":""}" This is the call to a CSS class based on the "Product Option" name. But, many colors have multiple names, like Baby Blue and Light Pink... so I included the Smarty code that replaces a space with nothing. Thus, "Baby Blue" is now a CSS class called "BabyBlue" and also "Black/White" is replaced with BlackWhite. You can add other variable replacements so that you can correctly call a CSS style. This is key as being CSS means that you can use colors, images, anything! I also created a custom CSS file called "colors.css" and put the include in the home.tpl underneath the main skin1.css: <LINK rel="stylesheet" href="{$SkinDir}/colors.css"> In this CSS file I listed my colors that could be called. If you have multiple color variations per name (two or three "Red" variants) just use an {if} statement to call the correct CSS file per manufacturer, like: Code:
I recommend bookmarking that one as it got me started playng with all of these minor but nifty tweaks... In the colors.css, I just listed the CSS names and color with hex codes. Like: Code:
In theory, if all of my swatches would have been images, I could have just ignored the CSS and called the images as background images in the swatch array drawn from the product options. OK- that about sums it up. But, I want to add some additionals to this mod and perhaps you can help.
Enjoy! And I'd love to see some samples of this in use. One nice thing about it is that a customer only see the colors that are available. If you remove or deactivate an option, no corresponding swatch appears. And being Smarty, you can call it or not with any of the many variables... - Mike
__________________
4.1.9 |
|||||||
#2
|
|||||||||
|
|||||||||
here is a 2 column layout for a custom detailed images mod.
you will have to make some tweaks, but you get the idea. Code:
you can see it in action here. http://ridersinc.com/store/customer/product.php?productid=4357&cat=1083&page=1 the detailed images section below the price and large thumb. |
|||||||||
#3
|
|||||||
|
|||||||
Thanks ETI! I'll see if I can get that to work right now... By the way, you could tweak that detailed mod of yours to swap the product image. But, how are those thumbs called? It appears to be an "extra" detailed image php call...
- Mike
__________________
4.1.9 |
|||||||
#4
|
|||||||
|
|||||||
Re: Auto-Generated Color or Image Swatches from Product Opti
Hi I've used you mod and it works well thanks.
But..... there's always a but I want my customer to be able to disable some of the variants if a color becomes unavailable. If you do so, color_swatches.tpl still do the loop as if all the variants were still available. The result is that I get blank space with an X at the place of the picture. Have you figure out how to skip th variant if its disable?
__________________
x-cart gold 4.0.15 |
|||||||
#5
|
|||||||
|
|||||||
Re: Auto-Generated Color or Image Swatches from Product Opti
Hello I've combined your mod with ETI's and have color swatch on 5 colums and i'm using images instead of css.
Feel free to use. Code:
However I still got this issue. Quote:
__________________
x-cart gold 4.0.15 |
|||||||
#6
|
|||||||
|
|||||||
tabarsoft,
My mod works for "available" options only, so I don't get any empties when options are unavailable (it only calls what is seen in the dropdown). Getting better and better though! - Mike
__________________
4.1.9 |
|||||||
#7
|
|||||||
|
|||||||
Solution for achieving multiple columns of swatches:
Code:
- Mike
__________________
4.1.9 |
|||||||
#8
|
|||||||||
|
|||||||||
No problem.
Glad it worked out. As for the image swap on the ridersinc site. All those watermarked images are dynamically generated, your suggestion would require another thumbnail to be generated and some more coding...wasnt required by the client.... but it could be done. |
|||||||||
#9
|
|||||||
|
|||||||
I was asked about using images for this mod, simply change the CSS to reflect an image URL:
Code:
Or if you have some images that you want to display per option, simply remove the border and call them. I did this in CSS as products are very different across manufacturers or lines. Better to keep control of the function in an easy to trasnport form.. - Mike
__________________
4.1.9 |
|||||||
#10
|
|||||||
|
|||||||
I am trying to change my product image by clicking the generated swatch (the images change by changing the variant option dropdown), but I can only get the swatch to change the dropdown and the dropdown to change the image.
In the img src tag of the swatch, I have added: Code:
Thanks for your help, Mike
__________________
4.1.9 |
|||||||
|
|||
X-Cart forums © 2001-2020
|