I am not sure I understand your question but you can add a new extension attributes that check stock status in rest/V1/carts/mine/items
and display the appropriate message.
Create your extension attribute in Vendor/ModuleName/etc/webapi_rest/extension_attributes.xml
<extension_attributes for="Magento\Quote\Api\Data\CartItemInterface">
<attribute code="stock" type="string" />
</extension_attributes>
Then Create your plugin to overwrite Magento\Quote\Model\Quote\Item\Repository::getList
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\Quote\Model\Quote\Item\Repository">
<plugin name="stock" type="Vendor\ModuleName\Plugin\Stock" disabled="false" sortOrder="70"/>
</type>
</config>
Then Create Stock.php in Vendor\ModuleName\Plugin\Stock.php
In Stock.php, we overwrite GetList with aroundplugin. We also get StockRegistryInterface to check If item is in stock by sku. Then we pass the message to our extension interface factory.
<?php
/**
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Vendor\ModuleName\Plugin;
use Magento\Quote\Model\Quote\Item\Repository as ItemRepository;
class Stock
{
protected $quoteRepository;
protected $cartItemExtensionFactory;
protected $stockRegistry;
public function __construct(
\Magento\Quote\Api\CartRepositoryInterface $quoteRepository,
\Magento\Quote\Api\Data\CartItemExtensionFactory $cartItemExtensionFactory,
\Magento\CatalogInventory\Api\StockRegistryInterface $stockRegistry
) {
$this->quoteRepository = $quoteRepository;
$this->stockRegistry = $stockRegistry;
$this->cartItemExtensionFactory = $cartItemExtensionFactory;
}
public function aroundGetList(ItemRepository $subject, \Closure $proceed, $cartId)
{
$cartItems = $proceed($cartId);
/** @var \Magento\Quote\Model\Quote $quote */
$quote = $this->quoteRepository->getActive($cartId);
/** @var \Magento\Quote\Api\Data\CartItemExtensionInterface $extensionAttributes */
$i = 0;
foreach ($quote->getAllVisibleItems() as $item) {
$extensionAttributes = $cartItems[$i]->getExtensionAttributes();
if ($extensionAttributes === null) {
$extensionAttributes = $this->cartItemExtensionFactory->create();
}
$sku = $item->getSku();
$stock = $this->stockRegistry->getStockItemBySku($sku)->getIsInStock();
if ($stock) {
$message = "Item In Stock";
} else {
$message = "Item Out Of Stock";
}
$extensionAttributes->setStock($message);
$cartItems[$i]->setExtensionAttributes($extensionAttributes);
$i++;
}
// $cartItems->setExtensionAttributes($extensionAttributes);
return $cartItems;
}
}
Thanks