I want 'sell' a donation for custom donation amounts, and I know that to do this, I will need to use line items. I wrote the following code which I thought would do the trick, but when I go to /cart, I see that the price has remained the same.
global $user; if(user_is_logged_in()) { //$order_id = commerce_cart_order_id($user->uid); //$order = commerce_order_load($order_id); $order = commerce_cart_order_load($user->uid); } else { $order = commerce_cart_order_load(); //no uid since user is not logged in. attempts to load an anonymous order from the session. } //var_dump($form_state['values']['donation-custom-amount']); $lineItem = commerce_line_item_load($order->commerce_line_items['und'][0]['line_item_id']); if($form_state['values']['donation-custom-amount'] !== "") { //if the user entered a custom amount $lineItem->commerce_unit_price['und'][0]['amount'] = $form_state['values']['donation-custom-amount']; $lineItem->commerce_total_price['und'][0]['amount'] = $form_state['values']['donation-custom-amount']; } else { $lineItem->commerce_unit_price['und'][0]['amount'] = $form_state['values']['donation-amount']; } commerce_line_item_save($lineItem);
I checked that $form_state['values'] was giving me the form data, and there are no errors, just no price change.