How to add manual order promotion?

Vote:
 

I am trying to add a manual order promotion same way as it is possible to add a manual line item promotion.

For a line item this works:

private static void AddDiscount(
    IOrderForm orderForm,
    string lineItemCode,
    decimal discountValue,
    string discountName)
{
    var promotionInformation = new PromotionInformation
    {
        Name = discountName,
        Description = discountName,
        DiscountType = EPiServer.Commerce.Marketing.DiscountType.Manual,
        Entries = new List
        {
            new PromotionInformationEntry
            {
                EntryCode = lineItemCode,
                SavedAmount = discountValue
            }
        },
        OrderForm = new PromotionInformationOrderForm
        {
            SavedAmount = 0
        }
    };
    orderForm.Promotions.Add(promotionInformation);
}

I tried to add a manual discount for the order form same way:

private void AddDiscount(IOrderForm orderForm, decimal discountValue, string discountName)
{
    var promotionInformation = new PromotionInformation
    {
        Name = discountName,
        Description = discountName,
        DiscountType = EPiServer.Commerce.Marketing.DiscountType.Manual,
        Entries = new List(),
        OrderForm = new PromotionInformationOrderForm
        {
            SavedAmount = discountValue
        }
    };
    orderForm.Promotions.Add(promotionInformation);
}

But after I run promotions this way:

cart.ApplyDiscounts(_promotionEngine, new PromotionEngineSettings());

Episerver removes my manual order promotion and does not apply it.

What is the correct way to add manual promotion to the whole order?

#177181
Apr 05, 2017 7:47
Vote:
 

Hi,

About manual discount, we support it only for line item. It is not supported for shipment/order level. That's from the old promotion system. As you can see, in Commerce Manager, you can add manual discount for line items when adding item to the cart/order and that's only place where you can add manual discount in Commerce Manager.

#177183
Apr 05, 2017 8:56
Vote:
 

That's sad. It is a common requirement for admins to be able to set any amount/percent discounts to the whole order. As it was not working in Commerce Manger, we are implementing it in the separate module.

Any other options to achieve this? Also, can I rely on the manual discounts for line items in future?

#177185
Apr 05, 2017 9:16
Vote:
 

Hi,

Yes, the manual discounts for line items will still be there. It's active feature and we have no plan to change/replace it.

But that's a good point. Manual order/shipment-level discount would be a nice addition. I can imagine the scenarios where that would make senses. No promises yet, but we will look into it.

Thanks,

/Q

#177197
Apr 05, 2017 10:54
Vote:
 

Hello Maris!

I have a suggestion you could try, it's not super straight forward but here it goes:

From the user interface you could set the manually discounted value on your own meta field ("ManualDiscount" or something) on the desired level (Shipment, OrderForm, OrderGroup), instead of creating PromotionInformation at that point.

Then you can add code that runs AFTER you run the promotion engine to create the promotioninformation for the manual discount, based on the data stored in your meta field.

You'll have to manually add the discount amount to the OrderForm / Shipment as well after the fact since the promotion enginge won't do it for you.

We do something similar in a project, but the discount is dynamically generated instead of manually set. Since we make use of workflows it is done in the CalculateDiscountVNextActivity, right after the PromotionEngine.Run() is called.

#177412
Edited, Apr 11, 2017 10:14
Vote:
 

Actually, I wrote a blog post yesterday about manual order discount: http://marisks.net/2017/04/09/manual-order-discount/

#177416
Apr 11, 2017 11:02
Vote:
 

Nice approach with doing it in a processor. :)

Want some feedback on your implementation example?

#177419
Apr 11, 2017 11:27
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.