From 186a3c5482967531ccc1c7190af9b9cb8ea401f4 Mon Sep 17 00:00:00 2001 From: Andrey Konosov Date: Tue, 6 Oct 2015 16:32:25 +0300 Subject: [PATCH 01/10] MAGETWO-43241: Simplified edition checks in setup script --- lib/internal/Magento/Framework/Composer/ComposerInformation.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/internal/Magento/Framework/Composer/ComposerInformation.php b/lib/internal/Magento/Framework/Composer/ComposerInformation.php index 2b216df65c187..c3af874e3ac3b 100755 --- a/lib/internal/Magento/Framework/Composer/ComposerInformation.php +++ b/lib/internal/Magento/Framework/Composer/ComposerInformation.php @@ -252,7 +252,7 @@ private function isMagentoRoot() { $rootPackage = $this->composer->getPackage(); - return preg_match('/magento\/magento2.e/', $rootPackage->getName()); + return preg_match('/magento\/magento2...?/', $rootPackage->getName()); } /** From 4ae42e433fb19259b2c10030bc2e2b0cc428f4aa Mon Sep 17 00:00:00 2001 From: Ievgen Sentiabov Date: Mon, 2 Nov 2015 17:18:10 +0200 Subject: [PATCH 02/10] MAGETWO-44812: Customer address is duplicated after placing order within PayPal Express Checkout - Removed unnecessary code from Paypal Express and Braintree - Updated unit tests - Fixed billing address setting in checkout --- .../Controller/PayPal/PlaceOrder.php | 88 ----- .../Unit/Controller/PayPal/PlaceOrderTest.php | 239 -------------- .../web/js/action/select-billing-address.js | 6 +- .../model/shipping-save-processor/default.js | 9 +- .../Magento/Paypal/Model/Express/Checkout.php | 107 ++---- .../Paypal/Model/Express/Checkout/Quote.php | 154 --------- .../Unit/Model/Express/Checkout/QuoteTest.php | 304 ------------------ .../Paypal/Model/Express/CheckoutTest.php | 55 ---- 8 files changed, 34 insertions(+), 928 deletions(-) delete mode 100644 app/code/Magento/Braintree/Controller/PayPal/PlaceOrder.php delete mode 100644 app/code/Magento/Braintree/Test/Unit/Controller/PayPal/PlaceOrderTest.php delete mode 100644 app/code/Magento/Paypal/Model/Express/Checkout/Quote.php delete mode 100644 app/code/Magento/Paypal/Test/Unit/Model/Express/Checkout/QuoteTest.php diff --git a/app/code/Magento/Braintree/Controller/PayPal/PlaceOrder.php b/app/code/Magento/Braintree/Controller/PayPal/PlaceOrder.php deleted file mode 100644 index febdcf06fed58..0000000000000 --- a/app/code/Magento/Braintree/Controller/PayPal/PlaceOrder.php +++ /dev/null @@ -1,88 +0,0 @@ -agreementsValidator = $agreementsValidator; - parent::__construct( - $context, - $customerSession, - $checkoutSession, - $braintreePayPalConfig, - $paypalConfig, - $checkoutFactory - ); - } - - /** - * Submit the order - * - * @return \Magento\Framework\Controller\Result\Redirect - */ - public function executeInternal() - { - try { - if (!$this->agreementsValidator->isValid(array_keys($this->getRequest()->getPost('agreement', [])))) { - throw new \Magento\Framework\Exception\LocalizedException( - __('Please agree to all the terms and conditions before placing the order.') - ); - } - $this->initCheckout(); - $this->getCheckout()->place(null); - - // prepare session to success or cancellation page - $this->checkoutSession->clearHelperData(); - - // "last successful quote" - $quoteId = $this->getQuote()->getId(); - $this->checkoutSession->setLastQuoteId($quoteId)->setLastSuccessQuoteId($quoteId); - - // an order may be created - $order = $this->getCheckout()->getOrder(); - if ($order) { - $this->checkoutSession->setLastOrderId($order->getId()) - ->setLastRealOrderId($order->getIncrementId()); - } - - /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */ - $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); - return $resultRedirect->setPath('checkout/onepage/success'); - } catch (\Magento\Framework\Exception\LocalizedException $e) { - $this->messageManager->addExceptionMessage($e, $e->getMessage()); - } catch (\Exception $e) { - $this->messageManager->addExceptionMessage($e, __('We can\'t place the order.')); - } - /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */ - $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); - return $resultRedirect->setPath('checkout/cart'); - } -} diff --git a/app/code/Magento/Braintree/Test/Unit/Controller/PayPal/PlaceOrderTest.php b/app/code/Magento/Braintree/Test/Unit/Controller/PayPal/PlaceOrderTest.php deleted file mode 100644 index 1d4fb2a241b78..0000000000000 --- a/app/code/Magento/Braintree/Test/Unit/Controller/PayPal/PlaceOrderTest.php +++ /dev/null @@ -1,239 +0,0 @@ -checkoutSessionMock = $this->getMockBuilder('\Magento\Checkout\Model\Session') - ->disableOriginalConstructor() - ->setMethods( - [ - 'clearHelperData', - 'getQuote', - 'setLastQuoteId', - 'setLastSuccessQuoteId', - 'setLastOrderId', - 'setLastRealOrderId', - ] - ) - ->getMock(); - - $this->checkoutFactoryMock = $this->getMockBuilder('\Magento\Braintree\Model\CheckoutFactory') - ->disableOriginalConstructor() - ->setMethods(['create']) - ->getMock(); - - $this->messageManager = $this->getMock('\Magento\Framework\Message\ManagerInterface'); - - $this->checkoutMock = $this->getMockBuilder('\Magento\Braintree\Model\Checkout') - ->disableOriginalConstructor() - ->getMock(); - - $this->requestMock = $this->getMock('\Magento\Framework\App\Request\Http', [], [], '', '', false); - - $this->resultFactoryMock = $this->getMockBuilder('\Magento\Framework\Controller\ResultFactory') - ->disableOriginalConstructor() - ->getMock(); - - $contextMock = $this->getMockBuilder('\Magento\Framework\App\Action\Context') - ->disableOriginalConstructor() - ->getMock(); - $contextMock->expects($this->any()) - ->method('getResultFactory') - ->willReturn($this->resultFactoryMock); - $contextMock->expects($this->any()) - ->method('getRequest') - ->willReturn($this->requestMock); - $contextMock->expects($this->any()) - ->method('getMessageManager') - ->willReturn($this->messageManager); - $this->objectManagerHelper = new ObjectManagerHelper($this); - $this->validatorMock = $this->getMock('Magento\Checkout\Api\AgreementsValidatorInterface'); - $this->controller = $this->objectManagerHelper->getObject( - '\Magento\Braintree\Controller\PayPal\PlaceOrder', - [ - 'context' => $contextMock, - 'checkoutSession' => $this->checkoutSessionMock, - 'checkoutFactory' => $this->checkoutFactoryMock, - 'agreementsValidator' => $this->validatorMock - ] - ); - } - - protected function setupCart() - { - $quoteMock = $this->getMockBuilder('\Magento\Quote\Model\Quote') - ->disableOriginalConstructor() - ->setMethods(['hasItems', 'getHasError', 'getPayment', 'getId']) - ->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); - - $this->requestMock->expects($this->any())->method('getPost')->willReturn([]); - return $quoteMock; - } - - public function testExecute() - { - $quoteId = 123; - $orderId = 'orderId'; - $orderIncrementId = 125; - - $quoteMock = $this->setupCart(); - $this->validatorMock->expects($this->once())->method('isValid')->willReturn(true); - $this->checkoutMock->expects($this->once()) - ->method('place') - ->with(null); - - $this->checkoutSessionMock->expects($this->once()) - ->method('clearHelperData'); - - $quoteMock->expects($this->once()) - ->method('getId') - ->willReturn($quoteId); - - $this->checkoutSessionMock->expects($this->once()) - ->method('setLastQuoteId') - ->with($quoteId) - ->willReturnSelf(); - $this->checkoutSessionMock->expects($this->once()) - ->method('setLastSuccessQuoteId') - ->with($quoteId) - ->willReturnSelf(); - - $orderMock = $this->getMockBuilder('\Magento\Sales\Model\Order') - ->disableOriginalConstructor() - ->getMock(); - $orderMock->expects($this->once()) - ->method('getId') - ->willReturn($orderId); - $orderMock->expects($this->once()) - ->method('getIncrementId') - ->willReturn($orderIncrementId); - - $this->checkoutMock->expects($this->once()) - ->method('getOrder') - ->willReturn($orderMock); - - $this->checkoutSessionMock->expects($this->once()) - ->method('setLastOrderId') - ->with($orderId) - ->willReturnSelf(); - $this->checkoutSessionMock->expects($this->once()) - ->method('setLastRealOrderId') - ->with($orderIncrementId) - ->willReturnSelf(); - - $resultRedirect = $this->getMockBuilder('\Magento\Framework\Controller\Result\Redirect') - ->disableOriginalConstructor() - ->getMock(); - $resultRedirect->expects($this->once()) - ->method('setPath') - ->with('checkout/onepage/success') - ->willReturnSelf(); - $this->resultFactoryMock->expects($this->once()) - ->method('create') - ->with(\Magento\Framework\Controller\ResultFactory::TYPE_REDIRECT) - ->willReturn($resultRedirect); - - $this->assertEquals($resultRedirect, $this->controller->executeInternal()); - } - - public function testExecuteException() - { - $this->setupCart(); - $this->validatorMock->expects($this->once())->method('isValid')->willReturn(true); - $exceptionMsg = new \Magento\Framework\Phrase('error'); - $exception = new \Magento\Framework\Exception\LocalizedException($exceptionMsg); - $this->checkoutMock->expects($this->once()) - ->method('place') - ->with(null) - ->willThrowException($exception); - - $this->messageManager->expects($this->once()) - ->method('addExceptionMessage') - ->with($exception, $exceptionMsg); - - $resultRedirect = $this->getMockBuilder('\Magento\Framework\Controller\Result\Redirect') - ->disableOriginalConstructor() - ->getMock(); - $resultRedirect->expects($this->once()) - ->method('setPath') - ->with('checkout/cart') - ->willReturnSelf(); - $this->resultFactoryMock->expects($this->once()) - ->method('create') - ->with(\Magento\Framework\Controller\ResultFactory::TYPE_REDIRECT) - ->willReturn($resultRedirect); - - $this->assertEquals($resultRedirect, $this->controller->executeInternal()); - } -} diff --git a/app/code/Magento/Checkout/view/frontend/web/js/action/select-billing-address.js b/app/code/Magento/Checkout/view/frontend/web/js/action/select-billing-address.js index 6fc4671f8826b..6431d8c8180bf 100644 --- a/app/code/Magento/Checkout/view/frontend/web/js/action/select-billing-address.js +++ b/app/code/Magento/Checkout/view/frontend/web/js/action/select-billing-address.js @@ -14,7 +14,11 @@ define( var address = null; if (quote.shippingAddress() && billingAddress.getCacheKey() == quote.shippingAddress().getCacheKey()) { address = $.extend({}, billingAddress); - address.save_in_address_book = false; + address.saveInAddressBook = false; + if (quote.shippingAddress().saveInAddressBook) { + address.saveInAddressBook = true; + quote.shippingAddress().saveInAddressBook = false; + } } else { address = billingAddress; } diff --git a/app/code/Magento/Checkout/view/frontend/web/js/model/shipping-save-processor/default.js b/app/code/Magento/Checkout/view/frontend/web/js/model/shipping-save-processor/default.js index d4f4be06dc735..b6958ed3061d4 100644 --- a/app/code/Magento/Checkout/view/frontend/web/js/model/shipping-save-processor/default.js +++ b/app/code/Magento/Checkout/view/frontend/web/js/model/shipping-save-processor/default.js @@ -6,6 +6,7 @@ define( [ 'ko', + 'jquery', 'Magento_Checkout/js/model/quote', 'Magento_Checkout/js/model/resource-url-manager', 'mage/storage', @@ -16,6 +17,7 @@ define( ], function ( ko, + $, quote, resourceUrlManager, storage, @@ -27,7 +29,12 @@ define( 'use strict'; return { saveShippingInformation: function() { - var billingAddress = quote.billingAddress() || quote.shippingAddress(); + var billingAddress = quote.billingAddress(); + if (!billingAddress) { + billingAddress = $.extend(quote.billingAddress(), quote.shippingAddress()); + quote.billingAddress(billingAddress); + quote.shippingAddress().sameAsBilling = 1; + } var payload = { addressInformation: { shipping_address: quote.shippingAddress(), diff --git a/app/code/Magento/Paypal/Model/Express/Checkout.php b/app/code/Magento/Paypal/Model/Express/Checkout.php index 2df901f5ce519..199425007eba3 100644 --- a/app/code/Magento/Paypal/Model/Express/Checkout.php +++ b/app/code/Magento/Paypal/Model/Express/Checkout.php @@ -8,7 +8,6 @@ use Magento\Customer\Api\Data\CustomerInterface as CustomerDataObject; use Magento\Customer\Model\AccountManagement; use Magento\Paypal\Model\Config as PaypalConfig; -use Magento\Paypal\Model\Express\Checkout\Quote as PaypalQuote; use Magento\Sales\Model\Order\Email\Sender\OrderSender; use Magento\Quote\Model\Quote\Address; use Magento\Framework\DataObject; @@ -254,11 +253,6 @@ class Checkout */ protected $orderSender; - /** - * @var PaypalQuote - */ - protected $paypalQuote; - /** * @var \Magento\Quote\Api\CartRepositoryInterface */ @@ -296,7 +290,6 @@ class Checkout * @param \Magento\Framework\Message\ManagerInterface $messageManager * @param \Magento\Customer\Api\CustomerRepositoryInterface $customerRepository * @param AccountManagement $accountManagement - * @param PaypalQuote $paypalQuote * @param OrderSender $orderSender * @param \Magento\Quote\Api\CartRepositoryInterface $quoteRepository * @param \Magento\Quote\Model\Quote\TotalsCollector $totalsCollector @@ -326,7 +319,6 @@ public function __construct( \Magento\Framework\Message\ManagerInterface $messageManager, \Magento\Customer\Api\CustomerRepositoryInterface $customerRepository, AccountManagement $accountManagement, - PaypalQuote $paypalQuote, OrderSender $orderSender, \Magento\Quote\Api\CartRepositoryInterface $quoteRepository, \Magento\Quote\Model\Quote\TotalsCollector $totalsCollector, @@ -353,7 +345,6 @@ public function __construct( $this->_messageManager = $messageManager; $this->orderSender = $orderSender; $this->_accountManagement = $accountManagement; - $this->paypalQuote = $paypalQuote; $this->quoteRepository = $quoteRepository; $this->totalsCollector = $totalsCollector; $this->_customerSession = isset($params['session']) @@ -620,7 +611,7 @@ public function returnFromPaypal($token) ->callGetExpressCheckoutDetails(); $quote = $this->_quote; - $this->_ignoreAddressValidation(); + $this->ignoreAddressValidation(); // import shipping address $exportedShippingAddress = $this->_api->getExportedShippingAddress(); @@ -708,7 +699,7 @@ public function prepareOrderReview($token = null) $this->_quote->setMayEditShippingMethod( '' == $this->_quote->getPayment()->getAdditionalInformation(self::PAYMENT_INFO_TRANSPORT_SHIPPING_METHOD) ); - $this->_ignoreAddressValidation(); + $this->ignoreAddressValidation(); $this->_quote->collectTotals(); $this->quoteRepository->save($this->_quote); } @@ -763,7 +754,7 @@ public function updateShippingMethod($methodCode) $shippingAddress = $this->_quote->getShippingAddress(); if (!$this->_quote->getIsVirtual() && $shippingAddress) { if ($methodCode != $shippingAddress->getShippingMethod()) { - $this->_ignoreAddressValidation(); + $this->ignoreAddressValidation(); $shippingAddress->setShippingMethod($methodCode)->setCollectShippingRates(true); $this->_quote->collectTotals(); $this->quoteRepository->save($this->_quote); @@ -786,31 +777,16 @@ public function place($token, $shippingMethodCode = null) $this->updateShippingMethod($shippingMethodCode); } - $isNewCustomer = false; switch ($this->getCheckoutMethod()) { case \Magento\Checkout\Model\Type\Onepage::METHOD_GUEST: - $this->_prepareGuestQuote(); - break; - case \Magento\Checkout\Model\Type\Onepage::METHOD_REGISTER: - $this->_prepareNewCustomerQuote(); - $isNewCustomer = true; - break; - default: - $this->_prepareCustomerQuote(); + $this->prepareGuestQuote(); break; } - $this->_ignoreAddressValidation(); + $this->ignoreAddressValidation(); $this->_quote->collectTotals(); $order = $this->quoteManagement->submit($this->_quote); - if ($isNewCustomer) { - try { - $this->_involveNewCustomer(); - } catch (\Exception $e) { - $this->_logger->critical($e); - } - } if (!$order) { return; } @@ -843,7 +819,7 @@ public function place($token, $shippingMethodCode = null) * * @return void */ - private function _ignoreAddressValidation() + private function ignoreAddressValidation() { $this->_quote->getBillingAddress()->setShouldIgnoreValidation(true); if (!$this->_quote->getIsVirtual()) { @@ -1109,62 +1085,6 @@ protected function _matchShippingMethodCode(Address $address, $selectedCode) return ''; } - /** - * Prepare quote for guest checkout order submit - * - * @return $this - */ - protected function _prepareGuestQuote() - { - $quote = $this->_quote; - $quote->setCustomerId(null) - ->setCustomerEmail($quote->getBillingAddress()->getEmail()) - ->setCustomerIsGuest(true) - ->setCustomerGroupId(\Magento\Customer\Model\Group::NOT_LOGGED_IN_ID); - return $this; - } - - /** - * Prepare quote for customer registration and customer order submit - * and restore magento customer data from quote - * - * @return void - */ - protected function _prepareNewCustomerQuote() - { - $this->paypalQuote->prepareQuoteForNewCustomer($this->_quote); - } - - /** - * Prepare quote for customer order submit - * - * @return void - */ - protected function _prepareCustomerQuote() - { - $this->paypalQuote->prepareRegisteredCustomerQuote($this->_quote, $this->_customerSession->getCustomerId()); - } - - /** - * Involve new customer to system - * - * @return $this - */ - protected function _involveNewCustomer() - { - $customer = $this->_quote->getCustomer(); - $confirmationStatus = $this->_accountManagement->getConfirmationStatus($customer->getId()); - if ($confirmationStatus === AccountManagement::ACCOUNT_CONFIRMATION_REQUIRED) { - $this->_messageManager->addSuccess( - __('Thank you for registering with Main Website Store.') - ); - } else { - $this->getCustomerSession()->regenerateId(); - $this->getCustomerSession()->loginById($customer->getId()); - } - return $this; - } - /** * Create payment redirect url * @param bool|null $button @@ -1218,4 +1138,19 @@ private function setShippingOptions(PaypalCart $cart, Address $address = null) } } } + + /** + * Prepare quote for guest checkout order submit + * + * @return $this + */ + protected function prepareGuestQuote() + { + $quote = $this->_quote; + $quote->setCustomerId(null) + ->setCustomerEmail($quote->getBillingAddress()->getEmail()) + ->setCustomerIsGuest(true) + ->setCustomerGroupId(\Magento\Customer\Model\Group::NOT_LOGGED_IN_ID); + return $this; + } } diff --git a/app/code/Magento/Paypal/Model/Express/Checkout/Quote.php b/app/code/Magento/Paypal/Model/Express/Checkout/Quote.php deleted file mode 100644 index 8dde08a65528a..0000000000000 --- a/app/code/Magento/Paypal/Model/Express/Checkout/Quote.php +++ /dev/null @@ -1,154 +0,0 @@ -addressFactory = $addressFactory; - $this->customerFactory = $customerFactory; - $this->customerRepository = $customerRepository; - $this->copyObject = $copyObject; - $this->dataObjectHelper = $dataObjectHelper; - } - - /** - * @param \Magento\Quote\Model\Quote $quote - * @return \Magento\Quote\Model\Quote - */ - public function prepareQuoteForNewCustomer(\Magento\Quote\Model\Quote $quote) - { - $billing = $quote->getBillingAddress(); - $shipping = $quote->isVirtual() ? null : $quote->getShippingAddress(); - $billing->setDefaultBilling(true); - if ($shipping && !$shipping->getSameAsBilling()) { - $shipping->setDefaultShipping(true); - $address = $shipping->exportCustomerAddress(); - $shipping->setCustomerAddressData($address); - } elseif ($shipping) { - $billing->setDefaultShipping(true); - } - $address = $shipping->exportCustomerAddress(); - $billing->setCustomerAddressData($address); - foreach (['customer_dob', 'customer_taxvat', 'customer_gender'] as $attribute) { - if ($quote->getData($attribute) && !$billing->getData($attribute)) { - $billing->setData($attribute, $quote->getData($attribute)); - } - } - $customer = $this->customerFactory->create(); - $this->dataObjectHelper->populateWithArray( - $customer, - $this->copyObject->getDataFromFieldset( - 'checkout_onepage_billing', - 'to_customer', - $billing - ), - '\Magento\Customer\Api\Data\CustomerInterface' - ); - $customer->setEmail($quote->getCustomerEmail()); - $customer->setPrefix($quote->getCustomerPrefix()); - $customer->setFirstname($quote->getCustomerFirstname()); - $customer->setMiddlename($quote->getCustomerMiddlename()); - $customer->setLastname($quote->getCustomerLastname()); - $customer->setSuffix($quote->getCustomerSuffix()); - $quote->setCustomer($customer); - $quote->addCustomerAddress($billing->exportCustomerAddress()); - if ($shipping->hasCustomerAddress()) { - $quote->addCustomerAddress($shipping->exportCustomerAddress()); - } - return $quote; - } - - /** - * @param \Magento\Quote\Model\Quote $quote - * @param int|null $customerId - * @return \Magento\Quote\Model\Quote - * @SuppressWarnings(PHPMD.CyclomaticComplexity) - * @SuppressWarnings(PHPMD.NPathComplexity) - */ - public function prepareRegisteredCustomerQuote(\Magento\Quote\Model\Quote $quote, $customerId) - { - $billing = $quote->getBillingAddress(); - $shipping = $quote->isVirtual() ? null : $quote->getShippingAddress(); - $customer = $this->customerRepository->getById($customerId); - - $isBillingAddressDefaultBilling = !$customer->getDefaultBilling(); - $isBillingAddressDefaultShipping = false; - - $isShippingAddressDefaultShipping = false; - - if ($shipping && !$customer->getDefaultShipping()) { - $isShippingAddressDefaultShipping = true; - } elseif (!$customer->getDefaultShipping()) { - $isBillingAddressDefaultShipping = true; - } - - if ($shipping && $shipping->getTelephone() && !$shipping->getSameAsBilling() - && (!$shipping->getCustomerId() || $shipping->getSaveInAddressBook() || !$customer->getDefaultShipping()) - ) { - $address = $shipping->exportCustomerAddress(); - $address->setIsDefaultShipping($isShippingAddressDefaultShipping); - $quote->addCustomerAddress($address); - } - - if ($billing && $billing->getTelephone() - && (!$customer->getDefaultBilling() || $billing->getSaveInAddressBook()) - ) { - $address = $billing->exportCustomerAddress(); - $address->setIsDefaultBilling($isBillingAddressDefaultBilling); - $address->setIsDefaultShipping($isBillingAddressDefaultShipping); - $quote->addCustomerAddress($address); - } - - return $quote; - } -} diff --git a/app/code/Magento/Paypal/Test/Unit/Model/Express/Checkout/QuoteTest.php b/app/code/Magento/Paypal/Test/Unit/Model/Express/Checkout/QuoteTest.php deleted file mode 100644 index b51b1061e05b5..0000000000000 --- a/app/code/Magento/Paypal/Test/Unit/Model/Express/Checkout/QuoteTest.php +++ /dev/null @@ -1,304 +0,0 @@ -addressFactoryMock = $this->getMock( - 'Magento\Customer\Api\Data\AddressInterfaceFactory', - ['create'], - [], - '', - false - ); - $this->copyObjectMock = $this->getMock( - 'Magento\Framework\DataObject\Copy', - [], - [], - '', - false - ); - $this->customerFactoryMock = $this->getMock( - 'Magento\Customer\Api\Data\CustomerInterfaceFactory', - ['create'], - [], - '', - false - ); - $this->customerRepositoryMock = $this->getMockForAbstractClass( - 'Magento\Customer\Api\CustomerRepositoryInterface', - ['getById'], - '', - false, - true, - true, - [] - ); - $this->quoteMock = $this->getMock( - 'Magento\Quote\Model\Quote', - [], - [], - '', - false - ); - $this->addressMock = $this->getMock('Magento\Quote\Model\Quote\Address', [], [], '', false); - $this->dataObjectHelper = $this->getMock( - 'Magento\Framework\Api\DataObjectHelper', - ['populateWithArray'], - [], - '', - false - ); - - $this->quote = new \Magento\Paypal\Model\Express\Checkout\Quote( - $this->addressFactoryMock, - $this->customerFactoryMock, - $this->customerRepositoryMock, - $this->copyObjectMock, - $this->dataObjectHelper - ); - } - - public function testPrepareQuoteForNewCustomer() - { - $customerAddressMock = $this->getMockBuilder('Magento\Customer\Api\Data\AddressInterface') - ->disableOriginalConstructor() - ->getMock(); - $this->addressMock->expects($this->any()) - ->method('exportCustomerAddress') - ->willReturn($customerAddressMock); - $this->addressMock->expects($this->any()) - ->method('getData') - ->willReturn([]); - $this->addressFactoryMock->expects($this->any()) - ->method('create') - ->willReturn($this->addressMock); - - $this->quoteMock->expects($this->any()) - ->method('isVirtual') - ->willReturn(false); - $this->quoteMock->expects($this->once()) - ->method('getBillingAddress') - ->willReturn($this->addressMock); - $this->quoteMock->expects($this->once()) - ->method('getShippingAddress') - ->willReturn($this->addressMock); - - $customerDataMock = $this->getMockBuilder('Magento\Customer\Api\Data\CustomerInterface') - ->disableOriginalConstructor() - ->getMock(); - $this->customerFactoryMock->expects($this->once()) - ->method('create') - ->willReturn($customerDataMock); - - $this->copyObjectMock->expects($this->any()) - ->method('getDataFromFieldset') - ->willReturn([]); - - $this->dataObjectHelper->expects($this->any()) - ->method('populateWithArray') - ->willReturnSelf(); - - $this->assertInstanceOf( - 'Magento\Quote\Model\Quote', - $this->quote->prepareQuoteForNewCustomer($this->quoteMock) - ); - } - - /** - * @param $conditions - * @param $exportShippingCustomerAddressCalls - * @param $exportBillingCustomerAddressCalls - * @dataProvider prepareRegisteredCustomerQuoteDataProvider - */ - public function testPrepareRegisteredCustomerQuote($conditions, $exportBillingCustomerAddressCalls, - $exportShippingCustomerAddressCalls) - { - $customerDataMock = $this->getMockBuilder('Magento\Customer\Model\Customer') - ->setMethods(['getDefaultShipping', 'getDefaultBilling']) - ->disableOriginalConstructor() - ->getMock(); - $customerDataMock->expects($this->any()) - ->method('getDefaultBilling') - ->willReturn($conditions['isDefaultBilling']); - $customerDataMock->expects($this->any()) - ->method('getDefaultShipping') - ->willReturn($conditions['isDefaultShipping']); - - $this->customerRepositoryMock->expects($this->once()) - ->method('getById') - ->willReturn($customerDataMock); - - $customerAddressMock = $this->getMockBuilder('Magento\Customer\Api\Data\AddressInterface') - ->disableOriginalConstructor() - ->getMock(); - - $shippingAddressMock = $this->getMockBuilder('Magento\Quote\Model\Quote\Address') - ->setMethods(['getTelephone', 'getSameAsBilling', 'getCustomerId', 'getSaveInAddressBook', 'exportCustomerAddress']) - ->disableOriginalConstructor() - ->getMock(); - $shippingAddressMock->expects($this->any()) - ->method('getTelephone') - ->willReturn($conditions['isTelephone']); - $shippingAddressMock->expects($this->any()) - ->method('getSameAsBilling') - ->willReturn($conditions['isShippingSameAsBilling']); - $shippingAddressMock->expects($this->any()) - ->method('getCustomerId') - ->willReturn(true); - $shippingAddressMock->expects($this->any()) - ->method('getSaveInAddressBook') - ->willReturn($conditions['isShippingSaveInAddressBook']); - $shippingAddressMock->expects($this->exactly($exportShippingCustomerAddressCalls)) - ->method('exportCustomerAddress') - ->willReturn($customerAddressMock); - - $billingAddressMock = $this->getMockBuilder('Magento\Quote\Model\Quote\Address') - ->setMethods(['getTelephone', 'getCustomerId', 'getSaveInAddressBook', 'exportCustomerAddress']) - ->disableOriginalConstructor() - ->getMock(); - $billingAddressMock->expects($this->any()) - ->method('getTelephone') - ->willReturn($conditions['isTelephone']); - $billingAddressMock->expects($this->any()) - ->method('getCustomerId') - ->willReturn(true); - $billingAddressMock->expects($this->any()) - ->method('getSaveInAddressBook') - ->willReturn($conditions['isBillingSaveInAddressBook']); - $billingAddressMock->expects($this->exactly($exportBillingCustomerAddressCalls)) - ->method('exportCustomerAddress') - ->willReturn($customerAddressMock); - - $this->quoteMock->expects($this->any()) - ->method('isVirtual') - ->willReturn(false); - $this->quoteMock->expects($this->once()) - ->method('getBillingAddress') - ->willReturn($billingAddressMock); - $this->quoteMock->expects($this->once()) - ->method('getShippingAddress') - ->willReturn($shippingAddressMock); - - $this->assertInstanceOf( - 'Magento\Quote\Model\Quote', - $this->quote->prepareRegisteredCustomerQuote($this->quoteMock, 1) - ); - } - - /** - * Check if shipping and billing addresses adds or not adds to customer address book by different conditions - * - * @case 1 POSITIVE saveInAddressBook for billing and shipping checked, shippingSameAsBilling false - * @case 2 POSITIVE shippingSameAsBilling true - * @case 3 POSITIVE customer haven't default shipping and billing addresses - * @case 4 POSITIVE customer address haven't phone number (from Paypal) - not saving addresses - * - * @return array - */ - public function prepareRegisteredCustomerQuoteDataProvider() - { - return [ - [ - 'conditions' => [ - 'isTelephone' => true, - 'isShippingSameAsBilling' => false, - 'isShippingSaveInAddressBook' => true, - 'isBillingSaveInAddressBook' => true, - 'isDefaultShipping' => true, - 'isDefaultBilling' => true, - ], - 'exportBillingCustomerAddressCalls' => 1, - 'exportShippingCustomerAddressCalls' => 1, - ], - [ - 'conditions' => [ - 'isTelephone' => true, - 'isShippingSameAsBilling' => true, - 'isShippingSaveInAddressBook' => false, - 'isBillingSaveInAddressBook' => true, - 'isDefaultShipping' => true, - 'isDefaultBilling' => true, - ], - 'exportBillingCustomerAddressCalls' => 1, - 'exportShippingCustomerAddressCalls' => 0, - ], - [ - 'conditions' => [ - 'isTelephone' => true, - 'isShippingSameAsBilling' => false, - 'isShippingSaveInAddressBook' => false, - 'isBillingSaveInAddressBook' => false, - 'isDefaultShipping' => false, - 'isDefaultBilling' => false, - ], - 'exportBillingCustomerAddressCalls' => 1, - 'exportShippingCustomerAddressCalls' => 1, - ], - [ - 'conditions' => [ - 'isTelephone' => false, - 'isShippingSameAsBilling' => false, - 'isShippingSaveInAddressBook' => false, - 'isBillingSaveInAddressBook' => false, - 'isDefaultShipping' => false, - 'isDefaultBilling' => false, - ], - 'exportBillingCustomerAddressCalls' => 0, - 'exportShippingCustomerAddressCalls' => 0, - ], - - ]; - } -} diff --git a/dev/tests/integration/testsuite/Magento/Paypal/Model/Express/CheckoutTest.php b/dev/tests/integration/testsuite/Magento/Paypal/Model/Express/CheckoutTest.php index e33b87137264d..f9db997ad67c2 100644 --- a/dev/tests/integration/testsuite/Magento/Paypal/Model/Express/CheckoutTest.php +++ b/dev/tests/integration/testsuite/Magento/Paypal/Model/Express/CheckoutTest.php @@ -85,61 +85,6 @@ public function testPrepareCustomerQuote() $this->assertEquals(2, $order->getShippingAddress()->getCustomerAddressId()); } - /** - * Verify that an order placed with a new customer will create the customer. - * - * @magentoDataFixture Magento/Paypal/_files/quote_payment_express.php - * @magentoAppIsolation enabled - * @magentoDbIsolation enabled - */ - public function testPrepareNewCustomerQuote() - { - /** @var \Magento\Customer\Api\CustomerRepositoryInterface $customerService */ - $customerService = $this->_objectManager->get('Magento\Customer\Api\CustomerRepositoryInterface'); - - /** @var Quote $quote */ - $quote = $this->_getFixtureQuote(); - $this->quoteInitialization($quote); - $checkout = $this->_getCheckout($quote); - $checkout->place('token'); - $customer = $customerService->getById($quote->getCustomerId()); - $this->assertEquals('user@example.com', $customer->getEmail()); - $this->assertEquals('11111111', $customer->getAddresses()[0]->getTelephone()); - } - - /** - * Verify that after placing the order, addresses are associated with the order and the quote is a guest quote. - * - * @magentoDataFixture Magento/Paypal/_files/quote_payment_express.php - * @magentoAppIsolation enabled - * @magentoDbIsolation enabled - */ - public function testPlaceGuestQuote() - { - /** @var Quote $quote */ - $quote = $this->_getFixtureQuote(); - $quote->setCheckoutMethod(Onepage::METHOD_GUEST); // to dive into _prepareGuestQuote() on switch - $quote->getShippingAddress()->setSameAsBilling(0); - $quote->setReservedOrderId(null); - - $checkout = $this->_getCheckout($quote); - $checkout->place('token'); - - $this->assertNull($quote->getCustomerId()); - $this->assertTrue($quote->getCustomerIsGuest()); - $this->assertEquals( - \Magento\Customer\Model\GroupManagement::NOT_LOGGED_IN_ID, - $quote->getCustomerGroupId() - ); - - $this->assertNotEmpty($quote->getBillingAddress()); - $this->assertNotEmpty($quote->getShippingAddress()); - - $order = $checkout->getOrder(); - $this->assertNotEmpty($order->getBillingAddress()); - $this->assertNotEmpty($order->getShippingAddress()); - } - /** * @param Quote $quote * @return Checkout From bccadfc5357ae4590006b4716a06c6d6bf44b32b Mon Sep 17 00:00:00 2001 From: Ievgen Sentiabov Date: Mon, 2 Nov 2015 17:34:08 +0200 Subject: [PATCH 03/10] MAGETWO-44812: Customer address is duplicated after placing order within PayPal Express Checkout - Fixed failed static test --- app/code/Magento/Paypal/Model/Express/Checkout.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Paypal/Model/Express/Checkout.php b/app/code/Magento/Paypal/Model/Express/Checkout.php index 199425007eba3..d2299c55ea95a 100644 --- a/app/code/Magento/Paypal/Model/Express/Checkout.php +++ b/app/code/Magento/Paypal/Model/Express/Checkout.php @@ -1143,7 +1143,7 @@ private function setShippingOptions(PaypalCart $cart, Address $address = null) * Prepare quote for guest checkout order submit * * @return $this - */ + */ protected function prepareGuestQuote() { $quote = $this->_quote; From b1f28f210bdba929a5b02f03ff7b8fa75645ed2e Mon Sep 17 00:00:00 2001 From: Ievgen Sentiabov Date: Mon, 2 Nov 2015 17:46:05 +0200 Subject: [PATCH 04/10] MAGETWO-44812: Customer address is duplicated after placing order within PayPal Express Checkout - Restored integration test --- .../Paypal/Model/Express/CheckoutTest.php | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/dev/tests/integration/testsuite/Magento/Paypal/Model/Express/CheckoutTest.php b/dev/tests/integration/testsuite/Magento/Paypal/Model/Express/CheckoutTest.php index f9db997ad67c2..a11ec2db0327c 100644 --- a/dev/tests/integration/testsuite/Magento/Paypal/Model/Express/CheckoutTest.php +++ b/dev/tests/integration/testsuite/Magento/Paypal/Model/Express/CheckoutTest.php @@ -85,6 +85,40 @@ public function testPrepareCustomerQuote() $this->assertEquals(2, $order->getShippingAddress()->getCustomerAddressId()); } + /** + * Verify that after placing the order, addresses are associated with the order and the quote is a guest quote. + * + * @magentoDataFixture Magento/Paypal/_files/quote_payment_express.php + * @magentoAppIsolation enabled + * @magentoDbIsolation enabled + */ + public function testPlaceGuestQuote() + { + /** @var Quote $quote */ + $quote = $this->_getFixtureQuote(); + $quote->setCheckoutMethod(Onepage::METHOD_GUEST); // to dive into _prepareGuestQuote() on switch + $quote->getShippingAddress()->setSameAsBilling(0); + $quote->setReservedOrderId(null); + + $checkout = $this->_getCheckout($quote); + $checkout->place('token'); + + $this->assertNull($quote->getCustomerId()); + $this->assertTrue($quote->getCustomerIsGuest()); + $this->assertEquals( + \Magento\Customer\Model\GroupManagement::NOT_LOGGED_IN_ID, + $quote->getCustomerGroupId() + ); + + $this->assertNotEmpty($quote->getBillingAddress()); + $this->assertNotEmpty($quote->getShippingAddress()); + + $order = $checkout->getOrder(); + $this->assertNotEmpty($order->getBillingAddress()); + $this->assertNotEmpty($order->getShippingAddress()); + } + + /** * @param Quote $quote * @return Checkout From 9823118676d14c64b2c445d15ced0272ad031905 Mon Sep 17 00:00:00 2001 From: Ievgen Sentiabov Date: Mon, 2 Nov 2015 17:52:37 +0200 Subject: [PATCH 05/10] MAGETWO-44812: Customer address is duplicated after placing order within PayPal Express Checkout - Removed unnecessary code --- .../Paypal/Model/Express/CheckoutTest.php | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/dev/tests/integration/testsuite/Magento/Paypal/Model/Express/CheckoutTest.php b/dev/tests/integration/testsuite/Magento/Paypal/Model/Express/CheckoutTest.php index a11ec2db0327c..9be4422128d76 100644 --- a/dev/tests/integration/testsuite/Magento/Paypal/Model/Express/CheckoutTest.php +++ b/dev/tests/integration/testsuite/Magento/Paypal/Model/Express/CheckoutTest.php @@ -29,22 +29,6 @@ protected function setUp() $this->_objectManager = Bootstrap::getObjectManager(); } - /** - * Initialization the quote - * - * @param Quote $quote - * @return void - */ - protected function quoteInitialization(Quote $quote) - { - $quote->setCheckoutMethod(Onepage::METHOD_REGISTER); - $quote->setCustomerEmail('user@example.com'); - $quote->setCustomerFirstname('Firstname'); - $quote->setCustomerLastname('Lastname'); - $quote->setCustomerIsGuest(false); - $quote->setReservedOrderId(null); - } - /** * Verify that an order placed with an existing customer can re-use the customer addresses. * From 205e9fab50b787923e6696e6ec342c751e54bfab Mon Sep 17 00:00:00 2001 From: Oleksandr Karpenko Date: Mon, 2 Nov 2015 18:42:50 +0200 Subject: [PATCH 06/10] MAGETWO-44773: [Product Video] Delete video button has title "Delete Image" --- .../view/adminhtml/templates/helper/gallery.phtml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/ProductVideo/view/adminhtml/templates/helper/gallery.phtml b/app/code/Magento/ProductVideo/view/adminhtml/templates/helper/gallery.phtml index 9f13b923dd13a..f2e2bfb2829c4 100755 --- a/app/code/Magento/ProductVideo/view/adminhtml/templates/helper/gallery.phtml +++ b/app/code/Magento/ProductVideo/view/adminhtml/templates/helper/gallery.phtml @@ -116,8 +116,8 @@ $elementName = $block->getElement()->getName() . '[images]';