11 replies [Last post]
gajillion's picture
Offline
Joined: 08/25/2007
Juice: 70
Was this information Helpful?

Is anyone working on attribute dependencies for product selection? For instance, say I sell 3 different sizes of widgets but each widget comes in a different number of colors depending on the size: 4 colors for large widgets, 3 for medium, and 2 for small. When the user selects which size widget they want on a product purchase page, the color selection pulldown should reflect only the colors available for that widget. I believe the current logic for implementing this is to have a different product for each of the size/color combinations, which is very impractical for a large enough inventory.

Is anyone working on implementing this kind of functionality? If not, would there be any interest in seeing it implemented? I've done this for a previous customer in osCommerce so I have most of the logic already. Ajax-y type functionality wasn't around way back then Smiling so I had to do it with page refreshes or reallly large javascript arrays containing all the possible attribute combinations.

I'd also be interested in tying this to the inventory module so only in-stock combinations can be selected.

Mark

heribert's picture
Offline
Joined: 08/27/2007
Juice: 21
Hi! I plan to write a my own

Hi!

I plan to write a my own Attribute-System, that will be much more flexible, but i am very new to Drupal and especially writing modules for Drupal, so it will take a long time that I can show some results (may be january next year).

I think a few developers should plan (i will help, of course) a absolute flexible attribute system, because this part has many feature requests.
What do you think?

heribert

gajillion's picture
Offline
Joined: 08/25/2007
Juice: 70
Probably not as complex

Heribert - I'm not really looking for anything terribly complex. I think the attribute set up that's already there is sufficient for describing products, but what's missing - and seems to be missing in most eCommerce packages - is the ability to chain dependencies. We go live in a couple months so January is a little late for me. If no one else is already working on it, I'll probably just take a crack at it and see what I come up with.

Mark

Ryan's picture
Offline
Joined: 08/07/2007
Juice: 15438
Re: Probably not as complex

Just wanted to offer up a simple "Go for it!" here. Smiling This would be a great addition to the attributes module, though I can see it adding some complexity to the already "busy" attributes form. Once you've got a way to specify which attributes are dependent on what, you're going to need a menu callback that can return HTML for the new options. To bring it all together, you'll need to use Javascript to detect a change on the master attribute that uses jQuery's $.post() method to communicate w/ the site to get the new options. It won't necessarily be easy, but this kind of thing is happening all over the place (for example, zones getting updated when the country is changed).

I can't imagine this working well for situations w/ more than two attributes per product.

gajillion's picture
Offline
Joined: 08/25/2007
Juice: 70
Attention diverted

Err... ignore this if anyone read it. Just as I said we don't need dependent attributes, I found about 10 cases where indeed, we do.

gajillion's picture
Offline
Joined: 08/25/2007
Juice: 70
And again - replying to my own post

I've been working on this for a couple months now and I'm about 2/3rds done. That said, I'm sorry to say I'm going to bail on the entire idea for now. The reason is pretty simple: uc_attributes was not written with dependent attributes in mind, and would require a complete re-write to make it work as anything less than a complete hack.

The problem is this: uc_attributes refers to "attributes" and "options". While they are essentially the same thing, "attributes" have a few more fields, referents, and (pardon the self reference) attributes than do options. However, in order to have dependent attributes, every possible option has to be able to be treated as an attribute, which they currently aren't. This made for some horribly awkward coding where you first have to check if you're at the top layer of a potential recursion tree, deal with it as an "attribute", then start your recursion, potentially treating "options" as attributes, and, if necessary, re-write the attribute specific portion of the code.

To have dependent attributes, you would need to take all of the existing attributes and make them options, or vice-versa, either eliminating the attribute specific attributes (like 'aid'), or adding them to options. You can then create a simple mapping table of parent <-> child relationships to show the dependencies. Something like this:

parent  aid
0       1
0       2
0       3
1       4
1       5
2       6
3       7
3       8
3       9
...

Where attributes 1-3 would be treated like "attributes" currently are, and 4-5 are attributes dependent on attribute 1, 6 on 2, and 7-9 on 3. I implemented something akin to this in my hack, but working around all the vagaries and differences between an "attribute" and an "option" just became too much, and I've got to get the rest of the site up and running for now Smiling

I'll come back to this if there's still interest at a later time, but backward compatibility may become an issue.

lostcarpark's picture
Offline
Joined: 09/22/2007
Juice: 109
Re: And again - replying to my own post

This sounds like it would be a really useful feature, but I can see how it would be difficult to build on the current attribute system. Ideally you would like a multi-way hierarchy, where selecting attribute 1 makes attributes 4, 5 and 7 available, while at the same time, selecting attribute 4 makes attributes 1 and 3 available. This means that if I'm sure I want the sweater in X-Large, I can only have red or green. On the other hand, if I have my heart set on having it in blue, I can have the choice of squeezing into a large. This could be implemented by having all the drop-downs fully populated when the page loads, but when you select an item from any list it removes items that are no longer valid from the others.

These sort of relationships are not very hard to set up in a relational database, but coming up with a clear and simple user interface can be a real challenge, and it gets more difficult as the number of attributes goes up. For two attributes, you could have a simple grid, with one set of attributes across the top, and another down the side, and a checkbox in each cell that you tick to indicate the combination is available. You'd have to come up with something else for three or more sets.

Good luck with this. It sounds very interesting, and sounds like there's a certain amount of overlap with the subproducts idea I raised in another thread.

bloke_zero's picture
Offline
Joined: 03/24/2009
Juice: 62
jquery

Yes, you can kind of do this with j-query and adding hidden fields to the options but it's pretty labour intensive and not pretty. Any one got any further with a module?

------------------------------
http://zero-design.info

SeanK's picture
Offline
Joined: 03/29/2009
Juice: 63
Re: jquery

I've been looking into the same thing and I think it can be done with the following two modules, but I've yet to test it. One is in development, the other is in beta, so maybe we can help out.

Ubercart Stock Manager With Attributes: http://drupal.org/project/uc_multi_stock
UC Attribute Stock Filter: http://drupal.org/project/uc_attribute_stock_filter

AntoineSolutions's picture
Offline
Bug Finder
Joined: 05/02/2008
Juice: 166
Ubercart Dependent Attributes module available!!!

I have just released a Dependent Attributes module at http://drupal.org/project/uc_dependent_attributes. A development snapshot should be available within the next 24 hours. This module provides answers to many of the requests on this thread. I could use some testers and a few additional eyes on the code wouldn't hurt either. Grab the download when it's available and lets get this thing flushed out and ready for live sites.

Cheers,

Jon Antoine
Antoine Solutions
Free Open Source PHP IDE

thedarkflop's picture
Offline
Joined: 07/19/2008
Juice: 25
Looking forward to some testing

I am looking forward to some testing with this. I really enjoy drupal and ubercart but I have to say this is the one main thing that is really holding up us moving on ubercart. Our products have a several variables which each control price and availability so something like this would be very great indeed.
Thanks for the great work on this so far Antoine.

robbie's picture
Offline
Joined: 03/17/2010
Juice: 107
Re: Dependent attributes?

I have faced the same problem!

I have to say that While AntoineSolutions's Dependent Attributes module is good for small sites that has limited number of product. You have to click into the edit >> adjustment tab to enable/disable each combinations, which can be extremely tedious for mid to large shops. I have developed my own module, called Chained Attributes and Options (CANO). I released it as RC because it's only tested on my sponsor's website yet. It seems to be stable. Everyone is welcome to use it: http://www.ubercart.org/project/uc_cano

Please, for us to improve the module, we need your feedback!