OpenCart: one store for multiple different domains
As a store owner you may start thinking of creating an additional domain name for your store in order to attract more visitors, if you came to think about this idea then you’d probably want to keep the same store along with the same products, categories & extensions… for both your domains which makes total sens but this isn’t as simple as creating and pointing your new domain to the same directory as your old domain, in fact your homepage may show up at first on the new domain but you will notice that the store is incomplete or wrong, if you see missing icons, corrupted images or links that still points to the old domain then be sure that you haven’t configured your OpenCart to handle the new domain correctly.
This tutorial will help you get your store showing up the same way for your secondary domain or any additional domain name that you might want to add later.
I am assuming that you’ve already gone through the new domain creation process and that you have pointed it to the same server directory as your old domain. so if your new domain is mysecondsite.com then you’re supposed to see your old homepage when you go to that url before starting on this tutorial.
Create a new store on your OpenCart admin panel
Login to your admin panel and go to System > Settings there you can find your stores list:
Now you need to create a new store by clicking the top right blue plus button, just fill the new store’s information and make sure that the store name ends up by a slash ( / ), so if your site is mysecondsite.com you should input: http://mysecondsite.com/
Once this step is done, you should at least see a change on your new domain, one of these is changes is that all your products or categories are gone, this isn’t bad because it means the new domain is finally pointing to the right store. we’ll see how to restore all of those in the following steps.
Assign your products and categories to the new store
now the new store created we need to make sure it has the same content as the old store, so to understand how OpenCart manages each store’s content, it simply consider a two different stores like if their stocks are separate from each other but still allow you to assign it to more than one store at a time and you can do that by going to the data tab of your product or category, in other words go to catalog > categories chose a category then access the data tab then under stores just check the store you want to assign the category to but you need to manually do this for each product and category and of course, if you’re here then you must be looking for an automatic solution in order to assign all your products and categories to the new store once and for all so that’s what we’re going to take care of in the following steps.
if you don’t see any section named Stores then don’t worry about this so just ignore this part.
Now in order to show all your previous categories and products on the new domain you need to execute some MySql queries on your database, so access your database manager (ex: phpmyadmin) through your host panel then go to the table oc_store and note the store_id of the new domain
in my example the store_id is 2, you’re going to need this number in the following steps
after that simply execute the following queries on your database manager and don’t forget to change the store_id value which is ‘2’ in my queries, if your store id is 3 then simply replace ‘2’ by ‘3’
INSERT INTO `oc_category_to_store`(`category_id`,`store_id`) SELECT `category_id`,'2' FROM `oc_category_to_store` WHERE `store_id` = "0"
INSERT INTO `oc_product_to_store` ( `product_id`, `store_id`) SELECT `product_id`, '2' FROM `oc_product_to_store` WHERE `store_id` = '0';
these queries will automatically assign all your products and categories to your new store and you should be able to see them now.