Let’s initiate a discussion!!
Firstly, we have to create a custom module.
Then, we have to declare a file named events.xml to catch an event that takes place after a product is added to the cart.
Create events.xml file at the following path Magemonkeys/CustomPriceInCart/etc/frontend/events.xml
1 2 3 4 5 6 |
<?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="CustomPriceInCart" instance="Magemonkeys\CustomPriceInCart\Observer\CustomPriceInCart" /> </event> </config> |
The next step is to create the observer to make changes to the price.
Create CustomPriceInCart.php file at the following path Magemonkeys/CustomPriceInCart/Observer/CustomPriceInCart.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
<?php namespace Magemonkeys\CustomPriceInCart\Observer; use Magento\Framework\Event\ObserverInterface; use Magento\Framework\App\RequestInterface; class CustomPriceInCart implements ObserverInterface { public function execute(\Magento\Framework\Event\Observer $observer) { $item = $observer->getEvent()->getData('quote_item'); $item = ($item->getParentItem() ? $item->getParentItem() : $item); // here your custom price goes $customPrice = 101; $item->setCustomPrice($customPrice); $item->setOriginalCustomPrice($customPrice); $item->getProduct()->setIsSuperMode(true); } } |
By turning on super mode to the product through function setIsSuperMode(true), we can stop the system generating the price.
Then we can set the custom prices for products in the cart.
[crayon-641fabdedd06f733139411/] Using above fucntion Images can be imported directly from...
Override view block using di.xml and add the below code...
You can check a list of called layout XML for...
Follow the below steps to install and set up PWA...
If you want to remove all leading zero's from order,...
Let our Magento expert connect to discuss your requirement.
We offer Magento
certified developers.
Our Magento clientele
is 500+.
We sign NDA for the
security of your projects.
We’ve performed 100+
Magento migration projects.
Free quotation
on your project.
Three months warranty on
code developed by us.