I am trying to use plugin to override Magento\Checkout\Model\Cart.php
- addOrderItem function
Instead of getting item's quantity, how to check if product is salable using isSalable()? Is there any way to use product id to get if product is isSalable().
public function aroundAddOrderItem($subject, callable $proceed, $orderItem, $qtyFlag = null)
{
if ($orderItem->getParentItem() === null) {
$sku = $orderItem->getSku();
$productId=$this->product->getIdBySku($sku);
$productStock = $this->stockItemRepository->get($productId);
$productQty = $productStock->getQty();
if($productQty < 1)
{
return $this;
}
else
{
return $proceed($orderItem, $qtyFlag);
}
}
return $this;
}