public function Subscribe() { if(!isset($_POST['check'])) { $GLOBALS['SubscriptionHeading'] = GetLang('Oops'); $GLOBALS['Class'] = "ErrorMessage"; $GLOBALS['SubscriptionMessage'] = GetLang('NewsletterSpammerVerification'); } else if(isset($_POST['nl_first_name']) && isset($_POST['nl_email'])) { $first_name = $_POST['nl_first_name']; $email = $_POST['nl_email']; if (!is_email_address($email)) { $GLOBALS['SubscriptionHeading'] = GetLang('NewsletterSubscription'); $GLOBALS['Class'] = "ErrorMessage"; $GLOBALS['SubscriptionMessage'] = GetLang('NewsletterEnterValidEmail'); } else { $subscription = new Interspire_EmailIntegration_Subscription_Newsletter($email, $first_name); $results = $subscription->routeSubscription(); $success = false; $existed = false; foreach ($results as /** @var Interspire_EmailIntegration_SubscriberActionResult */$result) { // message sent to visitor is 'ok' if even one subscription worked; other failures will be logged internally & emailed to store owner // this is a little counter-intuitive when multiple modules are enabled but it's the best compromise I think short of sending info about every module back to the visitor, who shouldn't be concered with such detail if ($result->pending) { $success = true; } else { if ($result->success) { $success = true; } if ($result->existed) { $existed = true; } } } if ($success) { if ($existed) { // most APIs will simply update existing details, rather than error - but this mimmicks the existing behaviour of ISC if the API can let us know the subscriber existed $GLOBALS['SubscriptionHeading'] = GetLang('Oops'); $GLOBALS['Class'] = "ErrorMessage"; $GLOBALS['SubscriptionMessage'] = sprintf(GetLang('NewsletterAlreadySubscribed'), $email); // legacy sprintf } else { $GLOBALS['SubscriptionHeading'] = GetLang('NewsletterThanksForSubscribing'); $GLOBALS['Class'] = ""; $GLOBALS['SubscriptionMessage'] = GetLang('NewsletterSubscribedSuccessfully') . sprintf(" <a href='%s'>%s.</a>", $GLOBALS['ShopPath'], GetLang('Continue')); } } else { $GLOBALS['SubscriptionHeading'] = GetLang('Oops'); $GLOBALS['Class'] = "ErrorMessage"; $GLOBALS['SubscriptionMessage'] = GetLang('NewsletterSubscribeError'); } } } $GLOBALS['ISC_CLASS_TEMPLATE']->SetPageTitle(sprintf("%s - %s", GetConfig('StoreName'), GetLang('NewsletterSubscription'))); $GLOBALS['ISC_CLASS_TEMPLATE']->SetTemplate("newsletter_subscribe"); $GLOBALS['ISC_CLASS_TEMPLATE']->ParseTemplate(); }
/** * Do we need to subscribe the customer to either of our mailing lists? * If they ticked yes then the appropriate cookies were set before they * chose their shipping provider and entered their payment details */ function SubscribeCustomerToLists($pendingOrderToken) { $orders = LoadPendingOrdersByToken($pendingOrderToken); $order = current($orders['orders']); $email = $order['ordbillemail']; $firstName = $order['ordbillfirstname']; foreach($orders['orders'] as $order) { $extraInfo =array(); if(isset($order['extrainfo']) && $order['extrainfo'] != '') { $extraInfo = @unserialize($order['extrainfo']); } $format = Interspire_EmailIntegration_Subscription::FORMAT_PREF_NONE; if (isset($extraInfo['mail_format_preference'])) { $format = (int)$extraInfo['mail_format_preference']; } // Should we add them to our newsletter mailing list? if(isset($extraInfo['join_mailing_list']) && $extraInfo['join_mailing_list'] == 1) { $subscription = new Interspire_EmailIntegration_Subscription_Newsletter($email, $firstName); $subscription->setDoubleOptIn(GetConfig('EmailIntegrationOrderDoubleOptin')); // override newsletter double-opt-in preference with order double-opt-in preference when subscribing someone to newsletter list through the checkout $subscription->setSendWelcome(GetConfig('EmailIntegrationOrderSendWelcome')); // as above $subscription->setEmailFormatPreference($format); $subscription->routeSubscription(); } // Should we add them to our special offers & discounts mailing list? if(isset($extraInfo['join_order_list']) && $extraInfo['join_order_list']) { $subscription = new Interspire_EmailIntegration_Subscription_Order($order['orderid']); $subscription->setEmailFormatPreference($format); $subscription->routeSubscription(); } } }
/** * Subscribe a customer to newsletter if they have opted in to them * * @param string $email The customers email * @param string $first_name The customers first name * * @return void */ public function SubscribeCustomerToNewsletter($email, $first_name) { // If the customer didn't opt in, stop immediately if ($this->response->data['new-order-notification']['buyer-marketing-preferences']['email-allowed']['VALUE'] != 'true') { return; } $subscription = new Interspire_EmailIntegration_Subscription_Newsletter($email, $first_name); $subscription->routeSubscription(); }