Question

I have a question regarding a custom category attribute that was added via a module/extension in a Magento 1.9.4.1 webshop and now is migrated correctly to the Magento 2 webshop (2.3.4). I checked the database manually with phpmyadmin to see if the attribute was migrated correctly, since it's not showing up in the backend. I found the attribute with ID 180 and saw that the values were migrated correctly.

I went ahead and changed the frontend template to show these values correctly. That worked out pretty well. It now shows the values correctly on the frontend. FYI this attribute holds some text (a description) regarding the category.

Next thing i wanted to do is, show this attribute in the backend at the category edit page. I'm wondering how this could be achieved. I already told you that in the M1 1.9.4.1 shop, this attribute was added via a custom extension, that uses the mysql installer to install the custom attribute in the database. Since the data is already migrated and in the M2 database, i was wondering: Do i need to create a new custom extension for M2 with the same mysql installer settings for this category attribute?

My worry is that if i do it this way, it will create another category attribute and that i need to transfer the data over to this new attribute. Will the mysql installer see that there already is a category attribute with the name: 'custom_attribute' and ignore the creation of a new attribute and instead just shows the attribute in the backend?

I hope someone can help me with this, since i don't want to ruin a perfect migrated webshop. Thanks in advance :)

Was it helpful?

Solution

I managed to fix my own problem. While posting a question here, i went ahead and further checked what i could do to fix this. I found an article about category attributes:

https://devdocs.magento.com/guides/v2.3/ui_comp_guide/howto/add_category_attribute.html

That explained to me that if there already is an attribute present, i don't need to create an install script. So i went and created a new extension and added the following XML file in Pagelab/Categoryattribute/view/adminhtml/ui_component/category_form.xml:

<?xml version="1.0"?><form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
<fieldset name="search_engine_optimization">
    <field name="custom_attribute">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="dataType" xsi:type="string">varchar</item>
                <item name="formElement" xsi:type="string">textarea</item>
                <item name="label" xsi:type="string" translate="true">SEO tekst</item>
            </item>
        </argument>
    </field>
</fieldset>

This creates an SEO textfield in the SEO section of the category page in the admin. Because i named the field name 'custom_attribute' it gets the right information from the already existing attribute in the database.

This solved the issue for me. Remember that if you want create a custom category attribute but you don't have the attribute setup in the database yet, you will need to create an install script for that too. You can find the information on how you do that in the URL i posted above.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top