7 replies [Last post]
agilpwc's picture
Offline
Joined: 12/10/2007
Juice: 213
Was this information Helpful?

Hi
I want to use hook_cart_item to modify the value of a couple attributes when the item is added to the cart.
hook_cart_item is passed $item, but I can't figure out how to get to the attributes of the item and change a couple of them.

Any help would be appreciated.
Eric

heribert's picture
Offline
Joined: 08/27/2007
Juice: 21
Re: hook_cart_item modify value of attribute

Are you looking for $item->data['attributes'] ?

agilpwc's picture
Offline
Joined: 12/10/2007
Juice: 213
Re: hook_cart_item modify value of attribute

Well I came up with a workable solution, I hooked into add_to_cart_data. Not sure if it is the best way.

It didn't seem like hook_cart_item allowed me to actually change the value of attributes.

sleepingmonk@drupal.org's picture
Offline
Joined: 01/20/2008
Juice: 81
Can you give an example?

Hi,

I'm developing a module that needs to add a customized item to the cart.

I can get it to add the item and quantity with uc_cart_add_item but I'm not sure how to pass in selected attributes.

Any advice?

Thanks alot!

-Calvin

"I've had this birthmark since I was born." --JB

slayerment's picture
Offline
Uber Donor
Joined: 01/06/2008
Juice: 86
Hi Calvin, You should look

Hi Calvin,

You should look into Cart Links as this will allow you to add attributes.

Quinton

sleepingmonk@drupal.org's picture
Offline
Joined: 01/20/2008
Juice: 81
Thanks for the idea.

Thanks for the idea, but this isn't quite what I was looking for. My module creates custom attributes on the fly for a specific product called "custom" based on user input. I was able to get my module to add the "custom" product to the cart but wasn't able to include a list of customized attributes.

I have figured that out as of yesterday. It was a matter of passing the correct array to uc_cart_add_item(). To figure that out I waded through a lot of uc core modules to see how they did things.

All is right in the world once again.

"I've had this birthmark since I was born." --JB

michels's picture
Offline
Uber DonorBug FinderInternationalizationizer
Joined: 08/12/2007
Juice: 205
Hey sleepingmonk. I'm really

Hey sleepingmonk.

I'm really interested in your module, cause I'm planning sth similar. Could you contribute it? Would be really nice.

Thanks.
Mic

sleepingmonk@drupal.org's picture
Offline
Joined: 01/20/2008
Juice: 81
Very specific

Hi Mic,

Unfortunately, at this time the module is written for very specific client needs. I'd have to generalize it and add Admin functions so you could configure it to generate the type of attributes you want. There are currently no Admin Functions, everything is hard coded into the module.

I'm not sure when I'll be able to contribute it but I'll put it on my list of things to do.

-sleepingmonk

"I've had this birthmark since I was born." --JB