Closed aminedhobb closed 4 years ago
Tremendous job @aminedhobb! The execution looks really good. I've left a few suggestions and comments for you to have a look at.
You also can make the entry file an executable and place it within
bin
folder. For example, we can renameupdate_shopify_products_position_in_collections.rb
toinit.rb
and add a shebang on top:#!/usr/bin/env ruby ...
That way, we will be able to run it as
./bin/init.rb
without specifyingruby update_shopify_products_position_in_collections.rb
. But it's completely a detail.
Thank you for your review and the words @praagyajoshi 🙌 ! I applied most of your suggestions and replied to some. As you can see and as I discussed with you, the implementation changed since we now have to fetch all the product ids from Shopify.
There is one I would still like to discuss :
Since we are not using the browse
method anymore (because it doesn't take into account the merchandising rules), I use now regular searches. However if the number of products on a collection is superior to the parameter paginationLimitedTo
, all the products won't be retrieved. It means that only the first N
products will be fetched from Algolia, N
being equal to paginationLimitedTo
.
After that the products will be ordered randomly (by doing the difference between all the collection product ids and the ones retrieved by Algolia).
However since only Algolia is fetching products in the storefront, meaning a customer cannot go beyond the products fetched by Algolia, it shouldn't be a problem I believe ?
For Fashion Nova N = 9600
, but they have collections with more than 150 000
products.
@praagyajoshi I updated the script to take only the first 100 products into account and is now ready to review. I would recommend you to also make a test on your store, I have been noticing some inconsistencies between different collections ordering.
I implemented the program that update the products order in collections to be the same in Shopify and in Algolia. How to install and run the program is explained in the README.
As for the implementation, it doesn't work the same way for custom collections and smart collections. For smart collection, updating the sort order and give an array of product ids (ordered the way we want to) does the work. For custom collections, we need to first update the sort order to
manual
and then pass in the payload the collects with the updated positions.Note The throttling is not optimized here : I pause the script for one second when the credits left are too low in the parts we make the most calls.