You are here

function commerce_cps_shipping_pane in Commerce Cart Pane 7

Shipping cart pane callback

1 string reference to 'commerce_cps_shipping_pane'
commerce_cps_commerce_cp_info in modules/shipping/commerce_cps.module
Implements hook_commerce_cp_info().

File

modules/shipping/commerce_cps.module, line 20

Code

function commerce_cps_shipping_pane($form, $form_state, $cart_order, $pane_weight) {
  $form_pane = array();

  // Collect shipping rates for the order.
  commerce_shipping_collect_rates($cart_order);

  // Generate an array of shipping service rate options.
  $options = commerce_shipping_service_rate_options($cart_order, $form_state);
  $shipping_default = commerce_cps_get_order_shipping($cart_order);

  // check case when user visited Checkout page and came back to Cart page directly (without clicking Cancel button). In this case we have to drop order status to 'cart' as it's 'checkout_checkout' now and if user will click on 'Update cart' button it will be changed to 'cart' and shipping will be reseted as well.
  // So we have to check status and reset status and shipping manually
  if ($cart_order->status == 'checkout_checkout') {
    $cart_order->status = 'cart';
    commerce_cps_add_order_shipping($cart_order, $shipping_default);
  }
  $form_pane['shipping_method'] = array(
    '#type' => 'radios',
    '#title' => t('Shipping methods'),
    '#options' => $options,
    '#default_value' => $shipping_default,
    '#ajax' => array(
      'callback' => 'commerce_cps_shipping_ajax_refresh',
    ),
    '#weight' => $pane_weight,
  );

  // we'll use order in ajax callback that will reload a cart page
  $form_pane['order'] = array(
    '#type' => 'value',
    '#value' => $cart_order,
  );
  return $form_pane;
}