dongshan8953 2016-07-14 13:10
浏览 45
已采纳

Magento - Adminhtml - 如何隐藏具有特定状态的订单?

I am using Magento 1.9.2 and i am using custom extension.

Here is it's config file:

<?xml version="1.0"?>
<config>
    <modules>
        <MageWorx_OrdersGrid>
            <version>2.0.2</version>
        </MageWorx_OrdersGrid>
    </modules>

    <admin>
        <routers>
            <adminhtml>
                <args>
                    <modules>
                        <MageWorx_OrdersGrid after="Mage_Adminhtml">MageWorx_OrdersGrid_Adminhtml</MageWorx_OrdersGrid>
                    </modules>
                </args>
            </adminhtml>
        </routers>
    </admin>

    <global>
        <blocks>
            <mageworx_ordersgrid>
                <class>MageWorx_OrdersGrid_Block</class>
            </mageworx_ordersgrid>
        </blocks>

        <models>

            <mageworx_ordersgrid>
                <class>MageWorx_OrdersGrid_Model</class>
                <resourceModel>mageworx_ordersgrid_resource</resourceModel>
            </mageworx_ordersgrid>

            <mageworx_ordersgrid_resource>
                <class>MageWorx_OrdersGrid_Model_Resource</class>
                <entities>
                    <order_group>
                        <table>mageworx_ordersgrid_order_group</table>
                    </order_group>
                </entities>
            </mageworx_ordersgrid_resource>
        </models>

        <helpers>
            <mageworx_ordersgrid>
                <class>MageWorx_OrdersGrid_Helper</class>
            </mageworx_ordersgrid>
        </helpers>

        <resources>
            <mageworx_ordersgrid_setup>
                <setup>
                    <module>MageWorx_OrdersGrid</module>
                    <class>MageWorx_OrdersGrid_Model_Resource_Setup</class>
                </setup>
                <connection>
                    <use>core_setup</use>
                </connection>
            </mageworx_ordersgrid_setup>
            <mageworx_ordersgrid_write>
                <connection>
                    <use>core_write</use>
                </connection>
            </mageworx_ordersgrid_write>
            <mageworx_ordersgrid_read>
                <connection>
                    <use>core_read</use>
                </connection>
            </mageworx_ordersgrid_read>
        </resources>
    </global>

    <frontend>
        <translate>
            <modules>
                <MageWorx_OrdersGrid>
                    <files>
                        <default>MageWorx_OrdersGrid.csv</default>
                    </files>
                </MageWorx_OrdersGrid>
            </modules>
        </translate>
        <layout>
            <updates>
                <mageworx_ordersgrid>
                    <file>mageworx_ordersgrid.xml</file>
                </mageworx_ordersgrid>
            </updates>
        </layout>
        <events>
            <sales_order_collection_load_before>
                <observers>
                    <mageworx_hide_deleted_orders>
                        <type>singleton</type>
                        <class>mageworx_ordersgrid/observer</class>
                        <method>hideDeletedOrders</method>
                    </mageworx_hide_deleted_orders>
                </observers>
            </sales_order_collection_load_before>
        </events>
    </frontend>

    <adminhtml>
        <events>
            <sales_order_grid_collection_load_before>
                <observers>
                    <enterprise_salesarchive>
                        <type>disabled</type>
                    </enterprise_salesarchive>
                    <mageworx_add_custom_columns_select>
                        <type>singleton</type>
                        <class>mageworx_ordersgrid/observer</class>
                        <method>addCustomColumnsSelect</method>
                    </mageworx_add_custom_columns_select>
                </observers>
            </sales_order_grid_collection_load_before>
            <core_block_abstract_to_html_before>
                <observers>
                    <mageworx_add_mass_actions>
                        <type>singleton</type>
                        <class>mageworx_ordersgrid/observer</class>
                        <method>addMassActionToSalesOrdersGrid</method>
                    </mageworx_add_mass_actions>
                </observers>
            </core_block_abstract_to_html_before>
            <core_layout_block_create_after>
                <observers>
                    <mageworx_add_custom_columns>
                        <type>singleton</type>
                        <class>mageworx_ordersgrid/observer</class>
                        <method>addCustomColumnsToSalesOrdersGrid</method>
                    </mageworx_add_custom_columns>
                    <mageworx_add_custom_columns_for_customer>
                        <type>singleton</type>
                        <class>mageworx_ordersgrid/observer</class>
                        <method>addCustomColumnsToCustomerOrdersGrid</method>
                    </mageworx_add_custom_columns_for_customer>
                </observers>
            </core_layout_block_create_after>
        </events>
        <layout>
            <updates>
                <mageworx_ordersgrid>
                    <file>mageworx_ordersgrid.xml</file>
                </mageworx_ordersgrid>
            </updates>
        </layout>
        <translate>
            <modules>
                <MageWorx_OrdersGrid>
                    <files>
                        <default>MageWorx_OrdersGrid.csv</default>
                    </files>
                </MageWorx_OrdersGrid>
            </modules>
        </translate>
    </adminhtml>

    <default>
        <mageworx_ordersmanagement>
            <ordersgrid>
                <enabled>1</enabled>
                <enable_shipping_price_edition>1</enable_shipping_price_edition>
                <enable_invoice_orders>1</enable_invoice_orders>
                <send_invoice_email>0</send_invoice_email>
                <enable_ship_orders>1</enable_ship_orders>
                <send_shipment_email>0</send_shipment_email>
                <enable_archive_orders>1</enable_archive_orders>
                <days_before_orders_get_archived>0</days_before_orders_get_archived>
                <archive_orders_status>canceled,closed,complete</archive_orders_status>
                <enable_delete_orders>1</enable_delete_orders>
                <hide_deleted_orders_for_customers>1</hide_deleted_orders_for_customers>
                <enable_delete_orders_completely>1</enable_delete_orders_completely>
                <grid_columns>
                    real_order_id,store_id,created_at,billing_name,shipping_name,base_grand_total,grand_total,status,order_group,action
                </grid_columns>
                <customer_grid_columns>increment_id,created_at,billing_name,shipping_name,grand_total,store_id,action
                </customer_grid_columns>
                <number_comments>3</number_comments>
                <show_thumbnails>1</show_thumbnails>
                <thumbnail_height>50</thumbnail_height>
            </ordersgrid>
        </mageworx_ordersmanagement>
    </default>

    <crontab>
        <jobs>
            <mageworx_ordersgrid_archive>
                <schedule>
                    <cron_expr>0 0 * * *</cron_expr>
                </schedule>
                <run>
                    <model>mageworx_ordersgrid/observer::scheduledArchiveOrders</model>
                </run>
            </mageworx_ordersgrid_archive>
        </jobs>
    </crontab>

</config>

Then i found this function in the observer:

public function hideDeletedOrders($observer)
{
    $helper = $this->getMwHelper();
    if ($helper->isEnabled() && $helper->isHideDeletedOrdersForCustomers()) {
        /** @var Mage_Sales_Model_Resource_Order_Collection $orderCollection */
        $orderCollection = $observer->getOrderCollection();
        $orderCollection->addFieldToFilter('order_group_id', array('neq' => '2'));
    }
}

And changed it to this:

public function hideDeletedOrders($observer)
{
    $helper = $this->getMwHelper();
    if ($helper->isEnabled() && $helper->isHideDeletedOrdersForCustomers()) {
        /** @var Mage_Sales_Model_Resource_Order_Collection $orderCollection */
        $orderCollection = $observer->getOrderCollection();
        $orderCollection->addFieldToFilter('order_group_id', array('neq' => '2'));
        $orderCollection->addFieldToFilter('status',array('neq' => 'epaycc'));
    }
}

So with this i was able to hide all orders with status epaycc from the frontend, but i don't know how to hide them for the admin panel also. I need that.

Here is the complete observer.php: http://pastebin.com/c60bMKbj

If you need any other file just let me know. I hope you can help me.

Thanks in advance!

  • 写回答

1条回答 默认 最新

  • duanming0494 2016-07-14 20:19
    关注

    please try to add this line:

    public function addCustomColumnsSelect($observer)
        {
            $helper = $this->getMwHelper();
            if ($helper->isEnabled()) {
            Varien_Profiler::start('mw_addCustomColumnsSelect');
            /** @var Mage_Sales_Model_Resource_Order_Grid_Collection $orderCollection */
            $orderGridCollection = $observer->getOrderGridCollection();
    
    
            /** add this line - start*/
            $orderGridCollection->addFieldToFilter('status', array('neq' => 'epaycc'));
            /** add this line - end*/
    
    
    
    
            /** @var MageWorx_OrdersGrid_Model_Grid $model */
            $model = Mage::getModel('mageworx_ordersgrid/grid');
            if (Mage::app()->getRequest()->getControllerName() == 'customer') {
                if (Mage::app()->getRequest()->getActionName() != 'orders') {
                    return;
                }
                $listColumns = $helper->getCustomerGridColumns();
                $model->modifyCustomerOrdersGridCollection($orderGridCollection, $listColumns);
            } else {
                $listColumns = $helper->getGridColumns();
                $model->modifyOrdersGridCollection($orderGridCollection, $listColumns);
            }
            Varien_Profiler::stop('mw_addCustomColumnsSelect');
        }
    
        return;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)