drupal_commerce - Skip shipping page on checkout flow
Error message
- Deprecated function: Methods with the same name as their class will not be constructors in a future version of PHP; GeSHi has a deprecated constructor in require_once() (line 818 of /home/xenyomed/public_html/sites/all/modules/libraries/libraries.module).
- Deprecated function: Function create_function() is deprecated in GeSHi->_optimize_regexp_list_tokens_to_string() (line 4736 of /home/xenyomed/public_html/sites/all/libraries/geshi/geshi.php).
- Deprecated function: Methods with the same name as their class will not be constructors in a future version of PHP; ctools_context has a deprecated constructor in require_once() (line 127 of /home/xenyomed/public_html/sites/all/modules/ctools/ctools.module).
- Deprecated function: Methods with the same name as their class will not be constructors in a future version of PHP; ctools_context_required has a deprecated constructor in require_once() (line 127 of /home/xenyomed/public_html/sites/all/modules/ctools/ctools.module).
- Deprecated function: Methods with the same name as their class will not be constructors in a future version of PHP; ctools_context_optional has a deprecated constructor in require_once() (line 127 of /home/xenyomed/public_html/sites/all/modules/ctools/ctools.module).
- Deprecated function: The each() function is deprecated. This message will be suppressed on further calls in _menu_load_objects() (line 579 of /home/xenyomed/public_html/includes/menu.inc).
/*
* Implements hook_commerce_checkout_router()
* Skip shipping page in checkout flow
*/
function MY_MODULE_commerce_checkout_router($order, $checkout_page) {
if ($checkout_page['page_id'] == 'shipping') {
//calculate shipping charge
commerce_shipping_collect_rates($order);
//update order status - @see commerce_checkout_form_submit
$order = commerce_order_status_update($order, 'checkout_' . $checkout_page['next_page'], FALSE, TRUE, t('Shipping Page was skipped'));
$form_state = array(
'order' => $order,
'checkout_page' => $checkout_page,
'rebuild' => FALSE,
);
$form_state['build_info']['args'][0] = $order;
$form_state['build_info']['args'][1] = $checkout_page;
$form_state['values']['commerce_shipping']['shipping_rates'] = $order->shipping_rates;
foreach ($order->shipping_rates as $key => $shipping_method) {
if (empty($form_state['values']['commerce_shipping']['shipping_service'])) {
$form_state['values']['commerce_shipping']['shipping_service'] = $key;
}
}
$form = drupal_get_form('commerce_checkout_form_shipping', $order, $checkout_page);
//run commerce_shipping_pane callback include validate and submit function
commerce_checkout_form_validate($form, $form_state);
drupal_goto('checkout/' . $order->order_id . '/' . $checkout_page['next_page']);
}
}