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. Nov 23, 2021 at 12:34
  • Agreed but for testing purpose i am using object manager 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();


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();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.