Showing posts with label Sort. Show all posts
Showing posts with label Sort. Show all posts

Thursday 5 May 2016

How to Shopify API Product / Order / Collection get sorted when passing in an created_at / updated_at filter

What would be ideal would be to be able to get results in ascending/descending order one way or another, but without having to pass in since_id, because we want to be able to pull in new data on orders on an ongoing basis as they may be updated.

Its possible to sort the Products/Orders/Collection by passing an "order" parameter. The "order" parameter should contain the field to sort by (supported fields are "created_at", "updated_at" and "processed_at"), followed by a space and then by an "asc" or "desc".

Please check following Example for solution.

https://example.myshopify.com/admin/orders.json?limit=2&fields=id,created_at&order=created_at%20asc

Saturday 11 July 2015

How to sort Magento products by popularity in frontend?

I have created a module to add a new option in 'sort by' dropdown box in the category page. the new option should show in each and every category page same as 'position' option which is already there. I want to add 'popularity' as an option. My Model class is executing and it's adding the option to the option array. But the block is not working. Please I need your help to find the issue in my code?
Here is the Block class


<?php
class Tal_Popularity_Block_Product_List_Toolbar extends Mage_Catalog_Block_Product_List_Toolbar{ public function setCollection($collection) { $this->_collection = $collection; $this->_collection->setCurPage($this->getCurrentPage()); // we need to set pagination only if passed value integer and more that 0 $limit = (int)$this->getLimit(); if ($limit) { $this->_collection->setPageSize($limit); } if($this->getCurrentOrder() == 'popularity'){ $this->_collection->sortByReview($this->getCurrentDirection()); } else if ($this->getCurrentOrder()) { $this->_collection->setOrder($this->getCurrentOrder(), $this->getCurrentDirection()); } return $this; }}
 
 
following is my config.xml
 
<?xml version="1.0" ?> <config> <modules> <Tal_Popularity> <version>0.1.0</version> </Tal_Popularity> </modules> <frontend> <routers> <popularity> <use>standard</use> <args> <module>Tal_Popularity</module> <frontName>popularity</frontName> </args> </popularity> </routers> </frontend> <global> <models> <catalog> <rewrite> <config>Tal_Popularity_Model_Config</config> </rewrite> </catalog> </models> <blocks> <catalog> <rewrite> <product_list_toolbar>Tal_Popularity_Block_Product_List_Toolbar</product_list_toolbar> </rewrite> </catalog> <catalog> <rewrite> <catalog>Tal_Popularity_Block</catalog> </rewrite> </catalog> </blocks> <resources> <popularity_setup> <setup> <module>Tal_Popularity</module> </setup> <connection> <use>core_setup</use> </connection> </popularity_setup> <popularity_write> <connection> <use>core_write</use> </connection> </popularity_write> <popularity_read> <connection> <use>core_read</use> </connection> </popularity_read> </resources> </global> </config> <rewrite> <product_list_toolbar>Tal_Popularity_Block_Product_List_Toolbar</product_list_toolbar> </rewrite> </catalog> <catalog> <rewrite> <catalog>Tal_Popularity_Block</catalog> </rewrite> </catalog> </blocks> <resources> <popularity_setup> <setup> <module>Tal_Popularity</module> </setup> <connection> <use>core_setup</use> </connection> </popularity_setup> <popularity_write> <connection> <use>core_write</use> </connection> </popularity_write> <popularity_read> <connection> <use>core_read</use> </connection> </popularity_read> </resources> </global></config>