Given this code
<?php
class Vendor_Module_Helper_Data extends Mage_Core_Helper_Abstract
{
protected $_currentCustomer = null;
protected $_settingsHelper = null;
public function involveCustomer($customer)
{
$this->_currentCustomer = $customer;
}
public function getCurrentCustomer()
{
if (!is_null($this->_currentCustomer)) {
return $this->_currentCustomer;
}
return $this->_getCustomerSession()->getCustomer();
}
public function getSettingsHelper()
{
if (is_null($this->_settingsHelper)) {
$this->_settingsHelper = Mage::helper('vendor_module/settings');
}
return $this->_settingsHelper;
}
}
class Vendor_Module_Helper_Settings extends Vendor_Module_Helper_Data
{
public function someMethod()
{
print_r($this->getCurrentCustomer()->getData());
exit;
}
}
If I call
$helper = Mage::helper('vendor_module');
I would expect, as a singleton class, $helper would remain the same instance during the rest of the code flow, so...
$helper->involveCustomer($customer);
Now $_currentCustomer has been set, and it contains a customer object
But then, calling
$helper = Mage::helper('vendor_module');
$helper->involveCustomer($customer);
$settings = $helper->getSettingsHelper();
$settings->someMethod();
The customer object printed is the customer logged in, not the one involved 2 lines before... Am I missing something?
If helpers are called as singleton I bet I should get the right customer object... In fact, I have been assuming this since I started to work with Magento, and now I feel really confused :S