@graphcommerce/magento-customer 11.0.0-canary.54 → 11.0.0-canary.56
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
+
## 11.0.0-canary.56
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#2663](https://github.com/graphcommerce-org/graphcommerce/pull/2663) [`8d0f4a0`](https://github.com/graphcommerce-org/graphcommerce/commit/8d0f4a0a6539d8003fa21e1bc09822f55aa4dedb) - Address forms now honor Magento's `customer/address/telephone_show` configuration instead of silently submitting a `000 - 000 0000` placeholder telephone.
|
|
8
|
+
|
|
9
|
+
`CartAddressInput.telephone` is a non-nullable `String!`, so the address forms always had to send a value; because the mutation variable is declared as an optional `String`, `required.telephone` resolved to `false` and the field rendered as optional, after which `onBeforeSubmit` substituted the placeholder. Every checkout that skipped the field therefore stored a fake phone number on the order.
|
|
10
|
+
|
|
11
|
+
Magento does expose whether a telephone is required — `attributesForm(formCode: "customer_address_edit")` returns `is_required` per address attribute and reflects `customer/address/telephone_show`. `ShippingAddressForm`, `EditBillingAddressForm` and `EditAddressForm` now read that metadata through the existing `useAttributesForm` hook and mark the field required accordingly. The placeholder is gone: an empty telephone is submitted as an empty string, which Magento validates against the very same `is_required` (`Magento\Customer\Model\Address\Validator\General::checkOptionalFields`).
|
|
12
|
+
|
|
13
|
+
This is a deliberate behavior change. Where a customer who bypassed the client-side validation previously got a successful order carrying a fake phone number, a shop that requires a telephone now gets a proper `"telephone" is required. Enter and try again.` validation error. Addresses that still carry the old placeholder are cleared when they are loaded into a form, so the customer fills in a real number instead of being shown zeroes.
|
|
14
|
+
|
|
15
|
+
`attributesForm` only exists since Magento 2.4.7, so all of this is version-gated in `stripLegacyPlaceholderTelephone()` / `applyLegacyPlaceholderTelephone()` (`@graphcommerce/magento-customer`): below 2.4.7 the placeholder is still submitted and no longer stripped, exactly as before.
|
|
16
|
+
|
|
17
|
+
Pages that render these forms should preload the metadata in `getStaticProps` with `await preloadAttributesForm(client, 'customer_address_edit')`, the same way the account pages already preload `customer_account_create` / `customer_account_edit`. The examples do this for the checkout and address pages, which also closes the window where a customer could submit before the metadata resolved. ([@paales](https://github.com/paales))
|
|
18
|
+
|
|
19
|
+
## 11.0.0-canary.55
|
|
20
|
+
|
|
3
21
|
## 11.0.0-canary.54
|
|
4
22
|
|
|
5
23
|
## 11.0.0-canary.53
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { ApolloErrorSnackbar, TelephoneElement } from '@graphcommerce/ecommerce-ui'
|
|
2
2
|
import { useQuery } from '@graphcommerce/graphql'
|
|
3
|
-
import { CountryRegionsDocument } from '@graphcommerce/magento-store'
|
|
3
|
+
import { CountryRegionsDocument, useAttributesForm } from '@graphcommerce/magento-store'
|
|
4
4
|
import { Button, Form, FormActions, FormRow } from '@graphcommerce/next-ui'
|
|
5
5
|
import { useFormGqlMutation } from '@graphcommerce/react-hook-form'
|
|
6
6
|
import { Trans } from '@lingui/react/macro'
|
|
7
7
|
import type { SxProps, Theme } from '@mui/material'
|
|
8
8
|
import { useRouter } from 'next/router'
|
|
9
9
|
import { useBillingAddressPermission } from '../../hooks'
|
|
10
|
+
import { stripLegacyPlaceholderTelephone } from '../../utils'
|
|
10
11
|
import type { AccountAddressFragment } from '../AccountAddress/AccountAddress.gql'
|
|
11
12
|
import { AddressFields } from '../AddressFields/AddressFields'
|
|
12
13
|
import { CompanyFields } from '../CompanyFields'
|
|
@@ -27,6 +28,11 @@ export function EditAddressForm(props: EditAddressFormProps) {
|
|
|
27
28
|
const router = useRouter()
|
|
28
29
|
const billingAddressReadonly = useBillingAddressPermission() === 'READONLY'
|
|
29
30
|
|
|
31
|
+
// Magento's address attribute metadata tells us whether a telephone is required, as configured by
|
|
32
|
+
// `customer/address/telephone_show`.
|
|
33
|
+
const addressAttributes = useAttributesForm({ formCode: 'customer_address_edit' })
|
|
34
|
+
const telephoneRequired = addressAttributes.find((a) => a.code === 'telephone')?.is_required
|
|
35
|
+
|
|
30
36
|
const form = useFormGqlMutation(
|
|
31
37
|
UpdateCustomerAddressDocument,
|
|
32
38
|
{
|
|
@@ -39,7 +45,7 @@ export function EditAddressForm(props: EditAddressFormProps) {
|
|
|
39
45
|
postcode: address?.postcode,
|
|
40
46
|
city: address?.city,
|
|
41
47
|
countryCode: address?.country_code,
|
|
42
|
-
telephone: address?.telephone,
|
|
48
|
+
telephone: stripLegacyPlaceholderTelephone(address?.telephone),
|
|
43
49
|
houseNumber: address?.street?.[1] ?? '',
|
|
44
50
|
addition: address?.street?.[2] ?? '',
|
|
45
51
|
region: address?.region,
|
|
@@ -92,7 +98,7 @@ export function EditAddressForm(props: EditAddressFormProps) {
|
|
|
92
98
|
<FormRow>
|
|
93
99
|
<TelephoneElement
|
|
94
100
|
variant='outlined'
|
|
95
|
-
required={required.telephone}
|
|
101
|
+
required={required.telephone || telephoneRequired === true}
|
|
96
102
|
control={control}
|
|
97
103
|
name='telephone'
|
|
98
104
|
disabled={formState.isSubmitting}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@graphcommerce/magento-customer",
|
|
3
3
|
"homepage": "https://www.graphcommerce.org/",
|
|
4
4
|
"repository": "github:graphcommerce-org/graphcommerce",
|
|
5
|
-
"version": "11.0.0-canary.
|
|
5
|
+
"version": "11.0.0-canary.56",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"prettier": "@graphcommerce/prettier-config-pwa",
|
|
8
8
|
"eslintConfig": {
|
|
@@ -21,20 +21,20 @@
|
|
|
21
21
|
"./plugins/magentoCustomerPrivateQueryContext": "./plugins/magentoCustomerPrivateQueryContext.ts"
|
|
22
22
|
},
|
|
23
23
|
"peerDependencies": {
|
|
24
|
-
"@graphcommerce/ecommerce-ui": "^11.0.0-canary.
|
|
25
|
-
"@graphcommerce/eslint-config-pwa": "^11.0.0-canary.
|
|
26
|
-
"@graphcommerce/framer-next-pages": "^11.0.0-canary.
|
|
27
|
-
"@graphcommerce/framer-utils": "^11.0.0-canary.
|
|
28
|
-
"@graphcommerce/graphql": "^11.0.0-canary.
|
|
29
|
-
"@graphcommerce/graphql-mesh": "^11.0.0-canary.
|
|
30
|
-
"@graphcommerce/image": "^11.0.0-canary.
|
|
31
|
-
"@graphcommerce/magento-graphql": "^11.0.0-canary.
|
|
32
|
-
"@graphcommerce/magento-store": "^11.0.0-canary.
|
|
33
|
-
"@graphcommerce/next-config": "^11.0.0-canary.
|
|
34
|
-
"@graphcommerce/next-ui": "^11.0.0-canary.
|
|
35
|
-
"@graphcommerce/prettier-config-pwa": "^11.0.0-canary.
|
|
36
|
-
"@graphcommerce/react-hook-form": "^11.0.0-canary.
|
|
37
|
-
"@graphcommerce/typescript-config-pwa": "^11.0.0-canary.
|
|
24
|
+
"@graphcommerce/ecommerce-ui": "^11.0.0-canary.56",
|
|
25
|
+
"@graphcommerce/eslint-config-pwa": "^11.0.0-canary.56",
|
|
26
|
+
"@graphcommerce/framer-next-pages": "^11.0.0-canary.56",
|
|
27
|
+
"@graphcommerce/framer-utils": "^11.0.0-canary.56",
|
|
28
|
+
"@graphcommerce/graphql": "^11.0.0-canary.56",
|
|
29
|
+
"@graphcommerce/graphql-mesh": "^11.0.0-canary.56",
|
|
30
|
+
"@graphcommerce/image": "^11.0.0-canary.56",
|
|
31
|
+
"@graphcommerce/magento-graphql": "^11.0.0-canary.56",
|
|
32
|
+
"@graphcommerce/magento-store": "^11.0.0-canary.56",
|
|
33
|
+
"@graphcommerce/next-config": "^11.0.0-canary.56",
|
|
34
|
+
"@graphcommerce/next-ui": "^11.0.0-canary.56",
|
|
35
|
+
"@graphcommerce/prettier-config-pwa": "^11.0.0-canary.56",
|
|
36
|
+
"@graphcommerce/react-hook-form": "^11.0.0-canary.56",
|
|
37
|
+
"@graphcommerce/typescript-config-pwa": "^11.0.0-canary.56",
|
|
38
38
|
"@lingui/core": "^5",
|
|
39
39
|
"@lingui/macro": "^5",
|
|
40
40
|
"@lingui/react": "^5",
|
package/utils/index.ts
CHANGED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { magentoVersion } from '@graphcommerce/next-config/config'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* `CartAddressInput.telephone` is a non-nullable `String!`, but whether a shop actually requires a
|
|
5
|
+
* telephone is a store configuration (`customer/address/telephone_show`). GraphCommerce couldn't
|
|
6
|
+
* read that, so it submitted this placeholder for an empty field — which is how fake phone numbers
|
|
7
|
+
* ended up on orders.
|
|
8
|
+
*
|
|
9
|
+
* Magento only exposes the required-status through `attributesForm`, which was added in 2.4.7. On
|
|
10
|
+
* older versions the placeholder is still the only way to satisfy the schema, so the behavior below
|
|
11
|
+
* is version-gated: it stays exactly as it was on < 2.4.7 and is only dropped where the address
|
|
12
|
+
* attribute metadata can take over.
|
|
13
|
+
*/
|
|
14
|
+
export const legacyPlaceholderTelephone = '000 - 000 0000'
|
|
15
|
+
|
|
16
|
+
/** Whether the address attribute metadata (`attributesForm`) is available to drive the field. */
|
|
17
|
+
const hasAddressAttributeMetadata = magentoVersion >= 247
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Reading direction: an address saved before this behavior changed still carries the placeholder.
|
|
21
|
+
* Clear it so the customer is asked for a real number instead of being shown zeroes.
|
|
22
|
+
*
|
|
23
|
+
* On Magento < 2.4.7 the placeholder is still actively submitted, so the value is left alone.
|
|
24
|
+
*/
|
|
25
|
+
export function stripLegacyPlaceholderTelephone<T extends string | null | undefined>(
|
|
26
|
+
telephone: T,
|
|
27
|
+
): T | '' {
|
|
28
|
+
if (!hasAddressAttributeMetadata) return telephone
|
|
29
|
+
return telephone === legacyPlaceholderTelephone ? '' : telephone
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Writing direction: submit an empty string for an empty field and let Magento validate it against
|
|
34
|
+
* the same `is_required` the form renders with.
|
|
35
|
+
*
|
|
36
|
+
* On Magento < 2.4.7 that flag can't be read, so the placeholder is submitted as before — otherwise
|
|
37
|
+
* a shop that requires a telephone would start rejecting a form that never marked the field
|
|
38
|
+
* required.
|
|
39
|
+
*/
|
|
40
|
+
export function applyLegacyPlaceholderTelephone(telephone: string | null | undefined): string {
|
|
41
|
+
if (!hasAddressAttributeMetadata) return telephone || legacyPlaceholderTelephone
|
|
42
|
+
return telephone || ''
|
|
43
|
+
}
|