inventory icon indicating copy to clipboard operation
inventory copied to clipboard

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

Open ioweb-gr opened this issue 2 years ago • 2 comments

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

ioweb-gr avatar Jan 04 '23 10:01 ioweb-gr

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


m2-assistant[bot] avatar Jan 04 '23 10:01 m2-assistant[bot]

We were able to reproduce this as well.

Megaventory avatar Jan 05 '23 13:01 Megaventory