Skip to content

#32615: [GraphQL] Add assign customer to cart mutation #33106

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

khrystynastolbova
Copy link
Contributor

@khrystynastolbova khrystynastolbova commented May 31, 2021

Description (*)

This pull request adds 'assignCustomerToGuestCart' mutation.
The mutation assigns a logged in customer and merge customer's shopping cart items to the specified guest shopping cart.

Related Pull Requests

Fixed Issues (if relevant)

  1. Fixes Add assign customer to cart mutation #32615

Manual testing scenarios (*)

mutation {
  assignCustomerToGuestCart(
    cart_id: "SCJUI4KfzhmTJfoCfy38xTmLccu71234"
  ){
  items {
      quantity
      product {
        sku
      }
    }
  }
}

Screenshot 2021-05-28 at 16 30 35

Questions or comments

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • README.md files for modified modules are updated and included in the pull request if any README.md predefined sections require an update
  • All automated tests passed successfully (all builds are green)

@m2-assistant
Copy link

m2-assistant bot commented May 31, 2021

Hi @khrystynastolbova. Thank you for your contribution
Here are some useful tips how you can test your changes using Magento test environment.
Add the comment under your pull request to deploy test or vanilla Magento instance:

  • @magento give me test instance - deploy test instance based on PR changes
  • @magento give me 2.4-develop instance - deploy vanilla Magento instance

❗ Automated tests can be triggered manually with an appropriate comment:

  • @magento run all tests - run or re-run all required tests against the PR changes
  • @magento run <test-build(s)> - run or re-run specific test build(s)
    For example: @magento run Unit Tests

<test-build(s)> is a comma-separated list of build names. Allowed build names are:

  1. Database Compare
  2. Functional Tests CE
  3. Functional Tests EE,
  4. Functional Tests B2B
  5. Integration Tests
  6. Magento Health Index
  7. Sample Data Tests CE
  8. Sample Data Tests EE
  9. Sample Data Tests B2B
  10. Static Tests
  11. Unit Tests
  12. WebAPI Tests
  13. Semantic Version Checker

You can find more information about the builds here

ℹ️ Please run only needed test builds instead of all when developing. Please run all test builds before sending your PR for review.

For more details, please, review the Magento Contributor Guide documentation.

⚠️ According to the Magento Contribution requirements, all Pull Requests must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting.

🕙 You can find the schedule on the Magento Community Calendar page.

📞 The triage of Pull Requests happens in the queue order. If you want to speed up the delivery of your contribution, please join the Community Contributions Triage session to discuss the appropriate ticket.

🎥 You can find the recording of the previous Community Contributions Triage on the Magento Youtube Channel

✏️ Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel

@magento-engcom-team magento-engcom-team added Release Line: 2.4 Partner: Atwix Pull Request is created by partner Atwix partners-contribution Pull Request is created by Magento Partner labels May 31, 2021
@khrystynastolbova
Copy link
Contributor Author

@magento run all tests

@magento-automated-testing
Copy link

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time.

@sdzhepa sdzhepa added the Priority: P2 A defect with this priority could have functionality issues which are not to expectations. label Jun 24, 2021
@khrystynastolbova
Copy link
Contributor Author

@magento run all tests

@magento-automated-testing
Copy link

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time.

@danielrussob
Copy link

@magento give me test instance

@magento-deployment-service
Copy link

Hi @danielrussob. Thank you for your request. I'm working on Magento instance for you.

@danielrussob
Copy link

@magento run Functional Tests EE

@magento-automated-testing
Copy link

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time.

@magento-deployment-service
Copy link

}

$currentUserId = $context->getUserId();
$guestMaskedCartId = $args['cart_id'];

Choose a reason for hiding this comment

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

Hello @khrystynastolbova,
thank you for your contribution

could you add a check on cart_id?

if (empty($args['cart_id'])) {
throw new GraphQlInputException(__('Required parameter "cart_id" is missing'));
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Hi @danielrussob, actually cart_id is a required field at the schema level, and personally don't see the reason to have an additional check for that.

$guestMaskedCartId = $args['cart_id'];
$storeId = (int)$context->getExtensionAttributes()->getStore()->getId();

$this->getCartForUser->execute($guestMaskedCartId,null, $storeId);
Copy link
Contributor

Choose a reason for hiding this comment

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

Hello, please add a space after $guestMaskedCartId, parameter (i.e. before null parameter) to avoid coding style complains. Thanks!

$this->guestCartManagementInterface->assignCustomer($guestMaskedCartId, $currentUserId, $storeId);
} catch (NoSuchEntityException $e) {
$message = $e->getMessage();
if (str_contains($message, 'No such entity with cartId = ')) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I may be wrong but don't you think that checking against a specific string could be fragile?
Let me explain: in case the exception message changes or is translated, this condition could be not satisfiable anymore.

I don't get the reason for changing the exception message here, can you elaborate on this to identify together an alternative solution?

Thank you!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @aleron75. You are right it could be fragile. I just wanted to avoid displaying non hashed cartId for the client

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe that will be enough

} catch (NoSuchEntityException $e) {
    $message = __('Could not find a cart with ID "%masked_cart_id"', ['masked_cart_id' => $guestMaskedCartId]);
 }

Copy link
Contributor

Choose a reason for hiding this comment

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

@khrystynastolbova approved 👍

@engcom-Bravo
Copy link
Contributor

Thank you @khrystynastolbova @engcom-Hotel
I am working on this.

Copy link
Contributor

@engcom-Hotel engcom-Hotel left a comment

Choose a reason for hiding this comment

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

Since it is auto moving to the "Ready for testing" bucket, moving back to "Change requested".

@engcom-Bravo
Copy link
Contributor

engcom-Bravo commented Sep 1, 2021

@engcom-Hotel assignCustomerToGuestCart Mutation will merge customer cart into guest cart.
Customer cart become inactive and the guest cart remains active only for guest cart new masked id is being generated.
That is why you are seeing new cart_id (quote masked id) but quote Id remains same.

Below is the mutation

mutation {
  assignCustomerToGuestCart(
    cart_id:"cxOBoVAfw9JYUisVNnwKT51ObBI98gwI",
  ) {
    items {
      id
      product {
        name
        sku
      }
      quantity
    }
  }
}

Before Merging customer cart to guest cart in can be found active in database as below

beforemerge

After merge guest cart can't be found in database with same masked ID
AfterMergeRecordCantBeFoundWithSame Id

Guest Cart can be found and active with new maskId
Record Can be found

@engcom-Hotel
Copy link
Contributor

✔️

Hello @engcom-Bravo,

Thanks for the clarification!

As per the screenshots attached in the coment, it is clear that the actual cart_id is not changing only the masked_id is updating (might be due to security reasons).

Please refer to my comment for the scenarios on which I have tested this PR.

Tested all the manual scenarios, no impact on regression testing.

Thanks

@m2-assistant
Copy link

m2-assistant bot commented Oct 24, 2021

Hi @khrystynastolbova, thank you for your contribution!
Please, complete Contribution Survey, it will take less than a minute.
Your feedback will help us to improve contribution process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: QuoteGraphQl Partner: Atwix Pull Request is created by partner Atwix partners-contribution Pull Request is created by Magento Partner Priority: P2 A defect with this priority could have functionality issues which are not to expectations. Progress: accept Release Line: 2.4
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add assign customer to cart mutation
8 participants