Monthly Archives: April 2012

Magento Belvg

Belvg had launches the new extension which will help the developer to get relief from the pain with already overridden Magento classes (models, routers, blocks, helpers). The extension provides the list of changes, made by other developers, and indicates where rewriting are located.

Just Click on the Link and you can download easily as it is free extension

Hope this will help you!

Magento Hide only particular category from left Navigation

Magneto Show Category on left side as but some time we require to hide particular category or subcategory
so we can remove just open the following file

 

app/design/frontend/yourtheme/default/template/catalog./layer/filter.phtml

after line 36 of this line add the following if condition and add your category name which u want to remove for us we have remove Electronics,Furniture

 

<ol>
<?php foreach ($this->getItems() as $_item): ?>
<?php  if(!in_array($_item->getLabel(),array("Furniture","Electronics"))){?>
    <li>
        <?php if ($_item->getCount() > 0): ?>
        <a href="<?php echo $this->urlEscape($_item->getUrl()) ?>"><?php echo $_item->getLabel() ?></a>
        <?php else: echo $_item->getLabel() ?>
        <?php endif; ?>
        (<?php echo $_item->getCount() ?>)
    </li>
<?  } ?>
<?php endforeach ?>
</ol>

 

and that’s it we get remove the Furniture and Electronics from left navigatin

 

Hope this will help you!

Magento Remove Category from left Navigation

Magento By default shows the Category on the left side navigation but sometime we don’t require to show the category on left side

so easy way to remove just open the following file and

app/design/frontend/default/yourtheme/catalog/layer/view.phtml

at line no 48 of the following file add the following if condition

canShowBlock()): ?>





__(’Shop by’) ?>







getStateHtml() ?>

canShowOptions()): ?>



__(’Browsing Options’) ?>





getFilters() ?>



getItemsCount()): ?>

getName() != “Category”){ ?>

__($_filter->getName()) ?>




getHtml() ?>



















that’s it your category will get removed

Magento increment QTY Box in Cart or View page

Magento had default textbox for Quantity but some time we require to add the qty box  with increment value without entering the value in textbox.We can add the followimg code in cart or view page

1) Add the one new file called jquery.qty.js and enter the following code

 

jQuery(document).ready(function(){
jQuery("div.quantity").append('<input type="button" value="+" id="add1" />').prepend('<input type="button" value="-" id="minus1" />');
        jQuery(".plus").click(function()
        {
            var currentVal = parseInt(jQuery(this).prev(".qty").val());
            if (!currentVal || currentVal=="" || currentVal == "NaN") currentVal = 1;
          jQuery(this).prev(".qty").val(currentVal + 1);

        });
        jQuery(".minus").click(function()
       {
            var currentVal = parseInt(jQuery(this).next(".qty").val());
            if (currentVal == "NaN") currentVal = 1;
            if (currentVal > 1)
            {
                jQuery(this).next(".qty").val(currentVal - 1);
            }
        });

        });

and place as per your theme folder structure

 

2)Add the Following

If you want in cart page open app/design/frontend/default/yourtheme/template/catalog/prdouct/view/addtocart.phtml search for qty code and place div like this

 <div>    
        <input name="cart[<?php echo $_item->getId() ?>][qty]" value="<?php echo $this->getQty() ?>" size="2" title="<?php echo $this->__('Qty') ?>" maxlength="12" />
</div>

 

IF u want in view page open app/design/frontend/default/yourtheme/template/checkout/cart/item/default.phtml search for qty code and place div like this

<div>
<input type="text" name="qty" id="qty" maxlength="12" value="<?php echo $this->getProductDefaultQty() * 1 ?>" title="<?php echo $this->__('Qty') ?>" />
</div>
Just check you will get the incerement box in cart and view page
Hope this will help you!

Magento Can’t able to login in admin

Some time After the installation of magento we can’t able to login in admin and we stuck that we have not installed Properly generically while installing some of the permission is required which is not available and so we need to edit one file

Go to app/code/core/Mage/Core/Model/Session/Abstract/Varien.php file within your magento directory.
For Magento 1.4-1.5 Version
Find the code:

session_set_cookie_params(

$this->getCookie()->getLifetime(),

$this->getCookie()->getPath(),

$this->getCookie()->getDomain(),

$this->getCookie()->isSecure(),

$this->getCookie()->getHttponly()

);

and replace with

session_set_cookie_params(

$this->getCookie()->getLifetime(),

$this->getCookie()->getPath()

//$this->getCookie()->getDomain(),

//$this->getCookie()->isSecure(),

//$this->getCookie()->getHttponly()

);

For Magento < 1.6 Version
Find the code:

$cookieParams = array(

            'lifetime' => $cookie->getLifetime(),

            'path'     => $cookie->getPath(),

            'domain'   => $cookie->getConfigDomain(),

            'secure'   => $cookie->isSecure(),

            'httponly' => $cookie->getHttponly()

        );

and replace with

$cookieParams = array(

            'lifetime' => $cookie->getLifetime(),

            'path'     => $cookie->getPath(),

           // 'domain'   => $cookie->getConfigDomain(),

           // 'secure'   => $cookie->isSecure(),

          // 'httponly' => $cookie->getHttponly()

        );

We have commented few lines
After this save the file.clear the cache and  And try to login into the admin.

Magento Review Raitng layout

Due to some reason we required the rating review layout should look different on list page and different  on view page but as magento had default one file which will work for both in list page and view page
Now  we can easily show different layout of review in List page and  different in view page or any other file
Need to follow this step

Suppose we need to change the Layout for the Rating in list page
1) Search the following code

getReviewsSummaryHtml($_product, false, true)?>

and replace with 

getReviewsSummaryHtml($_product, "listreview", true) ?>

2) Now create the  listreview.phtml under app/design/frontend/yourtheme/review/helaper/summary_listreview.phtml
Here you can add the existing code of the review from app/design/frontend/yourtheme/review/helaper/summary.phtml and change according to the need

and last
3)add the file name under app/code/local/Review/Block/Helper.php

that’s it you will get the layout for list page as you want

Hope this will help you!

Magento get URL Paths

WE can Easily get the URL path from static blocks in CMS, PHP and phtml pages
 To Retrieve URL path in STATIC BLOCK

 To get SKIN URL 
 {{skin url=’images/sampleimage.jpg ‘}}

 To get Media URL 
 {{media url=’/sampleimage.jpg’}}

 To get Store URL 
 {{store url=’mypage.html’}}

 To get Base URL 
 {{base url=’yourstore/mypage.html’}}

 To Retrieve URL path in PHTML Note: In editing PHTML don’t forget to enclode the following code with PHP tag Not secure Skin URL

getSkinUrl('images/sampleimage.jpg') ?>

Secure Skin URL

getSkinUrl('images/ sampleimage.gif', array('_secure'=>true)) ?>

Get Current URL 
 $current_url = Mage::helper(‘core/url’)->getCurrentUrl(); Get Home URL $home_url = Mage::helper(‘core/url’)->getHomeUrl(); 

Get Magento Media URL
 Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK); Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA); 

Get Magento Skin URL 
 Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN);

 Get Magento Store URL
 Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);

 Get Magento Js URL 
 Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_JS);

Magneto get Previous & Next Product Links on Product view Page

It will be easy if you will get the next and previous product from any page instead of going to category or navigation or any other link You can add this code in any of the temaplte file Suppose we are showing in the view.phtml

<?php // Previous and Next product links in product page

$_product = $this->getProduct();

if(!$_product->getCategoryIds())
return; // Don't show Previous and Next if product is not in any category

$cat_ids = $_product->getCategoryIds(); // get all categories where the product is located
$cat = Mage::getModel('catalog/category')->load( $cat_ids[0] ); // load first category, you should enhance this, it works for me

$order = Mage::getStoreConfig('catalog/frontend/default_sort_by');
$direction = 'asc'; // asc or desc

$category_products = $cat->getProductCollection()->addAttributeToSort($order, $direction);
$category_products->addAttributeToFilter('status',1); // 1 or 2
$category_products->addAttributeToFilter('visibility',4); // 1.2.3.4

$cat_prod_ids = $category_products->getAllIds(); // get all products from the category
$_product_id = $_product->getId();

$_pos = array_search($_product_id, $cat_prod_ids); // get position of current product
$_next_pos = $_pos+1;
$_prev_pos = $_pos-1;

// get the next product url
if( isset($cat_prod_ids[$_next_pos]) ) {
$_next_prod = Mage::getModel('catalog/product')->load( $cat_prod_ids[$_next_pos] );
} else {
$_next_prod = Mage::getModel('catalog/product')->load( reset($cat_prod_ids) );
}
// get the previous product url
if( isset($cat_prod_ids[$_prev_pos]) ) {
$_prev_prod = Mage::getModel('catalog/product')->load( $cat_prod_ids[$_prev_pos] );
} else {
$_prev_prod = Mage::getModel('catalog/product')->load( end($cat_prod_ids) );
}
?>

<div>
<?php if($_prev_prod != NULL): ?>
<a href="<?php print $_prev_prod->getUrlPath(); if($search_parameter):?>?search=1<?php endif;?>"><span><?php echo $this->__('PREVIOUS PRODUCT') ?></span></a>
<?php endif; ?>

<?php if($_next_prod != NULL): ?>
<a href="<?php print $_next_prod->getUrlPath(); if($search_parameter):?>?search=1<?php endif;?>"><span><?php echo $this->__('NEXT PRODUCT') ?></span></a>
<?php endif; ?>
</div>

Just Refresh the cache from the admin

Magento change main image to any product picture on mouse over

Magento change main image to any product picture on mouse over Magento eCommerce Product image change on hover: mouseover: Magento have default feature that when u click on the product image it will get opened in new window so now you can show the product image into the main image on mouseover or on mouse

 click just search the code in app/design/frontend/default/yourtheme/catalog/product/view/media.phtml 

<li><a href="#" onclick="popWin('<?php echo $this->getGalleryUrl($_image) ?>', 'gallery', 'width=300,height=300,left=0,top=0,location=no,status=yes,scrollbars=yes,resizable=yes'); return false;" title="<?php echo $this->htmlEscape($_image->getLabel()) ?>"><img src="<?php echo $this->helper('catalog/image')->init($this->getProduct(), 'thumbnail', $_image->getFile())->resize(56); ?>" width="56" height="56" alt="<?php echo $this->htmlEscape($_image->getLabel()) ?>" /></a></li>

 

and repalce with

 

<li><a href="<?php echo $this->helper('catalog/image')->init($this->getProduct(), 'image', $_image->getFile()); ?>" title="<?php echo $this->getName();?>" onmouseover="$('image').src = this.href; return false;" onclick="$('image').src = this.href; return false;"><img src="<?php echo $this->helper('catalog/image')->init($this->getProduct(), 'thumbnail', $_image->getFile())->resize(56); ?>" alt="<?php echo $this->htmlEscape($_image->getLabel()) ?>" title="<?php echo $this->htmlEscape($_image->getLabel()) ?>" /></a></li>

 

this will show the thumbnail image into the main image on mouse over and on mouse click

Magento Newsletter Subscribe Form in Footer or Header

Sometime it may required to add the newslettersubscribe box in Header or Footer.Magento template you would need to go and find the relevant lines in the layout XML files and modify them to show in a new postition. This however was a tedious process; especially when it came to precise positioning on your page.
create a block on the fly and position it precisely in your template files with one line of code.

getLayout()->createBlock('newsletter/subscribe')->setTemplate('newsletter/subscribe.phtml')->toHtml(); ?>