Cakephp - Choose your preferred country for ecommerce

176 views Asked by At

I'm developing an ecommerce website. Now, at the homepage, i want to put the preferred country. When the customer choose their preferred country, the list of product shown to them was from that prefered country only.

My database (products table has id, name, description, color, SKU and country_id)

Anyone has idea about this. I already check for global variable. But its like declaring in core.php or bootstrap.php. I want it to declare at my homepage when customer choose the country.

Please somebody help me. Thanks in advance ;p

2

There are 2 answers

1
Martin Bean On BEST ANSWER

If your user selects a country, store it in a session or cookie. If you want to be really efficient, you could have users select their preferred country on sign-up and store that in their profile record in the database, and set a configuration variable when they log in.

0
user2910265 On

I think "Magic Find Types" is a good place to start. You get this functionality automatically from your product Model class.

http://book.cakephp.org/2.0/en/models/retrieving-your-data.html#magic-find-types

Inside your controller, all you probably need to do is type something like this. It also has optional arguments for sorting and result set limiting. Of course, how you retrieve the preferred country is dependent on your application (browser cookie, logged in user profile etc).

$this->Product->findAllByCountryId($countryId)