1

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.

closed as off-topic by Amit Bera, Manoj Deswal, Jai, Murtuza Zabuawala, Prince Patel Jan 12 '18 at 6:45

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions about third-party modules are generally off-topic because the scope of functionality and code are not available. For more information, see this meta post/answer." – Amit Bera, Manoj Deswal, Jai, Murtuza Zabuawala, Prince Patel
If this question can be reworded to fit the rules in the help center, please edit the question.

1

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';

        }
}
  • can I use this in external php script? I dont want to do anything in Module itself. – Rahul Jan 12 '18 at 6:18
  • 1
    Ya, sure you can use – Amit Bera Jan 12 '18 at 6:47
  • I am sorry to asking your help in such a way here. Please can you guide me on this question magento.stackexchange.com/questions/266549/… – Rahul Mar 21 at 10:16

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