将列添加到 Magento 管理目录 >管理产品

Add column to Magento admin catolog gt; manage products(将列添加到 Magento 管理目录 管理产品)
本文介绍了将列添加到 Magento 管理目录 >管理产品的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

您好,我想在 catolg > 管理产品部分添加一列(不是产品,而是产品列表),此列需要列出产品已与其标识的任何相关产品 - 可能是按 sku 或名称 - 否偏好那里.

Hi I want to add a column to the catolg > manage products section (not the product but the list of products), this column needs to list any related products the product has identified with it - maybe by sku or name - no preferance there.

我为制造商添加了一列,但忘记了从哪里获得代码.

I added a column for manufacturer but forgot where i obtained the code from.

谢谢

推荐答案

我最近(实际上是昨天)不得不在同一个网格中添加一列.部分是因为这是不好的做法,主要是因为另一个模块已经使用了它自己的覆盖,我不想完全替换或覆盖该类.相反,这里提供了一种通过事件修改产品网格的简洁方法.

I recently (yesterday in fact) had to add a column to the same grid. Partly because it is poor practice and mostly because another module had already used it's own override, I didn't want to replace or override the class completely. Instead here is a clean way to modify the product's grid via events.

app/code/local/My/Module/etc/config.xml

<config>
    <adminhtml>
        <events>
            <adminhtml_block_html_before>
                <observers>
                    <mymodule>
                        <!-- Add column to catalog product grid -->
                        <class>mymodule/adminhtml_observer</class>
                        <method>onBlockHtmlBefore</method>
                    </mymodule>
                </observers>
            </adminhtml_block_html_before>
            <eav_collection_abstract_load_before>
                <observers>
                    <mymodule>
                        <!-- Add column to product list -->
                        <class>mymodule/adminhtml_observer</class>
                        <method>onEavLoadBefore</method>
                    </mymodule>
                </observers>
            </eav_collection_abstract_load_before>
        </events>
    </adminhtml>
</config>

app/code/local/My/Module/Model/Adminhtml/Observer

class My_Module_Model_Adminhtml_Observer
{

    public function onBlockHtmlBefore(Varien_Event_Observer $observer) {
        $block = $observer->getBlock();
        if (!isset($block)) return;

        switch ($block->getType()) {
            case 'adminhtml/catalog_product_grid':
                /* @var $block Mage_Adminhtml_Block_Catalog_Product_Grid */
                $block->addColumn('COLUMN_ID', array(
                    'header' => Mage::helper('mymodule')->__('COLUMN HEADER'),
                    'index'  => 'COLUMN_ID',
                ));
                break;
        }
    }

    public function onEavLoadBefore(Varien_Event_Observer $observer) {
        $collection = $observer->getCollection();
        if (!isset($collection)) return;

        if (is_a($collection, 'Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection')) {
            /* @var $collection Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection */
            // Manipulate $collection here to add a COLUMN_ID column
            $collection->addExpressionAttributeToSelect('COLUMN_ID', '...Some SQL goes here...');
        }
    }

}

这篇关于将列添加到 Magento 管理目录 >管理产品的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

In PHP how can you clear a WSDL cache?(在 PHP 中如何清除 WSDL 缓存?)
failed to open stream: HTTP wrapper does not support writeable connections(无法打开流:HTTP 包装器不支持可写连接)
Stop caching for PHP 5.5.3 in MAMP(在 MAMP 中停止缓存 PHP 5.5.3)
Caching HTTP responses when they are dynamically created by PHP(缓存由 PHP 动态创建的 HTTP 响应)
Memcached vs APC which one should I choose?(Memcached 与 APC 我应该选择哪一个?)
What is causing quot;Unable to allocate memory for poolquot; in PHP?(是什么导致“无法为池分配内存?在 PHP 中?)