1
votes

ok, so this isn't my first mass action but, this does have me scratching my head.

I made a module CLR_exportMassAction. Deployed it on the good old localhost with no problems. However when I move the files out to my server, nothing happens. I have reindexed and flushed caches. I have a feeling its some configuration weirdness and magento isn't hooking in my module.

Here is my code: \local\CLR\exportMassAction\etc\config.xml

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <global>
        <models>
            <CLR_exportMassAction>
                <class>CLR_exportMassAction_Model</class>
            </CLR_exportMassAction>
        </models>
    </global>
    <adminhtml>        
        <events>
            <adminhtml_block_html_before>
                <observers>
                    <CLR_exportMassAction>
                        <type>singleton</type>
                        <class>CLR_exportMassAction/observer</class>
                        <method>addExportMassactionToProductGrid</method>
                    </CLR_exportMassAction>
                </observers>
            </adminhtml_block_html_before>

        </events>        
    </adminhtml>

    <admin>
        <routers>
            <adminhtml>
                <args>
                    <modules>
                        <CLR_exportMassAction before="Mage_Adminhtml">CLR_exportMassAction_Adminhtml</CLR_exportMassAction>
                    </modules>
                </args>
            </adminhtml>
        </routers>
    </admin>        

</config>

local\CLR\exportMassAction\Model\Observer.php

<?php

class CLR_exportMassAction_Model_Observer
{


public function addExportMassactionToProductGrid($observer)
{
    $block = $observer->getBlock();
      if($block instanceof Mage_adminHtml_Block_Catalog_Product_Grid) {
           $block ->getMassactionBlock()->addItem('export', array(
                  'label' => Mage::helper('catalog')->__('Export to CSV'),
                  'url'   => $block->getUrl('*/*/massExport', array('_current'=>true)),
                   ));
        }
}



}

local\CLR\exportMassAction\controllers\Adminhtml\Catalog\ProductController.php

<?php

class CLR_exportMassAction_Adminhtml_Catalog_ProductController extends Mage_Adminhtml_Controller_Action
{

    public function massExportAction()
    {
        $productIds = $this->getRequest()->getParam('product');
        if (!is_array($productIds)) {
            $this->_getSession()->addError($this->__('Please select product(s).'));
            $this->_redirect('*/*/index');
        }
        else {
            //write headers to the csv file
            $content = "id,name,url,sku\n";
            try {
                foreach ($productIds as $productId) {
                    $product = Mage::getSingleton('catalog/product')->load($productId);
                    $content .= "\"{$product->getId()}\",\"{$product->getName()}\",\"{$product->getProductUrl()}\",\"{$product->getSku()}\"\n";
                }
            } catch (Exception $e) {
                $this->_getSession()->addError($e->getMessage());
                $this->_redirect('*/*/index');
            }
            $this->_prepareDownloadResponse('export.csv', $content, 'text/csv');
        }

    }



}

app\etc\CLR_exportMassAction.xml

<config>
    <modules>
        <CLR_exportMassAction>
            <active>true</active>
            <codePool>community</codePool>
        </CLR_exportMassAction>
    </modules>
</config>

I am just looking for a pointer really on where to go from here; I am not sure what the next troubleshooting options are.

1

1 Answers

0
votes

Most likely, your local setup is running on a case-insensitive file system (are you on Windows?), whereas your server is running on a case-sensitive file system (probably Linux).

Magento does a lot of string manipulation to convert class names into file names and such. For example, see Varien_Autoload::autoload(), which I presume is causing your problem:

$classFile = str_replace(' ', DIRECTORY_SEPARATOR, ucwords(str_replace('_', ' ', $class)));

If you plug in your observer class (CLR_exportMassAction_Model_Observer, after resolving CLR_exportMassAction/observer), you get:

str_replace('_', ' ', 'CLR_exportMassAction_Model_Observer')
  = 'CLR exportMassAction Model Observer'

ucwords('CLR exportMassAction Model Observer')
  = 'CLR ExportMassAction Model Observer'

str_replace(' ', DIRECTORY_SEPARATOR, 'CLR ExportMassAction Model Observer')
  = 'CLR/ExportMassAction/Model/Observer'

So, Magento is looking for a file called CLR/ExportMassAction/Model/Observer.php, but your file is called CLR/exportMassAction/Model/Observer.php - see the lower-case e?

There might be some other casing issues as well, but this is the most prominent one.

I recommend renaming your module namespace from CLR to Clr, and your actual module from exportMassAction to Exportmassaction, and making sure that all of your class names and file names match precisely. This is the easiest way to avoid casing issues with Magento (even if you have multiple words in the same identifier).