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


PHP Quote::setRemoteIp方法代码示例

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


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

示例1: getQuote

 /**
  * Get checkout quote instance by current session
  *
  * @return Quote
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function getQuote()
 {
     $this->_eventManager->dispatch('custom_quote_process', ['checkout_session' => $this]);
     if ($this->_quote === null) {
         $quote = $this->quoteFactory->create();
         if ($this->getQuoteId()) {
             try {
                 if ($this->_loadInactive) {
                     $quote = $this->quoteRepository->get($this->getQuoteId());
                 } else {
                     $quote = $this->quoteRepository->getActive($this->getQuoteId());
                 }
                 /**
                  * If current currency code of quote is not equal current currency code of store,
                  * need recalculate totals of quote. It is possible if customer use currency switcher or
                  * store switcher.
                  */
                 if ($quote->getQuoteCurrencyCode() != $this->_storeManager->getStore()->getCurrentCurrencyCode()) {
                     $quote->setStore($this->_storeManager->getStore());
                     $this->quoteRepository->save($quote->collectTotals());
                     /*
                      * We mast to create new quote object, because collectTotals()
                      * can to create links with other objects.
                      */
                     $quote = $this->quoteRepository->get($this->getQuoteId());
                 }
             } catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
                 $this->setQuoteId(null);
             }
         }
         if (!$this->getQuoteId()) {
             if ($this->_customerSession->isLoggedIn() || $this->_customer) {
                 $customerId = $this->_customer ? $this->_customer->getId() : $this->_customerSession->getCustomerId();
                 try {
                     $quote = $this->quoteRepository->getActiveForCustomer($customerId);
                     $this->setQuoteId($quote->getId());
                 } catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
                 }
             } else {
                 $quote->setIsCheckoutCart(true);
                 $this->_eventManager->dispatch('checkout_quote_init', ['quote' => $quote]);
             }
         }
         if ($this->_customer) {
             $quote->setCustomer($this->_customer);
         } elseif ($this->_customerSession->isLoggedIn()) {
             $quote->setCustomer($this->customerRepository->getById($this->_customerSession->getCustomerId()));
         }
         $quote->setStore($this->_storeManager->getStore());
         $this->_quote = $quote;
     }
     if (!$this->isQuoteMasked() && !$this->_customerSession->isLoggedIn() && $this->getQuoteId()) {
         $quoteId = $this->getQuoteId();
         /** @var $quoteIdMask \Magento\Quote\Model\QuoteIdMask */
         $quoteIdMask = $this->quoteIdMaskFactory->create()->load($quoteId, 'quote_id');
         if ($quoteIdMask->getMaskedId() === null) {
             $quoteIdMask->setQuoteId($quoteId)->save();
         }
         $this->setIsQuoteMasked(true);
     }
     $remoteAddress = $this->_remoteAddress->getRemoteAddress();
     if ($remoteAddress) {
         $this->_quote->setRemoteIp($remoteAddress);
         $xForwardIp = $this->request->getServer('HTTP_X_FORWARDED_FOR');
         $this->_quote->setXForwardedFor($xForwardIp);
     }
     return $this->_quote;
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:75,代码来源:Session.php


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