Magento销售订单视图过滤器集合

时间:2013-11-13 10:56:13

标签: magento collections filter magento-1.7

我有一个小问题 我想过滤admin sales order view集合。
我试过了,但找不到收集文件 请帮忙。

3 个答案:

答案 0 :(得分:0)

试试这些,它为我工作,

<?php
require_once('app/Mage.php'); //Path to Magento
umask(0);
Mage::app();
//echo $name = Mage::app()->getStore()->getId();

$orders = Mage::getModel('sales/order')->getCollection()
    ->addFieldToFilter('status', 'pending')
    ->addAttributeToSelect('customer_email', 'mail@domain.com')
    ;
foreach ($orders as $order) {
    $email = $order->getCustomerEmail();
    echo $email . "\n";
}

答案 1 :(得分:0)

你应该可以使用观察者

来做到这一点

在config.xml中

<adminhtml>
    <events>
    <sales_order_grid_collection_load_before>
        <observers>
            <magepal>
                <type>singleton</type>
                <class>magepal/observer</class>
                <method>handleOrderCollectionLoadBefore</method>
            </magepal>
        </observers>
    </sales_order_grid_collection_load_before>

在你的观察者中

public function handleOrderCollectionLoadBefore($observer) 
{
     $collection = $observer->getOrderGridCollection();
     // $collection->addFieldToFilter('status', 'pending');
     // you may need to do additional check to make sure that the filter is only apply to specific section

答案 2 :(得分:0)

<sales_order_item_collection_load_before>
    <observers>
        <set_discount_new_customer>
            <type>singleton</type>
            <class>modulename_customattribute/observer</class>
            <method>filterCollection</method>
        </set_discount_new_customer>
    </observers>
</sales_order_item_collection_load_before>

在观察员文件中:

public function filterCollection($observer)
{
   $rawnew = $observer->getOrderItemCollection();
   $rawnew->addFieldToFilter('mycustom_attribute',6);
   return $rawnew;
}

感谢R.S给予提示。