本文介绍了Magento addFieldToFilter:如何使用forigen键从表中getCollection()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新的magento,试图解决它,但没有成功。
我的问题是,我必须在基础上应用addFieldToFilter过滤器,如果store_id,我必须从表中收集特定商店/商店的所有订单

  sales_flat_order 

但是store_id在表格

  sales_flat_order_address 

sales_flat_order_order_address表的主键entity_id在sales_flat_order_address中作为外键用作parent_id,我写了一个这样的查询,

  $ ordercollection = Mage :: getModel('sales / order') - > getCollection(); 
$ ordercollection-> getSelect() - > joinLeft(array('sfoa'=>'sales_flat_order_address'),'main_table.entity_id = sfoa.store_id',array('store_id'=>'sfoa .store_id'));
$ ordercollection-> addFieldToFilter('store_id',array('neq'=>'555'));

我不明白,而且不能用

  

$ ordercollection-> addFieldToFilter('store_id',array('neq'=>'4'));
$ ordercollection-> getSelect() - > joinLeft('sales_flat_order_address',main_table.entity_id = sales_flat_order_address.parent_id,array('country_id'));


I am new to magento, tried to solved it, but not succeeded.My Problem is that,I have to apply "addFieldToFilter" filter on base if "store_id" , I have to drop all orders for a specific store/stores from collection on table

sales_flat_order

but store_id is in table

sales_flat_order_address

"sales_flat_order_address" table's primary key "entity_id" is used as foreign key in "sales_flat_order_address" as "parent_id", I have written a query some thing like this,

  $ordercollection = Mage::getModel('sales/order')->getCollection();
    $ordercollection->getSelect()->joinLeft(array('sfoa' => 'sales_flat_order_address'),'main_table.entity_id = sfoa.store_id',array('store_id'=>'sfoa.store_id'));
    $ordercollection->addFieldToFilter('store_id',array('neq'=>'555'));

I don't understand it, And it's not working

解决方案

You can use this to filter your orders by store id

    $ordercollection = Mage::getModel('sales/order')->getCollection();
    $ordercollection->addFieldToFilter('store_id',array('neq'=>'4'));
    $ordercollection->getSelect()->joinLeft('sales_flat_order_address', "main_table.entity_id = sales_flat_order_address.parent_id",array('country_id'));

这篇关于Magento addFieldToFilter:如何使用forigen键从表中getCollection()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 13:03