1

Good day people,

I have been trying to change the required field of lastname as not required in the form in the billing address of the checkout page:

enter image description here

As you can see the field of lastname is out and I used just Company name.

The things that I tried up until now are these:

to the talons/CheckoutPage/BillingAddress/useBillingAddress.js I erased the value lastname from the setBillingAddress & updateBillingAddress:

 const setBillingAddress = useCallback(() => {
        const {
            firstName,

            country,
            street1,
            street2,
            city,
            region,
            postcode,
            phoneNumber
        } = formState.values;

        updateBillingAddress({
            variables: {
                cartId,
                firstName,

                country,
                street1,
                street2,
                city,
                region,
                postcode,
                phoneNumber,
                sameAsShipping: false
            }
        });
    }, [formState.values, updateBillingAddress, cartId]);

to the talons/CheckoutPage/BillingAddress/billingAddress.gql.js I did the same:

export const SET_BILLING_ADDRESS = gql`
mutation setBillingAddress(
    $cartId: String!
    $firstName: String!
    $street1: String!
    $street2: String
    $city: String!
    $region: String!
    $postcode: String!
    $country: String!
    $phoneNumber: String!
) {
    setBillingAddressOnCart(
        input: {
            cart_id: $cartId
            billing_address: {
                address: {
                    firstname: $firstName
                    street: [$street1, $street2]
                    city: $city
                    region: $region
                    postcode: $postcode
                    country_code: $country
                    telephone: $phoneNumber
                    save_in_address_book: false
                }
            }
        }
    ) @connection(key: "setBillingAddressOnCart") {
        cart {
            id
            billing_address {
                firstname

                country {
                    code
                }
                street
                city
                region {
                    code
                }
                postcode
                telephone
            }
            ...PriceSummaryFragment
            ...AvailablePaymentMethodsFragment
        }
    }
}
${PriceSummaryFragment}
${AvailablePaymentMethodsFragment}

`;

I also change the is_required = 0 in the table eav_attribute, entity_type_id = 2

And finally I tried to comment the value of lastname in the schema CartAddressInput in my new module, the route of my module is this: /app/code/MyCompany/AdminUserForms/etc/schema.graphqls

the route of original module is this: vendor/magento/module-quote-graph-ql/etc/schema.graphqls

This is the schema:

input CartAddressInput
@doc(
    description: "Defines the billing or shipping address to be applied to the cart."
) {
firstname: String!
    @doc(description: "The first name of the customer or guest.")
# lastname: String!
#     @doc(description: "The last name of the customer or guest.")
company: String
    @doc(
        description: "The company specified for the billing or shipping address."
    )
street: [String!]!
    @doc(
        description: "An array containing the street for the billing or shipping address."
    )
city: String!
    @doc(
        description: "The city specified for the billing or shipping address."
    )
region: String
    @doc(
        description: "A string that defines the state or province of the billing or shipping address."
    )
region_id: Int
    @doc(
        description: "An integer that defines the state or province of the billing or shipping address."
    )
postcode: String
    @doc(
        description: "The ZIP or postal code of the billing or shipping address."
    )
country_code: String!
    @doc(
        description: "The country code and label for the billing or shipping address."
    )
telephone: String
    @doc(
        description: "The telephone number for the billing or shipping address."
    )
save_in_address_book: Boolean
    @doc(
        description: "Determines whether to save the address in the customer's address book. The default value is true."
    )

}

I did all of this and I getting the same error:

enter image description here

Does anyone have any solution for this?

1 Answer 1

0

You can define rules for the every file in the JS , It will work.

4
  • what do you mean? In the JS file inside each module in magento? Sep 1, 2022 at 13:08
  • You can override the form or You can create JS with the path view/base/web and use that js rules.
    – Rana Zain
    Sep 1, 2022 at 14:36
  • can you send me a path of a file to see as example please? Sep 1, 2022 at 15:08
  • or maybe just a documentation that explains how? Sep 2, 2022 at 7:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.