I need to get configurable products with parent product names, not variant names.

Getting product name and variant products names


Aether Gym Pant
Aether Gym Pant -32-Blue
Aether Gym Pant -32-Green

Suppose I have added product with 2 variant but I am getting 3 products with parent + 2 variants.

I just want to get the 2 variant products with the same parent product name(Aether Gym Pant) with variant data (such as amount, SKU no so on) not the (Aether Gym Pant -32-Blue).

Here is my code:

use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;

class SalesOrderSaveAfter implements ObserverInterface {
    protected $scopeConfig;
    protected $date;
    public function __construct(\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Framework\Stdlib\DateTime\DateTime $date)
      $this->scopeConfig = $scopeConfig;
      $this->date = $date;

   public function execute(\Magento\Framework\Event\Observer $observer) {

                $order = $observer->getEvent()->getOrder();
                foreach($order->getAllVisibleItems() as $item){
                        $pdata['emailAddress'] = $order->getCustomerEmail();
                        $pdata['orderId']= $order->getIncrementId();
                        $pdata['incrementId'] = $order->getIncrementId().$item->getProductId();
                        $pdata['productId'] = $item->getProductId();
                        $pdata['productName'] = $item->getName();
                        $pdata['productAmount'] = $item->getPrice();
                        $pdata['productSku'] = $item->getSku();
                        $pdata['productQty'] = (int)$item->getQtyOrdered();
                        $pdata['itemStatus'] = $item->getStatus();
        return $this;

Any idea?

Thanks in advance.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.