cancel
Showing results for 
Search instead for 
Did you mean: 

Argument 2 passed to Magento\InventorySales\Plugin\Sales\OrderManagement\AppendReservationsAfterOrde

Argument 2 passed to Magento\InventorySales\Plugin\Sales\OrderManagement\AppendReservationsAfterOrde

Hello

 

I am trying to make a payment with PayPal and place the order, at the link paypal/express/placeOrder/ is showing me this issue:

Uncaught TypeError: Argument 2 passed to Magento\InventorySales\Plugin\Sales\OrderManagement\AppendReservationsAfterOrderPlacementPlugin::afterPlace() must implement interface Magento\Sales\Api\Data\OrderInterface, null given, called in ...

This is the code on line 119:

 

public function afterPlace(OrderManagementInterface $subject, OrderInterface $order): OrderInterface
{
    $itemsById = $itemsBySku = $itemsToSell = [];
    foreach ($order->getItems() as $item) {
        if (!isset($itemsById[$item->getProductId()])) {
            $itemsById[$item->getProductId()] = 0;
        }
        $itemsById[$item->getProductId()] += $item->getQtyOrdered();
    }
    $productSkus = $this->getSkusByProductIds->execute(array_keys($itemsById));
    $productTypes = $this->getProductTypesBySkus->execute($productSkus);

    foreach ($productSkus as $productId => $sku) {
        if (false === $this->isSourceItemManagementAllowedForProductType->execute($productTypes[$sku])) {
            continue;
        }

        $itemsBySku[$sku] = (float)$itemsById[$productId];
        $itemsToSell[] = $this->itemsToSellFactory->create([
            'sku' => $sku,
            'qty' => -(float)$itemsById[$productId]
        ]);
    }

    $websiteId = (int)$order->getStore()->getWebsiteId();
    $websiteCode = $this->websiteRepository->getById($websiteId)->getCode();
    $stockId = (int)$this->stockByWebsiteIdResolver->execute((int)$websiteId)->getStockId();

    $this->checkItemsQuantity->execute($itemsBySku, $stockId);

    /** @var SalesEventInterface $salesEvent */
    $salesEvent = $this->salesEventFactory->create([
        'type' => SalesEventInterface::EVENT_ORDER_PLACED,
        'objectType' => SalesEventInterface::OBJECT_TYPE_ORDER,
        'objectId' => (string)$order->getEntityId()
    ]);
    $salesChannel = $this->salesChannelFactory->create([
        'data' => [
            'type' => SalesChannelInterface::TYPE_WEBSITE,
            'code' => $websiteCode
        ]
    ]);

    $this->placeReservationsForSalesEvent->execute($itemsToSell, $salesChannel, $salesEvent);
    return $order;
}

How can I solve this?

Our current Magento Version is 2.3.9 and, previously we had 2.3.4

Thanks

1 REPLY 1

Re: Argument 2 passed to Magento\InventorySales\Plugin\Sales\OrderManagement\AppendReservationsAfter

Please check custom modules have any plugin override on method place

LitExtension - #1 Shopping Cart Migration Expert

LitExtension helps store owners and agencies migrate all important data from one eCommerce platform to another accurately, securely and at the highest speed.

Visit website: http://litextension.com/