You are here

function commerce_product_bundle_get_sub_line_items in Commerce Product Bundle 7

Same name and namespace in other branches
  1. 7.2 commerce_product_bundle.module \commerce_product_bundle_get_sub_line_items()

This function returns all sub line items which relates to the given line item.

Parameters

obj $parent_line_item: The parent line item to get the children of.

Return value

array List of children line items.

5 calls to commerce_product_bundle_get_sub_line_items()
commerce_product_bundle_add_to_cart_form in ./commerce_product_bundle.module
Builds the add to cart form, for product bundles.
commerce_product_bundle_attribute_field in ./commerce_product_bundle.module
Implements hook_attribute_field().
commerce_product_bundle_calculate_price in ./commerce_product_bundle.rules.inc
Calculates the price for a bundle line item.
commerce_product_bundle_load_sub_items in ./commerce_product_bundle.rules.inc
Loads sub line items of a bundle product line item.
commerce_product_bundle_update_cart in ./commerce_product_bundle.module
Updates the specified product in a customer's shopping cart.

File

./commerce_product_bundle.module, line 1380
Allows the bundling of products in Drupal Commerce.

Code

function commerce_product_bundle_get_sub_line_items(&$parent_line_item, $reset = FALSE) {
  if (!is_object($parent_line_item)) {
    return array();
  }
  if ($reset || !isset($parent_line_item->data['sub_line_items']) || count($parent_line_item->data['sub_line_items']) <= 0) {
    $query = new EntityFieldQuery();
    $entities = $query
      ->entityCondition('entity_type', 'commerce_line_item')
      ->entityCondition('bundle', 'bundle')
      ->fieldCondition('commerce_parent_line_item', 'line_item_id', $parent_line_item->line_item_id, '=')
      ->execute();
    if (!isset($entities['commerce_line_item'])) {
      return array();
    }
    foreach ($entities['commerce_line_item'] as $item) {
      $item = commerce_line_item_load($item->line_item_id);
      $line_item_wrapper = entity_metadata_wrapper('commerce_line_item', $item);
      if (is_object($line_item_wrapper->commerce_parent_line_item
        ->value()) && $line_item_wrapper->commerce_parent_line_item->line_item_id
        ->value() == $parent_line_item->line_item_id) {
        $items[$item->line_item_id] = $item;
      }
    }
    $parent_line_item->data['sub_line_items'] = $items;
  }
  return $parent_line_item->data['sub_line_items'];
}