Skip to content
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

Shipping method metadata #136

Closed
michaelbromley opened this issue Aug 8, 2019 · 0 comments
Closed

Shipping method metadata #136

michaelbromley opened this issue Aug 8, 2019 · 0 comments

Comments

@michaelbromley
Copy link
Member

Is your feature request related to a problem? Please describe.
It would be useful to allow a ShippingEligibilityChecker & ShippingCalculator to attach arbitrary metadata to their results. For example, with a checker/calculator I am implementing which reads from a CSV price table, it would be useful to be able to include data such as "shipping provider" and "estimated shipping time" in addition to the eligibility & price.

Describe the solution you'd like
Currently the ShippingCalculator.calculate() method returns a ShippingPrice object:

type ShippingPrice = {
    price: number;
    priceWithTax: number;
};

Instead we could return:

type ShippingCalculationResult = {
    price: number;
    priceWithTax: number;
    metadata: Record<string, any>;
};

This could then be return from the eligibleShippingMethods query:

type ShippingMethodQuote {
    id: ID!
    price: Int!
    priceWithTax: Int!
    description: String!
    metadata: JSON
}

Use case

I have a CSV file containing data on a number of couriers (DPD, FedEx, Royal Mail etc) plus data on their charges & delivery times to various countries:

provider     ,country                       ,countryCode,baseWeight,baseCost,incrementWeight,incrementCost,upperWeight,shippingTime
"DPD Classic","Austria"                     ,"AT"       ,"25000"   ,"1376"  ,"25000"        ,"1376"       ,"200000"   ,"4 - 5"
"DPD Classic","Bosnia and Herzegovina"      ,"BA"       ,"25000"   ,"5063"  ,"25000"        ,"2563"       ,"200000"   ,"5 - 7"
"DPD Classic","Belgium"                     ,"BE"       ,"25000"   ,"1088"  ,"25000"        ,"1088"       ,"200000"   ,"3 - 4"

In my ShippingCalculator I take the order weight and shipping address to look up the the prices with eligible couriers.

Currently if I call eligibleShippingMethods from my storefront, I only get a single price. I'd like to additionally be able to display the courier and the expected delivery time too. This could be done with this metadata proposal:

// query 
{
  eligibleShippingMethods {
    id
    price
    description
    metadata
  }
}

// result
[
  {
     "id": "1",
     "price": 1000,
     "description": "Courier Shipping"
     "metadata": {
         "courier": "DPD Classic",
         "deliveryEstimate": "4 - 5"
      }
  }
]

It might also be useful to retain this metadata with the order, as a simple-json field shippingMetadata. For now I will avoid this as I wish to be as conservative as possible when it comes to adding new fields to existing entities.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant