I'm passing a collection to a method that will conditionally apply sorting to it. However, it seems that only 20 of the total products are being sorted, the rest, are unsorted and lay at the end of the bulk sorted section. Why is this? Below is the the conditional:
protected function sortProducts($collection)
{
switch ($this->getOrder()) {
case 'product group':
return $collection->addAttributeToSort('price', 'asc');
...
...
}
}
Below is the resultant log of the product collection (note this is a new products collection containing 25 products in total).
2015-01-29T21:53:38+00:00 DEBUG (7): SELECT 1 AS
status
,e
.entity_id
,e
.type_id
,e
.attribute_set_id
,cat_index
.position
AScat_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) ASminimal_price
,price_index
.min_price
,price_index
.max_price
,price_index
.tier_price
,e
.name
,e
.short_description
,e
.price
,e
.special_price
,e
.special_from_date
,e
.special_to_date
,e
.small_image
,e
.thumbnail
,e
.news_from_date
,e
.news_to_date
,e
.url_key
,e
.required_options
,e
.image_label
,e
.small_image_label
,e
.thumbnail_label
,e
.msrp_enabled
,e
.msrp_display_actual_price_type
,e
.msrp
,e
.tax_class_id
,e
.price_type
,e
.weight_type
,e
.price_view
,e
.shipment_type
,e
.links_purchased_separately
,e
.links_exist
,e
.giftcard_amounts
,e
.allow_open_amount
,e
.open_amount_min
,e
.open_amount_max
FROMcatalog_product_flat_1
ASe
INNER JOINcatalog_category_product_index
AScat_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 = '2' INNER JOINcatalog_product_index_price
ASprice_index
ON price_index.entity_id = e.entity_id AND price_index.website_id = '1' AND price_index.customer_group_id = 0 WHERE (((((e.news_from_date <= '2015-01-29 23:59:59') OR (e.news_from_date IS null))))) AND (((((e.news_to_date >= '2015-01-29 00:00:00') OR (e.news_to_date IS null))))) AND ((e
.news_from_date
IS not null) OR (e
.news_to_date
IS not null)) ORDER BYe
.news_from_date
desc,price_index
.min_price
asc
$collection->getSelect()->__toString()
If you can then paste that output with any other collection manipulation that might be done before the return ( passed into the method ) or after in the calling method I can try and help more.$collection->setPageSize(false);
Try running the query in a MySQL client and try updating the sortORDER BY
as currently its sorting onnews_from_date
desc and the nprice
asc perhaps the data you have is what makes this appear to be an issue and not the collection query that is being generated.news_from_date
sort and only using theprice
sort seems to have cleared things up, thanks. Now time to reconfigure this collection sort. If you create an answer I'll gladly accept.