Friday, July 3, 2009

Magento - Limit Displayed Characters From Product Short Description

Magento Tutorials: Limit displayed characters from Magento Product Short Description

<?php $sdesc = $_product->getShortDescription();
$sdesc = trim($sdesc);
$limit = 40;
if (strlen($sdesc) > $limit) {
$sdesc = substr($sdesc, 0, strrpos(substr($sdesc, 0, $limit), ' '));
}
?>
<?php echo $sdesc."..."; ?>

This script helps you limit characters form Product Short Description.

Tags : Product Short Description, Catalog , view.phtml

Wednesday, June 17, 2009

Magento Installation using Xampp

Magento Tutorials: Magento installation using in Xampp

First to install xampp new version to download http://www.apachefriends.org/en/xampp.html

Open httpd.conf file to Your xampp folder inside ex. C:\xampp\apache\conf\httpd.conf

Search the line of code:

#LoadModule rewrite_module modules/mod_rewrite.so

Remove the comment character #, so that the line as follows:

LoadModule rewrite_module modules/mod_rewrite.so

Open two php.ini files on ex: C:\xampp\apache\bin\php.ini , C:\xampp\php\php.ini

Search the code lines :

;extension=php_curl.dll

;extension=php_mcrypt.dll

;extension=php_mcrypt_filter.dll

;extension=php_mhash.dll

Remove the semicolon ";" so that the lines as follows:

extension=php_curl.dll

extension=php_mcrypt.dll

extension=php_mcrypt_filter.dll

extension=php_mhash.dll

Restart Xampp and Check it localhost in http://127.0.0.1

New version download Magento version and Sample data From download in http://www.magentocommerce.com/download

Download full release magento file and extract magento files

we now move one level higher in the folder and copy magento folder

paste to C:xampp/htdocs/

Installing Magento Sample data

Open phpmyadmin with which we create Magento database.

Goto import tab and choose magento latest sample data sql file which you downloaded Sample data

Then copy catalog folder from Sample data Media folder

paste to C: xampp/htdocs/magento/Media

check it C: xampp/htdocs/magento inside app,skin…. Files, this is ok go to next step

to run installation on magento in localhost in http://127.0.0.1/magento

Last You click Go to frontend and Go to backend, all should be good.

Tags: Xampp, Installation, windows

Wednesday, June 10, 2009

Bestselling Products in Magento

Magento Tutorials: Bestselling Products in Magento

Create new block class that will instantiate the Bestselling products

Create a new file, and directories: app/code/local/Mycompany/Bestsellers/Block/Product/Bestsellers.php

class Mycompany_Bestsellers_Block_Product_Bestsellers extends Mage_Catalog_Block_Product_Abstract
{
public function __construct()
{
parent
::__construct();

$storeId = Mage::app()->getStore()->getId();

$products = Mage::getResourceModel('reports/product_collection')
->addOrderedQty()
->addAttributeToSelect('*')
->setStoreId($storeId)
->addStoreFilter($storeId)
->setOrder('ordered_qty', 'desc');

Mage
::getSingleton('catalog/product_status')->addVisibleFilterToCollection($products);
Mage
::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($products);

$products->setPageSize(5)->setCurPage(1);

$this->setProductCollection($products);
}
}

Create a new config.xml for Bestselling products

Create a new file, and directories: app/code/local/Mycompany/Bestsellers/etc/config.xml

<?xml version="1.0"?>
<config>
<modules>
<Mycompany_Bestsellers>
<version>0.1.0</version>
</Mycompany_Bestsellers>
</modules>
<global>
<resources>
<bestsellers_setup>
<setup>
<module>Mycompany_Bestsellers</module>
</setup>
<connection>
<use>core_setup</use>
</connection>
</bestsellers_setup>
<bestsellers_write>
<connection>
<use>core_write</use>
</connection>
</bestsellers_write>
<bestsellers_read>
<connection>
<use>core_read</use>
</connection>
</bestsellers_read>
</resources>
<blocks>
<catalog>
<rewrite>
<product_bestsellers>
Mycompany_Bestsellers_Block_Product_Bestsellers
</product_bestsellers>
</rewrite>
</catalog>
</blocks>
</global>
</config>

Add new Bestsellers.phtml to your template

app/design/frontend/default/default/template/catalog/product/bestsellers.phtml

<?php $_productCollection=$this->getProductCollection() ?>
<div>Best Selling Products</div>
<?php if(!$_productCollection->count()): ?>
<div class="note-msg">
<?php echo $this->__('There are no products matching the selection.') ?>
</div>
<?php else: ?>
<?php // Grid Mode ?>
<div class="listing-type-grid catalog-listing">
<?php $_collectionSize = $_productCollection->count() ?>
<?php $i=0; foreach ($_productCollection as $_product): ?>
<?php if($i++%2==0): ?>
<ol class="grid-row">
<?php endif; ?>
<li class="item">
<p class="product-image">
<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(135, 135); ?>" width="135" height="135" alt="<?php echo $this->htmlEscape($_product->getName()) ?>" />
</a>
</p>
<h5><a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>"><?php echo $this->htmlEscape($_product->getName()) ?></a></h5>
<p class="add-to">
<?php if ($this->helper('wishlist')->isAllow()) : ?>
<a href="<?php echo $this->helper('wishlist')->getAddUrl($_product) ?>" class="link-cart"><?php echo $this->__('Add to Wishlist') ?></a>
<?php endif; ?>
<?php if($_compareUrl=$this->getAddToCompareUrl($_product)): ?><br/>
<a href="<?php echo $_compareUrl ?>"><?php echo $this->__('Add to Compare') ?></a>
<?php endif; ?>
</p>
<?php echo $this->getPriceHtml($_product, true) ?>
<div class="clear"></div>
<?php if($_product->getRatingSummary()): ?>
<?php echo $this->getReviewsSummaryHtml($_product, 'short') ?>
<?php endif; ?>
<?php if($_product->isSaleable()): ?>
<div class="button_pad" ><button class="form-button" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><?php echo $this->__('Add to Cart') ?></span></button></div>
<?php else: ?>
<div class="out-of-stock"><?php echo $this->__('Out of stock') ?></div>
<?php endif; ?>
</li>
<?php if($i%2==0 || $i==$_collectionSize): ?>
</ol>
<?php endif; ?>
<?php endforeach ?>
<script type="text/javascript">decorateGeneric($$('.grid-row'), 'last', 'odd', 'even']);</script>
</div>
<?php endif; ?>

Activate your module

create new Mycompany_Bestsellers.xml

<?xml version="1.0"?>
<config>
<modules>
<Mycompany_Bestsellers>
<active>true</active>
<codePool>local</codePool>
</Mycompany_Bestsellers>
</modules>
</config>

Add your block to the correct page:

{{block type="catalog/product_bestsellers" name="home.catalog.product.bestsellers" alias="product_bestsellers" template="catalog/product/bestsellers.phtml"}}

then Refresh your cache management.

check it and It's works well.


Tags: Catalog, Bestselling Products, Bestseller Products