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

Restructure Order shipping data model #580

Closed
michaelbromley opened this issue Dec 7, 2020 · 0 comments
Closed

Restructure Order shipping data model #580

michaelbromley opened this issue Dec 7, 2020 · 0 comments
Milestone

Comments

@michaelbromley
Copy link
Member

michaelbromley commented Dec 7, 2020

Is your feature request related to a problem? Please describe.
Currently we represent the Shipping method & costs of an order as 3 properties on the Order entity:

shippingMethod: ShippingMethod
shipping: number;
shippingWithTax: number;

There are a couple of issues with this:

  1. It makes it impossible to use more than 1 ShippingMethod per Order. Though uncommon, this may be a requirement, e.g. to enable certain items to be sent via one method, and a single item to be drop-shipped. I expect such things to mainly be handled later at the Fulfillment stage, but I can also foresee that it might also be required at the ShippingMethod stage e.g. in order to separate the charges more distinctly.

  2. Shipping promotions (e.g. free shipping) are hacky right now - you need to just do a OrderPromotionAction and subtract the
    shipping amount from the Order. Tax-wise this is not really correct, since you would then be reducing the (prorated) price of every OrderItem, even though it is actually only the shipping being discounted.

Describe the solution you'd like

Create a new ShippingLine entity which looks like this:

@Entity()
export class ShippingLine extends VendureEntity {

    shippingMethodId: ID | null;

    shippingMethod: ShippingMethod | null;

    order: Order;

    price: number;

    priceWithTax: number;

    adjustments: Adjustment[];
}

and then an Order entity has reference to one or more of these:

export class Order {

  shippingLines: ShippingLine[];
}

Then we need to introduce a new type of PromotionAction: PromotionShippingAction which allows us to add discounts to the ShippingLine.adjustments array.

Describe alternatives you've considered
Just keeping it as-is. Since we're already doing pretty big breaking changes to the Order model in v0.18.0, we might as well get it all right now and have it done with.

@michaelbromley michaelbromley added this to the v0.18.0 milestone Dec 7, 2020
michaelbromley added a commit that referenced this issue Dec 8, 2020
Relates to #580. This commit changes the data model & API of the Order type so that
shipping is stored as multiple ShippingLine entities. For the time being, we assume a
single ShippingLine per order, but in future we can add the ability to deal with multiple
shipping lines per order.

BREAKING CHANGE: The way shipping charges on Orders are represented has been changed - an Order
now contains multiple ShippingLine entities, each of which has a reference to a ShippingMethod.
This will require a database migration with manual queries to preserve existing order data. See
release blog post for details.
michaelbromley added a commit that referenced this issue Dec 8, 2020
Relates to #580. This commit introduces the new PromotionShippingAction, allowing the creation
of promotions which discount the shipping price specifically.
michaelbromley added a commit that referenced this issue Dec 8, 2020
Relates to #580, Relates to #573.

BREAKING CHANGE: The return object of the ShippingCalculator class has changed:
    ```ts
    // before
    return {
      price: 500,
      priceWithTax: 600,
    };

    // after
    return {
      price: 500,
      taxRate: 20,
      priceIncludesTax: false,
    };
    ```
    This change will require you to update any custom ShippingCalculator implementations, and also
    to update any ShippingMethods by removing and re-selecting the ShippingCalculator.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant