0

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.

asked Nov 23, 2021 at 11:35
2
  • object manager is not best practice for Magento. Same thing you can get without object manager as well. Commented Nov 23, 2021 at 12:34
  • Agreed but for testing purpose i am using object manager Commented Nov 23, 2021 at 12:38

1 Answer 1

0

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

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.