question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Category sort = 'position:asc' does not reflect the order set within magento categories

See original GitHub issue

Current behavior

Currently it does not seem possible to display products within categories using the order specified in the Magento admin.

I am able to see the position number in the elastic data using Kibana. When using the new magento2-vsbridge-indexer you can see this in the categories attribute against a product.

When using the mage2vuestorefront to import data, the position number is set on extension_attributes.category_links

In either case, setting sort = ‘position:asc’ or ‘position:desc’ makes no difference to the sorting of products.

Expected behavior

When sort = ‘position:asc’ products within categories should be ordered as per the order field within magento admin

Steps to reproduce the issue

Either using postman to hit the api directly or by configuring the storefront to sort products by position:asc products will not sort by the position number. And position:desc returns products in same position as position:asc.

Can you handle fixing this bug by yourself?

  • YES
  • NO

Which [Release Cycle]

  • This is a bug report for test version on https://test.storefrontcloud.io - In this case Developer should create branch from develop branch and create Pull Request 2. Feature / Improvement back to develop.
  • This is a bug report for current Release Candidate version on https://next.storefrontcloud.io - In this case Developer should create branch from release branch and create Pull Request 3. Stabilisation fix back to release.
  • This is a bug report for current Stable version on https://demo.storefrontcloud.io and should be placed in next stable version hotfix - In this case Developer should create branch from hotfix or master branch and create Pull Request 4. Hotfix back to hotfix.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:22 (9 by maintainers)

github_iconTop GitHub Comments

5reactions
dio5commented, Nov 30, 2020

I had it working by adding something like this to SearchAdapter.ts:

if (Request.type === 'product' && Request.sort) {
      const sortType = Request.sort.split(':', 2)
      if (sortType[0] === 'position') {
        const searchQuery = Request.searchQuery;
        const categories = searchQuery.getAppliedFilters().find(element => element.attribute === 'category_ids')
        let mainCategoryId = null
        if (categories && categories.value) {
          mainCategoryId = categories.value.in[0]
          if (mainCategoryId) {
            ElasticsearchQueryBody['sort'] = [{
              'category.position': {
                'order': sortType[1] || 'asc',
                'mode': 'min',
                'nested_path': 'category',
                'nested_filter': {
                  'term': {'category.category_id': mainCategoryId}
                }
              }
            }]
          }
        }
     }
 }

`

1reaction
simonmaasscommented, Aug 7, 2020

we are currently struggling with this exact problem - any solution yet? We are using VSF 1.12.2…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Magento 2 - Category List Sort by Position with Sub Category ...
A little background, I'm trying to do a custom Category listing, but at the moment it seems the ...
Read more >
Magento 2 - Category List Sort by Position ... - Stack Overflow
A little background, I'm trying to do a custom Category listing, but at the moment it seems the ...
Read more >
Fixing Magento Category Order Problems - novusweb
Recently, one of our clients could not get their product categories to appear in the order set in the Magento Catalog > Manage...
Read more >
How to change a products sort order in a Magento 2 category?
To change the default sorting, go to Catalog > Categories, choose the needed category, and open the Display Setting tab. Then go to...
Read more >
Sorting products in categories - Bug reports - PrestaShop
Also and most importantly the order you specify doesn't reflect in the front end, the order in the frontend (choosing Position insede category...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found