示例#1
0
 /**
  * Generate the module
  */
 protected function compile()
 {
     // Also check owner (see #126)
     if (($objOrder = Order::findOneBy('uniqid', (string) \Input::get('uid'))) === null || FE_USER_LOGGED_IN === true && $objOrder->member > 0 && \FrontendUser::getInstance()->id != $objOrder->member) {
         $this->Template = new \Isotope\Template('mod_message');
         $this->Template->type = 'error';
         $this->Template->message = $GLOBALS['TL_LANG']['ERR']['orderNotFound'];
         return;
     }
     // Order belongs to a member but not logged in
     if (TL_MODE == 'FE' && $this->iso_loginRequired && $objOrder->member > 0 && FE_USER_LOGGED_IN !== true) {
         global $objPage;
         $objHandler = new $GLOBALS['TL_PTY']['error_403']();
         $objHandler->generate($objPage->id);
         exit;
     }
     Isotope::setConfig($objOrder->getRelated('config_id'));
     $objTemplate = new \Isotope\Template($this->iso_collectionTpl);
     $objTemplate->linkProducts = true;
     $objOrder->addToTemplate($objTemplate, array('gallery' => $this->iso_gallery, 'sorting' => $objOrder->getItemsSortingCallable($this->iso_orderCollectionBy)));
     $this->Template->collection = $objOrder;
     $this->Template->products = $objTemplate->parse();
     $this->Template->info = deserialize($objOrder->checkout_info, true);
     $this->Template->date = Format::date($objOrder->locked);
     $this->Template->time = Format::time($objOrder->locked);
     $this->Template->datim = Format::datim($objOrder->locked);
     $this->Template->orderDetailsHeadline = sprintf($GLOBALS['TL_LANG']['MSC']['orderDetailsHeadline'], $objOrder->document_number, $this->Template->datim);
     $this->Template->orderStatus = sprintf($GLOBALS['TL_LANG']['MSC']['orderStatusHeadline'], $objOrder->getStatusLabel());
     $this->Template->orderStatusKey = $objOrder->getStatusAlias();
 }
示例#2
0
 /**
  * Replace known Isotope insert tags.
  *
  * @param string $insertTag
  *
  * @return string|bool
  */
 public function replace($insertTag)
 {
     $tokens = trimsplit('::', $insertTag);
     switch ($tokens[0]) {
         case 'cart':
             return $this->getValueForCollectionTag(Isotope::getCart(), $tokens);
         case 'order':
             if (($order = Order::findOneBy('uniqid', \Input::get('uid'))) === null) {
                 return '';
             }
             return $this->getValueForCollectionTag($order, $tokens);
         case 'product':
             if (($product = $this->findCurrentProduct($tokens[2])) === null) {
                 return '';
             }
             return $this->getValueForProductTag($product, $tokens[1]);
         case 'isolabel':
             return $this->getValueForLabel($tokens[1], $tokens[2]);
         case 'isotope':
         case 'cache_isotope':
             return $this->getValueForIsotopeTag($tokens[1]);
     }
     return false;
 }
示例#3
0
 /**
  * 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':
             /** @var Order $objOrder */
             if (($objOrder = Order::findOneBy('uniqid', (string) \Input::get('uid'))) === null) {
                 // Order already completed (see #1441)
                 if ($objOrder->checkout_complete || Isotope::getCart()->isEmpty()) {
                     /** @type \PageError404 $objHandler */
                     $objHandler = new $GLOBALS['TL_PTY']['error_404']();
                     $objHandler->generate((int) $GLOBALS['objPage']->id);
                     exit;
                 } else {
                     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':
             // canCheckout will override the template and show a message
             if (!$this->canCheckout()) {
                 return;
             }
             $arrSteps = $this->getSteps();
             // Make sure all steps have passed successfully
             foreach ($arrSteps as $step => $arrModules) {
                 /** @type IsotopeCheckoutStep $objModule */
                 foreach ($arrModules as $objModule) {
                     $objModule->generate();
                     if ($objModule->hasError()) {
                         static::redirectToStep($step);
                     }
                 }
             }
             $objOrder = Isotope::getCart()->getDraftOrder();
             $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);
             // !HOOK: pre-process checkout
             if (isset($GLOBALS['ISO_HOOKS']['preCheckout']) && is_array($GLOBALS['ISO_HOOKS']['preCheckout'])) {
                 foreach ($GLOBALS['ISO_HOOKS']['preCheckout'] as $callback) {
                     $objCallback = \System::importStatic($callback[0]);
                     if ($objCallback->{$callback}[1]($objOrder) === false) {
                         \System::log('Callback ' . $callback[0] . '::' . $callback[1] . '() cancelled checkout for Order ID ' . $this->id, __METHOD__, TL_ERROR);
                         static::redirectToStep('failed');
                     }
                 }
             }
             $objOrder->lock();
             $strBuffer = $objOrder->hasPayment() ? $objOrder->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
             /** @noinspection PhpMissingBreakStatementInspection */
         // Checkout/payment has failed, show the review page again with an error message
         /** @noinspection PhpMissingBreakStatementInspection */
         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;
 }
示例#4
0
 /**
  * Get and update order draft for current cart or create one if it does not yet exist
  *
  * @return Order
  */
 public function getDraftOrder()
 {
     if ($this->objDraftOrder === null) {
         $t = Order::getTable();
         $objOrder = Order::findOneBy(array("{$t}.source_collection_id=?", "{$t}.locked=''"), array($this->id));
         if ($objOrder === null) {
             $objOrder = Order::createFromCollection($this);
         } else {
             $objOrder->config_id = (int) $this->config_id;
             $objOrder->store_id = (int) $this->store_id;
             $objOrder->member = (int) $this->member;
             $objOrder->setShippingMethod($this->getShippingMethod());
             $objOrder->setPaymentMethod($this->getPaymentMethod());
             $objOrder->setShippingAddress($this->getShippingAddress());
             $objOrder->setBillingAddress($this->getBillingAddress());
             $objOrder->purge();
             $arrItemIds = $objOrder->copyItemsFrom($this);
             $objOrder->updateDatabase();
             // HOOK: order status has been updated
             if (isset($GLOBALS['ISO_HOOKS']['updateDraftOrder']) && is_array($GLOBALS['ISO_HOOKS']['updateDraftOrder'])) {
                 foreach ($GLOBALS['ISO_HOOKS']['updateDraftOrder'] as $callback) {
                     $objCallback = \System::importStatic($callback[0]);
                     $objCallback->{$callback}[1]($objOrder, $this, $arrItemIds);
                 }
             }
         }
         $this->objDraftOrder = $objOrder;
     }
     return $this->objDraftOrder;
 }