We sacrifice by not doing any other technology, so that you get the best of Magento.

We sacrifice by not doing any other technology, so that you get the best of Magento.

Create events.xml file in folder ‘Magemonkeys/Cartmodule/etc/frontend’ and use event ‘checkout_cart_product_add_after’. And paste the below code in it.

<?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="checkout_cart_product_add_after">
        <observer name="addprice" instance="MagemonkeysCartmoduleObserverAddPrice" />
    </event>
</config>

And now create ‘AddPrice.php’ file in ‘Observer’ folder with the following code:

<?php
    namespace MagemonkeysCartmoduleObserver;
 
    use MagentoFrameworkEventObserverInterface;
    use MagentoFrameworkAppRequestInterface;
 
    class AddPrice implements ObserverInterface
    {
        public function execute(MagentoFrameworkEventObserver $observer) {
            $item = $observer->getEvent()->getData('quote_item');         
            $item = ( $item->getParentItem() ? $item->getParentItem() : $item );
            $price = 50; // set custom price here
            $item->setCustomPrice($price);
            $item->setOriginalCustomPrice($price);
            $item->getProduct()->setIsSuperMode(true);
        }
 
    }
?>

 

Fill the below form if you have any Magento programming need.

    Recent Articles
    Get a Free Quote

      Let’s initiate a discussion!!