1

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.

2
  • add your XXX_GoogleTagManager.xml here Jun 28, 2018 at 8:17
  • @MurtuzaZabuawala, added
    – KuKu
    Jun 28, 2018 at 8:19

1 Answer 1

1

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>
3
  • Removed <cjtracking> <class>XXX_GoogleTagManager_Block</class> </cjtracking> and made changes as you suggested. Working
    – KuKu
    Jun 28, 2018 at 8:34
  • 1
    Appreciate your help
    – KuKu
    Jun 28, 2018 at 8:34
  • @KuKu you are always welcome :) Jun 28, 2018 at 8:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.