2011-12-08 54 views
1

基本上,我希望链接sales/order和sales/order_invoice表,以便在通过发票循环时从sales/order获取order_source feild;magento加入订单和发票

这是我attmpt:

$collection = Mage::getModel('sales/order_invoice')->getCollection(); 
$collection = $collection->addAttributeToFilter('order_id', array('from' =>$from)); 
$collection->joinAttribute('order_source', 'order/order_source', 'order_id', null, 'left'); 

foreach($collection as $invoice){ 

$orderSource = $invoice->getOrderSource(); 

//do other stuff 

} 

我是新来的Magento

+0

order_source是我添加的客户属性 – rosh3000

+0

'joinAttribute'对我来说看起来不错。你能解释什么是错的吗? – clockworkgeek

+0

@clockworkgeek我无法访问该变量,即它始终是'null',当我尝试排序时发现问题,因为它给了我一个错误消息:'致命错误:... Main_table.order_source未找到... (你说的没错,joinAttribute') – rosh3000

回答

3

(技术上不是一个正确的答案做的只是另一种方式)

我,而不是使用下面的join什么我用过:

$collection->join(array('order' => 'order'), 'order.entity_id=order_id', array('order_source'=>'order_source'), null , 'left'); 

$collection->addAttributeToSort('order_source', 'DESC'); 

foreach($collection as $invoice){ 

$orderSource = $invoice->getOrderSource(); 

//do other stuff 

} 

希望它可以帮助别人

PS获得所有属性从订单,你可以使用下列内容:(但不推荐,因为*优化):

$collection->join(array('order' => 'order'), 'order.entity_id=order_id', array('order'=>'*'), null , 'left'); 

,并获得具体领域使用:

$collection->join(array('order' => 'order'), 'order.entity_id=order_id', array('some_feild'=>'some_feild', 'some_other_feild' => 'some_alies_for_other_feild'), null , 'left'); 

和然后使用$collection->getSomeAliesForOtherFeild()$collection->getSomeFeild()

相关问题