After upgrading to 8.4.0 I can’t find the class ProductPricesHasNotChanged. Has that been removed or renamed?
Before it was located in namespace Litium.Accelerator.ValidationRules but found in Litium.Application.dll
Litium version: 8.4.0
After upgrading to 8.4.0 I can’t find the class ProductPricesHasNotChanged. Has that been removed or renamed?
Before it was located in namespace Litium.Accelerator.ValidationRules but found in Litium.Application.dll
Litium version: 8.4.0
It was removed as part of this bug: https://docs.litium.com/support/bugs/bug_details?id=60086
Here are the implementations (DiscountValueValidation
was also removed) if needed to build upon:
using System;
using System.Linq;
using Litium.Application.Sales;
using Litium.Application.Web;
using Litium.Globalization;
using Litium.Sales;
using Litium.Sales.Factory;
using Litium.Security;
using Litium.Validations;
using Microsoft.Extensions.Localization;
namespace Litium.Accelerator.ValidationRules
{
/// <summary>
/// Validates whether product prices has not changed in cart, since last time an order calculation was done.
/// </summary>
public class ProductPricesHasNotChanged : ValidationRuleBase<ValidateCartContextArgs>
{
private readonly ISalesOrderRowFactory _salesOrderRowFactory;
private readonly SecurityContextService _securityContextService;
private readonly IStringLocalizer<ProductPricesHasNotChanged> _localizer;
private readonly CountryService _countryService;
private readonly RoundOffService _roundOffService;
private readonly CurrencyService _currencyService;
public ProductPricesHasNotChanged(
ISalesOrderRowFactory salesOrderRowFactory,
SecurityContextService securityContextService,
IStringLocalizer<ProductPricesHasNotChanged> localizer,
CountryService countryService,
RoundOffService roundOffService,
CurrencyService currencyService)
{
_salesOrderRowFactory = salesOrderRowFactory;
_securityContextService = securityContextService;
_localizer = localizer;
_countryService = countryService;
_roundOffService = roundOffService;
_currencyService = currencyService;
}
public override ValidationResult Validate(ValidateCartContextArgs entity, ValidationMode validationMode)
{
var result = new ValidationResult();
var order = entity.Cart.Order;
if (order.Rows.Count > 0)
{
var personId = order.CustomerInfo?.PersonSystemId ?? _securityContextService.GetIdentityUserSystemId() ?? Guid.Empty;
var orderRows = from orderRow in order.Rows.Where(x => x.OrderRowType == OrderRowType.Product)
let createdRow = _salesOrderRowFactory.Create(new CreateSalesOrderRowArgs
{
ArticleNumber = orderRow.ArticleNumber,
Quantity = orderRow.Quantity,
PersonSystemId = personId,
ChannelSystemId = order.ChannelSystemId ?? Guid.Empty,
CountrySystemId = _countryService.Get(order.CountryCode)?.SystemId ?? Guid.Empty,
CurrencySystemId = _currencyService.Get(order.CurrencyCode)?.SystemId ?? Guid.Empty
}).CalculateByUnitPriceIncludingVat(order.CurrencyCode, _roundOffService)
where createdRow != null
where orderRow.UnitPriceExcludingVat != createdRow.UnitPriceExcludingVat
|| orderRow.VatRate != createdRow.VatRate
select orderRow;
if (orderRows.Any())
{
result.AddError("Cart", "sales.validation.productprices.haschanged".AsWebsiteText() ?? _localizer.GetString("sales.validation.productprices.haschanged"));
}
}
return result;
}
}
}
using System;
using System.Linq;
using System.Threading.Tasks;
using Litium.Application.Web;
using Litium.Sales;
using Litium.Validations;
using Microsoft.Extensions.Localization;
namespace Litium.Application.Sales.ValidationRules
{
/// <summary>
/// Validate discount value in cart when place order
/// </summary>
public class DiscountValueValidation : ValidationRuleBase<ValidateCartContextArgs>
{
private readonly IStringLocalizer<DiscountValueValidation> _localizer;
private readonly SalesOrderBuilderFactory _salesOrderBuilderFactory;
private readonly CartContextAccessor _cartContextAccessor;
public DiscountValueValidation(
SalesOrderBuilderFactory salesOrderBuilderFactory,
CartContextAccessor cartContextAccessor,
IStringLocalizer<DiscountValueValidation> localizer)
{
_localizer = localizer;
_salesOrderBuilderFactory = salesOrderBuilderFactory;
_cartContextAccessor = cartContextAccessor;
}
public async override Task<ValidationResult> ValidateAsync(ValidateCartContextArgs entity, ValidationMode validationMode)
{
var result = new ValidationResult();
var oldDiscountValue = entity.Cart.Order.Rows.Where(x => x.OrderRowType == OrderRowType.Discount).Sum(x=>x.TotalIncludingVat);
var orderBuilder = _salesOrderBuilderFactory.Create(entity.Cart.Order, entity.Cart.DiscountCodes);
var newOrder = orderBuilder.Build();
var newDiscountValue = newOrder.Rows.Where(x => x.OrderRowType == OrderRowType.Discount).Sum(x => x.TotalIncludingVat);
if (oldDiscountValue != newDiscountValue)
{
var cartContext = _cartContextAccessor.CartContext;
var shippingOption = cartContext.Cart.Order.ShippingInfo.FirstOrDefault()?.ShippingOption;
if (shippingOption is not null)
{
var selectShippingOptionArgs = new SelectShippingOptionArgs
{
ShippingOptionId = shippingOption
};
//recall select shipping for update the value of order in cart
await cartContext.SelectShippingOptionAsync(selectShippingOptionArgs);
}
result.AddError("Cart", "sales.validation.ordertotal.haschanged".AsWebsiteText() ?? _localizer.GetString("sales.validation.ordertotal.haschanged"));
}
return result;
}
public override ValidationResult Validate(ValidateCartContextArgs entity, ValidationMode validationMode)
{
throw new NotSupportedException("Validation need to be done async.");
}
}
}
This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.