You are here

class CommerceGoogleTagManagerActionPurchase in Commerce Google Tag Manager 7.2

@file This file contains the "Send the Purchase event to GTM" action definition.

Hierarchy

Expanded class hierarchy of CommerceGoogleTagManagerActionPurchase

File

includes/rules/CommerceGoogleTagManagerActionPurchase.php, line 7
This file contains the "Send the Purchase event to GTM" action definition.

View source
class CommerceGoogleTagManagerActionPurchase extends CommerceGoogleTagManagerBaseAction {

  /**
   * Defines the action.
   *
   * @return array
   */
  public static function getInfo() {
    return self::getDefaultsInfo() + array(
      'label' => t('Send "Purchase" event to google analytics via GTM'),
      'parameter' => array(
        'order' => array(
          'type' => 'commerce_order',
          'label' => t('Order in checkout'),
        ),
      ),
    );
  }

  /**
   * @return string
   */
  public function getCommerceEventName() {
    return 'purchase';
  }

  /**
   * Executes the action.
   *
   * @param array $order The order being purchased
   */
  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);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CommerceGoogleTagManagerActionPurchase::execute public function Executes the action.
CommerceGoogleTagManagerActionPurchase::getCommerceEventName public function Overrides CommerceGoogleTagManagerBaseAction::getCommerceEventName
CommerceGoogleTagManagerActionPurchase::getInfo public static function Defines the action.
CommerceGoogleTagManagerBaseAction::getDefaultsInfo protected static function Get the default Rule's info.
CommerceGoogleTagManagerBaseAction::pushCommerceData protected function Builds and pushes the current commerce data.
RulesPluginHandlerBase::$element protected property
RulesPluginHandlerBase::access public function Implements RulesPluginImplInterface::access(). Overrides RulesPluginHandlerInterface::access
RulesPluginHandlerBase::assertions public function Returns an array of info assertions for the specified parameters. Overrides RulesPluginHandlerInterface::assertions 1
RulesPluginHandlerBase::dependencies public function Returns an array of required modules. Overrides RulesPluginHandlerInterface::dependencies
RulesPluginHandlerBase::form_alter public function Alters the generated configuration form of the element. Overrides RulesPluginHandlerInterface::form_alter
RulesPluginHandlerBase::info_alter public function Allows altering of the element's action/condition info. Overrides RulesPluginHandlerInterface::info_alter
RulesPluginHandlerBase::process public function Processes settings independent from a form submission. Overrides RulesPluginHandlerInterface::process
RulesPluginHandlerBase::validate public function Validates $settings independent from a form submission. Overrides RulesPluginHandlerInterface::validate
RulesPluginHandlerBase::__construct public function Overridden to provide $this->element to make the code more meaningful.