質問

When going to edit a configurable product, it would be nice to see the status (enabled/disabled) of each of the simple products when going to Associated products tab. I'm not using the stock options but instead managing products by their status manually so this is the only way to see if the associated products are in use or not. Any idea how to achieve this?

I found out one way it could be done is by adding something like the following in /app/core/code/Adminhtml/Block/Catalog/Product/Edit/Tab/Super/Config/Grid.php

        $this->addColumn('status', array(
        'header'    => Mage::helper('catalog')->__('Status'),
        'renderer'  => 'adminhtml/catalog_product_edit_tab_super_config_grid_renderer_status',
        'filter'    => 'adminhtml/catalog_product_edit_tab_super_config_grid_filter_status',
        'index'     => 'status'
    ));

The above code snippet is a copy of the way in which the SKU is added to the grid. My problem is I cannot find where e.g. "adminhtml/catalog_product_edit_tab_super_config_grid_renderer_sku" or "adminhtml/catalog_product_edit_tab_super_config_grid_sku" are defined so I could clone the functionality.

Any tips where to look would be welcome...might not be a good idea to edit the core files anyways so tip of how to do this with an extension would be appreciated :)

役に立ちましたか?

解決

Firstly you should not make any edit to core

Take a look at Add custom renderer for a custom column in Magento grid

renderer - will display the content in the grid filter - Will all you to search that column in the grid

However I dont think using renderer is the way to go here.

There are other methods to accomplish this but one of the quickest is to rewrite Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Super_Config_Grid (see how to rewrite grid)

class <Module>_<Company>_Block_Catalog_Product_Edit_Tab_Super_Config_Grid extends Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Super_Config_Grid
{
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Prepare collection
     *
     * @return Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Super_Config_Grid
     */
    protected function _prepareCollection()
    {
        $allowProductTypes = array();
        foreach (Mage::helper('catalog/product_configuration')->getConfigurableAllowedTypes() as $type) {
            $allowProductTypes[] = $type->getName();
        }

        $product = $this->_getProduct();
        $collection = $product->getCollection()
            ....
            ->addAttributeToSelect('status')
            ....
            ->joinAttribute('name', 'catalog_product/name', 'entity_id', null, 'inner');

        ...
    }


    protected function _prepareColumns()
    {
        $product = $this->_getProduct();
        $attributes = $product->getTypeInstance(true)->getConfigurableAttributes($product);

        ...

         $this->addColumn('status', array(
            //'filter_index' => 'status',
            'header' => Mage::helper('sales')->__('Status'),
            'index' => 'status',
            'type'  => 'options',
            'width' => '70px',
            'filter_index' => 'status',
            'options' => Mage::getSingleton('catalog/product_status')->getOptionArray(),
        ));
...
}

他のヒント

Essentially you're defining a rendering block. So ideally, with an extension, you would first extend (and rewrite) the Admin Grid you noted there, and then setup a renderer within your module for the added status column.

You would then be able to define the output in the renderer similarly to the Inventory renderer (adminhtml/catalog_product_edit_tab_super_config_grid_renderer_inventory), which represents the block Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Super_Config_Grid_Renderer_Inventory.

ライセンス: CC-BY-SA帰属
所属していません magento.stackexchange
scroll top