Pregunta

We are trying to rewrite the 3rd party module's block.

Here is my extension

\app\etc\modules\XXX_GoogleTagManager.xml

<?xml version="1.0"?>
<config>
    <modules>
        <XXX_GoogleTagManager>
            <active>true</active>
            <codePool>local</codePool>
            <depends>
                <Shopgo_GTM />
            </depends>
        </XXX_GoogleTagManager>
    </modules>
</config>

Config.xml

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <modules>
        <XXX_GoogleTagManager>
            <version>0.1.0</version>
        </XXX_GoogleTagManager>
    </modules>
    <frontend>
        <layout>
            <updates>
                <googletagmanager>
                    <file>googletagmanager.xml</file>
                </googletagmanager>
            </updates>
        </layout>
    </frontend>

    <global>
        <blocks>
            <cjtracking>
                <class>XXX_GoogleTagManager_Block</class>
            </cjtracking>
            <gtm>
                <rewrite>
                    <gtm>Shopgo_GTM_Block_Gtm</gtm>
                </rewrite>
            </gtm>
        </blocks>
    </global>
</config>

Gtm.php

<?php

class XXX_GoogleTagManager_Block_Gtm extends Shopgo_GTM_Block_Gtm
{
}

here is config.xml file of Shopgo extension

<?xml version="1.0"?>
<config>
    <modules>
        <Shopgo_GTM>
            <version>1.0.3</version>
        </Shopgo_GTM>
    </modules>
    <global>
        <blocks>
            <gtm>
                <class>Shopgo_GTM_Block</class>
            </gtm>
        </blocks>
        <helpers>
            <gtm>
                <class>Shopgo_GTM_Helper</class>
            </gtm>
        </helpers>
        <models>
            <gtm>
                <class>Shopgo_GTM_Model</class>
            </gtm>
        </models>
    </global>
    <frontend>
        <routers>
            <shopgo_gtm>
                <use>standard</use>
                <args>
                    <module>Shopgo_GTM</module>
                    <frontName>gtm</frontName>
                </args>
            </shopgo_gtm>
        </routers>
        <translate>
            <modules>
                <Shopgo_GTM>
                    <files>
                        <default>Shopgo_GTM.csv</default>
                    </files>
                </Shopgo_GTM>
            </modules>
        </translate>
        <events>
            <sales_order_place_after>
                <observers>
                    <gtm_order_success>
                        <class>gtm/observer</class>
                        <method>setGTMTransactionData</method>
                    </gtm_order_success>
                </observers>
            </sales_order_place_after>
        </events>
        <layout>
            <updates>
                <gtm>
                    <file>shopgo/gtm.xml</file>
                </gtm>
            </updates>
        </layout>
    </frontend>
    <adminhtml>
        <translate>
            <modules>
                <Shopgo_GTM>
                    <files>
                        <default>Shopgo_GTM.csv</default>
                    </files>
                </Shopgo_GTM>
            </modules>
        </translate>
    </adminhtml>
    <default>
        <google>
            <gtm>
                <active>0</active>
                <datalayer>1</datalayer>
            </gtm>
        </google>
    </default>
</config>

We are just trying to rewrite block. Not any other functionality.

In phtml file, <?php echo $this->_getDataLayer(); ?> this piece of code getting called.

So, i am trying to make some changes in _getDataLayer() in XXX_GoogleTagManager_Block_Gtm so that changes can be seen in PHTML file.

¿Fue útil?

Solución

in your config.xml add your class at here

<rewrite>
    <gtm>XXX_GoogleTagManager_Block_Gtm</gtm><!--add your class here instead Shopgo_GTM_Block_Gtm-->
</rewrite>
Licenciado bajo: CC-BY-SA con atribución
No afiliado a magento.stackexchange
scroll top