Wednesday, 7 August 2013

How to exclude/Remove state from shipping in magento


Go to /app/code/core/Mage/Directory/Helper/data.php
Overwrite the default function with this

public function getRegionJson()
{
$exclude_regions = array ('AL','NJ','NY','CT','AS','AK','AA'); //this is the code of excluded state

Varien_Profiler::start('TEST: '.__METHOD__);
if (!$this->_regionJson) {
$cacheKey = 'DIRECTORY_REGIONS_JSON_STORE'.Mage::app()->getStore()->getId();
if (Mage::app()->useCache('config')) {
$json = Mage::app()->loadCache($cacheKey);
}
if (empty($json)) {
$countryIds = array();
foreach ($this->getCountryCollection() as $country) {
$countryIds[] = $country->getCountryId();
}
$collection = Mage::getModel('directory/region')->getResourceCollection()
->addCountryFilter($countryIds)
->load();
$regions = array();
foreach ($collection as $region) {

$rg = $region->getCode();

//if ($rg!=’AL’){
if(!in_array($rg, $exclude_regions)) {

if (!$region->getRegionId()) {
continue;
}
$regions[$region->getCountryId()][$region->getRegionId()] = array(
'code' => $region->getCode(),
//’name’ => $region->getName()
'name' => $this->__($region->getName())
);
}

}
$json = Mage::helper('core')->jsonEncode($regions);

if (Mage::app()->useCache('config')) {
Mage::app()->saveCache($json, $cacheKey, array('config'));
}
}
$this->_regionJson = $json;
}

Varien_Profiler::stop('TEST: '.__METHOD__);
return $this->_regionJson;
}

Monday, 15 July 2013

forget password email problem in magento

Go to app/design/frontend/default/[your_custom_theme_folder]/layout/customer.xml

Copy this at the last before: </layout>

<customer_account_resetpassword translate="label">
        <label>Reset a Password</label>
        <remove name="right"/>
        <remove name="left"/>

        <reference name="head">
            <action method="setTitle" translate="title" module="customer">
                <title>Reset a Password</title>
            </action>
        </reference>
        <reference name="root">
            <action method="setTemplate">
                <template>page/1column.phtml</template>
            </action>
            <action method="setHeaderTitle" translate="title" module="customer">
                <title>Reset a Password</title>
            </action>
        </reference>
        <reference name="content">
            <block type="customer/account_resetpassword" name="resetPassword" template="customer/form/resetforgottenpassword.phtml"/>
        </reference>
    </customer_account_resetpassword>

Thursday, 11 July 2013

Get Google feed in Magento

make a php file in your Magento root folder and this code and run that file.

Then You can find your text fine in var/export/google_base_feed.txt



<?php
    define('SAVE_FEED_LOCATION','export/google_base_feed.txt');//you can set a new folder and file if you want, don't forget to chmod the folder to 777

    // make sure we don't time out
    set_time_limit(0);   

    require_once 'app/Mage.php';
        Mage::app('default');
       
    try{
        $handle = fopen(SAVE_FEED_LOCATION, 'w');

       
        $heading = array('id','title','description','link','image_link','price','brand','product_type');
        $feed_line=implode("\t", $heading)."\r\n";
        fwrite($handle, $feed_line);
       
        //---------------------- GET THE PRODUCTS   
        $products = Mage::getModel('catalog/product')->getCollection();
        $products->addAttributeToFilter('status', 1);//enabled
        $products->addAttributeToFilter('visibility', 4);//catalog, search
        $products->addAttributeToSelect('*');
        $prodIds=$products->getAllIds();
       
        //echo 'Product filter: '.memory_get_usage(false).'<br>';
        //flush();
       
        $product = Mage::getModel('catalog/product');
       
        foreach($prodIds as $productId) {
            //echo '. ';
            //flush();
            //echo 'Loop start: '.memory_get_usage(false).'<br>';
            //flush();
   
            //$product = Mage::getModel('catalog/product');
            $product->load($productId);
           
            $product_data = array();   
            $product_data['sku']=$product->getSku();   
            $product_data['title']=$product->getName();
            $product_data['description']=$product->getDescription();
            $product_data['link']=$product->getProductUrl();
            $product_data['image_link']=Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA).'catalog/product'.$product->getImage();
            $product_data['price']=$product->getPrice();
            $product_data['brand']=$product->getResource()->getAttribute('manufacturer')->getFrontend()->getValue($product);   
            $product_data['product_type']='';       
         
            //echo 'Product load: '.memory_get_usage(false).'<br>';
            //flush();       
         
            //get the product categories                   
                    foreach($product->getCategoryIds() as $_categoryId){
            $category = Mage::getModel('catalog/category')->load($_categoryId);
            $product_data['product_type'].=$category->getName().', ';
            }
            $product_data['product_type']=rtrim($product_data['product_type'],', ');       

            //echo 'Category load: '.(memory_get_usage(false)).'<br>';           
           
            //sanitize data   
            foreach($product_data as $k=>$val){
            $bad=array('"',"\r\n","\n","\r","\t");
            $good=array(""," "," "," ","");
            $product_data[$k] = '"'.str_replace($bad,$good,$val).'"';
            }
           

            $feed_line = implode("\t", $product_data)."\r\n";
            fwrite($handle, $feed_line);
            fflush($handle);
           
            //echo 'Loop end: '.memory_get_usage(false).'<br>';
            //flush();
        }

        //---------------------- WRITE THE FEED   
        fclose($handle);
       
    }
    catch(Exception $e){
        die($e->getMessage());
    }
?>

To show root category's subcategories with thumbnail image in Magento


<div class="product_boxx">
<div id="list_x">
<div class="new_pro">
<ul>
<?php

$children = Mage::getModel('catalog/category')->getCategories(2);
$i=1;
foreach ($children as $category):
$category=Mage::getModel('catalog/category')->load($category->getId());
?>


<li>
<div class="new_promain">
<div class="pro_img"> <a href="<?php echo $category->getUrl() ?>"> <img src="<?php echo Mage::getBaseUrl('media').'catalog/category/'.$category->getThumbnail()  ?>" width="100" height="100" /> </a></div>

<div class="pro_detail">
<p><?php echo $category->getName() ?> </p>
</div>


</div>
</li>


<?php if($i%6=='0') {?>
</ul>
<ul>
<?php } $i++; endforeach; ?>
</ul>
</div>
</div>
</div>

How to call Related product in static Block in Magento

{{block type="catalog/product_list_related" name="catalog.product.related" before="-" template="catalog/product/list/related.phtml"}}

Thursday, 20 June 2013

To show review form and customer review on product detail page in magento

To call the all customer review:



{{block type="review/product_view_list" name="product.info.product_additional_data" as="product_additional_data" template="review/product/view/list.phtml"}}

To call the Review Form:


{{block type="review/form" name="product.review.form" as="review_form"}}

Thursday, 13 June 2013

Add captcha in contacts us page in magento

Replace this file to your /test/app/design/frontend/base/default/template/contacts/form.phtml

 
<script type="text/javascript">
function ram_mk()
{


a=document.getElementById('tot').value;
b=document.getElementById('catcha').value;
if(a!=b)
{
document.getElementById('mk_x').style.display='';
return false;
}
}

function akk()
{
ab=Math.floor((Math.random()*10)+1);
ab1=Math.floor((Math.random()*8)+1);
var tot=ab+ab1;
document.getElementById('captcha_1').innerHTML=ab;
document.getElementById('captcha_2').innerHTML=ab1;
document.getElementById('tot').value=tot;
document.getElementById('ab').value=ab;
document.getElementById('ab1').value=ab1;

}
window.onload = akk;
</script>
<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Academic Free License (AFL 3.0)
 * that is bundled with this package in the file LICENSE_AFL.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/afl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @category    design
 * @package     base_default
 * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
 * @license     http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */
?>
<div class="middle_a">
<?php if($_REQUEST['msg']!='') { ?>
<ul class="messages"><li class="success-msg"><ul><li><span><?php echo $_REQUEST['msg']; ?></span></li></ul></li></ul>
<?php } ?>
<div class="contact_page">
    <h3><?php echo Mage::helper('contacts')->__('got questions?') ?></h3>
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('contact-us')->toHtml() ?>
<div class="contact_form">
<form action="http://yourdomain.com/email.php" method="post">
<input type="hidden" name="url_x" value="<?php echo $currentUrl = Mage::helper('core/url')->getCurrentUrl() ?>" />

   <table width="100%" border="0" cellspacing="0" cellpadding="10">
<tr>
       
        <td><input name='name' type='text' class="text-df" onblur="if(this.value=='') this.value='Your Name'" onfocus="if(this.value=='Your Name') this.value=''" value="Your Name" required="required"/></td>
    </tr>
     <tr>
       
        <td><input name='email' type='email' class="text-df" onblur="if(this.value=='') this.value='Email Address'" onfocus="if(this.value=='Email Address') this.value=''" value="Email Address" required="required"/></td>
    </tr>
    <tr>
        <td><textarea name="Message" class="box-df1" required="required" onblur="if(this.value=='') this.value='Message'" onfocus="if(this.value=='Message') this.value=''" value="Message" >Message</textarea>
         </td>
    </tr>
     <tr>
       
        <td><input name="catcha" id="catcha" type='text' class="text-df" onblur="if(this.value=='') this.value='Enter Sum'" onfocus="if(this.value=='Enter Sum') this.value=''" value="Enter Sum" /></td>
    </tr>
    <tr style="display:none; color:#CC0000;" id="mk_x">
    <td align="center">Captcha not match</td>
    </tr>
   
    <tr>
       
        <td>
        <table width="100%">
        <tr>
        <td id="captcha-x">
        <span id="captcha_1">8</span> + <span id="captcha_2">5</span> = ?
       
        <input type="hidden" name="tot" id="tot" value="15"  size="2"/>
        <input type="hidden" name="ab" id="ab" value="15"  size="2"/>
        <input type="hidden" name="ab1" id="ab1" value="15"  size="2"/>
        </td>
        <td align="right">
        <input type='submit' name="submit" value="Send" class="send"  onclick="return ram_mk();" />
        </td>
        </tr>
        </table>
       
        </td>
    </tr>
</table>

</div>




<!-- contact_page -->

</div>

<!-- middle_a -->
<script type="text/javascript">
//<![CDATA[
    var contactForm = new VarienForm('contactForm', true);
//]]>
</script>



and add this file with name email.php to your magento root folder:

<?php
$catcha = $_REQUEST['catcha'];
$tot =$_REQUEST['tot'];
$ab = $_REQUEST['ab'];
$ab1 = $_REQUEST['ab1'];

$total=$ab+$ab1;
if($tot=='@100as_pti')
{
print("<script>window.location='".$_REQUEST['url_x']."'</script>");
exit;

}

if($catcha!=$total)
 {
print("<script>window.location='".$_REQUEST['url_x']."'</script>");
exit;

}



if($catcha==$total)
{

$mesg = $_REQUEST['Message'];
if(stristr($mesg, 'http') === FALSE)
{
if(stristr($mesg, 'https') === FALSE)
{

$_session['success']="Your inquiry was submitted and will be responded to as soon as possible. Thank you for contacting us";
$replymsg="Your inquiry was submitted and will be responded to as soon as possible. Thank you for contacting us";
$mail_to="shweta@ptiwebtech.com";
$sub="Contact us ";

$message = "<br>Name :  ".$_REQUEST['name'];
$message .= "<br>E-mail : ".$_REQUEST['email'];
$message .= "<br>Message  :  ".$_REQUEST['Message'];



$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .="From: ".$_REQUEST['email'];

mail($mail_to,$sub,$message,$headers);
}

 }

}

 print("<script>window.location='".$_REQUEST['url_x']."?msg=$replymsg'</script>");
 ?>



NOTE: replace $mail_to="shweta@ptiwebtech.com"; to your email id.