magento / magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
http://www.magento.com
Open Software License 3.0
11.55k stars 9.32k forks source link

[2.4.5-p1] assignCustomerToGuestCart GraphQL mutation resets same_as_billing flag on shipping address #37407

Open DuckThom opened 1 year ago

DuckThom commented 1 year ago

Preconditions and environment

Steps to reproduce

  1. Create an empty cart as guest
    mutation {
    createEmptyCart
    }
  2. Create a customer account (don't login yet)
    mutation {
    createCustomerV2(input: { firstname: "foo", lastname: "bar", email: "foobar@example.com", password: "foobar123" }) {
    customer {
      firstname
      lastname
    }
    }
    }
  3. Add a product to the cart
    mutation($cartId: String!) {
    addProductsToCart(cartId: $cartId, cartItems: { sku: "1234", quantity: 1 }) {
    cart {
      id
    }
    }
    }
  4. Set a shipping address with save_in_address_book: true on the cart
    mutation($cartId: String!) {
    setShippingAddressesOnCart(
    input: {
      cart_id: $cartId
      shipping_addresses: [
        {
          address: {
            firstname: "foo"
            lastname: "bar"
            telephone: "0987654321"
            street: ["Foobar 12"]
            region: "Groningen"
            postcode: "1234"
            city: "Groningen",
            country_code: "NL",
            save_in_address_book: true
          }
        }
      ]
    }
    ) {
    cart {
      id
    }
    }
    }
  5. Set a different billing address with save_in_address_book: true on the cart
    mutation($cartId: String!) {
    setBillingAddressOnCart(
    input: {
      cart_id: $cartId
      billing_address: {
        address: {
          firstname: "bar"
          lastname: "foo"
          telephone: "0987654321"
          street: ["Wefwef 94"]
          region: "Groningen"
          postcode: "9876"
          city: "Groningen"
          country_code: "NL"
          save_in_address_book: true
        }
      }
    }
    ) {
    cart {
      id
    }
    }
    }
  6. Generate a customer token for the account created in step 2
    mutation GenerateCustomerToken {
    generateCustomerToken(password: "foobar123", email: "foobar@example.com") {
    token
    }
    }
  7. Run the assignCustomerToGuestCart mutation, attaching the cart to the customer
    
    Header: Authorization: Bearer <token from step 6>

mutation($cartId: String!) { assignCustomerToGuestCart(cart_id: $cartId) { id } }


### Expected result

*Before* placing the order, the following query should show `same_as_billing: 0` both before and after the `assignCustomerToGuestCart` mutation for the shipping address:

```sql
select save_in_address_book, address_type, same_as_billing  from quote_address where quote_id = <quoteId>\G

*************************** 1. row ***************************
save_in_address_book: 1
        address_type: shipping
     same_as_billing: 0
*************************** 2. row ***************************
save_in_address_book: 1
        address_type: billing
     same_as_billing: 0

After placing the order, both the shipping and billing addresses are added to the customer's address book.

Actual result

Before placing the order, the following query shows same_as_billing: 1 after the assignCustomerToGuestCart mutation for the shipping address:

select save_in_address_book, address_type, same_as_billing  from quote_address where quote_id = <quoteId>\G

*************************** 1. row ***************************
save_in_address_book: 1
        address_type: shipping
     same_as_billing: 1
*************************** 2. row ***************************
save_in_address_book: 1
        address_type: billing
     same_as_billing: 0

After placing the order, only the billing addresses is added to the customer's address book.

Additional information

A workaround for the issue for now it to call setShippingAddressOnCart a second time after the assignCustomerToGuestCart mutation

Release note

No response

Triage and priority

m2-assistant[bot] commented 1 year ago

Hi @DuckThom. Thank you for your report. To speed up processing of this issue, make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, Add a comment to the issue:

m2-assistant[bot] commented 1 year ago

Hi @engcom-Bravo. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

engcom-Bravo commented 1 year ago

Hi @DuckThom,

Thank you for reporting and collaboration.

Verified the issue on Magento 2.4-develop instance and the issue is reproducible.Kindly refer the screenshots.

Steps to reproduce

As per Description.

Screenshot 2023-04-25 at 6 39 20 PM Screenshot 2023-04-25 at 6 39 24 PM Screenshot 2023-04-25 at 4 48 08 PM

We have added different shipping and billing address still we are getting same_as_billing: 1. in quote address.

Hence Confirming the issue.

Thanks.

github-jira-sync-bot commented 1 year ago

:white_check_mark: Jira issue https://jira.corp.adobe.com/browse/AC-8599 is successfully created for this GitHub issue.

m2-assistant[bot] commented 1 year ago

:white_check_mark: Confirmed by @engcom-Bravo. Thank you for verifying the issue.
Issue Available: @engcom-Bravo, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.

warishareza commented 1 year ago

hi @engcom-Bravo @DuckThom

Upon careful examination, it has come to my attention that there is a discrepancy between the flow of calling GraphQL and the vanilla frontend flow. This misalignment raises concerns as it deviates from the recommended and optimal approach for invoking APIs.

To illustrate this point, let's consider the scenario within Magento frontend:

  1. Add product to cart
  2. Goto checkout page
  3. add shipping address (NOT same as billing)
  4. add billing address (NOT same as billing)

At this stage, if an attempt is made to log in using an existing customer account, Magento will redirect the user back to the shipping address page. Consequently, the user will need to re-enter both the shipping and billing addresses. Based on these observations, it is my opinion that the current flow of calling GraphQL is suboptimal. I would appreciate it if you could kindly correct me if my understanding is incorrect or if there are additional factors that should be taken into consideration.

warishareza commented 1 year ago

@magento I am working on this

warishareza commented 1 year ago

@engcom-Bravo I am not working on this as I described above, you can remove me from this issue

nihara47 commented 1 year ago

@magento I am working on this

Vasudev-22 commented 1 year ago

@DuckThom , @engcom-Bravo ,

@DuckThom , as per your steps, the issue is reproducible. After assigning the guest cart to customer cart, Card_Id is changing, so we need to update the shipping address and billing address to reflect in order. Not only in GraphQl , it was changing even in Luma frontend.

Steps to follow:

  1. Create Empty cart

    mutation {
    createEmptyCart
    }
  2. Add Product to the above cart id

    mutation {
    addProductsToCart(cartId: "{cart id}", cartItems: { sku: "24-MB04", quantity: 4 }) {
    cart {
      id
    }
    }
    }
  3. Create a customer

    mutation {
    createCustomerV2(input: { firstname: "foo1", lastname: "bar", email: "foobar1@example.com", password: "foobar@123" }) {
    customer {
      firstname
      lastname
    }
    }
    }
  4. Generate token

    mutation GenerateCustomerToken {
    generateCustomerToken(password: "foobar@123", email: "foobar1@example.com") {
    token
    }
    }
  5. Assign Guest cart to Customer

    mutation {
    assignCustomerToGuestCart(cart_id: "{cart id}") {
    id
    }
    }

Here we get different card id, use this hereafter

  1. Set Shipping Address

    mutation {
    setShippingAddressesOnCart(
    input: {
      cart_id: "{new cart id}"
      shipping_addresses: [
        {
          address: {
            firstname: "foo"
            lastname: "bar"
            telephone: "0987654321"
            street: ["Foobar 12"]
            region: "Groningen"
            postcode: "1234"
            city: "Groningen",
            country_code: "NL",
            save_in_address_book: true
          }
        }
      ]
    }
    ) {
    cart {
      id
    }
    }
    }
  2. Set Billing Address

    mutation {
    setBillingAddressOnCart(
    input: {
      cart_id: "{new cart id}"
      billing_address: {
        address: {
          firstname: "bar"
          lastname: "foo"
          telephone: "0987654321"
          street: ["Wefwef 94"]
          region: "Groningen"
          postcode: "9876"
          city: "Groningen"
          country_code: "NL"
          save_in_address_book: true
        }
        same_as_shipping: false
      }
    }
    ) {
    cart {
      id
    }
    }
    }
  3. Set Shipping Method

    mutation {
    setShippingMethodsOnCart(input: {
    cart_id: "{new cart id}"
    shipping_methods: [
      {
        carrier_code: "freeshipping"
        method_code: "freeshipping"
      }
    ]
    }) {
    cart {
      shipping_addresses {
        selected_shipping_method {
          carrier_code
          method_code
          carrier_title
          method_title
        }
      }
    }
    }
    }
  4. Add payment Method

    mutation {
    setPaymentMethodOnCart(input: {
      cart_id: "{new cart id}"
      payment_method: {
          code: "checkmo"
      }
    }) {
    cart {
      selected_payment_method {
        code
      }
    }
    }
    }
  5. Place Order

mutation {
  placeOrder(input: {cart_id: "{new cart id}"}) {
    order {
      order_number
    }
  }
}
Screenshot 2023-07-12 at 12 28 50 PM

After Placing Order, we can see in Order View Page, Shipping and Billing Address are different.

coresh commented 6 months ago

Magento v2.4.7 + Magento PWA Studio v14.0.0

The issue - exists: Reproduced: by opening any frontend product or category page. Frontend: PWA Studio v14.0.0

./var/log/exception.log <==
[2024-05-13T19:37:12.902586+00:00] report.ERROR: Infinite loop detected, review the trace for the looping path

GraphQL (2:3)
1: mutation createCart {
2:   cartId: createEmptyCart
     ^
3: }
 {"exception":"[object] (GraphQL\\Error\\Error(code: 0): Infinite loop detected, review the trace for the looping path at ./vendor/webonyx/graphql-php/src/Error/Error.php:155)
[previous exception] [object] (LogicException(code: 0): Infinite loop detected, review the trace for the looping path at ./vendor/magento/module-checkout/Model/Session.php:254)"} []
GraphQL (2:3)
1: mutation createCart {
2:   cartId: createEmptyCart
     ^
3: }
 {"exception":"[object] (GraphQL\\Error\\Error(code: 0): The quote can't be created. at ./vendor/webonyx/graphql-php/src/Error/Error.php:155)
[previous exception] [object] (Magento\\Framework\\Exception\\CouldNotSaveException(code: 0): The quote can't be created. at ./vendor/magento/module-quote/Model/QuoteManagement.php:293)"} []

Note:

Config -> "core_config_data" path: "checkout/options/guest_checkout" is 0

Thank you