MSI: assignStatusToProduct for multi stocks is getting the wrong stock id
@nmalevanec is already working on this.
Since Apr 14, 2020.
- Dominant language
- PHP
- Stars
- 357
- Forks
- 262
- PR merge metrics
- No merged PRs in 30d
Description
Hello,
I think there is an error when magento try to get the stock id. Current store is selected instead of selecting product's store which leads to product availability errors when I try to create an order from a rma's order in admin.
### Preconditions (*)
1. magento/project-enterprise-edition 2.3.0
2.
### Steps to reproduce (*)
1. Enable multi stocks
2. Set quantity from product to stock A = 0 and stock B = 10
3. Store 1 should use stock A and Store 2 should use stock B
2. Create a product from an order item
2. Set product store id from order store id which was stock B
3. Check isSalable
```
$product = $this->_objectManager->create(Product::class)
->setStoreId($order->getStoreId())
->load($orderItem->getProductId());
if ($product->isSalable()) {
$unavailableProducts[] = $orderItem->getSku();
}
```
### Expected result (*)
1. isSalable should return true
### Actual result (*)
1. isSalable is false
2. Plugin/CatalogInventory/Helper/Stock/AdaptAssignStatusToProductPlugin.php is looking for stock id of current website which is not the website from the product.
So product availability in admin is calculate upon wrong website.
Which I did to try to fix it :
- I disabled plugin adapt_add_stock_status_to_products + adapt_assign_status_to_product
- I created new plugin which send "storeCode" through "Model\GetStockIdForCurrentWebsite"
```
$storeCode = '';
if (!is_null($product->getStore())) {
$storeCode = $product->getStore()->getCode();
}
$stockId = $this->getStockIdForCurrentWebsite->execute($storeCode);
```
- I override Model\GetStockIdForCurrentWebsite.php
```
public function execute($websiteCode = ''): int
{
if(empty($websiteCode)) {
$websiteCode = $this->storeManager->getWebsite()->getCode();
}
$stock = $this->stockResolver->execute(SalesChannelInterface::TYPE_WEBSITE, $websiteCode);
$stockId = (int)$stock->getStockId();
return $stockId;
}
```
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.