1.Where define database name,user name,and password of website
open magento folder
magento/app/etc/locale.xml
write in locale.xml
<config>
<global>
<install>
<date><![CDATA[Tue, 19 Jan 2010 05:11:20 +0000]]></date>
</install>
<crypt>
<key><![CDATA[86adf0890ed189543673a7d953659dcd]]></key>
</crypt>
<disable_local_modules>false</disable_local_modules>
<resources>
<db>
<table_prefix><![CDATA[]]></table_prefix>
</db>
<default_setup>
<connection>
<host>localhost</host>
<username>root</username>
<password>mysql_password</password>
<dbname>magento_demo</dbname>
<active>1</active>
</connection>
</default_setup>
</resources>
<session_save><![CDATA[files]]></session_save>
</global>
</config>
2)How to get the Current url path of any page in Magento
$currentUrl = $this->helper(‘core/url’)->getCurrentUrl();
3)How to get list of all categories in Magento
$categories = Mage::getModel('catalog/category')
->getCollection() |
->addAttributeToSelect('*');
4)How to get name of all modules in present Magento Installation
$modules =Mage::getConfig()->getNode('modules')->children();
5)Problems in magento Installation
Most common problem during magento installation is timeout
problem which often occurs . A very simple solution to it is to open your php.ini and navigate to these lines
a)max_execution_time = 60
Change its value to 1800 and second line you will encounter is
max_input_time = 60
Change its value to 1800
Now reinstall magento and most probably time out problem will not trouble you
6)Adding javascript and css on pages ->The Magento way
$headBlock = $this->getLayout()->getBlock(‘head’);
$headBlock->addJs(‘anyfoldername/anyjavascriptname.js’);
7)removing javascript and css on pages ->The Magento way
<action method=”removeItem”><type>js</type><name>calendar/calendar.js</name</action>
$this->getLayout->getBlock(‘head’)->removeItem(‘js’, ‘calendar/calendar.js’);
8)Model query in magento or How to insert record in database in magento
<?php
class Sapera_Nag_Model_Nag extends Mage_Core_Model_Abstract
{
public function _construct()
{
parent::_construct();
$this->_init(‘nag/nag’);
}
public function nagmani()
{
$collection = Mage::getResourceModel(‘nag/nag_collection’);
$collection->getSelect()->where(‘status = ?’, 1)->order(‘title’);
return $collection;
}
public function nagVish($title,$nagin_title,$filename,$content,$status)
{
$write = Mage::getSingleton(‘core/resource’)->getConnection(‘core_write’);
$write->query(“INSERT INTO nag(title,nagin_title,filename,content,status,created_time,update_time)VALUES (‘”.$title.”‘,’”.$nagin_title.”‘,’”.$filename.”‘,’”.$content.”‘,’”.$status.”‘, ’2010-11-03 17:08:29′, ’2010-11-04 17:08:32′)”);
return $write;
}
public function nagVish2($title,$nagin_title,$filename,$content,$status)
{
$getModel=Mage::getModel(‘nag/nag’);
$getModel->setNaginTitle($nagin_title);
$getModel->save();
return $getModel;
}
public function getSortColorCategories() {
$collection = Mage::getResourceModel(‘vmfabriccolorcat/vmfabriccolorcat_collection’);
$collection->getSelect()->where(‘status = ?’, 1)->order(‘sort_order’);
return $collection;
}
public function getFabricPartImage($fabricId, $designId, $partId) {
$collection = Mage::getResourceModel(‘vmsuitfabricdesignimage/vmsuitfabricdesignimage_collection’);
$collection->getSelect()->where(‘fabric_id = ?’, $fabricId)->where(‘design_id = ?’, $designId)->where(‘part_id = ?’, $partId);
$data = $collection->toArray();
$fabricImage = (isset($data['items'][0]['filename'])?$data['items'][0]['filename']:”);
return $fabricImage;
}
}
9)-view query in magento or coding of action script in magento
<h4><?php echo $this->__(‘Module List’) ?></h4>
<?php
/*
This shows how to load specific fields from a record in the database.
1) Note the load(15), this corresponds to saying “select * from table where table_id = 15″
2) You can then just use the get(fieldname) to pull specific data from the table.
3) If you have a field named news_id, then it becomes getNewsId, etc.
*/
/* fetch all ID Record*/
$raj = Mage::getModel(‘nag/nag’)->nagmani();
foreach($raj as $ne){
echo $ne['nag_id'].’—’;
echo $ne['content'].’—<br/>’;
}
/* fetch single ID Record*/
/*
$news = Mage::getModel(‘nag/nag’)->load(2);
echo $news->getNewsId();
echo $news->getTitle();
echo $news->getContent();
echo $news->getStatus().’——–1<br/>’;
/*
This shows an alternate way of loading datas from a record using the database the “Magento Way” (using blocks and controller).
Uncomment blocks in /app/code/local/Namespace/Module/controllers/IndexController.php if you want to use it.
*/
/* record show single record from controller*/
$object = $this->getNag();
echo ‘id: ‘.$object['nag_id'].’<br/>’;
echo ‘title: ‘.$object['title'].’<br/>’;
echo ‘nagin_title: ‘.$object['nagin_title'].’<br/>’;
echo ‘content: ‘.$object['content'].’<br/>’;
echo ‘status: ‘.$object['status'].’<br/>’;
/*
This shows how to load multiple rows in a collection and save a change to them.
1) The setPageSize function will load only 5 records per page and you can set the current Page with the setCurPage function.
2) The $collection->walk(‘save’) allows you to save everything in the collection after all changes have been made.
*/
$i = 0;
$collection = Mage::getModel(‘nag/nag’)->getCollection();
$collection->setPageSize(5);
$collection->setCurPage(2);
$size = $collection->getSize();
$cnt = count($collection);
foreach ($collection as $item) {
$i = $i+1;
$item->setTitle($i);
echo $item->getTitle();
}
$collection->walk(‘save’);
/*
This shows how to load a single record and save a change.
1) Note the setTitle, this corresponds to the table field name, title, and then you pass it the text to change.
2) Call the save() function only on a single record.
*/
$object = Mage::getModel(‘nag/nag’)->load(1);
$object->setTitle(‘This is a changed title’);
$object->save();
?>
10:) block query in magento
<?php
class Sapera_Nag_Block_Nag extends Mage_Core_Block_Template
{
public function _prepareLayout()
{
return parent::_prepareLayout();
}
public function getNag()
{
if (!$this->hasData(‘nag4′))
{
$this->setData(‘nag4′, Mage::registry(‘nag4′));
}
return $this->getData(‘nag4′);
}
}
11- controller coading in magento
<?php
class Sapera_Nag_IndexController extends Mage_Core_Controller_Front_Action
{
public function indexAction()
{
/*
* Load an object by id
* Request looking like:
* http://site.com/nag?id=15
* or
* http://site.com/nag/id/15
*/
if(isset($_REQUEST['submit']))
{
echo $title=$_REQUEST['title'];
echo $nagin_title=$_REQUEST['nagin_title'];
echo $filename=’index.jpg’;
echo $content=$_REQUEST['content'];
echo $status=$_REQUEST['status'];
echo $submit=$_REQUEST['submit'];
$rajh = Mage::getModel(‘nag/nag’)->nagVish($title,$nagin_title,$filename,$content,$status);
}
$nag_id = $this->getRequest()->getParam(‘id’);
if($nag_id != null && $nag_id != ”) {
$nag = Mage::getModel(‘nag/nag’)->load($nag_id)->getData();
} else {
$nag = null;
}
/*
* If no param we load a the last created item
*/
if($nag == null) {
$resource = Mage::getSingleton(‘core/resource’);
$read= $resource->getConnection(‘core_read’);
$nagTable = $resource->getTableName(‘nag’);
$select = $read->select()
->from($nagTable,array(‘nag_id’,'title’,'nagin_title’,'content’,'status’))
->where(‘status = ?’,1)
->order(‘created_time DESC’) ;
$nag = $read->fetchRow($select);
}
Mage::register(‘nag4′, $nag);
$this->loadLayout();
$this->renderLayout();
}
}
11-Short path for site folder
1-media url= pup/media:-
img src=”{{media url=”buying.png”}} http://uni-50.com/pup/media/buying.png
————————
2-store url= pup/index.php/nag
<li><a href=”{{store url=”"}}nag”>Product Item</a></li>
http://uni-50.com/pup/index.php/nag
12:-How to know whether a customer is logged in or not
Answer) the code below will give a boolean value which will tell whether customer is logged in. The advantage of code is it can be used in all files of magento to get whwther a customer is logged in or not
Mage::getSingleton(‘customer/session’)->isLoggedIn();
13)Retrieve Customer’s name which is login
The query below will give you name of customer which is logged in.The advantage of code is it can be used in all files of magento to get whwther a customer is logged in or not
Mage::helper(‘customer’)-> getCustomerName();
14)How to know whether Paypal Module is Enabled or not
The below code tells whether paypal module is enabled or not
$modules =Mage::getConfig()->getNode(‘modules’)->();$modulesArray =(array)$modules;
if(isset($modulesArray['Mage_Paypal')){
echo "Paypal module exists.";}else{
echo"Paypal module doesn't exist.";
}
This code is to be placed inside a block tag in xml whereever appropriate
15)How to get current category object and current product object in magento coding
By below code we can get current category object and then we can get various parameters
Mage::registry('current_category');
By below code we can get current product object and then we can get various parameters
return Mage::registry('current_product')
<div class="cmspro_news_summary">Sometimes you may want to change default text in Magento, for example from "My cart" to "My basket", or even change the text into your native language. </div> </div> <div class="cmspro_clear"> </div> <div class="cmspro_news_content"><p> <link href="file:///C:%5CDOCUME%7E1%5CBUINGO%7E1%5CLOCALS%7E1%5CTemp%5Cmsohtml1%5C01%5Cclip_filelist.xml" rel="File-List"><!--[if gte mso 9]><xml> <w:WordDocument> <w:View>Normal</w:View> <w:Zoom>0</w:Zoom> <w:PunctuationKerning /> <w:ValidateAgainstSchemas /> <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid> <w:IgnoreMixedContent>false</w:IgnoreMixedContent> <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText> <w:Compatibility> <w:BreakWrappedTables /> <w:SnapToGridInCell /> <w:WrapTextWithPunct /> <w:UseAsianBreakRules /> <w:DontGrowAutofit /> </w:Compatibility> <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel> </w:WordDocument> </xml><![endif]–><!–[if gte mso 9]><xml> <w:LatentStyles DefLockedState=”false” LatentStyleCount=”156″> </w:LatentStyles> </xml><![endif]–><style type=“text/css”> <!– /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-parent:”"; margin-top:0in; margin-right:0in; margin-bottom:10.0pt; margin-left:0in; line-height:115%; mso-pagination:widow-orphan; font-size:11.0pt; font-family:Arial; mso-fareast-font-family:Arial; mso-bidi-font-family:”Times New Roman”; mso-ansi-language:VI; mso-fareast-language:EN-US;} p {mso-style-noshow:yes; mso-margin-top-alt:auto; margin-right:0in; mso-margin-bottom-alt:auto; margin-left:0in; mso-pagination:widow-orphan; font-size:12.0pt; font-family:”Times New Roman”; mso-fareast-font-family:”Times New Roman”; mso-ansi-language:VI; mso-fareast-language:VI;} @page Section1 {size:8.5in 11.0in; margin:1.0in 1.25in 1.0in 1.25in; mso-header-margin:.5in; mso-footer-margin:.5in; mso-paper-source:0;} div.Section1 {page:Section1;} –> </style><!–[if gte mso 10]> <style> /* Style Definitions */ table.MsoNormalTable {mso-style-name:”Table Normal”; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-parent:”"; mso-padding-alt:0in 5.4pt 0in 5.4pt; mso-para-margin:0in; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:”Times New Roman”; mso-ansi-language:#0400; mso-fareast-language:#0400; mso-bidi-language:#0400;} </style> <![endif]–> </p>
<p><span lang="VI">In <strong>Magento</strong>, you can do that easily with a built-in tool: <strong>Translate inline</strong> . It enables you to make dynamic changes to default text without spending hours working with lines of code. </span></p> <p><span lang="VI">To enable Translate inline text, firstly, go to Admin panel ->System ->Configuration ->Developer ->Translate inline.</span></p> <p><span lang="VI">Then select Yes for Enable for Frontend </span></p> <p><span lang="VI">Now go to frontend and refresh the page. You should see red dotted lined around the text</span><span style="">. Roll mouse over them, a book icon will appear. Click on this and an editor lightbox window will pop up. Change the text as you want and click “submit”. After that, refresh the page. Remember that if your <strong>magento site</strong> is in other languages, you should tick Store View Specific.<o:p></o:p></span></p>
<p><span style="">And you’ve all done.
-->
Sometimes you may want to change default text in Magento, for example from "My cart" to "My basket", or even change the text into your native language.
16)How to enable translate Inline option and it's use in magento
In Magento you can do that easily with a built-in tool: Translate inline. It enables you to make dynamic changes to default text without spending hours working with lines of code.
To enable Translate inline text, firstly, go to Admin panel ->System ->Configuration ->Developer ->Translate inline.
Then select Yes for Enable for Frontend
Now go to frontend and refresh the page. You should see red dotted lined around the text Roll mouse over them, a book icon will appear. Click on this and an editor lightbox window will pop up. Change the text as you want and click “submit”. After that, refresh the page. Remember that if your magento site is in other languages, you should tick Store View Specific.
And you’ve all done.
17)How to use collection functions in magento ?
or
How to write database query interacting magento ?
Here some database interaction functions present in the class Mage_Eav_Model_Entity_Collection_Abstract. These collection functions are used to select data from Magento database.
$collection = Mage::getModel('catalog/product')->getCollection();
Now if we want to select all attributes :-
$collection->addAttributeToSelect('*');
Now if we want to select some specfic attributes
$collection->addAttributeToSelect(''name', 'url_key', 'color');
Now we want to give some condition like to produce a collection with status equals to one
select only those items whose status = 1
$collection->addAttributeToFilter('status', 1);
Using Like statement in select queries
$collection->addAttributeToFilter('sku', array('like' => '%ogi%'));
Using greater than command in select
$collection->addAttributeToFilter('id', array('gt' => 15));
18)How to write custom sql queries in magento ?
By the below way we can write custom sql queries for select
query
getConnection('core_read');
$query = 'SELECT * FROM ' . Mage::getSingleton('core/resource')->getTableName('catalog_product_entity');
$results = $read->fetchAll($query);
print_r($results);
19)How do we move a certain Block in magento from one position to other
This article is written for newsletter block and can be applied simlarly for various other magento blocks.By viewing the following guideline, you can change the position of block newsletter from 'left' to 'right', 'footer' to 'header' or 'right' to 'left' and viceversa. The changes are all carried out within the layout.xml located in app\design\frontend\default\your theme\layout\newsletter.xml
1. You just change the reference name from ‘left’ to ‘right’, or ‘right’ to 'left'
2. Move block newsletter to 'footer' or 'header'
Fistly, you change the reference name to 'footer' or to 'header'
The code is something like
<reference name="left">
<block type="newsletter/subscribe" name="left.newsletter" template="newsletter/subscribe.phtml"/>
</reference>
Now you can change refrence name to right , top etc:-
20)How to Enabling Template path hint and block hints
One very useful way of debugging magento code is to enable path hints for blocks and template. By enabling it we will be able to some hint with red background and white text with template path hint on left of a block and on right path of block name responsible for generating the block
Now we come to how to achieve it. we log in to admin by proper credential then on top menu click on "system" and a dropdown pops up and go extreme down to click "configuration". Then after page opens see the left vertical menu and go extreme down and click on
"developer". then a page loads with certain options. Now go to "Current Configuration Scope" at top left and in that dropdown choose your websites store view. Now on right clicon debug and change the value of "Template Path Hints" and "Add Block Names to Hints" to yes by drop down and clear the cache and then open index.php of your website
21)How to allow more than 5 recipients in the email to a friend section
We have a email to friend link on product page by default just below the product title .On clicking the link we go to "Email to friend" form and we can to maximum 5 recipients . Now to change we log in to admin by proper credential then on top menu click on "system" and a dropdown pops up and go extreme down to click "configuration". Then we go to left vertical menu and under catalog tab click Email to a Friend.Then on right under "Email Template" go to the setting "Max Recipients" which is 5 by default. Now change it then we can get more recipient as desired
