We're using Commerce Shipping and Commerce UPS to calculate shipping rates. We want to round the calculated rate displayed during checkout up to the nearest dollar.

Just to be clear we want to update the value of each Radio option on the Shipping Options page of checkout; NOT the Commerce Line Items.

I thought it might be possible via Rules but I cannot figure out a starting place. All the Commerce Shipping Rules seem to be about altering the line item; not the calculated value.

I tried the following which does not work. Do the callback functions override what I was trying to do? If so, is there an easy way to STOP the callback from recalculating the shipping after the page loads?

Or is this some obvious mistake?


function MYMODULE_form_commerce_checkout_form_shipping_alter(&$form, &$form_state, $form_id) { foreach($form['commerce_shipping']['shipping_rates']['#value'] as $values) { dpm($values); $newval = 100*(commerce_round(COMMERCE_ROUND_HALF_UP, $values->commerce_unit_price['und']['0']['amount']/100) ); $values->commerce_unit_price['und']['0']['amount'] = $newval; $values->commerce_unit_price['und']['0']['data']['components'][0]['price']['amount'] = $newval; } }

  • Try changing $values to &$values in the foreach
    – Clive
    Apr 2, 2015 at 22:27
  • You mean like this? &$values->commerce_unit_price['und']['0']['amount'] = $newval; Gives me a parser error.
    – jchwebdev
    Apr 2, 2015 at 22:42
  • In the declaration itself: ...as &$values)
    – Clive
    Apr 2, 2015 at 22:44
  • Made no difference. It looks like there is a callback function on each service has a callback function and is updated via AJAX which in turn calls a Rule which then calls the actual rate calculator code (Eg. ' commerce_ups_service_rate_order();). Eg. Is there a way to hook into -that-? (BTW: is there an -easy- way to print out the contents of a DPM array? As in all nested levels?)
    – jchwebdev
    Apr 2, 2015 at 23:34


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.