Magento 2.1.10: Sort by Special Price doesn't workingExport from the database brand, quantity and size/color varchar: MySQL & EEConvert SQL Select to Magento SQL querySubselect as main_table on magento collectioni want to write custom sql query to select low and high price in magento2?Indexer query error empty valuesHow to sort by popularity in magento 2 product list?Best seller sort order pagination query string not working correctlyMagento 1.9 - Product collection sort by price not working fineMagento Product Listing Sort By not working on some categoryCategory page take too much time to load because of search_tmp_* table

Replacing 5 gang light switches that have 3 of them daisy chained together

What verb goes with "coup"?

Why are symbols not written in words?

Is it advisable to inform the CEO about his brother accessing his office?

How soon after takeoff can you recline your airplane seat?

*p++->str : Understanding evaluation of ->

How to idiomatically express the idea "if you can cheat without being caught, do it"

How far can gerrymandering go?

What is the point of using the kunai?

Is it OK to throw pebbles and stones in streams, waterfalls, ponds, etc.?

How do I tell my girlfriend she's been buying me books by the wrong author for the last nine months?

What is the meaning of "it" in "as luck would have it"?

Finding an optimal set without forbidden subsets

Find the closest three-digit hex colour

What is the meaning of ゴト in the context of 鮎

Why can't i use !(single pattern) in zsh even after i turn on kshglob?

Can I deep fry food in butter instead of vegetable oil?

What does this Pokemon Trainer mean by saying the player is "SHELLOS"?

Simplify the code

Existence of infinite set of positive integers s.t sum of reciprocals is rational and set of primes dividing an element is infinite

How come having a Deathly Hallow is not a big deal?

Displace Mesh along Curve on single axis

How to track mail undetectably?

Are the Gray and Death Slaad's Bite and Claw attacks magical?



Magento 2.1.10: Sort by Special Price doesn't working


Export from the database brand, quantity and size/color varchar: MySQL & EEConvert SQL Select to Magento SQL querySubselect as main_table on magento collectioni want to write custom sql query to select low and high price in magento2?Indexer query error empty valuesHow to sort by popularity in magento 2 product list?Best seller sort order pagination query string not working correctlyMagento 1.9 - Product collection sort by price not working fineMagento Product Listing Sort By not working on some categoryCategory page take too much time to load because of search_tmp_* table













2















I'm working on category page, and try to sort the products collection by Special Price.

I've override setCollection() of MagentoCatalogBlockProductProductListToolbar
enter image description here



And the result is the only sort for Normal price (not including Special Price):
enter image description here



So my solution is Left Join with catalog_product_entity_decimal table (this table is using for store Special Price, also store Normal Price as well, 149.0000 is normal price, and 120.0000 is special price).
enter image description hereenter image description here



And I print the query, and got this:



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`, `catalog_product_entity_decimal`.`value` AS `special_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='127'
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_decimal` ON e.entity_id = catalog_product_entity_decimal.entity_id WHERE (attribute_id = 78 or attribute_id = 77) AND (catalog_product_entity_decimal.store_id = 0) GROUP BY `entity_id` ORDER BY `special_price` desc, `price` desc


But with this, the GROUP BY affected before ORDER BY, and ruin my result.

Its remove the 120.0000 and only show the 149.0000 in query result



If I remove the GROUP BY, it will show both, but the Magento code will error with "Already exists Entity Id".



If there is any way to make GROUP BY go after ORDER BY? Or better way to solve the problems?
Thanks.










share|improve this question
























  • I think there is no need for coding. You can add sort by special price in frontend by simply changing Used for Sorting in Product Listing value to Yes in special_price attribute.

    – Mohit Kumar Arora
    Jun 24 at 11:10











  • @MohitKumarArora i've tried as you said, but its not working, i've clear cache as well.

    – fudu
    Jun 24 at 11:25















2















I'm working on category page, and try to sort the products collection by Special Price.

I've override setCollection() of MagentoCatalogBlockProductProductListToolbar
enter image description here



And the result is the only sort for Normal price (not including Special Price):
enter image description here



So my solution is Left Join with catalog_product_entity_decimal table (this table is using for store Special Price, also store Normal Price as well, 149.0000 is normal price, and 120.0000 is special price).
enter image description hereenter image description here



And I print the query, and got this:



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`, `catalog_product_entity_decimal`.`value` AS `special_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='127'
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_decimal` ON e.entity_id = catalog_product_entity_decimal.entity_id WHERE (attribute_id = 78 or attribute_id = 77) AND (catalog_product_entity_decimal.store_id = 0) GROUP BY `entity_id` ORDER BY `special_price` desc, `price` desc


But with this, the GROUP BY affected before ORDER BY, and ruin my result.

Its remove the 120.0000 and only show the 149.0000 in query result



If I remove the GROUP BY, it will show both, but the Magento code will error with "Already exists Entity Id".



If there is any way to make GROUP BY go after ORDER BY? Or better way to solve the problems?
Thanks.










share|improve this question
























  • I think there is no need for coding. You can add sort by special price in frontend by simply changing Used for Sorting in Product Listing value to Yes in special_price attribute.

    – Mohit Kumar Arora
    Jun 24 at 11:10











  • @MohitKumarArora i've tried as you said, but its not working, i've clear cache as well.

    – fudu
    Jun 24 at 11:25













2












2








2








I'm working on category page, and try to sort the products collection by Special Price.

I've override setCollection() of MagentoCatalogBlockProductProductListToolbar
enter image description here



And the result is the only sort for Normal price (not including Special Price):
enter image description here



So my solution is Left Join with catalog_product_entity_decimal table (this table is using for store Special Price, also store Normal Price as well, 149.0000 is normal price, and 120.0000 is special price).
enter image description hereenter image description here



And I print the query, and got this:



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`, `catalog_product_entity_decimal`.`value` AS `special_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='127'
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_decimal` ON e.entity_id = catalog_product_entity_decimal.entity_id WHERE (attribute_id = 78 or attribute_id = 77) AND (catalog_product_entity_decimal.store_id = 0) GROUP BY `entity_id` ORDER BY `special_price` desc, `price` desc


But with this, the GROUP BY affected before ORDER BY, and ruin my result.

Its remove the 120.0000 and only show the 149.0000 in query result



If I remove the GROUP BY, it will show both, but the Magento code will error with "Already exists Entity Id".



If there is any way to make GROUP BY go after ORDER BY? Or better way to solve the problems?
Thanks.










share|improve this question
















I'm working on category page, and try to sort the products collection by Special Price.

I've override setCollection() of MagentoCatalogBlockProductProductListToolbar
enter image description here



And the result is the only sort for Normal price (not including Special Price):
enter image description here



So my solution is Left Join with catalog_product_entity_decimal table (this table is using for store Special Price, also store Normal Price as well, 149.0000 is normal price, and 120.0000 is special price).
enter image description hereenter image description here



And I print the query, and got this:



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`, `catalog_product_entity_decimal`.`value` AS `special_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='127'
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_decimal` ON e.entity_id = catalog_product_entity_decimal.entity_id WHERE (attribute_id = 78 or attribute_id = 77) AND (catalog_product_entity_decimal.store_id = 0) GROUP BY `entity_id` ORDER BY `special_price` desc, `price` desc


But with this, the GROUP BY affected before ORDER BY, and ruin my result.

Its remove the 120.0000 and only show the 149.0000 in query result



If I remove the GROUP BY, it will show both, but the Magento code will error with "Already exists Entity Id".



If there is any way to make GROUP BY go after ORDER BY? Or better way to solve the problems?
Thanks.







magento-2.1 query product-sorting






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jun 24 at 11:26









Raj Mohan R

1,1933 silver badges11 bronze badges




1,1933 silver badges11 bronze badges










asked Jun 24 at 11:03









fudufudu

47814 bronze badges




47814 bronze badges












  • I think there is no need for coding. You can add sort by special price in frontend by simply changing Used for Sorting in Product Listing value to Yes in special_price attribute.

    – Mohit Kumar Arora
    Jun 24 at 11:10











  • @MohitKumarArora i've tried as you said, but its not working, i've clear cache as well.

    – fudu
    Jun 24 at 11:25

















  • I think there is no need for coding. You can add sort by special price in frontend by simply changing Used for Sorting in Product Listing value to Yes in special_price attribute.

    – Mohit Kumar Arora
    Jun 24 at 11:10











  • @MohitKumarArora i've tried as you said, but its not working, i've clear cache as well.

    – fudu
    Jun 24 at 11:25
















I think there is no need for coding. You can add sort by special price in frontend by simply changing Used for Sorting in Product Listing value to Yes in special_price attribute.

– Mohit Kumar Arora
Jun 24 at 11:10





I think there is no need for coding. You can add sort by special price in frontend by simply changing Used for Sorting in Product Listing value to Yes in special_price attribute.

– Mohit Kumar Arora
Jun 24 at 11:10













@MohitKumarArora i've tried as you said, but its not working, i've clear cache as well.

– fudu
Jun 24 at 11:25





@MohitKumarArora i've tried as you said, but its not working, i've clear cache as well.

– fudu
Jun 24 at 11:25










0






active

oldest

votes














Your Answer








StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "479"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f279396%2fmagento-2-1-10-sort-by-special-price-doesnt-working%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Magento Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f279396%2fmagento-2-1-10-sort-by-special-price-doesnt-working%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

Circuit construction for execution of conditional statements using least significant bitHow are two different registers being used as “control”?How exactly is the stated composite state of the two registers being produced using the $R_zz$ controlled rotations?Efficiently performing controlled rotations in HHLWould this quantum algorithm implementation work?How to prepare a superposed states of odd integers from $1$ to $sqrtN$?Why is this implementation of the order finding algorithm not working?Circuit construction for Hamiltonian simulationHow can I invert the least significant bit of a certain term of a superposed state?Implementing an oracleImplementing a controlled sum operation

Magento 2 “No Payment Methods” in Admin New OrderHow to integrate Paypal Express Checkout with the Magento APIMagento 1.5 - Sales > Order > edit order and shipping methods disappearAuto Invoice Check/Money Order Payment methodAdd more simple payment methods?Shipping methods not showingWhat should I do to change payment methods if changing the configuration has no effects?1.9 - No Payment Methods showing upMy Payment Methods not Showing for downloadable/virtual product when checkout?Magento2 API to access internal payment methodHow to call an existing payment methods in the registration form?