How to add a New Reference or Position in Magento

There is often a need to create a new position in Magento apart from the default one. In Magento we call it References. Now the question is How To Create One ?.

newreferenceblock2-600x561

It’s pretty simple to add new Reference in Magento. Below are the steps on how to do it.

First thing we need to do is Create a New Structural Block.

Step 1 : Name the Structural Block

Open the file layout/page.xml in your active theme folder. Inside you will find lines like:

<block type=”core/text_list” name=”left” as=”left”/>
<block type=”core/text_list” name=”content” as=”content”/>
<block type=”core/text_list” name=”right” as=”right”/>

Let’s mimic this and add a new line somewhere inside the same block tag.

<block type=”core/text_list” name=”newreference” as=”newreference”/>

Now we told Magento that new structural block exists with the name “newreference”. Magento still doesn’t know what to do with it.
Continue reading

How to share custom data on social network site !!!

For Facebook share

<a id="ref_fb" href="http://www.facebook.com/sharer.php?s=100&amp;p[title]=<?php echo $ftitle;?>&amp;p[summary]=<?php echo $fdescription;?>&amp;p[url]=<?php echo urlencode($fshare_url);?>&amp;
p[images][0]=<?php echo $fimage_url;?>" onclick="javascript:window.open(this.href, '', 'menubar=no,toolbar=no,resizable=no,scrollbars=no,height=400,width=600'); return false;">&nbsp;</a>

For Twitter share

<a id="ref_tw" href="http://twitter.com/home?status=<?php echo $ttitle; ?>+<?php echo urlencode($tshare_url);?>" onclick="javascript:window.open(this.href, '', 'menubar=no,toolbar=no,resizable=no,scrollbars=no,height=400,width=600');return false;">&nbsp;</a>
 

For Linkedin share

<a id="ref_lkd" href="http://www.linkedin.com/shareArticle?mini=true&url=<?php echo urlencode($lshare_url);?>&title=<?php echo strip_tags($ltitle); ?>&source=<?php echo urlencode($siteurl);?>"onclick="javascript:window.open(this.href, '', 'menubar=no,toolbar=no,resizable=no,scrollbars=no,height=400,width=600');return false;">&nbsp;</a>

For Google+ share

<a id="ref_gp" href="https://plus.google.com/share?url=<?php echo urlencode($gshare_url);?>"
onclick="javascript:window.open(this.href, '', 'menubar=no,toolbar=no,resizable=no,scrollbars=no,height=400,width=600');return false">&nbsp;</a>
Please define  values  of varibles for better result !!!  

How to validate email id using checkdnsrr() function in PHP

Are you tired of dummy email id’s being used on your website. Like test@test.com, abc@abc.com etc ?

You can use PHP function

checkdnsrr()

It checks whether the dns value is valid or not. Only the email id with valid domain name will be accepted 😉

This is inspired from the original post of one of our Author SNEHAL. Originally posted on his blog.

checkdnsrr() function will take an email address and performs a DNS lookup on the specified host (either a hostname or IP address). You can use this function before sending emails. The function will return an error informing the user that the domain related to email address probably doesn’t exist.

This function can look up the following record types:

bool checkdnsrr (string $host [, string $type = “MX” ] )

Continue reading

How to submit a form using AJAX

This is a Registration.php file

In This file Simple create registration form and submit by using AJAX

<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">
</script>
<script>
$(document).ready(function(){
$('#myForm').on('submit',function(event) {
$.ajax({
url:'success.php',          //target file
data:$(this).serialize(),    //translate data structure and object
type:'POST',
success:function(data){

console.log(data);
$("#success").show();       // Show Success Message==
},
error:function(data){

$("#error").show().fadeOut(5000);   //===Show Error Message====
}
});
event.preventDefault();         //To Avoid Page Refresh and Fire the Event "Click"
});
});
</script>

</head>
<body>
<h2 >Registration Form</h2>

<table align:center>
<form id="myForm" method="POST" action="" >
<tr>
<tr><td>Name :</td><td><input type="text" name="name" required></td></tr>
<tr><td>SarName :</td><td><input type="text" name="sarname" required></td></tr>
<tr><td>Birthday :</td><td><input type="date" name="bday" required></td></tr>
<tr><td>E-mail :</td><td><input type="email" name="email" required></td></tr>
<tr><td>Password :</td><td><input type="password" name="password" required></td></tr>
<tr><td>re-Password :</td><td><input type="password" name="passward" required></td></tr>
<tr><td><button type="submit" name="submit" id="submit">submit</button></td> </tr>
</tr>
<span id="error" style="display:none; color:#F00">Some Error!Please Fill form Properly </span>

<span id="success" style="display:none; color:#0C0">All the records are submitted!</span>
</form>
</table>

<?php ?>
</body>

</html>

Continue reading

How to display blog posts (Fishpig module) with featured images on magento homepage?

When we integrate fishpig with magento we can have one folder
“wordpress” in the template folder.(path:- app\design\frontend\base\default\wordpress).
in that we can create our custom folder like “xyz”.
in that we need to create one .phtml file called “xyz.phtml”.

the followings code returns the post name, post featured image etc…

<?php
 $posts = $this->getPosts() ;
if (count($posts) > 0): 
 foreach($posts as $post): ?>
<img src=" <?php echo $image_url = $post->getFeaturedImage()->getAvailableImage();?>" />
// also call here getAvailableImage(); for  Featured image  plz take <img> tag
<?php
echo  getPermalink(); // Post link
echo $post_date = $post->getPostDate(); // Post date
 echo $post_day = date('l', strtotime($post_date)); // Day of Post
echo $post_title = $post->getPostTitle(); // Post Title
endforeach;
 endif;
?>

Then call this template in home page slide section like,

<?php createBlock('wordpress/sidebar_widget_posts')->
setTemplate('wordpress/xyz/xyz.phtml');
$blog->setPostCount(6);
echo $blog->toHtml();
?>

Custom THANK YOU page in Magento – success.phtml PART-2

In this post we will try to cover up how to get the cart details on Success Page. This is a second part of our post THANK YOU PAGE. If you are directly reading this post we recommend to refer the previous post before going through this.
The link of the previous post is https://universalcoder.wordpress.com/2014/03/20/custom-thank-you-page-in-magento-success-phtml/

thank-you-page

Now lets start how we will get the Cart Summary in Success Page.

1) Goto : app/design/frontend/YOURTHEME/default/template/checkout/success.phtml
I hope you are already on this page as you have already read the first part of this post 😉
2) Here, I am shamelessly pasting the whole code for obtaining Cart detail from my success.phtml. I’ll explain each bit below the code. Continue reading

How to display discount percentage for Special Price in Magento

This post is posted on Saurabh Patel’s Request. He required this thing to be done in Magento.

To display Special Price percentage discount in Magento, you need to do following steps

1) Goto app/design/frontend/YOURTHEME/default/template/catalog/product/price.phtml
2) Basically we need to find the percentage of the difference between the actual price and special price. So first we will obtain both special and actual price of the product using following code

$_actualPrice = $_store->roundPrice($_store->convertPrice($_product->getPrice()));
$_convertedFinalPrice = $_store->roundPrice($_store->convertPrice($_product->getFinalPrice()));

Here Both these prices are already retrived in the file price.phtml

3) To get the discount percentage use the following code

$_discountPercentage = round((($_actualPrice-$_convertedFinalPrice)/$_actualPrice)*100);

Now you got the discount percentage stored in $_discountPercentage variable. Next you need to display this percentage only where Special price is available. To do so you need to find the class “special-price” and under that class you can enter the discount amount percentage.

You can simply call it using echo $_discountPercentage.”%”. You can format it as per your requirement.

Thats it. Please provide your feedback as a comments