You are here

function mailchimp_ecommerce_get_campaign_id in Mailchimp E-Commerce 7

Same name and namespace in other branches
  1. 8 mailchimp_ecommerce.module \mailchimp_ecommerce_get_campaign_id()

Gets the campaign ID from the current user's session.

Return value

string The campaign ID.

2 calls to mailchimp_ecommerce_get_campaign_id()
mailchimp_ecommerce_add_cart in ./mailchimp_ecommerce.module
Adds a new cart to the current Mailchimp store.
mailchimp_ecommerce_add_order in ./mailchimp_ecommerce.module
Adds a new order to the current Mailchimp store.

File

./mailchimp_ecommerce.module, line 1203
Mailchimp eCommerce core functionality.

Code

function mailchimp_ecommerce_get_campaign_id() {
  $session_campaign = isset($_SESSION['mc_cid']) ? check_plain($_SESSION['mc_cid']) : '';
  $campaign_id = '';

  /* @var \Mailchimp\MailchimpCampaigns $mc_campaigns */
  $mc_campaigns = mailchimp_get_api_object('MailchimpCampaigns');

  // Check to see if this is a valid Mailchimp campaign.
  try {
    if (!empty($session_campaign)) {
      $campaign = $mc_campaigns
        ->getCampaign($session_campaign);
      $campaign_id = $campaign->id;
    }
  } catch (Exception $e) {
    if ($e
      ->getCode() == 404) {

      // Campaign doesn't exist; no need to log an error.
    }
    else {
      mailchimp_ecommerce_log_error_message('Unable to get campaign: ' . $e
        ->getMessage());
      mailchimp_ecommerce_show_error($e
        ->getMessage());
    }
  }
  return $campaign_id;
}