public static function addSubscriptions(Order $objOrder, $arrTokens)
 {
     $strEmail = $objOrder->getBillingAddress()->email;
     $objAddress = $objOrder->getShippingAddress() ?: $objOrder->getBillingAddress();
     $arrItems = $objOrder->getItems();
     $objSession = \Session::getInstance();
     if (!($intModule = $objSession->get('isotopeCheckoutModuleIdSubscriptions'))) {
         return true;
     }
     $objSession->remove('isotopeCheckoutModuleIdSubscriptions');
     $objModule = \ModuleModel::findByPk($intModule);
     foreach ($arrItems as $item) {
         switch ($objModule->iso_direct_checkout_product_mode) {
             case 'product_type':
                 $objFieldpalette = FieldPaletteModel::findBy('iso_direct_checkout_product_type', Standard::findAvailableByIdOrAlias($item->product_id)->type);
                 break;
             default:
                 $objFieldpalette = FieldPaletteModel::findBy('iso_direct_checkout_product', $item->product_id);
                 break;
         }
         if ($objFieldpalette !== null && $objFieldpalette->iso_addSubscription) {
             if ($objFieldpalette->iso_subscriptionArchive && (!$objFieldpalette->iso_addSubscriptionCheckbox || \Input::post('subscribeToProduct_' . $item->product_id))) {
                 $objSubscription = Subscription::findOneBy(array('email=?', 'pid=?', 'activation!=?', 'disable=?'), array($strEmail, $objFieldpalette->iso_subscriptionArchive, '', 1));
                 if (!$objSubscription) {
                     $objSubscription = new Subscription();
                 }
                 if ($objFieldpalette->iso_addActivation) {
                     $strToken = md5(uniqid(mt_rand(), true));
                     $objSubscription->disable = true;
                     $objSubscription->activation = $strToken;
                     if (($objNotification = Notification::findByPk($objFieldpalette->iso_activationNotification)) !== null) {
                         if ($objFieldpalette->iso_activationJumpTo && ($objPageRedirect = \PageModel::findByPk($objFieldpalette->iso_activationJumpTo)) !== null) {
                             $arrTokens['link'] = \Environment::get('url') . '/' . \Controller::generateFrontendUrl($objPageRedirect->row()) . '?token=' . $strToken;
                         }
                         $objNotification->send($arrTokens, $GLOBALS['TL_LANGUAGE']);
                     }
                 }
                 $arrAddressFields = \Config::get('iso_addressFields');
                 if ($arrAddressFields === null) {
                     $arrAddressFields = serialize(array_keys(static::getIsotopeAddressFields()));
                 }
                 foreach (deserialize($arrAddressFields, true) as $strName) {
                     $objSubscription->{$strName} = $objAddress->{$strName};
                 }
                 $objSubscription->email = $strEmail;
                 $objSubscription->pid = $objFieldpalette->iso_subscriptionArchive;
                 $objSubscription->tstamp = $objSubscription->dateAdded = time();
                 $objSubscription->quantity = \Input::post('quantity');
                 $objSubscription->order_id = $objOrder->id;
                 $objSubscription->save();
             }
         }
     }
     return true;
 }
 protected function compile()
 {
     $this->Template->formId = $this->strFormId;
     $arrFieldDcas = array('email' => array('label' => &$GLOBALS['TL_LANG']['tl_module']['email'], 'inputType' => 'text', 'eval' => array('rgxp' => 'email', 'mandatory' => true)), 'submit' => array('inputType' => 'submit', 'label' => &$GLOBALS['TL_LANG']['MSC']['cancel']));
     $arrWidgets = array();
     foreach ($arrFieldDcas as $strName => $arrData) {
         if ($strClass = $GLOBALS['TL_FFL'][$arrData['inputType']]) {
             $arrWidgets[] = new $strClass(\Widget::getAttributesFromDca($arrData, $strName));
         }
     }
     if (\Input::post('FORM_SUBMIT') == $this->strFormId) {
         // validate
         foreach ($arrWidgets as $objWidget) {
             $objWidget->validate();
             if ($objWidget->hasErrors()) {
                 $this->blnDoNotSubmit = true;
             }
         }
         if (!$this->blnDoNotSubmit) {
             // cancel subscription
             $strEmail = \Input::post('email');
             $arrArchives = deserialize($this->iso_cancellationArchives, true);
             $blnNoSuccess = false;
             foreach ($arrArchives as $intArchive) {
                 if (($objSubscription = Subscription::findBy(array('email=?', 'pid=?'), array($strEmail, $intArchive))) === null) {
                     if (count($arrArchives) == 1) {
                         $this->Template->error = sprintf($GLOBALS['TL_LANG']['MSC']['iso_subscriptionDoesNotExist'], $strEmail, SubscriptionArchive::findByPk($intArchive)->title);
                         $blnNoSuccess = true;
                     }
                     break;
                 }
                 $objSubscription->delete();
             }
             if (!$blnNoSuccess) {
                 // success message
                 if (count($arrArchives) > 1) {
                     $this->Template->success = $GLOBALS['TL_LANG']['MSC']['iso_subscriptionsCancelledSuccessfully'];
                 } else {
                     $this->Template->success = sprintf($GLOBALS['TL_LANG']['MSC']['iso_subscriptionCancelledSuccessfully'], $strEmail, SubscriptionArchive::findByPk($arrArchives[0])->title);
                 }
                 // redirect
                 if ($this->jumpTo && ($objPageRedirect = \PageModel::findByPk($this->jumpTo)) !== null) {
                     \Controller::redirect(\Controller::generateFrontendUrl($objPageRedirect->row()));
                 }
             }
         }
     }
     // parse (validated) widgets
     $this->Template->fields = implode('', array_map(function ($objWidget) {
         return $objWidget->parse();
     }, $arrWidgets));
 }
 protected function compile()
 {
     if (!($strToken = \Input::get('token'))) {
         return;
     }
     if (($objSubscription = Subscription::findByActivation($strToken)) !== null) {
         if (!$objSubscription->disable) {
             $objSubscription->activation = '';
             $objSubscription->save();
             $this->Template->warning = $GLOBALS['TL_LANG']['MSC']['iso_subscriptionAlreadyActivated'];
         } else {
             $this->Template->success = $GLOBALS['TL_LANG']['MSC']['iso_subscriptionActivatedSuccessfully'];
             $objSubscription->activation = $objSubscription->disable = '';
             $objSubscription->save();
             // redirect
             if ($this->jumpTo && ($objPageRedirect = \PageModel::findByPk($this->jumpTo)) !== null) {
                 \Controller::redirect(\Controller::generateFrontendUrl($objPageRedirect->row()));
             }
         }
     } else {
         $this->Template->error = $GLOBALS['TL_LANG']['MSC']['iso_subscriptionTokenNotFound'];
     }
 }
/**
 * Backend modules
 */
HeimrichHannot\HastePlus\Arrays::insertInArrayByName($GLOBALS['BE_MOD']['isotope'], 'iso_rules', array('iso_subscriptions' => array('tables' => array('tl_iso_subscription_archive', 'tl_iso_subscription'), 'icon' => 'system/modules/isotope_subscriptions/assets/img/icon.png', 'export_xls' => \HeimrichHannot\Exporter\ModuleExporter::getBackendModule())));
/**
 * Frontend modules
 */
$GLOBALS['FE_MOD']['isotope_subscriptions'] = array('iso_activation' => 'Isotope\\Module\\Activation', 'iso_cancellation' => 'Isotope\\Module\\Cancellation');
/**
 * Hooks
 */
$GLOBALS['ISO_HOOKS']['preCheckout']['setCheckoutModuleIdSubscriptions'] = array('Isotope\\IsotopeSubscriptions', 'setCheckoutModuleIdSubscriptions');
$GLOBALS['ISO_HOOKS']['preCheckout']['checkForExistingSubscription'] = array('Isotope\\IsotopeSubscriptions', 'checkForExistingSubscription');
$GLOBALS['ISO_HOOKS']['postCheckout']['addSubscriptions'] = array('Isotope\\IsotopeSubscriptions', 'addSubscriptions');
/**
 * Notification center notification types
 */
$arrNotifications =& $GLOBALS['NOTIFICATION_CENTER']['NOTIFICATION_TYPE']['isotope'];
$arrNotifications['iso_subscription_activation'] = $arrNotifications['iso_order_status_change'];
$arrNotifications['iso_subscription_activation']['email_text'][] = 'link';
/**
 * Models
 */
$GLOBALS['TL_MODELS'][\Isotope\Model\Subscription::getTable()] = 'Isotope\\Model\\Subscription';
$GLOBALS['TL_MODELS'][\Isotope\Model\SubscriptionArchive::getTable()] = 'Isotope\\Model\\SubscriptionArchive';
/**
 * Add permissions
 */
$GLOBALS['TL_PERMISSIONS'][] = 'subscriptions';
$GLOBALS['TL_PERMISSIONS'][] = 'subscriptionp';
 public static function getOrders(\DataContainer $objDc)
 {
     $arrOptions = array();
     if (($objSubscription = \Isotope\Model\Subscription::findByPk($objDc->activeRecord->id)) !== null) {
         if (($objOrders = \Isotope\Model\ProductCollection\Order::findByType('order')) !== null) {
             while ($objOrders->next()) {
                 foreach ($objOrders->current()->getItems() as $objItem) {
                     // the order needs to contain at least one item of the product type defined in the archive
                     if (($objProduct = $objItem->getProduct()) !== null && $objProduct->type == $objSubscription->getRelated('pid')->productType) {
                         $arrOptions[$objOrders->id] = $GLOBALS['TL_LANG']['MSC']['order'] . ' ' . $objOrders->document_number;
                         break;
                     }
                 }
             }
         }
         // inverse asort
         arsort($arrOptions);
     }
     return $arrOptions;
 }