You are here

function commerce_discount_extra_order_product_qty in Commerce Discount Extra 7

Get the quantity of a given product in an order.

Parameters

EntityDrupalWrapper $order_wrapper: An order entity wrapper.

array $product_ids: Array of product IDs.

Return value

int The quantity of a set of products on an order.

File

./commerce_discount_extra.module, line 597
Provides necessary inline conditions and support for extra discounts.

Code

function commerce_discount_extra_order_product_qty(EntityDrupalWrapper $order_wrapper, $product_ids) {
  $qty = 0;
  foreach ($order_wrapper->commerce_line_items as $line_item_wrapper) {
    if ($line_item_wrapper
      ->value() && in_array($line_item_wrapper
      ->getBundle(), commerce_product_line_item_types()) && in_array($line_item_wrapper->commerce_product
      ->getIdentifier(), $product_ids)) {
      $qty += $line_item_wrapper->quantity
        ->value();
    }
  }
  return $qty;
}