app/code/local/Mage/Catalog/Block/Product/New.php
<?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']) : 10; }// 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() { $todayDate = Mage::app()->getLocale()->date()->toString(Varien_Date::DATETIME_INTERNAL_FORMAT); $collection = Mage::getResourceModel('catalog/product_collection'); $collection->setVisibility(Mage::getSingleton('catalog/product_visibility')->getVisibleInCatalogIds()); $order = (isset($_REQUEST['order'])) ? $_REQUEST['order'] : "name"; $dir = (isset($_REQUEST['dir'])) ? $_REQUEST['dir'] : "asc"; $collection = $this->_addProductAttributesAndPrices($collection) ->addStoreFilter() ->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') ->addAttributeToSort($order, $dir) ->setPageSize($this->get_prod_count()); $collection->setCurPage($this->get_cur_page()); $this->setProductCollection($collection); return $collection; }// get product collection } ?>
app->design->fronted->your_package->your_theme->template->catalog->product->new.phtml
<?php $_productCollection=$this->getProductCollection(); $_helper = $this->helper('catalog/output'); ?> <?php if(!$_productCollection->count()): ?> <p class="note-msg"><?php echo $this->__('There are no products matching the selection.') ?></p> <?php else: ?> <div class="category-products"> <?php echo $this->getToolbarHtml() ?> <?php // List mode ?> <?php if($this->getMode()!='grid'): ?> <?php $_iterator = 0; ?> <ol class="products-list" id="products-list"> <?php foreach ($_productCollection as $_product): ?> <li class="item<?php if( ++$_iterator == sizeof($_productCollection) ): ?> last<?php endif; ?>"> <?php // Product Image ?> <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" class="product-image"><img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(135); ?>" width="135" height="135" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" /></a> <?php // Product description ?> <div class="product-shop"> <div class="f-fix"> <?php $_productNameStripped = $this->stripTags($_product->getName(), null, true); ?> <h2 class="product-name"><a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $_productNameStripped; ?>"><?php echo $this->htmlEscape($_product->getName()) ?></a></h2> <div class="desc std"> <?php echo $_helper->productAttribute($_product, $_product->getShortDescription(), 'short_description') ?> <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $_productNameStripped ?>" class="link-learn"><?php echo $this->__('Learn More') ?></a> </div> <?php echo $this->getPriceHtml($_product, true) ?> <?php if($_product->isSaleable()): ?> <p><button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><img src="<?php echo $this->getSkinUrl('images/add_to_cart_btn.gif');?>"/></button></p> <?php else: ?> <p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p> <?php endif; ?> <?php echo $this->getReviewsSummaryHtml($_product, 'short') ?> </div> </div> </li> <?php endforeach; ?> </ol> <script type="text/javascript">decorateList('products-list', 'none-recursive')</script> <?php else: ?> <?php // Grid Mode ?> <?php $_collectionSize = $_productCollection->count() ?> <?php $_columnCount = $this->getColumnCount(); ?> <?php $i=0; foreach ($_productCollection as $_product): ?> <?php if ($i++%$_columnCount==0): ?> <ul class="products-grid"> <?php endif ?> <li class="item<?php if(($i-1)%$_columnCount==0): ?> first<?php elseif($i%$_columnCount==0): ?> last<?php endif; ?>"> <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" class="product-image"><img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(135); ?>" width="135" height="135" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" /></a> <h2 class="product-name"> <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($_product->getName(), null, true) ?>"> <?php echo $this->htmlEscape($_product->getName()) ?> </a> </h2> <?php echo $this->getReviewsSummaryHtml($_product, 'short') ?> <?php echo $this->getPriceHtml($_product, true) ?> <div class="actions"> <?php if($_product->isSaleable()): ?> <button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><img src="<?php echo $this->getSkinUrl('images/add_to_cart_btn.gif');?>"/></button> <?php else: ?> <p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p> <?php endif; ?> </div> </li> <?php if ($i%$_columnCount==0 || $i==$_collectionSize): ?> </ul> <?php endif ?> <?php endforeach ?> <script type="text/javascript">decorateGeneric($$('ul.products-grid'), ['odd','even','first','last'])</script> <?php endif; ?> <div class="toolbar-bottom"> <?php echo $this->getToolbarHtml() ?> </div> </div> <?php endif; ?>
Add code in cms->page->design->Layout Update XML area.
<reference name="content"> <block type="catalog/product_new" name="product_new" template="catalog/product/new.phtml"> <action method="setCategoryId"><category_id>4</category_id></action> <action method="setColumnCount"><column_count>3</column_count></action> <action method="setProductsCount"><count>0</count></action> <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="addColumnCountLayoutDepend"><layout>one_column</layout><count>6</count></action> <action method="setToolbarBlockName"><name>product_list_toolbar</name></action> </block> </reference>
0 Comments