function commerce_coupon_order_discount_ids in Commerce Coupon 7.2
Load all discounts connected to an order.
This includes line item level discounts traced through line item unit price components.
Parameters
object $order: An order entity.
Return value
array A list of discount ids found on the order.
2 calls to commerce_coupon_order_discount_ids()
- commerce_coupon_order_coupon_code_discounts in ./
commerce_coupon.module - Load common discounts that are present in a coupon (by code) and an order.
- commerce_coupon_order_has_discount in ./
commerce_coupon.module - Determine whether an order has a particular discount.
File
- ./
commerce_coupon.module, line 1238 - Provides coupon functionality for Drupal Commerce.
Code
function commerce_coupon_order_discount_ids($order) {
$order_wrapper = entity_metadata_wrapper('commerce_order', $order);
$order_discount_ids = array();
foreach ($order_wrapper->commerce_line_items as $line_item_wrapper) {
if ($line_item_wrapper
->value()) {
$data = $line_item_wrapper->commerce_unit_price->data
->value();
foreach ($data['components'] as $key => $component) {
if (!empty($component['price']['data']['discount_name'])) {
$order_discount_name = $component['price']['data']['discount_name'];
$order_discount_wrapper = entity_metadata_wrapper('commerce_discount', $order_discount_name);
// Make a list of discounts present via the order's line item price
// components.
$order_discount_ids[] = $order_discount_wrapper->discount_id
->value();
}
}
}
}
// Add the set of discounts directly referenced on the order.
foreach ($order_wrapper->commerce_discounts
->raw() as $discount_id) {
$order_discount_ids[] = $discount_id;
}
$order_discount_ids = array_unique($order_discount_ids);
return $order_discount_ids;
}