/** * Generate module */ protected function compile() { $arrBuffer = array(); // Default template settings. Must be set at beginning so they can be overwritten later (eg. trough callback) $this->Template->action = ampersand(\Environment::get('request'), ENCODE_AMPERSANDS); $this->Template->formId = $this->strFormId; $this->Template->formSubmit = $this->strFormId; $this->Template->enctype = 'application/x-www-form-urlencoded'; $this->Template->previousLabel = specialchars($GLOBALS['TL_LANG']['MSC']['previousStep']); $this->Template->nextLabel = specialchars($GLOBALS['TL_LANG']['MSC']['nextStep']); $this->Template->nextClass = 'next'; $this->Template->showPrevious = true; $this->Template->showNext = true; $this->Template->showForm = true; $this->Template->steps = array(); // These steps are handled internally by the checkout module and are not in the config array switch ($this->strCurrentStep) { // Complete order after successful payment // At this stage, we do no longer use the client's cart but the order through UID in URL case 'complete': if (($objOrder = Order::findOneByUniqid((string) \Input::get('uid'))) === null) { static::redirectToStep('failed'); } $strBuffer = $objOrder->hasPayment() ? $objOrder->getPaymentMethod()->processPayment($objOrder, $this) : true; // true means the payment is successful and order should be completed if ($strBuffer === true) { // If checkout is successful, complete order and redirect to confirmation page if ($objOrder->checkout() && $objOrder->complete()) { \Controller::redirect(\Haste\Util\Url::addQueryString('uid=' . $objOrder->uniqid, $this->orderCompleteJumpTo)); } // Checkout failed, show error message static::redirectToStep('failed'); } elseif ($strBuffer === false) { static::redirectToStep('failed'); } else { $this->Template->showNext = false; $this->Template->showPrevious = false; $arrBuffer = array(array('html' => $strBuffer, 'class' => $this->strCurrentStep)); } break; // Process order and initiate payment method if necessary // Process order and initiate payment method if necessary case 'process': $arrSteps = $this->getSteps(); // Make sure all steps have passed successfully foreach ($arrSteps as $step => $arrModules) { foreach ($arrModules as $objModule) { $objModule->generate(); if ($objModule->hasError()) { static::redirectToStep($step); } } } $objOrder = Order::createFromCollection(Isotope::getCart()); $objOrder->checkout_info = $this->getCheckoutInfo($arrSteps); $objOrder->nc_notification = $this->nc_notification; $objOrder->iso_addToAddressbook = $this->iso_addToAddressbook; $objOrder->email_data = $this->getNotificationTokensFromSteps($arrSteps, $objOrder); $objOrder->save(); $strBuffer = Isotope::getCart()->hasPayment() ? Isotope::getCart()->getPaymentMethod()->checkoutForm($objOrder, $this) : false; if ($strBuffer === false) { static::redirectToStep('complete', $objOrder); } $this->Template->showForm = false; $this->doNotSubmit = true; $arrBuffer = array(array('html' => $strBuffer, 'class' => $this->strCurrentStep)); break; // Checkout/payment has failed, show the review page again with an error message // Checkout/payment has failed, show the review page again with an error message case 'failed': $this->Template->mtype = 'error'; $this->Template->message = strlen(\Input::get('reason')) ? \Input::get('reason') : $GLOBALS['TL_LANG']['ERR']['orderFailed']; $this->strCurrentStep = 'review'; // no break // no break default: // canCheckout will override the template and show a message if (!$this->canCheckout()) { return; } $arrBuffer = $this->generateSteps($this->getSteps()); break; } RowClass::withKey('class')->addFirstLast()->applyTo($arrBuffer); $this->Template->fields = $arrBuffer; }
/** * Replaces Isotope specific InsertTags in Frontend * @param string * @return mixed */ public function replaceIsotopeTags($strTag) { $arrTag = trimsplit('::', $strTag); // {{isotope::*}} and {{cache_isotope::*}} insert tags if ($arrTag[0] == 'isotope' || $arrTag[0] == 'cache_isotope') { switch ($arrTag[1]) { case 'cart_items': return Isotope::getCart()->countItems(); break; case 'cart_quantity': return Isotope::getCart()->sumItemsQuantity(); break; case 'cart_items_label': $intCount = Isotope::getCart()->countItems(); if (!$intCount) { return ''; } return $intCount == 1 ? '(' . $GLOBALS['TL_LANG']['MSC']['productSingle'] . ')' : sprintf('(' . $GLOBALS['TL_LANG']['MSC']['productMultiple'] . ')', $intCount); break; case 'cart_quantity_label': $intCount = Isotope::getCart()->sumItemsQuantity(); if (!$intCount) { return ''; } return $intCount == 1 ? '(' . $GLOBALS['TL_LANG']['MSC']['productSingle'] . ')' : sprintf('(' . $GLOBALS['TL_LANG']['MSC']['productMultiple'] . ')', $intCount); break; case 'cart_subtotal': return Isotope::formatPriceWithCurrency(Isotope::getCart()->getSubtotal()); break; case 'cart_taxfree_subtotal': return Isotope::formatPriceWithCurrency(Isotope::getCart()->getTaxFreeSubtotal()); break; case 'cart_total': return Isotope::formatPriceWithCurrency(Isotope::getCart()->getTotal()); break; case 'cart_taxfree_total': return Isotope::formatPriceWithCurrency(Isotope::getCart()->getTaxFreeTotal()); break; } return ''; } elseif ($arrTag[0] == 'isolabel') { return Translation::get($arrTag[1], $arrTag[2]); } elseif ($arrTag[0] == 'order') { if (($objOrder = Order::findOneByUniqid(\Input::get('uid'))) !== null) { return $objOrder->{$arrTag[1]}; } return ''; } elseif ($arrTag[0] == 'product') { // 2 possible use cases: // {{product::attribute}} - gets the data of the current product (Product::getActive() or GET parameter "product") // {{product::attribute::product_id}} - gets the data of the specified product ID if (count($arrTag) == 3) { $objProduct = Product::findAvailableByPk($arrTag[2]); } else { if (($objProduct = Product::getActive()) === null) { $objProduct = Product::findAvailableByIdOrAlias(\Haste\Input\Input::getAutoItem('product', false, true)); } } return $objProduct !== null ? $objProduct->{$arrTag[1]} : ''; } return false; }