Question

I am using M2epro for Amazon and eBay. We want to set custom attribute value(static) once order creates in Magento admin. Can anyone have any idea how we can do it?

Was it helpful?

Solution

Here is the solution to add a custom attribute in M2epro order.

Once the order has been placed in Magento using M2epro, it will trigger one event ess_order_place_success after order success in which you will get order object. You can create an observer using that event.

Below is the code for the event.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="ess_order_place_success">
        <observer name="package_module_after" instance="PackageName\ModuleName\Observer\CreateOrderAfterObserver" />
    </event>
</config>

and create an observer file name with CreateOrderAfterObserver.php

<?php
namespace PackageName\ModuleName\Observer;

use Magento\Framework\Event\Observer as EventObserver;
use Magento\Framework\Event\ObserverInterface;
use Magento\Framework\Exception\InputException;

class CreateOrderAfterObserver implements ObserverInterface
{
    public function execute(EventObserver $observer)
    {
        try {
                $order = $observer->getEvent()->getOrder()->getMagentoOrder();
                // do what ever you want to do
        } catch (\Exception $e) {
             echo $e->getMessage();
        }
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top