0

i want to perform some action if click on credit memo of any order from admin what code i need to write in observer and what event i need to use

0

You can use sales_order_save_after event to perform some actions.

create events.xml in your namespace->module->etc->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_save_after">
        <observer name="order_sync_observer" instance="Namespace\Module\Observer\SyncOrder" />
    </event>
</config> 

Create class in Namepsace->Module->Observer->SyncOrder.php

<?php
namespace Namespace\Module\Observer;

use Magento\Framework\Event\ObserverInterface;
use Magento\Framework\ObjectManager\ObjectManager;

class SyncOrder implements ObserverInterface
{

//   protected $logger;
  public $order;
  public $product;
  protected $eavConfig;
  protected $customerRepository;
  
  public function __construct(
    \Magento\Sales\Model\Order $order, 
    \Magento\Catalog\Api\ProductRepositoryInterface $product, 
    \Magento\Eav\Model\Config $eavConfig,
    \Magento\Customer\Api\CustomerRepositoryInterface $customerRepository
  )
  {

    $this->order = $order;
    $this->product = $product;
    $this->eavConfig = $eavConfig;
    $this->customerRepository = $customerRepository;


  }

  public function execute(\Magento\Framework\Event\Observer $observer)
  {


    $order = $observer->getEvent()->getOrder();
   
  
    }

}

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.