Hot Topics

Magento – Database Queries

Magento is a complete and awesome MVC application. It’s fully moduler and easy to extend its features and functionality. All…..

Magento – Emulate store programmatically

One of the biggest feature 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.

What’s the use of store emulator?

When a process run on backend for example cron jobs or email notifications, these processes work under admin store. No problem, but what if these codes need different store themes. For example product alert emails need to send store wise.

So each time a mail is sent it grabs the template from store view of the Emulated Store.

app/design/frontend/default/store1_theme/template/email/custom-email-block.phtml, for first store

app/design/frontend/default/store2_theme/template/email/custom-email-block.phtml for second store and so on.

So in that case store emulator play a very crucial role and help to create the store environment on the fly.

To emulate any store just copy the given code in any controller with specific store id.

$appEmulation = Mage::getSingleton('core/app_emulation');
//Start environment emulation of the specified store
$initialEnvironmentInfo = $appEmulation->startEnvironmentEmulation($storeId);

//Emulation Started
//Run any code here and it will use the emulated store
//Stop environment emulation and restore original store