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

Wrong total_count on GET /V1/inventory/export-stock-salable-qty/{salesChannelType}/{salesChannelCode} API #3416

Open
lamasfoker opened this issue Sep 27, 2024 · 1 comment

Comments

@lamasfoker
Copy link

Preconditions

  1. MSI tagged with 1.2.7-beta3, but also previous versions have the same bug;
  2. A fixed number of products, in this example 95486.

Steps to reproduce

Call the GET /V1/inventory/export-stock-salable-qty/{salesChannelType}/{salesChannelCode} API

curl --location --globoff 'https://127.0.0.1:8080/rest/V1/inventory/export-stock-salable-qty/{salesChannelType}/{salesChannelCode}?searchCriteria[currentPage]=5&searchCriteria[pageSize]=1000' \
--header 'Authorization: Bearer TOKEN' 

Expected result

total_count should return the number of product with stock item in the select sales channel:

{
    "items": [
        {
            "sku": "SKU_1",
            "qty": 0,
            "is_salable": false
        },
        [...]
        {
            "sku": "SKU_1000",
            "qty": 0,
            "is_salable": false
        }
    ],
    "search_criteria": {
        "filter_groups": [],
        "page_size": 1000,
        "current_page": 5
    },
    "total_count": 95486
}

Actual result

total_count return instead the number of items in the current response:

{
    "items": [
        {
            "sku": "SKU_1",
            "qty": 0,
            "is_salable": false
        },
        [...]
        {
            "sku": "SKU_1000",
            "qty": 0,
            "is_salable": false
        }
    ],
    "search_criteria": {
        "filter_groups": [],
        "page_size": 1000,
        "current_page": 5
    },
    "total_count": 1000
}

You can crearly see the bug here. Proposed solution:

    public function execute(
        \Magento\InventorySalesApi\Api\Data\SalesChannelInterface $salesChannel,
        \Magento\Framework\Api\SearchCriteriaInterface $searchCriteria
    ): ExportStockSalableQtySearchResultInterface {
        $stock = $this->getStockBySalesChannel->execute($salesChannel);
        $productSearchResult = $this->getProducts($searchCriteria);
        $items = $this->preciseExportStockProcessor->execute($productSearchResult->getItems(), $stock->getStockId());
        /** @var ExportStockSalableQtySearchResultInterface $searchResult */
        $searchResult = $this->exportStockSalableQtySearchResultFactory->create();
        $searchResult->setSearchCriteria($productSearchResult->getSearchCriteria());
        $searchResult->setItems($items);
-        $searchResult->setTotalCount(count($items));
+        $searchResult->setTotalCount($productSearchResult->getTotalCount());

        return $searchResult;
    }
Copy link

m2-assistant bot commented Sep 27, 2024

Hi @lamasfoker. 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


Join Magento Community Engineering Slack and ask your questions in #github channel.

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

1 participant