7

I am catching sales_order_place_after event in etc/adminhtml/events.xml everything working fine..

But same is not working while trying to catch in etc/frontend/events.xml. also tried to catch the event in etc/events.xml but no luck..

In brief my problem is:

sales_order_place_after event is working while placing the order from admin Dashboard but same is not working if order placed from frontend.

is there any different way to call this event from front end ??

adminhtml/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="sales_order_place_after">
        <observer name="sales_order_grid_vendors" instance="Company\Vendors\Observer\Adminhtml\Vendor\AddVendorSalesOrders" />
    </event>
</config>

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="sales_order_place_after">
        <observer name="sales_order_grid_vendors_customer" instance="Company\Vendors\Observer\AddVendorOrders" />
    </event>
</config>

observers: Observer/Adminhtml/Vendor/AddVendorSalesOrders.php

namespace Company\Vendors\Observer\Adminhtml\Vendor;
use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;
class AddVendorSalesOrders implements ObserverInterface
{
  public function execute(Observer $observer)
      {
        die('mujassam');
      }
}

Observer/AddVendorOrders.php

namespace Company\Vendors\Observer;
use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;
class AddVendorOrders implements ObserverInterface
{
  public function execute(Observer $observer)
      {
        die('mujassam');
      }
}
7
  • Did try deleting var/cache and var/generation after your changes ? Because this event is widely used in Magento 2 original code so it should work the way you described it. Please post your full events.xml Commented Apr 27, 2016 at 7:01
  • Can u please share your codeetc/frontend/events.xml
    – Amit Bera
    Commented Apr 27, 2016 at 7:08
  • @RaphaelatDigitalPianism i tried clearing all the cache/genration but no luck, I have edited the question with events. Commented Apr 27, 2016 at 7:17
  • @MohammadMujassam could you post both admin and frontend observers please ? Commented Apr 27, 2016 at 7:19
  • @RaphaelatDigitalPianism sure, edited the question. Commented Apr 27, 2016 at 7:36

3 Answers 3

3

In case you do not want to listen to the sales_order_place_after event globally, the correct scope would be webapi_rest instead of frontend.

2

Thanks for all your support.. this is how I did catch the event..

Company/Vendors/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="sales_order_place_after">
        <observer name="sales_order_grid_vendors_customer" instance="Company\Vendors\Observer\AddVendorOrders" />
    </event>
</config>

Instead of placing your event in Company/Vendors/etc/frontend/events.xml, place it in Company/Vendors/etc/events.xml

1
  • Thank you good sir! I spent the past 6+ hours trying to figure out why the observer was not working. I had it in the etc/frontend directory.
    – Dave
    Commented May 22, 2017 at 12:42
-1

CompanyName/ModuleName/view/frontend/layout/catalog_category_view.xml

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="2columns-left" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>  
        <block class="Magento\Catalog\Block\Product\ListProduct" name="YourName" cacheable="false"/>
    </body>
</page>

cacheable="false"

add this now you event is working

1
  • the answer is not relevant to original question
    – c0rewell
    Commented Jan 25, 2018 at 6:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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