public function CommerceGoogleTagManagerActionPurchase::execute in Commerce Google Tag Manager 7.2
Executes the action.
Parameters
array $order The order being purchased:
File
- includes/
rules/ CommerceGoogleTagManagerActionPurchase.php, line 38 - This file contains the "Send the Purchase event to GTM" action definition.
Class
- CommerceGoogleTagManagerActionPurchase
- @file This file contains the "Send the Purchase event to GTM" action definition.
Code
public function execute($order) {
$order = CommerceGoogleTagManagerHelper::getWrappedOrder($order);
$productsData = CommerceGoogleTagManagerHelper::getLineItemsData($order, $this
->getCommerceEventName());
$orderData = CommerceGoogleTagManagerHelper::getOrderData($order, $this
->getCommerceEventName());
$currencyCode = $order->commerce_order_total->currency_code
->value();
$data = array(
'currencyCode' => $currencyCode,
'purchase' => array(
'actionField' => $orderData,
'products' => $productsData,
),
);
$this
->pushCommerceData($data);
}