Tuesday, February 7, 2012

Add product list on MouseOver on My cart in top link Magento

if you want to display a dropdown list of products in  my cart on MouseOver on 'My Cart' in top menu then follow these easy step:

1.copy the following line of code and save this in file cartlist.phtml  at path
app\design\frontend\base\default\template\catalog\product\

code:
////////////
<?php if(Mage::helper('checkout/cart')->getSummaryCount()>0) { ?>
<div style="display:none;position: relative;left: 650px;width: 200px;top: -70px;" id="vinod">
<div class="block block-cart">
 
    <div class="block-title">
        <strong><span><?php echo $this->__('My Cart') ?></span></strong>
    </div>
    <div class="block-content">
        <?php
        $cartid= Mage::getModel('checkout/cart')->getProductIds();
   
      
            foreach($cartid as $pid)
            {
               $pname= Mage::getModel('catalog/product')->load($pid)->getName();
              ?>
               <p><b><?=$pid?>=<?=$pname?></b></p>
            <?php
               }
 
        ?>
           </div>  
</div>
</div>
<? }?>


//////////////

2. add this xml code in catalog.xml in default scope
app\design\frontend\base\default\layout\
////////////
<reference name="content">
             
          <block type="catalog/product" name="catalog.product.cartlist" template="catalog/product/cartlist.phtml"/>
          </reference>


///////////////////

3. find the following line of code in
app\code\core\Mage\Checkout\Block\ Links.php

//////////////

 public function addCartLink()
    {
      
        $parentBlock = $this->getParentBlock();
        if ($parentBlock && Mage::helper('core')->isModuleOutputEnabled('Mage_Checkout')) {
            $count = $this->getSummaryQty() ? $this->getSummaryQty()
                : $this->helper('checkout/cart')->getSummaryCount();
            if ($count == 1) {
                $text = $this->__('My Cart (%s item)', $count);
            } elseif ($count > 0) {
                $text = $this->__('My Cart (%s items)', $count);
            } else {
                $text = $this->__('My Cart');
            }
           
          
            $parentBlock->removeLinkByUrl($this->getUrl('checkout/cart'));
            $parentBlock->addLink($text, 'checkout/cart', $text, true, array(), 50, null, 'class="top-link-cart"');
        }
        return $this;
    }

/////////////



and replace with 
///////////
 public function addCartLink()
    {
     
        $parentBlock = $this->getParentBlock();
        if ($parentBlock && Mage::helper('core')->isModuleOutputEnabled('Mage_Checkout')) {
            $count = $this->getSummaryQty() ? $this->getSummaryQty()
                : $this->helper('checkout/cart')->getSummaryCount();
            if ($count == 1) {
                $text = $this->__('My Cart (%s item)', $count);
            } elseif ($count > 0) {
                $text = $this->__('My Cart (%s items)', $count);
            } else {
                $text = $this->__('My Cart');
            }
           
          
            $parentBlock->removeLinkByUrl($this->getUrl('checkout/cart'));
            $parentBlock->addLink($text, 'checkout/cart', $text, true, array(), 50, null, 'class="top-link-cart" onMouseOver="$(\'vinod\').toggle();"');
        }
        return $this;
    }
 
/////////


that's it.


Enjoy!!!.....




13 comments:

  1. Hello vinod,
    Its not working.

    Venkat

    ReplyDelete
    Replies
    1. It is working Venkat.....it may be jquery conflict or jquery not include problem...just chekout the source code of html page that div is coming or not..

      Delete
  2. Really Nice script Vinod , I was looking for it.
    Thanks

    ReplyDelete
  3. I'm not sure what I have done wrong. But the div is there. My cart however doesn't toggle on mouse over. When I checkout the source code there is no error whatsoever.
    Any idea? I'm using magento CE 1.6.2.
    Thank you

    ReplyDelete
    Replies
    1. Hi Han K. Hee,

      can you provide me the url where you are using this code ?

      Delete
    2. Hi Vinod,
      Thanks for your reply.
      However, while I was waiting for your reply, I return the files to their original condition in the meantime.
      I applied back to your files setting now.
      You can take a look at my project site at : www.kollap.com
      I wanted it to work like the login box beside my cart link.(only difference will be that login box is onclick not on hover)

      Delete
    3. Hi Han K. Hee,

      As I can see in your project you did not include catalog/product/cartlist.phtml file in the content part i.e. there is some mistake in first 1 & 2 step of my given solution.
      If you want to show cart item on click then please change the line $parentBlock->addLink($text, 'checkout/cart', $text, true, array(), 50, null, 'class="top-link-cart" onMouseOver="$(\'vinod\').toggle();"'); to the $parentBlock->addLink($text, 'checkout/cart', $text, true, array(), 50, null, 'class="top-link-cart" onClick="$(\'#vinod\').toggle();"');

      I think this will help you .....

      Delete
  4. This comment has been removed by the author.

    ReplyDelete
  5. This comment has been removed by the author.

    ReplyDelete
  6. hi vinod,

    it's working fine but when mouseover the page is flickering why?

    ReplyDelete
    Replies
    1. Thanks for your comment. Can you please check the jquery conflict and CSS property of the drop down cart block. I think the CSS property of block may cause of this.

      Delete
  7. This code support for magento 1.9.0.1

    ReplyDelete
    Replies
    1. I didn't try with this version. You can try, I hope it will work.

      Thanks

      Delete