static function CommerceGoogleTagManagerHelper::getLineItemData in Commerce Google Tag Manager 7.2
Gets an array-based representation of the given Line Item.
Parameters
EntityMetadataWrapper $item The order Line-Item object.:
Return value
array
3 calls to CommerceGoogleTagManagerHelper::getLineItemData()
- CommerceGoogleTagManagerActionAddToCart::execute in includes/
rules/ CommerceGoogleTagManagerActionAddToCart.php - Executes the action.
- CommerceGoogleTagManagerActionRemoveFromCart::execute in includes/
rules/ CommerceGoogleTagManagerActionRemoveFromCart.php - Executes the action.
- CommerceGoogleTagManagerHelper::getLineItemsData in includes/
CommerceGoogleTagManagerHelper.php
File
- includes/
CommerceGoogleTagManagerHelper.php, line 94 - This file contains the helper class CommerceGoogleTagManagerHelper.
Class
- CommerceGoogleTagManagerHelper
- @file This file contains the helper class CommerceGoogleTagManagerHelper.
Code
static function getLineItemData(\EntityMetadataWrapper $item, $event = NULL) {
$properties = $item
->getPropertyInfo();
$product_data = NULL;
if (isset($properties['commerce_product'])) {
$product_id = $item->commerce_product
->getIdentifier();
if (!empty($product_id)) {
// Build the item arguments.
$sku = $item->commerce_product->sku
->value();
$name = $item->commerce_product->title
->value();
$category = '';
$variant = commerce_product_type_get_name($item->commerce_product
->getBundle());
$price = commerce_currency_amount_to_decimal($item->commerce_unit_price->amount
->value(), $item->commerce_unit_price->currency_code
->value());
$quantity = (int) $item->quantity
->value();
// Building the ProductData array
$product_data = array(
'id' => $sku,
'name' => $name,
'category' => $category,
'variant' => $variant,
'price' => $price,
'quantity' => $quantity,
);
// Allow other modules to alter this product data.
$context = array(
'line-item' => $item,
'event' => $event,
);
drupal_alter('commerce_google_tag_manager_line_item_data', $product_data, $context);
}
}
return $product_data;
}