Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/284.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 将列添加到Magento admin catolog>;管理产品_Php_Magento - Fatal编程技术网

Php 将列添加到Magento admin catolog>;管理产品

Php 将列添加到Magento admin catolog>;管理产品,php,magento,Php,Magento,您好,我想在catolg>管理产品部分添加一列(不是产品,而是产品列表),此列需要列出产品与之标识的任何相关产品-可能按sku或名称-无偏好 我为manufacturer添加了一列,但忘记了代码是从哪里获得的 谢谢,我最近(事实上是昨天)不得不在同一个网格中添加一列。部分原因是因为这是一个糟糕的实践,主要是因为另一个模块已经使用了它自己的重写,我不想完全替换或重写这个类。相反,这里有一种通过事件修改产品网格的干净方法 app/code/local/My/Module/etc/config.xml

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

我为manufacturer添加了一列,但忘记了代码是从哪里获得的

谢谢,我最近(事实上是昨天)不得不在同一个网格中添加一列。部分原因是因为这是一个糟糕的实践,主要是因为另一个模块已经使用了它自己的重写,我不想完全替换或重写这个类。相反,这里有一种通过事件修改产品网格的干净方法

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>
要改进钟表匠的回答,请执行以下操作:

我决定不使用观察员,在我看来,这些事件太全球化,导致我们的观察员多次被呼叫。在您自己的模块config.xml中使用以下重写:

<config>
    <global>
        <blocks>
            <adminhtml>
               <rewrite>
                   <catalog_product_grid>Myname_Catalogextended_Block_Adminhtml_Catalog_Product_Grid</catalog_product_grid>
               </rewrite>
           </adminhtml>
        </blocks>
    </global>
</config>
包含以下内容:

<?php

class Myname_Catalogextended_Block_Adminhtml_Catalog_Product_Grid extends Mage_Adminhtml_Block_Catalog_Product_Grid
{
    /* Overwritten to be able to add custom columns to the product grid. Normally
     * one would overwrite the function _prepareCollection, but it won't work because
     * you have to call parent::_prepareCollection() first to get the collection.
     *
     * But since parent::_prepareCollection() also finishes the collection, the
     * joins and attributes to select added in the overwritten _prepareCollection()
     * are 'forgotten'.
     *
     * By overwriting setCollection (which is called in parent::_prepareCollection()),
     * we are able to add the join and/or attribute select in a proper way.
     *
     */
    public function setCollection($collection)
    {
        /* @var $collection Mage_Catalog_Model_Resource_Product_Collection */

        $store = $this->_getStore();

        if ($store->getId() && !isset($this->_joinAttributes['special_price'])) {
            $collection->joinAttribute(
                'special_price',
                'catalog_product/special_price',
                'entity_id',
                null,
                'left',
                $store->getId()
            );
        }
        else {
            $collection->addAttributeToSelect('special_price');
        }

        parent::setCollection($collection);
    }

    protected function _prepareColumns()
    {
        $store = $this->_getStore();
        $this->addColumnAfter('special_price',
            array(
                'header'=> Mage::helper('catalog')->__('special_price'),
                'type'  => 'price',
                'currency_code' => $store->getBaseCurrency()->getCode(),
                'index' => 'special_price',
            ),
            'price'
         );

        return parent::_prepareColumns();
    }
}

我更新了这个答案,这样管理员就可以用新添加的专栏来过滤产品了!这太棒了!我唯一看不到的是对新列进行排序的功能。FWIW。。。我最终在这个与过滤和排序有关的变体上获得了更好的成功。。。这种“另类”方法看起来更像我原来的帖子。Bang Dao的修改非常重要,回想起来,我更希望看到他单独回答,而不是劫持我的答案。你如何重命名观察者?
app/code/local/Myname/Catalogextended/Block/Adminhtml/Catalog/Product/Grid.php
<?php

class Myname_Catalogextended_Block_Adminhtml_Catalog_Product_Grid extends Mage_Adminhtml_Block_Catalog_Product_Grid
{
    /* Overwritten to be able to add custom columns to the product grid. Normally
     * one would overwrite the function _prepareCollection, but it won't work because
     * you have to call parent::_prepareCollection() first to get the collection.
     *
     * But since parent::_prepareCollection() also finishes the collection, the
     * joins and attributes to select added in the overwritten _prepareCollection()
     * are 'forgotten'.
     *
     * By overwriting setCollection (which is called in parent::_prepareCollection()),
     * we are able to add the join and/or attribute select in a proper way.
     *
     */
    public function setCollection($collection)
    {
        /* @var $collection Mage_Catalog_Model_Resource_Product_Collection */

        $store = $this->_getStore();

        if ($store->getId() && !isset($this->_joinAttributes['special_price'])) {
            $collection->joinAttribute(
                'special_price',
                'catalog_product/special_price',
                'entity_id',
                null,
                'left',
                $store->getId()
            );
        }
        else {
            $collection->addAttributeToSelect('special_price');
        }

        parent::setCollection($collection);
    }

    protected function _prepareColumns()
    {
        $store = $this->_getStore();
        $this->addColumnAfter('special_price',
            array(
                'header'=> Mage::helper('catalog')->__('special_price'),
                'type'  => 'price',
                'currency_code' => $store->getBaseCurrency()->getCode(),
                'index' => 'special_price',
            ),
            'price'
         );

        return parent::_prepareColumns();
    }
}