Hello,

I am trying to track down where during the shipping life cycle the rates are calculated and applied to each shipping method prior to displaying the shipping options to customers during the checkout.

Problem
I have several shipping options with different price points. The shipping rates are flat rates, it doesn't change based on the quantity or weight of a product. During the checkout process the customer is presented with one or more shipping methods based on the shipping address. The issue is "randomly" during a customer's checkout either the first time they reach the shipping methods panel or if the customer moves past the shipping step but returns to change an option.

The shipping method rate will either be off by a decimal ($10.00 becomes $0.10) or the total cost is set to zero $0.00!

This occurs no matter which product is provided or the address the customer is shipping to.

Research
I'm using several modules related to the commerce_shipping module and I've traced through every single one. If you have any recommendations on where to look I'd appreciate it greatly.

I think this is where the problem is happening. For some reason the drupal_static variable is loosing the rate values and or it become inconsistent.

function commerce_shipping_services($method = NULL) {
  // First check the static cache for a shipping services array.
  $shipping_services = &drupal_static(__FUNCTION__);

  // If it did not exist, fetch the services now.
  if (!isset($shipping_services)) {
    $shipping_services = array();

    // Find shipping services defined by hook_commerce_shipping_service_info().
    $weight = 0;

    foreach (module_implements('commerce_shipping_service_info') as $module) {
      foreach ((array) module_invoke($module, 'commerce_shipping_service_info') as $name => $shipping_service) {
        // Initialize shipping service properties if necessary.
        $defaults = array(
          'name' => $name,
          'base' => $name,
          'display_title' => $shipping_service['title'],
          'description' => '',
          'shipping_method' => '',
          'rules_component' => TRUE,
          'price_component' => $name,
          'weight' => $weight++,
          'callbacks' => array(),
          'module' => $module,
        );

        $shipping_service = array_merge($defaults, $shipping_service);

        // Merge in default callbacks.
        foreach (array('rate', 'details_form', 'details_form_validate', 'details_form_submit') as $callback) {
          if (!isset($shipping_service['callbacks'][$callback])) {
            $shipping_service['callbacks'][$callback] = $shipping_service['base'] . '_' . $callback;
          }
        }

        $shipping_services[$name] = $shipping_service;
      }
    }

    // Last allow the info to be altered by other modules.
    drupal_alter('commerce_shipping_service_info', $shipping_services);
  }

  // Filter out services that don't match the specified shipping method filter.
  if (!empty($method)) {
    $filtered_services = $shipping_services;

    foreach ($filtered_services as $name => $shipping_service) {
      if ($shipping_service['shipping_method'] != $method) {
        unset($filtered_services[$name]);
      }
    }

    return $filtered_services;
  }

  return $shipping_services;
}

Comments

emptyvoid’s picture

Status: Active » Closed (fixed)

I traced the issue to a hook that modifies the rates in my project. The module code appears to work just fine.