magento / inventory

Magento Inventory Project (a.k.a MSI)
Open Software License 3.0
338 stars 248 forks source link

Call to a member function getIsVirtual() on null #2271

Open csdougliss opened 5 years ago

csdougliss commented 5 years ago

Magento 2.3.1, happens locally using PHP 7.2, after returned from my 3dsecure test gateway to confirm order success.

Fatal error: Uncaught Error: Call to a member function getIsVirtual() on null in /home/ccarnell/Sites/vax-uk2/vendor/magento/module-inventory-shipping/Observer/VirtualSourceDeductionProcessor.php:160 Stack trace: #0 /home/ccarnell/Sites/vax-uk2/vendor/magento/module-inventory-shipping/Observer/VirtualSourceDeductionProcessor.php(148): Magento\InventoryShipping\Observer\VirtualSourceDeductionProcessor->hasValidItems(Object(Magento\Sales\Model\Order\Invoice)) #1 /home/ccarnell/Sites/vax-uk2/vendor/magento/module-inventory-shipping/Observer/VirtualSourceDeductionProcessor.php(92): Magento\InventoryShipping\Observer\VirtualSourceDeductionProcessor->isValid(Object(Magento\Sales\Model\Order\Invoice)) #2 /home/ccarnell/Sites/vax-uk2/vendor/magento/framework/Event/Invoker/InvokerDefault.php(72): Magento\InventoryShipping\Observer\VirtualSourceDeductionProcessor->execute(Object(Magento\Framework\Event\Observer)) #3 /home/ccarnell/Sites/vax-uk2/vendor/magento/framework/Event/Invoker/InvokerDefault.php(60): Magento\Framework\Event\I in /home/ccarnell/Sites/vax-uk2/vendor/magento/module-inventory-shipping/Observer/VirtualSourceDeductionProcessor.php on line 160
ishakhsuvarov commented 5 years ago

Hi @craigcarnell Some additional context on your 3dsecure test gateway would be really helpful. Does it use any specific controllers when order is placed? What is the flow in general?

csdougliss commented 5 years ago

@ishakhsuvarov order is saved, pending payment status

Customer is re-directed to a controller, which verifies that the customer is enrolled in 3dsecure through an API call.

If the customer is enrolled, they are re-directed to the bank, which then re-directs them back to the same controller in Magento.

There the order is captured (if 3dsecure was succesful):

/**
     * @param OrderInterface $order
     */
    protected function capture($order) {

        if(!$order) {
            return false;
        }

        /** @var Invoice $invoice */
        $invoice = null;

        if(!$order->hasInvoices()) {
            return false;
        }

        foreach ($order->getInvoiceCollection() as $previousInvoice) {
            $invoice = $previousInvoice;
            $invoice->capture();
        }

        if($invoice && $invoice->getId()) {
            $this->invoiceRepository->save($invoice);
        }
    }