Posts

Showing posts from July, 2013

Magento Collection Query with AND / OR Operators

For those who are new with magento, below post will help them to understand that how  AND & OR operator  should work with Magento to fetch Collection from Database Please Note: A. I am assuming that you are aware about Magento Model. B. In below Examples, lets considered  $salesorderid =9; Ex:1 - Magento SQL Query with - OR Operator $outstandingCollection= Mage::getModel('adminhtmlmodule/adminhtmlmodule')->getCollection()->addFieldToSelect('salesorderid');                 $outstandingCollection->addFieldToFilter(array('salesorderid','paystatus'), array(                   array('salesorderid','eq'=>$salesorderid),                   array('paystatus','eq'=>'0')              )          ); Output : SELECT `main_table`.`salesorderid` FROM `extracharges` AS `main_table` WHERE ((salesorderid = '9') OR (paystatus = '0')) --- Ex:2 - Magento  SQL Query with -

Change Default Sort Order of Product Listing to Descending

Hi Guys, Many times we need to change default functionality in Magento as per Client requirement. One problem which I have faced is how to " Change Default Sort Order to Descending " in product listing page. The best and simplest solution which works well for me. Just add below highlighted code in your catalog.xml (stored in your THEME LAYOUT) under these catalog_category_default &  catalog_category_layered sections Here is the code : <block type="catalog/product_list_toolbar" name="product_list_toolbar" template="catalog/product/list/toolbar.phtml"> <action method="setDefaultDirection"><dir>desc</dir></action> <block type="page/html_pager" name="product_list_toolbar_pager"/> </block>