You are here

mailchimp_ecommerce.module in Mailchimp E-Commerce 8

Same filename and directory in other branches
  1. 7 mailchimp_ecommerce.module

Mailchimp eCommerce core functionality.

File

mailchimp_ecommerce.module
View source
<?php

/**
 * @file
 * Mailchimp eCommerce core functionality.
 */

/**
 * Implements hook_page_attachments().
 */
function mailchimp_ecommerce_page_attachments(array &$attachments) {
  $campaign_id = filter_input(INPUT_GET, 'mc_cid', FILTER_SANITIZE_STRING);
  if (!empty($campaign_id)) {
    $_SESSION['mc_cid'] = $campaign_id;
    $_SESSION['mc_landing_site'] = (isset($_SERVER['HTTPS']) ? "https" : "http") . "://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}";
  }
}

/**
 * Generates a unique ID used to identify a store integration to Mailchimp.
 *
 * @return string
 *   The unique store ID.
 */
function mailchimp_ecommerce_generate_store_id() {
  return uniqid();
}

/**
 * Gets the store ID of the Mailchimp eCommerce integration.
 *
 * @return string
 *   The store ID.
 */
function mailchimp_ecommerce_get_store_id() {
  return \Drupal::service('mailchimp_ecommerce.helper')
    ->getStoreId();
}

/**
 * Gets the campaign ID from the current user's session.
 *
 * @return string
 *   The campaign ID.
 */
function mailchimp_ecommerce_get_campaign_id() {
  return \Drupal::service('mailchimp_ecommerce.helper')
    ->getCampaignId();
}

/**
 * Determines if a Mailchimp eCommerce integration is enabled.
 *
 * @return bool
 *   TRUE if an integration is enabled.
 */
function mailchimp_ecommerce_is_enabled() {
  return \Drupal::service('mailchimp_ecommerce.helper')
    ->isEnabled();
}

/**
 * Determines if customer data is valid.
 *
 * @param array $customer
 *   Array of customer data.
 *
 * @return bool
 *   TRUE if customer data is valid.
 */
function mailchimp_ecommerce_validate_customer(array $customer) {
  return \Drupal::service('mailchimp_ecommerce.helper')
    ->validateCustomer($customer);
}

/**
 * Get the List/Audience ID being used.
 *
 * @return string
 *   The List/Audience ID.
 */
function mailchimp_ecommerce_get_list_id() {
  return \Drupal::config('mailchimp_ecommerce.settings')
    ->get('mailchimp_ecommerce_list_id');
}

/**
 * Returns currency codes from the xml file.
 *
 * This is used if Drupal Commerce is not available.
 *
 * @return array
 *   Array of currency codes.
 */
function mailchimp_ecommerce_get_currency_codes() {
  return \Drupal::service('mailchimp_ecommerce.helper')
    ->getCurrencyCodes();
}

/**
 * Logs an error message using watchdog, if enabled.
 *
 * @todo This function cannot run, the function "watchdog" is never defined.
 *
 * @param string $message
 *   The error message to log.
 */
function mailchimp_ecommerce_log_error_message($message) {
  if (function_exists('watchdog')) {
    \Drupal::logger('mailchimp_ecommerce')
      ->error('%message', array(
      '%message' => $message,
    ));
  }
}

Functions

Namesort descending Description
mailchimp_ecommerce_generate_store_id Generates a unique ID used to identify a store integration to Mailchimp.
mailchimp_ecommerce_get_campaign_id Gets the campaign ID from the current user's session.
mailchimp_ecommerce_get_currency_codes Returns currency codes from the xml file.
mailchimp_ecommerce_get_list_id Get the List/Audience ID being used.
mailchimp_ecommerce_get_store_id Gets the store ID of the Mailchimp eCommerce integration.
mailchimp_ecommerce_is_enabled Determines if a Mailchimp eCommerce integration is enabled.
mailchimp_ecommerce_log_error_message Logs an error message using watchdog, if enabled.
mailchimp_ecommerce_page_attachments Implements hook_page_attachments().
mailchimp_ecommerce_validate_customer Determines if customer data is valid.