Magento – Magento API – Category Create – Default Product Listing Sort by does not exist

apimagento-1.9PHPsoap

Fatal error: Uncaught SoapFault exception: [1] Default Product Listing
Sort by does not exist in Available Product Listing Sort By.

I cannot figure out why Magento keeps giving me this error? Using the default sort by position.

    $result = $client->catalogCategoryCreate($session, 2, array(
    'name' => $cat_name,
    'is_active' => 1,
    'available_sort_by' => array('position'),
    'custom_design' => null,
    'custom_apply_to_products' => null,
    'custom_design_from' => null,
    'custom_design_to' => null,
    'custom_layout_update' => null,
    'default_sort_by' => 'position',
    'description' => $cat_name,
    'display_mode' => null,
    'is_anchor' => 0,
    'landing_page' => null,
    'meta_description' => $cat_name,
    'meta_keywords' => $cat_name,
    'meta_title' => $cat_name,
    'page_layout' => 'two_columns_left',
    'url_key' => $cat_url,
    'include_in_menu' => 1,
));

// Print Result = New Category ID
// var_dump ($result);

return $result;

It was working perfectly fine until last Wednesday when the Schema server went down for couple of hours. Any idea how to by pass the error, or fix it?

UPDATED – Problem "Resolved"

I changed from v2 SOAP, to just plain SOAP. Had to modify the API call a bit. It appears there is a problem with v2 SOAP…

$result = $client->call($session, 'catalog_category.create', array(2, array(
    'name' => $cat_name,
    'is_active' => 1,
    'available_sort_by' => 'position',
    'custom_design' => null,
    'custom_apply_to_products' => null,
    'custom_design_from' => null,
    'custom_design_to' => null,
    'custom_layout_update' => null,
    'default_sort_by' => 'position',
    'description' => $cat_name,
    'display_mode' => null,
    'is_anchor' => 1,
    'landing_page' => null,
    'meta_description' => $cat_name,
    'meta_keywords' => $cat_name,
    'meta_title' => $cat_name,
    'page_layout' => 'two_columns_left',
    'url_key' => $cat_url,
    'include_in_menu' => 0,
)));

Best Answer

The error indicates that the value for the default_sort_by field is invalid, because you use a empty value. Depending on the field that you want to use for sorting you need to enter it here, for example you could use position:

for example:

$result = $client->call($session, 'catalog_category.update', array(181, array(
                'is_anchor' => 1,
                'include_in_menu' => 0,
                'available_sort_by' => "position",
                'default_sort_by' => "position",
            )));

The code above should work, other options that are there by default are 'name' and 'price'. If you want another attribute to use as sortable field, you can set the option 'Used for Sorting in Product Listing' to 'Yes' for the attribute thru that admin option Catalog => Attributes => Manage Attributes

or other solution is:

I changed the settings in all store views, but it didn't changed in all sotre views. When I tried to change the setting Use Default Value in my "languagesviews". I get the error "Default Product Listing Sort by not exists on Available Product Listing Sort By".

So I "just" need to change all categorysettings of each language.

EDIT:

After editing some categories and checking/unchecking "use default values" the error is gone and I set all "use default values" to yes.

so you need to check the checkbox default use in display settings.

I hope this will help you.

Related Topic