cancel
Showing results for 
Search instead for 
Did you mean: 

Setting custom subtotal for item when being added to cart?

Setting custom subtotal for item when being added to cart?

I am running a Magento 2.4 shop and am trying to set an items subtotal. I tried with several events, nothing works so far. The events I tried are sales_quote_product_add_after, sales_quote_collect_totals_before and checkout_cart_product_add_after.

 

Nothing worked so far, setting a custom price or the qty works without problems with any of the events. This is the code I used to set price and subtotal:

 

$item->setQty(4); // works
$item->setCustomPrice(100); // works
$item->setOriginalCustomPrice(100); // works
$item->setRowTotal(250); // does NOT work
$item->setSubTotal(250); // does NOT work
$item->getProduct()->setIsSuperMode(true);

The subtotal is always the result of qty * price, in my case 4 * 100 = 400 (not 250). Any ideas what else I can try or what might be wrong?

 

Thanks!