August 4, 2017

opencart attach all categories and products to a new store

Added a new store to opencart and now realised that none of the existing products and categories are linked to it. Will have to either manually edit 700 items, or come up with a MySQL query to bulk add multiple products and categories to that store for me.

Products

Store ID=123. Deleting all existing links to this store (if any) to avoid duplicate index error. Then attaching all products to it.
DELETE FROM feetunique.product_to_store where store_id=123;
INSERT INTO product_to_store (product_id, store_id) SELECT product_id, '123' from `product`;

Categories

Again, first deleting all existing links then adding new ones.
DELETE FROM feetunique.category_to_store where store_id=123;
INSERT INTO category_to_store (category_id, store_id) SELECT category_id, '123' from `category`;

You can add conditions to retrieve only active products (status=1), or any other filters if you want.

1 comment:

Unknown said...

Спасибо за содержательный пост. Есть ли возможность создать подобную функцию на платформе джумла, в рабочем шаблоне https://www.templatemonster.com/ru/opencart-templates-type/, разрабатывал не я, поэтому не знаю тонкостей. Буду благодарен если напишете развернутый ответ с инструкциями и пояснениями, думаю не одному мне будет полезно знать.