我需要在magento中创造畅销书.... 我编写了一些代码......但是它不起作用..
我需要知道我在这段代码中修改过的内容...... 对于畅销书....
$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('special_from_date', array('or'=> array(
0 => array('date' => true, 'to' => $todayDate),
1 => array('is' => new Zend_Db_Expr('null')))
), 'left')
->addAttributeToFilter('special_to_date', array('or'=> array(
0 => array('date' => true, 'from' => $todayDate),
1 => array('is' => new Zend_Db_Expr('null')))
), 'left')
->addAttributeToFilter(
array(
array('attribute' => 'special_from_date', 'is'=>new Zend_Db_Expr('not null')),
array('attribute' => 'special_to_date', 'is'=>new Zend_Db_Expr('not null'))
)
)
->addAttributeToSort('special_from_date', 'desc')
->setPageSize($this->getProductsCount())
->setCurPage(1)
;
答案 0 :(得分:0)
您可以通过这种方式获得最畅销的产品:
$collection = Mage::getResourceModel('sales/report_bestsellers_collection')
->setModel('catalog/product');
如果您希望它们用于特定商店视图,只需添加此行
即可$collection->addStoreFilter($storeId);
如果您想要限制添加:
$collection->setCurPage(1)->setPageSize($limit);