Does not work events magento 2main.CRITICAL: Plugin class doesn't existSet custom price of product when adding to cart code not workingMagento 2 Log Bundle Product Data in List Page?Magento 2: Add a product to the cart programmaticallyMagento 2 Create dynamic array From different Model Collection to use in multi select in gridMonolog 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?

Why is my log file so massive? 22gb. I am running log backups

What do the Banks children have against barley water?

How can I fix this gap between bookcases I made?

Can a planet have a different gravitational pull depending on its location in orbit around its sun?

Unbreakable Formation vs. Cry of the Carnarium

Why do UK politicians seemingly ignore opinion polls on Brexit?

"My colleague's body is amazing"

Manga about a female worker who got dragged into another world together with this high school girl and she was just told she's not needed anymore

OA final episode explanation

Does a dangling wire really electrocute me if I'm standing in water?

Why is making salt water prohibited on Shabbat?

Doomsday-clock for my fantasy planet

Can I legally use front facing blue light in the UK?

Why was the "bread communication" in the arena of Catching Fire left out in the movie?

Does it makes sense to buy a new cycle to learn riding?

Extreme, but not acceptable situation and I can't start the work tomorrow morning

Calculate Levenshtein distance between two strings in Python

aging parents with no investments

Can produce flame be used to grapple, or as an unarmed strike, in the right circumstances?

Is Social Media Science Fiction?

Some basic questions on halt and move in Turing machines

Is domain driven design an anti-SQL pattern?

Ideas for colorfully and clearly highlighting graph edges according to weights

Why airport relocation isn't done gradually?



Does not work events magento 2


main.CRITICAL: Plugin class doesn't existSet custom price of product when adding to cart code not workingMagento 2 Log Bundle Product Data in List Page?Magento 2: Add a product to the cart programmaticallyMagento 2 Create dynamic array From different Model Collection to use in multi select in gridMonolog 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?






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








0















Events do not work when I go to the product page.




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="adding_to_cart_before">
<observer name="attributesProduct" instance="RonisSameDayDeliveryObserverDayDelivery" />
</event>
</config>



DayDelivery.php




<?php

namespace RonisSameDayDeliveryObserver;

use MagentoFrameworkEventObserverInterface;

class DayDelivery implements ObserverInterface

protected $resultPageFactory;

/**
* @var MagentoCheckoutModelCart
*/
protected $_cart;

/**
* [__construct description]
* @param MagentoFrameworkAppActionContext $context [description]
* @param MagentoFrameworkViewResultPageFactory $resultPageFactory [description]
* @param MagentoCheckoutModelCart $cart [description]
*/
public function __construct(
MagentoFrameworkAppActionContext $context,
MagentoFrameworkViewResultPageFactory $resultPageFactory,
MagentoCheckoutModelCart $cart
)
$this->resultPageFactory = $resultPageFactory;
$this->_cart = $cart;
parent::__construct($context);


public function execute(MagentoFrameworkEventObserver $observer)

$writer = new ZendLogWriterStream(BP . '/var/log/daydelivery.log');
$logger = new ZendLogLogger();
$logger->addWriter($writer);

$productInfo = $this->_cart->getQuote()->getItemsCollection();
$logger->info('-------------------------');
foreach ($productInfo as $item)
$item->getProductId();
$logger->info($item->getProductId());
if($item->getProductId() == '1')

echo "Item available in cart";

else

echo "Item not available in cart";













share|improve this question






















  • Have you got any error? or any log in the log file?

    – Chirag Patel
    10 hours ago












  • No, and does not write anything to my log

    – Рома Лытарь
    10 hours ago











  • What's that event?? when you want that event to be triggered?

    – Prathap Gunasekaran
    10 hours ago











  • When I go to the product page

    – Рома Лытарь
    10 hours ago











  • You mean each time when you go for product page

    – Prathap Gunasekaran
    10 hours ago

















0















Events do not work when I go to the product page.




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="adding_to_cart_before">
<observer name="attributesProduct" instance="RonisSameDayDeliveryObserverDayDelivery" />
</event>
</config>



DayDelivery.php




<?php

namespace RonisSameDayDeliveryObserver;

use MagentoFrameworkEventObserverInterface;

class DayDelivery implements ObserverInterface

protected $resultPageFactory;

/**
* @var MagentoCheckoutModelCart
*/
protected $_cart;

/**
* [__construct description]
* @param MagentoFrameworkAppActionContext $context [description]
* @param MagentoFrameworkViewResultPageFactory $resultPageFactory [description]
* @param MagentoCheckoutModelCart $cart [description]
*/
public function __construct(
MagentoFrameworkAppActionContext $context,
MagentoFrameworkViewResultPageFactory $resultPageFactory,
MagentoCheckoutModelCart $cart
)
$this->resultPageFactory = $resultPageFactory;
$this->_cart = $cart;
parent::__construct($context);


public function execute(MagentoFrameworkEventObserver $observer)

$writer = new ZendLogWriterStream(BP . '/var/log/daydelivery.log');
$logger = new ZendLogLogger();
$logger->addWriter($writer);

$productInfo = $this->_cart->getQuote()->getItemsCollection();
$logger->info('-------------------------');
foreach ($productInfo as $item)
$item->getProductId();
$logger->info($item->getProductId());
if($item->getProductId() == '1')

echo "Item available in cart";

else

echo "Item not available in cart";













share|improve this question






















  • Have you got any error? or any log in the log file?

    – Chirag Patel
    10 hours ago












  • No, and does not write anything to my log

    – Рома Лытарь
    10 hours ago











  • What's that event?? when you want that event to be triggered?

    – Prathap Gunasekaran
    10 hours ago











  • When I go to the product page

    – Рома Лытарь
    10 hours ago











  • You mean each time when you go for product page

    – Prathap Gunasekaran
    10 hours ago













0












0








0








Events do not work when I go to the product page.




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="adding_to_cart_before">
<observer name="attributesProduct" instance="RonisSameDayDeliveryObserverDayDelivery" />
</event>
</config>



DayDelivery.php




<?php

namespace RonisSameDayDeliveryObserver;

use MagentoFrameworkEventObserverInterface;

class DayDelivery implements ObserverInterface

protected $resultPageFactory;

/**
* @var MagentoCheckoutModelCart
*/
protected $_cart;

/**
* [__construct description]
* @param MagentoFrameworkAppActionContext $context [description]
* @param MagentoFrameworkViewResultPageFactory $resultPageFactory [description]
* @param MagentoCheckoutModelCart $cart [description]
*/
public function __construct(
MagentoFrameworkAppActionContext $context,
MagentoFrameworkViewResultPageFactory $resultPageFactory,
MagentoCheckoutModelCart $cart
)
$this->resultPageFactory = $resultPageFactory;
$this->_cart = $cart;
parent::__construct($context);


public function execute(MagentoFrameworkEventObserver $observer)

$writer = new ZendLogWriterStream(BP . '/var/log/daydelivery.log');
$logger = new ZendLogLogger();
$logger->addWriter($writer);

$productInfo = $this->_cart->getQuote()->getItemsCollection();
$logger->info('-------------------------');
foreach ($productInfo as $item)
$item->getProductId();
$logger->info($item->getProductId());
if($item->getProductId() == '1')

echo "Item available in cart";

else

echo "Item not available in cart";













share|improve this question














Events do not work when I go to the product page.




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="adding_to_cart_before">
<observer name="attributesProduct" instance="RonisSameDayDeliveryObserverDayDelivery" />
</event>
</config>



DayDelivery.php




<?php

namespace RonisSameDayDeliveryObserver;

use MagentoFrameworkEventObserverInterface;

class DayDelivery implements ObserverInterface

protected $resultPageFactory;

/**
* @var MagentoCheckoutModelCart
*/
protected $_cart;

/**
* [__construct description]
* @param MagentoFrameworkAppActionContext $context [description]
* @param MagentoFrameworkViewResultPageFactory $resultPageFactory [description]
* @param MagentoCheckoutModelCart $cart [description]
*/
public function __construct(
MagentoFrameworkAppActionContext $context,
MagentoFrameworkViewResultPageFactory $resultPageFactory,
MagentoCheckoutModelCart $cart
)
$this->resultPageFactory = $resultPageFactory;
$this->_cart = $cart;
parent::__construct($context);


public function execute(MagentoFrameworkEventObserver $observer)

$writer = new ZendLogWriterStream(BP . '/var/log/daydelivery.log');
$logger = new ZendLogLogger();
$logger->addWriter($writer);

$productInfo = $this->_cart->getQuote()->getItemsCollection();
$logger->info('-------------------------');
foreach ($productInfo as $item)
$item->getProductId();
$logger->info($item->getProductId());
if($item->getProductId() == '1')

echo "Item available in cart";

else

echo "Item not available in cart";










magento2 event-observer






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 10 hours ago









Рома ЛытарьРома Лытарь

1719




1719












  • Have you got any error? or any log in the log file?

    – Chirag Patel
    10 hours ago












  • No, and does not write anything to my log

    – Рома Лытарь
    10 hours ago











  • What's that event?? when you want that event to be triggered?

    – Prathap Gunasekaran
    10 hours ago











  • When I go to the product page

    – Рома Лытарь
    10 hours ago











  • You mean each time when you go for product page

    – Prathap Gunasekaran
    10 hours ago

















  • Have you got any error? or any log in the log file?

    – Chirag Patel
    10 hours ago












  • No, and does not write anything to my log

    – Рома Лытарь
    10 hours ago











  • What's that event?? when you want that event to be triggered?

    – Prathap Gunasekaran
    10 hours ago











  • When I go to the product page

    – Рома Лытарь
    10 hours ago











  • You mean each time when you go for product page

    – Prathap Gunasekaran
    10 hours ago
















Have you got any error? or any log in the log file?

– Chirag Patel
10 hours ago






Have you got any error? or any log in the log file?

– Chirag Patel
10 hours ago














No, and does not write anything to my log

– Рома Лытарь
10 hours ago





No, and does not write anything to my log

– Рома Лытарь
10 hours ago













What's that event?? when you want that event to be triggered?

– Prathap Gunasekaran
10 hours ago





What's that event?? when you want that event to be triggered?

– Prathap Gunasekaran
10 hours ago













When I go to the product page

– Рома Лытарь
10 hours ago





When I go to the product page

– Рома Лытарь
10 hours ago













You mean each time when you go for product page

– Prathap Gunasekaran
10 hours ago





You mean each time when you go for product page

– Prathap Gunasekaran
10 hours ago










1 Answer
1






active

oldest

votes


















2














Try this,



You should use this event controller_action_predispatch_catalog_product_view instead of adding_to_cart_before



but the problem is, it will trigger only on first time when you visit the product page, since it is cacheable page. You may try disable cacheable="false" to any of the block from product page and check then it will trigger all the time you visit.




NOTE : It's not recommended to disable cache on product page, so try using plugin to do that.




Hope this information helps.






share|improve this answer























  • and how can I now transfer these id's to the js template so that, depending on this ids, I showed a popup on the product page

    – Рома Лытарь
    9 hours ago











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%2f269186%2fdoes-not-work-events-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









2














Try this,



You should use this event controller_action_predispatch_catalog_product_view instead of adding_to_cart_before



but the problem is, it will trigger only on first time when you visit the product page, since it is cacheable page. You may try disable cacheable="false" to any of the block from product page and check then it will trigger all the time you visit.




NOTE : It's not recommended to disable cache on product page, so try using plugin to do that.




Hope this information helps.






share|improve this answer























  • and how can I now transfer these id's to the js template so that, depending on this ids, I showed a popup on the product page

    – Рома Лытарь
    9 hours ago















2














Try this,



You should use this event controller_action_predispatch_catalog_product_view instead of adding_to_cart_before



but the problem is, it will trigger only on first time when you visit the product page, since it is cacheable page. You may try disable cacheable="false" to any of the block from product page and check then it will trigger all the time you visit.




NOTE : It's not recommended to disable cache on product page, so try using plugin to do that.




Hope this information helps.






share|improve this answer























  • and how can I now transfer these id's to the js template so that, depending on this ids, I showed a popup on the product page

    – Рома Лытарь
    9 hours ago













2












2








2







Try this,



You should use this event controller_action_predispatch_catalog_product_view instead of adding_to_cart_before



but the problem is, it will trigger only on first time when you visit the product page, since it is cacheable page. You may try disable cacheable="false" to any of the block from product page and check then it will trigger all the time you visit.




NOTE : It's not recommended to disable cache on product page, so try using plugin to do that.




Hope this information helps.






share|improve this answer













Try this,



You should use this event controller_action_predispatch_catalog_product_view instead of adding_to_cart_before



but the problem is, it will trigger only on first time when you visit the product page, since it is cacheable page. You may try disable cacheable="false" to any of the block from product page and check then it will trigger all the time you visit.




NOTE : It's not recommended to disable cache on product page, so try using plugin to do that.




Hope this information helps.







share|improve this answer












share|improve this answer



share|improve this answer










answered 9 hours ago









Prathap GunasekaranPrathap Gunasekaran

1,7611618




1,7611618












  • and how can I now transfer these id's to the js template so that, depending on this ids, I showed a popup on the product page

    – Рома Лытарь
    9 hours ago

















  • and how can I now transfer these id's to the js template so that, depending on this ids, I showed a popup on the product page

    – Рома Лытарь
    9 hours ago
















and how can I now transfer these id's to the js template so that, depending on this ids, I showed a popup on the product page

– Рома Лытарь
9 hours ago





and how can I now transfer these id's to the js template so that, depending on this ids, I showed a popup on the product page

– Рома Лытарь
9 hours ago

















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%2f269186%2fdoes-not-work-events-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

Best approach to update all entries in a list that is paginated?Best way to add items to a paginated listChoose Your Country: Best Usability approachUpdate list when a user is viewing the list without annoying themWhen would the best day to update your webpage be?What should happen when I add a Row to a paginated, sorted listShould I adopt infinite scrolling or classical pagination?How to show user that page objects automatically updateWhat is the best location to locate the comments section in a list pageBest way to combine filtering and selecting items in a listWhen one of two inputs must be updated to satisfy a consistency criteria, which should you update (if at all)?

Вунгтау (аеропорт) Загальні відомості | Див. також | Посилання | Навігаційне меню10°22′00″ пн. ш. 107°05′00″ сх. д. / 10.36667° пн. ш. 107.08333° сх. д. / 10.36667; 107.0833310°22′00″ пн. ш. 107°05′00″ сх. д. / 10.36667° пн. ш. 107.08333° сх. д. / 10.36667; 107.083337731608Vinh AirportVinh airport facelift improves serviceвиправивши або дописавши їївиправивши або дописавши їїр

Тонконіг бульбистий Зміст Опис | Поширення | Екологія | Господарське значення | Примітки | Див. також | Література | Джерела | Посилання | Навігаційне меню1114601320038-241116202404kew-435458Poa bulbosaЭлектронный каталог сосудистых растений Азиатской России [Електронний каталог судинних рослин Азіатської Росії]Малышев Л. Л. Дикие родичи культурных растений. Poa bulbosa L. - Мятлик луковичный. [Малишев Л. Л. Дикі родичи культурних рослин. Poa bulbosa L. - Тонконіг бульбистий.]Мятлик (POA) Сем. Злаки (Мятликовые) [Тонконіг (POA) Род. Злаки (Тонконогові)]Poa bulbosa Linnaeus, Sp. Pl. 1: 70. 1753. 鳞茎早熟禾 lin jing zao shu he (Description from Flora of China) [Poa bulbosa Linnaeus, Sp. Pl. 1: 70. 1753. 鳞茎早熟禾 lin jing zao shu he (Опис від Флора Китаю)]Poa bulbosa L. – lipnice cibulkatá / lipnica cibulkatáPoa bulbosa в базі даних Poa bulbosa на сайті Poa bulbosa в базі даних «Global Biodiversity Information Facility» (GBIF)Poa bulbosa в базі даних «Euro + Med PlantBase» — інформаційному ресурсі для Євро-середземноморського розмаїття рослинPoa bulbosa L. на сайті «Плантариум»