I'm working on magento2.4 .Need to get the quantity of the product in product save after observer. while get qty it always returns null for newly created products.
Note:qty shows correctly for updating the product.
<?php
namespace YOURNAMESPACE\YOURMODULENAME\Observer;
use Magento\Framework\Event\ObserverInterface;
class Productsaveafter implements ObserverInterface
{
public function execute(\Magento\Framework\Event\Observer $observer)
{
$product = $observer->getEvent()->getProduct();
$stockItem = $product->getExtensionAttributes()->getStockItem();
$stockData = $stockItem->getQty();
}
}