With help of David above answer,Hope David would not mind.
I am try explain more in detail
start with Mage.php and go to function helper
public static function helper($name)
{
$registryKey = '_helper/' . $name;
if (!self::registry($registryKey)) {
$helperClass = self::getConfig()->getHelperClassName($name);
self::register($registryKey, new $helperClass);
}
return self::registry($registryKey);
}
a) $registryKey = '_helper/' . $name;
result: $registryKey = _helper/sales
b) check now registry key exits ot not,if not then set a registry
variable
if (!self::registry($registryKey)) {
its becomes true when system is first times
for a session:
c) $helperClass = self::getConfig()->getHelperClassName($name);
that means
$name=sales send to Mage_Core_Model_Config class function
getHelperClassName
for getting helper class send param
d)Then set class name is registry variable
e
self::register($registryKey, new $helperClass);
Result: may be proper class name Mage_Sales_Helper_Data
Now goes to getHelperClassName function of class Mage_Core_Model_Config
a) This function Retrieve helper class name string $name
string
public function getHelperClassName($helperName)
{
if (strpos($helperName, '/') === false) {
$helperName .= '/data';
}
return $this->getGroupedClassName('helper', $helperName);
}
explain of function:
$helperName is sales
the logic:
if (strpos($helperName, '/') === false) {
becomes true as $helperName=sales then set $helperName=sales/data
b) return $this->getGroupedClassName('helper', $helperName);
Details:
call function getGroupedClassName with params 'helper','sales/data'
and getGroupedClassName return class name of helper class
Now goto function getGroupedClassName('helper','sales/data',null)
public function getGroupedClassName($groupType, $classId, $groupRootNode=null)
{
if (empty($groupRootNode)) {
$groupRootNode = 'global/'.$groupType.'s';
}
$classArr = explode('/', trim($classId));
$group = $classArr[0];
$class = !empty($classArr[1]) ? $classArr[1] : null;
if (isset($this->_classNameCache[$groupRootNode][$group][$class])) {
return $this->_classNameCache[$groupRootNode][$group][$class];
}
$config = $this->_xml->global->{$groupType.'s'}->{$group};
// First - check maybe the entity class was rewritten
$className = null;
if (isset($config->rewrite->$class)) {
$className = (string)$config->rewrite->$class;
} else {
/**
* Backwards compatibility for pre-MMDB extensions.
* In MMDB release resource nodes <..._mysql4> were renamed to <..._resource>. So <deprecatedNode> is left
* to keep name of previously used nodes, that still may be used by non-updated extensions.
*/
if ($config->deprecatedNode) {
$deprecatedNode = $config->deprecatedNode;
$configOld = $this->_xml->global->{$groupType.'s'}->$deprecatedNode;
if (isset($configOld->rewrite->$class)) {
$className = (string) $configOld->rewrite->$class;
}
}
}
// Second - if entity is not rewritten then use class prefix to form class name
if (empty($className)) {
if (!empty($config)) {
$className = $config->getClassName();
}
if (empty($className)) {
$className = 'mage_'.$group.'_'.$groupType;
}
if (!empty($class)) {
$className .= '_'.$class;
}
$className = uc_words($className);
}
$this->_classNameCache[$groupRootNode][$group][$class] = $className;
return $className;
}
**this function task **
retrieve class name by class group
param string $groupType currently supported helper
param string $classId slash separated class identifier, ex. group/class
param string $groupRootNode optional config path for group config
return string
a)$classArr = explode('/', trim($classId));
result:explode helper name(sales/data by /) for getting classs name in array $classArr
b)$class = !empty($classArr[1]) ? $classArr[1] : null;
Result:as $classArr[1] is data then value of $class is data
c) $config = $this->_xml->global->{$groupType.'s'}->{$group};
details:get config setting then $config = $this->_xml->global->helpers->sales;
d)$className = null;
Details:set $className null
.
e) check rewrite class exits in config.xml files, check if class is rewrite then
you can easly get
code: if (isset($config->rewrite->$class)) {
result:if (isset($config->rewrite->data)) {
f)for default magento ,it false to goto else
skip if ($config->deprecatedNode) {
as deprecatedNode is for model($grouptype) and ,it only used for _mysql4
g) if (empty($className)) {
result:
if sales helper not rewrite then if (empty($className)) { becomes true
h)if (!empty($config)) {
Result
:false
if (!empty($config)) { becomes false;`
i) if (empty($className)) {
Result:as $className is till
null then this code is true
j) make class $className = 'mage_'.$group.'_'.$groupType;
result:
$group=sales
$groupTyp=helper
$className = 'mage_sales_helper';
k)
if (!empty($class)) {
$className .= '_'.$class;
}
result:
as $class = data the this condition is true and $className = 'mage_sales_helper_data';
l)** make in upper case $className = uc_words($className)
;
Now return class return $className; which is Mage_Sales_Helper_Data**
Thanks to
David Manners and Rajeev K Tomy