Skip to content

[GraphQl] Add wishlist item to cart Implementation #31584

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

Merged

Conversation

shikhamis11
Copy link
Member

@shikhamis11 shikhamis11 commented Jan 7, 2021

Description (*)

Implement coverage for this new mutation

https://github.com/magento/architecture/blob/master/design-documents/graph-ql/coverage/customer/Wishlist.graphqls
addWishlistItemsToCart( wishlistUid: ID!, @doc(description: "unique Id of wishlist") wishlistItemUids: [ID!> @doc(description: "Optional param. selected wish list items that are to be added") ): AddWishlistItemsToCartOutput @doc(description: "Add Requisition List Items To Customer Cart")

AC

  • The field wishlistItemUids in the input can be null. Which implies that all the items in the wishlist will be added to the cart when wishlistItemUids are null.
  • The status field in the response conveys the result of the operation true/false
    
  • The addwishlist_items_to_cart_usererrors field should aggregate all the errors occurred when adding the corresponding items to the cart.
    

Related Pull Requests

https://github.com/magento/partners-magento2ee/pull/449

Fixed Issues (if relevant)

  1. Fixes [GraphQl] Add wishlist item to cart Implementation #31331

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)
  • All automated tests passed successfully (all builds are green)

@m2-assistant
Copy link

m2-assistant bot commented Jan 7, 2021

Hi @shikhamis11. Thank you for your contribution
Here is 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

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

@m2-community-project m2-community-project bot added the Priority: P1 Once P0 defects have been fixed, a defect having this priority is the next candidate for fixing. label Jan 7, 2021
Added Test for wishlist items add to cart
@shikhamis11
Copy link
Member Author

@magento run all tests

@shikhamis11
Copy link
Member Author

@magento give me test instance

@magento-deployment-service
Copy link

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

@magento-deployment-service
Copy link

@cpartica
Copy link
Contributor

cpartica commented Jan 7, 2021

@magento run all tests

Copy link
Contributor

@keharper keharper left a comment

Choose a reason for hiding this comment

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

My comments on the attribute descriptions.

@@ -23,7 +23,8 @@ type WishlistOutput @doc(description: "Deprecated: `Wishlist` type should be use
}

type Wishlist {
id: ID @doc(description: "The unique ID for a `Wishlist` object")
id: ID @deprecated(reason: "Use `wishlists.uid` instead") @doc(description: "The unique ID for a `Wishlist` object")
Copy link
Contributor

Choose a reason for hiding this comment

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

Should the reason be "Use Wishlist.uid instead"? If yes, I'd prefer the reason to be "Use uid instead", since both attributes are in the same data type.

@@ -35,7 +36,8 @@ type Wishlist {
}

interface WishlistItemInterface @typeResolver(class: "Magento\\WishlistGraphQl\\Model\\Resolver\\Type\\WishlistItemType") {
id: ID! @doc(description: "The unique ID for a `WishlistItemInterface` object")
id: ID! @deprecated(reason: "Use `WishlistItemInterface.uid` instead") @doc(description: "The unique ID for a `WishlistItemInterface` object")
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above regarding the reason text. "Use uid instead"

@@ -60,6 +62,15 @@ type Mutation {
addProductsToWishlist(wishlistId: ID!, wishlistItems: [WishlistItemInput!]!): AddProductsToWishlistOutput @doc(description: "Adds one or more products to the specified wish list. This mutation supports all product types") @resolver(class: "\\Magento\\WishlistGraphQl\\Model\\Resolver\\AddProductsToWishlist")
removeProductsFromWishlist(wishlistId: ID!, wishlistItemsIds: [ID!]!): RemoveProductsFromWishlistOutput @doc(description: "Removes one or more products from the specified wish list") @resolver(class: "\\Magento\\WishlistGraphQl\\Model\\Resolver\\RemoveProductsFromWishlist")
updateProductsInWishlist(wishlistId: ID!, wishlistItems: [WishlistItemUpdateInput!]!): UpdateProductsInWishlistOutput @doc(description: "Updates one or more products in the specified wish list") @resolver(class: "\\Magento\\WishlistGraphQl\\Model\\Resolver\\UpdateProductsInWishlist")
addWishlistItemsToCart(
wishlistUid: ID!, @doc(description: "The unique ID of the requisition list")
wishlistItemUids: [ID!] @doc(description: "An array of UIDs presenting products to be added to the cart. If no UIDs are specified, all items in the wishlist will be added to the cart")
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
wishlistItemUids: [ID!] @doc(description: "An array of UIDs presenting products to be added to the cart. If no UIDs are specified, all items in the wishlist will be added to the cart")
wishlistItemUids: [ID!] @doc(description: "An array of UIDs representing products to be added to the cart. If no UIDs are specified, all items in the wishlist will be added to the cart")

addWishlistItemsToCart(
wishlistUid: ID!, @doc(description: "The unique ID of the requisition list")
wishlistItemUids: [ID!] @doc(description: "An array of UIDs presenting products to be added to the cart. If no UIDs are specified, all items in the wishlist will be added to the cart")
): AddWishlistItemsToCartOutput @resolver(class: "Magento\\WishlistGraphQl\\Model\\Resolver\\Wishlist\\AddToCart") @doc(description: "Add items in the wishlist to the customer's cart")
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
): AddWishlistItemsToCartOutput @resolver(class: "Magento\\WishlistGraphQl\\Model\\Resolver\\Wishlist\\AddToCart") @doc(description: "Add items in the wishlist to the customer's cart")
): AddWishlistItemsToCartOutput @resolver(class: "Magento\\WishlistGraphQl\\Model\\Resolver\\Wishlist\\AddToCart") @doc(description: "Add items in the specified wishlist to the customer's cart")


type AddWishlistItemsToCartOutput {
status: Boolean!
add_wishlist_items_to_cart_user_errors: [CartUserInputError!]!
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
add_wishlist_items_to_cart_user_errors: [CartUserInputError!]!
add_wishlist_items_to_cart_user_errors: [CartUserInputError!]! @doc(description: "An array of errors encountered while adding products to the customer's cart")

}

type AddWishlistItemsToCartOutput {
status: Boolean!
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
status: Boolean!
status: Boolean! @doc(description: "Indicates whether the attempt to add items to the customer's cart was successful")

@shikhamis11
Copy link
Member Author

@magento run Static Tests

@keharper
Copy link
Contributor

These are my opinions only. It's up to Maura and the development team to decide whether to accept or reject my opinions.

  • This mutation moves products from a wishlist to the cart. Consider renaming the mutation to moveWishlistItemsToCart.
  • The mutation should return the updated wishlist. I presume this mutation would be run on a wish list page. On Luma, the stops displaying the items that were added to the cart.
  • Consider returning the cart. The addRequisitionListItemsToCart mutation does this.

Copy link
Contributor

@prabhuram93 prabhuram93 left a comment

Choose a reason for hiding this comment

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

Nice work! couple of comments needs to be addressed. Thanks!

@@ -23,7 +23,8 @@ type WishlistOutput @doc(description: "Deprecated: `Wishlist` type should be use
}

type Wishlist {
id: ID @doc(description: "The unique ID for a `Wishlist` object")
id: ID @deprecated(reason: "Use `uid` instead") @doc(description: "The unique ID for a `Wishlist` object")
uid: ID @doc(description: "The unique ID for a `Wishlist` object")
Copy link
Contributor

Choose a reason for hiding this comment

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

@shikhamis11 Good work on the PR! I see you have introduced uid for wishlist, but it will complicate things at this point as it will welcome conflicts on existing mutations. @mauragcyrus We need to have a follow up story, if needed. @shikhamis11 Can you remove this uid here and on the wishlist item. If there are any concerns please reply. thanks!

Copy link
Member Author

Choose a reason for hiding this comment

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

@prabhuram93 thanks for review. I added uid for Wishlist and WishlistItemInterface as in addWishlistItemsToCart mutation we require wishlistUid & wishlistItemUids

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah agree. I think that's confusing. I will work with @cpartica on renaming that to wishlistId & wishlistItemItds.

@@ -35,7 +36,8 @@ type Wishlist {
}

interface WishlistItemInterface @typeResolver(class: "Magento\\WishlistGraphQl\\Model\\Resolver\\Type\\WishlistItemType") {
id: ID! @doc(description: "The unique ID for a `WishlistItemInterface` object")
id: ID! @deprecated(reason: "Use `uid` instead") @doc(description: "The unique ID for a `WishlistItemInterface` object")
uid: ID! @doc(description: "The unique ID for a `WishlistItemInterface` object")
Copy link
Contributor

Choose a reason for hiding this comment

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

Even this needs to be removed.


/** @var AddProductsToCartOutput $addProductsToCartOutput */
$addProductsToCartOutput = $this->addProductsToCartService->execute($maskedCartId, $cartItems);

Copy link
Contributor

Choose a reason for hiding this comment

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

How are we removing the items from the wishlist after it is added to the cart?

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually not removing wishlist items now. I missed that part. I will push changes for this today

@shikhamis11
Copy link
Member Author

@magento run all tests

@shikhamis11
Copy link
Member Author

@magento run all tests

@@ -60,6 +60,15 @@ type Mutation {
addProductsToWishlist(wishlistId: ID!, wishlistItems: [WishlistItemInput!]!): AddProductsToWishlistOutput @doc(description: "Adds one or more products to the specified wish list. This mutation supports all product types") @resolver(class: "\\Magento\\WishlistGraphQl\\Model\\Resolver\\AddProductsToWishlist")
removeProductsFromWishlist(wishlistId: ID!, wishlistItemsIds: [ID!]!): RemoveProductsFromWishlistOutput @doc(description: "Removes one or more products from the specified wish list") @resolver(class: "\\Magento\\WishlistGraphQl\\Model\\Resolver\\RemoveProductsFromWishlist")
updateProductsInWishlist(wishlistId: ID!, wishlistItems: [WishlistItemUpdateInput!]!): UpdateProductsInWishlistOutput @doc(description: "Updates one or more products in the specified wish list") @resolver(class: "\\Magento\\WishlistGraphQl\\Model\\Resolver\\UpdateProductsInWishlist")
addWishlistItemsToCart(
wishlistId: ID!, @doc(description: "The unique ID of the requisition list")
Copy link
Contributor

@dthampy dthampy Jan 29, 2021

Choose a reason for hiding this comment

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

The description should be "The unique ID of the wish list"
Shouldn't the field names match with what the architectural schema dictates : "wishlistUid" and "wishlistItemUids" ?

Copy link
Member Author

Choose a reason for hiding this comment

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

hi @dthampy thanks for review
I have updated wishlistUid and wishlistItemUids to wishlistId and wishlistItemIds as per change request by @prabhuram93
#31584 (comment)

@shikhamis11
Copy link
Member Author

@magento run all tests

@prabhuram93
Copy link
Contributor

This pull request is being processed internally. Please do not add any more commits on this PR.

@magento-engcom-team magento-engcom-team merged commit 50efec2 into magento:2.4-develop Feb 16, 2021
@m2-assistant
Copy link

m2-assistant bot commented Feb 16, 2021

Hi @shikhamis11, 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: WishlistGraphQl Partner: Cedcommerce partners-contribution Pull Request is created by Magento Partner Priority: P1 Once P0 defects have been fixed, a defect having this priority is the next candidate for fixing. Progress: review Project: GraphQL Release Line: 2.4
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[GraphQl] Add wishlist item to cart Implementation
7 participants