0

I've been struggling with this issue for the past few weeks now.

My goal is to set a custom price for an item after I edit them on Cart.

Basically, I'm using an observer on the event checkout_cart_update_item_complete, and on that observer I eventually do the following:

$item->setCustomPrice($price);
$item->setOriginalCustomPrice($price);
$item->getProduct()->setIsSuperMode(true);
$item->save();

Where $item is the new quote item after the update (check Magento\Checkout\Controller\Cart\UpdateItemOptions.php) and $price is my custom price.

After this, the quote item price gets the value of 0, even though the custom_price field on database is actually the value that I wanted.

Any help is appreciated :)

  • have you check that the controller comes in that file or not? – Balwant Singh Dec 4 '18 at 17:38
0

Try to write your custom code under process() function.

vendor\magento\module-sales-rule\Model\Validator.php

/**
     * Quote item discount calculation process
     *
     * @param AbstractItem $item
     * @return $this
     */
    public function process(AbstractItem $item)
    {
     ..............
     ..............
     $price = 50;
     $item->setCustomPrice($price);
     $item->setOriginalCustomPrice($price);
     $item->getProduct()->setIsSuperMode(true);
     ..............
     ..............

    }

NOTE: Don't use $item->save() once and try.

I hope it help..!!

  • Tried it, didn't work :( even without the $item->save(). Thanks anyways! – gasparrmg Dec 5 '18 at 9:50
  • @gasparrmg have you tried your code in this vendor\magento\module-sales-rule\Model\Validator.php file? – Balwant Singh Dec 5 '18 at 10:00
  • Yes, it did not work. But even if it did, I wanted to this through my observer and not by extending/overriding this class :/ – gasparrmg Dec 5 '18 at 10:01
  • @BalwantSingh, same i am facing, without save() also its not working – jafar pinjar Mar 1 at 16:21
  • It is not working. – Dhaduk Mitesh Apr 22 at 7:33

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.