コード例 #1
0
ファイル: Checkout.php プロジェクト: Aziz-JH/core
 /**
  * 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;
 }
コード例 #2
0
ファイル: Cart.php プロジェクト: ralfhartmann/isotope_core
 /**
  * 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;
 }