Monthly Archives: December 2009

Add a image silder that change on page refresh

<div class="image_add" align="right">
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
var randomTWD = 0;
var DoIt = 0;
images = new Array;
images[1] = new Image();
images[1].src = "your image";
images[2] = new Image();
images[2].src = "your image";
function TWDpics() {
var imgnum = images.length - 1;
do {
var randnum = Math.random();
randomTWD = Math.round((imgnum - 1) * randnum) + 1;
} while (randomTWD == DoIt);
DoIt = randomTWD;
document.ImageHolder.src = images[DoIt].src;
}
// End -->
</script>
<body onLoad="TWDpics();">
<a  href="your domin"><img  width="320px" height="63px"name="ImageHolder" src="your image" border="0" alt="Change image on load"></a>
</div>
Advertisements

Add a tree like left menu in Magento.

Magento in common has no left menu.
So i edit some core and design code to implement a left tree like menu.

Here i give the example of my code.

Step 1:Edit core code in app/code/core/mage/catalog/Block/Navigation.php and add these code in LeftNav.php in same place

<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/osl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @category   Mage
 * @package    Mage_Catalog
 * @copyright  Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
 * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */


/**
 * Catalog navigation
 *
 * @category   Mage
 * @package    Mage_Catalog
 * @author      Magento Core Team <core@magentocommerce.com>
 */
class Mage_Catalog_Block_LeftNav extends Mage_Core_Block_Template
{
    protected $_categoryInstance = null;

    protected function _construct()
    {
        $this->addData(array(
            'cache_lifetime'    => false,
            'cache_tags'        => array(Mage_Catalog_Model_Category::CACHE_TAG, Mage_Core_Model_Store_Group::CACHE_TAG),
        ));
    }

    /**
     * Retrieve Key for caching block content
     *
     * @return string
     */
    public function getCacheKey()
    {
        return 'CATALOG_NAVIGATION_' . Mage::app()->getStore()->getId()
            . '_' . Mage::getDesign()->getPackageName()
            . '_' . Mage::getDesign()->getTheme('template')
            . '_' . Mage::getSingleton('customer/session')->getCustomerGroupId()
            . '_' . md5($this->getTemplate() . $this->getCurrenCategoryKey());
    }

    public function getCurrenCategoryKey()
    {
        if ($category = Mage::registry('current_category')) {
            return $category->getPath();
        } else {
            return Mage::app()->getStore()->getRootCategoryId();
        }
    }

    /**
     * Get catagories of current store
     *
     * @return Varien_Data_Tree_Node_Collection
     */
    public function getStoreCategories()
    {
        $helper = Mage::helper('catalog/category');
        return $helper->getStoreCategories();
    }

    /**
     * Retrieve child categories of current category
     *
     * @return Varien_Data_Tree_Node_Collection
     */
    public function getCurrentChildCategories()
    {
        $layer = Mage::getSingleton('catalog/layer');
        $category   = $layer->getCurrentCategory();
        /* @var $category Mage_Catalog_Model_Category */
        $categories = $category->getChildrenCategories();
        $productCollection = Mage::getResourceModel('catalog/product_collection');
        $layer->prepareProductCollection($productCollection);
        $productCollection->addCountToCategories($categories);
        return $categories;
    }

    /**
     * Checkin activity of category
     *
     * @param   Varien_Object $category
     * @return  bool
     */
    public function isCategoryActive($category)
    {
        if ($this->getCurrentCategory()) {
            return in_array($category->getId(), $this->getCurrentCategory()->getPathIds());
        }
        return false;
    }

    protected function _getCategoryInstance()
    {
        if (is_null($this->_categoryInstance)) {
            $this->_categoryInstance = Mage::getModel('catalog/category');
        }
        return $this->_categoryInstance;
    }

    /**
     * Get url for category data
     *
     * @param Mage_Catalog_Model_Category $category
     * @return string
     */
    public function getCategoryUrl($category)
    {
        if ($category instanceof Mage_Catalog_Model_Category) {
            $url = $category->getUrl();
        } else {
            $url = $this->_getCategoryInstance()
                ->setData($category->getData())
                ->getUrl();
        }

        return $url;
    }

    /**
     * Enter description here...
     *
     * @param Mage_Catalog_Model_Category $category
     * @param int $level
     * @param boolean $last
     * @return string
     */
    public function drawItem($category, $level=0, $last=false)
    {
        $html = '';
        if (!$category->getIsActive()) {
            return $html;
        }
        if (Mage::helper('catalog/category_flat')->isEnabled()) {
            $children = $category->getChildrenNodes();
            $childrenCount = count($children);
        } else {
            $children = $category->getChildren();
            $childrenCount = $children->count();
        }
        $hasChildren = $children && $childrenCount;
        $html.= '<li';
        if ($hasChildren) {
             //$html.= ' onmouseover="toggleMenu(this,1)" onmouseout="toggleMenu(this,0)"';
			//replace
			$html.= ''; 
        }

       // $html.= ' class="level'.$level;
       // $html.= ' nav-'.str_replace('/', '-', Mage::helper('catalog/category')->getCategoryUrlPath($category->getRequestPath()));
        if ($this->isCategoryActive($category)) {
           // $html.= ' active';
		    $html .='';
        }
        if ($last) {
           // $html .= ' last';
		    $html .='';
        }
        if ($hasChildren) {
            $cnt = 0;
            foreach ($children as $child) {
                if ($child->getIsActive()) {
                    $cnt++;
                }
            }
            if ($cnt > 0) {
              //  $html .= ' parent';
			   //$html .=' current';
			   $html .='';
            }
        }
        $html.= '>'."\n";
        $html.= '<a href="'.$this->getCategoryUrl($category).'"><span>'.$this->htmlEscape($category->getName()).'</span></a>'."\n";

        if ($hasChildren){

            $j = 0;
            $htmlChildren = '';
            foreach ($children as $child) {
                if ($child->getIsActive()) {
                    $htmlChildren.= $this->drawItem($child, $level+1, ++$j >= $cnt);
                }
            }

            if (!empty($htmlChildren)) {
                $html.= '<ul>'."\n"
                        .$htmlChildren
                        .'</ul>';
            }

        }
        $html.= '</li>'."\n";
        return $html;
    }

    /**
     * Enter description here...
     *
     * @return Mage_Catalog_Model_Category
     */
    public function getCurrentCategory()
    {
        if (Mage::getSingleton('catalog/layer')) {
            return Mage::getSingleton('catalog/layer')->getCurrentCategory();
        }
        return false;
    }

    /**
     * Enter description here...
     *
     * @return string
     */
    public function getCurrentCategoryPath()
    {
        if ($this->getCurrentCategory()) {
            return explode(',', $this->getCurrentCategory()->getPathInStore());
        }
        return array();
    }

    /**
     * Enter description here...
     *
     * @param Mage_Catalog_Model_Category $category
     * @return string
     */
    public function drawOpenCategoryItem($category) {
        $html = '';
        if (!$category->getIsActive()) {
            return $html;
        }

        $html.= '<li';

        if ($this->isCategoryActive($category)) {
            $html.= ' class="active"';
        }

        $html.= '>'."\n";
        $html.= '<a href="'.$this->getCategoryUrl($category).'"><span>'.$this->htmlEscape($category->getName()).'</span></a>'."\n";

        if (in_array($category->getId(), $this->getCurrentCategoryPath())){
            $children = $category->getChildren();
            $hasChildren = $children && $children->count();

            if ($hasChildren) {
                $htmlChildren = '';
                foreach ($children as $child) {
                    $htmlChildren.= $this->drawOpenCategoryItem($child);
                }

                if (!empty($htmlChildren)) {
                    $html.= '<ul>'."\n"
                            .$htmlChildren
                            .'</ul>';
                }
            }
        }
        $html.= '</li>'."\n";
        return $html;
    }

}

Step 2.:: Add a new .phtml file in app\design\frontend\default\default\template\catalog\navigation\left_close.phtml and add this code here


<div class="box layered-nav">
  <div class="head">
    <h3><?php echo $this->__('Browse By') ?></h3>
  </div>
  <div id="Main_div"> <span> </span>
    <div>
      <h4 style="padding-left:5px; color:#E38048">Category Navigation:</h4 >
    <ul id="treemenu1" class="treeview">
      <?php foreach ($this->getStoreCategories() as $_category): ?>
      <?php echo $this->drawItem($_category) ?>
      <?php endforeach ?>
    </ul>
  </div>
  <?php echo $this->getChildHtml('topLeftLinks') ?> </div>


<script type="text/javascript">

//ddtreemenu.createTree(treeid, enablepersist, opt_persist_in_days (default is 1))

ddtreemenu.createTree("treemenu1", true)
//ddtreemenu.createTree("treemenu2", false)

</script>

Step 3: Edit your \app\design\frontend\default\default\layout\page.xml

/**add the close.js file in js/Leftclose folder*/
<action method="addJs"><script>Leftclose/close.js</script></action>

/**add the close.css file in skin/frontend/default/default/Leftclose folder*/
<action method="addCss"><stylesheet>css/Leftclose/close.css</stylesheet></action>

step 4: Add this code in close.css file in \skin\frontend\default\default\css\Leftclose


.treeview ul{ /*CSS for Simple Tree Menu*/
margin: 0;
padding: 0;
}

.treeview li{ /*Style for LI elements in general (excludes an LI that contains sub listslist.gif)*/
background: /*white*/ url('http://yourdominaddress/skin/frontend/default/default/images/join.gif') no-repeat left center;
list-style-type: none;
padding-left: 22px;
margin-bottom: 3px;
}

.treeview li a 
{
	color:#A14945;
	font-family:Arial;
	font-weight:bold;
	text-decoration:none;
	font-size:9pt;
}


.treeview li a:hover
{
	color:#D96708;
	font-family:Arial;
	font-weight:bold;
	text-decoration:none;
	font-size:9pt;
}



.treeview li.submenu{ /* Style for LI that contains sub lists (other ULs).nolines_minus.gif   closed.gif*/
background: /*white*/ url('http://yourdomineaddess/skin/frontend/default/default/images/nolines_plus.gif') no-repeat left 1px;
cursor: hand !important;
cursor: pointer !important;
}


.treeview li.submenu ul{ /*Style for ULs that are children of LIs (submenu) */
display: none; /*Hide them by default. Don't delete. */
}

.treeview .submenu ul li{ /*Style for LIs of ULs that are children of LIs (submenu) */
cursor: default;
}


.treeview .submenu ul li a
{
	color:#2A8BC2;
	font-family:Arial;
	font-weight:normal;
	text-decoration:none;
	font-size:8pt;


}

.treeview .submenu ul li a:hover
{
	color:#203548;
	font-family:Arial;
	font-weight:normal;
	text-decoration:none;
	font-size:8pt;


}


Step 5: add this close.js file in js\Leftclose


var persisteduls=new Object()
var ddtreemenu=new Object()

ddtreemenu.closefolder="http://yourdomineaddessskin/frontend/default/default/images/nolines_plus.gif" //closed.gifset image path to "closed" folder image
ddtreemenu.openfolder="http://yourdomineaddess/skin/frontend/default/default/images/nolines_minus.gif" //open.gifset image path to "open" folder image

//////////No need to edit beyond here///////////////////////////

ddtreemenu.createTree=function(treeid, enablepersist, persistdays){
var ultags=document.getElementById(treeid).getElementsByTagName("ul")
if (typeof persisteduls[treeid]=="undefined")
persisteduls[treeid]=(enablepersist==true && ddtreemenu.getCookie(treeid)!="")? ddtreemenu.getCookie(treeid).split(",") : ""
for (var i=0; i<ultags.length; i++)
ddtreemenu.buildSubTree(treeid, ultags[i], i)
if (enablepersist==true){ //if enable persist feature
var durationdays=(typeof persistdays=="undefined")? 1 : parseInt(persistdays)
ddtreemenu.dotask(window, function(){ddtreemenu.rememberstate(treeid, durationdays)}, "unload") //save opened UL indexes on body unload
}
}

ddtreemenu.buildSubTree=function(treeid, ulelement, index){
ulelement.parentNode.className="submenu"
if (typeof persisteduls[treeid]=="object"){ //if cookie exists (persisteduls[treeid] is an array versus "" string)
if (ddtreemenu.searcharray(persisteduls[treeid], index)){
ulelement.setAttribute("rel", "open")
ulelement.style.display="block"
ulelement.parentNode.style.backgroundImage="url("+ddtreemenu.openfolder+")"
}
else
ulelement.setAttribute("rel", "closed")
} //end cookie persist code
else if (ulelement.getAttribute("rel")==null || ulelement.getAttribute("rel")==false) //if no cookie and UL has NO rel attribute explicted added by user
ulelement.setAttribute("rel", "closed")
else if (ulelement.getAttribute("rel")=="open") //else if no cookie and this UL has an explicit rel value of "open"
ddtreemenu.expandSubTree(treeid, ulelement) //expand this UL plus all parent ULs (so the most inner UL is revealed!)
ulelement.parentNode.onclick=function(e){
var submenu=this.getElementsByTagName("ul")[0]
if (submenu.getAttribute("rel")=="closed"){
submenu.style.display="block"
submenu.setAttribute("rel", "open")
ulelement.parentNode.style.backgroundImage="url("+ddtreemenu.openfolder+")"
}
else if (submenu.getAttribute("rel")=="open"){
submenu.style.display="none"
submenu.setAttribute("rel", "closed")
ulelement.parentNode.style.backgroundImage="url("+ddtreemenu.closefolder+")"
}
ddtreemenu.preventpropagate(e)
}
ulelement.onclick=function(e){
ddtreemenu.preventpropagate(e)
}
}

ddtreemenu.expandSubTree=function(treeid, ulelement){ //expand a UL element and any of its parent ULs
var rootnode=document.getElementById(treeid)
var currentnode=ulelement
currentnode.style.display="block"
currentnode.parentNode.style.backgroundImage="url("+ddtreemenu.openfolder+")"
while (currentnode!=rootnode){
if (currentnode.tagName=="UL"){ //if parent node is a UL, expand it too
currentnode.style.display="block"
currentnode.setAttribute("rel", "open") //indicate it's open
currentnode.parentNode.style.backgroundImage="url("+ddtreemenu.openfolder+")"
}
currentnode=currentnode.parentNode
}
}

ddtreemenu.flatten=function(treeid, action){ //expand or contract all UL elements
var ultags=document.getElementById(treeid).getElementsByTagName("ul")
for (var i=0; i<ultags.length; i++){
ultags[i].style.display=(action=="expand")? "block" : "none"
var relvalue=(action=="expand")? "open" : "closed"
ultags[i].setAttribute("rel", relvalue)
ultags[i].parentNode.style.backgroundImage=(action=="expand")? "url("+ddtreemenu.openfolder+")" : "url("+ddtreemenu.closefolder+")"
}
}

ddtreemenu.rememberstate=function(treeid, durationdays){ //store index of opened ULs relative to other ULs in Tree into cookie
var ultags=document.getElementById(treeid).getElementsByTagName("ul")
var openuls=new Array()
for (var i=0; i<ultags.length; i++){
if (ultags[i].getAttribute("rel")=="open")
openuls[openuls.length]=i //save the index of the opened UL (relative to the entire list of ULs) as an array element
}
if (openuls.length==0) //if there are no opened ULs to save/persist
openuls[0]="none open" //set array value to string to simply indicate all ULs should persist with state being closed
ddtreemenu.setCookie(treeid, openuls.join(","), durationdays) //populate cookie with value treeid=1,2,3 etc (where 1,2... are the indexes of the opened ULs)
}

////A few utility functions below//////////////////////

ddtreemenu.getCookie=function(Name){ //get cookie value
var re=new RegExp(Name+"=[^;]+", "i"); //construct RE to search for target name/value pair
if (document.cookie.match(re)) //if cookie found
return document.cookie.match(re)[0].split("=")[1] //return its value
return ""
}

ddtreemenu.setCookie=function(name, value, days){ //set cookei value
var expireDate = new Date()
//set "expstring" to either future or past date, to set or delete cookie, respectively
var expstring=expireDate.setDate(expireDate.getDate()+parseInt(days))
document.cookie = name+"="+value+"; expires="+expireDate.toGMTString()+"; path=/";
}

ddtreemenu.searcharray=function(thearray, value){ //searches an array for the entered value. If found, delete value from array
var isfound=false
for (var i=0; i<thearray.length; i++){
if (thearray[i]==value){
isfound=true
thearray.shift() //delete this element from array for efficiency sake
break
}
}
return isfound
}

ddtreemenu.preventpropagate=function(e){ //prevent action from bubbling upwards
if (typeof e!="undefined")
e.stopPropagation()
else
event.cancelBubble=true
}

ddtreemenu.dotask=function(target, functionref, tasktype){ //assign a function to execute to an event handler (ie: onunload)
var tasktype=(window.addEventListener)? tasktype : "on"+tasktype
if (target.addEventListener)
target.addEventListener(tasktype, functionref, false)
else if (target.attachEvent)
target.attachEvent(tasktype, functionref)
}

Finally You must upload those images properly to find any success.
nolines_plus.gif
nolines_minus.gif
join.gif

Change PHPBB footer Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group !!

Go to your cache/tpl_prosilver_overall_footer.html.php
then find out these code and replace what you want

Add a Youtube in your site in magento

It pervades the most easy work
just go to the added youtube site and copy the Embed link and save it


Add a image slider banner in magento home page

Image slider is a very interesting in magento. We can implement from Admin->CMS pages in home page and add these code where you want to rotated the image after a while

 <!--Image Slider Start-->
	
	<div align="center">
<script type="text/javascript">

var image1=new Image()
image1.src="{{skin url=images/banner_1.jpg}}"
var image2=new Image()
image2.src="{{skin url=images/banner_2.jpg}}"
var image3=new Image()
image3.src="{{skin url=images/banner_3.jpg}}"

</script>
<a href="http://##">
<img src="{{skin url=images/banner_1.jpg}}" border="2" name="slide" width="890" height="277" /></a>
<script>

//variable that will increment through the images
var step=1
function slideit(){
//if browser does not support the image object, exit.
if (!document.images)
return
document.images.slide.src=eval("image"+step+".src")
if (step<3)
step++
else
step=1
//call function "slideit()" every 2.5 seconds
setTimeout("slideit()",5000)
}
slideit()

</script>

</div>
<!--Image Slider End-->

Add a new jQuery Top menu !!

The default drop down Navigation (known as topMenu) in Magento is not accessible because it uses:


onmouseover="toggleMenu(this,1)" onmouseout="toggleMenu(this,0)"

That means if you add a

a:focus

to your style sheet, the tab navigation will only work for the top level menu and when JS is turned off, the dropdown stops working.

The script controls the above code is in the js/varien/menu.js

With a few modifications, and adapting the jQuery Superfish script, we can improve Magento Category Menu to a fully accessible, keyboard tab-able dropdown menu; what’s more beautiful is that the dropdown will continue working when JS is turned off.

Step 1: Download Superfish Script

First, go download the Superfish Script and jQuery 1.2.6; you may also want to download hoverIntent plugin that can enhance the menu hover behaviour.

Well! After downloading the files, you know how the routine works right? Yes, go place the scripts to js/jquery/ folder and CSS files to skin/frontend/default/yourtheme/css, then add the links to the page.xml and remove the



<action method="addJs"><script>varien/menu.js</script></action>

and remove “iehover fix script” too because we don’t need it anymore:



<action method="addItem"><type>js</type><name>varien/iehover-fix.js</name><params/><if>lt IE 7</if></action>

I have briefly explained how to implement the jQuery noConflict in other jQuery’s articles, so that jQuery code can co-exist with Prototype Script that comes with Magento. Also, this article in the Magento Wiki posted by a Magento community member, laurent, is a bulletproof method using jQuery in Magento.

In this example, I will focus on the ‘Navbar style’ that shows a nice horizontal navigation bar for the second level of the Category Menu. If you’re going to do the same, remember to download the

superfish-navbar.css

Step 2: Modify the Navigation.php

The file is located at code/core/Mage/Catalog/Block/Navigation.php. For Magento upgrade compatibility’s sake, I prefer to make a custom file for Navigation.php, but I have yet figured how to correctly do it yet; so here we go, just go ahead making a few changes in the Navigation file instead.

In line 153, replace this line of code:


$html.= ' onmouseover="toggleMenu(this,1)" onmouseout="toggleMenu(this,0)"'; 

//to

$html.= ''; 

My test shows that Superfish script works well without removing the above code, however it disables the navbar completely. Though I have not tested it on the Superfish’s Basic and Vertical Style yet, but I believe it affects only Navbar because the third level dropdown menu works with the above code intact, therefor I think you can safely skip the Step 2 if you use Basic or Vertical Style.

Scroll down to line 172, add a ‘current’ class next to the “parent”:

Further testing shows that ‘current’ class is not necessary in below code as it creates a ‘current’ state for the menu when we are at CMS page. Instead, we can utilize the ‘active’ class and change ‘current’ to ‘active’ in the pathClass at Step 3.

$html .= ' parent  <del datetime="2009-12-18T20:04:22+00:00">current</del>';

Step 3: Edit template/catalog/navigation/top.phtml
Change

<ul id="nav">

//to

<ul class="sf-menu sf-navbar">

and add the following script in the file.

jQuery(function(){
jQuery(‘ul.sf-menu’).superfish({
pathClass: ‘current’
});
});

[/source

Step 4: Edit the superfish.css

It’s almost done! All you need is edit the two superfish style sheets to match your layout.

Power By”lsd”.

Add new folder basic store

Magento is much popular for it’s multiple store management.
For creating a folder basic store go to your root folder and create a folder “example” and then copy index.php and .htaccess to it
Now search this code from index.php

$mageFilename = 'app/Mage.php';
/**and**/
umask(0);
Mage::run();

Then replace this code

$mageFilename = '../app/Mage.php';
umask(0);
Mage::run('example','website');

First lines find the path of Mage which is default like main website.
and third line will find out the newly created website. Here the most important things to keep mind that the website name must be same as the folder name.

Now Go to systm->manage store
and then click “create website” from right top corner.
then fill up the information but u must remain that the code name must be same as the folder name.
Then click “create store” from the right corner to create a store and also same procedure to create a view.

%d bloggers like this: