Error: Cannot instantiate interface MagentoInventorySalesApiApiGetProductSalableQtyInterface
Found this error while removing deprecation of StockStateInterface for REST API, Does anyone has an idea why this error occurs? Thanks in advance
My code is
namespace VendorModulePlugin;
use MagentoCatalogApiProductRepositoryInterface;
use MagentoInventorySalesApiApiGetProductSalableQtyInterface;
use MagentoQuoteApiCartRepositoryInterface;
use MagentoQuoteApiDataCartItemExtensionFactory;
use PsrLogLoggerInterface;
class CartItemPlugin
{
/**
* @var CartItemExtensionFactory
*/
protected $cartItemExtension;
/**
* @var ProductRepositoryInterface
*/
protected $productRepository;
/**
* @var GetProductSalableQtyInterface
*/
protected $stockState;
/**
* @var LoggerInterface
*/
protected $logger;
/**
* @param CartItemExtensionFactory $cartItemExtension
* @param ProductRepositoryInterface $productRepository
* @param LoggerInterface $logger
* @param GetProductSalableQtyInterface $stockState
*/
public function __construct(
CartItemExtensionFactory $cartItemExtension,
ProductRepositoryInterface $productRepository,
LoggerInterface $logger,
GetProductSalableQtyInterface $stockState
) {
$this->cartItemExtension = $cartItemExtension;
$this->productRepository = $productRepository;
$this->logger = $logger;
$this->stockState = $stockState;
}
public function afterSave(CartRepositoryInterface $subject,$quote
) {
if ($quote !=null) {
foreach ($quote->getItems() as $item) {
$productData = $this->productRepository->get($item->getSku());
$stock = $this->stockState->getStockQty($productData->getId());
$stockArray = [
'image' => $productData->getThumbnail(),
'special_price' => $productData->getPrice(),
'stock_qty' => $stock,
'is_in_stock' => $productData->getStatus() ? "Yes" : "NO",
];
$extensionAttributes = $item->getExtensionAttributes();
$extensionAttributes->setStockItem($stockArray);
$item->setExtensionAttributes($extensionAttributes);
}
}
return $quote;
}
}