Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/magento/5.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
Events Magento-使用<;转换模块;重写>;将事件用于销售>;有序网格_Events_Magento_Magento 1.5 - Fatal编程技术网

Events Magento-使用<;转换模块;重写>;将事件用于销售>;有序网格

Events Magento-使用<;转换模块;重写>;将事件用于销售>;有序网格,events,magento,magento-1.5,Events,Magento,Magento 1.5,我制作了一个简单的模块,在销售>订单网格中添加了额外的字段。它工作得很好,但问题是我们正在使用的另一个模块订单网格将其字段添加到网格中。我想尝试将它改为使用事件(此外,这是一种更好的方法) 问题是我一直在努力,但我就是无法实现。(也许我还不能理解事件/观察者的概念…) 以下是我当前的模块结构: app/code/local/Artizara/OrderGridAdditions/ app/code/local/Artizara/OrderGridAdditions/Block/Sales/Ord

我制作了一个简单的模块,在销售>订单网格中添加了额外的字段。它工作得很好,但问题是我们正在使用的另一个模块
订单网格将其字段添加到网格中。我想尝试将它改为使用事件(此外,这是一种更好的方法)

问题是我一直在努力,但我就是无法实现。(也许我还不能理解事件/观察者的概念…)

以下是我当前的模块结构:

app/code/local/Artizara/OrderGridAdditions/
app/code/local/Artizara/OrderGridAdditions/Block/Sales/Order/Grid.php
app/code/local/Artizara/OrderGridAdditions/etc/config.xml
app/code/local/Artizara/OrderGridAdditions/controllers [empty]
app/code/local/Artizara/OrderGridAdditions/Helper [empty]
app/code/local/Artizara/OrderGridAdditions/Model [empty]
在我的Grid.php文件中,我已将主Grid.php文件内容复制到我的Grid.php文件中,并编辑了
\u getCollectionClass()
\u prepareCollection()
\u prepareColumns()
函数

我已将
\u getCollectionClass()
更改为:

//return 'sales/order_grid_collection';
return 'sales/order_collection';
$collection = Mage::getResourceModel($this->_getCollectionClass());

$collection->getSelect()->joinLeft(array('sfog' => 'sales_flat_order_grid'),'main_table.entity_id = sfog.entity_id',array('sfog.shipping_name','sfog.billing_name'));
$collection->getSelect()->joinLeft(array('sfo'=>'sales_flat_order'),'sfo.entity_id=main_table.entity_id',array('sfo.customer_email','sfo.weight','sfo.discount_description','sfo.increment_id','sfo.store_id','sfo.created_at','sfo.status','sfo.base_grand_total','sfo.grand_total','shipping_description','sfo.total_item_count'));
$collection->getSelect()->joinLeft(array('sfoa'=>'sales_flat_order_address'),'main_table.entity_id = sfoa.parent_id AND sfoa.address_type="shipping"',array('sfoa.street','sfoa.city','sfoa.region','sfoa.postcode','sfoa.telephone'));
//$collection->getSelect()->joinLeft(array('sfop' => 'sales_flat_order_payment'),'main_table.entity_id = sfop.entity_id',array('sfop.method'));

$this->setCollection($collection);

return parent::_prepareCollection();
我已将
\u prepareCollection()
更改为:

//return 'sales/order_grid_collection';
return 'sales/order_collection';
$collection = Mage::getResourceModel($this->_getCollectionClass());

$collection->getSelect()->joinLeft(array('sfog' => 'sales_flat_order_grid'),'main_table.entity_id = sfog.entity_id',array('sfog.shipping_name','sfog.billing_name'));
$collection->getSelect()->joinLeft(array('sfo'=>'sales_flat_order'),'sfo.entity_id=main_table.entity_id',array('sfo.customer_email','sfo.weight','sfo.discount_description','sfo.increment_id','sfo.store_id','sfo.created_at','sfo.status','sfo.base_grand_total','sfo.grand_total','shipping_description','sfo.total_item_count'));
$collection->getSelect()->joinLeft(array('sfoa'=>'sales_flat_order_address'),'main_table.entity_id = sfoa.parent_id AND sfoa.address_type="shipping"',array('sfoa.street','sfoa.city','sfoa.region','sfoa.postcode','sfoa.telephone'));
//$collection->getSelect()->joinLeft(array('sfop' => 'sales_flat_order_payment'),'main_table.entity_id = sfop.entity_id',array('sfop.method'));

$this->setCollection($collection);

return parent::_prepareCollection();
我在
\u prepareColumns()
中添加了如下列(此处仅添加一列作为示例):

在我的
config.xml
文件中,我有一个简单的

<modules>
    <Artizara_OrderGridAdditions>
        <version>0.1.0</version>
    </Artizara_OrderGridAdditions>
</modules>

<global>
    <blocks>
        <adminhtml>
            <rewrite>
                <sales_order_grid>Artizara_OrderGridAdditions_Block_Sales_Order_Grid</sales_order_grid>
            </rewrite>
        </adminhtml>
        <ordergridadditions>
            <class>Artizara_OrderGridAdditions_Block</class>
        </ordergridadditions>
    </blocks>

</global>
/etc/config.xml
中,我尝试了很多方法。以下是我的最新尝试:

<modules>
    <Artizara_OrderGridAdditions>
        <version>0.1.0</version>
    </Artizara_OrderGridAdditions>
</modules>

<adminhtml>
    <events>
        <adminhtml_block_html_before>
            <observers>
                <Artizara_OrderGridAdditions_Observer>
                    <class>Artizara_OrderGridAdditions_Model_Observer</class>
                    <method>addAdditionsToGrid</method>
                </Artizara_OrderGridAdditions_Observer>
            </observers>
        </adminhtml_block_html_before>
    </events>
</adminhtml>

<global>


    <models>
        <Artizara_OrderGridAdditions>
            <class>Artizara_OrderGridAdditions_Model</class>
        </Artizara_OrderGridAdditions>
    </models>

    <blocks>
        <Artizara_OrderGridAdditions>
            <class>Artizara_OrderGridAdditions_Block</class>
        </Artizara_OrderGridAdditions>
    </blocks>

    <helper>
        <Artizara_OrderGridAdditions>
            <class>Artizara_OrderGridAdditions_Helper</class>
        </Artizara_OrderGridAdditions>
    </helper>


</global>
addAdditionsToGrid()
中,我尝试了许多不同的方法,包括复制整个
Grid.php
文件,但似乎没有任何效果(错误):(

请帮助指导我使用事件重新创建这个简单的模块请!

没有(好的)方法通过观察者向销售订单网格添加列,因为没有事件调用。请查看
Mage::dispatchEvent
内部
Mage\u Adminhtml\u Block\u Sales\u Order\u网格
和所有超类

我认为最好的做法是像这样扩展grid类:

class Artizara_OrderGridAdditions_Block_Sales_Grid extends Mage_Adminhtml_Block_Sales_Order_Grid {
    protected function _prepareColumns() {
        $this->addColumn(/* your definition here */);
    }
}

如果你真的需要观察者来做这件事,你可以观察
adminhtml\u block\u html\u before
事件并找出一条出路,但是很多块也会调用这个事件。

那么你是说唯一的方法(或“最佳方法”)就是像我已经做的那样扩展网格类?那么与其他扩展的冲突呢(因此我为什么要尝试这个…?)我想我需要“挖出一条路”的帮助由于我似乎无法做到这一点…您可以简单地将
Mage\u Adminhtml\u Block\u Sales\u Order\u Grid
复制到app/code/local,并在需要的地方添加
Mage::dispatchEvent
呼叫,呼叫您自己的观察员。但是,这样您以后可能会在升级Magento时遇到问题。我想感谢您的持续帮助。我知道w您可以使用(core_block_abstract_prepare_layout_before)作为事件,将massaction选项添加到下拉列表(在Sales>Order Grid区域)。我尝试过使用该选项,但似乎仍然无法使其正常工作,我想这是因为我缺少了类似文件的内容/代码-某个地方,而不是
事件本身。我正在查看事件/观察者挂钩备忘单(),正如我首先回答的那样,Magento Admin中没有特定的观察者。我在这里测试了一些东西,并向Admin Sales Order grid添加了一列:
if($observer->getBlock()实例of Mage_Adminhtml_Block_Sales_Order_grid){$observer->getBlock()->addColumn(/*列定义*/);}
在观察之前的
adminhtml\u block\u html\u时
这不是一个好方法,但可以让事情变得更简单。我会继续寻找更好的方法来做到这一点。我认为这不是使用
core\u block\u abstract\u prepare\u layout\u的好方法,因为它也是从前端调用的。
class Artizara_OrderGridAdditions_Block_Sales_Grid extends Mage_Adminhtml_Block_Sales_Order_Grid {
    protected function _prepareColumns() {
        $this->addColumn(/* your definition here */);
    }
}