Day: January 18, 2011

  • Lack of ideas to manage javascript in Magento

    In Magento System >> Configuration >> Catalog >> Frontend, when List Mode selected value is changed, some fields (i.e. Products per page on Grid allowed values, Products per Page on Grid default value, Products per Page on List allowed values, Products per Page on List default value) are shown/hidden accordingly.

    List mode showing both grid and list options
    List mode showing both grid and list options

    List mode showing only grid options
    List mode showing only grid options

    I had thought List Mode had a special frontend model defined so it could interact with other fields. I spent an hour to search for special settings of List Mode but did not find any. Instead I was disappointed to find out the frondend interaction is not defined in xml or php class, but by app/design/adminhtml/default/default/template/system/config/js.phtml.

    The way Magento did this kind of interaction is not replicable, which is a pity. By and large, the way how Magento uses javascript is messy. Maybe I am asking too much from Magento. What I am keen on is a “Google Web Toolkit” way, that means no need to manage javascript at all because javascript is compiled from server end script.

  • Constants are not overridden as varibles

    今天发现我写的一个底层的 Magento class 竟然有个低级错误。错误的根源是我在父类里定义了一个常量

    const XML_PATH_TO_SYSTEM_CONFIG = 'some value';
    

    然后在父类里有个方法用到了这个常量

    public static function getConfigValue()
    {
    	return Mage::getStoreConfig(self::XML_PATH_TO_SYSTEM_CONFIG);
    }
    

    然后在子类里复写了常量

    const XML_PATH_TO_SYSTEM_CONFIG = 'some other value';
    

    但子类并没有父类的方法 getConfigValue()。我指望通过复写每个子类的常量后调用子类的方法 getConfigValue() 得到不同的值,哪知道每次都得到跟父类的方法 getConfigValue() 相同的值。

    仔细一想,这是因为父类的 self::XML_PATH_TO_SYSTEM_CONFIG 并没有被复写。改用一个变量来存储值就能达到我的原定目的,但这个变量不能是静态变量,否则效果还是跟常量一样。