How to sort Product by it's parent category positionI can't translate position, name and price on sort by listSort product collection after loadHow to add custom category product position base on country and sort in Magento 1.9.x?How to sort a category by its subcategoriesSort products by date DESC as the base sort order on category page?Magento 1.9.2 Sort attribute by positionHow do i remove remove SORT BY Price, Position, Name in Magento 2.1?Change category product sort order valuesHow to change Product Listing Sort by custom select option?Sort Magento Topmenu (category name)

Are there any vegetarian astronauts?

Plotting with different color for a single curve

What are the benefits of using the X Card safety tool in comparison to plain communication?

What is the legal status of travelling with (unprescribed) methadone in your carry-on?

Why doesn't a marching band have strings?

What do you call a weak person's act of taking on bigger opponents?

Through the Looking-Glass

5 cars in a roundabout traffic

Alphabet completion rate

Why is the G major to Bb major resolution so strong?

Does Marvel have an equivalent of the Green Lantern?

Employer wants to use my work email account after I quit, is this legal under German law? Is this a GDPR waiver?

Story-based adventure with functions and relationships

In the Marvel universe, can a human have a baby with any non-human?

Why is the Turkish president's surname spelt in Russian as Эрдоган, with г?

What happens when your group is victim of a surprise attack but you can't be surprised?

What would earth look like at night in medieval times?

What is the fibered coproduct of abelian groups?

Is my Rep in Stack-Exchange Form?

Sho, greek letter

How to perform Login Authentication at the client-side?

Using “sparkling” as a diminutive of “spark” in a poem

What is the line crossing the Pacific Ocean that is shown on maps?

Fedora boot screen shows both Fedora logo and Lenovo logo. Why and How?



How to sort Product by it's parent category position


I can't translate position, name and price on sort by listSort product collection after loadHow to add custom category product position base on country and sort in Magento 1.9.x?How to sort a category by its subcategoriesSort products by date DESC as the base sort order on category page?Magento 1.9.2 Sort attribute by positionHow do i remove remove SORT BY Price, Position, Name in Magento 2.1?Change category product sort order valuesHow to change Product Listing Sort by custom select option?Sort Magento Topmenu (category name)






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















$sale_products = Mage::getModel('catalog/product')->getCollection();
$sale_products->addAttributeToSelect(array(
'image',
'name',
'short_description',
))
->addFieldToFilter('visibility', array(
Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH,
Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_CATALOG
))
->addFieldToFilter('feature', array('eq' => 1))
->addAttributeToSort('position', 'ASC')
->addFinalPrice()
->getSelect()
->where('price_index.final_price < price_index.price')


Right now I only know how to sort by position. and I believe the position is sorted by the date item become sale.



If I sort by ->addAttributeToSort('category_id', 'ASC') I am not sure if it have any effect. b/c product have many category ids. and I can't find a pattern that match.



How to sort Product by it's parent category position?










share|improve this question
























  • Did you try something like this: Mage::getResourceModel('catalog/product_collection')->addCategoryFilter($category)->addAttributeToSort('position','asc'); ?

    – Raphael at Digital Pianism
    Jan 18 '16 at 15:38











  • No, but I think what you did was filter out the category. so it's is only displaying items in that category. what I want is item in all category but sorted in the position the category position as listed in admin

    – wlin
    Jan 18 '16 at 15:51











  • There's one big problem with what you want to achieve. It's the fact that the same product can belong to several categories with a different position. The position itself is stored under the catalog_category_product table if you want to check the structure is very simple but in your case, it makes the solution a little bit complex.

    – Raphael at Digital Pianism
    Jan 18 '16 at 15:56











  • @DigitalPianism I just want to filter it at a level2 ( one directly under root, which each product only have one cat assigned to ). is there a way to do that? with out loop through 2 foreach

    – wlin
    Jan 18 '16 at 15:59

















1















$sale_products = Mage::getModel('catalog/product')->getCollection();
$sale_products->addAttributeToSelect(array(
'image',
'name',
'short_description',
))
->addFieldToFilter('visibility', array(
Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH,
Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_CATALOG
))
->addFieldToFilter('feature', array('eq' => 1))
->addAttributeToSort('position', 'ASC')
->addFinalPrice()
->getSelect()
->where('price_index.final_price < price_index.price')


Right now I only know how to sort by position. and I believe the position is sorted by the date item become sale.



If I sort by ->addAttributeToSort('category_id', 'ASC') I am not sure if it have any effect. b/c product have many category ids. and I can't find a pattern that match.



How to sort Product by it's parent category position?










share|improve this question
























  • Did you try something like this: Mage::getResourceModel('catalog/product_collection')->addCategoryFilter($category)->addAttributeToSort('position','asc'); ?

    – Raphael at Digital Pianism
    Jan 18 '16 at 15:38











  • No, but I think what you did was filter out the category. so it's is only displaying items in that category. what I want is item in all category but sorted in the position the category position as listed in admin

    – wlin
    Jan 18 '16 at 15:51











  • There's one big problem with what you want to achieve. It's the fact that the same product can belong to several categories with a different position. The position itself is stored under the catalog_category_product table if you want to check the structure is very simple but in your case, it makes the solution a little bit complex.

    – Raphael at Digital Pianism
    Jan 18 '16 at 15:56











  • @DigitalPianism I just want to filter it at a level2 ( one directly under root, which each product only have one cat assigned to ). is there a way to do that? with out loop through 2 foreach

    – wlin
    Jan 18 '16 at 15:59













1












1








1








$sale_products = Mage::getModel('catalog/product')->getCollection();
$sale_products->addAttributeToSelect(array(
'image',
'name',
'short_description',
))
->addFieldToFilter('visibility', array(
Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH,
Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_CATALOG
))
->addFieldToFilter('feature', array('eq' => 1))
->addAttributeToSort('position', 'ASC')
->addFinalPrice()
->getSelect()
->where('price_index.final_price < price_index.price')


Right now I only know how to sort by position. and I believe the position is sorted by the date item become sale.



If I sort by ->addAttributeToSort('category_id', 'ASC') I am not sure if it have any effect. b/c product have many category ids. and I can't find a pattern that match.



How to sort Product by it's parent category position?










share|improve this question
















$sale_products = Mage::getModel('catalog/product')->getCollection();
$sale_products->addAttributeToSelect(array(
'image',
'name',
'short_description',
))
->addFieldToFilter('visibility', array(
Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH,
Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_CATALOG
))
->addFieldToFilter('feature', array('eq' => 1))
->addAttributeToSort('position', 'ASC')
->addFinalPrice()
->getSelect()
->where('price_index.final_price < price_index.price')


Right now I only know how to sort by position. and I believe the position is sorted by the date item become sale.



If I sort by ->addAttributeToSort('category_id', 'ASC') I am not sure if it have any effect. b/c product have many category ids. and I can't find a pattern that match.



How to sort Product by it's parent category position?







sort






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 18 '16 at 15:41







wlin

















asked Jan 18 '16 at 15:34









wlinwlin

2771 gold badge4 silver badges10 bronze badges




2771 gold badge4 silver badges10 bronze badges












  • Did you try something like this: Mage::getResourceModel('catalog/product_collection')->addCategoryFilter($category)->addAttributeToSort('position','asc'); ?

    – Raphael at Digital Pianism
    Jan 18 '16 at 15:38











  • No, but I think what you did was filter out the category. so it's is only displaying items in that category. what I want is item in all category but sorted in the position the category position as listed in admin

    – wlin
    Jan 18 '16 at 15:51











  • There's one big problem with what you want to achieve. It's the fact that the same product can belong to several categories with a different position. The position itself is stored under the catalog_category_product table if you want to check the structure is very simple but in your case, it makes the solution a little bit complex.

    – Raphael at Digital Pianism
    Jan 18 '16 at 15:56











  • @DigitalPianism I just want to filter it at a level2 ( one directly under root, which each product only have one cat assigned to ). is there a way to do that? with out loop through 2 foreach

    – wlin
    Jan 18 '16 at 15:59

















  • Did you try something like this: Mage::getResourceModel('catalog/product_collection')->addCategoryFilter($category)->addAttributeToSort('position','asc'); ?

    – Raphael at Digital Pianism
    Jan 18 '16 at 15:38











  • No, but I think what you did was filter out the category. so it's is only displaying items in that category. what I want is item in all category but sorted in the position the category position as listed in admin

    – wlin
    Jan 18 '16 at 15:51











  • There's one big problem with what you want to achieve. It's the fact that the same product can belong to several categories with a different position. The position itself is stored under the catalog_category_product table if you want to check the structure is very simple but in your case, it makes the solution a little bit complex.

    – Raphael at Digital Pianism
    Jan 18 '16 at 15:56











  • @DigitalPianism I just want to filter it at a level2 ( one directly under root, which each product only have one cat assigned to ). is there a way to do that? with out loop through 2 foreach

    – wlin
    Jan 18 '16 at 15:59
















Did you try something like this: Mage::getResourceModel('catalog/product_collection')->addCategoryFilter($category)->addAttributeToSort('position','asc'); ?

– Raphael at Digital Pianism
Jan 18 '16 at 15:38





Did you try something like this: Mage::getResourceModel('catalog/product_collection')->addCategoryFilter($category)->addAttributeToSort('position','asc'); ?

– Raphael at Digital Pianism
Jan 18 '16 at 15:38













No, but I think what you did was filter out the category. so it's is only displaying items in that category. what I want is item in all category but sorted in the position the category position as listed in admin

– wlin
Jan 18 '16 at 15:51





No, but I think what you did was filter out the category. so it's is only displaying items in that category. what I want is item in all category but sorted in the position the category position as listed in admin

– wlin
Jan 18 '16 at 15:51













There's one big problem with what you want to achieve. It's the fact that the same product can belong to several categories with a different position. The position itself is stored under the catalog_category_product table if you want to check the structure is very simple but in your case, it makes the solution a little bit complex.

– Raphael at Digital Pianism
Jan 18 '16 at 15:56





There's one big problem with what you want to achieve. It's the fact that the same product can belong to several categories with a different position. The position itself is stored under the catalog_category_product table if you want to check the structure is very simple but in your case, it makes the solution a little bit complex.

– Raphael at Digital Pianism
Jan 18 '16 at 15:56













@DigitalPianism I just want to filter it at a level2 ( one directly under root, which each product only have one cat assigned to ). is there a way to do that? with out loop through 2 foreach

– wlin
Jan 18 '16 at 15:59





@DigitalPianism I just want to filter it at a level2 ( one directly under root, which each product only have one cat assigned to ). is there a way to do that? with out loop through 2 foreach

– wlin
Jan 18 '16 at 15:59










1 Answer
1






active

oldest

votes


















0














Assuming your products are only assigned to one category, I reckon you could do something like this, you may have to make modifications to get it working with your current code, but that gives you a good idea on how to do it:



$sale_products = Mage::getModel('catalog/product')->getCollection()
$sale_products->getSelect()->joinLeft(
'ccp'=>'catalog_category_product',
'main_table.category_id = ccp.category_id and main_table.entity_id = ccp.product_id',
array('ccp.position'));
$sale_products->getSelect()->order('ccp.position asc');





share|improve this answer

























    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%2f97851%2fhow-to-sort-product-by-its-parent-category-position%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Assuming your products are only assigned to one category, I reckon you could do something like this, you may have to make modifications to get it working with your current code, but that gives you a good idea on how to do it:



    $sale_products = Mage::getModel('catalog/product')->getCollection()
    $sale_products->getSelect()->joinLeft(
    'ccp'=>'catalog_category_product',
    'main_table.category_id = ccp.category_id and main_table.entity_id = ccp.product_id',
    array('ccp.position'));
    $sale_products->getSelect()->order('ccp.position asc');





    share|improve this answer



























      0














      Assuming your products are only assigned to one category, I reckon you could do something like this, you may have to make modifications to get it working with your current code, but that gives you a good idea on how to do it:



      $sale_products = Mage::getModel('catalog/product')->getCollection()
      $sale_products->getSelect()->joinLeft(
      'ccp'=>'catalog_category_product',
      'main_table.category_id = ccp.category_id and main_table.entity_id = ccp.product_id',
      array('ccp.position'));
      $sale_products->getSelect()->order('ccp.position asc');





      share|improve this answer

























        0












        0








        0







        Assuming your products are only assigned to one category, I reckon you could do something like this, you may have to make modifications to get it working with your current code, but that gives you a good idea on how to do it:



        $sale_products = Mage::getModel('catalog/product')->getCollection()
        $sale_products->getSelect()->joinLeft(
        'ccp'=>'catalog_category_product',
        'main_table.category_id = ccp.category_id and main_table.entity_id = ccp.product_id',
        array('ccp.position'));
        $sale_products->getSelect()->order('ccp.position asc');





        share|improve this answer













        Assuming your products are only assigned to one category, I reckon you could do something like this, you may have to make modifications to get it working with your current code, but that gives you a good idea on how to do it:



        $sale_products = Mage::getModel('catalog/product')->getCollection()
        $sale_products->getSelect()->joinLeft(
        'ccp'=>'catalog_category_product',
        'main_table.category_id = ccp.category_id and main_table.entity_id = ccp.product_id',
        array('ccp.position'));
        $sale_products->getSelect()->order('ccp.position asc');






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 18 '16 at 16:08









        Raphael at Digital PianismRaphael at Digital Pianism

        55.5k22 gold badges131 silver badges294 bronze badges




        55.5k22 gold badges131 silver badges294 bronze badges



























            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%2f97851%2fhow-to-sort-product-by-its-parent-category-position%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

            Get product attribute by attribute group code in magento 2get product attribute by product attribute group in magento 2Magento 2 Log Bundle Product Data in List Page?How to get all product attribute of a attribute group of Default attribute set?Magento 2.1 Create a filter in the product grid by new attributeMagento 2 : Get Product Attribute values By GroupMagento 2 How to get all existing values for one attributeMagento 2 get custom attribute of a single product inside a pluginMagento 2.3 How to get all the Multi Source Inventory (MSI) locations collection in custom module?Magento2: how to develop rest API to get new productsGet product attribute by attribute group code ( [attribute_group_code] ) in magento 2

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

            Magento 2.3: How do i solve this, Not registered handle, on custom form?How can i rewrite TierPrice Block in Magento2magento 2 captcha not rendering if I override layout xmlmain.CRITICAL: Plugin class doesn't existMagento 2 : Problem while adding custom button order view page?Magento 2.2.5: Overriding Admin Controller sales/orderMagento 2.2.5: Add, Update and Delete existing products Custom OptionsMagento 2.3 : File Upload issue in UI Component FormMagento2 Not registered handleHow to configured Form Builder Js in my custom magento 2.3.0 module?Magento 2.3. How to create image upload field in an admin form