diff --git a/vendor/magento/module-checkout/view/frontend/web/js/model/checkout-data-resolver.js b/vendor/magento/module-checkout/view/frontend/web/js/model/checkout-data-resolver.js index 66539ad21185..b96a01c8b78d 100644 --- a/vendor/magento/module-checkout/view/frontend/web/js/model/checkout-data-resolver.js +++ b/vendor/magento/module-checkout/view/frontend/web/js/model/checkout-data-resolver.js @@ -43,13 +43,6 @@ define([ resolveEstimationAddress: function () { var address; - if (checkoutData.getShippingAddressFromData()) { - address = addressConverter.formAddressDataToQuoteAddress(checkoutData.getShippingAddressFromData()); - selectShippingAddress(address); - } else { - this.resolveShippingAddress(); - } - if (quote.isVirtual()) { if (checkoutData.getBillingAddressFromData()) { address = addressConverter.formAddressDataToQuoteAddress( @@ -59,6 +52,11 @@ define([ } else { this.resolveBillingAddress(); } + } else if (checkoutData.getShippingAddressFromData()) { + address = addressConverter.formAddressDataToQuoteAddress(checkoutData.getShippingAddressFromData()); + selectShippingAddress(address); + } else { + this.resolveShippingAddress(); } }, diff --git a/vendor/magento/module-quote/Model/Cart/CartTotalRepository.php b/vendor/magento/module-quote/Model/Cart/CartTotalRepository.php index 2c487cdea63f..5481b952fa0e 100644 --- a/vendor/magento/module-quote/Model/Cart/CartTotalRepository.php +++ b/vendor/magento/module-quote/Model/Cart/CartTotalRepository.php @@ -88,6 +88,7 @@ public function get($cartId) /** @var \Magento\Quote\Model\Quote $quote */ $quote = $this->quoteRepository->getActive($cartId); if ($quote->isVirtual()) { + $quote->collectTotals(); $addressTotalsData = $quote->getBillingAddress()->getData(); $addressTotals = $quote->getBillingAddress()->getTotals(); } else { diff --git a/vendor/magento/module-tax/Model/Sales/Total/Quote/CommonTaxCollector.php b/vendor/magento/module-tax/Model/Sales/Total/Quote/CommonTaxCollector.php index 877aec37bdd6..7a0d10ac1506 100644 --- a/vendor/magento/module-tax/Model/Sales/Total/Quote/CommonTaxCollector.php +++ b/vendor/magento/module-tax/Model/Sales/Total/Quote/CommonTaxCollector.php @@ -6,6 +6,7 @@ namespace Magento\Tax\Model\Sales\Total\Quote; +use Magento\Customer\Api\AccountManagementInterface as CustomerAccountManagement; use Magento\Customer\Api\Data\AddressInterfaceFactory as CustomerAddressFactory; use Magento\Customer\Api\Data\AddressInterface as CustomerAddress; use Magento\Customer\Api\Data\RegionInterfaceFactory as CustomerAddressRegionFactory; @@ -144,6 +145,11 @@ class CommonTaxCollector extends AbstractTotal */ private $quoteDetailsItemExtensionFactory; + /** + * @var CustomerAccountManagement + */ + private $customerAccountManagement; + /** * Class constructor * @@ -156,6 +162,8 @@ class CommonTaxCollector extends AbstractTotal * @param CustomerAddressRegionFactory $customerAddressRegionFactory * @param TaxHelper|null $taxHelper * @param QuoteDetailsItemExtensionInterfaceFactory|null $quoteDetailsItemExtensionInterfaceFactory + * @param CustomerAccountManagement|null $customerAccountManagement + * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( \Magento\Tax\Model\Config $taxConfig, @@ -166,7 +174,8 @@ public function __construct( CustomerAddressFactory $customerAddressFactory, CustomerAddressRegionFactory $customerAddressRegionFactory, TaxHelper $taxHelper = null, - QuoteDetailsItemExtensionInterfaceFactory $quoteDetailsItemExtensionInterfaceFactory = null + QuoteDetailsItemExtensionInterfaceFactory $quoteDetailsItemExtensionInterfaceFactory = null, + ?CustomerAccountManagement $customerAccountManagement = null ) { $this->taxCalculationService = $taxCalculationService; $this->quoteDetailsDataObjectFactory = $quoteDetailsDataObjectFactory; @@ -178,6 +187,8 @@ public function __construct( $this->taxHelper = $taxHelper ?: ObjectManager::getInstance()->get(TaxHelper::class); $this->quoteDetailsItemExtensionFactory = $quoteDetailsItemExtensionInterfaceFactory ?: ObjectManager::getInstance()->get(QuoteDetailsItemExtensionInterfaceFactory::class); + $this->customerAccountManagement = $customerAccountManagement ?? + ObjectManager::getInstance()->get(CustomerAccountManagement::class); } /** @@ -413,7 +424,24 @@ public function mapItems( public function populateAddressData(QuoteDetailsInterface $quoteDetails, QuoteAddress $address) { $quoteDetails->setBillingAddress($this->mapAddress($address->getQuote()->getBillingAddress())); - $quoteDetails->setShippingAddress($this->mapAddress($address)); + if ($address->getAddressType() === QuoteAddress::ADDRESS_TYPE_BILLING + && !$address->getCountryId() + && $address->getQuote()->isVirtual() + && $address->getQuote()->getCustomerId() + ) { + $defaultBillingAddress = $this->customerAccountManagement->getDefaultBillingAddress( + $address->getQuote()->getCustomerId() + ); + $addressCopy = $address; + if ($defaultBillingAddress) { + $addressCopy = clone $address; + $addressCopy->importCustomerAddressData($defaultBillingAddress); + } + + $quoteDetails->setShippingAddress($this->mapAddress($addressCopy)); + } else { + $quoteDetails->setShippingAddress($this->mapAddress($address)); + } return $quoteDetails; }