Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default phone number in profile not used in checkout form #276

Open
QAComet opened this issue Feb 20, 2024 · 2 comments
Open

Default phone number in profile not used in checkout form #276

QAComet opened this issue Feb 20, 2024 · 2 comments

Comments

@QAComet
Copy link
Contributor

QAComet commented Feb 20, 2024

Description

On the user profile page in the account settings, there is a section for setting a default phone number. If a user sets this, I would expect this to fill in the phone number on the checkout form.

Steps to reproduce

  • Go to /us/account/profile as an authenticated user
  • Click the "Edit" button on the "Phone" row at the bottom
  • Enter in the phone number, e.g. 1112223333
  • Click save
  • Go to the store at /us/store
  • Select the first item
  • On the item page, add it to the cart
  • Go to the cart page
  • Click on the checkout button
  • The phone form next to the email is empty, I was expecting to see 1112223333

Suggestions for improvement

There are some ways to improve the situation:

  1. Fill in the phone number by default with the phone number saved in the profile
  2. Remove the default phone number in the user's profile and instead just use the phone number in the address selected

Option 1

This choice requires a little work since the checkout form should be filled out with the saved phone number if an address isn't selected. Also, if a selected address does not have a phone number, the saved phone number in the profile should be used. If the selected address does use a phone number, then the phone number stored there, with the address, should be used, overwriting the default profile phone in the checkout form.

Option 2

This choice is easier since this just means removing some code from the user profile page.

@pankaj061999
Copy link

Summary of Changes Made:
In response to the issue described, I made modifications to the code to ensure that the phone number is correctly populated in the checkout form. I updated the formData initialization to include a fallback mechanism for retrieving the phone number from either the shipping address or the customer details.

Implementation Details:
I added cart?.customer?.phone as a fallback for the phone number field in the formData object. This ensures that if the phone number is not directly available under the shipping address, the code will attempt to retrieve it from the customer details.

const [formData, setFormData] = useState({
  "shipping_address.first_name": cart?.shipping_address?.first_name || "",
  "shipping_address.last_name": cart?.shipping_address?.last_name || "",
  "shipping_address.address_1": cart?.shipping_address?.address_1 || "",
  "shipping_address.company": cart?.shipping_address?.company || "",
  "shipping_address.postal_code": cart?.shipping_address?.postal_code || "",
  "shipping_address.city": cart?.shipping_address?.city || "",
  "shipping_address.country_code":
    cart?.shipping_address?.country_code || countryCode || "",
  "shipping_address.province": cart?.shipping_address?.province || "",
  email: cart?.email || "",
  "shipping_address.phone": cart?.shipping_address?.phone || cart?.customer?.phone || "",
});

Testing:
I thoroughly tested the updated code to ensure its correctness:

Tested scenarios where the phone number is available under the shipping address.
Tested scenarios where the phone number is not available under the shipping address but is present in the customer details.
Verified that the correct phone number is populated in the checkout form under various conditions.

Future Considerations:
For future enhancements, it might be worth considering additional error handling or validation to ensure that the phone number is consistently and accurately retrieved from the appropriate source. Additionally, further testing across different user scenarios could help identify any edge cases that may need to be addressed.

@VariableVic
Copy link
Collaborator

Hey guys, happy to accept a PR for this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants