3

I want to get all the products with all attributes it tried

$productCollectionFactory = $objectManager->get('\Magento\Catalog\Model\ResourceModel\Product\CollectionFactory');
$collection = $productCollectionFactory->create();
$collection->addAttributeToFilter(
    'status', array('eq' => \Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED)
);
$collection->setStoreId(1);
echo '<pre>';

foreach ($collection as $productcollection) {
// $productcollection->save();
 print_r($productcollection->getData());

}

so If try this then it returns me specific attributes not all the attributes as you can see from the image
enter image description here
but if I remove the comment from the $productioncollection->save() as you can see from the above code then it shows all the attributes as shown in the image below
enter image description here
but after getting three(3) products it gives me an error
t
how to solve this error or how to get products with all attributes?

3

Update your code like below:

    $collection->addAttributeToFilter(
    'status', array('eq' => \Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED)
    )->addAttributeToSelect('*');
$collection->setStoreId(1);
echo '<pre>';
foreach ($collection as $productcollection) {
    // $productcollection->save();
    print_r($productcollection->getData());
}

Let me know it's working OR not?

  • Thank U Sir :) it works – Asad Khan Jun 26 at 12:46
  • Welcome. 1+ for mark as read. :) – Ravi Soni Jun 26 at 12:47

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.