0

In my category pages, I would like to mix the order of the products to be random.


Problem:

I was adding products to my site by "Brand". Now if I click on "T-Shirt" category, first 5 pages is Adidas only, then next 5 pages it's Puma etc. I would like to mix the products in all my categories to be totally random.

Desired result:

Category pages have products randomly displayed. So for example, page 1 in "T-Shirt" category, will have a mix of all the products within this category in random sort order.

Using Magento 2.1.8 and custom theme.

3
  • You would have to extend core functionality to do random, you can change the position of products within the category. Change the numbers in the right hand column to change the sort order, 0 is always the top. Apr 18, 2018 at 14:14
  • I see... Do you know at what table in the database is the position of the product held? Maybe randomise the numbers there? :D
    – Greg
    Apr 18, 2018 at 14:24
  • I believe its catalog_category_product.position Apr 18, 2018 at 14:30

1 Answer 1

0

It might be not ideal, but solved the problem for me:

  1. I have downloaded the table called catalog_category_product in CSV format from my database.

  2. I opened the the table in excel and left only the entries of the desired category (41 in my case) and deleted the rest of entries.

  3. Next to the range of rows, in new column, I added a simple formula rand() to generate a random number in each row.

  4. I have sorted the new column of random numbers using data -> sort ZA option which randomised my rows.

  5. I removed the created column with random numbers.

  6. In column for position add numbers and increase them by 10.

  7. Import the table back to the original. Make sure you tick "Update data when duplicate keys found on import (add ON DUPLICATE KEY UPDATE)"

I hope someone will find this useful.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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