I'm trying to add a new attribute set and I have this data:

$data = [
   'attribute_set_name' => 'Sample attribute set',
   'entity_type_id' => $entityTypeId,
   'sort_order' => 200,
];

Could someone explain what the sort_order means here? I just started to learn Magento 2, so it's a little confusing.

up vote 2 down vote accepted

Basically this sort_order is a field where you put a number in order to sort the object or xml fields.

You can define ascendent or descendent but most of the places I've seen are ascendent.

EDITED:

These are 4 fields that we created with the layout. Have a look at the code and see one of the parameters is sort_order.

enter image description here

 <group id="customer">

            <field id="permission_info" translate="label" type="select" sortOrder="100"
                   showInDefault="1" showInWebsite="1" showInStore="1">
                <label>Allow edit customer data</label>
                <source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
            </field>

            <field id="permission_freetext" translate="label" type="select" sortOrder="110"
                   showInDefault="1" showInWebsite="1" showInStore="1">
                <label>Show free text field</label>
                <source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
            </field>

            <field id="permission_payment" translate="label" type="select" sortOrder="120"
                   showInDefault="1" showInWebsite="1" showInStore="1">
                <label>Allow edit condition and payment method</label>
                <source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
            </field>

            <field id="permission_bank" translate="label" type="select" sortOrder="130"
                   showInDefault="1" showInWebsite="1" showInStore="1">
                <label>Allow edit bank data and payment days</label>
                <source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
            </field>              

        </group>

If I change the values of the field with the id="permission_bank" and I put in the sort_order parameter a value between 101 and 109, this field will go between Allow edit customer data and Show free text field:

enter image description here

It's just a tool to sort.

  • I still didn't quite get it... – HELPME Aug 10 at 8:16
  • Have a look again, I edited a bit. :D – Raül Vila Aug 10 at 8:43

sort_order is added to tell the system where you want to display the field in the form.
Higher the sort_order lower it will be displayed in the form.

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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