There doesn't seem to be any means of changing the order of products in the "Listing Option" droplist.

Products appear in a fixed but strangely peculiar order! It almost seems to be alphabetic up to the first character difference then reverse alphabetic! (it's not alphabetic SKU order either - already tried that!).

Can a means be added to re-order the list or at the very least put it into SKU alphabetic or price order.

Comments

Florpunch’s picture

I have the same request. It could be interesting to be able to order the products in the "Listing Option".

Jedd Casella’s picture

I had a bit of a play with this on a dev site recently. I found if you add an asort() to the $products array in the function commerce_node_checkout_get_node_type_product_list the list will sort by price from highest to lowest.

marty.true’s picture

Bump... issue is still persisting after a year and a half. This is really bad UX and would love to see some efforts on this.

arlingtonvoicellc’s picture

FYI: the order of the list is determined alphanumerically by the product ID. I found a quick workaround is to change the product_id for each item. In my case, my ID's changed from:

1_day
2_days
5_days
7_days

to:

1_1_days
2_2_days
3_5_days
4_7_days

jhonatanfdez’s picture

Goodnight. My name is Jonathan Fernández. Excuse my English, but I want to show how I could order the product field for the SKU.
Example SKU:
SKU - Title
0 Free Product - Free Product.
1 Payment Product - Payment Product.

In order to sort this field, I had to create a custom module. Please change the word "order_product" for the name of your module.

order_product.module

<?php

/**
 * Hook_info_alter()
 * 
 * Change call back function
 */    
 
function order_product_element_info_alter(&$type) {
  // change the call_back function
  if (isset($type['commerce_node_checkout']['#type']) && $type['commerce_node_checkout']['#type'] == 'commerce_node_checkout') {
    $type['commerce_node_checkout']['#process'][0] ='order_product_process_element';
  }
}

/**
 * Element process callback to build the product selection form widget
 * for a node.
 * Change label and helptext
 */
function order_product_process_element($element) {
  // Get the available products for this node
                            
  $products = order_product_commerce_node_checkout_get_node_type_product_list($element['#node_type']);

  // Add a selection for the product
  $element['commerce_node_checkout_product'] = array(
    '#type' => (count($products) > 1) ? 'select' : 'radios',
    '#title' => t('Product List'),
    '#options' => $products,
    '#description' => t('Select your desired listing option.'),
    '#default_value' => key($products),
    '#required' => TRUE,
    '#access' => !empty($products),
  );

  return $element;
}





/**
 * Provide a formatted list of products enabled for a specific node type
 * that can be used to present to a user.
 *
 * @param $type
 *   The node type.
 * @return
 *   An array of products keyed by product ID with a value of the product
 *   name with the price appended.
 */
function order_product_commerce_node_checkout_get_node_type_product_list($type) {
  $products = array();
 
  //we update the variable indicated in the module "commerce_node_checkout.module", with the product list order by sku
  variable_set('commerce_node_checkout_products_classified',order_product_commerce_node_checkout_get_product_list());

 
  // See if this node type has enabled products
  if ($enabled = commerce_node_checkout_get_node_type_enabled_products($type)) {
    // Load and iterate the enabled products
    
    
    foreach (commerce_product_load_multiple($enabled) as $pid => $product) {
      if ($product->status==1) {
              
              // Create a wrapper
              $wrapper = entity_metadata_wrapper('commerce_product', $product);
        
              // Extract the price
              $price_data = $wrapper->commerce_price->value();
              $price = commerce_currency_format($price_data['amount'], $price_data['currency_code'], $product);
        
              // Format the title along with the price
              $products[$pid] = $wrapper->title->value() . ($price ? (' - ' . $price) : '');
      }
    }
  }

  return $products;
}



/**
 * Fetch the a list of available products for all node types.
 *
 * @param $available_products
 *   An optional array of product IDs to filter the list by.
 * @return array
 *   Array of product names keyed by product ID.
 */
function order_product_commerce_node_checkout_get_product_list($available_products = array()) {
  $options = array();

  // Set the options for the search
  $field = array('field_name' => 'commerce_node_checkout_products');
  $instance = array('settings' => array('referenceable_types' => array('commerce_node_checkout')));

  // Execute the search
  $products = commerce_product_match_products($field, $instance, '', 'contains', $available_products);

  // Loop through all product matches.
  foreach ($products as $pid => $data) {
    // Add them to the options list.
    $options[] = $pid;
  }

  return $options;
}