0

I'm trying to extend the Action List. I've looked for rewrite conflicts with the many rewrite tools. I'm just not seeing it. Here is my code.

<?php

 class MDN_BarcodeLabel_Block_Product_List extends
 Mage_Adminhtml_Block_Catalog_Product_List {

     protected function _prepareMassaction() {


         parent::_prepareMassaction();

         // Append new mass action option
         $this->getMassactionBlock()->addItem(
             'BarcodeLabel',
             array('label' => $this->__('Print barcode labels'),
                   'url'   => $this->getUrl('adminhtml/BarcodeLabel_Admin/printSelectedProductLabel')
             )
         );

     }

 }

 ?>

Here rewrite script below show it being listed by itself. Here is the Observer.php. I have everything working fine on a clean install, but I can't seem to find the conflict anywhere. There is ACL built in, but that is working perfect.

public function addMassAction($observer) {
        $block = $observer->getEvent()->getBlock();
        if (get_class($block) == 'Mage_Adminhtml_Block_Widget_Grid_Massaction'
                && $block->getRequest()->getControllerName() == 'catalog_product') {

            $admin_user_session = Mage::getSingleton('admin/session');
            $adminuserId = $admin_user_session->getUser()->getUserId();
            $role_data = Mage::getModel('admin/user')->load($adminuserId)->getRole();
            $roleIdUser = $role_data->getRoleId();

            $barcodeprofiles = Mage::getModel('barcodeprofile/barcodeprofile')->getCollection()
                ->addFieldToFilter('status', 1);
            $arrayBarcode = array();
            foreach($barcodeprofiles as $data) {
                $arrayRole = explode(',', $data->getRole());
                if(in_array($roleIdUser, $arrayRole)) {
                    $arrayBarcode[$data->getId()] = $data->getProfile();
                }
            }

            $block->addItem('BarcodeLabel', array(
                'label' => Mage::helper('BarcodeLabel')->__('Print barcode labels'),
                'url' => Mage::app()->getStore()->getUrl('adminhtml/BarcodeLabel_Admin/printSelectedProductLabel'),
                'additional' => array(
                    'visibility' => array(
                        'name' => 'barcode_profile',
                        'type' => 'select',
                        'class' => 'required-entry',
                        'label' => Mage::helper('catalog')->__('Barcode Profile'),
                        'values' => $arrayBarcode
                    )
                )
            ));

If you interested here is the config.xml. Sorry about the length. ...

    <global>

        <helpers>
            <BarcodeLabel>
                <class>MDN_BarcodeLabel_Helper</class>
            </BarcodeLabel>
        </helpers>

        <blocks>
            <BarcodeLabel>
                <class>MDN_BarcodeLabel_Block</class>
            </BarcodeLabel>


            <adminhtml>
                <rewrite>
                    <catalog_product_list>MDN_BarcodeLabel_Block_Product_List</catalog_product_list>
                </rewrite>
            </adminhtml>

        </blocks>

        <models>
            <BarcodeLabel>
                <class>MDN_BarcodeLabel_Model</class>
                <resourceModel>BarcodeLabel_mysql4</resourceModel>
            </BarcodeLabel>

           <BarcodeLabel_mysql4>
                <class>MDN_BarcodeLabel_Model_Mysql4</class>
                <entities>
                    <List>
                        <table>barcode_label_list</table>
                    </List> 
                    <ProductVarchar>
                        <table>catalog_product_entity_varchar</table>
                    </ProductVarchar>
                </entities>
            </BarcodeLabel_mysql4>

            <AdvancedStock>
                <rewrite>
                    <Pdf_BarcodeLabels>MDN_BarcodeLabel_Model_Pdf_Labels</Pdf_BarcodeLabels>
                </rewrite>
            </AdvancedStock>

        </models>

        <resources>
            <BarcodeLabel_setup>
                <setup>
                    <module>MDN_BarcodeLabel</module>
                    <class>Mage_Catalog_Model_Resource_Eav_Mysql4_Setup</class>
                </setup>
                <connection>
                    <use>core_setup</use>
                </connection>
            </BarcodeLabel_setup>
            <BarcodeLabel_write>
                <connection>
                    <use>core_write</use>
                </connection>
            </BarcodeLabel_write>
            <BarcodeLabel_read>
                <connection>
                    <use>core_read</use>
                </connection>
            </BarcodeLabel_read>
        </resources>

        <events>
            <model_save_after>
                <observers>
                    <BarcodeLabel>
                        <type>singleton</type>
                        <class>BarcodeLabel/observer</class>
                        <method>model_save_after</method>
                    </BarcodeLabel>
                </observers>
            </model_save_after>
        </events>
    </global>

    <adminhtml>

        <translate>
            <modules>
                <MDN_BarcodeLabel>
                    <files>
                        <default>MDN_BarcodeLabel.csv</default>
                    </files>
                </MDN_BarcodeLabel>
            </modules>
        </translate>

        <layout>
            <updates>
                <BarcodeLabel>
                    <file>BarcodeLabel.xml</file>
                </BarcodeLabel>
            </updates>
        </layout>

        <acl>
            <resources>
                <admin>
                    <children>
                        <system>
                            <children>
                                <config>
                                    <children>
                                        <barcodelabel module="BarcodeLabel">
                                            <title>Barcode label</title>
                                        </barcodelabel>
                                    </children>
                                </config>
                            </children>
                        </system>
                    </children>
                </admin>
            </resources>
        </acl>

        <events>
            <core_block_abstract_prepare_layout_before>
                <observers>
                        <BarcodeLabel_core_block_abstract_prepare_layout_before>
                            <class>BarcodeLabel/observer</class>
                            <method>addMassAction</method>
                        </BarcodeLabel_core_block_abstract_prepare_layout_before>
                </observers>
            </core_block_abstract_prepare_layout_before>
        </events>

    </adminhtml>

    <frontend>
        <secure_url>
            <BarcodeLabel>/BarcodeLabel/</BarcodeLabel>
        </secure_url>
        <routers>
            <BarcodeLabel>
                <use>standard</use>
                <args>
                    <module>MDN_BarcodeLabel</module>
                    <frontName>BarcodeLabel</frontName>
                </args>
            </BarcodeLabel>
        </routers>
    </frontend>

    <admin>
        <routers>
            <adminhtml>
                <args>
                    <modules>
                        <BarcodeLabel before="Mage_Adminhtml">MDN_BarcodeLabel_Adminhtml</BarcodeLabel>
                    </modules>
                </args>
            </adminhtml>
        </routers>
    </admin>
...
0
1

UPDATE

As per @Digital pointed, is there class called Mage_Adminhtml_Block_Catalog_Product_List presents? I believe there is not. Please check which class are you trying to extend. But yes, extending approach is the same as below.

First approach via extension

If you have created an extension for this then you must have this in your config.xml in order to extend it

<global>
   <blocks>
        .................
         <adminhtml>
            <rewrite>
                <catalog_product_list>MDN_BarcodeLabel_Block_Product_List</catalog_product_list>
            </rewrite>
        </adminhtml>
   </blocks>
</global>

*You must have List.php in this format:

app/code/community[or local]/MDN/BarcodeLabel/Block/Product/List.php

Second approach via local folder

If you don't want to create an extension for this then just place List.php file in following directory.

app/code/local/Mage/Adminhtml/Block/Catalog/Product

This should work.

UPDATE

Sometime your extended class doesn't come to effect due to other extension extending same class.

To check which other extension extending what, create this file in your root

<?php 
$folders = array('app/code/local/', 'app/code/community/');//folders to parse
$configFiles = array();
foreach ($folders as $folder){
    $files = glob($folder.'*/*/etc/config.xml');//get all config.xml files in the specified folder
    $configFiles = array_merge($configFiles, $files);//merge with the rest of the config files
}
$rewrites = array();//list of all rewrites

foreach ($configFiles as $file){
    $dom = new DOMDocument;
    $dom->loadXML(file_get_contents($file));
    $xpath = new DOMXPath($dom);
        $path = '//rewrite/*';//search for tags named 'rewrite'
        $text = $xpath->query($path);
        foreach ($text as $rewriteElement){
            $type = $rewriteElement->parentNode->parentNode->parentNode->tagName;//what is overwritten (model, block, helper)
            $parent = $rewriteElement->parentNode->parentNode->tagName;//module identifier that is being rewritten (core, catalog, sales, ...)
            $name = $rewriteElement->tagName;//element that is rewritten (layout, product, category, order)
            foreach ($rewriteElement->childNodes as $element){
                $rewrites[$type][$parent.'/'.$name][] = $element->textContent;//class that rewrites it
            }
        }
}
echo "<pre>";print_r($rewrites);

And call it from browser. Reference

If you find your class is extended by other extension then you have two choice, one is to merge one of the file (which is hard to handle in future) and other is create dependancy one in other.

5
  • I would think it would too. My config.xml look just like that. Well, it has some addition rewrites as well, but this is the area I can't get the work. The others are working just fine. – Bill Murray Mar 11 '16 at 12:53
  • Check my update, it will let you check who is extending what. – Adarsh Khatri Mar 11 '16 at 13:58
  • Appreciate all the hard work helping. Great PHP script too. However, cant seem to find the conflict. It's working on a clean install, so it's definitely a conflict. Here is my script for that section. I've added the script to the main question – Bill Murray Mar 14 '16 at 2:47
  • I can see your observer method as addMassAction but in config.xml as model_save_after. They should match exactly. – Adarsh Khatri Mar 14 '16 at 3:08
  • There is more the the observer. public function model_save_after(Varien_Event_Observer $observer)..Didn't want to put all the code on here as I thought it was too much. in this case I'm just try to see why the massAction is populating. – Bill Murray Mar 14 '16 at 3:26
0

I'm not aware of such class Mage_Adminhtml_Block_Catalog_Product_List I assume you're referring to Mage_Adminhtml_Block_Catalog_Product_Grid right ?

In that case, a safer way of doing it compared to rewrite the entire block is to use event observers in a custom module:

In your config.xml add the following code

    <adminhtml>
        <events>
            <!-- event triggered after the original massaction items are added -->
            <adminhtml_catalog_product_grid_prepare_massaction>
                <observers>
                    <massaction_add>
                        <type>singleton</type>
                        <class>extension/observer</class>
                        <method>addAction</method>
                    </massaction_add>
                </observers>
            </adminhtml_catalog_product_grid_prepare_massaction>
        </events>
    </adminhtml>

Then create a Model/Observer.php file with the following content

<?php

class Vendor_Extension_Model_Observer
{
    /**
     * Add a new massaction
     * @param Varien_Event_Observer $observer
     */
    public function addAction(Varien_Event_Observer $observer)
    {
        $block = $observer->getEvent()->getBlock();

        $block->getMassactionBlock()->addItem('BarcodeLabel',
             array('label' => $this->__('Print barcode labels'),
                   'url'   => $this->getUrl('adminhtml/BarcodeLabel_Admin/printSelectedProductLabel')
             ));
    }
}

Be sure to replace extension with your extension name in the code I provided for config.xml as well as replacing the Observer.php class name with your module name and vendor.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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