I want to get the Product attribute using Object manager and check the availability of the product if its RTS I have to assign that product to a category id.
1 Answer
Product Attribute
You can get product attribute with below code -
$product = $this->getProduct();
$ressource = $product->getResource();
$store = $this->_storeManager->getStore();
$ressource->getAttributeRawValue($product->getId(),'attribute_code',$store->getId());
Product Availability
public function __construct(
\Magento\CatalogInventory\Api\StockRegistryInterface $stockRegistry
) {
$this->stockRegistry = $stockRegistry;
}
// you can pass $product object to the function
public function getStockStatus($product)
{
return $this->stockRegistry->getStockItem($product->getId());
}
You can get all the stock details by
$stockItem = $this->stockRegistry->getStockItem($product->getId());
$stockData = $stockItem->getData();
$stockItem->getIsInStock();