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)); }
public static function checkForExistingSubscription(Order $objOrder, $objModule) { $strEmail = $objOrder->getBillingAddress()->email; $arrItems = $objOrder->getItems(); 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->iso_addSubscriptionCheckbox || \Input::post('subscribeToProduct_' . $item->product_id)) && $objFieldpalette->iso_addSubscription && $objFieldpalette->iso_subscriptionArchive && ($objSubscriptionArchive = SubscriptionArchive::findByPk($objFieldpalette->iso_subscriptionArchive)) !== null) { if (Subscription::findBy(array('email=?', 'pid=?', 'disable!=?'), array($strEmail, $objSubscriptionArchive->id, 1)) !== null) { $_SESSION['ISO_ERROR'][] = sprintf($GLOBALS['TL_LANG']['MSC']['iso_subscriptionAlreadyExists'], $strEmail, $item->name); return false; } } } return true; }