Magento扩展getCssJsHtml()

时间:2014-10-28 13:14:12

标签: magento extend core

我不确定我做错了什么:

我有这个:

app/code/local/Company/etc/confix.xml:

<?xml version="1.0"?>
<config>
    <modules>
        <Company_Core>
            <version>0.1.0</version>
        </Company_Core>
    </modules>
    <global>
       <models>
          <core>
              <rewrite>
                  <store>Company_Page_block_Html_Head</Store>
              </rewrite>
          </core>
       </models>
    </global>
</config>

app/code/local/Company/Page/Block/Html/Head.php:

include('Mage/Page/Block/Html/Head.php');

class Company_Page_block_Html_Head extends Mage_Catalog_Model_Product {
    /**
     * Get HEAD HTML with CSS/JS/RSS definitions
     * (actually it also renders other elements, TODO: fix it up or rename this method)
     *
     * @return string
     */
    public function getCssJsHtml()
    {
        echo 'asd';
        return parent::getCssJsHtml();
    }
}

但是没有任何改变,我的调试文本“asd”根本没有显示,我不知道我可能做错了什么?

我正在运行magento 1.9 CE

1 个答案:

答案 0 :(得分:1)

如果您的目标是覆盖getCssJsHtml(),那么您的代码完全错误。请检查以下代码以覆盖getCssJsHtml()方法

<modules>
    <Company_Metadata>
        <version>0.0.1</version>
    </Company_Metadata>
</modules>
<global>
    <blocks>
        <metadata>
            <class>Company_Metadata_Block</class>
        </metadata>
        <page>
            <rewrite>
                <html_head>Company_Metadata_Block_Title</html_head>
            </rewrite>
        </page>
    </blocks>
</global>

<?php
class Company_Metadata_Block_Title extends Mage_Page_Block_Html_Head
{
    public function getCssJsHtml()
    {
       echo 'asd';
    return parent::getCssJsHtml();
    }
}

如果您有任何疑问,请告诉我