add_to_cart - idea/feature request

Posts: 88
Joined: 01/02/2008
Bug Finder

With a really simple product (single attribute - no options), when you add to cart $data contains:

Array
(
  [attributes] => Array
  (
    [1] => 123
  )

  [model] =>
  [module] => uc_product
  [shippable] => 0
)

I'm thinking it would be really nice to have it do something more like :

Array
(
  [attributes] => Array
  (
    [1] => Array
    (
      [name] => attribute_name
      [value] => 123
    )
  )

  [model] =>
  [module] => uc_product
  [shippable] => 0
)

I found this because i'm trying to create a contrib which will validate any attributes with the word "email" in them to be valid email addresses. Could be too edge case, but seems nice to me.

Guessing it would need an extra query in uc_attribute_add_to_cart_data.

What do you think?

Posts: 82
Joined: 08/12/2007
Uber DonorBug FinderInternationalizationizer

+1 to this!
I remember that I had a very similar problem last week.

+2 if there would also be the attribute id, AND the option ids in the array!

Posts: 2271
Joined: 08/07/2007
AdministratoreLiTe!

At this point it's a little late to mess with the data given to the cart. I think it's a good idea though, so it'll be considered for the future.

Until then, I think your module can use uc_attribute_load() to get all the information about the attribute and option for that product. An extra query is needed anyway, so you can control exactly when it is done and the information you get out of it.