Stores > Attributes > Product > My Custom Attribute > Storefront Properties tab
I'm not able to change the Storefront Properties 'Used for Sorting in Product Listing', since it is disabled or grayed out.
What is the reason behind it ? How can I fix this ?
Updated
Script used below and version is Magento Commerce 2.4.0
$attributeData = [
'attribute_code' => $formattedCode,
'is_global' => 1,
'frontend_label' => $replAttribute->getDescription() ?: $replAttribute->getCode(),
'frontend_input' => $frontendInput,
'is_unique' => 0,
'apply_to' => 0,
'is_required' => 0,
'is_configurable' => 0,
'is_searchable' => 1,
'is_comparable' => 1,
'is_user_defined' => 1,
'is_visible_in_advanced_search' => 0,
'is_used_for_price_rules' => 0,
'is_wysiwyg_enabled' => 0,
'is_html_allowed_on_front' => 1,
'is_visible_on_front' => 1,
'used_in_product_listing' => 0,
'used_for_sort_by' => 1,
'backend_type' => 'varchar',
'backend_model' => ArrayBackend::class,
'is_filterable' => ($frontendInput === 'multiselect') ? 1 : 0,
'is_filterable_in_search' => ($frontendInput === 'multiselect') ? 1 : 0
];