cancel
Showing results for 
Search instead for 
Did you mean: 

Custom Product Attribute - Display based on attrubite?

Custom Product Attribute - Display based on attrubite?

Hi all....

I have a number of custom product attributes containing key features.

Each attribute is a multiple selection type.

For example, one of the attributes is 'key_features_air' and another would be 'key_features_ground', etc..

Each attribute contains different sets of values and have different attribute codes.

I want to display these 'key features' on the product detail page (under the product price).

How can I display the correct attribute code values depending on the products custom attribute?

I am using this code in my custom theme layout and this does display the attribute values for the 'key_features_air'.

But how would I do this dependent on the attribute that the product is using?

 

Code:

<block class="Magento\Catalog\Block\Product\View" name="product.attribute.key_features_air" template="product/view/attribute.phtml">
<arguments>
<argument name="at_call" xsi:type="string">getkey_features_air</argument>
<argument name="at_code" xsi:type="string">key_features_air</argument>
<argument name="at_label" xsi:type="string">Key Features Air</argument>
<argument name="css_class" xsi:type="string">key_features_air</argument>
</arguments>
</block>

Many Thanks in Advance

Andy

 

3 REPLIES 3

Re: Custom Product Attribute - Display based on attrubite?


@Prepaid Gift Balance wrote:

Hi all....

I have a number of custom product attributes containing key features.

Each attribute is a multiple selection type.

For example, one of the attributes is 'key_features_air' and another would be 'key_features_ground', etc..

Each attribute contains different sets of values and have different attribute codes.

I want to display these 'key features' on the product detail page (under the product price).

How can I display the correct attribute code values depending on the products custom attribute?

I am using this code in my custom theme layout and this does display the attribute values for the 'key_features_air'.

But how would I do this dependent on the attribute that the product is using?

 

Code:

<block class="Magento\Catalog\Block\Product\View" name="product.attribute.key_features_air" template="product/view/attribute.phtml">
<arguments>
<argument name="at_call" xsi:type="string">getkey_features_air</argument>
<argument name="at_code" xsi:type="string">key_features_air</argument>
<argument name="at_label" xsi:type="string">Key Features Air</argument>
<argument name="css_class" xsi:type="string">key_features_air</argument>
</arguments>
</block>

Many Thanks in Advance

Andy

 


You can display custom product attribute on category page. 

$_getMyAttr = $_product->getResource()->getAttribute('model_no'); // attribute name

// Get Value$attrTestValue = $_getMyAttr->getFrontend()->getValue($_product);

// Get Label$attrTestLabel = $_getMyAttr->getStoreLabel();


Also check following property:

  • if you do want to see an attribute, go in the Magento backend and verify the attribute is setup to be Used In Product Listing

  • then, you may have to refresh the index/cache and your code will show the attribute you will have verified.

Re: Custom Product Attribute - Display based on attrubite?

Thank You rafaelmattb8e6

I may be confusing things.

I can get the attribute values on the product page but each product may be using a different attribute set.

So product A may be using attribute set 'key_features_air', product B may be using 'key_features_tools', etc.

So really, it's like a foreach within a foreach. The outer ones finds out which attribute set is being used and the inner one finds out the attribute values.

All attribute values display on the product page in the same place.

Thank you

Andy

Re: Custom Product Attribute - Display based on attrubite?

Still no joy with this one :-(

Does anyone know how to get the values from a custom product attribute based on the attribute set for that product?

Andy