magento加入订单和发票

时间:2011-12-08 11:49:52

标签: php magento join

基本上我想链接销售/订单和sales / order_invoice表,以便在通过发票循环时从销售/订单获取order_source feild;

这是我的鄙视:

$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的新手

1 个答案:

答案 0 :(得分: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

}

希望它可以帮助某人

p.s从订单中获取所有属性,您可以使用以下内容:(但由于优化*而不推荐):

$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()