Ensure empty data scenarios

This commit is contained in:
Emili Castells Guasch 2024-05-09 16:14:37 +02:00
parent 41eb1792c0
commit 39cf0c99fc
2 changed files with 39 additions and 7 deletions

View file

@ -583,15 +583,24 @@ class AxoManager {
if (authResponse.authenticationState === 'succeeded') {
log(JSON.stringify(authResponse));
this.setShipping(authResponse.profileData.shippingAddress);
const shippingData = authResponse.profileData.shippingAddress;
if(shippingData) {
this.setShipping(shippingData);
}
const billingAddress = authResponse.profileData?.card?.paymentSource?.card?.billingAddress;
if(billingAddress) {
this.setBilling({
address: billingAddress,
phoneNumber: authResponse.profileData.shippingAddress.phoneNumber.nationalNumber ?? ''
});
const cardBillingAddress = authResponse.profileData?.card?.paymentSource?.card?.billingAddress;
if(cardBillingAddress) {
this.setCard(authResponse.profileData.card);
const billingData = {
address: cardBillingAddress,
};
const phoneNumber = authResponse.profileData?.shippingAddress?.phoneNumber?.nationalNumber ?? '';
if(phoneNumber) {
billingData.phoneNumber = phoneNumber
}
this.setBilling(billingData);
}
this.setStatus('validEmail', true);

View file

@ -38,6 +38,20 @@ class ShippingView {
const stateCode = data.value('stateCode');
const stateName = (this.states[countryCode] && this.states[countryCode][stateCode]) ? this.states[countryCode][stateCode] : stateCode;
if(
this.hasEmptyValues(data, stateName)
) {
return `
<div style="margin-bottom: 20px;">
<div class="axo-checkout-header-section">
<h3>Shipping</h3>
<a href="javascript:void(0)" ${this.el.changeShippingAddressLink.attributes}>Edit</a>
</div>
<div>Please fill in your shipping details.</div>
</div>
`;
}
return `
<div style="margin-bottom: 20px;">
<div class="axo-checkout-header-section">
@ -118,6 +132,15 @@ class ShippingView {
});
}
hasEmptyValues(data, stateName) {
return !data.value('email')
|| !data.value('firstName')
|| !data.value('lastName')
|| !data.value('street1')
|| !data.value('city')
|| !stateName;
}
isActive() {
return this.group.active;
}