我有一個new.phtml文件和new.php文件,我確信主頁上顯示的產品僅來自這些文件。目前只有6種產品正在展出。我只是想知道如何能夠顯示更多的產品(應增加3的乘法)像9,12,15等 我試圖在兩個文件中替換所有'6'到'9',但我無法得到我要找的東西?請任何人都幫助我,給我一些技巧! 這裏是new.php文件代碼:如何設置Magento主頁上顯示的產品數
class Mage_Catalog_Block_Pro duct_New extends Mage_Catalog_Block_Product_Abstract
{
protected $_productsCount = null;
const DEFAULT_PRODUCTS_COUNT = 5;
/**
* Initialize block's cache
*/
protected function _construct()
{
parent::_construct();
$this->addColumnCountLayoutDepend('empty', 10)
->addColumnCountLayoutDepend('one_column', 5)
->addColumnCountLayoutDepend('two_columns_left', 4)
->addColumnCountLayoutDepend('two_columns_right', 4)
->addColumnCountLayoutDepend('three_columns', 3);
$this->addData(array(
'cache_lifetime' => 86400,
'cache_tags' => array(Mage_Catalog_Model_Product::CACHE_TAG),
));
}
/**
* Get Key pieces for caching block content
*
* @return array
*/
public function getCacheKeyInfo()
{
return array(
'CATALOG_PRODUCT_NEW',
Mage::app()->getStore()->getId(),
Mage::getDesign()->getPackageName(),
Mage::getDesign()->getTheme('template'),
Mage::getSingleton('customer/session')->getCustomerGroupId(),
'template' => $this->getTemplate(),
$this->getProductsCount()
);
}
/**
* Prepare collection with new products and applied page limits.
*
* return Mage_Catalog_Block_Product_New
*/
protected function _beforeToHtml()
{
$todayStartOfDayDate = Mage::app()->getLocale()->date()
->setTime('00:00:00')
->toString(Varien_Date::DATETIME_INTERNAL_FORMAT);
$todayEndOfDayDate = Mage::app()->getLocale()->date()
->setTime('23:59:59')
->toString(Varien_Date::DATETIME_INTERNAL_FORMAT);
$collection = Mage::getResourceModel('catalog/product_collection');
$collection->setVisibility(Mage::getSingleton('catalog/product_visibility')->getVisibleInCatalogIds());
$collection = $this->_addProductAttributesAndPrices($collection)
->addStoreFilter()
->addAttributeToFilter('news_from_date', array('or'=> array(
0 => array('date' => true, 'to' => $todayEndOfDayDate),
1 => array('is' => new Zend_Db_Expr('null')))
), 'left')
->addAttributeToFilter('news_to_date', array('or'=> array(
0 => array('date' => true, 'from' => $todayStartOfDayDate),
1 => array('is' => new Zend_Db_Expr('null')))
), 'left')
->addAttributeToFilter(
array(
array('attribute' => 'news_from_date', 'is'=>new Zend_Db_Expr('not null')),
array('attribute' => 'news_to_date', 'is'=>new Zend_Db_Expr('not null'))
)
)
->addAttributeToSort('news_from_date', 'desc')
->setPageSize(9)
->setCurPage(1)
;
$this->setProductCollection($collection);
return parent::_beforeToHtml();
}
/**
* Set how much product should be displayed at once.
*
* @param $count
* @return Mage_Catalog_Block_Product_New
*/
public function setProductsCount($count)
{
$this->_productsCount = $count;
return $this;
}
/**
* Get how much products should be displayed at once.
*
* @return int
*/
public function getProductsCount()
{
if (null === $this->_productsCount) {
$this->_productsCount = self::DEFAULT_PRODUCTS_COUNT;
}
return $this->_productsCount;
}
}
Here is my new.phtml file:
<?php $_helper = $this->helper('catalog/output'); ?>
<?php if (($_products = $this->getProductCollection()) && $_products->getSize()): ?>
<?php $_columnCount = 3 ?>
<div class="block-new-top"><strong class="cat-tit"><?php echo $this->__('New Products') ?></strong></div>
<div class="block-new">
<div class="clear"></div>
<div class="block-content">
<?php $m=1; ?>
<?php $i=0; foreach ($_products->getItems() as $_product): ?>
<?php if ($i++%$_columnCount==0 ): ?>
<ul class="products-grid" id="proid<?php echo $m; ?>">
<?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->htmlEscape($_product->getName()) ?>" class="product-image"><img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(160) ?>" width="160" height="160" alt="<?php echo $this->htmlEscape($_product->getName()) ?>" /></a>
<div class="align-prodname-price-review">
<h3 class="product-name"><a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>"><?php echo $this->htmlEscape($_product->getName()) ?></a></h3>
<?php echo $this->getReviewsSummaryHtml($_product, 'short') ?>
</div>
<div class="new-des">
<?php
$position=50; // Define how many character you want to display.
$message= $_helper->productAttribute($_product, $_product->getShortDescription(), 'short_description');
$post = substr($message, 0, $position);
echo $post;
echo "...";
?>
</div>
<div class="actions">
<div class="pri"><?php echo $this->getPriceHtml($_product, true, '-new') ?></div>
<div class="view-more">
<?php if($_product->isSaleable()): ?>
<div class="detail-container"><a href="<?php echo $_product->getProductUrl() ?>"> View More>> </a></div>
<?php else: ?>
<p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
<?php endif; ?>
</div>
</div>
</li>
<?php if ($i%$_columnCount==0 || $i==count($_products)): ?>
</ul>
<?php endif ?>
<?php $m++; ?>
<?php endforeach; ?>
</div>
<?php endif; ?>
</div>
<div class="block-new-bottom"></div>
正在使用的產品loadedcollection這些文件,或不得不編寫自定義代碼來獲取產品? –
我認爲它是一個自定義代碼 –
您是指在magento樣本數據中使用的最暢銷產品? –