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


PHP Model\Session类代码示例

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


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


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