You are here

public function CommerceGoogleTagManagerActionRemoveFromCart::execute in Commerce Google Tag Manager 7.2

Executes the action.

Parameters

array $item The Line Item of the order:

string $count Number of items added to the order:

File

includes/rules/CommerceGoogleTagManagerActionRemoveFromCart.php, line 44
This file contains the "Send Remove From Cart event to GTM" action definition.

Class

CommerceGoogleTagManagerActionRemoveFromCart
@file This file contains the "Send Remove From Cart event to GTM" action definition.

Code

public function execute($item, $count) {
  $item = CommerceGoogleTagManagerHelper::getWrappedLineItem($item);
  $productData = CommerceGoogleTagManagerHelper::getLineItemData($item, $this
    ->getCommerceEventName());
  $order = $item->order;
  $currencyCode = $order->commerce_order_total->currency_code
    ->value();

  // Override the product quantity, if set:
  if ($count) {
    $productData['quantity'] = $count;
  }
  $data = array(
    'currencyCode' => $currencyCode,
    'remove' => array(
      'products' => array(
        $productData,
      ),
    ),
  );
  $this
    ->pushCommerceData($data);
}