Skip to content
This repository was archived by the owner on Feb 23, 2024. It is now read-only.

Commit 577279e

Browse files
authored
Copy shipping phone to billing phone if sync is checked (#10603)
1 parent e162612 commit 577279e

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

assets/js/blocks/checkout/inner-blocks/checkout-shipping-address-block/customer-address.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ const CustomerAddress = ( {
3434
setShippingAddress,
3535
setBillingAddress,
3636
setShippingPhone,
37+
setBillingPhone,
3738
useShippingAsBilling,
3839
} = useCheckoutAddress();
3940
const { dispatchCheckoutEvent } = useStoreEvents();
@@ -129,6 +130,12 @@ const CustomerAddress = ( {
129130
dispatchCheckoutEvent( 'set-phone-number', {
130131
step: 'shipping',
131132
} );
133+
if ( useShippingAsBilling ) {
134+
setBillingPhone( value );
135+
dispatchCheckoutEvent( 'set-phone-number', {
136+
step: 'billing',
137+
} );
138+
}
132139
} }
133140
/>
134141
) }

tests/e2e/tests/checkout/checkout-block-shipping.block_theme.side_effects.spec.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,23 @@ test.describe( 'Shopper → Checkout block → Shipping', () => {
5757
FLAT_RATE_SHIPPING_PRICE
5858
)
5959
).toBe( true );
60-
await page.getByLabel( 'Use same address for billing' ).uncheck();
60+
61+
await pageObject.syncBillingWithShipping();
62+
await pageObject.fillInCheckoutWithTestData( {
63+
phone: '0987654322',
64+
} );
65+
await pageObject.unsyncBillingWithShipping();
66+
const shippingForm = page.getByRole( 'group', {
67+
name: 'Shipping address',
68+
} );
69+
const billingForm = page.getByRole( 'group', {
70+
name: 'Billing address',
71+
} );
72+
73+
await expect( shippingForm.getByLabel( 'Phone' ).inputValue ).toEqual(
74+
billingForm.getByLabel( 'Phone' ).inputValue
75+
);
76+
6177
await pageObject.fillInCheckoutWithTestData();
6278
const overrideBillingDetails = {
6379
firstname: 'Juan',

tests/e2e/tests/checkout/checkout.page.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,14 @@ export class CheckoutPage {
332332
}
333333
}
334334

335+
async syncBillingWithShipping() {
336+
await this.page.getByLabel( 'Use same address for billing' ).check();
337+
}
338+
339+
async unsyncBillingWithShipping() {
340+
await this.page.getByLabel( 'Use same address for billing' ).uncheck();
341+
}
342+
335343
getOrderId() {
336344
// Get the current URL
337345
const url = this.page.url();

0 commit comments

Comments
 (0)