EAV collections work with attributes, the sorting method is a little different here as well
For non-EAV collections use one of the following methods
You cannot change the default order direction for product lists from configuration.
You can however change the direction from layout XML.
Here are a few examples that you can put in your layout XML file, e.g. local.xml:
<!-- Change default direction for simple searches -->
Note: It has been brought to my attention that this solution does not work for Magento 1.9.2. In order to save others wasted time I'd like to point this out at the top of this post. If I develop my own solution or find someone else's solution that works for 1.9.2 I will update this post at that time.
Notice: The solution laid out here extends a block class ...
If you want to use an attribute like created_at that it isn't in admin->stores->(attribute) product, because attributes defined in admin have the setting Sorting in Product Listing = Yes/No, you have to work with these two files:
We can achieve it by using Plugins.
Please create following files in your module.
<plugin name="Package_CustomToolbar::addCustomOptions" type="Package\CustomToolbar\Plugin\Model\Config" />
You can add this code in the __construct method of your grid block after calling parent::__construct();:
For frontend you can use this:
$collection = Mage::getResourceModel('banners/manage_collection');
Sadly Magento will validate the order options in Varien_Data_Collection_Db _setOrder function. But you can get the select of the collection and add a new expression to build the order as you like.
/* @var $collection Mage_Catalog_Model_Resource_Product_Collection */
$collection = Mage::getModel('catalog/product')
I found the answer after some intense searching on Stack Overflow all i had to do was add these lines to my layout.xml
You can add sort order like this:
More information: http://www.magentocommerce.com/wiki/1_-_installation_and_configuration/using_collections_in_magento
Hope can help you.
Just to add my two cents, the other two answers did well to point me in fix's direction, but I thought I'd attack it at the source rather than the block presentation point.
You can achieve the same result by extending the Mage_Catalog_Model_Resource_Product_Type_Configurable_Attribute_Collection model's _loadPrices() method, which despite the name is where ...
We'll need to fix this in 2 parts. The first part is actually tracking which simple products in the cart come from grouped products. The second is the sorting.
First for the tracking. We'll add an extra column in sales_flat_quote_item to store that information.
To do this properly write your own module, a tutorial about that you can find here on Tutsplus....
There are two ways to do it
1) Using Magento Admin Panel
2) Using Custom Coding
1) To add using Magento Backend you need to follow below steps
a) Goto Catalog->Attributes->Manage Attributes
b) Select the attribute you want to add in Sort By option. Suppose you need to add a Sort By Brand Option.
c) Goto Brand Attribute and check for "Used for Sorting ...
Short answer: The sorting doesn't work for Yes/No attributes.
When calling addAttributeToSort on a product collection, if the attribute has a source model then Magento calls addValueSortToCollection from that source model to sort the products.
The Yes/No attributes use the source model ...
To sort products by rating you can use the following code, taken from this module:
'rating_summary', // alias
'review/review_aggregate', // table
'rating_summary', // field
'entity_pk_value=entity_id', // bind
'entity_type' => 1,
The available sorting methods are
addOrder(), setOrder(), unshiftOrder(), addAttributeToSort() and getSelect()->order()
Only setOrder($field, $dir) is available regardless of collection type and system settings. I suggest you get used to using setOrder().
If you need to enforce an order, but an order is already set on the collection, use unshiftOrder($...
You need to a custom extension with plugins, I followed this
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
quick workaround can be add a condition in theme templates file Magento_Catalog/templates/product/list/toolbar/sorter.phtml
if $key != 'position' then don't add in drop down options :
<select id="sorter" data-role="sorter" class="sorter-options">
<?php foreach ($block->getAvailableOrders() as $_key => $_order): ?>
Ok, I try to explain my solution, I give here most important points, but you should have some experiences like magento layouts, blocks, create custom module.
1. Create attribute which you assumed in your question.
2. Configure your products attaching them to particular category and attribute value created above.
3. Create custom block given in example (/app/...
for -> Recently Viewed see here
for ->Sorting by rating
Copy the file
in list.php find for this line
which will be in around line no 86 add the following code after that
I would suppose that search is implemented using MySQL FULLTEXT index.
Here is a quote from MySQL official documentation regarding to how that index works:
Rows returned are automatically sorted with the highest relevance first. Relevance values are nonnegative floating-point numbers. Zero relevance means no similarity. Relevance is computed based on the ...
You will need to add sort order to search criteria
Add \Magento\Framework\Api\SortOrderBuilder $sortOrderBuilder as dependency in constructor.
public function getCollection()
$sortOrder = $this->sortOrderBuilder->setField('position')->setDirection('DESC')->create();
$searchCriteria = $this->searchCriteriaBuilder->...
Ok. I should wait an hour more before posting a question.
This seams to work.
I've rewritten Mage_Catalog_Model_Resource_Product_Collection::addAttributeToSort() and made it look like this (not a pretty code but works, layered navigation and all):
you cannot modify the attribute created_at in the backend.
So you need to create a module that just activates the created_at attribute for sorting.
For this you will need the following files:
app/etc/modules/[Namespace]_[Module].xml - the declaration file
Question is tagged CE 188.8.131.52 but this solution is useful for those on 184.108.40.206 so I'm adding it here.
We had an opposite problem where we needed to show the cheapest products first when sorted by Price. For the OP's first concern, this doesn't apply because in Magento CE 1.9 it already defaults to descending so this is actually not needed. The second ...
Never mind, I figured it out. I can just call Varien_Data_Collection_Db::setOrder twice, e.g.:
This example would first sort the collection by the bill to attribute and then the created at attribute.
Typical! After hours of searching I make a post...only to find the answer 5 minutes later.
Modify the local file app/code/local/Mage/Adminhtml/Block/Catalog/Product/Grid.php and make line 41 read:
The reason you got two lists with ascending order is because of PHP sort() function. The default sorting behavior for this function is non-natural ordering, so it gives you unpredictable results. Try natcasesort() instead of sort(). See more detail about PHP sort() on below link:
try to sorting your ...
Go to Stores > Configuration > Sales > Payment Methods there you find 'Sort Order' field corresponding to all payment methods. So, provide greater number to paypal and lesser number to sagepay to rearrange it.
Make sure the archive attribute is added to the flat product data by setting Used in Product Listing to yes. Also it's probably better to load the product collection via the catalog/category model instead of joining another table.
Also, to have yes come as last make the order ascending instead of descending
$category = Mage::getModel('catalog/category')-&...
First add a dummy attribute called 'discount_percent' and make it "used for sorting" (just as Giuseppe said in the other answer).
It's not important what type it is or what values it has.
it's easier that way. If you don't want to add the attribute you have to rewrite the method Mage_Catalog_Model_Config::getAttributeUsedForSortByArray to include your ...