dotmailer / dotmailer-magento2-extension

The official Dotdigital for Magento2 extension
https://dotdigital.com/integrations/magento
MIT License
48 stars 63 forks source link

Order export crashes if product is deleted / missing #556

Closed extroniks closed 4 years ago

extroniks commented 4 years ago

Hello,

In the following file: Model/Connector/Order.php

Following will cause a fatal error / crash if getProduct() returns null: if (in_array($productItem->getProduct()->getTypeId(), ['configurable', 'bundle'])) {

Here is a code patch I added above this line so it won't crash as a temporary fix so a single order doesn't prevent a whole batch from failing: if(!$productItem->getProduct()) { continue; }

Function in question:

private function processOrderItems($orderData, $syncCustomOption)
    {
        foreach ($orderData->getAllItems() as $productItem) {

            // fixes fatal error / crash when getProduct() returns null
            if(!$productItem->getProduct()) {
                continue;
            }

            if (in_array($productItem->getProduct()->getTypeId(), ['configurable', 'bundle'])) {
                // We store data for configurable and bundle products, to be output alongside their children
                unset($parentProductModel, $parentLineItem);
                $parentProductModel = $productItem->getProduct();
                $parentLineItem = $productItem;

                // Custom options stored against parent order items
                $customOptions = ($syncCustomOption) ? $this->_getOrderItemOptions($productItem) : [];

                continue;
            }

            ...

Happens on Magento 2.3.3.

Stefan

extroniks commented 4 years ago

Hello, nevermind I noticed it is patched in the latest version, sorry for a false report.