Question

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');
      }
}
Was it helpful?

Solution 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

OTHER TIPS

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.

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

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top