Latest News : 亮瞎双眼的那些年!

Magento1.x 首页调用产品数量并进行数量控制

Magento admin 1378 views 0 comments

<?php
$category = Mage::getModel(‘catalog/category’)->load($this->getCategoryId());
$products = Mage::getModel(‘catalog/product’)->getCollection();
Mage::getSingleton(‘cataloginventory/stock’)
->addInStockFilterToCollection($products);
$products->addCategoryFilter($category);
$products->addAttributeToSelect(array(‘name’, ‘thumbnail’, ‘price’,’special_price’)); //feel free to add any other attribues
$products->addAttributeToSort(“entity_id”,”DESC”);
Mage::getSingleton(‘catalog/product_status’)->addVisibleFilterToCollection($products);
Mage::getSingleton(‘catalog/product_visibility’)->addVisibleInCatalogFilterToCollection($products);
//$products->getSelect()->order(‘RAND()’);
$products->addAttributeToSort(“entity_id”,”DESC”);
// $products ->setOrder(‘ordered_qty’, ‘desc’) ;
$products->getSelect()->limit(12);
$_columnCount = 4;
$i=0;
?>
<div class=”category-products”>
<ul class=”products-grid category-products-grid itemgrid itemgrid-adaptive itemgrid-3col single-line-name centered hover-effect equal-height”>
<?php foreach ($products as $_product) : ?>
<li class=”item”>
<?php $_imgSize = 210; ?>

<div class=”product-image-wrapper” style=”max-width:<?php echo $_imgSize; ?>px;”>
<a href=”<?php echo $_product->getProductUrl() ?>” title=”<?php echo $_product->getName(); ?>” class=”product-image”>
<img src=”<?php echo $this->helper(‘catalog/image’)->init($_product, ‘thumbnail’)->resize(275); ?>” alt=”<?php echo $_product->getName(); ?>” id=”product-collection-image-<?php echo $_product->getId(); ?>”/>
</a> </div>

<h2 class=”product-name<?php echo $productNameClasses; ?>”>
<a href=”<?php echo $_product->getProductUrl(); ?>”><?php echo $_product->getName(); ?></a>
</h2>
<div class=”price-box”>
<span class=”regular-price”>

<span class=”price”>

<?php if ( $_product->getSpecialPrice()) {
?>

<p class=”old-price”>

<span class=”price” id=”old-price-1″>
<?php echo Mage::helper(‘core’)->currency($_product->getPrice(),true,false); ?> </span>
</p>
<p class=”special-price”>

<span class=”price” id=”product-price-1″>
<?php echo Mage::helper(‘core’)->currency($_product->getSpecialPrice(),true,false); ?> </span>
</p>
<?
}else{

echo Mage::helper(‘core’)->currency($_product->getPrice(),true,false);

}
?>
</span>
</span>

</div>

<div class=”actions”>
<?php if(!$_product->canConfigure() && $_product->isSaleable()): ?>
<button type=”button” title=”<?php echo Mage::helper(‘core’)->quoteEscape($this->__(‘Add to Cart’)) ?>” class=”button btn-cart” onclick=”setLocation(‘<?php echo $this->helper(‘checkout/cart’)->getAddUrl($_product); ?>’)”><span><span><?php echo $this->__(‘Add to Cart’) ?></span></span></button>
<?php elseif($_product->getStockItem() && $_product->getStockItem()->getIsInStock()): ?>
<a title=”<?php echo $this->__(‘View Details’) ?>” class=”button btn-cart” href=”<?php echo $_product->getProductUrl() ?>”><?php echo $this->__(‘View Details’) ?></a>
<?php else: ?>
<p class=”availability out-of-stock”><span><?php echo $this->__(‘Out of stock’) ?></span></p>
<?php endif; ?>
</div>

</li>
<?php endforeach; ?>
</ul>
</div>

后台控制调用代码

{{block type="core/template" category_id="3" template="catalog/product/list_home.phtml"}}

Please indicate: 无趣的人生也产生有意思的事件 » Magento1.x 首页调用产品数量并进行数量控制

Hi, you must log in to comment !