Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fatal error in inventory:reservation:list-inconsistencies because of wrong sku parameter type #2904

Closed
LittleBigDev opened this issue Mar 27, 2020 · 0 comments

Comments

@LittleBigDev
Copy link

Preconditions

  1. magento/inventory-composer-metapackage v1.1.3
  2. magento/module-inventory v1.0.6

Steps to reproduce

  1. Create a product with a numerical sku (for example, an EAN)
  2. Create an order with this product, to get inventory reservation(s)
  3. In inventory_reservation table, duplicate a row for this product. This will create a reservation inconsistency.
  4. Execute cli command : inventory:reservation:list-inconsistencies

Expected result

  1. Inconsistencies are listed correctly (eg: "Product 1234567891234 should be compensated by +1.000000")

Actual result

  1. Fatal error: Uncaught TypeError: Argument 1 passed to Magento\Inventory\Model\ResourceModel\IsProductAssignedToStock::execute() must be of the type string, integer given, called in /var/www/html/vendor/magento/module-inventory-reservation-cli/Model/SalableQuantityInconsistency/FilterManagedStockProducts.php on line 56 and defined in /var/www/html/vendor/magento/module-inventory/Model/ResourceModel/IsProductAssignedToStock.php:34

What I figured

After some investigation, I was able to conclude that numerical skus like EANs are added as integers in \Magento\InventoryReservationCli\Model\SalableQuantityInconsistency::addItemQty().
This is because skus are KEYS of \Magento\InventoryReservationCli\Model\SalableQuantityInconsistency::$items array. Php saves numerical string array keys as actual numbers. String type is lost.

Suggestion

Before using \Magento\InventoryReservationCli\Model\SalableQuantityInconsistency::getItems()'s result, and especially keys (skus), cast them as string again.
For example in \Magento\InventoryReservationCli\Model\SalableQuantityInconsistency\FilterManagedStockProducts::execute():

    /**
     * Remove all reservations with incomplete state
     *
     * @param SalableQuantityInconsistency[] $inconsistencies
     * @return SalableQuantityInconsistency[]
     * @throws LocalizedException
     * @throws SkuIsNotAssignedToStockException
     */
    public function execute(array $inconsistencies): array
    {
        foreach ($inconsistencies as $inconsistency) {
            $filteredItems = [];
            foreach ($inconsistency->getItems() as $sku => $qty) {
                if (false === $this->isProductAssignedToStock->execute((string)$sku, $inconsistency->getStockId())) {
                    continue;
                }

                $stockConfiguration = $this->getStockItemConfiguration->execute((string)$sku, $inconsistency->getStockId());
                if ($stockConfiguration->isManageStock()) {
                    $filteredItems[$sku] = $qty;
                }
            }
            $inconsistency->setItems($filteredItems);
        }

        return $inconsistencies;
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants