标签归档:Magento最新商品

Magento获取最近更新商品

Magento最新商品

Magento最新商品

今天google了下,总结了下如何获取Magento每个分类的最近更新商品,根据商品的ID号,倒序排列出最后添加的商品。代码如下

<?php
	$categories = Mage::helper('catalog/category');
	/* @var $helper Mage_Catalog_Helper_Category */
	$categories_collection = $categories->getStoreCategories('name', true, false);	
	$categories_url = Mage::helper('catalog/category');
?>

<?php if($categories_collection->getSize()): ?>
    <dl class="new-product">
        <?php foreach ($categories_collection as $_item): ?>

				<dt><a href="<?php echo $categories_url->getCategoryUrl($_item) ?>"><?php echo $_item->name ?></a></dt>

				<?Php
					$p_collection = $_item->getProductCollection();
					$p_collection->addAttributeToSelect(array('name', 'id', 'price', 'url_key', 'small_image'))
					             ->addAttributeToFilter('status', 1)
								 ->addAttributeToFilter('visibility', 4) //catalog, search
								 ->addAttributeToFilter('sku',array("nlike"=>'%CUS001%'))
								 ->setOrder('entity_id', 'DESC')
								 ->getSelect()->limit( 8 );
								 //->setPageSize(10);

				?>	
				<?php
				/*foreach ($p_collection as $product) {
						echo $product->getName().'<br />';
						echo $product->getSmallImage().'<br />';

						echo Mage::helper('core')->currency($product->getFinalPrice()).'<br />';
					}*/

				?>
				<?php if($p_collection->getSize()): ?>
				<dd>
				<ul class="new-product-ul">
				<?php foreach ($p_collection as $product): ?>
					<li>
					<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(200); ?>" width="200"  alt="<?php echo $product->getName(); ?>" /></a>
						<h3 class="product-name"><a href="<?php echo $product->getProductUrl() ?>" title="<?php echo $product->getName(); ?>"><?php echo $product->getName() ?></a></h3>

					<?php echo $this->getPriceHtml($product, true) ?>
					</li>

				<?php endforeach; ?>
				</ul>
				</dd>
				<?php else: ?>
					<dd>
						<p class="note-msg">
							<?php echo $this->__('There are no %s available.', $this->getItemsTitle()); ?>
						</p>
					</dd>

				<?php endif ?>

        <?php endforeach; ?>
    </dl>
<?php else: ?>
    <p class="note-msg">
        <?php echo $this->__('There are no %s available.', $this->getItemsTitle()); ?>
    </p>
<?php endif ?>

继续阅读