You are here

public function MailchimpEcommerceHelper::getCampaignId in Mailchimp E-Commerce 8

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

Return value

string The campaign ID.

File

src/MailchimpEcommerceHelper.php, line 97

Class

MailchimpEcommerceHelper
Class MailchimpEcommerceHelper.

Namespace

Drupal\mailchimp_ecommerce

Code

public function getCampaignId() {
  $session_campaign = $this->request
    ->getSession()
    ->get('mc_cid', '');
  $campaign_id = '';

  // Check to see if this is a valid Mailchimp campaign.
  try {
    if (!empty($session_campaign)) {
      $campaign = $this->mcCampaigns
        ->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()); */
      $this->messenger
        ->addError($e
        ->getMessage());
    }
  }
  return $campaign_id;
}