1

Show Error after click ship only one product

enter image description here

Fatal error: Uncaught Error: Call to a member function getTypeId() on null in /var/www/vhosts/xyz.com/httpdocs/vendor/magento/module-inventory-shipping-admin-ui/Model/IsOrderSourceManageable.php:71 Stack trace: #0 /var/www/vhosts/xyz.com/httpdocs/vendor/magento/module-inventory-shipping-admin-ui/Observer/NewShipmentLoadBefore.php(81): Magento\InventoryShippingAdminUi\Model\IsOrderSourceManageable->execute(Object(Squareup\Omni\Model\Sales\Order\Interceptor)) #1 /var/www/vhosts/xyz.com/httpdocs/vendor/magento/framework/Event/Invoker/InvokerDefault.php(72): Magento\InventoryShippingAdminUi\Observer\NewShipmentLoadBefore->execute(Object(Magento\Framework\Event\Observer)) #2 /var/www/vhosts/xyz.com/httpdocs/vendor/magento/framework/Event/Invoker/InvokerDefault.php(60): Magento\Framework\Event\Invoker\InvokerDefault->_callObserverMethod(Object(Magento\InventoryShippingAdminUi\Observer\NewShipmentLoadBefore), Object(Magento\Framework\Event\Observer)) #3 /var/www/vhosts/xyz.com/httpdoc in /var/www/vhosts/xyz.com/httpdocs/vendor/magento/module-inventory-shipping-admin-ui/Model/IsOrderSourceManageable.php on line 71
4
  • add your code into question Mar 13, 2020 at 11:37
  • 1
    Well, can you check if the product you are trying to ship still exists in Magento and it isn't deleted?
    – Tsita
    Mar 13, 2020 at 11:44
  • @Tsita Yes i have 5 product in this orders one product are delete screenshot: prnt.sc/rfs0ek
    – DK Thakur
    Mar 13, 2020 at 11:53
  • @DineshThakur See my answer for more details
    – Tsita
    Mar 13, 2020 at 11:57

1 Answer 1

5

If i get this right then in the following function

public function execute(OrderInterface $order): bool
{
    $stocks = $this->stockRepository->getList()->getItems();
    $orderItems = $order->getItems();
    foreach ($orderItems as $orderItem) {
        $productType = $orderItem->getProduct()->getTypeId();
        if (!$this->isSourceItemManagementAllowedForProductType->execute($productType)) {
            continue;
        }

        /** @var StockInterface $stock */
        foreach ($stocks as $stock) {
            $inventoryConfiguration = $this->getStockItemConfiguration->execute(
                $this->getSkuFromOrderItem->execute($orderItem),
                $stock->getStockId()
            );

            if ($inventoryConfiguration->isManageStock()) {
                return true;
            }
        }
    }

    return false;
}

You should replace this line by overriding the class in a module.

$productType = $orderItem->getProduct()->getTypeId();

with this

$productType = $orderItem->getProduct() ? $orderItem->getProduct()->getTypeId() : '';

The product is possibly deleted and the system is trying to get the type id of a not existing product. This part equals to null $orderItem->getProduct() in your case.

This has already been fixed in the latest releases of Magento.

5

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.