Monthly Archives: January 2014

Magento New arrival product

Magento New arrival product

Create newarrival.phtml file and put it here :

app/design/frontend/yourtheme/template/catalog/product/newarrival.phtml

<?php
$storeId = Mage::app()->getStore()->getId();
$collection =  Mage::getResourceModel(‘catalog/product_collection’)
->addAttributeToSelect(‘*’) // select all attributes
->setStoreId($storeId)
->addStoreFilter($storeId)
->addAttributeToSort(‘entity_id’, ‘DESC’) // sorting
->addAttributeToFilter(‘status’, array(‘eq’ => Mage_Catalog_Model_Product_Status::STATUS_ENABLED))// status
->setPageSize(80); // for limit

?>

<?php if(!$collection->count()): ?>
<p><?php echo $this->__(‘There are no products matching the selection.’) ?></p>
<?php else: ?>
<div style=”margin:0 15px;”>
<ul id=”newarrival”>
<?php // Grid Mode ?>
<?php $_collectionSize = $collection->count() ?>
<?php $_columnCount = $this->getColumnCount(); ?>
<?php $i=0;
foreach ($collection as $_product):
//$obj = Mage::getModel(‘catalog/product’);
//$productid = $product[‘entity_id’];
//$_product = $obj->load($productid);
?>
<?php if ($i++%$_columnCount==0): ?>
<input type=”hidden” id=”prd” value=”<?php print  Mage::getSingleton(‘core/session’)->getMyValue(); ?>”  />
<li style=”margin-right:5px;”>
<a href=”<?php echo $_product->getProductUrl() ?>” title=”<?php echo $this->htmlEscape($this->getImageLabel($_product, ‘small_image’)) ?>”><img src=”<?php echo $this->helper(‘catalog/image’)->init($_product, ‘small_image’)->resize(150,150); ?>” width=”150″ height=”150″ alt=”<?php echo $this->htmlEscape($this->getImageLabel($_product, ‘small_image’))?>” /><span>&nbsp;</span></a>
<h2><?php //print Mage::getSingleton(‘core/session’)->getMyValue(); ?><a href=”<?php echo $_product->getProductUrl() ?>” title=”<?php echo $this->htmlEscape($_product->getName()) ?>”><?php echo $this->htmlEscape(substr($_product->getName(),0,20)) ?></a></h2>
</li>
<?php endif ?>
<?php
endforeach ?>
</ul>
</div>
<!–   <script type=”text/javascript”>decorateGeneric($$(‘ul.tabs-products-grid’), [‘odd’,’even’,’first’,’last’])</script>–>
<?php endif; ?>

Now put this line where you want to view best selling products..

you can use through block or through XML also

{{block type=”catalog/product_popular” template=”catalog/product/newarrival.phtml”}}

Magento Best Selling or Top Selling Product

Magento Best Selling or Top Selling Product

Here, we have written article about How to display Best Selling or Top Selling Product in Magento?. To show Best selling or Top selling Product at Home page. So that Best products should come on home page.

For that follow the following steps:

Create a Bestseller.php file and put it here :
app/code/local/Mage/Catalog/Block/Product/Bestseller.php

class Mage_Catalog_Block_Product_Bestseller extends Mage_Catalog_Block_Product_Abstract{
public function __construct(){
parent::__construct();
$storeId = Mage::app()->getStore()->getId();
$products = Mage::getResourceModel(‘reports/product_collection’)
->addOrderedQty()
->addAttributeToSelect(‘id’)
->addAttributeToSelect(array(‘name’, ‘price’, ‘small_image’))
->setStoreId($storeId)
->addStoreFilter($storeId)
->setOrder(‘ordered_qty’, ‘desc’); // most best sellers on top
Mage::getSingleton(‘catalog/product_status’)->addVisibleFilterToCollection($products);
Mage::getSingleton(‘catalog/product_visibility’)->addVisibleInCatalogFilterToCollection($products);
$products->setPageSize(3)->setCurPage(1);
$this->setProductCollection($products);
}
}

Create bestseller.phtml file and put it here :

app/design/frontend/yourtheme/template/catalog/product/bestseller.phtml

<?php

$_products = $this->getProductCollection();
Mage::getSingleton(‘cataloginventory/stock’)->addInStockFilterToCollection($_products); // for qty stock check

for print Query

//echo $_products->getSelect();
//print $_products->getSize();

if ($_products->getSize()): : ?>
<div>
<?php $i=0; foreach ($_products->getItems() as $_product): ?>
<?php if ($i>5): continue; endif; ?>
<div>
<div>
<a href=”<?php echo $_product->getProductUrl() ?>” title=”<?php echo $this->htmlEscape($_product->getName()) ?>”>
<img src=”<?php echo $this->helper(‘catalog/image’)->init($_product, ‘small_image’)->resize(65,65); ?>” alt=”<?php echo $this->htmlEscape($_product->getName()) ?>”/>
</a>
<?php echo $_product->getDescription(); //also getShortDescription ?>
</div>
<div>
<p><a href=”<?php echo $_product->getProductUrl() ?>” title=”<?php echo $this->htmlEscape($_product->getName()) ?>)”><?php echo $_product->getName() ?></a></p>
<?php //echo $this->helper(‘review/product’)->getSummaryHtml($_product, ‘short’) //product review link ?>
<?php echo $this->getReviewsSummaryHtml($_product, false, true)?>
<?php //echo $this->helper(‘catalog/product’)->getPriceHtml($_product) ?>
<?php echo $this->getPriceHtml($_product) ?>
<?php echo $_product->getProductId(); ?>
<?php if($_product->getevent_date()) {echo $_product->getevent_date();} ?>
</div>
</div>
<?php $i++; endforeach; ?>
<?php for($i;$i%5!=0;$i++): ?>
<?php endfor ?>
</div>
<?php endif; ?>

Now put this line where you want to view best selling products..

you can use through block or through XML also

{{block type=”catalog/product_bestseller” template=”catalog/product/bestseller.phtml”}}