1
Answers
Vote up!
0
Vote down!

How to sort product list on SKU content?

Despite reading many articles of other kickstart users who try to sort on the SKU without success, like them I cannot find any solution for the following:

I use something like AB1234-knife and AB1234-spoon as the SKU

If I search in AB1234 I get both correct presented in the product list results which is intended. Both items were added at a random point in time, so, in the unfiltered product list they don't show up next to each other, thats due to the basic sort like 'newest not top' in the product list display.

I want to have the product list sorted on SKU, the sort filter above the page (newest/oldest, title etc) is irrelevant for me though sorting on 'newest' remains handy. Problem is that as I cannot add the sku in that section so I cannot create a sorted product page by making this the default in the search api, I cannot add it here either (and then add 'default and descending'. So I tried to override this by forcing the product display to sort on the sku and then on descending. But this also seems completely impossible.

There is no SKU field in the product view sort criteria (at /products). However, I can add this add a field in 'Fields -> add' when I use HTML with forced fields. Yet it still does not appear in 'sort' and neither in 'Relationships -> add'.

So how do you make a product list to be sorted on the SKU only and bypass the search api sort or add the SKU to the search api and make it here the default descending order? (tab Sorts)

It should be simple but despite reading for weeks now I cannot find any solution for such a simple concept. can anyone guid me to a solution or tell me if this is a mistake in the Kickstart design?

Rob
Asked by: Rob
on October 19, 2014

Comments

I feel your pain. I'd call the documentation and support for Kickstart criminal, but that would be an insult to criminals.

Question: What Sort options are -available- to you in the Search API? If it's only Title and Newest, your problem is likely the same as mine... you need a patch: https://www.drupal.org/node/2202093

I dunno your Drupal level... I'm certainly no expert... but the Commerce Kickstart 'bundle' contains -several- really awful problems like this--modules that have not been updated. I've driven myself -nuts- because I thought Kickstart was fully tested and any problems I had were -my- fault. I now assume that when I'm having a problem it may well be that the code is not fully baked. YMMV.

- suntower on October 22, 2014

I looked at the solution you gave in the link. I tried that and it still does not work so revert back to original code. Trying to make things work via php amendments is really something we should not need to do, it gets overridden when module updates appear and at some point we would need a huge change control list to recreate bespoke code when updates still do not work.

I think the docs and support are a new version of quatum mechanics, or a sort of digital eugenics experiment.... maybe a day will come someone enlightens us.

Indeed I suspect that there is a code issue, according some video's I should be able to use commerce products fields in the sort criteria, but none show up. So sorting on SKU remains impossible. I'm on core version 7.32 and commerce_kickstart-7.x-2.19.

I'm still experimenting with the zillions of possible routes and let you known if I found a "relative solution" using only TTW changes.

- Rob on October 29, 2014

1 Answer

Vote up!
1
Vote down!

A method for sorting sorting a product display list on the SKU value.

I found this somewhere on the web and summarize it. Applies to Drupal Kickstart 7.x configuration, the one I found was maybe 6.x as it use tab names not familiar to me in 7.x version of Search Api.

We need a new field for a SKU of type 'string' and use this in the product display view to sort on

Step 1
Go to the Admin -> config -> section "Search and metadata" -> Search Api
Go to product display -> Filters and then to the subsection "Call Back Setting"

Make a new field in aggregate fields called "SKU Aggregated" of type "Fulltext".
Select the field "Product >> SKU" and save the new field.
Do a index refresh, clear cache and run cron, go back to the Search Api

Go in the Search Api to the field tab and find
SKU Aggregated (Fulltext) search_api_aggregation_[a number], select index 'on' and set it to type 'string'.
Do a index refresh, clear cache and run cron

In Views go to the product display page. The default has:

FORMAT
Format: HTML list | Settings
Show: Fields | Settings

FIELDS
Content: Rendered Content

FILTER CRITERIA
Search: Fulltext search (exposed)
Indexed Content: Status (= Published)

SORT CRITERIA
[empty]

We need to get "SKU Aggregated" in the SORT CRITERIA section and this can be done by adding the field in "CONTEXTUAL FILTERS" and set to "display all values" like so:

Indexed Content: SKU Aggregated (Fulltext)

Now add this field to Sort Criteria like this

Indexed Content: SKU Aggregated (Fulltext) (desc)

It stops the default 'oldest newest' block above the product display from working so I removed that block. A new SKU is always higher than the previous one which is a kind of newest here. I don't use 'highest/lowest value' either, a facet can already narrow the value range.

Hope this is helpful for anyone struggling with this.

Rob
Answer by: Rob
Posted: Nov 6, 2014

Comments

Just to be clear for any fellow travelers in the future: I needed to follow the instructions in the drupal.org link (my original msg) in order to be able to add fields to the Sort tab. At that point one could then create an Aggregate field (as Rob describes) and it will appear in the list of available Sorts. That's what I did and it seems to work with the default Sort block.

- suntower on January 21, 2015