Posts

Showing posts from July, 2012

How to add a text counter in textarea or Setting a maxlength on a textarea?

if you want to add text counter your textarea and set the Setting a maxlength on a textarea. so simply add this code in file and run the file in your browser <form name="textcount" id="textcount"> <textarea cols="60"  rows="12" class="input_compose_textarea" id="description" name="description" onkeypress="textCounter(this,this.form.counter,500);" onblur="textCounter(this,this.form.counter,500);"></textarea> <br/> Max length - <input    type="text" readonly="readonly"    name="counter"    maxlength="3"    size="3"    value="500"    onblur="textCounter(this.form.counter,this,500);"> char remaining. </form> <script type="application/javascript"> function textCounter( field, countfield, maxlimit ) { if ( field.value.length > maxlimit ) { field.value = field.va

How to Check if current page is Homepage or not in magento?

Simply add this code in your page this code will check if current page is Homepage or not in magento. <?php if($this->getUrl('') == $this->getUrl('*/*/*', array('_current'=>true, '_use_rewrite'=>true))): echo "yes homepage of magento"; else: echo "this is not Homepage"; endif; ?>

How to remove right column from product details page in magento?

go to this directory app/design/frontend/base/default/layout/ open catalog.xml and search  <label>Catalog Product View (Any)</label> you can find this line around 180 line of this page code will be like this <catalog_product_view translate="label">         <label>Catalog Product View (Any)</label>         <!-- Mage_Catalog -->         <reference name="root">             <action method="setTemplate"><template>page/2columns-right.phtml</template></action>         </reference> change 2columns-right.phtml to 1column.phtml  <catalog_product_view translate="label">         <label>Catalog Product View (Any)</label>         <!-- Mage_Catalog -->         <reference name="root">             <action method="setTemplate"><template>page/1column.phtml</template></action>         </reference&

How to get the path of downloadable product's file of associated product or group product which was upload during add downloadable product?

How to get the path of  downloadable product's file of associated product or group product which was upload during add downloadable product? This will return you full path of downloadable product  $file =''; $home_url = Mage::helper('core/url')->getHomeUrl(); $static_path = $home_url."media/downloadable/files/links"; $productLinks = $ $product ->getTypeInstance(true)->getLinks($product); foreach($productLinks as $key=>$val) {       $val = trim($productLinks[$key]->link_file);         if($val!='')         {         $file = $val;         }         else         {         $file = '';         } } echo $file_path = $static_path.$file;

HOW TO GET GET BASE URL, SKIN URL, GET MEDIA URL, GET STORE URL AND OTHER URLS IN MAGENTO?

HOW TO GET  GET BASE URL, SKIN URL, GET MEDIA URL, GET STORE URL AND OTHER URLS IN MAGENTO? HERE IS SOME USEFULL URL FOR YOU WHICH CAN HELP YOU TO USE THE DEFINE URL IN MAGENTO HOPE THIS WILL HELP YOU. To get Media URL {{media url='/sampleimage.jpg'}} To get Store URL {{store url='mypage.html'}} To get Base URL {{base url='yourstore/mypage.html'}} TO Retrieve URL path in PHTML Note: In editing PHTML don't forget to enclode the following code with PHP tag Not secure Skin URL: <?php echo $this->getSkinUrl('images/sampleimage.jpg') ?> Secure Skin URL <?php echo $this->getSkinUrl('images/ sampleimage.gif', array('_secure'=>true)) ?> Get  Current URL $current_url = Mage::helper('core/url')->getCurrentUrl(); Get Home URL $home_url = Mage::helper('core/url')->getHomeUrl(); Get Magento Media Url Mage::getBaseUrl(

How to know product type in magento?

How to know product type in magento that product is group or simple or downloadable. echo $product->getTypeId();

How to get the id of associated products in magento from the array of associated products?

Get the id of associated products in magento from the array of associated products. i was getting rid that i have array of associated product but unable to get the id of associated product. after so much search i found this solution check this it will works for you .... $associatedProducts = $_product->getTypeInstance(true)->getAssociatedProducts($_product); foreach($associatedProducts as $assoc_id) { $aid = $assoc_id->getId(); echo "id of associated products is = ".$aid; echo "<br/>"; }

How to get the array of associated product of group product in magento?

For get the array of associated product of group product in magento you to add simple this line in code where you are getting group product details. $associatedProducts = $_product->getTypeInstance(true)->getAssociatedProducts($_product); print_r( $associatedProducts ); it will return to you all associated products array of group product now you can use this array as you want. and you want to get the associated product ids only then you can simple add this like below above code foreach($associatedProducts as $assoc_id) { $aid = $assoc_id->getId(); echo "id of associated products is = ".$aid; echo "<br/>"; }

How to get count of cart item in magento?

simply copy and paste where you want to get count of cart item in magento <?php $mageFilename = 'app/Mage.php'; require_once $mageFilename; umask(0); Mage::app(); Mage::getSingleton('core/session', array('name'=>'frontend')); $session = Mage::getSingleton('checkout/session'); $output = ""; foreach ($session->getQuote()->getAllItems() as $item) {     $output .= $item->getQty() . "<br>"; } print $output; ?>

How to create a page which show only subcategory or how to show all category on one page in magento?

Go to the admin Now follow the step CMS->PAGES->Add new page Insert these data in the form Step 1:- insert in Page Information tab Titile-> categories URL Key *-> categories Status *->Enabled Step 2:- insert in Content Content Heading->anything according to you and paste this code in the textarea box {{block type="catalog/navigation" name="catalog.categories" template="catalog/navigation/category_listing.phtml"}} Step 3:- select in Page Layout Layout *->select   2 columns with right bar After this save the page Now add new page and in this directories App/design/frontend/base/default/templates/catalog/navigation/ category_listing.phtml And add this code in this page <?php $_category  = $this->getCurrentCategory();  $collection = Mage::getModel('catalog/category')->getCategories($_category->entity_id); $helper     = Mage::helper('catalog/category'); ?>

How to show Currency Options drop down on homepage or header in magento?

show Currency Options drop down on homepage or header in magento? and if not showing  Currency Options drop down somewhere so follow these steps. - Follow these steps to show store specific currency:- - Go to System -> Configuration -> GENERAL -> Currency Setup - In left sidebar at top, you will see “Current Configuration Scope” - Select your desired store from the selection list - Now, under “Currency Options“, you will see “Default Display Currency” - Select your desired currency from the selection list You are done. In frontend, select the store for which you did the above changes. You will see the price in your desired currency. and put this line of code where u you want to display currency converter <?php echo $this->getLayout()->createBlock('directory/currency')->setTemplate('directory/currency.phtml')->toHtml(); ?>

How to show category on right side or left side in magento?

First of all you have to create a new block in xml to show the category Navigate to /app/design/frontend/default/default/layout/catalog.xml Open this page and search this keyword " Default layout, loads most of the pages " and put this code in block <reference name="right"> <block type="catalog/navigation" name="catalog.righthomenav" template="catalog/navigation/right_home_nav.phtml" /> </reference> you can change layout position in mageto to change the  reference name as ( right, left, footer, etc ) create a new and directory like this path  /app/design/frontend/default/default/template/ catalog/navigation/ right_home_nav .phtml and paste this code in that in new page  right_home_nav .phtml <h2>Browse</h2> <div class="block"> <ul id="nav_category" class="nav_category"> <?php foreach ( $this -> getStoreCategories ( ) as $_category ) :

How to show featured products on home page in magento?

If you want to show featured products on home page in magento so here is code for you... IF you still have not add featured attribute in magento so first of all you have to add arrtibute in  Manage Attributes Step 1: Create new Featured attribute Create a new attribute by going to Catalog > Attributes > Manage Attributes > Add New Attribute. Attribute Properties Attribute Identifier: featured Scope: Store View Catalog Input Type for Store Owner: Yes/No Unique Value (not shared with other products): No Values Required: No Input Validation for Store Owner: None Apply To: All Product Types Front End Properties Use in quick search: No Use in advanced search: Yes Comparable on Front-end: No Use In Layered Navigation (Can be used only with catalog input type ‘Dropdown’): No Visible on Catalog Pages on Front-end: Yes Manage Label/Options Default: Featured Product Save the new attribute and go to Catalog ? A

Why session become blank on several pages in codeigniter?

I was to irritate that session did not work or became blank on sevral pages during work on website. i tried too many short ways but they all are works for some time or some place finally i got a permanent way to store a session in mvc codeigniter. First of all go in application/config/config.php open this file and change this content $config['sess_use_database'] = FALSE; TO $config['sess_use_database'] = TRUE; and $config['sess_table_name'] = 'ci_sessions'; // sess_table_name should be " ci_sessions "  when You change this after that copy and paste this sql query in database CREATE TABLE IF NOT EXISTS `ci_sessions` (   `session_id` varchar(40) COLLATE utf8_unicode_ci NOT NULL DEFAULT '0',   `ip_address` varchar(16) COLLATE utf8_unicode_ci NOT NULL DEFAULT '0',   `user_agent` varchar(50) COLLATE utf8_unicode_ci NOT NULL,   `last_activity` int(10) unsigned NOT NULL DEFAULT '0',   `user_data` text

How to save an image with image validation in new folder in php?

If you want to save an image on a new folder which will create on run time and with image validation , then simply copy and paste this code and change the name of image field name and you can replace $id to your folder name. $id=$_POST['id']; $last_url = $_SERVER['HTTP_REFERER']; if(!empty($_FILES['uploadedfile']['name'])){ $imgExtension = array("jpg","jpe","jpeg","gif","png","GIF","JPG","JPEG"); $image_name = pathinfo($_FILES['uploadedfile']['name']); $extension = strtolower($image_name['extension']); if(in_array($extension,$imgExtension)){ $file_name = $_FILES['uploadedfile']['name']; $ext = end(explode('.',$file_name)); $folder_path = 'public/uploads/auction/'.$id; $save_path  = 'public/uploads/auction/'.$id.'/'.$file_name; $path  = 'publ

How to get alexa rank using php?

I tried to many script of alexa which return you the rank of website but they all script return 0 always. so i make a new alexa script which return exact rank of website and this works. simple copy and paste alexa script code in your php file, it will also work on localhost <?php     function alexaRank ($domain)     {         $remote_url = 'http://data.alexa.com/data?cli=10&dat=snbamz&url='.trim($domain);         $search_for = '<POPULARITY URL';         $part='';         if ($handle = @fopen($remote_url, "r")) {         while (!feof($handle)) {         $part .= fread($handle, 100);         $pos = strpos($part, $search_for);         if ($pos === false)         continue;         else         break;         }         $part .= fread($handle, 100);         fclose($handle);         }         $str = explode($search_for, $part);         $str = array_shift(explode('"/>', $str[1]));         $str = explo