1

Is there any way to get all attributes of configurable products in the product listing page. Like as magento 1

<?php $simple_collection = $conf->getUsedProductCollection()->addAttributeToSelect('*')->addFilterByRequiredOptions(); ?>

So how to show all attributes ?

1 Answer 1

0

We should try:

    /**
     * @var \Magento\ConfigurableProduct\Model\Product\Type\Con‌​figurable
     */
    protected $configurableType;
    .......

   $collection = $this->configurableType->getUsedProductCollection($this->getProduct())
                           ->add‌​AttributeToSelect('*‌​')
                           ->addFilterByRequi‌​redOptions();
9
  • if we don't want any change in the core files, is there any way to call all of that attributes inside our list.phtml file in the theme?
    – Yudi
    Sep 14, 2016 at 12:24
  • We should override the core Magento. Actually, we can get the collection directly on phtml by using object Manager. But, this way discourages by Magento 2 best practice. Sep 14, 2016 at 12:27
  • exactly i am overriding the core magento code. can you please share the code using object manager code, how to get all attributes?
    – Yudi
    Sep 14, 2016 at 12:29
  • thanks khoa...but using this code we just get 'name' only. I want all the attributes and show all of them with corresponding values in an array? can we get all attributes in an array? so that using loop we can display all the attributes and their values?
    – Yudi
    Sep 14, 2016 at 12:38
  • You should try $product = \Magento\Framework\App\ObjectManager::getInstance() ->create('Magento\Catalog\Model\ProductFactory'); $product->getCollection()->addAttributeToSelect('*'); Sep 14, 2016 at 12:40

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.