Information needed about refreshing an order to apply member pricing

Hi

My question is mostly around child OrderLines but some background on why first.

I’m using a custom ProductAdapter to apply member pricing as custom properties to a product snapshot, which are then used to apply an adjustment with a custom PriceAdjuster. These properties are only added if the customer was logged in. So, I’m handling the OrderAssigningToCustomerNotification, inside which I thaw the prices and need a way of refreshing the order with the properties.

Firstly, is there a better way to do this other than iterating over each order line, removing, and then re-adding them afterwards?

Secondly, I noticed there’s some deprecation around child OrderLines, so can I confirm that an Order should only ever have a mix of the following two options.

  1. A OrderLine without children.
  2. A BundleOrderLine with many BundledOrderLine without any children

Hope that makes sense.

Cheers
Ben

Quick update from some experimentation. I think it’s probably better to iterate over all OrderLines and get a new snapshot from the IProductService then just calling SetPropertiesAsync() with the properties from that snapshot.

After that I thaw prices and call RecalculateAsync() on the order.

Going by the deprecations it looks like bundles are only intended to being a one level deep hierarchy although you can still specify a bundleId parameter (not parentBundleId) when using AddProductToBundleAsync() so not 100% certain on this.

foreach(BundleOrderLineReadOnly bundleLine in evt.Order.GetBundles())
{
    IProductSnapshot snapshot = await _productService.GetProductAsync(evt.Order.StoreId,
                                                                      bundleLine.ProductReference,
                                                                      evt.Order.LanguageIsoCode,
                                                                      cancellationToken);
    await evt.Order.WithOrderLine(bundleLine.Id)
                    .SetPropertiesAsync(snapshot.Properties);

    foreach(var bundledOrderLine in bundleLine.OrderLines)
    {
        IProductSnapshot bundledSnapshot = await _productService.GetProductAsync(evt.Order.StoreId,
                                                                                 bundleLine.ProductReference,
                                                                                 evt.Order.LanguageIsoCode,
                                                                                 cancellationToken);
        await evt.Order.WithOrderLine(bundledOrderLine.Id)
                        .SetPropertiesAsync(snapshot.Properties);
    }
}

foreach(OrderLineReadOnly orderLine in evt.Order.OrderLines.Where(p=>p.IsBundle() == false))
{
    IProductSnapshot snapshot = await _productService.GetProductAsync(evt.Order.StoreId,
                                                                      orderLine.ProductReference,
                                                                      evt.Order.LanguageIsoCode,
                                                                      cancellationToken);
    await evt.Order.WithOrderLine(orderLine.Id)
                    .SetPropertiesAsync(snapshot.Properties);
}
await _priceFreezerService.ThawPricesAsync(evt.Order.Id);
await evt.Order.RecalculateAsync(cancellationToken);

It’d be good to know if I’ve got a grasp on this correctly and that I’m doing this in the intended way.