Try our conversational search powered by Generative AI!

Create a custom line item

Vote:
 

Hi,

I am using commerce 13.21 (Foundation), there is a scenario where I have too add interest as a line item for certain orders. 

Example: 

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?

Regards,

Siddharth

#230834
Nov 15, 2020 22:52
ryan-mllrdev - May 24, 2021 2:27
Hello Siddharth,

I'm also trying to add a custom field in the line item, do you have an update on this one?
Vote:
 

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?

#231005
Nov 17, 2020 10:26
Siddharth Gupta - Nov 17, 2020 20:48
Hey Praful, thanks for your reply. The requirement is to add the interest to the order total and also display it as a line item. That was the driving factor for me to think of adding this as a line item.
Vote:
 

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

example snippet

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
        }

  }

 

#248169
Feb 04, 2021 18:15
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.