1

I am trying to get category_ids but below code working for me. but print_r($collection->getData()); Not showing attribute values but in foreach data is there.

foreach ($collection as  $product) {
   print_r($product->getCategoryIds()); // this is working fine 
}

my code to get collection

   protected $_productCollectionFactory;


   public function __construct( .....
        \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory,               
                          ....

            .....
            $this->_productCollectionFactory = $productCollectionFactory; 
            ......
    }


    $collection = $this->_productCollectionFactory->create()->addAttributeToSelect(array('category_ids'));

0

Your Answer

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

Browse other questions tagged or ask your own question.