Developer forum

Forum » Dynamicweb 10 » Apply price lit to cart

Apply price lit to cart

Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi guys,
I have a new situation when handling prices.
One of my prospects is using a concept of "Order Price list" that is not tied to a specific customer, but rather to a cart.
This means that they want to define several pricelists that are customer independent and the sales rep should apply a price list to a Customer quote request.
This approach seems to be very used for solutions and particular biddings.
What would be the best approach for handling this scenario?
I could probably try to use "Group Customer Number" and change it on the Quote cart but I am not sure if this is the right way.

Thank you,

Adrian


Replies

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

Hi Adrian

Here are a couple of ideas:

Answer 1 --- Custom PriceProvider

The recommended approach is to implement a custom PriceProvider that reads a price list identifier stored on the cart/order (e.g. in a custom order field), then uses that to filter prices.

How it works:

  • Extend PriceProvider and register it via the AddIn system
  • In FindPrice(PriceContext context, PriceProductSelection selection), inspect the current order/cart to find which price list has been applied by the sales rep
  • Use the price list identifier (stored as a custom field on the Order, or via Order.Comment, a secondary customer number field, etc.) to look up the correct prices from the price matrix
  • Return a PriceRaw with the appropriate price

Storing "which price list": Since PriceContext only carries Customer, Currency, Shop, and Country, you'd store the selected price list on the Order itself --- e.g. using a custom order field or by setting Order.CustomerNumber (or a dedicated field) to the price list identifier before the sales rep saves the quote.

public class QuotePriceListProvider : PriceProvider
{
    public override PriceRaw? FindPrice(PriceContext context, PriceProductSelection selection)
    {
        // Read the price list key from the current cart context
        var order = ...; // fetch current cart
        var priceListKey = order.GetCustomField("QuotePriceList"); // e.g. "BIDDING_TIER_A"

        if (string.IsNullOrEmpty(priceListKey)) return null; // fall through to default

        // Lookup price against your custom price matrix using priceListKey
        return new PriceRaw(...);
    }
}

Pros: Clean, fully decoupled from customer identity, survives recalculations, extensible per quote. Cons: Requires a custom price storage/lookup mechanism alongside the standard price matrix.


Answer 2 --- CustomerGroupId / GroupCustomerNumber hack

The quick approach the partner already suspected: define each "order price list" as a User Group with a specific CustomerNumber (e.g. "PRICELIST_A", "PRICELIST_B"), enter prices in the price matrix tagged with CustomerGroupId = "PRICELIST_A", and then set the cart's customer to a user that belongs to the matching group --- or temporarily override the lookup.

The CustomerGroupPriceFilter in DefaultPriceProvider matches Price.CustomerGroupId against the user's group CustomerNumber. So:

  1. Create User Groups: "PRICELIST_A", "PRICELIST_B" with those as CustomerNumber
  2. Enter prices in the price matrix with CustomerGroupId set to the relevant code
  3. When the sales rep applies a price list to a quote, assign the quote's customer to the matching group (or switch CustomerAccessUserId to a "proxy user" pre-assigned to that group)

Pros: No custom code, works within standard Dynamicweb price matrix tooling. Cons: Conflates "price list selection" with user group membership, creates awkward data modeling, fragile if the customer already belongs to groups with other purposes, and the "assign user to group" step may not be easily exposed in the UI for sales reps.


Bottom line: For a proper quote/bidding workflow, Answer 1 (custom PriceProvider) is the right long-term architecture. Answer 2 can work as a no-code workaround for simpler scenarios, but it will become unwieldy as the number of price lists grows. A hybrid is also possible: store the selected price list key as a custom field and use it within the standard price matrix via CustomerGroupId --- the PriceProvider then temporarily impersonates the right "price list group" context.

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi Nicolai,
Thank you very much for the detailed explanation.
I will first need to figure out with the prospect the expected level of complexity for the number of Price Lists. If there will be just a few (fewer than 10), maybe the standard approach would still be feasible in the long run.
If not, I agree that the CustomPriceProvider is the more suitable way to go.
Nevertheless, since we don't have an actual "PriceList" concept, I would still have to virtualise it (attach it to a User, UserGroup, or CustomerNumber) and reuse it in the Quote interface.  

Thank you,
Adrian

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

Have you seen this one: https://github.com/dynamicweb/DynamicWeb/issues/497

It is in this epic: https://doc.dynamicweb.dev/documentation/fundamentals/dw10release/releasenotes/workiteminfo.html?workitemid=27052

And here if you still have access to devops: https://dev.azure.com/dynamicwebsoftware/Dynamicweb/_workitems/edit/27052

It might cover all or some of your needs.

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi Nicolai,
I did not.
I still have access to DevOps, so I can have a look.
At first read, it still seems that the price logic is tied to either the User/UserGroup or the Product/ProductGroup. In my situation, it should be tied to the cart and should apply to products from different groups.
 

Adrian

 

You must be logged in to post in the forum