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?

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>";
}
  • It is not what I ask. Also my ask for magento 1.9 - not 2. – makz Oct 22 at 20:03
0

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

Thanks

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

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.