0

Magento version: 2.0

events.xml

<event name="prepare_catalog_product_index_select">
        <observer name="list_product_observer" instance="Demo\Product\Observer\ListProductObserver" />
    </event>

ListProductObserver.php

class ListProductObserver implements ObserverInterface
{   
    public function execute(Observer $observer)
    {
        $data = array(
            'product' => $productId,
            'user'  => $userId,
            'value' => 333
        );
        $myfile = fopen("/file_path/ListProductObserver.txt", "w");
        fwrite($myfile, print_r($data, true));
        fclose($myfile);
    }
}

I create a function to do some when admin user enter the catalog list page. But it doesn't work for me.

  • I'd check next cases: 1. Be sure that event "prepare_catalog_product_index_select" is dispatched. 2. Verify that your observer is in list of the event observers. Need to debug code in \Magento\Framework\Event\Manager::dispatch 3. Verify that your observer is invoked. – Arkadii Chyzhov Mar 14 '16 at 12:04
  • @ArkadiiChyzhov do you have the full list of events? do you tell me where i can find them? – Mike Zhang Mar 14 '16 at 12:12
  • @ArkadiiChyzhov 1, this event is in the list of url you recommend below. 2, I tried to check whether it is in the event list, but i can get the error or correct message on \Magento\Framework\Event\Manager::dispatch. do you have another suggestion? – Mike Zhang Mar 14 '16 at 15:19
0

You defined the instance of "ListProductObserver" in events.xml, but you named the class as "ListOwnerProductObserver"

  • thanks for your reply. i made a typo and correct it just now. but it doesn't work for me. I guess the event name is wrong. i don't know which name is correct. – Mike Zhang Mar 14 '16 at 11:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.