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..e3813c0276ade 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 || quote.shippingAddress().save_in_address_book) { + 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..66ca1d451f4ef 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.shippingAddress()); + quote.billingAddress(billingAddress); + quote.shippingAddress().sameAsBilling = 1; + } var payload = { addressInformation: { shipping_address: quote.shippingAddress(), diff --git a/app/code/Magento/Newsletter/Model/ResourceModel/Subscriber/Collection.php b/app/code/Magento/Newsletter/Model/ResourceModel/Subscriber/Collection.php index 92de4c8b2e6cc..7862f7f41bf15 100644 --- a/app/code/Magento/Newsletter/Model/ResourceModel/Subscriber/Collection.php +++ b/app/code/Magento/Newsletter/Model/ResourceModel/Subscriber/Collection.php @@ -146,7 +146,8 @@ public function showCustomerInfo() [ 'customer' => $this->getTable('customer_entity') ], - 'main_table.customer_id = customer.entity_id' + 'main_table.customer_id = customer.entity_id', + ['firstname', 'lastname'] ); return $this; } diff --git a/app/code/Magento/Paypal/Model/Express/Checkout.php b/app/code/Magento/Paypal/Model/Express/Checkout.php index 2df901f5ce519..7459d3a6c2f37 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,14 @@ 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(); - break; + if ($this->getCheckoutMethod() == \Magento\Checkout\Model\Type\Onepage::METHOD_GUEST) { + $this->prepareGuestQuote(); } - $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 +817,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 +1083,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 +1136,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/app/code/Magento/ProductVideo/view/adminhtml/templates/helper/gallery.phtml b/app/code/Magento/ProductVideo/view/adminhtml/templates/helper/gallery.phtml index 9f13b923dd13a..9f7e8b1130b9a 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,18 @@ $elementName = $block->getElement()->getName() . '[images]';