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

Allow multiple OrderItemPriceCalculationStrategy's #2764

Open
martijnvdbrug opened this issue Apr 4, 2024 · 0 comments
Open

Allow multiple OrderItemPriceCalculationStrategy's #2764

martijnvdbrug opened this issue Apr 4, 2024 · 0 comments

Comments

@martijnvdbrug
Copy link
Contributor

Is your feature request related to a problem? Please describe.

Whenever a project installs a custom OrderItemPriceCalculationStrategy, it won't allow you to use a plugin that uses a custom strategy. Or vice versa, whichever is loaded last overrides the others.

In our cases, most times a custom OrderItemPriceCalculationStrategy is used, it's only used for specific products or cases. If the custom strategy is not applicable, we call super.calculateUnitPrice(ctx, productVariant). See an example in the Stripe Subscription plugin.

The problem here, is that super always refers to the built-in strategy. There is no way to reference previously loaded strategies.

Describe the solution you'd like

It would be nice if our custom strategy can say This is not for me, try next strategy in stack. I haven't looked into the details, but I imagine we can have something like this:

// In vendure-config, we change to accepting an array of strategies. Plugins would just add to this array (or prepend?)
config.orderOptions.orderItemPriceCalculationStrategies = [ 
      new CustomOrderItemCalculation(),
      new AnotherOrderItemCalculation(),
   ];

// In our strategy, we should be able to return `false`, indicating that we weren't able to calculate the unit price.
async calculateUnitPrice(ctx, productVariant): Promise<PriceCalculationResult | false> {
    if (!productVariant.customFields.useCustomPrice){
      // Not for this strategy. Try next in stack
      return false;
    }
    // Or, return custom price
    return {
      priceIncludesTax: true,
      price: productVariant.customFields.customPrice,
    };
  }

Describe alternatives you've considered
We try to avoid OrderItemPriceCalculationStrategy where possible, because it's quite intrusive in that it won't allow you to use any plugins that also use the same strategy.

Additional context
Discord question: https://discord.com/channels/1100672177260478564/1225093130974531616

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