Created
November 10, 2013 17:57
-
-
Save jacquesbh/7401505 to your computer and use it in GitHub Desktop.
Store emulation on Magento <http://jacques.sh/2013/11/et-si-on-emulait.html>
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Get the old store | |
$oldStore = Mage::app()->getStore(true); | |
// Set the new store | |
/* @var $customer Mage_Customer_Model_Customer */ | |
$newStore = Mage::app()->getStore($customer->getStoreId()); | |
Mage::app()->setCurrentStore($newStore); | |
// Here my code... Am I really on the new store? | |
// Set the old store | |
Mage::app()->setCurrentStore($oldStore); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Start emulation | |
/* @var $customer Mage_Customer_Model_Customer */ | |
/* @var $emulator Mage_Core_Model_App_Emulation */ | |
$emulator = Mage::getModel('core/app_emulation'); | |
$initial = $emulator->startEnvironmentEmulation($customer->getStoreId()); | |
// Here my code... Yes! I'm really on the new store! | |
// Stop emulation | |
$emulator->stopEnvironmentEmulation($initial); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment