/** * @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')); } }
/** * @return bool */ public function isValid() { if (!$this->checkoutSession->getLastSuccessQuoteId()) { return false; } if (!$this->checkoutSession->getLastQuoteId() || !$this->checkoutSession->getLastOrderId()) { return false; } return true; }
/** * 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; }
public function getOrder() { if (!$this->_order) { $this->_order = $this->_checkoutSession->getLastRealOrder(); } return $this->_order; }
public function testSalesQuoteSaveAfter() { $observer = $this->getMock('Magento\\Framework\\Event\\Observer', [], [], '', false); $observer->expects($this->once())->method('getEvent')->will($this->returnValue(new \Magento\Framework\Object(['quote' => new \Magento\Framework\Object(['is_checkout_cart' => 1, 'id' => 7])]))); $this->checkoutSession->expects($this->once())->method('getQuoteId')->with(7); $this->object->salesQuoteSaveAfter($observer); }
/** * 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; }
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]); }
/** * @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); }
/** * @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)); }
/** * 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; }
public function testAfterGetOptions() { $quote = $this->getMockBuilder('Magento\\Sales\\Model\\Quote')->disableOriginalConstructor()->getMock(); $this->sessionMock->expects($this->once())->method('getQuote')->will($this->returnValue($quote)); $this->filterMock->expects($this->once())->method('hasRecurringItems')->with($quote)->will($this->returnValue(true)); $this->assertArrayHasKey('hasRecurringItems', $this->payment->afterGetOptions($this->getMock('\\Magento\\Checkout\\Block\\Onepage\\Payment', array(), array(), '', false), array())); }
/** * 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; }
/** * @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(); } }
/** * 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; }
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); }
/** * 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; }
/** * @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()); } }
public function getPostData() { $orderId = $this->_checkoutSession->getLastOrderId(); if ($orderId) { $incrementId = $this->_checkoutSession->getLastRealOrderId(); return $this->Config->getPostData($incrementId); } }
/** * 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(); } }
/** * @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; }
/** * 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(); }
/** * 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); } } }
/** * Fetch coupon info * * Controller Action */ public function execute() { $total = $this->getRequest()->getParam('cost'); $quote = $this->_checkoutSession->getQuote(); //save value to DiscountCoupon collect $this->_registry->register('mercadopago_total_amount', $total); $this->quoteRepository->save($quote->collectTotals()); return; }
/** * Validates minimum quote amount and zero grand total * * @param bool $isInCatalog * @return bool */ public function isQuoteSummaryValid($isInCatalog) { $quote = $isInCatalog ? null : $this->_checkoutSession->getQuote(); // validate minimum quote amount and validate quote for zero grandtotal if (null !== $quote && (!$quote->validateMinimumAmount() || !$quote->getGrandTotal())) { return false; } return true; }
protected function setupCart() { $quoteMock = $this->getMockBuilder('\\Magento\\Quote\\Model\\Quote')->disableOriginalConstructor()->setMethods(['hasItems', 'getHasError', 'getPayment'])->getMock(); $quoteMock->expects($this->any())->method('hasItems')->willReturn(true); $quoteMock->expects($this->any())->method('getHasError')->willReturn(false); $this->checkoutSessionMock->expects($this->any())->method('getQuote')->willReturn($quoteMock); $this->checkoutFactoryMock->expects($this->any())->method('create')->willReturn($this->checkoutMock); return $quoteMock; }
/** * Cancel order, return quote to customer * * @param string $errorMsg * @return false|string */ protected function _cancelPayment($errorMsg = '') { $gotoSection = false; $this->_checkoutHelper->cancelCurrentOrder($errorMsg); if ($this->_checkoutSession->restoreQuote()) { //Redirect to payment step $gotoSection = 'paymentMethod'; } return $gotoSection; }
/** * Is valid session? * * @param \Magento\Checkout\Model\Session $checkoutSession * @return bool */ public function isValid(\Magento\Checkout\Model\Session $checkoutSession) { if (!$checkoutSession->getLastSuccessQuoteId()) { return false; } if (!$checkoutSession->getLastQuoteId() || !$checkoutSession->getLastOrderId()) { return false; } return true; }
/** * Cancel order, return quote to customer * * @param string $errorMsg * @return false|string */ protected function _cancelPayment($errorMsg = '') { $gotoSection = false; $helper = $this->_objectManager->get('Magento\\Paypal\\Helper\\Checkout'); $helper->cancelCurrentOrder($errorMsg); if ($this->_session->restoreQuote()) { $gotoSection = 'paymentMethod'; } return $gotoSection; }
/** * Add recurring payment ids to session * * @return void */ public function addRecurringPaymentIdsToSession() { if ($this->_recurringPayments) { $ids = array(); foreach ($this->_recurringPayments as $payment) { $ids[] = $payment->getId(); } $this->_checkoutSession->setLastRecurringPaymentIds($ids); } }
/** * Dispatch request * * @return \Magento\Framework\Controller\ResultInterface * @throws Action\NotFoundException */ public function execute() { $quote = $this->checkoutSession->getQuote(); $address = $quote->getShippingAddress(); $address->collectShippingRates()->save(); $rates = $address->getGroupedAllShippingRates(); $result = $this->resultFactory->create(\Magento\Framework\Controller\ResultFactory::TYPE_JSON); $result->setData($rates); return $result; }