-
Notifications
You must be signed in to change notification settings - Fork 9.4k
#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
#32615: [GraphQL] Add assign customer to cart mutation #33106
Conversation
Hi @khrystynastolbova. Thank you for your contribution
❗ Automated tests can be triggered manually with an appropriate comment:
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. 🕙 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 run all tests |
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 run all tests |
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 give me test instance |
Hi @danielrussob. Thank you for your request. I'm working on Magento instance for you. |
@magento run Functional Tests EE |
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. |
Hi @danielrussob, here is your Magento Instance: https://67a329ab19fabd89241ecba5d0a1ba0c.instances.magento-community.engineering |
} | ||
|
||
$currentUserId = $context->getUserId(); | ||
$guestMaskedCartId = $args['cart_id']; |
There was a problem hiding this comment.
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'));
}
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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 = ')) { |
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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]);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@khrystynastolbova approved 👍
Thank you @khrystynastolbova @engcom-Hotel |
There was a problem hiding this 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-Hotel Below is the mutation
Before Merging customer cart to guest cart in can be found active in database as below After merge guest cart can't be found in database with same masked ID |
✔️ 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 |
Hi @khrystynastolbova, thank you for your contribution! |
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)
Manual testing scenarios (*)
Questions or comments
Contribution checklist (*)