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

All,
Having given up on implementing dependent attributes, can someone point me to an example or give some recommendations on the best way to set up Ubercart to implement the functionality we need?

The product is a "design" or picture, so the entire site is built around creating, editing, and critiquing these designs or pictures. Once the design is complete, it can be applied to one of three products, a cup, a mug, or a plate. Each of these products can come in one of a number of colors (which will vary based on the design and product).

What I'd like is to have one product page featuring the design. Then, on that page, be able to select a product and color for that design. However, the colors for one product aren't necessarily going to be available for all of the other products. For instance,

Design "A" would be available on

Red cup, white cup
Red mug, blue mug, white mug
Blue plate, white plate

Now, I can't use [Cup, Mug, Plate] as one attribute and [Red, White, Blue] as another attribute because that would create invalid combinations (Red plate, Blue, cup).

Any thoughts on the best way to do this?

cYu
cYu's picture
Offline
Bug FinderGetting busy with the Ubercode.
Joined: 11/19/2007
Juice: 850
Re: Examples or recommendations on best way to set up?

This problem has cropped up before and I believe the suggestion was just to list each combination as a separate option to one attribute.

gajillion's picture
Offline
Joined: 08/25/2007
Juice: 70
Re: Re: Examples or recommendations on best way to set up?

And just to follow up on my original question, I'm following cYu's suggestion:

cYu wrote:

This problem has cropped up before and I believe the suggestion was just to list each combination as a separate option to one attribute.

But what I'm doing is creating a "grid" of products with stock level indicators instead of using the pull-down menu. Thanks for the suggestion. Once I have that working and have something I can roll out, I'll look at writing a new attribute module.

natcolley's picture
Offline
Joined: 01/13/2008
Juice: 48
interested party

I'm just jumping in so I can track this issue. Up to now it seems like the best way to handle attribute combinations that don't exist/aren't for sale was to give each their own sku and then set the inventory to zero. Is this right? I'm still feeling my way thru ubercart, so if I'm off base, fine, just let me know. I'm learning by doing because even when I read the documentation sometimes I have no idea what you're talking about until I try it and see it myself.

gajillion's picture
Offline
Joined: 08/25/2007
Juice: 70
That's about right

That's what I ended up doing. I automated the process and used a standard for SKU creation so I could just use the SKUs and parse out information I need for my phase 1 implementation (see attached). It worked out pretty slick but I'll still probably follow the above recommendations and write my own attribute module eventually.

AttachmentSize
product_grid.JPG 16.57 KB
Ryan's picture
Offline
Joined: 08/07/2007
Juice: 15438
Re: Examples or recommendations on best way to set up?

Just out of curiosity... what led you to give up on the dependent attributes?

If it was lack of ideas and not necessarily coding skill you can try this...

Thinking outside the box, something you could do would be to add the attributes but not assign any attributes to them. Then, use hook_form_alter() to change the textfields that show up on the add to cart form into select boxes. Populate the first one (product type?) and disable the second one. Then, use JS to determine what options to add to the color select depending on what product was chosen. Add those options and enable the select.

Attributes with no options will take whatever value they find, so you changing the types of the elements won't affect the form submission at all.

gajillion's picture
Offline
Joined: 08/25/2007
Juice: 70
Giving up

I'm not knocking anything or anyone, but what made me give up was the fact that Ubercart isn't really designed with dependent attributes in mind. When you start looking at dependent attributes, the distinction between an "attribute" and an "option" quickly disappears. Any "option" can become an "attribute" upon which some other "option" is based. When I did this in osCommerce, there wasn't any distinction between attributes and options - in fact, the concept of "attribute" didn't even exist. Therefore it was a simple matter of just creating a dependency table of

Parent Attr #, Child Attr #

where anything with no Parent Attr would be what Ubercart considers an "attribute" and everything else is considered an option. Unfortunately in Ubercart I found that attributes and options were handled differently so I ended up with a special case for every "top level" attribute. So what should have been very clean recursive functions turned into skimming the first option, and determining if it should be handled as an attribute or an option. If it was an option, then call the recursive procedure, otherwise handle it like an attribute in a different function.

The portion of code where I converted an option back and forth to a dependent attribute and not was actually pretty easy and is already done. My only database change was adding this `parent` mediumint(9) NOT NULL default 0, to uc_attributes and uc_attribute_options. But then, when it came to displaying and managing the data (specifically, modifying the code for edit/options so options with dependent attributes were displayed like attributes instead of options) it turned into a nightmarish hack-job, basically having to treat every option with dependents as a special case.

I haven't given up completely on the idea, but we're going to be launching soon (relatively speaking) and I just couldn't spend any more time on making it work. I like your idea, but with what I was able to get done, I believe I already was beyond that - only dependent options were displayed. Like I said, creating the dependencies was relatively easy. Managing, editing, and displaying them became the real trick.

I think the way to approach this is to ignore uc_attributes altogether because there's really nothing in there that's not also in uc_attribute_options. The only difference is 'aid' which just establishes a relationship between an attribute and an option. The 'parent' field does the same thing, but it's self referential - the contents of the parent field is just an 'oid' from the same table, or '0' meaning it has no parent. In the code, anything that references uc_attributes would just reference uc_attribute_options where 'parent' = 0; But that's such a huge logical difference I don't know if it would be possible to do that and still make it compatible with existing data.

Ryan's picture
Offline
Joined: 08/07/2007
Juice: 15438
Re: Giving up

gajillion, if you don't need to use Ubercart's adjustments stuff, you could just create your own attributes module... heck, you could even make it use Ubercart's same adjustment tables and be compatible with everything. You can use hook_cart_item() to add data to the products coming into the cart and simply mimic the default attribute module where necessary.

gajillion's picture
Offline
Joined: 08/25/2007
Juice: 70
Re: Re: Giving up

That's interesting. Hadn't thought about that. Let me look at that approach instead.