业务对象: Difference between revisions

Jump to navigation Jump to search
No edit summary
Tag: 2017 source edit
Tag: 2017 source edit
 
Line 46: Line 46:
<source lang="php">
<source lang="php">
// get invoices from an already loaded order:
// get invoices from an already loaded order:
// 从已加载的订单中获取发票:
$result = $order->fetchObjectLinked($order->id, 'commande', null, 'facture');
$result = $order->fetchObjectLinked($order->id, 'commande', null, 'facture');
if ($result <= 0) {
if ($result <= 0) {
Line 51: Line 52:
}
}
// important notice : the newly populated arrays are associative. Keys are llx_element_element row ids.
// important notice : the newly populated arrays are associative. Keys are llx_element_element row ids.
// 重要提示:新填充的数组是关联的。主键是llx_element_element的row ids。


// now if we expect only one linked invoice:
// now if we expect only one linked invoice:
// 现在,如果我们预计只有一个相关联的发票:


// WRONG way to get it ($invoice_id will be NULL):  
// WRONG way to get it ($invoice_id will be NULL):  
// 错误的获取方式($invoice_id将为NULL):
$invoice_id = $order->linkedObjectsIds['facture'][0]
$invoice_id = $order->linkedObjectsIds['facture'][0]


// CORRECT way ($invoice_id will hold the ID):
// CORRECT way ($invoice_id will hold the ID):
// 正确的方式($invoice_id将保存id):
$invoice_id = array_values($order->linkedObjectsIds['facture'])[0]
$invoice_id = array_values($order->linkedObjectsIds['facture'])[0]


// Better (if there are more than one linked invoices) :
// Better (if there are more than one linked invoices) :
// 更好的方式(如果有多个相关联的发票):
foreach ($order->linkedObjectsIds['facture'] as $element_element_id => $facture_id) {
foreach ($order->linkedObjectsIds['facture'] as $element_element_id => $facture_id) {
     // process it
     // process it(处理它)
}
}
</source>
</source>
714

edits

Navigation menu