Skip to main content
deleted 127 characters in body
Source Link
Prashant Valanda
  • 12.7k
  • 5
  • 43
  • 69

Use below code:

public function execute(\Magento\Framework\Event\Observer $observer)
{
      $order = $observer->getEvent()->getOrder();
      $order_id = $order->getIncrementId();
     foreach($order->getAllItems() as $item){
             $ProdustIds = $item->getProductId();
     // product name
     $proName[] = $item->getName(); 


    $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
    $customProduct = $objectManager->get('Magento\Catalog\Model\Product')->load($ProdustIds);

     $productAttributeId = $customProduct->getData('attribute_set_id');

    //get attribute set name for each product
     $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
    $attributeSet = $objectManager->create('Magento\Eav\Api\AttributeSetRepositoryInterface');
    $attributeSetRepository = $attributeSet->get($productAttributeId);
    $attribute_set_name = $attributeSetRepository->getAttributeSetName();
    $attribute_name = strtolower($attribute_set_name);
    
    $StockState//use =below $objectManager->get('\Magento\CatalogInventory\Api\StockStateInterface');to get ordered qty
    echo $StockState->getStockQty($customProduct->getId(),echo $customProduct->getStore()$item->getWebsiteId>getQtyOrdered());

    //get prodcut price
    $productAttributePrice = $customProduct->getData('price');
    //product qty
    $productAttributeQty = $customProduct->getData('qty');
    $proQty[] = $item->getQty();

Use below code:

public function execute(\Magento\Framework\Event\Observer $observer)
{
      $order = $observer->getEvent()->getOrder();
      $order_id = $order->getIncrementId();
     foreach($order->getAllItems() as $item){
             $ProdustIds = $item->getProductId();
     // product name
     $proName[] = $item->getName(); 


    $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
    $customProduct = $objectManager->get('Magento\Catalog\Model\Product')->load($ProdustIds);

     $productAttributeId = $customProduct->getData('attribute_set_id');

    //get attribute set name for each product
     $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
    $attributeSet = $objectManager->create('Magento\Eav\Api\AttributeSetRepositoryInterface');
    $attributeSetRepository = $attributeSet->get($productAttributeId);
    $attribute_set_name = $attributeSetRepository->getAttributeSetName();
    $attribute_name = strtolower($attribute_set_name);
    
    $StockState = $objectManager->get('\Magento\CatalogInventory\Api\StockStateInterface');
    echo $StockState->getStockQty($customProduct->getId(), $customProduct->getStore()->getWebsiteId());

    //get prodcut price
    $productAttributePrice = $customProduct->getData('price');
    //product qty
    $productAttributeQty = $customProduct->getData('qty');
    $proQty[] = $item->getQty();

Use below code:

public function execute(\Magento\Framework\Event\Observer $observer)
{
      $order = $observer->getEvent()->getOrder();
      $order_id = $order->getIncrementId();
     foreach($order->getAllItems() as $item){
             $ProdustIds = $item->getProductId();
     // product name
     $proName[] = $item->getName(); 


    $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
    $customProduct = $objectManager->get('Magento\Catalog\Model\Product')->load($ProdustIds);

     $productAttributeId = $customProduct->getData('attribute_set_id');

    //get attribute set name for each product
     $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
    $attributeSet = $objectManager->create('Magento\Eav\Api\AttributeSetRepositoryInterface');
    $attributeSetRepository = $attributeSet->get($productAttributeId);
    $attribute_set_name = $attributeSetRepository->getAttributeSetName();
    $attribute_name = strtolower($attribute_set_name);
    
    //use below to get ordered qty
     echo $item->getQtyOrdered();

    //get prodcut price
    $productAttributePrice = $customProduct->getData('price');
    //product qty
    $productAttributeQty = $customProduct->getData('qty');
    $proQty[] = $item->getQty();
Source Link
Prashant Valanda
  • 12.7k
  • 5
  • 43
  • 69

Use below code:

public function execute(\Magento\Framework\Event\Observer $observer)
{
      $order = $observer->getEvent()->getOrder();
      $order_id = $order->getIncrementId();
     foreach($order->getAllItems() as $item){
             $ProdustIds = $item->getProductId();
     // product name
     $proName[] = $item->getName(); 


    $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
    $customProduct = $objectManager->get('Magento\Catalog\Model\Product')->load($ProdustIds);

     $productAttributeId = $customProduct->getData('attribute_set_id');

    //get attribute set name for each product
     $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
    $attributeSet = $objectManager->create('Magento\Eav\Api\AttributeSetRepositoryInterface');
    $attributeSetRepository = $attributeSet->get($productAttributeId);
    $attribute_set_name = $attributeSetRepository->getAttributeSetName();
    $attribute_name = strtolower($attribute_set_name);
    
    $StockState = $objectManager->get('\Magento\CatalogInventory\Api\StockStateInterface');
    echo $StockState->getStockQty($customProduct->getId(), $customProduct->getStore()->getWebsiteId());

    //get prodcut price
    $productAttributePrice = $customProduct->getData('price');
    //product qty
    $productAttributeQty = $customProduct->getData('qty');
    $proQty[] = $item->getQty();