0

Stemming from my last question, I am stumped trying to do an override. I am doing exactly what MudithaE's answer here did, too.

I want to implement my own _prepareColumns() as found in the file app/code/core/Mage/Adminhtml/Block/Sales/Order/Grid.php. I set up my module's directories and the files as below. While researching, I saw a lot of developers like to do Dev_Module_Block_Adminhtml_blah, so I tried changing the directory structure and class names everywhere in my code. No change. My Cycleworks_SalesGridImproved module appears in the System -> Config -> Advanced listing, too.

Files: app/code/local/Cycleworks/SalesGridImproved/Adminhtml/Block/Sales/Order/Grid.php:

<?php
class Cycleworks_SalesGridImproved_Adminhtml_Block_Sales_Order_Grid  extends Mage_Adminhtml_Block_Sales_Order_Grid {
    protected function _prepareColumns() // tried public too
    {
                    parent::_prepareColumns();
        ...
        ...
        $this->addColumn('created_at', array(
            'header' => Mage::helper('sales')->__('Purchased On'),
            'index' => 'created_at',
             'type' => 'datetime',
             'format' => 'MMM d, h:mm a',
            'width' => '165px', 
        ));
        ...
        ...
        return $this; 
    }
}

app/code/local/Cycleworks/SalesGridImproved/etc/config.xml:

<?xml version="1.0"?>
<config>
    <modules>
        <!-- also tried: Cycleworks_SalesGridImproved -->
        <Cycleworks_Adminhtml>
            <version>0.0.01</version>
        </Cycleworks_Adminhtml>
    </modules>

    <global>
        <blocks>
            <adminhtml>
                <salesgridimproved>
                      <class>Cycleworks_SalesGridImproved_Adminhtml_Block_Sales_Order_Grid</class>
                </salesgridimproved>
                <rewrite>
                    <sales_order_grid>Cycleworks_SalesGridImproved_Adminhtml_Block_Sales_Order_Grid</sales_order_grid>
                </rewrite>
            </adminhtml>
        </blocks>        
    </global>

</config>

And in /app/etc/modules/Cycleworks_SalesGridImproved.xml:

<?xml version="1.0"?>
<config>
    <modules>
        <Cycleworks_SalesGridImproved>
            <active>true</active>
            <codePool>local</codePool>
        </Cycleworks_SalesGridImproved>
    </modules>
</config>  

Please show me see what I'm missing... Thanks!


Update:

Just found out the extension EM_DeleteOrder is also overriding the same sales order grid class that I am. His extension's configuration is more complicated than mine, as his is set up to be called before the Mage core. The config.xml sure is busy!

<?xml version="1.0"?>
<config>
    <modules>
        <EM_DeleteOrder>
            <version>1.0.0</version>
        </EM_DeleteOrder>
    </modules>
    <global>
        <rewrite>
        <em_emadmin_adminhtml_sales_order>
            <from><![CDATA[#/admin/sales_order/#]]></from>
            <to>/emadmin/adminhtml_sales_order/</to>
        </em_emadmin_adminhtml_sales_order>
        </rewrite>

        <blocks>
            <adminhtml>
                <rewrite>
                    <sales_order_grid>EM_DeleteOrder_Block_Adminhtml_Sales_Order_Grid</sales_order_grid>
                </rewrite>
            </adminhtml>
        </blocks>       
    </global>
    <admin>
        <routers>
            <em_deleteorder>
                <use>admin</use>
                <args>
                    <module>EM_DeleteOrder</module>
                    <frontName>emadmin</frontName>
                </args>
            </em_deleteorder>           
            <adminhtml>
                <args>
                  <modules>
                    <EM_DeleteOrder_Adminhtml before="Mage_Adminhtml">EM_DeleteOrder_Adminhtml</EM_DeleteOrder_Adminhtml>
                  </modules>
                </args>
            </adminhtml>
        </routers>
    </admin>
</config>

Do you have any thoughts how I can use similar syntax and get my module to work and not have to hack his code? Like with an after="Mage_Adminhtml"?


Final Update: Sadly, the 3 answers below weren't the answer, it was the extension conflict. I'll answer my own question and mark it answered.

Community
  • 1
  • 1
Krista K
  • 21,503
  • 3
  • 31
  • 43

4 Answers4

3

I just tried this and it works. I think by returning parent::_prepareColumns() that it's ignoring your change. Adding it at the top of the function then returning $this works fine for me.

<?php
class Cycleworks_SalesGridImproved_Adminhtml_Block_Sales_Order_Grid  extends Mage_Adminhtml_Block_Sales_Order_Grid {
protected function _prepareColumns() // tried public too
{
//       ...
  //     ...

parent::_prepareColumns();



    $this->addColumn('created_at', array(
        'header' => Mage::helper('sales')->__('Purchased On'),
        'index' => 'created_at',
         'type' => 'datetime',
         'format' => 'MMM d, h:mm a',
        'width' => '165px',
    ));
 //   ...
   // ...
    return $this; #parent::_prepareColumns();
}
}
seanbreeden
  • 6,104
  • 5
  • 36
  • 45
  • Hi Sean, thanks for your answer! It's still not working for me. I tried your changes. Then I put an `exit;` in, too. My code isn't being executed at all. – Krista K Feb 19 '13 at 20:02
  • I copied your code exactly into a dev copy of Magento and this mod worked for me. Try installing Magento from scratch and copy your module exactly how you have it in your question. If it isn't executing then double check your folder names and cases. Be sure to clear your cache too. – seanbreeden Feb 19 '13 at 20:18
  • Digging through this EM_DeleteOrder is overriding the same slaes order grid class that I am. His extension's configuration is more complicated than mine. Perhaps if I use the same "tricks" as his on mine, I can get my extension called last – Krista K Feb 20 '13 at 01:48
2

I'm answering myself, as this was a big lesson in extension conflicts and their resolution. Further, I learned a lot about our particular installation and how sloppy extensions can break everything.

As in the update, EM_DeleteOrder was overriding Adminhtml Block Sales Order Grid (absog). I also used the extension MDN_ExtensionConflict and while it wasn't detecting my exact conflict, it did show me that EM_DeleteOrder was using absog. I searched for extensions that would allow deletion of orders without using absog, which must be the easy way to go about it.

The extension Asperience_DeleteAllOrders manages to do this without overwriting the whole page and instead catches something in the router. Its config.xml is abstract art to me, so if you're an advanced developer, I think you'd appreciate his work more than I.

Ultimately, I found MageWorx_ExtendedOrders which replaces the entire absog with their own grid and has configurable additional columns. Included are custom shipping rates, order editing, deletion of orders, and order archiving. I am impressed with this extension for $149. I also am going through deleting the multiple extensions that were replaced with MageWorx_ExtendedOrders. I'm hacking their extension's code to put the columns in my desired order and to update the date format (and I'll share my changes with them as feature suggestions).

Krista K
  • 21,503
  • 3
  • 31
  • 43
1

_prepareColumns() is protected, not public.

benmarks
  • 23,384
  • 1
  • 62
  • 84
1

Try putting adminhtml folder inside block folder i.e. app/code/local/Cycleworks/SalesGridImproved/Block/Adminhtml/Sales/Order/Grid

ANKIT
  • 341
  • 3
  • 13
  • Thanks, that was one of the things I tried as that seems popular with developers. I'm pretty sure this is a router issue I need to solve with the EM_DeleteOrder extension. – Krista K Feb 20 '13 at 19:16