2

Through observing the event checkout_cart_product_add_after, I was able to customize the price of the item in the cart, now I need to have an observer for customizing its subtotal calculation. What event/events need to be observed?

Is it possible to customize the calculation like $cart->setQuote()->getSubtotal() in observer and save the quote?

And basically, can it be done through observer or plugin is the solution?

Edit:

Here is my current event:

<event name="sales_quote_collect_totals_before">
        <observer name="customuitemprice" instance="vendor\code\Observer\BindUpdateItem"/>
    </event>

Observer:

class BindUpdateItem implements ObserverInterface
{
    public function execute(\Magento\Framework\Event\Observer $observer)
    {
        $quote = $observer->getQuote();
        foreach ($quote->getAllItems() as $item)
        {
            $product = $item->getProduct();
            ?How change the subtotal?

        }
        return $this;
    }
}
0

I managed to changed the sub total for any item, here is the code:

$item->setCustomRowTotalPrice($item->getCustomPrice() * $item->getQty());
$item->setRowTotal($item->getCustomPrice() * $item->getQty());
$item->setBaseRowTotal($item->getCustomPrice() * $item->getQty());

This should be ok. This code couldn't work properly if you are running the function

calcRowTotal()

which calculate again the sub total for each item in the cart again overwriting your change.

Let me know if you have luck.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.