cancel
Showing results for 
Search instead for 
Did you mean: 

New Shiping and Billing Address

SOLVED

New Shiping and Billing Address

Hello Friends,

 

I am facing 1 issue after successfull order my new shipping and billing address is not getting stored in user address book. As i check new shipping and billing address are coming in order detail view page. 
So can you please reply what can be the issue for which address are not getting stored.

 

This issue is only coming for existing user. For new user its working good

 

Please reply asap.

1 ACCEPTED SOLUTION

Accepted Solutions

Re: New Shiping and Billing Address

Hello Nuhe

 

Please override below file in custom module and replace with below savePaymentInformation function.

 

/vendor/magento/module-checkout/Model/PaymentInformationManagement.php

 

 

 public function savePaymentInformation(
        $cartId,
        \Magento\Quote\Api\Data\PaymentInterface $paymentMethod,
        \Magento\Quote\Api\Data\AddressInterface $billingAddress = null
    ) {
        if ($billingAddress) {
            /** @var \Magento\Quote\Api\CartRepositoryInterface $quoteRepository */
            $quoteRepository = $this->getCartRepository();
            /** @var \Magento\Quote\Model\Quote $quote */
            $quote = $quoteRepository->getActive($cartId);
            $quote->removeAddress($quote->getBillingAddress()->getId());
            
            $customer = $quote->getCustomer();
            if (is_null($customer->getDefaultBilling())) {
                $customer->setDefaultBilling($billingAddress->getId());
            }

            $quote->setBillingAddress($billingAddress);
            $quote->setDataChanges(true);
            $shippingAddress = $quote->getShippingAddress();
            if ($shippingAddress && $shippingAddress->getShippingMethod()) {
                $shippingDataArray = explode('_', $shippingAddress->getShippingMethod());
                $shippingCarrier = array_shift($shippingDataArray);
                $shippingAddress->setLimitCarrier($shippingCarrier);
            }
        }
        $this->paymentMethodManagement->set($cartId, $paymentMethod);
        return true;
    }

If issue solved , Click Kudos & Accept as Solution

 

View solution in original post

2 REPLIES 2

Re: New Shiping and Billing Address

Hello Nuhe

 

Please override below file in custom module and replace with below savePaymentInformation function.

 

/vendor/magento/module-checkout/Model/PaymentInformationManagement.php

 

 

 public function savePaymentInformation(
        $cartId,
        \Magento\Quote\Api\Data\PaymentInterface $paymentMethod,
        \Magento\Quote\Api\Data\AddressInterface $billingAddress = null
    ) {
        if ($billingAddress) {
            /** @var \Magento\Quote\Api\CartRepositoryInterface $quoteRepository */
            $quoteRepository = $this->getCartRepository();
            /** @var \Magento\Quote\Model\Quote $quote */
            $quote = $quoteRepository->getActive($cartId);
            $quote->removeAddress($quote->getBillingAddress()->getId());
            
            $customer = $quote->getCustomer();
            if (is_null($customer->getDefaultBilling())) {
                $customer->setDefaultBilling($billingAddress->getId());
            }

            $quote->setBillingAddress($billingAddress);
            $quote->setDataChanges(true);
            $shippingAddress = $quote->getShippingAddress();
            if ($shippingAddress && $shippingAddress->getShippingMethod()) {
                $shippingDataArray = explode('_', $shippingAddress->getShippingMethod());
                $shippingCarrier = array_shift($shippingDataArray);
                $shippingAddress->setLimitCarrier($shippingCarrier);
            }
        }
        $this->paymentMethodManagement->set($cartId, $paymentMethod);
        return true;
    }

If issue solved , Click Kudos & Accept as Solution

 

Re: New Shiping and Billing Address

Hello mate,

 

Thanks for reply i changed the code but the issue is same mate not saving the new billing and shipping address for existing user. 

Please reply if anything more to do

 

Thanks