3 replies [Last post]
timdiacon's picture
Joined: 12/13/2009
Juice: 23
Was this information Helpful?

Hey, I'm adding a product which has some options to my cart using uc_cart_add_item like so...

$data = array('nid' => $productId, 'qty' => '1', 'attributes' => array (1 =>$materialOption, 2 => $packagingOption), 'shippable' => '1');

It works as expected the product is placed in the cart and you can see that the correct options have been added. However one option is supposed to adjust the SKU and it is not working.

If I add the product with the same options through the html product page the SKU is correctly adjusted but if I use the method (uc_cart_add_item) it doesn't.

I'm not sure if this is a bug or if I need to send an additional attribute to make this work (I previously discovered I needed the "shippable" attribute to make the postage quotes work!)

Any ideas?

jpdaut's picture
Joined: 02/25/2009
Juice: 70
Re: uc_cart_add_item - not adjusting SKU

I'm having the same problem. Did you find a way to make this work?

MatteusX's picture
Joined: 03/25/2009
Juice: 18
Re: uc_cart_add_item - not adjusting SKU

Also having this problem. edit: It turns out my problem was referring to the attributes by their text names instead of their numeric ids. I got surprisingly far doing it the wrong way, but it turns out you do need to use the numeric attribute IDs. Like this:

uc_cart_add_item($nid, $qty, array(1=>4, 2=>'Blue')); // good

and not like:

uc_cart_add_item($nid, $qty, array('size'=>4, 'color'=>'Blue')); // bad

It looks like the OP was already using the correct method, so this won't be any help to him. But, it should help someone else. I've seen uc_cart_add_item examples where text attribute IDs are used - but for my version of Ubercart, 6.x-2.4 (old yes) this is how I had to do it.

veeray's picture
Joined: 10/14/2013
Juice: 4
multiple options per attribute

That is very helpful. but I am still wondering what the structure us for the $data array if you have checkbox attributes with multiple option values.