magento / architecture

A place where Magento architectural discussions happen
275 stars 153 forks source link

Added replace or merge option for addRequisitionListItemToCart mutation #388

Closed saravanansp96 closed 4 years ago

saravanansp96 commented 4 years ago

Problem

Whenever we add requisition list items to cart if the cart has items we have an option to replace or merge the requisition list items with the existing cart items. We don't have the option in the addRequisitionListItemToCart mutation.

Solution

Added a seperate parameter ( is_replace ) to the addRequisitionListItemToCart mutation.

Requested Reviewers

@nrkapoor @paliarush

paliarush commented 4 years ago

It should be possible to implement in on the side of the client application, without server side mutation. Currently the idea is that operation of moving items between cart, wishlist, requisition list and gift registry will be implemented on the client via reading existing items from the source and adding them to the destination.

nrkapoor commented 4 years ago

It should be possible to implement in on the side of the client application, without server side mutation. Currently the idea is that operation of moving items between cart, wishlist, requisition list and gift registry will be implemented on the client via reading existing items from the source and adding them to the destination.

@paliarush I agree. It can be easily done on the client-side.

saravanansp96 commented 4 years ago

@nrkapoor could you please confirm on which approach should we follow, the one mentioned by @DrewML or @paliarush? Thanks

DrewML commented 4 years ago

we have an option to replace or merge the requisition list items with the existing cart items

Can you explain this a bit more? Is this an option a user is presented with in the UI? Screenshots would be super helpful.

I'm working with this screenshot atm:

image

saravanansp96 commented 4 years ago

@DrewML @paliarush @nrkapoor

Steps to get the modal with the merge or replace option.

  1. Add products to the cart (minimum 1 product).
  2. Go to the requisition list and select a product.
  3. Click Add to Cart Button below.

Please check the screenshot Screenshot from 2020-06-23 10-44-36

Thanks

DrewML commented 4 years ago

It should be possible to implement in on the side of the client application, without server side mutation. Currently the idea is that operation of moving items between cart, wishlist, requisition list and gift registry will be implemented on the client via reading existing items from the source and adding them to the destination.

@paliarush @nrkapoor Although this is possible, I'm not sure it's the best option to put this work on the client, at least without some improvements.

Example Imagine I'm a buyer, and I have 3 items I want to quickly order from a requisition list. I already have a few items in my cart, but I'd like to just get rid of those and do my requisition list order.

The UI has to do the following:

  1. Use Query.cart or Query.customerCart to get a list of all items in the cart. This list will likely be paged per #389 because the cart listing could be large for B2B users
  2. Use Mutation.removeItemFromCart to remove a single item from the cart. To remove every item in the cart, the developer needs to dynamically generate the mutation (can't just write it out). For 20 items, that will be 20 mutations.
    • If any of those 20 mutations fail, the UI is now in a state where it needs to handle letting the user know that they've lost some items in their cart, but still have others, and the UI still has to decide whether to add the requisition list items to the cart or not
  3. Use Mutation.addRequisitionListItemToCart to add the new items to the cart

This is 2 or 3 requests to perform what is really a single logical action for the storefront, and requires the UI now handle new error states.

Proposed Options (We can pick 1 or multiple)

  1. Add a new mutation to clear/empty the cart. Then a client can send something like clearCustomerCart and addRequisitionListItemToCart in a single request
  2. Add a new mutation like removeItemsFromCart that allows removing multiple items with a single mutation
  3. Add a new mutation that can clear the cart and populate with requisition list items in a single operation. Something like Mutation.replaceCartWithRequisitionListItems

@nrkapoor Alex is out this week, but let me know your thoughts.

nrkapoor commented 4 years ago

It should be possible to implement in on the side of the client application, without server side mutation. Currently the idea is that operation of moving items between cart, wishlist, requisition list and gift registry will be implemented on the client via reading existing items from the source and adding them to the destination.

@paliarush @nrkapoor Although this is possible, I'm not sure it's the best option to put this work on the client, at least without some improvements.

Example Imagine I'm a buyer, and I have 3 items I want to quickly order from a requisition list. I already have a few items in my cart, but I'd like to just get rid of those and do my requisition list order.

The UI has to do the following:

  1. Use Query.cart or Query.customerCart to get a list of all items in the cart. This list will likely be paged per #389 because the cart listing could be large for B2B users
  2. Use Mutation.removeItemFromCart to remove a single item from the cart. To remove every item in the cart, the developer needs to dynamically generate the mutation (can't just write it out). For 20 items, that will be 20 mutations.

    • If any of those 20 mutations fail, the UI is now in a state where it needs to handle letting the user know that they've lost some items in their cart, but still have others, and the UI still has to decide whether to add the requisition list items to the cart or not
  3. Use Mutation.addRequisitionListItemToCart to add the new items to the cart

This is 2 or 3 requests to perform what is really a single logical action for the storefront, and requires the UI now handle new error states.

Proposed Options (We can pick 1 or multiple)

  1. Add a new mutation to clear/empty the cart. Then a client can send something like clearCustomerCart and addRequisitionListItemToCart in a single request
  2. Add a new mutation like removeItemsFromCart that allows removing multiple items with a single mutation
  3. Add a new mutation that can clear the cart and populate with requisition list items in a single operation. Something like Mutation.replaceCartWithRequisitionListItems

@nrkapoor Alex is out this week, but let me know your thoughts.

@DrewML I like option 1.

DrewML commented 4 years ago

@nrkapoor sounds good to me.

@saravanansp96 let's go with this one:

Add a new mutation to clear/empty the cart. Then a client can send something like clearCustomerCart and addRequisitionListItemToCart in a single request

Does that sound good to you? Then a client can do:

mutation EmptyCartAndAddRequisitionItems {
   clearCustomerCart
   addRequisitionListItemsToCart(...args) {
      # fields
   }
}
nrkapoor commented 4 years ago

@nrkapoor sounds good to me.

@saravanansp96 let's go with this one:

Add a new mutation to clear/empty the cart. Then a client can send something like clearCustomerCart and addRequisitionListItemToCart in a single request

Does that sound good to you? Then a client can do:

mutation EmptyCartAndAddRequisitionItems {
   clearCustomerCart
   addRequisitionListItemsToCart(...args) {
      # fields
   }
}

@DrewML yes. this looks good.

saravanansp96 commented 4 years ago

@DrewML @nrkapoor @paliarush Yes, it looks good, will update the Pull Request.

Thanks

saravanansp96 commented 4 years ago

@DrewML @nrkapoor I have updated the PR. Could you please review the changes.

Thanks

saravanansp96 commented 4 years ago

@nrkapoor @DrewML @paliarush I have updated the PR. Could you please review the changes.

Thanks

saravanansp96 commented 4 years ago

@nrkapoor @paliarush @DrewML I have changed the arguments to the camel case. Thanks