Thursday 31 January 2013

skip entry if already exist Mysql

Hi we can easily do this with the use of single parameter  ignore
 after insert

like

$insert1= mysql_query("INSERT IGNORE INTO your_table_name(your column name,..) VALUES('your values')",$conn1);

this will help you to skip a entry if already exist in table and continue after that with other entries

.htaacess file not visible in magento folder

Hi i was doing my magento project with multi store setup, in which i need to copy the .htacess file to new folder but i was amaze it was not present there
after so long i found the reason. in my folder the option for show hidden files was disable 

so for displaying the files you must go to

view-> and click on show hidden files

and you will able tyo see all hidden files with in that folder

Friday 18 January 2013

Print star with php using loops

  
You can print any shape with php like i have create a simple star shape shown below by using loops




<?php $nbsp = "*";
      $a = 100;
      $b = 0 ;
       $e = 10 ;
      for($i=0; $i<=10;$i++){ ?>
    <div ><div style = "text-align:center;width:<?php echo $a++ ;?>px;"><?php echo str_repeat($nbsp,$b++) ;?></div></div>
     <?php } ?>
<?php
           for($i=0; $i<=10;$i++){ ?>
    <div ><div style = "text-align:center;width:<?php echo $a++ ;?>px;"><?php echo str_repeat($nbsp,$e--) ;?></div></div>
     <?php } ?>

Tuesday 15 January 2013

Simple javascritp toggle or hide/show on click

Hi this is the simplest JavaScript toggle function to use on click


<script type="text/javascript">
                function toggle(element) {
              document.getElementById(element).style.display = (document.getElementById(element).style.display == "none") ? "" : "none";
   }

  // function toggle1(element) {
              //document.getElementById(element).style.display = "none";
  // }
    </script>


<div id="secret" style="display: none;">
         <!--content to show on click -->
             <div>put your content here which should be show on click</div>
           <!--/ontent to show on click -->
 </div>


//here is the li where i have use the toggle function
 <li><a  href="javascript:toggle('secret')" >click here to toggle or hide/show </a></li>

JUST COPY THE WHOLE CODE AND PLACE IN YOUR EDITOR TO GET IT WORK

Get product quantity in magento

with this code you can get the product quantity of a product           

   
 $qty = Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty();

echo   $qty ;

You can use this quantity also to show almost gone or soldout image for a product on category or product view page.

need to place in condition like this

<?php if($qty<10){ ?>
  show almost gone image...
    <?php }elseif ($qty<1) {?>
       show soldout image.............
    <?php } ?>

Monday 14 January 2013

Get custom attribute value in magento admin orders

with this code you can get any custom attribute value in magento admin order section , you can show only in admin or in frontend depends upon your need
   

 <div style="color: black; font-size: 14px; font-weight: bold;">proviser <span><?php $product = Mage::getModel('catalog/product')->loadByAttribute('sku', $_item->getSku(), array('provider')); echo $product->getprovider(); ?>  </span>  </div>

in above code just replace your attribute code which you specify in admin for that like for my case i use "provider "
just replace provider with your attribute code and place this in your 

/public_html/app/design/adminhtml/default/default/template/sales/items/column/name.phtml file   

Show custom error messages on cart page

Hi in this article i will try to tell you all about how to show custom error messages or popups on cartpage

in the below folder
app/code/core/Mage/Checkout/controllers/CartController.php

near about line 537 you will find code something like this

 else {
                    $this->_getSession()->addError(
                        $this->__('Coupon code "%s" is not valid.', Mage::helper('core')->htmlEscape($couponCode))
                    );
                }




which contains a error message for wrong coupon code apply

which i have change to

else {
                    $this->_getSession()->addError(
               
                        $this->__('Coupon code "%s" is not valid.', Mage::helper('core')->htmlEscape($couponCode))
                    );
                    $myValue = 'Hello World';
                   Mage::getSingleton('customer/session')->setMyvalue($myValue);
                                              
                }



in this i have make use of magento sessions , i have set a session as setMyvalue
for the wrong code apply and than check the value of this in cart file

cart file path = under your theme /template/checkout/cart.phtm
i have retrieve the session value something like

 <?php $myValue=  Mage::getSingleton('customer/session')->getMyvalue(); ?> 
<?php if ($myValue!= ''){ ?>
do something:: you can do anything here like show your html ,js popups.....
<?php } else {?>
do somethindo something:: you can do anything here like show your html ,js popups.....
<?php }?>  

thats it ......


Get store code in Magento

$storeCode = Mage::app()->getStore()->getCode();
echo $storeCode;

Thursday 10 January 2013

Get all cms pages in header dynamically Magento

  Place this code in header file below topcontainer

  <?php $collection = Mage::getModel('cms/page')->getCollection()->addStoreFilter(Mage::app()->getStore()->getId());?>
<?php  $collection->getSelect()
->where('is_active = 1'); ?>
<ul id="nav">
<?php foreach ($collection as $page): ?>
<?php $PageData = $page->getData(); ?>
<?php// print_r($PageData);?>
<?php if($PageData['identifier']!='no-route' && $PageData['identifier']!='enable-cookies' && $PageData['identifier']!='home2') { ?>
<li>
<a href="/magento/index.php/<?php echo $PageData['identifier']?>"><span><?php echo $PageData['title'] ?></span></a>
</li>
<?php } ?>
<?php endforeach; ?>
</ul>


Note change this part of code "/magento/index.php/" according to your domain 

SIMPLE JAVASCRIPT CALCULATOR CODE

<!-- Opening a HTML Form.
Number 1: Number 2: Get Result:
-->
<script language="javascript" type="text/javascript"> 
function multiply(){ 
a=Number(document.calculator.number1.value); 
b=Number(document.calculator.number2.value); 
c=a*b; 
document.calculator.total.value=c; 


function addition(){ 
a=Number(document.calculator.number1.value); 
b=Number(document.calculator.number2.value); 
c=a+b; 
document.calculator.total.value=c; 


function subtraction(){ 
a=Number(document.calculator.number1.value); 
b=Number(document.calculator.number2.value); 
c=a-b; 
document.calculator.total.value=c; 


function division(){ 
a=Number(document.calculator.number1.value); 
b=Number(document.calculator.number2.value); 
c=a/b; 
document.calculator.total.value=c; 


function modulus(){ 
a=Number(document.calculator.number1.value); 
b=Number(document.calculator.number2.value); 
c=a%b; 
document.calculator.total.value=c; 

</script> 
 
</head> 
 
<body> 
 
<!-- Opening a HTML Form. -->  
<form name="calculator"> 
 
<!-- Here user will enter 1st number. -->  
Number 1: <input type="text" name="number1">  
  
 
<!-- Here user will enter 2nd number. -->  
Number 2: <input type="text" name="number2">  
 
 
<!-- Here result will be displayed. -->  
Get Result: <input type="text" name="total">  
 
 
<!-- Here respective button when clicked, calls only respective artimetic function. -->  
<input type="button" value="ADD" onclick="javascript:addition();"> 
<input type="button" value="SUB" onclick="javascript:subtraction();"> 
<input type="button" value="MUL" onclick="javascript:multiply();"> 
<input type="button" value="DIV" onclick="javascript:division();"> 
<input type="button" value="MOD" onclick="javascript:modulus();"> 
 
</form> 
 
</body> 
</html> 

Wednesday 9 January 2013

code to show category images on custom phtml files and link to their category pages

<?php

 $root_category = Mage::getModel('catalog/category')->load(2); // Put your root category ID here. like 2
$subcategories = $root_category->getChildren();
foreach(explode(',',$subcategories) as $subcategory) {
$category = Mage::getModel('catalog/category')->load($subcategory);
echo'<pre>';
//print_r($category);
echo  $category->getImageUrl(); //place this url in your image tag to show the image

  }

  ?>