When displaying products in e.g. Commerce Kickstart with Stock enabled, it seems to me it is kind of negative UX for the visitor to see the Out of Stock message when the first variation in the list is out of stock.

A customer may abandon the purchase if they think the product is totally out of stock, whereas some other size / color combination may be in stock.

It would be handy to have a setting in the preferences for this module to always show the first variation (size / color / other attribute combo) that IS in stock.

This way they will not be immediately discouraged and if they do manually select a combo that happens to not be in stock, that's much better than not even bothering because they think it's unavailable.

Comments

guy_schneerson’s picture

yes I agree this would be a great addition but not the easiest to implement, we get around this issue by setting an out of stock msg "out of stock - try another size or colour'

marktheshark’s picture

I assume the logic to implement would be to query for the stock level of each choice to populate in the combo box and set the 'selected' attribute on the first non-zero stock level, right?

As for the message to display, is this already configurable?

marktheshark’s picture

Any progress on this? Thanks in advance

guy_schneerson’s picture

I had another look at this and all indications are that the core commerce product add to cart from dosen't support a 'selected' product, even when I managed to change it, in the combo box it showed the details for the wrong product.

marktheshark’s picture

Thanks for looking into this.

This is a potential cause for driving away customers because they think there is no availability.

An informational message would be most helpful, though as a workaround I could probably add a block that says: "if the currently selected variation is out of stock, please try a different combination".

guy_schneerson’s picture

It is also possible to add the msg only if out of stock.

marktheshark’s picture

In the current module, or in the custom block?

Do you advise this is checked via JS?

guy_schneerson’s picture

A few options are available:

  • You can configure the standard stock action to say something like "Out of stock try a another size"
  • You can try and use the advance cart configuration action to re write the form action and add a text msg.
  • You can look at the hook_form_alter module (in sandbox) this integrates with commerce stock and you can add a second action from the same stock event.

And my favorite:
You can use the new "Commerce Stock Decimal formatter" (you will need to enable the module under the commerce stock section)
To configure:

  1. Enable the module
  2. go to the product display i.e. products/types/product/display
  3. select the format "Show stock display as message" for the stock field
  4. Configure the formtter to:
    If stock <= 0 Message: "Currently out of stock - try a different variation"
    make sure the stock field is positioned above or below your cart form
guy_schneerson’s picture

Title: UX improvement: allow showing first product variation that IS in stock » UX improvement: allow showing first product variation that is in stock

Thanks @MrPaulDriver to pointing the following #2084869: Option to direct buy button to 'in-stock' variations. :

In the following post, https://drupal.org/node/1637786#comment-7551813 Ryan suggests that the stock module could be modified to point the buy button to a variation that is in stock and I ask whether this improvement could be incorporated into the stock module

marktheshark’s picture

+1

MrPaulDriver’s picture

The stock message formatter is a very good tool in it's own right and helps somewhat with this problem.

Ideally, Commerce should not default to the first variation but instead should have a normal select function with a prompt saying 'Please select an option' or whatever.

As an interim workaround, if the stock module could be made to point the buy button at the first variation in stock I think this would be really positive move forward.

marktheshark’s picture

Come to think of it, I don't know if the stock module is the place to do this.

Stock probably doesn't know how the products are presented in order to default to an available variation.

MrPaulDriver’s picture

Above my paygrade I'm affraid, just listening to Ryan at https://drupal.org/node/1637786#comment-7551813

guy_schneerson’s picture

marktheshark, MrPaulDriver
If this hook works than its perfect for the Stock module, will look into it when I get a chance.

Neo13’s picture

Issue summary: View changes

For anyone trying to solve this. Here is a nice little module - https://www.drupal.org/project/commerce_stocked_default

John Pitcairn’s picture

We're using the hook mentioned. Something like this:

/**
 * Implements hook_commerce_product_reference_default_delta_alter().
 */
function MYMODULE_commerce_product_reference_default_delta_alter(&$delta, $products) {
  // Check whether the default is in stock.
  $stock = field_get_items('commerce_product', $products[$delta], 'commerce_stock');
  if ($stock[0]['value'] == '0.00') {
    // Find the first product in stock.
    foreach ($products as $key => $product) {
      $stock = field_get_items('commerce_product', $product, 'commerce_stock');
      if ($stock[0]['value'] != '0.00') {
        $delta = $key;
        break;
      }
    }
  }
}