VirtueMart Dev/Coding Central: VM1 (old version) > Development Projects, Modifications, Hacks & Tweaks. VM1.1

Attributes depending on other attributes (vm 1.1.x)

(1/4) > >>

vmlab:
I read a lot about people wanting to display a set of attributes / drop downs based on
the selection of another drop down.

Even as I sat to write this hack, I understood what an enormous task it is.

After 12 hours of work I managed to compile this hack. It is not the most
elegant solution but gets the work done.

mod edit: link removed

The first link has 3 attributes  and the second link has two attributes

This is working on Virtuemart 1.1.x and Joomla 1.5.x.

This for advanced attributes provided by Virtuemart 1.1.x

Let us assume that we want to sell a T Shirt which has 3 attributes, Color,size and vendor.

We want the size attribute to get populated based on the Color selection.

We want the company attribute to get populated based on the Color and size selection.

So let us say we have the colors Red,Blue and Green.

We want the drop down to behave as follows

1. When Red is selected we want the size to display S,M and L
2. When Blue is selected we want the size to display L and XL
3. When Green is selected we want the size to display S and XXL

We want the Vendor drop down to behave as follows

1. When Red colour and S is selected we want to display Vendor1,Vendor2 and Vendor3 to be displayed.
2. When Red colour and M is selected we want to display Vendor1 to be displayed.
3. When Red colour and L is selected we want to display Vendor1 to be displayed.
4. When Blue colour and L is selected we want to display Vendor2,Vendor4 to be displayed.
5. When Blue colour and XL is selected we want to display Vendor5 to be displayed.
6. When Green colour and XL is selected we want to display Vendor5,Vendor6 to be displayed.
7. When Green colour and XXL is selected we want to display Vendor6,Vendor7 to be displayed.

So first we will create a product called a TShirt with 3 advanced attributes Color, Size and Company.

Color attribute must be created first and then size as size drop down depends on Color and then Comapny attribute as Company depends on Size and Color selection.

For color attribute we will set up three options Red,Blue and Green.

Then for the size options we will set up the options as

1S,1M and 1L, these are for Red, that is the first selection and hence 1 is prepended to the options
2L and 2XL,these are for Blue, that is the second selection and hence 2 is prepended to the options
3S and 3XXL,these are for Green, that is the third selection and hence 3 is prepended to the options

Then for company options we will set up the options as

11Vendor1,11Vendor2,11Vendor3 are for Red and S, that is the first selection in the first drop down and the first selection in the second drop down and hence 11 is prepended.
12Vendor1 for Red and M, that is the first selection in the first drop down and the second selection in the second drop down and hence 12 is prepended.
12Vendor1 for Red and L, that is the first selection in the first drop down and the third selection in the second drop down and hence 13 is prepended.
and so on

For more clarity refer to the screenshot in the attachment.

Do not worry these number will not get displayed on the screen.

Now you will have to modify two files namely

addtocart_advanced_attribute.tpl.php and addtocart_form.tpl.php.

These modified files are available in the attachment.

These files are located at yoursite\components\com_virtuemart\themes\default\templates\product_details\includes

please take a back of the original files before you use this hack.

Please note that this hack has been developed for two attributes where one is dependent on another.
To include more attribute sets you will have to modify the javascript in addtocart_form.tpl.php






Roadrunna:
Just what i've been looking for.

When I select the second attribute though the number is appended back onto the start of the property name  :-\

vmlab:
Hi Roadrunna

Did you use all the code that I have used above ?

Roadrunna:
Yep,  I used the code in the zip and also copied the Javascript from your demo page as well.  Strangely I still get the same thing happening.

What I did notice afterwards is that your demo page suffers from another issue (which also happens on mine).
If you select from the 1st dropdown the 2nd list is populated with the correct options.  However, once you select and alter the option in the second dropdown if you click on it again you;ll see that it's fully populated with the complete list again.

I'm going to have a play around with it and also attempt to modify it for more than 2 attributes.  If I fix the issue I'll send you any changes I make.

Cheers.

dimitrakopoulos:
Hello from Greece, i upload all files as vmlab say but unfortunately i have the same problem with Roadrunna...
vmlab can you help us??

Navigation

[0] Message Index

[#] Next page

Go to full version