We currently have some code that fires on member login, that updates any prices when the member logs in (prices are dynamic and can change, pulled from an external source)
We have this code that loops over the order lines and updates the prices, but I’m wondering if we also need to actually update the order line with the updated price, or will the productPriceFreezerService?.FreezeProductPrice be enough??
foreach (var orderLine in order.OrderLines.Where(ol => ol.UnitPrice == 0))
{
var productPriceFreezerService = _httpContextAccessor.HttpContext?.RequestServices.GetRequiredService<IProductPriceFreezerService>();
productPriceFreezerService?.ThawFrozenProductPrice(
store.Id,
order.Id,
orderLine.ProductReference,
orderLine.ProductVariantReference,
order.CurrencyId);
var unFrozenPrice = productPriceFreezerService?.GetOrCreateFrozenProductPrice(
store.Id,
order.Id,
orderLine.ProductReference,
orderLine.ProductVariantReference,
order.CurrencyId);
if (unFrozenPrice != null)
{
if (unFrozenPrice.Value == 0)
{
_logger.LogInformation("Unfrozen price is still 0 for sku: {0}", orderLine.ProductReference);
}
productPriceFreezerService?.FreezeProductPrice(
store.Id,
order.Id,
orderLine.ProductReference,
orderLine.ProductVariantReference,
unFrozenPrice);
beenProcessed = true;
}
else
{
_logger.LogWarning("Unable to retrieve unfrozen price while updating cart prices.");
}
}