magento / inventory

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

\Magento\InventoryShipping\Model\InventoryRequestFromOrderFactory not working for bundle products #3369

Open ioweb-gr opened 1 year ago

ioweb-gr commented 1 year ago

Preconditions (*)

  1. Magento 2.4.3-p1
  2. Inventory 1.2.1-p1

Steps to reproduce (*)

  1. Create a bundle product with one physical item and 2 virtual ones

image

  1. Place an order with the bundle product
  2. Make sure the order doesn't have any other type of product
  3. Create a sample class
<?php
/**

namespace Vendor\Module\Helper;

use Magento\Framework\App\Helper\AbstractHelper;
use Magento\Framework\App\Helper\Context;
use Magento\InventoryShipping\Model\InventoryRequestFromOrderFactory;
use Magento\Sales\Api\Data\OrderInterface;
use Magento\Sales\Api\Data\OrderItemInterface;

class SourceSelection extends AbstractHelper
{
    protected $inventoryRequestFromOrderFactory;
    protected $sourceSelectionService;

    public function __construct(
        \Magento\InventorySourceSelectionApi\Api\SourceSelectionServiceInterface $sourceSelectionService,
        InventoryRequestFromOrderFactory                                         $inventoryRequestFromOrderFactory,
        Context                                                                  $context
    )
    {
        $this->inventoryRequestFromOrderFactory = $inventoryRequestFromOrderFactory;
        $this->sourceSelectionService = $sourceSelectionService;
        parent::__construct($context);
    }

    public function getAlgorithmSourceCode()
    {
        return $this->scopeConfig->getValue('vendor/orders/source_selection_algorithm_code');
    }

    /**
     * @param OrderInterface $order
     * @return void
     */
    public function getPreferredSource($order)
    {
        $inventoryRequest = $this->inventoryRequestFromOrderFactory->create($order);
        $result = $this->sourceSelectionService->execute($inventoryRequest, $this->getAlgorithmSourceCode());
        return $result;
    }
}

However the same issue doesn't happen when you ship the order from the backend and everything works as expected.

Expected result (*)

The $inventoryRequest contains the bundle SKU product

This is the sample inventory request created when shipping the product via the backend. As you can see it contains one product the physical one.

image image

Actual result (*)

  1. The $inventoryRequest contains an empty items array

image

m2-assistant[bot] commented 1 year ago

Hi @ioweb-gr. Thank you for your report. To speed up processing of this issue, make sure that you provided sufficient information.

Add a comment to assign the issue: @magento I am working on this


Megaventory commented 1 year ago

We were able to reproduce this as well.