Custom price of product not getting applied in cart in Magento 2How can i rewrite TierPrice Block in Magento2magento 2 captcha not rendering if I override layout xmlmain.CRITICAL: Plugin class doesn't existSet custom price of product when adding to cart code not workingWhat is the event after total calculation of cart item in Magento 2 using PluginMagento 2: Add a product to the cart programmaticallyMagento 2.2.5: Overriding Admin Controller sales/orderMagento 2: After custom cookie is created all pages default to home pageI have created one field using product form field for my price i want save my field value at product creation time from backend magento2Magento 2.2.5: Add, Update and Delete existing products Custom Options

Why are there no stars visible in cislunar space?

How to test the sharpness of a knife?

What is the tangent at a sharp point on a curve?

Writing in a Christian voice

Animating wave motion in water

How to read string as hex number in bash?

Imaginary part of expression too difficult to calculate

CLI: Get information Ubuntu releases

Why is "la Gestapo" feminine?

How do researchers send unsolicited emails asking for feedback on their works?

How can I create URL shortcuts/redirects for task/diff IDs in Phabricator?

The English Debate

Jem'Hadar, something strange about their life expectancy

Did Nintendo change its mind about 68000 SNES?

Determine voltage drop over 10G resistors with cheap multimeter

Can a university suspend a student even when he has left university?

Interior of Set Notation

Knife as defense against stray dogs

Why is this tree refusing to shed its dead leaves?

DisplayForm problem with pi in FractionBox

Why is there so much iron?

Can other pieces capture a threatening piece and prevent a checkmate?

TDE Master Key Rotation

Would this string work as string?



Custom price of product not getting applied in cart in Magento 2


How can i rewrite TierPrice Block in Magento2magento 2 captcha not rendering if I override layout xmlmain.CRITICAL: Plugin class doesn't existSet custom price of product when adding to cart code not workingWhat is the event after total calculation of cart item in Magento 2 using PluginMagento 2: Add a product to the cart programmaticallyMagento 2.2.5: Overriding Admin Controller sales/orderMagento 2: After custom cookie is created all pages default to home pageI have created one field using product form field for my price i want save my field value at product creation time from backend magento2Magento 2.2.5: Add, Update and Delete existing products Custom Options













0















I am trying to set the custom price of product to cart using Magento2 but unable to do that. For that I have created a module TW - as namespace Cart- as Module name . So under TW/Cart I have created 2 folders etc and Observer. Below is the code in respective folders. Do i need to register this module by putting registration.php file under this module ? Please help me what am I doing wrong?



Code for etc/frontend/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="checkout_cart_product_add_after">
<observer name="cart_observer_customprice" instance="TWCartObserverCustomPrice" />
</event>
</config>


Code for Observer/CustomPrice.php



namespace TWCartObserver;
use MagentoFrameworkEventObserverInterface;
use MagentoFrameworkAppRequestInterface;
use PsrLogLoggerInterface;

class CustomPrice implements ObserverInterface

protected $logger;
public function __construct(LoggerInterface $logger)

$this->logger = $logger;

public function execute(MagentoFrameworkEventObserver $observer)


$item = $observer->getEvent()->getData('quote_item');
$item = ( $item->getParentItem() ? $item->getParentItem() : $item );
$price = 120; //set your price here
$this->logger->debug("Hello I am here", [
'price' => $price,
]);
$item->setCustomPrice($price);
$item->setOriginalCustomPrice($price);
$item->getProduct()->setIsSuperMode(true);












share|improve this question














bumped to the homepage by Community 13 hours ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.










  • 1





    Yes you have to create registration.php and enable your module first.

    – Emipro Technologies Pvt. Ltd.
    Jul 4 '17 at 10:14















0















I am trying to set the custom price of product to cart using Magento2 but unable to do that. For that I have created a module TW - as namespace Cart- as Module name . So under TW/Cart I have created 2 folders etc and Observer. Below is the code in respective folders. Do i need to register this module by putting registration.php file under this module ? Please help me what am I doing wrong?



Code for etc/frontend/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="checkout_cart_product_add_after">
<observer name="cart_observer_customprice" instance="TWCartObserverCustomPrice" />
</event>
</config>


Code for Observer/CustomPrice.php



namespace TWCartObserver;
use MagentoFrameworkEventObserverInterface;
use MagentoFrameworkAppRequestInterface;
use PsrLogLoggerInterface;

class CustomPrice implements ObserverInterface

protected $logger;
public function __construct(LoggerInterface $logger)

$this->logger = $logger;

public function execute(MagentoFrameworkEventObserver $observer)


$item = $observer->getEvent()->getData('quote_item');
$item = ( $item->getParentItem() ? $item->getParentItem() : $item );
$price = 120; //set your price here
$this->logger->debug("Hello I am here", [
'price' => $price,
]);
$item->setCustomPrice($price);
$item->setOriginalCustomPrice($price);
$item->getProduct()->setIsSuperMode(true);












share|improve this question














bumped to the homepage by Community 13 hours ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.










  • 1





    Yes you have to create registration.php and enable your module first.

    – Emipro Technologies Pvt. Ltd.
    Jul 4 '17 at 10:14













0












0








0


0






I am trying to set the custom price of product to cart using Magento2 but unable to do that. For that I have created a module TW - as namespace Cart- as Module name . So under TW/Cart I have created 2 folders etc and Observer. Below is the code in respective folders. Do i need to register this module by putting registration.php file under this module ? Please help me what am I doing wrong?



Code for etc/frontend/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="checkout_cart_product_add_after">
<observer name="cart_observer_customprice" instance="TWCartObserverCustomPrice" />
</event>
</config>


Code for Observer/CustomPrice.php



namespace TWCartObserver;
use MagentoFrameworkEventObserverInterface;
use MagentoFrameworkAppRequestInterface;
use PsrLogLoggerInterface;

class CustomPrice implements ObserverInterface

protected $logger;
public function __construct(LoggerInterface $logger)

$this->logger = $logger;

public function execute(MagentoFrameworkEventObserver $observer)


$item = $observer->getEvent()->getData('quote_item');
$item = ( $item->getParentItem() ? $item->getParentItem() : $item );
$price = 120; //set your price here
$this->logger->debug("Hello I am here", [
'price' => $price,
]);
$item->setCustomPrice($price);
$item->setOriginalCustomPrice($price);
$item->getProduct()->setIsSuperMode(true);












share|improve this question














I am trying to set the custom price of product to cart using Magento2 but unable to do that. For that I have created a module TW - as namespace Cart- as Module name . So under TW/Cart I have created 2 folders etc and Observer. Below is the code in respective folders. Do i need to register this module by putting registration.php file under this module ? Please help me what am I doing wrong?



Code for etc/frontend/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="checkout_cart_product_add_after">
<observer name="cart_observer_customprice" instance="TWCartObserverCustomPrice" />
</event>
</config>


Code for Observer/CustomPrice.php



namespace TWCartObserver;
use MagentoFrameworkEventObserverInterface;
use MagentoFrameworkAppRequestInterface;
use PsrLogLoggerInterface;

class CustomPrice implements ObserverInterface

protected $logger;
public function __construct(LoggerInterface $logger)

$this->logger = $logger;

public function execute(MagentoFrameworkEventObserver $observer)


$item = $observer->getEvent()->getData('quote_item');
$item = ( $item->getParentItem() ? $item->getParentItem() : $item );
$price = 120; //set your price here
$this->logger->debug("Hello I am here", [
'price' => $price,
]);
$item->setCustomPrice($price);
$item->setOriginalCustomPrice($price);
$item->getProduct()->setIsSuperMode(true);









magento2 event-observer magento-2.1.7 custom-prices






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jul 4 '17 at 10:06









ssnegissnegi

227




227





bumped to the homepage by Community 13 hours ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







bumped to the homepage by Community 13 hours ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.









  • 1





    Yes you have to create registration.php and enable your module first.

    – Emipro Technologies Pvt. Ltd.
    Jul 4 '17 at 10:14












  • 1





    Yes you have to create registration.php and enable your module first.

    – Emipro Technologies Pvt. Ltd.
    Jul 4 '17 at 10:14







1




1





Yes you have to create registration.php and enable your module first.

– Emipro Technologies Pvt. Ltd.
Jul 4 '17 at 10:14





Yes you have to create registration.php and enable your module first.

– Emipro Technologies Pvt. Ltd.
Jul 4 '17 at 10:14










1 Answer
1






active

oldest

votes


















0















First create a module using free module creator tool called silk software




Magento 2 Module Creator Tool Using Silk Software



and enable using following commands below.



  1. php bin/magento module:enable Tw_Cart

  2. php bin/magento setup:upgrade

  3. php bin/magento setup:di:compile

  4. php bin/magento setup:static-content:deploy


create events.xml in the path:- app/code/Tw/Cart/etc/frontend/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="checkout_cart_product_add_after">
<observer name="Tw_Cart_Addtocart_Customprice" instance="TWCartObserverCustomPrice" />
</event>
</config>



create CustomPrice.php in the path: app/code/Tw/Cart/Observer/ & keep the below code




<?php
namespace TWCartObserver;
use MagentoFrameworkEventObserverInterface;
use MagentoFrameworkAppRequestInterface;
use PsrLogLoggerInterface;
class CustomPrice implements ObserverInterface


public function execute(MagentoFrameworkEventObserver $observer)

$writer = new ZendLogWriterStream(BP.'/var/log/stackexchange.log');
$logger = new ZendLogLogger();
$logger->addWriter($writer);
/* Code here */
$quote_item = $observer->getEvent()->getQuoteItem();
$price = 400; //set your price here
$quote_item->setCustomPrice($price);
$quote_item->setOriginalCustomPrice($price);
$quote_item->getProduct()->setIsSuperMode(true);
$logger->info("success !!!!");








share|improve this answer

























  • I tried to vote .. but it does not allow me to do so :(

    – ssnegi
    Jul 5 '17 at 9:55











  • Tried This, product is added with custom price in cart, but in summary original product price is showing... any update on this..?

    – Rizwan
    Nov 17 '17 at 11:13











  • could you please share me screenshot thanks

    – Nagaraju Kasa
    Nov 17 '17 at 11:38










Your Answer








StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "479"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f181945%2fcustom-price-of-product-not-getting-applied-in-cart-in-magento-2%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0















First create a module using free module creator tool called silk software




Magento 2 Module Creator Tool Using Silk Software



and enable using following commands below.



  1. php bin/magento module:enable Tw_Cart

  2. php bin/magento setup:upgrade

  3. php bin/magento setup:di:compile

  4. php bin/magento setup:static-content:deploy


create events.xml in the path:- app/code/Tw/Cart/etc/frontend/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="checkout_cart_product_add_after">
<observer name="Tw_Cart_Addtocart_Customprice" instance="TWCartObserverCustomPrice" />
</event>
</config>



create CustomPrice.php in the path: app/code/Tw/Cart/Observer/ & keep the below code




<?php
namespace TWCartObserver;
use MagentoFrameworkEventObserverInterface;
use MagentoFrameworkAppRequestInterface;
use PsrLogLoggerInterface;
class CustomPrice implements ObserverInterface


public function execute(MagentoFrameworkEventObserver $observer)

$writer = new ZendLogWriterStream(BP.'/var/log/stackexchange.log');
$logger = new ZendLogLogger();
$logger->addWriter($writer);
/* Code here */
$quote_item = $observer->getEvent()->getQuoteItem();
$price = 400; //set your price here
$quote_item->setCustomPrice($price);
$quote_item->setOriginalCustomPrice($price);
$quote_item->getProduct()->setIsSuperMode(true);
$logger->info("success !!!!");








share|improve this answer

























  • I tried to vote .. but it does not allow me to do so :(

    – ssnegi
    Jul 5 '17 at 9:55











  • Tried This, product is added with custom price in cart, but in summary original product price is showing... any update on this..?

    – Rizwan
    Nov 17 '17 at 11:13











  • could you please share me screenshot thanks

    – Nagaraju Kasa
    Nov 17 '17 at 11:38















0















First create a module using free module creator tool called silk software




Magento 2 Module Creator Tool Using Silk Software



and enable using following commands below.



  1. php bin/magento module:enable Tw_Cart

  2. php bin/magento setup:upgrade

  3. php bin/magento setup:di:compile

  4. php bin/magento setup:static-content:deploy


create events.xml in the path:- app/code/Tw/Cart/etc/frontend/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="checkout_cart_product_add_after">
<observer name="Tw_Cart_Addtocart_Customprice" instance="TWCartObserverCustomPrice" />
</event>
</config>



create CustomPrice.php in the path: app/code/Tw/Cart/Observer/ & keep the below code




<?php
namespace TWCartObserver;
use MagentoFrameworkEventObserverInterface;
use MagentoFrameworkAppRequestInterface;
use PsrLogLoggerInterface;
class CustomPrice implements ObserverInterface


public function execute(MagentoFrameworkEventObserver $observer)

$writer = new ZendLogWriterStream(BP.'/var/log/stackexchange.log');
$logger = new ZendLogLogger();
$logger->addWriter($writer);
/* Code here */
$quote_item = $observer->getEvent()->getQuoteItem();
$price = 400; //set your price here
$quote_item->setCustomPrice($price);
$quote_item->setOriginalCustomPrice($price);
$quote_item->getProduct()->setIsSuperMode(true);
$logger->info("success !!!!");








share|improve this answer

























  • I tried to vote .. but it does not allow me to do so :(

    – ssnegi
    Jul 5 '17 at 9:55











  • Tried This, product is added with custom price in cart, but in summary original product price is showing... any update on this..?

    – Rizwan
    Nov 17 '17 at 11:13











  • could you please share me screenshot thanks

    – Nagaraju Kasa
    Nov 17 '17 at 11:38













0












0








0








First create a module using free module creator tool called silk software




Magento 2 Module Creator Tool Using Silk Software



and enable using following commands below.



  1. php bin/magento module:enable Tw_Cart

  2. php bin/magento setup:upgrade

  3. php bin/magento setup:di:compile

  4. php bin/magento setup:static-content:deploy


create events.xml in the path:- app/code/Tw/Cart/etc/frontend/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="checkout_cart_product_add_after">
<observer name="Tw_Cart_Addtocart_Customprice" instance="TWCartObserverCustomPrice" />
</event>
</config>



create CustomPrice.php in the path: app/code/Tw/Cart/Observer/ & keep the below code




<?php
namespace TWCartObserver;
use MagentoFrameworkEventObserverInterface;
use MagentoFrameworkAppRequestInterface;
use PsrLogLoggerInterface;
class CustomPrice implements ObserverInterface


public function execute(MagentoFrameworkEventObserver $observer)

$writer = new ZendLogWriterStream(BP.'/var/log/stackexchange.log');
$logger = new ZendLogLogger();
$logger->addWriter($writer);
/* Code here */
$quote_item = $observer->getEvent()->getQuoteItem();
$price = 400; //set your price here
$quote_item->setCustomPrice($price);
$quote_item->setOriginalCustomPrice($price);
$quote_item->getProduct()->setIsSuperMode(true);
$logger->info("success !!!!");








share|improve this answer
















First create a module using free module creator tool called silk software




Magento 2 Module Creator Tool Using Silk Software



and enable using following commands below.



  1. php bin/magento module:enable Tw_Cart

  2. php bin/magento setup:upgrade

  3. php bin/magento setup:di:compile

  4. php bin/magento setup:static-content:deploy


create events.xml in the path:- app/code/Tw/Cart/etc/frontend/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="checkout_cart_product_add_after">
<observer name="Tw_Cart_Addtocart_Customprice" instance="TWCartObserverCustomPrice" />
</event>
</config>



create CustomPrice.php in the path: app/code/Tw/Cart/Observer/ & keep the below code




<?php
namespace TWCartObserver;
use MagentoFrameworkEventObserverInterface;
use MagentoFrameworkAppRequestInterface;
use PsrLogLoggerInterface;
class CustomPrice implements ObserverInterface


public function execute(MagentoFrameworkEventObserver $observer)

$writer = new ZendLogWriterStream(BP.'/var/log/stackexchange.log');
$logger = new ZendLogLogger();
$logger->addWriter($writer);
/* Code here */
$quote_item = $observer->getEvent()->getQuoteItem();
$price = 400; //set your price here
$quote_item->setCustomPrice($price);
$quote_item->setOriginalCustomPrice($price);
$quote_item->getProduct()->setIsSuperMode(true);
$logger->info("success !!!!");









share|improve this answer














share|improve this answer



share|improve this answer








edited Jul 6 '17 at 9:15









Teja Bhagavan Kollepara

3,00641949




3,00641949










answered Jul 4 '17 at 10:14









Nagaraju KasaNagaraju Kasa

2,68721540




2,68721540












  • I tried to vote .. but it does not allow me to do so :(

    – ssnegi
    Jul 5 '17 at 9:55











  • Tried This, product is added with custom price in cart, but in summary original product price is showing... any update on this..?

    – Rizwan
    Nov 17 '17 at 11:13











  • could you please share me screenshot thanks

    – Nagaraju Kasa
    Nov 17 '17 at 11:38

















  • I tried to vote .. but it does not allow me to do so :(

    – ssnegi
    Jul 5 '17 at 9:55











  • Tried This, product is added with custom price in cart, but in summary original product price is showing... any update on this..?

    – Rizwan
    Nov 17 '17 at 11:13











  • could you please share me screenshot thanks

    – Nagaraju Kasa
    Nov 17 '17 at 11:38
















I tried to vote .. but it does not allow me to do so :(

– ssnegi
Jul 5 '17 at 9:55





I tried to vote .. but it does not allow me to do so :(

– ssnegi
Jul 5 '17 at 9:55













Tried This, product is added with custom price in cart, but in summary original product price is showing... any update on this..?

– Rizwan
Nov 17 '17 at 11:13





Tried This, product is added with custom price in cart, but in summary original product price is showing... any update on this..?

– Rizwan
Nov 17 '17 at 11:13













could you please share me screenshot thanks

– Nagaraju Kasa
Nov 17 '17 at 11:38





could you please share me screenshot thanks

– Nagaraju Kasa
Nov 17 '17 at 11:38

















draft saved

draft discarded
















































Thanks for contributing an answer to Magento Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f181945%2fcustom-price-of-product-not-getting-applied-in-cart-in-magento-2%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Sum ergo cogito? 1 nng

三茅街道4182Guuntc Dn precexpngmageondP