adding validation on the ShipmentMethodCode#68
adding validation on the ShipmentMethodCode#68AhmedElmehalawi wants to merge 1 commit intoVirtoCommerce:devfrom
Conversation
|
|
|
Review task created: https://virtocommerce.atlassian.net/browse/VCST-3723 |
|
Moved to #74. Closing this one. |
|
This is accepted behavior since we could create an empty shipment without a code, for example a shipment with only address while a specific shipment method was not selected by the user. What kind of issues do you have with this behavior? |
I don't see it as a valid business case, how you will validate on the price of this unknown shipment? The request can be intercepted and any value can be sent to the backend without any validation on the price amount. |
|
Creating a shipment object without the code is a valid business case for us. Shipment validator will be invoked before creating an order so in case of invalid shipment price the order will not be created.
public class CartShipmentValidator2 : CartShipmentValidator
{
public CartShipmentValidator2()
{
RuleFor(x => x).Custom((shipmentContext, context) =>
{
if (string.IsNullOrWhiteSpace(shipmentContext.Shipment.ShipmentMethodCode))
{
context.AddFailure(new CartValidationError(shipmentContext.Shipment, "ShipmentMethodCode is Mandatory", "SHIPMENT_METHOD_CODE_IS_MANDATORY"));
}
});
}
}
public void PostInitialize(IApplicationBuilder appBuilder)
{
AbstractTypeFactory<CartShipmentValidator>.OverrideType<CartShipmentValidator, CartShipmentValidator2>();
}Upon calling AddOrUpdateCartShipment the validators will be executed in the following sequence: CartShipmentValidator -> CartShipmentValidator2. |
Description
adding validation on the ShipmentMethodCode to be mandatory sent.
Issue
On the AddOrUpdateCartShipment mutaion, if the ShipmentMethodCode is not sent, a new shipment with null ShipmentMethodCode is being created which causes a lot of issues.