当前位置: 首页>>代码示例>>PHP>>正文


PHP Session::setLastOrderId方法代码示例

本文整理汇总了PHP中Magento\Checkout\Model\Session::setLastOrderId方法的典型用法代码示例。如果您正苦于以下问题:PHP Session::setLastOrderId方法的具体用法?PHP Session::setLastOrderId怎么用?PHP Session::setLastOrderId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Magento\Checkout\Model\Session的用法示例。


在下文中一共展示了Session::setLastOrderId方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: saveOrder

 /**
  * Create order based on checkout type. Create customer if necessary.
  *
  * @return $this
  */
 public function saveOrder()
 {
     $this->validate();
     $isNewCustomer = false;
     switch ($this->getCheckoutMethod()) {
         case self::METHOD_GUEST:
             $this->_prepareGuestQuote();
             break;
         case self::METHOD_REGISTER:
             $this->_prepareNewCustomerQuote();
             $isNewCustomer = true;
             break;
         default:
             $this->_prepareCustomerQuote();
             break;
     }
     /** @var \Magento\Sales\Model\Service\Quote $quoteService */
     $quoteService = $this->_serviceQuoteFactory->create(array('quote' => $this->getQuote()));
     $quoteService->submitAllWithDataObject();
     if ($isNewCustomer) {
         try {
             $this->_involveNewCustomer();
         } catch (\Exception $e) {
             $this->_logger->logException($e);
         }
     }
     $this->_checkoutSession->setLastQuoteId($this->getQuote()->getId())->setLastSuccessQuoteId($this->getQuote()->getId())->clearHelperData();
     $order = $quoteService->getOrder();
     if ($order) {
         $this->_eventManager->dispatch('checkout_type_onepage_save_order_after', array('order' => $order, 'quote' => $this->getQuote()));
         /**
          * a flag to set that there will be redirect to third party after confirmation
          */
         $redirectUrl = $this->getQuote()->getPayment()->getOrderPlaceRedirectUrl();
         /**
          * we only want to send to customer about new order when there is no redirect to third party
          */
         if (!$redirectUrl && $order->getCanSendNewEmailFlag()) {
             try {
                 $order->sendNewOrderEmail();
             } catch (\Exception $e) {
                 $this->_logger->logException($e);
             }
         }
         // add order information to the session
         $this->_checkoutSession->setLastOrderId($order->getId())->setRedirectUrl($redirectUrl)->setLastRealOrderId($order->getIncrementId());
     }
     $this->_eventManager->dispatch('checkout_submit_all_after', array('order' => $order, 'quote' => $this->getQuote()));
     return $this;
 }
开发者ID:Atlis,项目名称:docker-magento2,代码行数:55,代码来源:Onepage.php

示例2: saveOrder

 /**
  * Create order based on checkout type. Create customer if necessary.
  *
  * @return $this
  */
 public function saveOrder()
 {
     $this->validate();
     $isNewCustomer = false;
     switch ($this->getCheckoutMethod()) {
         case self::METHOD_GUEST:
             $this->_prepareGuestQuote();
             break;
         case self::METHOD_REGISTER:
             $this->_prepareNewCustomerQuote();
             $isNewCustomer = true;
             break;
         default:
             $this->_prepareCustomerQuote();
             break;
     }
     $order = $this->quoteManagement->submit($this->getQuote());
     if ($isNewCustomer) {
         try {
             $this->_involveNewCustomer();
         } catch (\Exception $e) {
             $this->_logger->critical($e);
         }
     }
     $this->_checkoutSession->setLastQuoteId($this->getQuote()->getId())->setLastSuccessQuoteId($this->getQuote()->getId())->clearHelperData();
     if ($order) {
         $this->_eventManager->dispatch('checkout_type_onepage_save_order_after', ['order' => $order, 'quote' => $this->getQuote()]);
         /**
          * a flag to set that there will be redirect to third party after confirmation
          */
         $redirectUrl = $this->getQuote()->getPayment()->getOrderPlaceRedirectUrl();
         /**
          * we only want to send to customer about new order when there is no redirect to third party
          */
         if (!$redirectUrl && $order->getCanSendNewEmailFlag()) {
             try {
                 $this->orderSender->send($order);
             } catch (\Exception $e) {
                 $this->_logger->critical($e);
             }
         }
         // add order information to the session
         $this->_checkoutSession->setLastOrderId($order->getId())->setRedirectUrl($redirectUrl)->setLastRealOrderId($order->getIncrementId())->setLastOrderStatus($order->getStatus());
     }
     $this->_eventManager->dispatch('checkout_submit_all_after', ['order' => $order, 'quote' => $this->getQuote()]);
     return $this;
 }
开发者ID:nja78,项目名称:magento2,代码行数:52,代码来源:Onepage.php

示例3: placeOrder

 /**
  * {@inheritdoc}
  */
 public function placeOrder($cartId, $agreements = null, PaymentInterface $paymentMethod = null)
 {
     $quote = $this->quoteRepository->getActive($cartId);
     if ($paymentMethod) {
         $paymentMethod->setChecks([\Magento\Payment\Model\Method\AbstractMethod::CHECK_USE_CHECKOUT, \Magento\Payment\Model\Method\AbstractMethod::CHECK_USE_FOR_COUNTRY, \Magento\Payment\Model\Method\AbstractMethod::CHECK_USE_FOR_CURRENCY, \Magento\Payment\Model\Method\AbstractMethod::CHECK_ORDER_TOTAL_MIN_MAX, \Magento\Payment\Model\Method\AbstractMethod::CHECK_ZERO_TOTAL]);
         $quote->getPayment()->setQuote($quote);
         $data = $paymentMethod->getData();
         if (isset($data['additional_data'])) {
             $data = array_merge($data, (array) $data['additional_data']);
             unset($data['additional_data']);
         }
         $quote->getPayment()->importData($data);
     }
     if ($quote->getCheckoutMethod() === self::METHOD_GUEST) {
         $quote->setCustomerId(null);
         $quote->setCustomerEmail($quote->getBillingAddress()->getEmail());
         $quote->setCustomerIsGuest(true);
         $quote->setCustomerGroupId(\Magento\Customer\Api\Data\GroupInterface::NOT_LOGGED_IN_ID);
     }
     $order = $this->submit($quote);
     $this->checkoutSession->setLastQuoteId($quote->getId());
     $this->checkoutSession->setLastSuccessQuoteId($quote->getId());
     $this->checkoutSession->setLastOrderId($order->getId());
     $this->checkoutSession->setLastRealOrderId($order->getIncrementId());
     $this->checkoutSession->setLastOrderStatus($order->getStatus());
     $this->eventManager->dispatch('checkout_submit_all_after', ['order' => $order, 'quote' => $quote]);
     return $order->getId();
 }
开发者ID:nja78,项目名称:magento2,代码行数:31,代码来源:QuoteManagement.php

示例4: placeOrder

 /**
  * {@inheritdoc}
  */
 public function placeOrder($cartId, PaymentInterface $paymentMethod = null)
 {
     $quote = $this->quoteRepository->getActive($cartId);
     if ($paymentMethod) {
         $paymentMethod->setChecks([\Magento\Payment\Model\Method\AbstractMethod::CHECK_USE_CHECKOUT, \Magento\Payment\Model\Method\AbstractMethod::CHECK_USE_FOR_COUNTRY, \Magento\Payment\Model\Method\AbstractMethod::CHECK_USE_FOR_CURRENCY, \Magento\Payment\Model\Method\AbstractMethod::CHECK_ORDER_TOTAL_MIN_MAX, \Magento\Payment\Model\Method\AbstractMethod::CHECK_ZERO_TOTAL]);
         $quote->getPayment()->setQuote($quote);
         $data = $paymentMethod->getData();
         $quote->getPayment()->importData($data);
     }
     if ($quote->getCheckoutMethod() === self::METHOD_GUEST) {
         $quote->setCustomerId(null);
         $quote->setCustomerEmail($quote->getBillingAddress()->getEmail());
         $quote->setCustomerIsGuest(true);
         $quote->setCustomerGroupId(\Magento\Customer\Api\Data\GroupInterface::NOT_LOGGED_IN_ID);
     }
     $this->eventManager->dispatch('checkout_submit_before', ['quote' => $quote]);
     $order = $this->submit($quote);
     if (null == $order) {
         throw new LocalizedException(__('Unable to place order. Please try again later.'));
     }
     $this->checkoutSession->setLastQuoteId($quote->getId());
     $this->checkoutSession->setLastSuccessQuoteId($quote->getId());
     $this->checkoutSession->setLastOrderId($order->getId());
     $this->checkoutSession->setLastRealOrderId($order->getIncrementId());
     $this->checkoutSession->setLastOrderStatus($order->getStatus());
     $this->eventManager->dispatch('checkout_submit_all_after', ['order' => $order, 'quote' => $quote]);
     return $order->getId();
 }
开发者ID:rafaelstz,项目名称:magento2,代码行数:31,代码来源:QuoteManagement.php

示例5: execute

 public function execute()
 {
     $redirectTo = 'checkout/cart';
     $defaultErrorMessage = $this->_dataHelper->__('An error occurred during the payment process.');
     try {
         $this->_logger->debug(__METHOD__ . ':' . print_r($this->_request->getPost()->toArray(), true));
         $this->_cart->getCustomerSession()->unsUniqueId();
         if (!$this->_request->isPost()) {
             throw new \Exception('Not a post request');
         }
         $return = \WirecardCEE_QPay_ReturnFactory::getInstance($this->_request->getPost()->toArray(), $this->_dataHelper->getConfigData('basicdata/secret'));
         if (!$return->validate()) {
             throw new \Exception('Validation error: invalid response');
         }
         if (!strlen($return->mage_orderId)) {
             throw new \Exception('Magento OrderId is missing');
         }
         if (!strlen($return->mage_quoteId)) {
             throw new \Exception('Magento QuoteId is missing');
         }
         $orderId = $this->_request->getPost('mage_orderId');
         /** @var \Magento\Sales\Model\Order $order */
         $order = $this->_objectManager->create('\\Magento\\Sales\\Model\\Order');
         $order->loadByIncrementId($orderId);
         $orderExists = (bool) $order->getId();
         if ($return->mage_orderCreation == 'before') {
             if (!$orderExists) {
                 throw new \Exception('Order not found');
             }
             $payment = $order->getPayment();
             if (!strlen($payment->getAdditionalInformation('paymentState'))) {
                 $this->_logger->debug(__METHOD__ . ':order not processed via confirm server2server request, check your packetfilter!');
                 $order = $this->_orderManagement->processOrder($return);
             }
         }
         if ($return->mage_orderCreation == 'after') {
             if (!$orderExists && ($return->getPaymentState() == \WirecardCEE_QPay_ReturnFactory::STATE_SUCCESS || $return->getPaymentState() == \WirecardCEE_QPay_ReturnFactory::STATE_PENDING)) {
                 $this->_logger->debug(__METHOD__ . ':order not processed via confirm server2server request, check your packetfilter!');
                 $order = $this->_orderManagement->processOrder($return);
             }
         }
         switch ($return->getPaymentState()) {
             case \WirecardCEE_QPay_ReturnFactory::STATE_SUCCESS:
             case \WirecardCEE_QPay_ReturnFactory::STATE_PENDING:
                 if ($return->getPaymentState() == \WirecardCEE_QPay_ReturnFactory::STATE_PENDING) {
                     $this->messageManager->addNoticeMessage($this->_dataHelper->__('Your order will be processed as soon as we receive the payment confirmation from your bank.'));
                 }
                 /* needed for success page otherwise magento redirects to cart */
                 $this->_checkoutSession->setLastQuoteId($order->getQuoteId());
                 $this->_checkoutSession->setLastSuccessQuoteId($order->getQuoteId());
                 $this->_checkoutSession->setLastOrderId($order->getId());
                 $this->_checkoutSession->setLastRealOrderId($order->getIncrementId());
                 $this->_checkoutSession->setLastOrderStatus($order->getStatus());
                 $redirectTo = 'checkout/onepage/success';
                 break;
             case \WirecardCEE_QPay_ReturnFactory::STATE_CANCEL:
                 /** @var \WirecardCEE_QPay_Return_Cancel $return */
                 $this->messageManager->addNoticeMessage($this->_dataHelper->__('You have canceled the payment process!'));
                 if ($return->mage_orderCreation == 'before') {
                     $quote = $this->_orderManagement->reOrder($return->mage_quoteId);
                     $this->_checkoutSession->replaceQuote($quote)->unsLastRealOrderId();
                 }
                 break;
             case \WirecardCEE_QPay_ReturnFactory::STATE_FAILURE:
                 /** @var \WirecardCEE_QPay_Return_Failure $return */
                 $msg = $return->getErrors()->getConsumerMessage();
                 if (!strlen($msg)) {
                     $msg = $defaultErrorMessage;
                 }
                 $this->messageManager->addErrorMessage($msg);
                 if ($return->mage_orderCreation == 'before') {
                     $quote = $this->_orderManagement->reOrder($return->mage_quoteId);
                     $this->_checkoutSession->replaceQuote($quote)->unsLastRealOrderId();
                 }
                 break;
             default:
                 throw new \Exception('Unhandled Wirecard Checkout Page payment state:' . $return->getPaymentState());
         }
         if ($this->_request->getPost('iframeUsed')) {
             $redirectUrl = $this->_url->getUrl($redirectTo);
             $page = $this->_resultPageFactory->create();
             $page->getLayout()->getBlock('checkout.back')->addData(['redirectUrl' => $redirectUrl]);
             return $page;
         } else {
             $this->_redirect($redirectTo);
         }
     } catch (\Exception $e) {
         if (!$this->messageManager->getMessages()->getCount()) {
             $this->messageManager->addErrorMessage($defaultErrorMessage);
         }
         $this->_logger->debug(__METHOD__ . ':' . $e->getMessage());
         $this->_redirect($redirectTo);
     }
 }
开发者ID:wirecard,项目名称:magento2-wcp,代码行数:94,代码来源:Back.php


注:本文中的Magento\Checkout\Model\Session::setLastOrderId方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。