Magento 1.5 Magento observer(销售\订单\网格\收集\加载之前),按产品属性筛选收集
因此,目前我正在使用Magento 1.5 Magento observer(销售\订单\网格\收集\加载之前),按产品属性筛选收集,magento-1.5,magento,Magento 1.5,Magento,因此,目前我正在使用sales\u order\u grid\u collection\u load\u,在observer事件之前,我可以通过$collection=$observer->getEvent()->getOrderGridCollection()获取正在使用的集合,我只是想知道,是否可以从订单属性按产品筛选此集合。 我的意思是,订单网格集合具有与该订单相关的子产品,我只需要在至少一个产品符合特定条件时显示订单(在我的例子中,我为产品提供了一个admin_id属性,该属性设置为添加
sales\u order\u grid\u collection\u load\u,在observer事件之前,我可以通过$collection=$observer->getEvent()->getOrderGridCollection()获取正在使用的集合代码>,我只是想知道,是否可以从订单属性按产品筛选此集合。
我的意思是,订单网格集合具有与该订单相关的子产品,我只需要在至少一个产品符合特定条件时显示订单(在我的例子中,我为产品提供了一个admin_id属性,该属性设置为添加产品的管理员)
谢谢 我不确定您是否可以直接从订单\网格\集合
(我不这么认为)访问产品,但您可以将此集合与销售\平面\订单\项目
结合,然后根据需要进行筛选。
HTH我做了一件非常类似的事情,做了以下几件事:
覆盖销售订单网格块。要做到这一点,您需要设置您自己的扩展(看起来您可能已经在这样做了,但为了以防万一,在
您可能不需要连接到sales_flat_order表……您只需执行上面所示的_prepareCollection函数第二部分中的过滤即可。在我的例子中,我在网格中显示客户组id和客户电子邮件,以便用户可以在需要时手动筛选。我如何才能将id列表添加到sales\u flat\u order\u项目中,并且在清除缓存时不会清空这些id?customer\u group\u id不在sales\u flat\u order表中吗?在我的情况下,产品不在销售订单中,这就是为什么它让我很难。如果我有一个订单,有多个关联的产品,所有产品都有不同的“admin_id”属性,我只需要显示至少有一个产品的订单,其中“admin_id”是登录管理员的产品。如果您查看上面的代码,您是绝对正确的,我对sales_flat_order表进行左联接,以检索它$collection->getSelect()->联接('sales_flat_order','main_table.entity_id=sales_flat_order.entity_id',数组('customer_group_id'=>'customer_group_id','customer_email=>'customer_email'),null,'left')代码>。你可以做同样的事情很好,我必须像你说的那样重写类,但是我不能像你说的那样过滤项目,最后不得不循环遍历所有项目,如果它们不应该在那里,就删除任何项目。无论如何,谢谢。@CCBlackburn如何在obsever中添加类别过滤器,我尝试了这个->$category\u products=Mage::getModel('catalog/category')->addAttributeToFilter('category\u id',array('in'=>array('680','894','895'))->setWebsiteId(2);
<config>
<modules>
<Company_Module>
<version>0.1.0</version>
</Company_Module>
</modules>
<global>
<blocks>
<company_module>
<class>Company_Module_Block</class>
</company_module>
<adminhtml>
<rewrite>
<sales_order_grid>Company_Module_Block_Sales_Order_Grid</sales_order_grid>
</rewrite>
</adminhtml>
</blocks>
</global>
</config>
protected function _prepareCollection() {
$collection = Mage::getResourceModel($this->_getCollectionClass());
// left join onto the sales_flat_order table, retrieving the customer_group_id and customer_email columns -< this can be expanded
$collection->getSelect()->join('sales_flat_order', 'main_table.entity_id=sales_flat_order.entity_id', array('customer_group_id'=>'customer_group_id', 'customer_email'=>'customer_email'), null, 'left');
// grab the current user and get their associated customer groups (additional coding required to associate the customer groups to an admin user
$user = Mage::getSingleton('admin/session')->getUser();
$roleId = implode('', $user->getRoles());
$customerGroupIds = Mage::getModel('admin/roles')->load($roleId)->getCustomerGroupIds();
$orders = Mage::getResourceModel('sales/order_collection');
// if the admin user has associated customer group ids then find the orders associated with those
// this would be where you would do your filtering of the products
if (count($customerGroupIds)) {
$orders->addAttributeToFilter('customer_group_id', array('in' => $customerGroupIds));
}
$orderIds = $orders->getAllIds();
$collection->addAttributeToFilter('entity_id', array('in' => $orderIds));
$this->setCollection($collection);
return parent::_prepareCollection();
}