4 replies [Last post]
PaulW's picture
Offline
Joined: 05/23/2008
Juice: 148
Was this information Helpful?

Drupal 5.10
uc_event 5.x-1.0-rc2 (uc_event_2.zip)

I am developing a module in which I've overridden hook_form_submit($form_id, $form_values) with my own buy_events_form_submit($form_id, $form_values).

I am adding items to the cart using the following (I am determining $thisnode and $cartqty elsewhere in the module.):

uc_cart_add_item($thisnode,$cartqty);

The description and price in the shopping cart are, as expected:
The title is $node->title and the unit price is $node->sell_price.

I also need to add a second item for the same node to the shopping cart with a different description and price. I've attempted the following:

$node = node_load(array("nid" => $form_values['nid']));
$node->title = $node->title . ' (Non-member)';
$node->sell_price = $node->list_price;
drupal_set_message('<pre>$node values: '.print_r($node,true).'</pre>');
uc_cart_add_item($thisnode,$otherqty);

The set_message reveals that the title and sell_price have changed accordingly.

However, when the item is added to the cart, the original title and sell_price in the node has been added to the cart, not the new title and sell_price. Any thoughts on how I can override these two node fields when adding the second item?

Ryan's picture
Offline
Joined: 08/07/2007
Juice: 15438
Re: Overriding $node->sell_price and $node->title

Well, first of all your example still uses the previously defined $thisnode variable. However, the way items are added to the cart your code won't work anyways. There would have to be a separate product node w/ the correct title and price. UC stores the nid when products are added to the cart and updates the price from there so that the shopping cart always contains the latest title/price of products in it.

One option is to use attributes/options. The option chosen can be displayed in the cart to represent the differences in the title and options can affect the price of the product.

PaulW's picture
Offline
Joined: 05/23/2008
Juice: 148
Re: Re: Overriding $node->sell_price and $node->title

Yup. Thanks for your response.

I ended up creating an unpublished node for the event with an SKU similar to that for the event but with a specific suffix (I call it a "shadow event"). It's sell_price is the list_price for the normal event. (I'm using the list price for non-members and the sell-price for members.) I've used hook_form_alter to create a textbox for the user to indicate the number of non-member seats to purchase. With that quantity, I grab the nid of the "shadow event" and add that to the cart along with the regular member-price event. Seems to work OK.

By the way, your comment about price in the cart bothers me a bit.

Quote:

UC stores the nid when products are added to the cart and updates the price from there so that the shopping cart always contains the latest title/price of products in it.

If someone places an item in their cart and doesn't check out for a while - and then the price is changed before they check out. The item in their cart will have the new price, not the price that they expected to pay.

Ryan's picture
Offline
Joined: 08/07/2007
Juice: 15438
PaulW wrote:If someone
PaulW wrote:

If someone places an item in their cart and doesn't check out for a while - and then the price is changed before they check out. The item in their cart will have the new price, not the price that they expected to pay.

Exactly. This is by design, so a customer can't put an item in their cart and wait 3 months before buying it at an old price. That makes good business sense to me. Smiling (For our company, it can mean a difference of a couple hundred dollars.)

Just like you can't go sit at the gas station for a week and expect to pay the same price as when you pulled into the station. Eye-wink

PaulW's picture
Offline
Joined: 05/23/2008
Juice: 148
Re: PaulW wrote:If someone

Yes, I see what you mean. Thank you.