/** * @param \Magento\Checkout\Model\Type\Onepage $subject * @param array $result * @return $this */ public function afterSaveShippingMethod(\Magento\Checkout\Model\Type\Onepage $subject, array $result) { if (!$result) { $giftMessages = $this->request->getParam('giftmessage'); $quote = $subject->getQuote(); $this->message->add($giftMessages, $quote); } return $result; }
protected function setUp() { $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); $carrier = $this->getMock('Magento\\SampleShippingProvider\\Model\\Carrier', [], [], '', false); $carrier->expects($this->once())->method('getCarrierCode')->willReturn('storepickup'); $carrier->expects($this->any())->method('getLocationInfo')->willReturn($this->locationData); $this->shippingAddress = $this->getMock('Magento\\Quote\\Model\\Quote\\Address', ['getShippingMethod', 'setCountryId', 'setRegionId', 'setPostcode', 'setCity', 'setStreet', 'setTelephone'], [], '', false); $quote = $this->getMock('Magento\\Quote\\Model\\Quote', [], [], '', false); $quote->expects($this->once())->method('getShippingAddress')->willReturn($this->shippingAddress); $this->subject = $this->getMock('Magento\\Checkout\\Model\\Type\\Onepage', [], [], '', false); $this->subject->expects($this->once())->method('getQuote')->willReturn($quote); $this->model = $objectManager->getObject('Magento\\SampleShippingProvider\\Model\\Type\\Plugin\\Onepage', ['carrier' => $carrier]); }
/** * If card can be saved for further use * * @return boolean */ public function canSaveCard() { if ($this->config->useVault() && ($this->customerSession->isLoggedIn() || $this->onepage->getCheckoutMethod() == \Magento\Checkout\Model\Type\Onepage::METHOD_REGISTER)) { return true; } return false; }
/** * Test for execute method * * @return void */ public function testExecuteWithSuccessOrderSave() { $testData = $this->getExecuteWithSuccessOrderSaveTestData(); $redirectMock = $this->getMockBuilder('Magento\\Framework\\Controller\\Result\\Redirect')->disableOriginalConstructor()->getMock(); $paymentMock = $this->getMockBuilder('Magento\\Quote\\Model\\Quote\\Payment')->disableOriginalConstructor()->getMock(); $checkoutMock = $this->getMockBuilder('Magento\\Checkout\\Model\\Session')->disableOriginalConstructor()->setMethods(['getRedirectUrl'])->getMock(); $resultJsonMock = $this->getMockBuilder('Magento\\Framework\\Controller\\Result\\Json')->disableOriginalConstructor()->getMock(); $redirectMock->expects($this->never())->method('setPath')->with('*/*/')->willReturn('redirect'); $this->formKeyValidatorMock->expects($this->once())->method('validate')->with($this->requestMock)->willReturn(true); $this->resultRedirectFactoryMock->expects($this->never())->method('create')->willReturn($redirectMock); $this->objectManagerMock->expects($this->atLeastOnce())->method('get')->willReturnMap($testData['objectManager.get']); // call _expireAjax method $this->expireAjaxFlowHasItemsFalse(); $this->requestMock->expects($this->atLeastOnce())->method('getPost')->willReturnMap($testData['request.getPost']); $this->agreementsValidatorMock->expects($this->once())->method('isValid')->with($testData['agreementsValidator.isValid'])->willReturn(true); $this->quoteMock->expects($this->atLeastOnce())->method('getPayment')->willReturn($paymentMock); $paymentMock->expects($this->once())->method('setQuote')->with($this->quoteMock); $paymentMock->expects($this->once())->method('importData')->with($testData['payment.importData']); $this->onepageMock->expects($this->once())->method('saveOrder'); $this->onepageMock->expects($this->once())->method('getCheckout')->willReturn($checkoutMock); $checkoutMock->expects($this->once())->method('getRedirectUrl')->willReturn(null); $this->eventManagerMock->expects($this->once())->method('dispatch')->withConsecutive($this->equalTo('checkout_controller_onepage_saveOrder'), $this->countOf(2)); $this->resultJsonFactoryMock->expects($this->once())->method('create')->willReturn($resultJsonMock); $resultJsonMock->expects($this->once())->method('setData')->with($testData['resultJson.setData'])->willReturnSelf(); $this->assertEquals($resultJsonMock, $this->controller->execute()); }
/** * Check Captcha On Checkout as Guest Page * * @param \Magento\Framework\Event\Observer $observer * @return $this */ public function execute(\Magento\Framework\Event\Observer $observer) { $formId = 'guest_checkout'; $captchaModel = $this->_helper->getCaptcha($formId); $checkoutMethod = $this->_typeOnepage->getQuote()->getCheckoutMethod(); if ($checkoutMethod == \Magento\Checkout\Model\Type\Onepage::METHOD_GUEST) { if ($captchaModel->isRequired()) { $controller = $observer->getControllerAction(); if (!$captchaModel->isCorrect($this->captchaStringResolver->resolve($controller->getRequest(), $formId))) { $this->_actionFlag->set('', \Magento\Framework\App\Action\Action::FLAG_NO_DISPATCH, true); $result = ['error' => 1, 'message' => __('Incorrect CAPTCHA')]; $controller->getResponse()->representJson($this->jsonHelper->jsonEncode($result)); } } } return $this; }
/** * {@inheritdoc} */ public function saveShippingMethod($shippingMethod) { $pluginInfo = $this->pluginList->getNext($this->subjectType, 'saveShippingMethod'); if (!$pluginInfo) { return parent::saveShippingMethod($shippingMethod); } else { return $this->___callPlugins('saveShippingMethod', func_get_args(), $pluginInfo); } }
public function testGetLastOrderId() { $orderIncrementId = 100001; $orderId = 1; $this->checkoutSessionMock->expects($this->once())->method('getLastOrderId')->will($this->returnValue($orderId)); $orderMock = $this->getMock('Magento\\Sales\\Model\\Order', ['load', 'getIncrementId', '__wakeup'], [], '', false); $orderMock->expects($this->once())->method('load')->with($orderId)->will($this->returnSelf()); $orderMock->expects($this->once())->method('getIncrementId')->will($this->returnValue($orderIncrementId)); $this->orderFactoryMock->expects($this->once())->method('create')->will($this->returnValue($orderMock)); $this->assertEquals($orderIncrementId, $this->onepage->getLastOrderId()); }
/** * New address, customer address is invalid (customer validation should fail, not address validation). */ public function testSaveBillingInvalidCustomerData() { /** Preconditions */ $customerData = $this->_getCustomerData(); $customerData['email'] = 'invalidemail'; $this->_getQuote()->setCheckoutMethod(\Magento\Checkout\Model\Type\Onepage::METHOD_REGISTER); $customerAddressId = false; /** Execute SUT */ $result = $this->_model->saveBilling($customerData, $customerAddressId); $validationErrors = '"Email" is not a valid email address.'; $this->assertEquals(['error' => -1, 'message' => $validationErrors], $result, 'Validation error is invalid.'); }
/** * Replace shipping address with pickup location address * * @param CheckoutOnePage $subject * @param array $result * @return $this */ public function afterSaveShippingMethod(CheckoutOnePage $subject, array $result) { if ($result) { return $result; } $quote = $subject->getQuote(); $shippingAddress = $quote->getShippingAddress(); $shippingMethod = $shippingAddress->getShippingMethod(); /** * In-Store pickup selected * Update Shipping Address */ if (strpos($shippingMethod, $this->carrier->getCarrierCode()) !== false) { $locationAddress = $this->carrier->getLocationInfo($shippingMethod); $shippingAddress->setCountryId($locationAddress['country_id']); $shippingAddress->setRegionId($locationAddress['region_id']); $shippingAddress->setPostcode($locationAddress['postcode']); $shippingAddress->setCity($locationAddress['city']); $shippingAddress->setStreet($locationAddress['street']); $shippingAddress->setTelephone($locationAddress['phone']); } return $result; }
/** * Send request to authorize.net * * @return string */ public function execute() { $paymentParam = $this->getRequest()->getParam('payment'); $controller = $this->getRequest()->getParam('controller'); $response = $this->getResponse(); if (isset($paymentParam['method'])) { $this->_getDirectPostSession()->setQuoteId($this->_getCheckout()->getQuote()->getId()); /** * Current workaround depends on Onepage checkout model defect * Method Onepage::getCheckoutMethod performs setCheckoutMethod */ $this->onepageCheckout->getCheckoutMethod(); if ($controller == IframeConfigProvider::CHECKOUT_IDENTIFIER) { return $this->placeCheckoutOrder(); } $params = $this->dataFactory->create(DataFactory::AREA_FRONTEND)->getSaveOrderUrlParams($controller); $this->_forward($params['action'], $params['controller'], $params['module'], $this->getRequest()->getParams()); } else { $result = ['error_messages' => __('Please choose a payment method.'), 'goto_section' => 'payment']; if ($response instanceof Http) { $response->representJson($this->jsonHelper->jsonEncode($result)); } } }
/** * Check Captcha On Checkout Register Page * * @param \Magento\Framework\Event\Observer $observer * @return $this */ public function checkRegisterCheckout($observer) { $formId = 'register_during_checkout'; $captchaModel = $this->_helper->getCaptcha($formId); $checkoutMethod = $this->_typeOnepage->getQuote()->getCheckoutMethod(); if ($checkoutMethod == \Magento\Checkout\Model\Type\Onepage::METHOD_REGISTER) { if ($captchaModel->isRequired()) { $controller = $observer->getControllerAction(); if (!$captchaModel->isCorrect($this->_getCaptchaString($controller->getRequest(), $formId))) { $this->_actionFlag->set('', \Magento\Framework\App\Action\Action::FLAG_NO_DISPATCH, true); $result = array('error' => 1, 'message' => __('Incorrect CAPTCHA')); $controller->getResponse()->representJson($this->_coreData->jsonEncode($result)); } } } return $this; }
/** * {@inheritdoc} */ public function getLastOrderId() { $pluginInfo = $this->pluginList->getNext($this->subjectType, 'getLastOrderId'); if (!$pluginInfo) { return parent::getLastOrderId(); } else { return $this->___callPlugins('getLastOrderId', func_get_args(), $pluginInfo); } }
/** * Set method info * * @return $this */ public function setMethodInfo() { $payment = $this->_checkoutModel->getQuote()->getPayment(); $this->setMethod($payment->getMethodInstance()); return $this; }