I want to apply a custom price for the current order. I read that I should use sales_quote_add_item, But its looks like I am doing something wrong. I found some tutorials for magento1 but not for Magento 2. So please let me know what I am doing wrong.
app/code/Myvendor/HelloMagento/etc/adminhtml/events.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
<event name="sales_quote_add_item">
<observer name="change_hello_magento_display" instance="Myvendor\Addtocart\Observer\Change" />
</event>
</config>
app/code/Myvendor/HelloMagento/Observer/Change.php
<?php
namespace Myvendor\Addtocart\Observer;
class Change implements \Magento\Framework\Event\ObserverInterface
{
public function execute(\Magento\Framework\Event\Observer $observer)
{
$event = $observer->getEvent();
$quote_item = $event->getQuoteItem();
$new_price = 987;
$quote_item->setOriginalCustomPrice($new_price);
$quote_item->save();
}
}
Let me know please what I am doing wrong. I want to achieve the same thing for Magento 2 given on below link for magento1.