0

How can I get all attributes of product with its values? I mean attributes like size, color, gender and like that, but not availablity, quantity or sku. I need to use them for filters, how can I get it?

2 Answers 2

1

you have write on block class file

<?php
namespace Pradip\Magegig\Block;
class Products extends \Magento\Framework\View\Element\Template
{    
    protected $_productCollectionFactory;

    public function __construct(
        \Magento\Backend\Block\Template\Context $context,        
        \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory,        
        array $data = []
    )
    {    
        $this->_productCollectionFactory = $productCollectionFactory;    
        parent::__construct($context, $data);
    }

    public function getProductCollection()
    {
        $collection = $this->_productCollectionFactory->create();
        $collection->addAttributeToSelect('*');
        $collection->setPageSize(3); 
        return $collection;
    }
}
?>

in Phtml file you will getting all attribute along with product

$productCollection = $block->getProductCollection();
foreach ($productCollection as $product) {
    print_r($product->getData());     
    echo "<br>";
}
1
  • It is not what I ask. Also my ask for magento 1.9 - not 2.
    – makz
    Oct 22, 2019 at 20:03
0

Please check the link. Which have all the answer of your question.

Thanks

2
  • There no answer for my question.
    – makz
    Oct 22, 2019 at 20:05
  • Means I am not getting you.
    – Mayur
    Oct 23, 2019 at 4:00

Your Answer

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

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