Exemplo n.º 1
0
 /**
  * New customer, billing address should not be used as shipping address, it should be persisted to DB.
  *
  * @magentoAppIsolation enabled
  * @magentoDbIsolation enabled
  */
 public function testSaveBilling()
 {
     $quote = $this->_model->getQuote();
     /** Preconditions */
     $customerData = $this->_getCustomerData();
     $customerData['use_for_shipping'] = 0;
     $customerAddressId = false;
     $this->assertEquals(1, $customerData['save_in_address_book'], "Precondition failed: save_in_address_book is invalid");
     $this->assertEmpty($quote->getBillingAddress()->getId(), "Precondition failed: billing address must not be initialized.");
     $this->assertEmpty($quote->getShippingAddress()->getId(), "Precondition failed: billing address must not be initialized.");
     /** Execute SUT */
     $result = $this->_model->saveBilling($customerData, $customerAddressId);
     $this->assertEquals([], $result, 'Return value is invalid');
     /** Ensure that quote addresses were persisted correctly */
     $billingAddress = $quote->getBillingAddress();
     $shippingAddress = $quote->getShippingAddress();
     $quoteAddressFieldsToCheck = ['quote_id' => $quote->getId(), 'firstname' => 'John', 'lastname' => 'Smith', 'email' => '*****@*****.**', 'street' => '6131 Monterey Rd, Apt 1', 'city' => 'Los Angeles', 'postcode' => '90042', 'country_id' => 'US', 'region_id' => '1', 'region' => 'Alabama', 'telephone' => '(323) 255-5861', 'customer_id' => null, 'customer_address_id' => null];
     foreach ($quoteAddressFieldsToCheck as $field => $value) {
         $this->assertEquals($value, $billingAddress->getData($field), "{$field} value is invalid");
     }
     $this->assertGreaterThan(0, $billingAddress->getData('address_id'), "address_id value is invalid");
     $this->assertEmpty($shippingAddress->getData('firstname'), "Shipping address should not be populated with billing address data when 'same_as_billing' is set to 0.");
     $this->assertEquals(1, $billingAddress->getData('save_in_address_book'), "save_in_address_book value is invalid");
     /** Ensure that customer-related data was ported to quote correctly */
     $quoteFieldsToCheck = ['customer_firstname' => 'John', 'customer_lastname' => 'Smith', 'customer_email' => '*****@*****.**'];
     foreach ($quoteFieldsToCheck as $field => $value) {
         $this->assertEquals($value, $quote->getData($field), "{$field} value is set to quote incorrectly.");
     }
     /** Perform if checkout steps status was correctly updated in session */
     /** @var \Magento\Checkout\Model\Session $checkoutSession */
     $checkoutSession = Bootstrap::getObjectManager()->get('Magento\\Checkout\\Model\\Session');
     $this->assertTrue($checkoutSession->getStepData('billing', 'allow'), 'Billing step should be allowed.');
     $this->assertTrue($checkoutSession->getStepData('billing', 'complete'), 'Billing step should be completed.');
     $this->assertTrue($checkoutSession->getStepData('shipping', 'allow'), 'Shipping step should be allowed.');
 }
Exemplo n.º 2
0
 public function testSetQuote()
 {
     /** @var \Magento\Quote\Model\Quote $quoteMock */
     $quoteMock = $this->getMock('Magento\\Quote\\Model\\Quote', [], [], '', false);
     $this->onepage->setQuote($quoteMock);
     $this->assertEquals($quoteMock, $this->onepage->getQuote());
 }
 /**
  * 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;
 }
Exemplo n.º 4
0
 /**
  * @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;
 }
Exemplo n.º 5
0
 /**
  * {@inheritdoc}
  */
 public function getQuote()
 {
     $pluginInfo = $this->pluginList->getNext($this->subjectType, 'getQuote');
     if (!$pluginInfo) {
         return parent::getQuote();
     } else {
         return $this->___callPlugins('getQuote', func_get_args(), $pluginInfo);
     }
 }
Exemplo n.º 6
0
 /**
  * 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;
 }
Exemplo n.º 7
0
 /**
  * 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;
 }
Exemplo n.º 8
0
 /**
  * Set quote and payment
  * 
  * @return $this
  */
 public function setMethodInfo()
 {
     $payment = $this->onepage->getQuote()->getPayment();
     $this->setMethod($payment->getMethodInstance());
     return $this;
 }
Exemplo n.º 9
0
 /**
  * Set method info
  *
  * @return $this
  */
 public function setMethodInfo()
 {
     $payment = $this->_checkoutModel->getQuote()->getPayment();
     $this->setMethod($payment->getMethodInstance());
     return $this;
 }