Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Adding specific attribute value to adming catalog filter
 
imiller97
Jr. Member
 
Total Posts:  1
Joined:  2008-06-20
 

I have a catalog with 900+ products where I would like to update the attributes of a selected group of products.  The selection criteria is a specific value of one attribute.  What I would like to do is modify the Admin “manage products” page to contain a column which allows a specification of one value for one attribute (of the selected attribute set).  I can create the column in the page via ...Catalog/Product/Grid.php, but I am not familiar enough with the data model and mechanics of Mage to create the mechanism for specifying the attribute and value.  This would allow me to “select all” and do a batch update of some other attributes for those products.

In my particular case the attribute values are of “dropdown” type so there is a limited range of possible values (all are text), although a solution where any text value can be entered would be fine too.

I am very grateful for any help, pointers, or general hints on the data model.  Going through and editing all 900+ products isn’t exactly a fun thought wink and I’m a bit gunshy to simply update the tables directly through SQL (again, I’m not sure about the data model and thus not sure what repercussions the attribute value change might have).

Many thanks,
Ian

 
Magento Community Magento Community
Magento Community
Magento Community
 
evL
Member
 
Total Posts:  32
Joined:  2008-04-23
 

Have you been able to fix your problem ?

I have the same issue with a custom attribute ... can’t figure out how to put it on the Grid.

 
Magento Community Magento Community
Magento Community
Magento Community
 
BoostMyShop
Sr. Member
 
Avatar
Total Posts:  155
Joined:  2008-06-11
France
 

first override Catalog/Product/Grid.php in order to add your own column: in the adcolumn function, u can set a renderer that is a class that control the way the column values are displayed.

Second, create your renderer class and add code to display a select control including values u want to display in. (example of a renderer : app\code\core\Mage\Adminhtml\Block\Sales\Reorder\Renderer)

Third, create your own mass action (for example save) in grid.php too: when user will select mass action, form data will be send to the matching controller (in your case, probably app/code/core/mage/adminhtml/models/catalog/controllers/ProductController): in this file, add a method names [your_mass_actio_name]Action

In this method u can retrieve form data using $this->getRequest()->getPost($myfieldname)

 
Magento Community Magento Community
Magento Community
Magento Community
 
evL
Member
 
Total Posts:  32
Joined:  2008-04-23
 

Can you post some concrete example ?

 
Magento Community Magento Community
Magento Community
Magento Community
 
nikefido
Guru
 
Avatar
Total Posts:  481
Joined:  2008-07-11
New Haven, CT
 
olixelle - 07 August 2008 01:47 PM

first override Catalog/Product/Grid.php in order to add your own column: in the adcolumn function, u can set a renderer that is a class that control the way the column values are displayed.

Second, create your renderer class and add code to display a select control including values u want to display in. (example of a renderer : app\code\core\Mage\Adminhtml\Block\Sales\Reorder\Renderer)

Third, create your own mass action (for example save) in grid.php too: when user will select mass action, form data will be send to the matching controller (in your case, probably app/code/core/mage/adminhtml/models/catalog/controllers/ProductController): in this file, add a method names [your_mass_actio_name]Action

In this method u can retrieve form data using $this->getRequest()->getPost($myfieldname)

That’s great info for a start! (Guys I suggest following his file locations to see sample code)

Left unfinished is what to do with that request data - that might involves your own Models to enter the info into the database (altho it seems to me that adding or editing an attribute would be something that would be “built into” magento’s classes somewhere...).
Perhaps try to find some core code that handles updating / changing attributes - most likely a Controller class found in conjunction with a model…

Check out files in app/code/core/Mage/Eav/Model/Entity/Attribute (and other places...like in the Model folder in the Catalog area in the Core code) for reference.
(good luck, that’s a potential mess to wade through!)

On the bright side, you might be able to find the code that handles this “update all” functionality and just tag the extra added data along by seeing the code there - I’m not sure where that is....)

 
Magento Community Magento Community
Magento Community
Magento Community
 
BoostMyShop
Sr. Member
 
Avatar
Total Posts:  155
Joined:  2008-06-11
France
 

Here are some code samples.
My module namespace is MDN, module name is MageCustomization.

I hope this could help u..

first override Catalog/Product/Grid.php in order to add your own column: in the adcolumn function, u can set a renderer that is a class that control the way the column values are displayed.

I override sales order grid:

Add code in ur module config.xml to override the grid:

<global>
           <
blocks>
            <
adminhtml>
             <
rewrite>
        <
sales_order_grid>MDN_MageCustomization_Block_Adminhtml_Sales_Order_Grid</sales_order_grid>
             </
rewrite>
                               ........

Create MDN_MageCustomization_Block_Adminhtml_Sales_Order_Grid class in app/code/local/mdn/MageCustomization/block/adminhtml/sales/order/grid.php:

<?php

/*
* Rajouter une colonne "commande complete" dans la liste des commandes
* dans l'interface d'admin
*/
class MDN_MageCustomization_Block_Adminhtml_Sales_Order_Grid extends Mage_Adminhtml_Block_Sales_Order_Grid
{
    
    
public function addAfterColumn($columnId$column,$indexColumn{
        $columns 
= array();
        foreach (
$this->_columns as $gridColumnKey => $gridColumn{
            $columns[$gridColumnKey] 
$gridColumn;
            if(
$gridColumnKey == $indexColumn{
                $columns[$columnId] 
$this->getLayout()->createBlock('adminhtml/widget_grid_column')
                        ->
setData($column)
                        ->
setGrid($this);
                
$columns[$columnId]->setId($columnId);         
            
}
        }
        $this
->_columns $columns;
        return 
$this;
    
}
    
    
public function addBeforeColumn($columnId$column,$indexColumn{
        $columns 
= array();
        foreach (
$this->_columns as $gridColumnKey => $gridColumn{
            
if($gridColumnKey == $indexColumn{
                $columns[$columnId] 
$this->getLayout()->createBlock('adminhtml/widget_grid_column')
                        ->
setData($column)
                        ->
setGrid($this);
                
$columns[$columnId]->setId($columnId);         
            
}
            $columns[$gridColumnKey] 
$gridColumn;
        
}
        $this
->_columns $columns;
        return 
$this;
    
}
        
    
protected function _prepareColumns()
    
{
        parent
::_prepareColumns();
            
        
//Colonne pour commande complete
        
$this->addAfterColumn('complete_order', array(
            
'header'=> Mage::helper('MageCustomization')->__('Complete'),
            
'renderer'  => 'MDN_MageCustomization_Block_Adminhtml_Widget_Grid_Column_Renderer_CompleteOrderColumn',
            
'width' => '40px',
            
'type'  => 'options',
            
'index' => 'complete_order',
            
'align' => 'center',
            
'options' => Mage::getSingleton('MageCustomization/CompleteOrderColumn')->getStatuses(),
        ),
'status');

         
}

    
/*
    * Mass actions pour fianet & mageCustomization
    */
    
protected function _prepareMassaction()
    
{
        parent
::_prepareMassaction();
        
$this->getMassactionBlock()
        ->
addItem('payment_setfull', array(
             
'label'=> Mage::helper('MageCustomization')->__('Set as Paid'),
             
'url'  => $this->getUrl('fianet/adminhtml_index/masssetaspaid'),))
        ;
        
        return 
$this;
    
}
}

?>

Second, create your renderer class and add code to display a select control including values u want to display in. (example of a renderer : app\code\core\Mage\Adminhtml\Block\Sales\Reorder\Renderer)

In my sample, file app/code/local/mdn/magecustomization/block/adminhtml/widget/grid/column/renderer/CompleteOrderColumn.php :

<?php

/*
* définit comment doit etre desssiné la colonne "compltet" dans la liste des commandes
*/
class MDN_MageCustomization_Block_Adminhtml_Widget_Grid_Column_Renderer_CompleteOrderColumn
    
extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract 
{
    
public function render(Varien_Object $row)
    
{
        
return $this->_getEvaluationElement($row);
    
}
    
    
protected function _getEvaluationElement($row){
        
        
//recupere la commande
        
$CommandComplete true;
        
$order $row;
        
        
//en fonction du statut de la commande
        
$OrderStatus $order->getStatusCode();
        if ((
$OrderStatus == Mage_Sales_Model_Order::STATE_CANCELED) || ($OrderStatus == Mage_Sales_Model_Order::STATE_CLOSED )  || ($OrderStatus == Mage_Sales_Model_Order::STATE_COMPLETE))
        
{
            
return "-";
        
}
        
else 
        
{
            
if ($order->IsWaitingForSupply())
                return 
"<font color=\"#FF0000\">Non</font>";
            
else 
                return 
"<font color=\"#00FF00\">Oui</font>";
        
}
    }
}

Third, create your own mass action (for example save) in grid.php too: when user will select mass action, form data will be send to the matching controller (in your case, probably app/code/core/mage/adminhtml/models/catalog/controllers/ProductController): in this file, add a method names [your_mass_actio_name]Action

Take a look at prepareMassaction in the first code sample.
To catch submission in ur controller, u have to override the controller using url redirect:

....

SOrry i have to go, i’ll continue that post tomorrow smile

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top