You are here

function _commerce_product_urls_get_product_ids_from_line_item in Commerce Product URLs 7

Retrieves the array of product IDs from the line item's context data array.

3 calls to _commerce_product_urls_get_product_ids_from_line_item()
commerce_product_urls_commerce_cart_add_to_cart_form_submit in ./commerce_product_urls.module
Extra form submit handler: replaces commerce_cart's form redirect to go back to the same product variation that was just added to the cart.
commerce_product_urls_form_alter in ./commerce_product_urls.module
Implements hook_form_alter().
_commerce_product_urls_build_query_string in ./commerce_product_urls.module
Re-builds URL query string for current product: adds 'id' parameter pointing to currently selected product, and strips all attribute field parameters (they are not needed anymore once 'id' param is added). Keeps all other…

File

./commerce_product_urls.module, line 332
Implements unique URLs for particular products on product displays. See d.o. issue #1082596: http://drupal.org/node/1082596

Code

function _commerce_product_urls_get_product_ids_from_line_item($line_item) {
  $product_ids = array();

  // If the product IDs setting tells us to use entity values...
  if ($line_item->data['context']['product_ids'] == 'entity' && is_array($line_item->data['context']['entity'])) {
    $entity_data = $line_item->data['context']['entity'];

    // Load the specified entity.
    $entity = entity_load_single($entity_data['entity_type'], $entity_data['entity_id']);

    // Extract the product IDs from the specified product reference field.
    if (!empty($entity->{$entity_data['product_reference_field_name']})) {
      $product_ids = entity_metadata_wrapper($entity_data['entity_type'], $entity)->{$entity_data['product_reference_field_name']}
        ->raw();
    }
  }
  elseif (is_array($line_item->data['context']['product_ids'])) {
    $product_ids = $line_item->data['context']['product_ids'];
  }
  return $product_ids;
}