Right now I have US products in my database only. They reside within a table named products. These products are searchable through assigned tags which are in a separate table.
My challenge is to now add products from a different country with the requirement that wherever the user is from he will only see products from his country.
The country can either be selected by these infamous country-flag-picker dropdowns, set in the user profile or first determined by the visitors IP.
How would you store the international products in the database? Presumably there will not only be one more country added but many more.
Would it either make sense to simply add a column in the products table which country this product belongs to or
have a mapping table or
have separate tables for each country or
something totally different?
Right now I can not say for sure that each product will only be sold exclusively in one country. So I have to assume that one product may be sold in more than one country.
Looking forward to hear your thoughts on this.
That’s a classical many-to-many case.
Create a country table and a reference table which stores links between countryID and productID. That way you’ll be able to sell a product in only one country or as many countries as you want.
There is a lot of information on SO about many-to-many relationships: https://stackoverflow.com/search?q=many-to-many+mysql