2

I want to get all allow attributes of a product in single page.

In magento 1.7 i was using below code :

<?php $_attributes = Mage::helper('core')->decorateArray($this->getAllowAttributes()); ?>

But how can i achieve same thing in magento 2 ?

Also I have to display all these attributes in single product page. So how to render configurable.phtml file inside single product page file?

2
  • 1
    you mean all the allowed configurable attributes for a configurable product or all the attributes of a certain product (simple, configurable, virtual, ...) ?
    – Marius
    Nov 28, 2016 at 7:05
  • Yes @Marius. all the allowed configurable attributes for a configurable product
    – Yudi
    Nov 28, 2016 at 8:14

3 Answers 3

1

If you have a product object then you can it configurable product

 public function __construct(     ...
    \Magento\Framework\Stdlib\ArrayUtils $arrayUtils,     ....) {     ....
    $this->arrayUtils = $arrayUtils;  .....
}

public function decorateArray($array, $prefix = 'decorated_', $forceSetAll = false)
{
    return $this->arrayUtils->decorateArray( $_product->getTypeInstance()->getConfigurableAttributes($_product), $prefix, $forceSetAll);
}
0

In Magento-2 you can use like this.

$_attributes = $block->decorateArray($block->getAllowAttributes());
8
  • I am using this. But its not working...:(
    – Yudi
    Nov 28, 2016 at 6:54
  • In Which file you are used ? Nov 28, 2016 at 6:56
  • I am Using configurable.phtml file inside Magento_catalog/product/view/type/options/ also i tried to use view.phtml file inside MAgento_catalog/product/view.phtml file.
    – Yudi
    Nov 28, 2016 at 6:59
  • If i use this in configurable.phtml file, Then i have to call configurable.phtml file in view.phtml . and in magento 1.7, configurable.phtml file was calling from container1 or container2. And i am not getting this thing also. what is container1 and container2 which are using in catalog.xml file. They are calling in view.phtml file like this <?php echo $this->getChildChildHtml('container2', '', true, true); ?>. Totally confused, what is happening in magento 1.7 and what to do to achieve this things in magento2. :(
    – Yudi
    Nov 28, 2016 at 7:03
  • There is a wrong file path. You have to use this file in your theme vendor/magento/module-configurable-product/view/frontend/templates/product/view/type/options/configurable.phtml Nov 28, 2016 at 7:03
0

You can use like this,

$this->_product->getTypeInstance()->getConfigurableAttributes($this->_product);

May be it will help you.

Your Answer

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

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