I have built my own OrderPromotionProcessorBase to handle order discounts.
[ServiceConfiguration(Lifecycle = ServiceInstanceScope.Singleton)]
public class CustomSpendAmountGetOrderDiscountProcessor : OrderPromotionProcessorBase
It works every now and then. It works just fine for a while and suddenly it stops working and the default behavior is back.
Is there some way to configure so that Commerce always uses my custom processor and not the default one?
Sounds like a bug to me. Check the places where it's not used and reflect the code to see if somewhere the code is not using it injected, but instancing it instead.
Adding the ServiceConfiguration attribute will add your type to the container, but it will not remove the existing ones. What if you evict the existing one, the one you want to replace, from the container (usually done in an initialization module)?
I also wonder if you might need to set ServiceType="typeof(OrderPromotionProcessorBase<SpendAmountGetOrderDiscount>)" on the ServiceConfiguration. If no ServiceType is set that means that it will be registered for the current type, in this case CustomSpendAmountGetOrderDiscountProcessor.
If you want to look into how the processor resolving is done, it is handled by the class EPiServer.Commerce.Marketing.PromotionProcessorResolver. It is also possible to replace that resolver, if you want to modify the logic.
One easier approach is to set your processor Priority to higher value, for example, 100. This will make sure it is chosen everytime.
I'll log a bug for it. - Or maybe not. The Priority property is what needs to be overriden...
I'll log a bug for it.
Thanks Per and Quan!
Actually both ways works. Either setting the ServiceType or override the Priority.