Is there a way to regenerate item website routes in bulk?
Right now the workaround is:
- Remove the content on route field
- Disable show in website
- Save item
- Enable show in website
- save item
But the problem comes when you have more than 20,000 items.
So I am thinking to do the first 3 steps ( above ) with mysql but for point 4 and 5 is hard because there are some function executed when you save via web which is what generates the correct current route.
Is there a way to simulate doctype save maybe through console, that way I can make a script to loop on all items and save so it adds the currect route.
BTW I am V11
Have you tried setting the route field directly in the database? For example running a Python script something like this:
$ bench console
items = frappe.get_all("Item", fields=['name'])
for i in items:
item = frappe.get_doc("Item", i['name'])
item.show_in_website = 1
item.route = "{0}/{1}".format(item.item_group.lower(), item.item_code.lower())
item.save()
frappe.db.commit()
print("Enabled website for {0}".format(item.item_code))
Or if you prefer MySQL:
$ bench mariadb
UPDATE `tabItem` SET `show_in_webbsite` = 1, `route` = CONCAT(LOWER(`item_group`), "/", LOWER(`item_code`));
That worked! awesome now I will put a condition only to put enable show in website if the product has an image, that save ton of time! thanks man
1 Like
Great to hear, glad it worked!