NickFrederiksen
02/10/2025, 2:54 PMNotificationEventHandlerBase<OrderProductAddingNotification>
and look at the values that are passed into the handler.
Lo and behold, there is a property called Properties
. It's a dictionary that can be manipulated, eg. not an IReadOnlyDictionary
. It is also not marked as nullable so I figured I could use that. Digging through some decompiled code, it actually seems that the values in this property will be added to the orderline. Excellent.
However.
The Properties
property on the OrderProductAddingNotification
object is null
and only has a getter so I wont be able to instantiate the property my self.
I also tried the OrderProductAddedNotification
, same result and the OrderLineAddingNotification
only has a readonly dictionary.
So, how do I set properties on an orderline, whenever a product is added?
I'm using Umbraco Commerce 15.0.1Sander L
02/10/2025, 3:05 PMvar order = _commerceApi.GetOrCreateCurrentOrder(store.Id)
.AsWritable(uow);
foreach (var orderLine in order.OrderLines)
{
order.WithOrderLine(orderLine.Id).SetQuantity(2).SetProperties(new Dictionary<string, string>
{
{ "key1", "value1" },
});
}
NickFrederiksen
02/11/2025, 7:37 AMNickFrederiksen
02/11/2025, 7:37 AMOrderProductAddingNotification
handler. As I understand it, this event is fired before the line is event created.Mike Chambers
02/11/2025, 6:01 PM"In the Commerce API, everything is read-only for performance so you need to make it writable to add the product."
https://docs.umbraco.com/umbraco-commerce/how-to-guides/delete-item tucked away here.. so making writeable would be the preferred way?Sander L
02/12/2025, 5:39 AMMike Chambers
02/12/2025, 8:57 AMNickFrederiksen
02/12/2025, 8:59 AMOrderLineAddingNotification
route. But it's weird there are multiple notifications that suggests doing the same thing.
But the documentation contradicts itself. It either implies that I should create a single handler that handles everything per notification, or many handlers. If I create multiple handlers, It's unclear that they will be run sequentially or parallel.
This page, https://docs.umbraco.com/umbraco-commerce/key-concepts/unit-of-work, tells me that I should have all writes in a single unit of work. But in a multi-handler scenario, that would be impossible. And a single handler scenario can easily become very crowded and complex.
I went with a single handler and implementing my own pipeline to handle edits in a sequential way wrapped in a single unit of work. However, the pipeline api is badly documented as well. What I learned, is that all tasks are singleton. This makes injecting services difficult. I went with injecting the IFactory
service and requesting services through this. But I'm not sure if this is the preferred way of doing it.NickFrederiksen
02/12/2025, 9:55 AMOrderLineAddingNotification
handler, how do I prevent the line being added if some case is present? Eg. "you cannot add this product because xyz".Mike Chambers
02/12/2025, 10:20 AMnotification.CancelOperation()
in other umbraco notification handlers.NickFrederiksen
02/12/2025, 10:47 AMOrderLineAddingNotification
or OrderLineChangingNotification
Mike Chambers
02/12/2025, 11:06 AMMike Chambers
02/12/2025, 11:15 AMOrderLineChangingNotification
any use?NickFrederiksen
02/12/2025, 11:19 AMMike Chambers
02/12/2025, 11:21 AMNickFrederiksen
02/12/2025, 12:09 PM