【问题标题】:Magento sales order view filter collectionMagento 销售订单视图过滤器集合
【发布时间】:2013-11-14 20:24:39
【问题描述】:

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

【问题讨论】:

    标签: magento collections filter magento-1.7


    【解决方案1】:

    试试这些,它对我有用,

    <?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";
    }
    

    【讨论】:

      【解决方案2】:

      你应该可以使用观察者来做到这一点

      在 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
      

      【讨论】:

      • R.S 感谢您的提示。如果我想用观察者来计算下面黄色的总和……可以吗?
      【解决方案3】:
      <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 提供提示。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-04-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多