function commerce_invoice_load_for_order in Commerce Invoice 7.2
Load the existing invoices for an order.
Parameters
object $order: The Commerce order object.
array $properties: Properties to filter invoices by. Each property should be an array of 3 elements: name, value, and operator.
int $limit: Limit the number of invoices to return, or 0 for no limit.
string|NULL $sort: A property to sort invoices by, or NULL for no sorting.
bool $descending: Leave FALSE to sort ascending. Set TRUE to sort in descending order.
Return value
Invoice[] The order's invoices or an empty array if none are found.
4 calls to commerce_invoice_load_for_order()
- CommerceInvoiceTestCase::testInvoiceCreationAndPayment in tests/
commerce_invoice.test - Tests creation and payment of an Invoice.
- CommerceInvoiceTestCase::testOrderUpdateWithPendingInvoices in tests/
commerce_invoice.test - Tests invoice behavior when orders were updated prior to payment.
- commerce_invoice_create_from_order in ./
commerce_invoice.module - Create a new invoice based on a Commerce order.
- commerce_invoice_load_current in ./
commerce_invoice.module - Load the current invoice for an order.
File
- ./
commerce_invoice.module, line 360 - The Commerce Invoice module.
Code
function commerce_invoice_load_for_order($order, array $properties = [], $limit = 0, $sort = NULL, $descending = FALSE) {
$query = new EntityFieldQuery();
$query
->entityCondition('entity_type', 'commerce_invoice');
$query
->propertyCondition('order_id', $order->order_id);
foreach ($properties as $property) {
list($column, $value, $operator) = $property;
$query
->propertyCondition($column, $value, $operator);
}
if ($sort !== NULL) {
$query
->propertyOrderBy($sort, $descending ? 'DESC' : 'ASC');
}
if (!empty($limit)) {
$query
->range(0, $limit);
}
$result = $query
->execute();
return !empty($result['commerce_invoice']) ? entity_load('commerce_invoice', array_keys($result['commerce_invoice'])) : [];
}