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
Communication
layer of theApplication
module, in Zed, insrc/Pyz/Zed
, add theController
directory. - Inside
Controller
, extendIndexController
to 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
DEMO
by adding a new array key to the store configuration file inconfig/Shared/stores.php
.
$stores['DEMO'] = $stores['DE'];
- Create
config_default_DEMO.php
andconfig_default_development_DEMO.php
. You can copy other config files. - Add a new Zed module to
src/Pyz/Zed
and 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
Communication
layer directory with aController
directory inside. - Add a new
IndexController
for 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
nginx
config for Zed:- Copy the
nginx
config 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_store
toDEMO
. - Change
server_name
to~^zed\\.demo\\..+\\.local$
. - If you use dev VM, add a new host to
/etc/hosts
with 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 database
table:
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