Hello everyone
I have an issue when using the EcomCartLineAddedObserver. I've added two fields in the admin panel. The first is a Orderfield which contains a comma-separated list of single-letter values, example: (A,U). This list represents a select in the front-end, where the choice is stored in a Orderlinefield. The product is added using these parameters: "productid=<id>&cartcmd=add&EcomOrderLineFieldInput_Binding=U&Quantity=1" and so far everything is fine.
The issue then surfaces for some of our "special" users, that should not have option 'A'. This works fine in the front-end, and i've even implemented a EcomCartLineAddedObserver that validates the values set in EcomOrderLineFieldInput_Binding. The logic will set the value to 'U', if the submitted is deemed incorrect, but this is where a orderline duplication can happen.
Lets say a "special" user, that is abit more clever than the rest, has added a product with the above parameters, where "EcomOrderLineFieldInput_Binding=U". The user then manually submits a new product with "EcomOrderLineFieldInput_Binding=A". The logic i implemented then kicks in for the second product and changes the OrderLineFieldValue to 'U'. It does this (simplified) by getting:
bindingValue = orderLine.OrderLineFieldValues.First(x => x.OrderLineFieldSystemName == "Binding");
bindingValue.Value = "U";
When the user then navigates to his/her cart, there is TWO identical orderlines. I've noticed the eCom cart can automaticly merge orderlines when editing the binding on the orderline through the Cart, but this does not happen if the two orderlines become identical, due to some logic in a EcomCartLineAddedObserver. I imagine the validation of the cart runs before NotificationSubscribers.
I cannot find any observer that can be used for validation of the product before a orderline is created, so should i implement some manual logic for handling this type of case, using orderLine.CanBeMerged(line), or do you have another suggestion?
Best Regards, Jeppe.