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;
$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
add a comment |
$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
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 2foreach
– wlin
Jan 18 '16 at 15:59
add a comment |
$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
$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
sort
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 2foreach
– wlin
Jan 18 '16 at 15:59
add a comment |
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 2foreach
– 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
add a comment |
1 Answer
1
active
oldest
votes
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');
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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');
add a comment |
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');
add a comment |
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');
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');
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
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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