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.
-
object manager is not best practice for Magento. Same thing you can get without object manager as well.Sarvesh Tiwari– Sarvesh Tiwari2021年11月23日 12:34:37 +00:00Commented Nov 23, 2021 at 12:34
-
Agreed but for testing purpose i am using object managerAniket Singh– Aniket Singh2021年11月23日 12:38:09 +00:00Commented Nov 23, 2021 at 12:38
1 Answer 1
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();
answered Nov 23, 2021 at 12:28
Sarvesh Tiwari
74012 silver badges41 bronze badges
Explore related questions
See similar questions with these tags.
default