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

?>