Skip to content

Use same_as_billing and address id instead of comparing addresses - #1430

Open
royduin wants to merge 5 commits into
masterfrom
same-as-billing
Open

royduin wants to merge 5 commits into
masterfrom
same-as-billing

Conversation

@royduin

@royduin royduin commented Oct 13, 2026 •

Copy link
Copy Markdown
Member

With those 2 we can remove the manual address comparison and we do not have to search for address ID's within customer addresses anymore.

Ref: RAP-1879 + RAP-1634

if (value.billing_address) {
// Magento resets this flag every time the shipping address is saved,
// it's set again when the billing address is saved with same_as_shipping.
value.billing_address.same_as_shipping = !!value.shipping_addresses?.[0]?.same_as_billing

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

!!... vs Boolean(...), which one do we want to use? I personally find !!... less readable on first glance.

email
shipping_addresses {
uid
customer_address_id: id

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the magento docs:

id - Id of the customer address. (Deprecated: Use customer_address_uid instead.)

Although I don't really understand why Magento has to be weird/inconsistent once again and use uid instead of just id for that. Now I don't even really know if that variable will even work. Frustrating.

billing_address: {
same_as_shipping: true
}
}) @@include(if: $same_as_billing) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting that this works! Have you checked that this doesn't introduce racing conditions within Magento? I've seen a few examples of doing these two queries together causing a database deadlock, but I don't know for sure whether that was with them merged or not.

If that's not an issue, this probably solves quite a few common bugs by itself.

>
<div partial-submit v-on:partial-submit="(e) => mutate().then(e.detail.resolve).catch(e.detail.reject)">
{{-- A billing address that's the same as the shipping address is updated within the shipping address mutation --}}
<div partial-submit v-on:partial-submit="(e) => variables.same_as_shipping && cart.value.billing_address?.same_as_shipping ? e.detail.resolve() : mutate().then(e.detail.resolve).catch(e.detail.reject)">

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm struggling to see why we're checking both the variables data and the cart.value.billing_address data. Does this avoid some edge case?

{{-- Without a billing address on the cart yet we follow the checkbox of the billing address step. --}}
:before-request="(query, variables, options) => [
variables.customer_address_id ? config.queries.setExistingShippingAddressesOnCart : query,
{ ...variables, same_as_billing: cart.value.billing_address ? cart.value.billing_address.same_as_shipping : (refs.billingAddress?.data.same_as_shipping ?? true) },

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same check here but then needing the ref just for this purpose. Make sure this is actually needed, otherwise this extra complexity will surely come to bite us later.

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

Successfully merging this pull request may close these issues.

2 participants