The problem is that the Mage::getModel('core/email_template')
loads the design information using Mage_Core_Model_Template::_applyDesignConfig()
which intern loads a store via Mage::getDesign()->getStore()
. When you follow this down the rabbit hole you will see the following.
public function getStore()
{
if ($this->_store === null) {
return Mage::app()->getStore();
}
return $this->_store;
}
This means that if the store is not set if will load the default store, note that nothing is being passed into the getStore
call.
So one way around this is to call Mage::app()->setCurrentStore(22)
but as pointed out by Sander there is a better way.
You can use Mage::getSingleton('core/app_emulation')
to wrap your code in store emulation.
$appEmulation = Mage::getSingleton('core/app_emulation');
//Start environment emulation of the specified store
$initialEnvironmentInfo = $appEmulation->startEnvironmentEmulation($storeId);
// Your code here
//Stop environment emulation and restore original store
$appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo);
For more information see Inchoo