I am looking for sample code to programmatically add to the Cart using for instance uc_cart_add_item where the price is needing to be set custom.
From what I understand;
uc_cart_add_item($nid, $qty, $data)

where $data is an arbitrary array of attributes.
What is the mapping within $data to alter the sell price of the item?

Comments

longwave’s picture

Status: Active » Fixed

There is no way of setting a price directly using $data, but you can set $data['attributes'] to force a particular set of attribute options.

If this is not what you need, you can implement hook_uc_product_alter() to change the product price; maybe the simplest way is to set $data['price'] and then set $node->price = $node->data['price'] in your hook implementation

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.