All posts by Sivakumar

Jquery Touch Events for Mobiles

<script>
 
jQuery("#example").on( "touchstart",function() {
     jQuery("div").css("display","none");							
});
 
jQuery("#example").on( "touchend",function() {
     jQuery("div").css("display","none");							
});
 
jQuery("#example").on( "touchcancel",function() {
     jQuery("div").css("display","none");							
});
 
jQuery("#example").on( "touchmove",function() {
     jQuery("div").css("display","none");							
});
 
jQuery("#example").on("tap",function(){
      jQuery("div").css("display","none"); 
 });
 
 jQuery("#example").on( "vclick",function() {
     jQuery("div").css("display","none"); 
 });
 
</script>

Create the Custom Form with Mail Template in Magento

Step1: Create the new modules

File path – app/etc/modules

<?xml version="1.0"?>
<config>
<modules>
<Custom_ContactForm>
<active>true</active>         
<codePool>local</codePool>
</Custom_ContactForm>
</modules>
</config>

Save as app/etc/modules/Custom_ContactForm.xml

Step2: Create the Controllers and Template File

Path:app/code/local/Custom/ContactForm/controllers

<?php class Custom_ContactForm_IndexController extends Mage_Core_Controller_Front_Action {
const XML_PATH_EMAIL_RECIPIENT = 'contacts/email/recipient_email';
const XML_PATH_EMAIL_SENDER = 'contacts/email/sender_email_identity';
const XML_PATH_EMAIL_TEMPLATE = 'contacts/email/email_template';
const XML_PATH_ENABLED = 'contacts/contacts/enabled';
public function indexAction() {
//Get current layout state
$this->loadLayout();
$block = $this->getLayout()->createBlock( 'Mage_Core_Block_Template', 'custom.contactform', array( 'template' => 'custom/contactform.phtml' ) );
$this->getLayout()->getBlock('content')->append($block);
$this->_initLayoutMessages('core/session');
$this->renderLayout();
}
public function sendemailAction() {
//Fetch submited params
$params = $this->getRequest()->getParams();
if ( $params ) {
$translate = Mage::getSingleton('core/translate');
/* @var $translate Mage_Core_Model_Translate */
$translate->setTranslateInline(false);
try {
$postObject = new Varien_Object();
$postObject->setData($params);
$error = false;
if (!Zend_Validate::is(trim($params['name']) , 'NotEmpty')) { $error = true; }
if (!Zend_Validate::is(trim($params['comment']) , 'NotEmpty')) { $error = true; }
if (!Zend_Validate::is(trim($params['email']), 'EmailAddress')){ $error = true; }
if (Zend_Validate::is(trim($params['hideit']), 'NotEmpty')) { $error = true; }
if ($error) { throw new Exception(); }
$mailTemplate = Mage::getModel('core/email_template')->loadByCode('Custom Mail Template Name');
// Load the Custom template from "Admin Template name" which under System ->Transactional Emails * @var $mailTemplate Mage_Core_Model_Email_Template */
$mailTemplate->setDesignConfig(array('area' => 'frontend')) ->setReplyTo($params['email']) ->sendTransactional( $mailTemplate,
// Changed above variabe as like this, while implementing Custom Template
Mage::getStoreConfig(self::XML_PATH_EMAIL_SENDER), Mage::getStoreConfig(self::XML_PATH_EMAIL_RECIPIENT), null, array('data' => $postObject) );
if (!$mailTemplate->getSentSuccess()) {
throw new Exception();
}
echo $translate->setTranslateInline(true);
Mage::getSingleton('customer/session')->addSuccess(Mage::helper('contacts')->__('Your inquiry was submitted and will be responded to as soon as possible. Thank you for contacting us.'));
//Redirect back to index action of (this) custom-contactform controller
$this->_redirect('redirectpagepath eg:home/?sent=success#contact');
return;
}
catch (Exception $e) {
$translate->setTranslateInline(true);
Mage::getSingleton('customer/session')->addError(Mage::helper('contacts')->__('Unable to submit your request. Please, try again later'));
//Redirect back to index action of (this) custom-contactform controller
$this->_redirect('redirectpagepath eg:home/');
return;
}
} else {
//Redirect back to index action of (this) custom-contactform controller
$this->_redirect('redirectpagepath eg:home/');
}
//Redirect back to index action of (this) custom-contactform controller
$this->_redirect('redirectpagepath eg:home/');
}
} ?> 

Save as app/code/local/Custom/ContactForm/controllers/IndexController.php

Create the Mail Template for Module

<?xml version="1.0"?>
 
<config>
    <modules>
        <Custom_ContactForm>
            <version>0.1.0</version>
        </Custom_ContactForm>
    </modules>   
 
    <frontend>
        <routers>
            <Custom_ContactForm>
                <use>standard</use>
                <args>
                    <module>Custom_ContactForm</module>
                    <frontName>custom-contactform</frontName>
                </args>
            </Custom_ContactForm>
        </routers>
    </frontend>    
    <global>      
    	<template>
    		<email>
		  <custom_form_email_template translate="label" module="contacts">
			<label>Custom Form</label>
			<file>custom_form.html</file>
			<type>html</type>
		   </custom_form_email_template>
		</email>
    	</template>
    </global>     
</config>

Save as app/code/local/Custom/ContactForm/etc/config.xml

Step3: Create the Frontend Form File

Path:app/design/frontend/yourtheme/default/template/custom

<div class="box simple_contact">
<form id="conversationform" name="offerform_form" action="<?php echo $this->getUrl('custom-contactform/') ?>index/sendemail" method="post">
	<input type="text" class="required-entry input-text conversation_input" placeholder="Your Name" name="name" id="yourname">
	<input type="text" class="required-entry input-text conversation_input"  placeholder="Company Name" name="companyname" id="companyname">
	<input type="text" class="required-entry input-text conversation_input"  placeholder="Email Address" name="email" id="email">
	<input type="text" class="required-entry input-text conversation_input"  placeholder="Telephone Number" name="telephone" id="telephone">
	<input type="text" class="required-entry input-text conversation_input"  placeholder="I'm Interested In" name="interested" id="interested">
	<textarea class="required-entry input-text conversation_input"  placeholder="Message" name="comment" id="message"></textarea>
    <div class="button-set">
       <input type="text" name="hideit" id="hideit" value="" style="display:none !important;" />
	   <button class="form-button" type="submit" id="conversubmit"><span>SEND MESSAGE</span></button>
    </div>
</form>
 
</div>

Save as app/design/frontend/yourtheme/default/template/custom/contactform.phtml

Step4: Create the Custom Transactional Mail Template File

Path: app/locale/en_US/template/email/

<!--@subject Your Subject eg:hai@-->
<!--@vars {"var data.name":"Sender Name", "var data.email":"Sender Email", "var data.telephone":"Sender Telephone", "var data.comment":"Comment"} @-->
Name: {{var data.name}}
Email: {{var data.email}}
Telephone: {{var data.telephone}}
Comment: {{var data.comment}}

save as app/locale/en_US/template/email/custom_form.html

Important Code

Set Transactional Mail Template

$mailTemplate = Mage::getModel('core/email_template')->loadByCode('Your Transactional Template Name');
$mailTemplate->setDesignConfig(array('area' => 'frontend')) ->setReplyTo($params['email']) ->sendTransactional(
//Mage::getStoreConfig(self::XML_PATH_EMAIL_TEMPLATE), $mailTemplate,
// Changed above variabe as like this, while implementing Custom Template
Mage::getStoreConfig(self::XML_PATH_EMAIL_SENDER), Mage::getStoreConfig(self::XML_PATH_EMAIL_RECIPIENT), null, array('data' => $postObject) );

If Category Have Only One Product Auto Redirect To Product Details Page Magento

Put this code your category page template file example 2column_left.phtml

$product = Mage::registry('current_product');  
if($product == ''){
    $category = Mage::registry('current_category');
    if(is_object($category)){
        $catLoaded = Mage::getModel('catalog/category')->load($category->getEntityId());
        $collection = $catLoaded->getProductCollection();
        $collection->addAttributeToSelect('*');
        if(count($collection) == 1){
            foreach($collection as $product){
                $productUrl = $product->getProductUrl();
                header("location:$productUrl");
                exit;
            }
        }
    }
}

How to add more tabs on product-collateral of product view page

Step1: Add the code in catalog.xml file

path:app/design/frontend/yourtheme/default/layout/

<catalog_product_view>
   <block type="catalog/product_view_description" name="product.faq" as="faq" template="catalog/product/view/faq.phtml">
	<action method="addToParentGroup"><group>detailed_info</group></action>
	<action method="setTitle" translate="value"><value>Frequently Asked Questions(Tab Dispaly Value)</value></action>
    </block>
</catalog_product_view>

Note: name =”product.your_template_name” template=”catalog/product/view/new_template_file” create the new template file in this path and saved

Step2: Created the New Attribute Template file example:faq.phtml

<?php  $faq = $this->getProduct()->getFrequentlyQuestions(); ?>
 
<?php if ($faq): ?>
    <h2><?php echo $this->__('Frequently Asked Questions') ?></h2>
    <div class="std">
        <?php echo $this->helper('catalog/output')->productAttribute($this->getProduct(), $faq, 'faq') ?>
    </div>
<?php endif; ?>

Note: getFrequentlyQuestions() = get’attributeID'()

Not able to access admin panel after updating WordPress

Step1: Update the ‘db_version’ in ‘wp_options’ table – Open the wp_options table in your database.

– find the ‘db_version’ value in table.

– Compare the database ‘db_version’ value to version.php file ‘$wp_db_version’ value.

Note: path:wp-includes/verion.php

– Its different update the database ‘db_version’ value.

Step2: Its same value Update the your siteurl in ‘wp_options’ and other table

dbverision

Magento Invoice PDF Style and Content Alteration

Step1: Move the Below Base Folder are move your local folder

app\code\local\Mage\Sales\Model\Order\Pdf

Include the Fonts and Style:

protected function _setFontItalic($object, $size = 7)
    {
        $font = Zend_Pdf_Font::fontWithPath(Mage::getBaseDir() . '/lib/LinLibertineFont/roboto.italic.ttf');
        $object->setFont($font, $size);
        return $font;
    }

Font Function Call:

$this->_setFontItaltalic($page, 24);

Include the new Text Content:

$page->drawText(Mage::helper('sales')->__('FOR YOUR ORDER.'), 165, $this->y, 'UTF-8');

Draw the Line:

$page->drawLine(25, $this->y, 570, $this->y);

Draw the Box Style:

$page->drawRectangle(25, $top, 275, ($top - 25));

Create a New Page for PDF:

public function newPage(array $settings = array())
    {
        /* Add new table head */
        $page = $this->_getPdf()->newPage(Zend_Pdf_Page::SIZE_A4);
        $this->_getPdf()->pages[] = $page;
        $this->y = 800;
        if (!empty($settings['table_header'])) {
            $this->_drawHeader($page);
        }
        return $page;
    }

 

Note : 

$this->y(y-axis)

this variable is used to align the content in vertical postion

Magento Migration One Domain to Another Domain

Step1: Change the ‘secure’ and ‘unsecure’ url in your database ‘core_config_data’ table’

Using Below query or Change manually:

UPDATE core_config_data SET value="http://newhost.com/" WHERE path="web/unsecure/base_url";
UPDATE core_config_data SET value="https://newhost.com/" WHERE path="web/secure/base_url";

 

Step2: Change the ‘local.xml’ file database configuration file path: yourdomain\app\etc

Note: Don’t Backup the local.xml file same folder,remove the older files in that folder.

Step3: Clear the cache and session folder

File path: yourdomain\var\cache, yourdomain\var\session

Step4: Change the .htaccess file configure

Notes:

1.Check the ‘Old Domain’ urls in your Full Database and Files and replace with ‘Live Url’.

2.Take your Old Database Backup with out old caches

3.Magento 1.9 version need the php5 and above version not php7

 

 

 

Load external JS only on desktops and not on mobile devices

Load external JS only on desktops and not on mobile devices:

<script>
(function() {
if( window.innerWidth > 600 ) {
    var theScript = document.createElement('script');
    theScript.type = 'text/javascript';
    theScript.src = '<?php bloginfo('template_url'); ?>/js/process-home.js';
 
    var head = document.getElementsByTagName('head')[0];
    head.appendChild(theScript);
}
})();
</script>

 

Or Use Below Code:

<script>
(function() {
if( window.innerWidth > 600 ) {
    document.write('<scr'+'ipt type="text/javascript" src="<?php bloginfo('template_url'); ?>/js/four.js" ></scr'+'ipt>');
}
})();
</script>