0
如何在magento中顯示特定類別中的新產品並僅顯示其圖像,名稱和說明?是否有可能將其添加到通訊?如何顯示Magento中特定類別的新產品?
如何在magento中顯示特定類別中的新產品並僅顯示其圖像,名稱和說明?是否有可能將其添加到通訊?如何顯示Magento中特定類別的新產品?
使用下面的代碼。設置您news_from_date
和news_to_date
日期和CategoryId
It've創建它剛纔並用事先準備好的產品進行了測試:
$collection = Mage::getModel('catalog/product')
->getCollection()
->addCategoryFilter(Mage::getModel('catalog/category')->load(3))
->addAttributeToSelect(array('name', 'sku', 'description', 'small_image', 'news_from_date', 'news_to_date', 'category_id'))
->addAttributeToFilter('news_from_date',array('date' => true, 'gteq' => '2013-05-03'))
->addAttributeToFilter('news_to_date', array('date' => true, 'lteq' => '2013-11-25'))
;
foreach ($collection as $product)
{
var_dump($product->getName());
var_dump($product->getDescription());
var_dump($product->getNewsFromDate());
var_dump($product->getNewsToDate());
}
<?php
$categoryid = 12;
$category = new Mage_Catalog_Model_Category();
$category->load($categoryid);
$collection = $category->getProductCollection();
$collection->addAttributeToSelect('*');
foreach ($collection as $_product) { ?>
<a href="<?php echo $_product->getProductUrl() ?>"><img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(200); ?>" width="200" height="200" alt="" /></a> <a href="<?php echo $_product->getProductUrl(); ?>"><?php echo $_product->getName(); ?></a>
enter code here
感謝您的及時答覆,我在哪裏可以放這段代碼,我將如何使用這段代碼 –
這是php代碼,所以你可以在magento app/design/front中將它作爲單個'.phtml'文件添加結束/ ...'上下文。如果你使用它作爲新聞通訊的內容,也許你必須創建一個「塊」來將腳本的輸出嵌入到通訊cms編輯器中......但我不知道,如何完全做到這一點... –
@StefanBrendle很好的解釋.. – Elavarasan