Sunday 24 November 2013

Get product attribute on cart page magento

 
Hi to get the product atribute on cart page 
 
place the below code in 
 
in app/design/frontend/default/your_theme/template/checkout/cart/item/default.phtml 
 
<?php 
$_item = $this->getItem();
$_product = $_item->getProduct()->load();
?>
<?php echo $_product->getCustomAttribute(); ?>// place ths where ever you show 
and replace the CustomAttribute  with your attribute code
 
 
thanks 

add arrow to the div through css

Hi to add the css to your div at any position you can folow the below link

http://cssarrowplease.com/

here you will find the live demo and you can customize the css according to your need online.


hope this will help somebody
thanks

Thursday 14 November 2013

check current page is category page or another page in Magento

 
Hi In magento sometime we need to place conditions on content on the basis of page type .
For  that the best way to find the current page type is to check the controller of that page,
Below you can see how we can do this


  <?php $category = Mage::app()->getFrontController()->getRequest()->getControllerName(); // gives current controller name for eg "cart", "category"

you can check it by
 echo  $category ;  and than on the basis of that you can place your condition like below

in this i have check two controllers cart and or category thats why i have use array to check there values .
    $catpage = array("cart", "category");
if(in_array($category, $catpage)){    ;?>       

        <?php } else { ?>

<?php }?>

highlight current category link in magento

Hi with the below peace of code you can highlight the current category link. In this we get first get the current url and than match it with the category url and on the basis of that we will apply our classes  


 <?php $curr =  "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; //full current url
                                    $currcate =  $category->getURL(); // your category url (i have use this  on product list page )
                                    if ($curr == $currcate) {
                                    $class = "active";}else {

                                    $class="nonactive";}
                                    //echo $class;

                                    ?>
                            
on the bais of above match we will apply alss in the anchor tag as below
<a class="<?php echo $class; ?> " href="<?php echo $category->getURL()?>">




Friday 8 November 2013

onclick increment number by 1 javascript

<!DOCTYPE html>
<html>
<head>
<script>
function changeLink()
{
var a = document.getElementById('inc').value;
var b = ++a;

document.getElementById('inc').value= b;
}
</script>
</head>
<body>

<a id="myAnchor"  onclick="changeLink()" href="#">click</a>
<input type="button" id ="inc" value="1">



</body>
</html>

get all categories and subcategories in magento

 
 
<?php 
$_categories = Mage::getBlockSingleton('catalog/navigation'); 
foreach ($_categories->getStoreCategories() as $_category) { 
$category = Mage::getModel('catalog/category'); 
$category->load($_category->getId()); 
$subcategories = explode(',', $category->getChildren()); 
?> 
<dl> 
<dt><?php echo $this->htmlEscape($_category->getName()); ?></dt> 
<dd> 
<ol> 
<?php 
foreach ($subcategories as $subcategoryId) { 
$category->load($subcategoryId); 
echo '<li><a href="' . $category->getURL() . '">' . $category->getName() . '</a></li>'; 
} 
?> 
</ol> 
</dd> 
</dl> 
<?php

} 
?>

Tuesday 5 November 2013

submit multiplr forms on single click

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $("#submitButton").click(function () {
                $.post($("#form1").attr("action"), $("#form1").serialize(),
                  function () {
                      alert('Form 1 submitted');
                  });

                $.post($("#form2").attr("action"), $("#form1").serialize(),
                  function () {
                      alert('Form 2 submitted');
                  });
            });
        });
    </script>
</head>
<body>
    <form id="form1" action="#" method="post">
        <input type="button" id="submitButton" value="Submit" />
    </form>

    <!-- Hidden form -->
    <form id="form2" action="#" method="post">
        <input type="text" id="data1" value="testing1" />
        <input type="text" id="data2" value="testing2" />
    </form>
</body>
</html>

simple jquery increment decrement on click

<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">
</script>
<script>
$(document).ready(function(){
  $("p").click(function(){
    var newf = parseFloat($(inc).val())+1;
$(inc).val(newf);
  });

  $("b").click(function(){
    var newm = parseFloat($(inc).val())-1;
$(inc).val(newm);
  });



});
</script>
</head>
<body>
<p>If you click on me, I will add 1.</p>
<b>If you click on me, will reduce 1 </b>



<input type="text" value="1" id ="inc" name="num"/>
</body>
</html>