AmpersandHQ / magento2-disable-stock-reservation

This module disables the inventory reservation logic introduced as part of MSI in Magento 2.3.3
GNU Lesser General Public License v3.0
211 stars 60 forks source link

Exception while canceling old orders: Source model with the order ID "%1" does not exist #125

Closed raulsinapsis closed 9 months ago

raulsinapsis commented 9 months ago

I understand this happens since database table order_sources was added If you try canceling old orders, which has no data in that database table then exception is thrown

To fix this, I understand this code should return default source model instead of throwing that exception

    public function getByOrderId(string $orderId): SourcesInterface
    {
        /** @var SourcesModel $sourcesModel */
        $sourcesModel = $this->sourcesFactory->create();

        $this->sourcesResourceModel->load(
            $sourcesModel,
            $orderId,
            SourcesInterface::ORDER_ID_KEY
        );

        if (!$sourcesModel->getId()) {
            throw new NoSuchEntityException(__('Source model with the order ID "%1" does not exist', $orderId));
        }

        return $sourcesModel;
    }
convenient commented 9 months ago

Recently worked on in https://github.com/AmpersandHQ/magento2-disable-stock-reservation/pull/124

I think rather than modifying any sources the approach for old orders would be to do no stock modification, rather than returning stock to somewhere inappropriate?