• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP Model\Session类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: execute

 /**
  * @param \Magento\Framework\Event\Observer $observer
  * @return void
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     try {
         $this->checkoutSession->loadCustomerQuote();
     } catch (\Magento\Framework\Exception\LocalizedException $e) {
         $this->messageManager->addError($e->getMessage());
     } catch (\Exception $e) {
         $this->messageManager->addException($e, __('Load customer quote error'));
     }
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:15,代码来源:LoadCustomerQuoteObserver.php


示例2: isValid

 /**
  * @return bool
  */
 public function isValid()
 {
     if (!$this->checkoutSession->getLastSuccessQuoteId()) {
         return false;
     }
     if (!$this->checkoutSession->getLastQuoteId() || !$this->checkoutSession->getLastOrderId()) {
         return false;
     }
     return true;
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:13,代码来源:SuccessValidator.php


示例3: afterGenerateXml

 /**
  * After generate Xml
  *
  * @param \Magento\Framework\View\LayoutInterface $subject
  * @param \Magento\Framework\View\LayoutInterface $result
  * @return \Magento\Framework\View\LayoutInterface
  */
 public function afterGenerateXml(\Magento\Framework\View\LayoutInterface $subject, $result)
 {
     if ($this->moduleManager->isEnabled('Magento_PageCache') && $this->cacheConfig->isEnabled() && !$this->request->isAjax() && $subject->isCacheable()) {
         $this->checkoutSession->clearStorage();
     }
     return $result;
 }
开发者ID:aiesh,项目名称:magento2,代码行数:14,代码来源:DepersonalizePlugin.php


示例4: getOrder

 public function getOrder()
 {
     if (!$this->_order) {
         $this->_order = $this->_checkoutSession->getLastRealOrder();
     }
     return $this->_order;
 }
开发者ID:vuleticd,项目名称:vuleticd_assist2,代码行数:7,代码来源:Payment.php


示例5: _getDiscountAmount

 /**
  * Return mp discount
  *
  * @return float|int
  */
 protected function _getDiscountAmount()
 {
     $quote = $this->_checkoutSession->getQuote();
     $totals = $quote->getShippingAddress()->getTotals();
     $discount = isset($totals['discount_coupon']) ? $totals['discount_coupon']['value'] : 0;
     return $discount;
 }
开发者ID:SummaSolutions,项目名称:cart-magento2,代码行数:12,代码来源:FinanceCost.php


示例6: setUp

 protected function setUp()
 {
     $this->markTestIncomplete();
     $this->messageManager = $this->getMockForAbstractClass('Magento\\Framework\\Message\\ManagerInterface');
     $this->config = $this->getMock('Magento\\Paypal\\Model\\Config', [], [], '', false);
     $this->request = $this->getMock('Magento\\Framework\\App\\Request\\Http', [], [], '', false);
     $this->quote = $this->getMock('Magento\\Quote\\Model\\Quote', [], [], '', false);
     $this->quote->expects($this->any())->method('hasItems')->will($this->returnValue(true));
     $this->redirect = $this->getMockForAbstractClass('Magento\\Framework\\App\\Response\\RedirectInterface');
     $this->response = $this->getMock('Magento\\Framework\\App\\Response\\Http', [], [], '', false);
     $this->customerData = $this->getMock('Magento\\Customer\\Api\\Data\\CustomerInterface', [], [], '', false);
     $this->checkout = $this->getMock('Magento\\Paypal\\Model\\Express\\Checkout', [], [], '', false);
     $this->customerSession = $this->getMock('Magento\\Customer\\Model\\Session', [], [], '', false);
     $this->customerSession->expects($this->any())->method('getCustomerDataObject')->will($this->returnValue($this->customerData));
     $this->checkoutSession = $this->getMock('Magento\\Checkout\\Model\\Session', [], [], '', false);
     $this->checkoutFactory = $this->getMock('Magento\\Paypal\\Model\\Express\\Checkout\\Factory', [], [], '', false);
     $this->checkoutFactory->expects($this->any())->method('create')->will($this->returnValue($this->checkout));
     $this->checkoutSession->expects($this->any())->method('getQuote')->will($this->returnValue($this->quote));
     $this->session = $this->getMock('Magento\\Framework\\Session\\Generic', [], [], '', false);
     $objectManager = $this->getMock('Magento\\Framework\\ObjectManagerInterface');
     $this->objectManagerCallback = function ($className) {
         if ($className == 'Magento\\Paypal\\Model\\Config') {
             return $this->config;
         }
         return $this->getMock($className, [], [], '', false);
     };
     $objectManager->expects($this->any())->method('get')->will($this->returnCallback(function ($className) {
         return call_user_func($this->objectManagerCallback, $className);
     }));
     $objectManager->expects($this->any())->method('create')->will($this->returnCallback(function ($className) {
         return call_user_func($this->objectManagerCallback, $className);
     }));
     $helper = new ObjectManagerHelper($this);
     $this->model = $helper->getObject('\\Magento\\\\Paypal\\Controller\\Express\\' . $this->name, ['messageManager' => $this->messageManager, 'response' => $this->response, 'redirect' => $this->redirect, 'request' => $this->request, 'customerSession' => $this->customerSession, 'checkoutSession' => $this->checkoutSession, 'checkoutFactory' => $this->checkoutFactory, 'paypalSession' => $this->session, 'objectManager' => $objectManager]);
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:35,代码来源:ExpressTest.php


示例7: testAddBillingAgreementToSession

 /**
  * @param bool $isValid
  * @dataProvider addBillingAgreementToSessionDataProvider
  */
 public function testAddBillingAgreementToSession($isValid)
 {
     $agreement = $this->getMock('Magento\\Paypal\\Model\\Billing\\Agreement', [], [], '', false);
     $agreement->expects($this->once())->method('isValid')->will($this->returnValue($isValid));
     $comment = $this->getMockForAbstractClass('Magento\\Framework\\Model\\AbstractModel', [], '', false, true, true, ['__wakeup']);
     $order = $this->getMock('Magento\\Sales\\Model\\Order', [], [], '', false);
     $order->expects($this->once())->method('addStatusHistoryComment')->with($isValid ? __('Created billing agreement #%1.', 'agreement reference id') : __('We can\'t create a billing agreement for this order.'))->will($this->returnValue($comment));
     if ($isValid) {
         $agreement->expects($this->any())->method('__call')->with('getReferenceId')->will($this->returnValue('agreement reference id'));
         $agreement->expects($this->once())->method('addOrderRelation')->with($order);
         $order->expects(new MethodInvokedAtIndex(0))->method('addRelatedObject')->with($agreement);
         $this->_checkoutSession->expects($this->once())->method('__call')->with('setLastBillingAgreementReferenceId', ['agreement reference id']);
     } else {
         $this->_checkoutSession->expects($this->once())->method('__call')->with('unsLastBillingAgreementReferenceId');
         $agreement->expects($this->never())->method('__call');
     }
     $order->expects(new MethodInvokedAtIndex($isValid ? 1 : 0))->method('addRelatedObject')->with($comment);
     $payment = $this->getMock('Magento\\Sales\\Model\\Order\\Payment', [], [], '', false);
     $payment->expects($this->once())->method('__call')->with('getBillingAgreementData')->will($this->returnValue('not empty'));
     $payment->expects($this->once())->method('getOrder')->will($this->returnValue($order));
     $agreement->expects($this->once())->method('importOrderPayment')->with($payment)->will($this->returnValue($agreement));
     $this->_event->setPayment($payment);
     $this->_agreementFactory->expects($this->once())->method('create')->will($this->returnValue($agreement));
     $this->_model->execute($this->_observer);
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:29,代码来源:AddBillingAgreementToSessionObserverTest.php


示例8: testClearHelperData

 /**
  * @param $paramToClear
  * @dataProvider clearHelperDataDataProvider
  */
 public function testClearHelperData($paramToClear)
 {
     $storage = new \Magento\Framework\Session\Storage('default', [$paramToClear => 'test_data']);
     $this->_session = $this->_helper->getObject('Magento\\Checkout\\Model\\Session', ['storage' => $storage]);
     $this->_session->clearHelperData();
     $this->assertNull($this->_session->getData($paramToClear));
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:11,代码来源:SessionTest.php


示例9: execute

 /**
  * Push trackEcommerceCartUpdate to tracker on cart view page
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return \Henhed\Piwik\Observer\CartViewObserver
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     if ($this->_dataHelper->isTrackingEnabled()) {
         $this->_trackerHelper->addQuote($this->_checkoutSession->getQuote(), $this->_piwikTracker);
     }
     return $this;
 }
开发者ID:henkelund,项目名称:magento2-henhed-piwik,代码行数:13,代码来源:CartViewObserver.php


示例10: afterGenerateXml

 /**
  * After generate Xml
  *
  * @param \Magento\Framework\View\LayoutInterface $subject
  * @param \Magento\Framework\View\LayoutInterface $result
  * @return \Magento\Framework\View\LayoutInterface
  */
 public function afterGenerateXml(\Magento\Framework\View\LayoutInterface $subject, $result)
 {
     if ($this->depersonalizeChecker->checkIfDepersonalize($subject)) {
         $this->checkoutSession->clearStorage();
     }
     return $result;
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:14,代码来源:DepersonalizePlugin.php


示例11: execute

 /**
  * @param EventObserver $observer
  * @return void
  */
 public function execute(EventObserver $observer)
 {
     /** @var \Magento\Sales\Model\Order\Payment $orderPayment */
     $orderPayment = $observer->getEvent()->getPayment();
     $agreementCreated = false;
     if ($orderPayment->getBillingAgreementData()) {
         $order = $orderPayment->getOrder();
         /** @var \Magento\Paypal\Model\Billing\Agreement $agreement */
         $agreement = $this->agreementFactory->create()->importOrderPayment($orderPayment);
         if ($agreement->isValid()) {
             $message = __('Created billing agreement #%1.', $agreement->getReferenceId());
             $order->addRelatedObject($agreement);
             $agreement->addOrderRelation($order);
             $this->checkoutSession->setLastBillingAgreementReferenceId($agreement->getReferenceId());
             $agreementCreated = true;
         } else {
             $message = __('We can\'t create a billing agreement for this order.');
         }
         $comment = $order->addStatusHistoryComment($message);
         $order->addRelatedObject($comment);
     }
     if (!$agreementCreated) {
         $this->checkoutSession->unsLastBillingAgreementReferenceId();
     }
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:29,代码来源:AddBillingAgreementToSessionObserver.php


示例12: _getQuoteItems

 /**
  * Returns an array of SKUs of items in the basket
  *
  * @return array
  */
 protected function _getQuoteItems()
 {
     $skus = [];
     foreach ($this->_checkoutSession->getQuote()->getAllVisibleItems() as $item) {
         $skus[] = $item->getProduct()->getData('sku');
     }
     return $skus;
 }
开发者ID:halk,项目名称:recowise-magento2-demo,代码行数:13,代码来源:Similar.php


示例13: testAfterGenerateXmlNoDepersonalize

 public function testAfterGenerateXmlNoDepersonalize()
 {
     $expectedResult = $this->getMock('Magento\\Framework\\View\\Layout', [], [], '', false);
     $this->depersonalizeCheckerMock->expects($this->once())->method('checkIfDepersonalize')->willReturn(false);
     $this->checkoutSessionMock->expects($this->never())->method('clearStorage')->will($this->returnValue($expectedResult));
     $actualResult = $this->plugin->afterGenerateXml($this->layoutMock, $expectedResult);
     $this->assertEquals($expectedResult, $actualResult);
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:8,代码来源:DepersonalizePluginTest.php


示例14: getPaymentInfo

 /**
  * Retrieve payment info model
  *
  * @return \Magento\Payment\Model\Info|false
  */
 public function getPaymentInfo()
 {
     $info = $this->_checkoutSession->getQuote()->getPayment();
     if ($info->getMethod()) {
         return $info;
     }
     return false;
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:13,代码来源:Info.php


示例15: execute

 /**
  * @param \Magento\Framework\Event\Observer $observer
  * @return void
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     $quote = $observer->getEvent()->getQuote();
     /* @var $quote \Magento\Quote\Model\Quote */
     if ($quote->getIsCheckoutCart()) {
         $this->checkoutSession->getQuoteId($quote->getId());
     }
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:12,代码来源:SalesQuoteSaveAfterObserver.php


示例16: getPostData

 public function getPostData()
 {
     $orderId = $this->_checkoutSession->getLastOrderId();
     if ($orderId) {
         $incrementId = $this->_checkoutSession->getLastRealOrderId();
         return $this->Config->getPostData($incrementId);
     }
 }
开发者ID:MagePsycho,项目名称:magento2-module-payment-tmrobokassa,代码行数:8,代码来源:Redirect.php


示例17: execute

 /**
  * Set quote to be loaded even if not active
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return void
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     if (!($this->_persistentSession->isPersistent() && !$this->_customerSession->isLoggedIn() && !$this->_persistentData->isShoppingCartPersist())) {
         return;
     }
     if ($this->_checkoutSession) {
         $this->_checkoutSession->setLoadInactive();
     }
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:16,代码来源:SetLoadPersistentQuoteObserver.php


示例18: afterGetConfig

 /**
  * @param \Magento\Checkout\Model\DefaultConfigProvider $subject
  * @param array $result
  * @return array
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function afterGetConfig(\Magento\Checkout\Model\DefaultConfigProvider $subject, array $result)
 {
     if ($this->persistentHelper->isEnabled() && $this->persistentSession->isPersistent() && !$this->customerSession->isLoggedIn()) {
         /** @var $quoteIdMask \Magento\Quote\Model\QuoteIdMask */
         $quoteIdMask = $this->quoteIdMaskFactory->create();
         $result['quoteData']['entity_id'] = $quoteIdMask->load($this->checkoutSession->getQuote()->getId(), 'quote_id')->getMaskedId();
     }
     return $result;
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:15,代码来源:ConfigProviderPlugin.php


示例19: testExecuteException

 /**
  * Run test for execute method (exception)
  *
  * @expectedException \Magento\Framework\Exception\LocalizedException
  * @expectedExceptionMessage Wrong type of request.
  */
 public function testExecuteException()
 {
     $this->contextMock = $this->getMockBuilder('Magento\\Framework\\App\\Action\\Context')->disableOriginalConstructor()->getMock();
     $this->contextMock->expects(static::once())->method('getRequest')->willReturn($this->getRequestMock(false));
     $this->checkoutSessionMock = $this->getMockBuilder('Magento\\Checkout\\Model\\Session')->disableOriginalConstructor()->getMock();
     $this->checkoutSessionMock->expects(static::never())->method('getQuote');
     $getButtonData = new GetButtonData($this->contextMock, $this->checkoutSessionMock);
     $getButtonData->execute();
 }
开发者ID:whoople,项目名称:magento2-testing,代码行数:15,代码来源:GetButtonDataTest.php


示例20: execute

 /**
  * Record order shipping information after order is placed
  *
  * @param EventObserver $observer
  * @return void
  */
 public function execute(EventObserver $observer)
 {
     if ($this->shipperDataHelper->getConfigValue('carriers/shipper/active')) {
         $order = $this->orderFactory->create()->loadByIncrementId($this->checkoutSession->getLastRealOrderId());
         if ($order->getIncrementId()) {
             $this->recordOrder($order);
         }
     }
 }
开发者ID:shipperhq,项目名称:module-shipper,代码行数:15,代码来源:RecordOrder.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP Page\CheckoutCart类代码示例发布时间:2022-05-23
下一篇:
PHP Api\StockRegistryInterface类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap