-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2118 from graphcommerce-org/bug/GCOM-1280-persist…
…-address removed ignorecache
- Loading branch information
Showing
4 changed files
with
53 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@graphcommerce/magento-cart-shipping-address': patch | ||
--- | ||
|
||
Fixed bug where if the customer created a new address during checkout it would not be persisted when navigating back from the payment step. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
packages/magento-cart-shipping-address/utils/findCustomerAddressFromCartAddress.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { CartAddressFragment } from '@graphcommerce/magento-cart/components/CartAddress/CartAddress.gql' | ||
import { CustomerAddressFragment } from '@graphcommerce/magento-customer/components/CreateCustomerAddressForm/CustomerAddress.gql' | ||
import { filterNonNullableKeys } from '@graphcommerce/next-ui' | ||
|
||
export function findCustomerAddressFromCartAddress<CustomerAddress extends CustomerAddressFragment>( | ||
customerAddresses: (CustomerAddress | null | undefined)[] | null | undefined, | ||
cartAddress: CartAddressFragment | null | undefined, | ||
): CustomerAddress | undefined { | ||
if (!customerAddresses || !cartAddress) return undefined | ||
|
||
return filterNonNullableKeys(customerAddresses, [])?.find( | ||
(customerAddr) => | ||
[ | ||
customerAddr.firstname === cartAddress.firstname, | ||
customerAddr.lastname === cartAddress.lastname, | ||
customerAddr.city === cartAddress.city, | ||
customerAddr.postcode === cartAddress.postcode, | ||
customerAddr.company === cartAddress.company, | ||
customerAddr.street?.[0] === cartAddress.street[0], | ||
customerAddr.street?.[1] === cartAddress.street[1], | ||
customerAddr.street?.[2] === cartAddress.street[2], | ||
customerAddr.country_code === cartAddress.country.code, | ||
customerAddr.region?.region_code === cartAddress.region?.code, | ||
customerAddr.telephone === cartAddress.telephone, | ||
].filter((v) => !v).length === 0, | ||
) | ||
} | ||
|
||
export function isCartAddressACustomerAddress<CustomerAddress extends CustomerAddressFragment>( | ||
customerAddresses: (CustomerAddress | null | undefined)[] | null | undefined, | ||
cartAddress: CartAddressFragment | null | undefined, | ||
): boolean { | ||
return !!findCustomerAddressFromCartAddress(customerAddresses, cartAddress) | ||
} |