Hello,
Here I am Create Custom Query for Product list. I want to get all product that price
less than 1000 in magento. I am Giving Example for that
First Create Cms page goto Cms=>page
in cms page
goto design=>Layout Update XML
Write below code in xml
<reference name="root">
<action method="setTemplate"><template>page/2columns-left.phtml</template></action>
<action method="unsetChild"><alias>breadcrumbs</alias></action>
<block type="page/html_breadcrumbs" name="breadcrumbs" as="breadcrumbs">
<action method="addCrumb">
<crumbName>Home</crumbName>
<crumbInfo><label>Home</label><title>Home</title><link>/</link></crumbInfo>
</action>
<action method="addCrumb">
<crumbName>Custom Page</crumbName>
<crumbInfo><label>1000 Under</label><title>1000 Under</title></crumbInfo>
</action>
</block>
</reference>
<reference name="left">
<block type="catalog/navigation" name="catalog.categorymenu" before="catalog.leftnav" template="catalog/product/categorymenu.phtml"/>
</reference>
<reference name="content">
<block type="catalog/product_new" name="product_list" template="catalog/product/list.phtml">
<block type="catalog/product_list_toolbar" name="product_list_toolbar" template="catalog/product/list/toolbar.phtml">
<block type="page/html_pager" name="product_list_toolbar_pager"/>
</block>
<action method="setToolbarBlockName"><name>product_list_toolbar</name></action>
</block>
</reference>
Here I am Create Custom Query for Product list. I want to get all product that price
less than 1000 in magento. I am Giving Example for that
First Create Cms page goto Cms=>page
in cms page
goto design=>Layout Update XML
Write below code in xml
<reference name="root">
<action method="setTemplate"><template>page/2columns-left.phtml</template></action>
<action method="unsetChild"><alias>breadcrumbs</alias></action>
<block type="page/html_breadcrumbs" name="breadcrumbs" as="breadcrumbs">
<action method="addCrumb">
<crumbName>Home</crumbName>
<crumbInfo><label>Home</label><title>Home</title><link>/</link></crumbInfo>
</action>
<action method="addCrumb">
<crumbName>Custom Page</crumbName>
<crumbInfo><label>1000 Under</label><title>1000 Under</title></crumbInfo>
</action>
</block>
</reference>
<reference name="left">
<block type="catalog/navigation" name="catalog.categorymenu" before="catalog.leftnav" template="catalog/product/categorymenu.phtml"/>
</reference>
<reference name="content">
<block type="catalog/product_new" name="product_list" template="catalog/product/list.phtml">
<block type="catalog/product_list_toolbar" name="product_list_toolbar" template="catalog/product/list/toolbar.phtml">
<block type="page/html_pager" name="product_list_toolbar_pager"/>
</block>
<action method="setToolbarBlockName"><name>product_list_toolbar</name></action>
</block>
</reference>
after create block in your app\code\local\Mage\Catalog\Block\Product\new.php
Write this code for that
<?php
class Mage_Catalog_Block_Product_New extends Mage_Catalog_Block_Product_List
{
function get_prod_count()
{
//unset any saved limits
Mage::getSingleton('catalog/session')->unsLimitPage();
return (isset($_REQUEST['limit'])) ? intval($_REQUEST['limit']) : 12;//set your page limit
}// get_prod_count
function get_cur_page()
{
return (isset($_REQUEST['p'])) ? intval($_REQUEST['p']) : 1;
}// get_cur_page
/**
* Retrieve loaded category collection
*
* @return Mage_Eav_Model_Entity_Collection_Abstract
**/
protected function _getProductCollection()
{
$collection = Mage::getModel('catalog/product')
->getCollection()
->addAttributeToSelect('*')
->addPriceData()
->setOrder('price', 'ASC')
->addAttributeToFilter('price', array('lt' => '1001'))
->addFieldToFilter('status', array('eq' => '1')
);
$this->setProductCollection($collection);
return $collection;
}// _getProductCollection
}// Mage_Catalog_Block_Product_New
?>
0 komentar:
Post a Comment