Magento is famous for is its capabilities to develop multi-store and multi-language web stores. Each store can be completely different from its fellow stores. Store Emulation helps developers to emulate any store programmatically.
Store emulation is also know as Area Emulation and App Emulation.
Suppose you want to send custom transactional e-mail for all stores at the same time as cronjob.
When a process run on backend for example cron jobs or email notifications, these processes work under admin store.
But suppose if you want to send transactional e-mail on store wise, then email template need grab from store view.
You can enable App Emulation and perform this action.
Let’s check an quick example which demonstrates store emulation cron running for specific store.
I’m supposing that you have created your module or if not check this tutorial for create a custom module.
Let’s get started !!
Magento has provided a class to do such things, \Magento\Store\Model\App\Emulation this class provides two methods:
//1. Start Emulation by passing following params
$area = \Magento\Framework\App\Area::AREA_FRONTEND,
$force = false
//2. Stop Emulation after completing work
An example of how we can use these methods to emulate the store environment :
* @var Emulation
* @param Emulation $emulation
public function __construct(Emulation $emulation)
$this->emulation = $emulation;
* Example function in which we want to emulate a store environment
* @return void
public function execute()
$storeId = 1;
// starting the store emulation by specifying storeId , Area & Force
$this->emulation->startEnvironmentEmulation($storeId, Area::AREA_FRONTEND, true);
// your code here
// discard the emulated environment after doing your work
This way you can emulate area in Magento 2. I hope you like the tutorial, Let me know if you have any query in the comment box or contact me.