InsideDarkWeb.com

Magento 2: what is the catalog_attributes.xml file?

I noticed that Magento 2 contains several catalog_attributes.xml files in the following folders:

  • app/code/Magento/Bundle/etc
  • app/code/Magento/Catalog/etc
  • app/code/Magento/CatalogSearch/etc
  • app/code/Magento/CatalogUrlRewrite/etc
  • app/code/Magento/Downloadable/etc
  • app/code/Magento/GiftMessage/etc
  • app/code/Magento/Msrp/etc
  • app/code/Magento/Sales/etc
  • app/code/Magento/Tax/etc
  • app/code/Magento/Wishlist/etc

Those files look like this (example for the Sales file):

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Catalog:etc/catalog_attributes.xsd">
    <group name="quote_item">
        <attribute name="sku"/>
        <attribute name="type_id"/>
        <attribute name="name"/>
        <attribute name="status"/>
        <attribute name="visibility"/>
        <attribute name="price"/>
        <attribute name="weight"/>
        <attribute name="url_path"/>
        <attribute name="url_key"/>
        <attribute name="thumbnail"/>
        <attribute name="small_image"/>
        <attribute name="tax_class_id"/>
        <attribute name="special_from_date"/>
        <attribute name="special_to_date"/>
        <attribute name="special_price"/>
        <attribute name="cost"/>
        <attribute name="gift_message_available"/>
    </group>
</config>

What are those files used for ?

Magento Asked by Raphael at Digital Pianism on September 7, 2020

2 Answers

2 Answers

In general, these files contain a list of attributes that serve different purposes.

The group used_in_autogeneration from the file in catalog module serves for listing attributes that have the value autogenerated.
They are retrieved in MagentoCatalogHelperProduct::getAttributesAllowedForAutogeneration

The group quote_item represents the attributes that are going to be copied from the product to the quote item.

unassignable contains the list of attributes that cannot be unassigned from any attribute set.

Sorry, but I don't know all the available groups.

But you are not limited only to the existing groups. You can add your own and use them as you please just by calling MagentoCatalogModelAttributeConfig::getAttributeNames('group_name_here'). (but instantiate the class first).

[EDIT]
I'm not sure about this one, but I think catalog_category and catalog_product groups hold the system attributes for products and categories.

Correct answer by Marius on September 7, 2020

Just yesterday I stumbled upon that for the first time. It's used for example to add custom attributes to quote item products, otherwise they won't be loaded to save resources (in my case I wanted to display the color attribute on the cart page). In Magento 1 you would enter something like this to your module config.xml:

<config>
    <global>
        <sales>
            <quote>
                <item>
                    <product_attributes>
                        <color />
                    </product_attributes>
                </item>
            </quote>
        </sales>
    </global>
</config>

To achieve the same in M2, you have to add a catalog_attributes.xml to your module and do the following:

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Catalog:etc/catalog_attributes.xsd">
    <group name="quote_item">
        <attribute name="color" />
    </group>
</config>

Answered by fmrng on September 7, 2020

Add your own answers!

Related Questions

Magento 2 Access-Control-Allow-Origin

2  Asked on September 9, 2020 by borche-glafche

   

Magento 2: what is the catalog_attributes.xml file?

2  Asked on September 7, 2020 by raphael-at-digital-pianism

       

magento 2 – modify db_schema.xml field length

1  Asked on September 4, 2020 by sairaj-gadekar

 

Magento 2.3.2 Upgrade to 2.4

2  Asked on September 4, 2020 by hatim

 

Magento 2: Make sales without stock

1  Asked on August 9, 2020 by hudson-alves-triunfante

     

Magento 2 : print_r or var_dump is not working

4  Asked on July 30, 2020 by zed-blackbeard

   

Create quick order form at product page

0  Asked on July 29, 2020 by faraz-bashir

   

How to Special price based on attribute?

2  Asked on July 26, 2020 by user90560

     

is creating block within template in magento 2 good practice

0  Asked on July 24, 2020 by herve-tribouilloy

       

Ask a Question

Get help from others!

© 2021 InsideDarkWeb.com. All rights reserved.