Thursday 16 October 2014

how to make magento webpage available only for registered users

paste below code in header part :- 



<?php $myStatus = Mage::getSingleton('customer/session')->isLoggedIn() ?>
<?php if(!$myStatus): ?>

<style type="text/css">
.blankdiv{background-color:#000;
position:fixed;
z-index: 9001;
top:0px; height:100%;
left:0px;
width:100%; opacity: 0.65;
filter:alpha(opacity=65);}


#popupform1{height: 100%;
    left: 0;
    padding: 15px;
    position: fixed;
    top: 0;
    width:97%;
    z-index: 10001;
    }
   
#popupform1 .applyform{position:relative; overflow:auto;
background-color:#fff;
width:500px;
height:500px;  margin:5% auto auto auto;
z-index: 9002; padding:10px; border:10px solid #7F3814; }


#pclose{background-image: url("http://www.americanpowergear.com/close.png");
    background-position: left top;
    background-repeat: no-repeat;
    cursor: pointer;
    height: 25px;
    margin: 5% auto -6%;
    position: relative;
    right: -348px;
    text-indent: -9999px;
    top: 0;
    width: 25px;
    z-index: 9999;}
</style>







 
            
<div id="popupform1" style="display:block" width="500" height="500">
<div class="blankdiv" style="opacity:1!important; background-color: #FFFFFF;"></div>

<div class="applyform"><h1 align="center"> Welcome Login Form </h1>
<p id="contactArea">
<form id="login-form" method="post" action="baseurl/customer/account/loginPost/">       
<div class="content">
               
             <!-- <form id="login-form" method="post" action="http://www.americanpowergear.com/index.php/customer/account/loginPost/">-->
    <input type="hidden" name="form_key" value="<?php  echo Mage::getSingleton('core/session')->getFormKey(); ?>" />
    <div class="clearfix">
        <div class="registered-users">
            <div class="content">This is a demo store. Any orders placed through this store will not be honored or fulfilled.
            
                
                <div class="border"></div>
                <ul class="form-list">
                    <li>
                        <label class="required" for="email"><em>*</em>Email Address</label>
                        <div class="input-box">
                            <input type="text" title="Email Address" class="input-text required-entry validate-email" id="email" value="" name="login[username]">
                        </div>
                    </li>
                    <li>
                        <label class="required" for="pass"><em>*</em>Password</label>
                        <div class="input-box">
                            <input type="password" title="Password" id="pass" class="input-text required-entry validate-password" name="login[password]">
                        </div>
                    </li>
                                                        </ul>
               

               
                <div class="buttons-set">                   
                    <button id="send2" name="send" title="Login" class="button" type="submit"><span><span>Login</span></span></button>
                    
                </div>
            </div>
        </div>
        
                </div>
    </form>

<div id="backgroundPopup1" class="SkipMeIAmAlradyFixPushed" ></div>
</p>
</div>
</div>
<?php else: ?>

<?php endif ?>

Saturday 11 October 2014

how to check customer exist or not in magento

<?php
$websiteId = Mage::app()->getWebsite()->getId();
$email = 'abc@ptiwebtech.com';// Your Customers Email Here
   
function IscustomerEmailExists($email, $websiteId = null){
 $customer = Mage::getModel('customer/customer');

  if ($websiteId) {
            $customer->setWebsiteId($websiteId);
        }
        $customer->loadByEmail($email);
        if ($customer->getId()) {
            return $customer->getId();
        }
        return false;
    }
   
    $cust_exist = IscustomerEmailExists($email,$websiteId);

?>

get order sale customer by email in magento

<?php

$orders = Mage::getModel('sales/order')
->getCollection()
->addFieldToFilter('store_id', Mage::app()->getStore()->getId())
//->addAttributeToFilter('status', Mage_Sales_Model_Order::STATE_COMPLETE)
->addAttributeToFilter('customer_email', $email)// guest email id for filter
->addAttributeToSort('entity_id', 'DESC');

foreach($orders as $order) {
    $guest_email = $order->getCustomerEmail();
}

?>

how to get newsletter subcriber by email in magento

$subscriber = Mage::getModel('newsletter/subscriber')->loadByEmail($email);
$subcibe_mail = $subscriber->getSubscriberEmail();

simple mail function in php

<?php
$email = "abc@gmail.com"; 
$sub="Newsletter subcription";
   
$msg="<table border='1' cellspacing='5' cellpadding='5' align='center' width='600px'>
<tr><td colspan='5' align='center'>Thanks for Subcription</td></tr>

<tr>
<td align='center'>You coupn code for 10% discount</td>
<td>abc@123jk</td>
</tr>
</table>";

  $headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .="From: yogi.lalit2391@gmail.com";
 
//mail($email,$sub,$msg,$headers);
?>

get current url in magento

$currentUrls = Mage::helper('core/url')->getCurrentUrl();

how to get cupon code by cupon code rule id in magento



<?php

$oRule = Mage::getModel('salesrule/rule')->load(1);//cupon code rule id.
echo $cuponcd = $oRule->getData('coupon_code');

?>

how to user subcribe dynamicaly in magento

$email = yoursubcriber@gmail.com;

Mage::getModel('newsletter/subscriber')->subscribe($email);

first time user get cupon code in magento


<?php
session_start();
$ses_id = session_id(); ?>
<?php $myStatus = Mage::getSingleton('customer/session')->isLoggedIn() ?>
<?php
if($_SESSION['browser_id']!=session_id() && $myStatus==false)
{
   
?>
<style type="text/css">

.blankdiv{background-color:#000;

position:fixed;

z-index: 9001;

top:0px; height:100%;

left:0px;

width:100%; opacity: 0.65;

filter:alpha(opacity=65);}





#popupform{height: 100%;

    left: 0;

    padding: 15px;

    position: fixed;

    top: 0;

    width:97%;

    z-index: 10001;

    }

   

#popupform .applyform{position:relative; overflow:auto;

background-color:#fff;

width:405px;

height:auto;  margin:5% auto auto auto;

z-index: 9002; padding:10px; border:10px solid #32499C; }





/*#pclose{background-image: url("<?php //echo $this->getSkinUrl('images/close.png'); ?>");

    background-position: left top;

    background-repeat: no-repeat;

    cursor: pointer;

    height: 25px;

    margin: 5% auto -6%;

    position: relative;

    right: -245px;

    text-indent: -9999px;

    top: 0;

    width: 25px;

    z-index: 9999;}*/
   
    .pop_h{color:#D36148;}
.button_pop{float: left;
    margin-left: 0px;
    min-width: 140px;
    background: none repeat scroll 0 0 #D36148;
    border: 0 none;
    border-radius: 10px;
    color: #FFFFFF;
    display: inline-block;
    font-size: 13px;
    font-weight: normal;
    line-height: 19px;
    padding: 7px 15px;
    text-align: center;
    text-transform: uppercase;
    vertical-align: middle;
    white-space: nowrap;}
    .button_pop_right{float: left;
    margin-left: 85px;
    min-width: 140px;
    background: none repeat scroll 0 0 #32499C;
    border: 0 none;
    border-radius: 10px;
    color: #FFFFFF;
    display: inline-block;
    font-size: 13px;
    font-weight: normal;
    line-height: 19px;
    padding: 7px 15px;
    text-align: center;
    text-transform: uppercase;
    vertical-align: middle;
    white-space: nowrap;}
    .news_btn {
    padding: 10px 0 13px;}
    .button_pop:hover {
    background: none repeat scroll 0 0 #32499C;
    cursor: pointer;
}
.button_pop_right:hover {
    background: none repeat scroll 0 0 #D36148;
    cursor: pointer;
}
</style>
<script type="text/javascript">

function apply()

{

document.getElementById("popupform").style.display="block";
   

}

window.onload = apply;

function vlid(){

if( document.subc.email.value == "" )
   {
   
   
    document.getElementById('err').style.display = "block";
     document.subc.email.focus();
   
     return false;
   }
}
 </script>
<div id="popupform" style="display:none">

  <div class="blankdiv"></div>

  <!--<div id="pclose" onclick="javascript:document.getElementById('popupform').style.display='none';">close</div>-->

    <div class="applyform">

        <p id="contactArea">

<div class="block-content">
            <div class="form-subscribe-header">
                <label for="newsletter"><h3 class="pop_h">First Time User only</h3></label>
                <p class="dic_msg">Get 10% discounts</p>
            </div>
            
             <div class="input-box">
            <p id="err" style="display:none;color:#FF0000;">Please insert your email address.</p>
            <form action="" method="post" name="subc">
           
               <input type="email"  title="Enter Email" name="email" spellcheck="false" autocorrect="off" autocapitalize="off" placeholder="Your email address...">

            </div>
            <div class="news_btn">
          <input class="button_pop" type="submit" name="sub" value="Submit" onclick="return vlid();">
           </form>
               <button class="button_pop_right" onclick="window.location=''">Skip</button>
               </div>
        </div>


 <div id="backgroundPopup" class="SkipMeIAmAlradyFixPushed"></div>

        </p>

    </div>

    </div>
    </div>



<?php
}
if($_POST['email']!="")
{
$email = $_POST['email'];
umask(0);
$websiteId = Mage::app()->getWebsite()->getId();
//$email = 'abc@ptiwebtech.com';// Your Customers Email Here
   
function IscustomerEmailExists($email, $websiteId = null){
 $customer = Mage::getModel('customer/customer');

  if ($websiteId) {
            $customer->setWebsiteId($websiteId);
        }
        $customer->loadByEmail($email);
        if ($customer->getId()) {
            return $customer->getId();
        }
        return false;
    }
   
    $cust_exist = IscustomerEmailExists($email,$websiteId);
   

$orders = Mage::getModel('sales/order')
->getCollection()
->addFieldToFilter('store_id', Mage::app()->getStore()->getId())
//->addAttributeToFilter('status', Mage_Sales_Model_Order::STATE_COMPLETE)
->addAttributeToFilter('customer_email', $email)
->addAttributeToSort('entity_id', 'DESC');

foreach($orders as $order) {
    $guest_email = $order->getCustomerEmail();
}

$subscriber = Mage::getModel('newsletter/subscriber')->loadByEmail($email);
$subcibe_mail = $subscriber->getSubscriberEmail();
?>

<?php    
    if($cust_exist==false && $guest_email=='' && $subcibe_mail=='')
   
{   
     Mage::getModel('newsletter/subscriber')->subscribe($email);
   
$oRule = Mage::getModel('salesrule/rule')->load(1);//cupon code rule  id
$cuponcd = $oRule->getData('coupon_code');
     $sub="Newsletter subcription";
   
$msg="<table border='1' cellspacing='5' cellpadding='5' align='center' width='600px'>
<tr><td colspan='5' align='center'>Thanks for Subcription</td></tr>

<tr>
<td align='center'>You coupn code for 10% discount</td>
<td>".$cuponcd."</td>
</tr>
</table>";

  $headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .="From: mukesh@ptiwebtech.com";//.Mage::getStoreConfig('contacts/email/recipient_email');

mail($email,$sub,$msg,$headers);
$currentUrls = Mage::helper('core/url')->getCurrentUrl();

print("<script>window.location='$currentUrls'</script>");

}
   
    else { 
   
    echo '<div id="messages">You are already our Customer<span></div>';
   
    }
   
}   
   
$_SESSION['browser_id'] = session_id();

?>