我想改变Magento核心文件New.php将新产品称为块的方式。
该文件位于app / code / core / Mage / Catalog / Block / Product / New.php - 我已将此文件复制到本地目录以保护其免受更新。
感兴趣的内容是:
protected function _beforeToHtml()
{
$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());
$collection = $this->_addProductAttributesAndPrices($collection)
->addStoreFilter()
->addAttributeToFilter('news_from_date', array('or'=> array(
0 => array('date' => true, 'to' => $todayDate),
1 => array('is' => new Zend_Db_Expr('null')))
), 'left')
->addAttributeToFilter('news_to_date', array('or'=> array(
0 => array('date' => true, 'from' => $todayDate),
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($this->getProductsCount())
->setCurPage(1)
;
$this->setProductCollection($collection);
return parent::_beforeToHtml();
}
该文件的工作原理是从产品管理员中提取New Product From
和New Product To
日期字段的选项字段。考虑到更新这些字段所需的目录和手动管理的大小,这是不方便的。所以基本上我想改变功能以获得MAX产品ID(即添加的最新产品)并在此之前运行到100。这将列出商店中最近的100种产品。
我尝试过类似的东西,但它不起作用。
$collection = $this->_addProductAttributesAndPrices($collection)
->addStoreFilter()
->addAttributeToFilter ('entity_id')
->addAttributeToSort('entity_id', 'desc')
->setPageSize($this->getProductsCount())
->setCurPage(1)
;
$this->setProductCollection($collection);
return parent::_beforeToHtml();
}
这只是试图根据产品ID(entity_id)返回产品,但没有返回任何内容(它也没有给出任何php错误)。
答案 0 :(得分:1)
尝试(删除 - > addAttributeToFilter('entity_id')...在v1.7上测试)
....
$collection = $this->_addProductAttributesAndPrices($collection)
->addStoreFilter()
->addAttributeToSort('entity_id', 'desc')
->setPageSize($this->getProductsCount())
->setCurPage(1);
...