How can I get all columns all or all attributes on product if there is no data on it?

For example this one : enter image description here

How can I get the list of (post_id, name, url_key, post_content, tags, status, featured_image, created_at, updated_at).

  • May I know which Magento version are you using also Please provide any code you have – poojan sharma Jul 22 '19 at 3:59
  • I'm using Magento 2.3.1 @poojansharma – Fiko iCube Jul 23 '19 at 0:49

First of all, add ProductRepository in your custom module __construct

public function __construct(\Magento\Catalog\Model\ProductRepository $productRepository)
   $this->_productRepository = $productRepository;

Then call a getProductAttribute function with argument SKU. Below is the code for the same.

public function getProductAttribute($sku)
        $new= array();
        $product = $this->_productRepository->get($sku);
        $attributes = $product->getAttributes();
        foreach($attributes as $a)
            $new[$a->getName()] = $product->getData($a->getName());
      return $new; 

Note: before execute code make sure run below command

php bin/magento setup:di:compile
php bin/magento cache:clean

Your Answer

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

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