Hello
I'm using Commercer 12.8.1
I have also tried to update to Commerce 12.17.2, but the issue is still the same with newer version.
The goal: Change products on a created Purchaseorder (Add / Remove / Update products in a placed order)
I'm doing this in steps.
- Getting a diff of changes
- Removing all old LineItems
- Adding the new set of items
- Adjusting any payments
I can see from the debugger and the Database the all new LineItems are saved to the DB after step 3. (If I return the function here all look as expected, except of course that payment totals are wrong.)
I then start with the process of getting new totals.
When I here run
_orderRepository.Service.Save(order);
some, but not all LineItems are removed from the order. This happens before I run ProcessPayments, but after that I have new totals calcualted.
We have a filter to exclude some items for discount calculations, and the items that are removed from the order are part of this filter. If I comment out the specific product types in this filter, the code works as intended and payments are handled correctly as well
However, this is a filter that we trigger only for discount calculation, and no breakpoints I set here are triggered when I step over the save frunction from OrderRepository.
I have also checked in the events triggered for PurchaseOrder.
In OnUpdating all LineItems are present, but in OnUpdated some are removed.
This only seem to happen for products that are part of our custom filter, but I can't understand why this should be triggerd in Save at a specific time, sine it does not always do so. And IF it is this filter that is getting triggered from the Save method, why I cant see this from breakpoints or logging when I run the application?
In what cases are LineItems removed from an order when _orderRepository.Service.Save(order);
is called?
I have also setup a custom ILineItemValidator that simply adds logging if a LineItem is removed due to being invalid in some way, but this is not triggered before the removal of the LineItem either.
Is there any other form of LineItemValidation that is done in the saving of PurchaseOrder that might affect my order that I can look at for more info?
We do not use Inventory tracking for any productsin the catalog.