Magento – apply custom discount in cart magento2 via observer

magento2promotionssalesshopping-cart-price-rules

I have created a custom promotion in magento2. To get that working I needed to do some customization in cart which I am trying to do with salesrule_validator_process event.
I needed the rulename and discount values to be modified before applying in cart.

Now In Magento1 we used to update values as below:

$result = $observer['result'];

$result->setDiscountAmount($DiscountAmount);

$result->setBaseDiscountAmount($BaseDiscountAmount);

How we can achieve the same in Magento2?

Any thoughts/suggestions are welcome.

Best Answer

You can apply discount amount in magento2 by same event just write below code in your observer file:

$result = $observer->getEvent()->getResult();

$result->setAmount($DiscountAmoun);

$result->setBaseAmount($DiscountAmoun); 
Related Topic