postnl / postnl-magento2

This is the official Magento 2 extension for the logistics company PostNL. Add shipping options and parcelshops to your checkout. Create labels with track and trace functionality from the backend.
58 stars 60 forks source link

Error when creating shipment when no PostNLOrder is present #54

Closed markPostema closed 6 years ago

markPostema commented 6 years ago

In the function get in the file postnl-magento2/Service/Handler/SentDateHandler.php a postnlOrder is retrieved and this postnlOrder is passed on to $this->sentDate->setParameters. Except in our shop a postnlOrder isn't always created in the table. So the postnlOrder is actually NULL and this generates an error when you want to create a shipment from the order grid. I've quickly fixed this by inserting this code:

if(!$postnlOrder){
            $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
            $order = $objectManager->create('\Magento\Sales\Model\Order')->load($shipment->getOrderId());

            $neworder = $this->orderRepository->create();
            // $neworder->setData($postnlOrder->getData());
            $neworder->setData('order_id', $order->getId());
            $neworder->setData('quote_id', $order->getQuoteId());
            $neworder->setData('parcel_count', 1);
            $this->orderRepository->save($neworder);

            $postnlOrder = $this->getPostnlOrder($shipment);
        }

But this isn't the way this should be fixed, I know. Could not find why the postnlOrder isn't created in the first place so this has to do the trick for now. Orders do have the correct shipping method stored.

Are there other, better fixes for this problem?

tig-jeffreybranderhorst commented 6 years ago

Good day Mark,

Unfortunately, we don't have a fix for this, if you can find out why the order isn't in the postnl_order table then you will automatically fix this problem. Do you maybe have other extensions that could be influencing the quote?

Best regard, Jeffrey Branderhorst

tig-rikjonkmans commented 6 years ago

Good day,

I will close this issue. If you keep having, or still have problems i suggest contacting us at sd@tig.nl