Dependent Attributes

mrfelton - October 21, 2008 - 11:15
Project:Ubercart
Version:6.x-2.x-dev
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:postponed
Description

I'm using Ubercart for a new D6 site I'm developing, but had the need for a feature that wasn't available. I wanted to introduce the concept of 'dependent attributes'. That is, a product attribute that is only available based on the value of another attribute. An example might help explain:

I'm selling language courses. Each language course is set up as a product in Ubercart and has several attributes that affect it's price. One such attribute is 'Accommodation Option' This could be a Single Room, Double Room or None. In the case of the user selecting a Single or Double Room, another option should be presented to the user, 'Accommodation Length', where the user can specify how long he/she would like the accommodation for.

In the above example, the 'Accommodation Length' attribute could be said to 'depend on' the 'Accommodation Option' attribute. I have written a module which lets you introduce attribute dependencies. Whilst at present it only offers rather basic functionality, it does function well for my needs and I'm sure other people would find a use for it so I would like to release it to the community.

Currently the module lets you choose one other attribute that the attribute depends on. It also lets you specify a list of attribute options that count as a null selection. In the example above, I entered the attribute option id (oid) of the 'None' value. When the user selects one of these null_values on the dependency, the dependent attribute is disabled with AJAX

Things to do before an official release can be made:
- Update/override form validation handler based on attribute visibility/presence

Possible extensions are:
- Ability to choose more than 1 dependency
- Ability to override dependencies at the product class and product levels
- Provide a nicer way of specifying the null_values (multiple select box? auto complete text area?)
- Allow users to choose if form elements should be disabled or completely removed
- Allow users to specify a default value for when elements are just disabled rather than removed.

Questions:

  1. What do you think of the idea?
  2. Has it already been implemented elsewhere?
  3. Would anybody be willing to help out with this module?
  4. If I release it as a contributed module, what do you think for a name? Currently I have it as uc_aad - Uberart Ajax Attribute Dependencies. I'm not sure about including AJAX and was thinking about uc_attribute_dependencies instead...

#1

mrfelton - October 21, 2008 - 16:24

Edit:
Things to do before an official release can be made:
- Update/override form validation handler based on attribute visibility/presence

#2

alpritt - October 22, 2008 - 22:25

If I've understood correctly this sounds similar to Hierarchical Select to me. Have a read of: http://www.ubercart.org/forum/development/5335/hierarchical_select_uberc...

#3

mrfelton - October 23, 2008 - 06:51

No, not really. I know about and use the Hierarchial Select module already. That module simply give you a nice AJAX way of browsing tree like structures and making selections from them (taxonomy for example). What I have done here is set up a dependency for an Ubercart product attribute. Which makes the attribute in question only required (or even available) if it's 'parent' attribute has been selected with a certain value.

#4

Island Usurper - December 29, 2008 - 20:06
Status:active» postponed

I don't know what's been done towards this issue, but I know that I won't get to it until we start working on the 3.x version. If someone has an update in a different direction, they are welcome to take over this issue.

#5

jpdaut - February 24, 2009 - 22:12

mrfelton: Just reading this for the first time today. This "dependant attributes" is exactly what I need. Where are you with your project, are you close to a contributed module on this?

Also, I'm running 5.x, and realize you're on D6.

#6

mrfelton - February 25, 2009 - 09:53

Well, I use what I have on a live site. However, I didn't really peruse much further (as in, create an actual contributed module) it as it sounded like this was something that would be implemented in the future, but in a more complete way that I went about it. You are welcome to my code if you like, but it is Drupal 6 only and I have no intention on backporting it. That said, if you think it is useful, and feel that other s would too, AND you are willing to backport and maintain a Drupal 5 version, then I would consider creating an official project out of it.

The code is attached. I haven't actually touched this code for a while, but as I say, I use it on a live D6 ubercart site without issue (although I haven't updated ubercart to the latest -dev code on that site for over a month now, so things may have changed)

EDIT: For an example of it in use, see: http://www.geminicourses.com/courses/bristol-school-language-project-gen.... Select an accommodation option, and you should see a new option appear below it.

AttachmentSize
uc_aad.tar_.gz 3.76 KB

#7

jpdaut - February 25, 2009 - 12:32

Thanks but I can't open the file in your attachment: it seems to be a binary file. Could you attach the file in ASCII? Thanks.

Your site looks great. I'm looking forward to backporting this to D5. An official project would make sense I think but let's address this after I implement the D5 port.

#8

jpdaut - February 25, 2009 - 13:19

Ok I was able to unpack your files after all. No need to resend them. I will look into this, thanks again.

#9

jpdaut - March 12, 2009 - 08:59

I'm hoping to have a chance to look at this fairly soon. Do you have a newer version? If so please send. Thanks.

#10

mrfelton - March 12, 2009 - 12:44

no, what I have there is the latest. I haven't worked on the site that uses this for a while.

#11

raintonr - June 2, 2009 - 21:51

This is a good idea and partly what I'm looking for. I'm looking for something like 'grouped' attributes.

Imagine a clothing store where certain garments are available in certain sizes and colours, but the colours vary depending on those sizes. Eg, the full list of options for a shirt might be:

Small, Red
Medium, Red
Medium, Blue
Large, Blue

Now, I know you are thinking that these could be created as 4 different attributes but that doesn't work if a user wants to search for all the 'medium' shirts available. To perform proper searching the attributes would have to be separate.

However, in the example, some sort of dependency or grouping would need enforcing to say for this product if the user chooses 'Small' they must choose 'Red'. If they choose 'Large' they must choose 'Blue'.

Does that make sense and do you think this is possible?

#12

Nick_vh - June 4, 2009 - 12:37

I agree with raintonnr! Please implement this as we need it :-)

#13

AntoineSolutions - November 5, 2009 - 00:14

I have introduced a new Dependent Attributes module. You can find the project at http://drupal.org/project/uc_dependent_attributes. There will be a development snapshot available within the next 24 hours. This module accomplishes what is requested in #11 and #12. I need testers so please download the snapshot as soon as it is available and begin testing.

Cheers,

Antoine

 
 

Drupal is a registered trademark of Dries Buytaert.