reactioncommerce / api-plugin-carts

Carts plugin for the Reaction API
GNU General Public License v3.0
1 stars 14 forks source link

Accept User input for Fulfillment type in PDP & Fulfillment Grouping #45

Open sujithvn opened 2 years ago

sujithvn commented 2 years ago

Resolves #MCOSS-52 Impact: breaking Type: feature

Issue

Currently "shipping" is the only fulfillment group in the cart/order and the current logic is to add the items into the the first matching group (comparing supported fulfillment type and existing groups).

Solution

Code fixed to pass all the supported fulfillment types into the grouping logic. This ensures that all the required groups based on the types can be created. Additionally code changes made to add the item to all the matching groups (earlier it was just the first matching).

In case the UI provided the optional field of selected fulfillment type (assuming the user selected it in the PDP page), then this is considered and the item is added only to the selected group.

Breaking changes

As the item is added to all the supported groups, we have to explicitly make the user select one of the group during the checkout and remove the items from the remaining groups. In case the user has already selected the fulfillment type in previous screens and provided the selectedFulfillmentType in API, then the item is already grouped under a single one.

Testing

  1. Tested by invoking the mutation addCartItems with and without "selectedFulfillmentType" and the results had the group created separately Sample
    mutation addCartItem {
    addCartItems(input: {
      items: [
                {
                    price: {
                        amount: 19.99,
                        currencyCode: "USD"
                    },
                    productConfiguration: {
                        productId: "cmVhY3Rpb24vcHJvZHVjdDpzdzN3Z1BNWEdGV2NLTHo0aQ==",
                        productVariantId: "cmVhY3Rpb24vcHJvZHVjdDptN253OW1SOFlFcUFoSjRZNQ=="
                    },
                    quantity: 1,
                     selectedFulfillmentType: "pickup"
                }
            ],
            cartToken: "GgoC2nR8vW7NXq-c7r5gxBy4hbyNqtTQEk1-q2iG5HK",
            cartId: "cmVhY3Rpb24vY2FydDp3c2RIcVFNMzRwYkE0ZnlybQ=="
    }) {
      cart  {
        checkout {
          fulfillmentGroups {
            _id
            type
            items {
              title
              selectedFulfillmentType
              quantity
            }            
          }
        }
      }
    }
    }