Magento 2 checkout_cart_product_add_after not workingmain.CRITICAL: Plugin class doesn't existSet custom price of product when adding to cart code not workingMagento 2: Add a product to the cart programmaticallyAdd to cart button freezes and nothing is put in basketMonolog Error After 2.2 UpgradeMagento 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 OptionsMagento 2.3 Can't view module's front end page output?Undefined variable: _ENV in magento 2.3

What makes Ada the language of choice for the ISS's safety-critical systems?

How to forge a multi-part weapon?

bash script: "*.jpg" expansion not working as expected inside $(...), for picking a random file

How to handle self harm scars on the arm in work environment?

Pre-1972 sci-fi short story or novel: alien(?) tunnel where people try new moves and get destroyed if they're not the correct ones

Why is one of Madera Municipal's runways labelled with only "R" on both sides?

How to deal with apathetic co-worker?

What is the highest possible temporary AC at level 1, without any help from others?

Do simulator games use a realistic trajectory to get into orbit?

Passing multiple files through stdin (over ssh)

Is open-sourcing the code of a webapp not recommended?

Inward extrusion is not working

How can I get an unreasonable manager to approve time off?

A curious prime counting approximation or just data overfitting?

Soft question: Examples where lack of mathematical rigour cause security breaches?

SOQL Not Recognizing Field?

What is the `some` keyword in SwiftUI?

Overlapping String-Blocks

Compiling C files on Ubuntu and using the executable on Windows

This riddle is not to see but to solve

Cycle through MeshStyle directives in ListLinePlot

Is it a problem if <h4>, <h5> and <h6> are smaller than regular text?

How to tell your grandparent to not come to fetch you with their car?

Were Alexander the Great and Hephaestion lovers?



Magento 2 checkout_cart_product_add_after not working


main.CRITICAL: Plugin class doesn't existSet custom price of product when adding to cart code not workingMagento 2: Add a product to the cart programmaticallyAdd to cart button freezes and nothing is put in basketMonolog Error After 2.2 UpgradeMagento 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 OptionsMagento 2.3 Can't view module's front end page output?Undefined variable: _ENV in magento 2.3






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















here am trying to add custom price during adding product to cart but checkout_cart_product_add_after event is not getting fired.
my API to add to cart is



http://localhost/magento/rest/V1/carts/636/items/ [POST]


this is my events.xml



vendor/Cart/etc/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="customprice" instance="VendorCartObserverCustomPrice" />
</event>
</config>


this is My Observer



VendorCartObserver

<?php

namespace VendorCartObserver;

use MagentoFrameworkEventObserverInterface;
use MagentoFrameworkAppRequestInterface;

class CustomPrice implements ObserverInterface

protected $_request;
protected $_helper;
protected $cart;
public function __construct(MagentoFrameworkAppRequestInterface $request,TWProductHelperData $helper,MagentoCheckoutModelCart $cart)

$this->_request = $request;
$this->_helper = $helper;
$this->cart= $cart;


public function execute(MagentoFrameworkEventObserver $observer)
$this->_eventManager->dispatch('sales_quote_add_item', ['quote_item' => $item]);
$writer = new ZendLogWriterStream(BP.'/var/log/test.log');
$logger = new ZendLogLogger();
$logger->addWriter($writer);
$logger->info("success !!!!");






Am not understanding where am wrong, can i get help? , Thank you in advance










share|improve this question
























  • Is it triggering while add to cart manually in the website?

    – Prathap Gunasekaran
    May 30 at 11:12











  • its website is not in use. so I working through API calls, its not triggering

    – Praveen Negimani
    May 30 at 11:20

















0















here am trying to add custom price during adding product to cart but checkout_cart_product_add_after event is not getting fired.
my API to add to cart is



http://localhost/magento/rest/V1/carts/636/items/ [POST]


this is my events.xml



vendor/Cart/etc/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="customprice" instance="VendorCartObserverCustomPrice" />
</event>
</config>


this is My Observer



VendorCartObserver

<?php

namespace VendorCartObserver;

use MagentoFrameworkEventObserverInterface;
use MagentoFrameworkAppRequestInterface;

class CustomPrice implements ObserverInterface

protected $_request;
protected $_helper;
protected $cart;
public function __construct(MagentoFrameworkAppRequestInterface $request,TWProductHelperData $helper,MagentoCheckoutModelCart $cart)

$this->_request = $request;
$this->_helper = $helper;
$this->cart= $cart;


public function execute(MagentoFrameworkEventObserver $observer)
$this->_eventManager->dispatch('sales_quote_add_item', ['quote_item' => $item]);
$writer = new ZendLogWriterStream(BP.'/var/log/test.log');
$logger = new ZendLogLogger();
$logger->addWriter($writer);
$logger->info("success !!!!");






Am not understanding where am wrong, can i get help? , Thank you in advance










share|improve this question
























  • Is it triggering while add to cart manually in the website?

    – Prathap Gunasekaran
    May 30 at 11:12











  • its website is not in use. so I working through API calls, its not triggering

    – Praveen Negimani
    May 30 at 11:20













0












0








0








here am trying to add custom price during adding product to cart but checkout_cart_product_add_after event is not getting fired.
my API to add to cart is



http://localhost/magento/rest/V1/carts/636/items/ [POST]


this is my events.xml



vendor/Cart/etc/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="customprice" instance="VendorCartObserverCustomPrice" />
</event>
</config>


this is My Observer



VendorCartObserver

<?php

namespace VendorCartObserver;

use MagentoFrameworkEventObserverInterface;
use MagentoFrameworkAppRequestInterface;

class CustomPrice implements ObserverInterface

protected $_request;
protected $_helper;
protected $cart;
public function __construct(MagentoFrameworkAppRequestInterface $request,TWProductHelperData $helper,MagentoCheckoutModelCart $cart)

$this->_request = $request;
$this->_helper = $helper;
$this->cart= $cart;


public function execute(MagentoFrameworkEventObserver $observer)
$this->_eventManager->dispatch('sales_quote_add_item', ['quote_item' => $item]);
$writer = new ZendLogWriterStream(BP.'/var/log/test.log');
$logger = new ZendLogLogger();
$logger->addWriter($writer);
$logger->info("success !!!!");






Am not understanding where am wrong, can i get help? , Thank you in advance










share|improve this question
















here am trying to add custom price during adding product to cart but checkout_cart_product_add_after event is not getting fired.
my API to add to cart is



http://localhost/magento/rest/V1/carts/636/items/ [POST]


this is my events.xml



vendor/Cart/etc/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="customprice" instance="VendorCartObserverCustomPrice" />
</event>
</config>


this is My Observer



VendorCartObserver

<?php

namespace VendorCartObserver;

use MagentoFrameworkEventObserverInterface;
use MagentoFrameworkAppRequestInterface;

class CustomPrice implements ObserverInterface

protected $_request;
protected $_helper;
protected $cart;
public function __construct(MagentoFrameworkAppRequestInterface $request,TWProductHelperData $helper,MagentoCheckoutModelCart $cart)

$this->_request = $request;
$this->_helper = $helper;
$this->cart= $cart;


public function execute(MagentoFrameworkEventObserver $observer)
$this->_eventManager->dispatch('sales_quote_add_item', ['quote_item' => $item]);
$writer = new ZendLogWriterStream(BP.'/var/log/test.log');
$logger = new ZendLogLogger();
$logger->addWriter($writer);
$logger->info("success !!!!");






Am not understanding where am wrong, can i get help? , Thank you in advance







magento2 event-observer addtocart






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited May 30 at 12:59







Praveen Negimani

















asked May 30 at 10:50









Praveen NegimaniPraveen Negimani

508




508












  • Is it triggering while add to cart manually in the website?

    – Prathap Gunasekaran
    May 30 at 11:12











  • its website is not in use. so I working through API calls, its not triggering

    – Praveen Negimani
    May 30 at 11:20

















  • Is it triggering while add to cart manually in the website?

    – Prathap Gunasekaran
    May 30 at 11:12











  • its website is not in use. so I working through API calls, its not triggering

    – Praveen Negimani
    May 30 at 11:20
















Is it triggering while add to cart manually in the website?

– Prathap Gunasekaran
May 30 at 11:12





Is it triggering while add to cart manually in the website?

– Prathap Gunasekaran
May 30 at 11:12













its website is not in use. so I working through API calls, its not triggering

– Praveen Negimani
May 30 at 11:20





its website is not in use. so I working through API calls, its not triggering

– Praveen Negimani
May 30 at 11:20










1 Answer
1






active

oldest

votes


















0














checkout_cart_product_add_after is a frontent event.It is not work with Rest.



You can try with below event which can fire for all area frontend, backend, Rest API, rest soap.




$this->_eventManager->dispatch('sales_quote_add_item', ['quote_item' => $item]);






share|improve this answer

























  • Thank you for reply ill add and test it

    – Praveen Negimani
    May 30 at 11:43











  • I updated the code please check, its not working

    – Praveen Negimani
    May 30 at 12:18











  • what change you have done?

    – Amit Bera
    May 30 at 12:29











  • added dispatch event in observer

    – Praveen Negimani
    May 30 at 12:54











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%2f276720%2fmagento-2-checkout-cart-product-add-after-not-working%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














checkout_cart_product_add_after is a frontent event.It is not work with Rest.



You can try with below event which can fire for all area frontend, backend, Rest API, rest soap.




$this->_eventManager->dispatch('sales_quote_add_item', ['quote_item' => $item]);






share|improve this answer

























  • Thank you for reply ill add and test it

    – Praveen Negimani
    May 30 at 11:43











  • I updated the code please check, its not working

    – Praveen Negimani
    May 30 at 12:18











  • what change you have done?

    – Amit Bera
    May 30 at 12:29











  • added dispatch event in observer

    – Praveen Negimani
    May 30 at 12:54















0














checkout_cart_product_add_after is a frontent event.It is not work with Rest.



You can try with below event which can fire for all area frontend, backend, Rest API, rest soap.




$this->_eventManager->dispatch('sales_quote_add_item', ['quote_item' => $item]);






share|improve this answer

























  • Thank you for reply ill add and test it

    – Praveen Negimani
    May 30 at 11:43











  • I updated the code please check, its not working

    – Praveen Negimani
    May 30 at 12:18











  • what change you have done?

    – Amit Bera
    May 30 at 12:29











  • added dispatch event in observer

    – Praveen Negimani
    May 30 at 12:54













0












0








0







checkout_cart_product_add_after is a frontent event.It is not work with Rest.



You can try with below event which can fire for all area frontend, backend, Rest API, rest soap.




$this->_eventManager->dispatch('sales_quote_add_item', ['quote_item' => $item]);






share|improve this answer















checkout_cart_product_add_after is a frontent event.It is not work with Rest.



You can try with below event which can fire for all area frontend, backend, Rest API, rest soap.




$this->_eventManager->dispatch('sales_quote_add_item', ['quote_item' => $item]);







share|improve this answer














share|improve this answer



share|improve this answer








edited May 31 at 2:49

























answered May 30 at 11:24









Amit BeraAmit Bera

60.9k1682181




60.9k1682181












  • Thank you for reply ill add and test it

    – Praveen Negimani
    May 30 at 11:43











  • I updated the code please check, its not working

    – Praveen Negimani
    May 30 at 12:18











  • what change you have done?

    – Amit Bera
    May 30 at 12:29











  • added dispatch event in observer

    – Praveen Negimani
    May 30 at 12:54

















  • Thank you for reply ill add and test it

    – Praveen Negimani
    May 30 at 11:43











  • I updated the code please check, its not working

    – Praveen Negimani
    May 30 at 12:18











  • what change you have done?

    – Amit Bera
    May 30 at 12:29











  • added dispatch event in observer

    – Praveen Negimani
    May 30 at 12:54
















Thank you for reply ill add and test it

– Praveen Negimani
May 30 at 11:43





Thank you for reply ill add and test it

– Praveen Negimani
May 30 at 11:43













I updated the code please check, its not working

– Praveen Negimani
May 30 at 12:18





I updated the code please check, its not working

– Praveen Negimani
May 30 at 12:18













what change you have done?

– Amit Bera
May 30 at 12:29





what change you have done?

– Amit Bera
May 30 at 12:29













added dispatch event in observer

– Praveen Negimani
May 30 at 12:54





added dispatch event in observer

– Praveen Negimani
May 30 at 12:54

















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%2f276720%2fmagento-2-checkout-cart-product-add-after-not-working%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

Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

Circuit construction for execution of conditional statements using least significant bitHow are two different registers being used as “control”?How exactly is the stated composite state of the two registers being produced using the $R_zz$ controlled rotations?Efficiently performing controlled rotations in HHLWould this quantum algorithm implementation work?How to prepare a superposed states of odd integers from $1$ to $sqrtN$?Why is this implementation of the order finding algorithm not working?Circuit construction for Hamiltonian simulationHow can I invert the least significant bit of a certain term of a superposed state?Implementing an oracleImplementing a controlled sum operation

Magento 2 “No Payment Methods” in Admin New OrderHow to integrate Paypal Express Checkout with the Magento APIMagento 1.5 - Sales > Order > edit order and shipping methods disappearAuto Invoice Check/Money Order Payment methodAdd more simple payment methods?Shipping methods not showingWhat should I do to change payment methods if changing the configuration has no effects?1.9 - No Payment Methods showing upMy Payment Methods not Showing for downloadable/virtual product when checkout?Magento2 API to access internal payment methodHow to call an existing payment methods in the registration form?