Tutorial: Different stores, different logic - landing pages
Edit on GitHubThis tutorial is also available on the Spryker Training website. For more information and hands-on exercises, visit the Spryker Training website.
Challenge description
Spryker lets you have multi-stores and different logic for different stores in a very elegant and simple way.
Just extend the functionality for a specific store and postfix the module name with your store name.
This tutorial shows how to implement different home pages for the Back Office for different stores.
You can use the same steps for any other logic in the shop.
Extend the DE store
Override the current home page. There is a set of steps you need to follow to override the current homepage:
- In the
Communicationlayer of theApplicationmodule, in Zed, insrc/Pyz/Zed, add theControllerdirectory. - Inside
Controller, extendIndexControllerto return just a string when callingindexAction().
namespace Pyz\Zed\Application\Communication\Controller;
use Spryker\Zed\Application\Communication\Controller\IndexController as SprykerIndexController;
class IndexController extends SprykerIndexController
{
/**
* @return string
*/
public function indexAction()
{
return 'Hello DE Store!';
}
}
- Check the Backend Office (
https://zed.mysprykershop.com/) to see the new message for the DE store.
Add the new DEMO store
Add a new store and a new home page for it.
- Add a new store and call it
DEMOby adding a new array key to the store configuration file inconfig/Shared/stores.php.
$stores['DEMO'] = $stores['DE'];
- Create
config_default_DEMO.phpandconfig_default_development_DEMO.php. You can copy other config files. - Add a new Zed module to
src/Pyz/Zedand call itApplicationDEMO. This naming is a convention in Spryker.
To extend the logic for a specific shop, the module name must be $moduleName$shopName.
- Inside the new module, add a
Communicationlayer directory with aControllerdirectory inside. - Add a new
IndexControllerfor the DEMO store.
The main difference between IndexController in step 1 and this controller is the namespace and the output.
namespace Pyz\Zed\ApplicationDEMO\Communication\Controller;
use Spryker\Zed\Kernel\Communication\Controller\AbstractController;
class IndexController extends AbstractController
{
/**
* @return string
*/
public function indexAction()
{
return 'Hello DEMO Store!!!';
}
}
-
The shop is ready to support both landing pages for both stores. Modify the virtual machine to redirect you to the right store. For this, change the store in the
nginxconfig for Zed:- Copy the
nginxconfig for DE store with a new namesudo cp /etc/nginx/sites-available/DE_development_zed /etc/nginx/sites-available/DEMO_development_zed. - Open the config file
sudo vim /etc/nginx/sites-available/DEMO_development_zed. - Change
$application_storetoDEMO. - Change
server_nameto~^zed\\.demo\\..+\\.local$. - If you use dev VM, add a new host to
/etc/hostswith IP VM. - Save the changes.
- Copy the
-
Restart Nginx by running
sudo /etc/init.d/nginx restart. -
Create a store record in your
spy_store databasetable:
console data:import:store
To see the new message for the DEMO store, heck the Backend Office (https://zed.mysprykershop.com/) again.
Thank you!
For submitting the form