Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9238733
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:49:50+00:00 2026-06-18T07:49:50+00:00

i have a custom product attribute with actually three possible values Frühjahr/Sommer, Herbst/Winter, (empty).

  • 0

i have a custom product attribute with actually three possible values
“Frühjahr/Sommer”, “Herbst/Winter”, “” (empty).

I want to sort the product collection by this value in a predefined order
e.g. “Frühjahr/Sommer”, “Herbst/Winter”, “” OR
“Herbst/Winter”, “Frühjahr/Sommer”, “”

This is alternating.
The empty values should be allways at the end but maybe there are more values to come so it must be a fixed predefined order.

I need to execute the following MySQL
ORDER BY FIELD (saison, “Frühjahr/Sommer”, “Herbst/Winter”, “”)

The problem is i have no clue how to execute this command in Magento.
I know the “->setOrder”-Method but i need to commit a fixed order instead of using DESC or ASC.

I search a lot on stackoverflow and google but no answer so far.

I hope you can help me

Thanks

[edit in responds to the answer of magalter]

unfortunately it doesn’t work i tried it before:

$this->_collection->getSelect()->order(new Zend_Db_Expr("FIELD(season, 'Frühjahr/Sommer','Herbst/Winter','')"));

The result is “There has been an error processing your request.

$this->_collection->getSelect();

return:

SELECT `e`.*, `cat_index`.`position` AS `cat_index_position`, `price_index`.`price`, `price_index`.`tax_class_id`, `price_index`.`final_price`, IF(price_index.tier_price IS NOT NULL, LEAST(price_index.min_price, price_index.tier_price), price_index.min_price) AS `minimal_price`, `price_index`.`min_price`, `price_index`.`max_price`, `price_index`.`tier_price` FROM `catalog_product_entity` AS `e` INNER JOIN `catalog_category_product_index` AS `cat_index` ON cat_index.product_id=e.entity_id AND cat_index.store_id=1 AND cat_index.visibility IN(2, 4) AND cat_index.category_id='124' INNER JOIN `catalog_product_index_price` AS `price_index` ON price_index.entity_id = e.entity_id AND price_index.website_id = '1' AND price_index.customer_group_id = 0 ORDER BY FIELD(season, 'Frühjahr/Sommer','Herbst/Winter','')

I executed this sql-statement in phpMyAdmin and get the following error message “Unknown column ‘season’ in ‘order clause'”

If I order by “season” DESC

$this->_collection->setOrder('season', 'DESC');

it works … and generate the following sql-statement

SELECT `e`.*, `cat_index`.`position` AS `cat_index_position`, `price_index`.`price`, `price_index`.`tax_class_id`, `price_index`.`final_price`, IF(price_index.tier_price IS NOT NULL, LEAST(price_index.min_price, price_index.tier_price), price_index.min_price) AS `minimal_price`, `price_index`.`min_price`, `price_index`.`max_price`, `price_index`.`tier_price`, IF(season_option_value_t2.value_id IS NULL, season_option_value_t1.value, season_option_value_t2.value) AS `season` FROM `catalog_product_entity` AS `e` INNER JOIN `catalog_category_product_index` AS `cat_index` ON cat_index.product_id=e.entity_id AND cat_index.store_id=1 AND cat_index.visibility IN(2, 4) AND cat_index.category_id='124' INNER JOIN `catalog_product_index_price` AS `price_index` ON price_index.entity_id = e.entity_id AND price_index.website_id = '1' AND price_index.customer_group_id = 0 LEFT JOIN `catalog_product_entity_int` AS `season_t1` ON e.entity_id=season_t1.entity_id AND season_t1.attribute_id='180' AND season_t1.store_id=0 LEFT JOIN `catalog_product_entity_int` AS `season_t2` ON e.entity_id=season_t2.entity_id AND season_t2.attribute_id='180' AND season_t2.store_id='1' LEFT JOIN `eav_attribute_option_value` AS `season_option_value_t1` ON season_option_value_t1.option_id=IF(season_t2.value_id > 0, season_t2.value, season_t1.value) AND season_option_value_t1.store_id=0 LEFT JOIN `eav_attribute_option_value` AS `season_option_value_t2` ON season_option_value_t2.option_id=IF(season_t2.value_id > 0, season_t2.value, season_t1.value) AND season_option_value_t2.store_id=1 ORDER BY `season` DESC

But this is order by DESC not by a predefined order like i want it so i can’t use it.

What i need is the SQL Statement above with

ORDER BY FIELD(season, 'Frühjahr/Sommer','Herbst/Winter','')

instead

ORDER BY `season` DESC

Another idea ???

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T07:49:50+00:00Added an answer on June 18, 2026 at 7:49 am

    Finaly I have found a solution.
    Maybe another user needs it so here it is:

    (Probably not the best solution, but it works)

    I created a new Modul and extends Mage_Catalog_Block_Product_List_Toolbar.
    Then i override the “setCollection”-Method like this

    public function setCollection($collection)
    {
        $this->_collection = $collection;
    
        $this->_collection->setCurPage($this->getCurrentPage());
    
        // we need to set pagination only if passed value integer and more that 0
        $limit = (int)$this->getLimit();
        if ($limit) {
            $this->_collection->setPageSize($limit);
        }
        if ($this->getCurrentOrder()) {
            $mySource = $this->_collection->getEntity()->getAttribute('season');
    
            $mySource = $this->_collection->getEntity()->getAttribute('season')->getSource(); //Mage_Eav_Model_Entity_Attribute_Source_Table
            $collection = $this->_collection;
            $valueTable1    = 'season_t1';
            $valueTable2    = 'season_t2';
    
            $collection->getSelect()
                ->joinLeft(
                    array($valueTable1 => $mySource->getAttribute()->getBackend()->getTable()),
                    "e.entity_id={$valueTable1}.entity_id"
                    . " AND {$valueTable1}.attribute_id='{$mySource->getAttribute()->getId()}'"
                    . " AND {$valueTable1}.store_id=0",
                    array()
                )
                ->joinLeft(
                    array($valueTable2 => $mySource->getAttribute()->getBackend()->getTable()),
                    "e.entity_id={$valueTable2}.entity_id"
                    . " AND {$valueTable2}.attribute_id='{$mySource->getAttribute()->getId()}'"
                    . " AND {$valueTable2}.store_id='{$collection->getStoreId()}'",
                    array()
                );
            $valueExpr = $collection->getSelect()->getAdapter()
            ->getCheckSql("{$valueTable2}.value_id > 0", "{$valueTable2}.value", "{$valueTable1}.value");
    
            Mage::getResourceModel('eav/entity_attribute_option')
                ->addOptionValueToCollection($collection, $mySource->getAttribute(), $valueExpr);
    
            $sortBySeason = "FIELD(IF(season_option_value_t2.value_id IS NULL, season_option_value_t1.value, season_option_value_t2.value), ";
    
    
            $getSelectedSeason = Mage::getStoreConfig('sortproductsbyseason_options/general/current_season');
    
            if($getSelectedSeason == "herbst_winter"){
                $sortBySeason .= "'Frühjahr/Sommer', 'Herbst/Winter' ,''";
            }else{
                $sortBySeason .= "'Herbst/Winter', 'Frühjahr/Sommer' ,''";
            }
            $sortBySeason .= ") DESC";
    
            $this->_collection->getSelect()->order(new Zend_Db_Expr($sortBySeason));
    
            $this->_collection->setOrder($this->getCurrentOrder(), $this->getCurrentDirection());
        }
    
        return $this;
    }   
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have added custom fields in products table in magento. I want to sort
I have a custom attribute yes/no and what i want to do is on
What's the difference between a product attribute and Custom Options? For example, I have
I want to make a custom collection query to load the products that have
In our system we have an entity Product , which might have various custom
I'm using nant to build our product and have written a custom task to
I have custom classes that I currently instantiate within App.xaml as resources. I want
Story: I have a list of products. I want to be able to sort
Summary I want to create a product attribute that is not saved to products,
We have a custom attribute that our previous developer (recently disappeared) has created in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.