4

I'm working on an order updater and got everything working except for the shipment notifier (sending the email on order completion).

The log below shows looping over three orders and the errors being thrown when $this->ShipmentNotifier->notify($shipment); is being called.
I already load configuration using $objectManager->configure($configLoader->load('frontend'));

My log is as follows:

[2016-12-23 09:02:48] main.INFO: Company\Plugin\Cron\Orders::update [] []
[2016-12-23 09:02:48] main.INFO: Updating 000000006 [] []
[2016-12-23 09:02:49] main.ERROR: Required parameter 'theme_dir' was not passed [] []
[2016-12-23 09:02:49] main.INFO: Updating 000000013 [] []
[2016-12-23 09:02:49] main.ERROR: Environment emulation nesting is not allowed. [] []
[2016-12-23 09:02:49] main.ERROR: From Header set twice [] []
[2016-12-23 09:02:49] main.INFO: Updating 000000015 [] []
[2016-12-23 09:02:49] main.ERROR: From Header set twice [] []

Even with the errors being thrown ShipmentNotifier is still returning true.
What am I missing?

ps: The code I'm using is largely following this tutorial: http://www.magestore.com/magento-2-tutorial/how-to-create-shipment-programmatically-in-magento-2/ Only difference being that I am using dependency injection instead of the object manager.

2 Answers 2

1

I assume you call $objectManager->configure($configLoader->load('frontend')); within the class where you pass the shipment notifier via dependency injection.

This is too late. The object manager already has created the object and its dependencies, but not within the frontend area, that's why theme_dir is missing.

You can defer object creation by using a proxy:

public function __construct(\Magento\Shipping\Model\ShipmentNotifier\Proxy $notifier)

Now the real object is not created before you call any methods on it.

1
  • Sadly still running into the same issue, thanks anyway.
    – HTDutchy
    Commented Jan 2, 2017 at 14:18
0

Since theme_dir won't load while running from command line I have created a work-around and have put the code where I am using the shipment notifier in a public controller.

This controller is then called using a curl call in the cronjob.
While a kind off hacky solution, it works and is still completely contained within Magento.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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