I am using commerce 13.21 (Foundation), there is a scenario where I have too add interest as a line item for certain orders.
LineItem 1, SKU 001-001, Qty 2, line item price $5, line item extended price $10
LineItem 2, SKU Interest, Qty 1, line item extended price (based on internal logic)
I am planning to add a variant in the catalog with "INTEREST" as SKU. And then add a meta field "IsInterest" on the lineitem, and then override the DefaultLineItemCalculator's CalculateExtendedPrice method to check for the "INTEREST" lineitem and compute it's price.
Is there a better approach to this?
You can just add meta field on meta class for the interest value. Do you have to implement any extra logic on that? Can you give an high level idea abot your requirements?
if I understand you correctly you want to override price calculation of a variant. For variant "Interest" you want to do a custom calculation to get pricing.
you need to write your own pricing service (or price helper class) that will inherit with DefaultPlacedPriceProcessor & IPlacedPriceProcessor
public class PlacedPriceProcessor : DefaultPlacedPriceProcessor, IPlacedPriceProcessor
public override bool UpdatePlacedPrice(ILineItem lineItem, CustomerContact customerContact, MarketId marketId, Currency currency, Action<ILineItem, ValidationIssue> onValidationError)
// Custom logic
public override Money? GetPlacedPrice(EntryContentBase entry, decimal quantity, CustomerContact customerContact,
MarketId marketId, Currency currency)
// Custom logic