Magento - 从特定类别获取产品

时间:2013-05-02 21:10:00

标签: php magento

我目前正在使用以下代码以随机顺序显示四种产品。它有效,但我想将结果限制为特定类别或类别数组。我将如何实施此更改?

谢谢!

<?php $products = Mage::getModel('catalog/product')->getCollection();
  $products->addAttributeToSelect(array('name', 'thumbnail', 'price')); //feel free to add any other attribues you need.
  Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($products);
  Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($products); 
  $products->getSelect()->order('RAND()');
  $products->getSelect()->limit(4);
  foreach ($products as $product)  : ?>
    <div class="three columns">
      <div class="product_container ">
        <div class="feat_prod_cont">
          <h4 class="feature_product_title"><a href="<?php echo $product->getProductUrl()?>"><?php echo $product->getName()?></a></h4>
          <a href="<?php echo $product->getProductUrl()?>"><img class="thumbnail" src="<?php echo Mage::helper('catalog/image')->init($product, 'thumbnail')->resize(93, 100)?>" alt=" "></a>
          <div class="prod_details_featured">
            <h3 class="price">$199.99</h3>
            Free Shipping Free Stove
          </div>
          <div class="buy_btn"><a href="<?php echo Mage::helper('checkout/cart')->getAddUrl($product); ?>">ADD TO CART</a></div>
        </div>
      </div>
    </div>
<?php endforeach; ?>

0 个答案:

没有答案