How to create Magento Order programatically in Amazon M2epro [closed]
-
26-12-2020 - |
Question
I want to create magento order from Amazon M2Epro Extension in magento 2.
I am able to create Order Object but not sure how can I call Controller function CreateMagentoOrder()
Git Link - https://github.com/m2epro/magento2-extension
Controller path - https://github.com/m2epro/magento2-extension/blob/master/Controller/Adminhtml/Amazon/Order/CreateMagentoOrder.php
Code -
$id = '9302';
$amazonobj = $objManager->get('\Ess\M2ePro\Model\Amazon\Order');
$order = $amazonobj->load($id);
print_r($order->getData());
$order->createMagentoOrder(); // Not Working
Anyone please explain how to call controller function from external php script.
Solution
try this one
$force = 'yes';
$amazonFactory = $objManager->create('\Ess\M2ePro\Model\ActiveRecord\Component\Parent\Amazon\Factory');
$order =$amazonFactory->getObjectLoaded('Order', (int)$id);
$order->getLog()->setInitiator(\Ess\M2ePro\Helper\Data::INITIATOR_USER);
if (is_null($order->getMagentoOrderId()) && $force == 'yes')
{
// Create magento order
// ---------------------------------------
try {
$order->createMagentoOrder();
echo 'Magento Order was created.';
// Create invoice
// ---------------------------------------
if ($order->getChildObject()->canCreateInvoice()) {
$result = $order->createInvoice();
}
// ---------------------------------------
// Create shipment
// ---------------------------------------
if ($order->getChildObject()->canCreateShipment()) {
$result && $this->messageManager->addSuccess($this->__('Shipment was created.'));
}
// ---------------------------------------
// ---------------------------------------
$order->updateMagentoOrderStatus();
} catch (\Exception $e) {
/**@var \Ess\M2ePro\Helper\Module\Exception $helper */
'Magento Order was not created';
}
}
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange