0

i have a View that provides a list of products(content type Product). This view has two sort criteria. The one is the "SKU" and the second is "New product". The "New product" is a List(float) field and the available options are N/A, Yes and No.

The view must show first the new products and then all the rest. New products are considered those that they have selected the option "Yes".

Is this possible? Any idea?

Thank

0

You can do it using views_query_alter. Find out what are the key values being stored from your list and then use them accordingly in the code below.

function yourmodule_views_query_alter(&$view, &$query) { 
  if ($view->name == 'shop' && $view->current_display == 'page') {
     $query->orderby[0] = array(
           'field' => 'CASE table.type WHEN '1' THEN 1 WHEN '0' THEN 2 WHEN    
            ELSE 3 END');
  }
}
  • Hi, as i am not programmer could you please tell me the exact syntax? The field is : field_new_product with values 0|NO 1|YES View name : shop Machine name : page Thanks – drupspark Jun 27 '14 at 12:34
  • Have a look at drupal.org/node/1074360 to learn how to create your modules. – Gokul N K Jul 1 '14 at 6:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.