I have built a custom salesrule which implements the DiscountInterface.

When the sales rules criteria is met, the calculate() method runs on the for each product in the cart.

Rather than apply a discount to the products, I want to change the actual price.

So I have something like

public function calculate($rule, $item, $qty)
    $discountData = $this->discountFactory->create();
    $fixedPrice = 1;
    if ($item->getSku() == "SKU01")
    return $discountData;

This correctly updates the prices for the product in my cart.

However, if I remove another item from the cart, which negates the sales rule criteria, I would like the price to revert to it's previous state.

This doesn't happen through because the calculate() is not run again.

I suppose I could plugin to cart update observer or plugin, but that seems a little convoluted.

Any suggestions?

  • this wrong logic to set price using setOriginalCustomPrice during discount calculation. – Amit Bera Jun 5 at 13:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.