Pages

Tuesday, June 25, 2013

Different kind of catalog sorting (top selling,top rated, new products, special products) in magento

////////////////////////////////////
template/catalog/product/list/toolbar.phtml
<div class=”demoTarget toolbar”>
<span class=”pagingTotal”>Order:</span>
<?php /*?><select onchange=”setLocation(this.value)” id=”default-usage-selectdate”>
<?php foreach($this->getAvailableOrders() as $_key=>$_order): ?>
<option value=”<?php echo $this->getOrderUrl($_key, ‘asc’) ?>”<?php if($this->isOrderCurrent($_key)): ?> selected=”selected”<?php endif; ?>>
<?php echo $this->__($_order) ?>
</option>
<?php endforeach; ?>
</select><?php */?>
<?php $orderDir = $this->getRequest()->getParam(‘dir’);?>
<select onchange=”setLocation(this.value)” id=”default-usage-selectdate”>
<option value=”<?php echo $this->getOrderUrl(‘topsellings’, ‘desc’) ?>”<?php if($this->isOrderCurrent(‘topsellings’)): ?> selected=”selected”<?php endif; ?>>
Top Selling
</option>
<option value=”<?php echo $this->getOrderUrl(‘special_price’, ‘desc’) ?>”<?php if($this->isOrderCurrent(‘special_price’)): ?> selected=”selected”<?php endif; ?>>
Special Orice
</option>
<option value=”<?php echo $this->getOrderUrl(‘newest’, ‘desc’) ?>”<?php if($this->isOrderCurrent(‘newest’)): ?> selected=”selected”<?php endif; ?>>
New Products
</option>
<option value=”<?php echo $this->getOrderUrl(‘popularity’, ‘desc’) ?>”<?php if($this->isOrderCurrent(‘popularity’)): ?> selected=”selected”<?php endif; ?>>
Popularity (Most Rated)
</option>
</select>
<div class=”clr”></div>
</div>
——————————————————————————–
D:\xampp\htdocs\lamemo\live\app\code\core\Mage\Catalog\Block\Product\List\Toolbar.php
in function setCollection() put below code
————————————————-
<?php
if($this->getCurrentOrder() == ‘popularity’){
$this->_collection->joinField(‘rating_score’,
‘lamemoreview_entity_summary’,
‘rating_summary’,
‘entity_pk_value=entity_id’,
array(‘entity_type’=>1, ‘store_id’=> Mage::app()->getStore()->getId()),
‘left’
)->setOrder(‘rating_score’, $this->getCurrentDirection());
}
elseif($this->getCurrentOrder() ==’special_price’)
{
$todayDate = Mage::app()->getLocale()->date()->toString(Varien_Date::DATETIME_INTERNAL_FORMAT);
/*$this->_collection->addAttributeToFilter(‘special_from_date’, array(‘or’=> array(
0 => array(‘date’ => true, ‘to’ => $todayDate),
1 => array(‘is’ => new Zend_Db_Expr(‘null’)))
))->addAttributeToFilter(‘special_to_date’, array(‘or’=> array(
0 => array(‘date’ => true, ‘from’ => $todayDate),
1 => array(‘is’ => new Zend_Db_Expr(‘null’)))
))->addAttributeToSort(‘special_price’, ‘DESC’);*/
/*$this->_collection->joinTable(‘lamemocatalog_product_flat_1′,’entity_id=entity_id’,array(‘goodcustom’=>”abs (lamemocatalog_product_flat_1.special_from_date <= ‘”.$todayDate.”‘ and (lamemocatalog_product_flat_1.special_to_date >= ‘”.$todayDate.”‘ or lamemocatalog_product_flat_1.special_to_date = NULL))”),NULL,’left’)->getSelect()->order(“goodcustom desc”);
echo $this->_collection->getSelect();*/
$this->_collection->joinTable(‘lamemocatalog_product_flat_1′,’entity_id=entity_id’,array(‘cust_ord_field’=>”IF((special_from_date <= ‘”.$todayDate.”‘ &&
(special_to_date >= ‘”.$todayDate.”‘ || isnull(special_to_date))),’yes’,'no’)”),NULL,’left’);
$this->_collection->getSelect()->order(“cust_ord_field desc”);
$this->_collection->getSelect()->order(“final_price asc”);
//echo $this->_collection->getSelect();
/*$this->_collection->addAttributeToFilter(‘special_from_date’, array(‘date’ => true, ‘to’ => $todayDate))
->addAttributeToFilter(‘special_to_date’, array(‘or’=> array(
0 => array(‘date’ => true, ‘from’ => $todayDate),
1 => array(‘is’ => new Zend_Db_Expr(‘null’)))
), ‘left’)->addAttributeToSort(‘special_price’, ‘ASC’);*/
}
elseif($this->getCurrentOrder() == ‘newest’){
$todayDate = Mage::app()->getLocale()->date()->toString(Varien_Date::DATETIME_INTERNAL_FORMAT);
/*$this->_collection->addAttributeToFilter(‘news_from_date’, array(‘date’ => true, ‘to’ => $todayDate))
->addAttributeToFilter(‘news_to_date’, array(‘or’=> array(
0 => array(‘date’ => true, ‘from’ => $todayDate),
1 => array(‘is’ => new Zend_Db_Expr(‘null’)))
), ‘left’)->setOrder(‘news_to_date’, $this->getCurrentDirection());;*/
/*$this->_collection->joinTable(‘lamemocatalog_product_flat_1′,’entity_id=entity_id’,array(‘goodcustom’=>”abs (lamemocatalog_product_flat_1.news_from_date <= ‘”.$todayDate.”‘ and lamemocatalog_product_flat_1.news_to_date >= ‘”.$todayDate.”‘)”),NULL,’left’)->getSelect()->order(“goodcustom desc”);
echo $this->_collection->getSelect();*/
$this->_collection->joinTable(‘lamemocatalog_product_flat_1′,’entity_id=entity_id’,array(‘cust_ord_field’=>”if(news_from_date <= ‘”.$todayDate.”‘ and
(news_to_date >= ‘”.$todayDate.”‘ || isnull(news_to_date)) ,’yes’,'no’)”),NULL,’left’);
$this->_collection->getSelect()->order(“cust_ord_field desc”);;
$this->_collection->getSelect()->order(“final_price desc”);;
//”news_from_date <= ‘”.$todayDate.”‘ and news_to_date >= ‘”.$todayDate.”‘ desc”
// echo $this->_collection->getSelect();
}
elseif($this->getCurrentOrder() == ‘topsellings’){
/* $this->_collection->getSelect()->
joinLeft(‘lamemosales_flat_order_item AS sfoi’,
‘e.entity_id = sfoi.product_id’,
‘SUM(sfoi.qty_ordered) AS ordered_qty’)->
group(‘e.entity_id’)->order(‘ordered_qty DESC’); */
create view
CREATE  VIEW `salesitemsqty` AS select `lamemosales_flat_order_item`.`product_id` AS `product_id`,count(0) AS `ord_qty` from `lamemosales_flat_order_item` group by `lamemosales_flat_order_item`.`product_id`
$this->_collection->joinTable(‘salesitemsqty’,'product_id=entity_id’,array(‘tqty_ordered’=>’ord_qty’),NULL,’left’)->setOrder(‘tqty_ordered’, $this->getCurrentDirection());
/*$this->_collection->joinField(‘ordered_qty’,
‘lamemosales_flat_order_item’,
‘SUM(qty_ordered) AS ordered_qty’,
‘product_id = entity_id’,
array(‘store_id’=> Mage::app()->getStore()->getId()),
‘left’
)->setOrder(‘ordered_qty’, $this->getCurrentDirection()); */
/*$storeId = Mage::app()->getStore()->getId();
$products = Mage::getResourceModel(‘reports/product_collection’)
->addOrderedQty()
->addAttributeToSelect(‘*’) //Need this so products show up correctly in product listing
->setStoreId($storeId)
->addStoreFilter($storeId);
Mage::getSingleton(‘catalog/product_status’)->addVisibleFilterToCollection($products);
Mage::getSingleton(‘catalog/product_visibility’)->addVisibleInCatalogFilterToCollection($products);*/
}
?>

No comments:

Post a Comment