0

I have inserted 4000 products and now our client want the inverse order so how to reorder them programatically? any help please

  • Do you want to change the position value in the database? – Mohit Kumar Arora May 27 at 10:07
  • i want to see in frontend the products listed from first to last added now i see the last added to first and i can't sort them by position because it will take time to attribute every product a position so is there a way to reorder them so that i can see the first added to last added – Developper Magento May 27 at 10:10
  • I can suggest programmatical steps. If it could help, please let me know. – Mohit Kumar Arora May 27 at 10:21
  • ok can you please give me those steps and thanks for your replay * – Developper Magento May 27 at 10:46
1
  • Create a controller's action or a custom PHP file, so that you can run your custom script to change the position.
  • Get all products collection order by position in decremental order and store it as an array having product IDs and position.
  • From the array above, you can easily find the biggest position and the smallest position. Now loop through the products array and assign the new positions (for this step, start from the smallest position value and every time a product is assigned the new value, add 1 to the get a new position)

For faster execution of your script, you can use updateAttribute() function as shown in How to update product eav attribute in magento 2 link.

Please let me know if anything is unclear.

  • i will try your solution immadiatly thanks for your replay – Developper Magento May 27 at 13:15

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.