Saturday 11 October 2014

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();

?>

No comments:

Post a Comment