PHP define constants with arrays

You need to define a constant containing an array but the code below doesn’t work ?

define('FILTER_ECOLE', array('price, categorie, niveau'));

You get an error :

Notice: Use of undefined constant FILTER_ECOLE - assumed 'FILTER_ECOLE'  in /home/www/adin/app/code/local/Adin/Catalog/Block/Nav/Catalog/Layer/View/Sidebar.php on line 50

To define an use a constant containing an array you can simply serialize it :

#define
define('FILTER_ECOLE', serialize(array('price, categorie, niveau')));

#use
$filter = unserialize(FILTER_ECOLE);

Magento – update attribute parameters programmatically

This is how you can update attribute parameters, the one saved in catalog_eav_attribute table

In this exemple we will enable the “used_in_product_listing” params of the “code_catalogue” attribute

$attributeId = Mage::getResourceModel('eav/entity_attribute')->getIdByCode('catalog_product','code_catalogue');
if ($attributeId) {
    $attribute = Mage::getModel('catalog/resource_eav_attribute')->load($attributeId);
    $attribute->setUsedInProductListing(1)->save();
}

And that’s all.

Magento – How to get current router module controller action ?

You can easily know “where you are” using these fonctions :

in template / block files

$this->getRequest()->getRouteName();
$this->getRequest()->getModuleName();
$this->getRequest()->getControllerName();
$this->getRequest()->getActionName();

in class files

Mage::app()->getRequest()->getRouteName();
Mage::app()->getRequest()->getModuleName();
Mage::app()->getRequest()->getControllerName();
Mage::app()->getRequest()->getActionName();