문제

I have been trying to get this right for a bit, but when I look at the adminhtml_head block I see that it extends off the html_head block. I have extended the html_head block so that I could add a cdn item. It works just fine on the front when I adjust the layout xml, but when I adjust the layout xml for the back end it skips over extended class, so the overwrite doesn't work. Basically what I've done is test it by added a javascript to the adminhtml/page_head and that works using the normal add_js type. But when I go to use the cdn_js type, since it's not hitting my method, it just skips it.

Is there any reason that the admin would not be picking up my over write even thou both the admin end up extending off the core Mage_Page_Block_Html_Head ?

In my config I have this

<blocks>
<page>
<rewrite>
    <html_head>Wsu_Storeutilities_Block_Html_Head</html_head>
</rewrite>
</page>
</blocks>

Which works for the front. I have tried many different combinations to get the adminhtml to pick up as well with no luck.

도움이 되었습니까?

해결책

The default head block in the backend is an instance of Mage_Adminhtml_Block_Page_Head (adminhtml/page_head). You need to override that also and add your method.
Even if Mage_Adminhtml_Block_Page_Head extends Mage_Page_Block_Html_Head and you've overwritten Mage_Page_Block_Html_Head the block used in the backend still extends the original Magento class, and your methods is not present in it.
[EDIT]
Your blocks rewrite section should look like this:

<blocks>
    <page><!-- rewrite the frontend head block -->
        <rewrite>
            <html_head>Wsu_Storeutilities_Block_Html_Head</html_head>
        </rewrite>
    </page>
    <adminhtml><!-- rewrite admin head block -->
        <rewrite>
            <page_head>Wsu_Storeutilities_Block_Adminhtml_Page_Head</page_head>
        </rewrite>
    </adminhtml>
</blocks>

Then create the file Wsu/Storeutilities/Block/Adminhtml/Page/Head.php with this content:

<?php
class Wsu_Storeutilities_Block_Adminhtml_Page_Head extends Mage_Adminhtml_Block_Page_Head{
    //your methods here
}

다른 팁

It sounds like you don't quite understand how Magento class rewrites work — but don't worry, it's an easy enough thing to be confused about.

PHP's object system doesn't have a ruby/python like duck-typing/money-patching system. That means Magento only allows you to rewrite a directly instantiated class.

That is, when a block object in instantiated with a factory method (which looks something like this)

$layout->createBlock('page/html_head');

Magento will scan the configuration and look for a <page/> node with a <rewrite/> child node. If it finds one, it will look inside the <rewrite/> node for a <html_head/> node. If it finds a class inside that node, it will instantiate the object using that class instead.

So, in the admin console application, the head block is instantiated with something like this

$layout->createBlock('adminhtml/page_head')

This means the admin console will ignore your class rewrite, since your configuration only rewrites the page/html_head block.

Long story short: You need a second class rewrite for the adminhtml/page_head block.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 magento.stackexchange
scroll top