Upgrade Your Drupal Skills

We trained 1,000+ Drupal Developers over the last decade.

See Advanced Courses NAH, I know Enough

Drupal commerce & free shipping offers

Parent Feed: 

At Studio.gd, we love Drupal, and we’ve started to use Drupal Commerce and all its features in early 2012. Since, we created a bunch of sites using it. We found that Drupal Commerce is really extensible, you can really do, as in Drupal, all what you want to do.

To manage shipping with Drupal Commerce, you need the Commerce Shipping module. With that module, you can use shipping methods provided by contributed modules and/or create your custom shipping methods and services.

It’s a very common case in e-commerce that your clients want to offer free shipping to their customers when they order a certain quantity of products, or when they reach a defined amount of money, or whatever the condition.

The way to do it with Commerce Shipping and Rules

http://commerceguys.com/blog/advanced-commerce-shipping-configuration-free-shipping-based-order-total-and-role

This method forces you to create a new shipping service with a free amount and with some rules so that the right service is displayed to the client. That can be a problem when you have custom shipping services, when you have a lot of them, and you want to provide these exact custom services but with a free amount.

This method can be hard to configure and maintain. Also, it can be confusing for the UX too, as the free shipping rate are updated after the customer selects the shipping services.

The way we need it

As an administrator, we need a simple admin page that let us configure the free shipping for each service.

As a shop manager, we need to interact with the customer to let him know what happens.

As a customer, we need consistency on shipping prices all along the checkout process.

We decided to follow the logic of the drupal community, by using existing contributed module when they exists, or by contributing back to the drupal community when we have to create a module for more than one of our sites.

You can download and try this module here :
http://drupal.org/project/commerce_free_shipping

How ?

We use the hook provided by Commerce Shipping :

/**
 * Allows modules to alter the shipping services defined by other modules.
 *
 * @param $shipping_services
 *   The array of shipping services defined by other modules.
 *
 * @see hook_commerce_shipping_service_info()
 */
function hook_commerce_shipping_service_info_alter(&$shipping_services) {
  // No example.
}

Our implementation :

/**
 * Implements hook_commerce_shipping_service_info_alter().
 */
function commerce_free_shipping_commerce_shipping_service_info_alter(&$shipping_services) {
  if (empty($shipping_services)) {
    return;
  }
  foreach ($shipping_services as $name => $shipping_service) {
    $base = $shipping_service['base'];
    // Check if free shipping is enabled for this services.
    if (!variable_get($base . '_free_shipping_enabled', FALSE)) {
      continue;
    }
    $shipping_service['callbacks']['original_rate'] = $shipping_service['callbacks']['rate'];
    $shipping_service['callbacks']['rate'] = 'commerce_free_shipping_rate_callback';
    $shipping_services[$name] = $shipping_service;
  }

}

We add a sort of preprocess around the shipping service rate callback, we do all our checks in it, and then return the original callback rate or the free shipping rate.

We use this method to display the good price when the user chooses the shipping services, other method provided by Commerce Shipping lets you change the rate after the user picks up the shipping method, and we found that this is confusing for the UX.

Configuration

Go to the configuration page of this module, you got a list of your store shipping services.

Inside each fieldset there are free shipping settings and messages to display to the customer.

The customer point of view

The checkout pane that display the shipping services to the customer :

Thanks for reading

I hope this module will be a time saver for you too. Any advice or comment is welcome.

You can download and try this module here :
http://drupal.org/project/commerce_free_shipping
Original Post: 

About Drupal Sun

Drupal Sun is an Evolving Web project. It allows you to:

  • Do full-text search on all the articles in Drupal Planet (thanks to Apache Solr)
  • Facet based on tags, author, or feed
  • Flip through articles quickly (with j/k or arrow keys) to find what you're interested in
  • View the entire article text inline, or in the context of the site where it was created

See the blog post at Evolving Web

Evolving Web