Magento has a very powerful admin configuration system. It allows you to create config forms to be able to configure your custom modules from admin panel, also to enable users to modify it.

t’s quite simple to do – and it should only take you a few minutes to implement this. But, the options are endless. You can add all sorts of custom configurable options that you can edit in the admin panel very easily.

Here my simplified module:

local/SWT/Mymodule/etc/config.xml

<?xml version=”1.0″?>
<config>
<modules>
<SWT_Mymodule>
<version>0.1.0</version>
</SWT_Mymodule>
</modules>
<global>
<models>
<mymodule>
<class>SWT_Mymodule_Model</class>
</mymodule>
</models>
<helpers>
<mymodule>
<class>SWT_Mymodule_Helper</class>
</mymodule>
</helpers>
<resources>
<mymodule_setup>
<setup>
<module>SWT_Mymodule</module>
</setup>
<connection>
<use>core_setup</use>
</connection>
</mymodule_setup>
</resources>
</global>

<adminhtml>
<acl>
<resources>
<admin>
<children>
<system>
<children>
<config>
<children>
<mymodule>
<title>My Module Section</title>
</mymodule>
</children>
</config>
</children>
</system>
</children>
</admin>
</resources>
</acl>
<translate>
<modules>
<SWT_Mymodule>
<files>
<default>SWT.csv</default>
</files>
</SWT_Mymodule>
</modules>
</translate>
</adminhtml>

<default>
<mymodule>
<mymoduleconfig>
<host><![CDATA[localhost]]></host>
<active>1</active>
</mymoduleconfig>
</mymodule>
</default>
</config>

local/SWT/Mymodule/etc/system.xml

<?xml version=”1.0″ encoding=”UTF-8″?>
<config>
<tabs>
<mymodule translate=”label” module=”mymodule”>
<label>SWT</label>
<sort_order>200</sort_order>
</mymodule>
</tabs>
<sections>
<mymodule translate=”label” module=”mymodule”>
<label>My Module</label>
<tab>mymodule</tab>
<frontend_type>text</frontend_type>
<sort_order>102</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<groups>
<schedep translate=”label”>
<label>My Module Settings</label>
<frontend_type>text</frontend_type>
<sort_order>1</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<fields>

<active translate=”label”>
<label>Enabled</label>
<frontend_type>select</frontend_type>
<source_model>adminhtml/system_config_source_yesno</source_model>
<sort_order>1</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>0</show_in_store>
</active>
</fields>
</schedep>
</groups>
</mymodule>
</sections>
</config>

local/SWT/Mymodule/Helper/Data.php

<?php

class SWT_Mymodule_Helper_Data extends Mage_Core_Helper_Abstract {

}

?>

local/SWT/Mymodule/Model/Mymodule.php

<?php

class SWT_Mymodule_Model_Mymodule extends Mage_Core_Model_Abstract
{

protected function _construct()
{
$this->_init(‘mymodule/mymodule’);
}

protected function _beforeSave()
{
return parent::_beforeSave();
}

}

 

Creating a PHP website template starting with HTML and CSS.

The actual template will be created mentioned below steps

Step 1 :

create a new folder and named folder “newwebsite”

Inside of this folder we are now going to create two new files. One is index.html and the other file is going to be named style.css

Step 2 :

Next we are going to create two more folders inside of our main folder “newwebsite”. The first folder is going to be named includes, and the second folder will be named variables.

Step 3 :

create a basic html website document

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>

<meta http-equiv="content-type" content="text/html; charset=utf-8" />

<meta name="description" content="" />

<meta name="keywords" content="" />

<meta name="author" content="" />

<link rel="stylesheet" type="text/css" href="style.css" media="screen" />

<title>SMARTWEBTUTORIALS Template</title>

</head>

	<body>

		<div id="wrapper">

<div id="header">

</div> <!-- end #header -->

<div id="nav">

</div> <!-- end #nav -->

<div id="content">

</div> <!-- end #content -->

<div id="sidebar">

</div> <!-- end #sidebar -->

<div id="footer">

</div> <!-- end #footer -->

		</div> <!-- End #wrapper -->

	</body>

</html>

Step 4:

open up the style.css file and add the divs we will be using.

This is the CSS I am adding to the stylesheet:

body {
background-color:#f1f1f1;
font-family: georgia,sans-serif;
color:#333;
margin:0;
padding:0;
}

#wrapper {
width:960px;
background-color:#f8f8f8;
margin:0 auto;
border-left:1px solid #ccc;
border-right:1px solid #ccc;
}

#header {
width:960px;
height:135px;
margin:0 auto;
margin-bottom:25px;
border-bottom:1px solid #ccc;
border-top:1px solid #ccc;
}

#header h2 {
padding:10px;
}

#nav {
width:960px;
height:40px;
border-bottom:1px solid #ccc;
}

#nav a {
display:inline;
padding:10px;
text-decoration:none;
background-color:#f1f1f1;
}

#nav a:hover {
background-color:#bababa;
height:80px;
}

#content {
width:675px;
float:left;
padding:10px;
}

#sidebar {
width:200px;
float:right;
margin-bottom:25px;
}

#sidebar a {
text-decoration:none;
}

#sidebar li {
list-style:none;
}

#footer {
clear:both;
width:960px;
height:135px;
border-top:1px solid #ccc;
}

#footer p {
padding:10px;
}

Step 5:

create some more files under includes folder

header.php, nav.php, sidebar.php, footer.php

Step 6:

 

sending Magento order confirmation emails for orders placed  using order id.

<?php
require ‘app/Mage.php’;
Mage::app(‘admin’)->setUseSessionInUrl(false);
//replace your own orders numbers here:
$test_order_id = ‘100000014’;

$order = Mage::getModel(‘sales/order’)->loadByIncrementId($test_order_id);

if ($order->getId()) {
try {
$order->sendNewOrderEmail();
echo “Order $orderIncrement successfully sent\n”;
} catch (Exception $e) {
echo $e->getMessage();
}
} else {
echo “Order $orderIncrement not found\n”;
}

 

?>

If you want to protect your Magento backend against attackers, you can follow below mentioned steps to change your admin url/path.

Follow these steps to change the admin URL/path.

Step1 :

First, open the local.xml configuration file in your favorite text editor, or use the Text Editor in the cPanel File Manager. The file is usually located in the app/etc/ directory under your Magento installation. Locate the following code segment:

<admin>
<routers>
<adminhtml>
<args>
<frontName><![CDATA[admin]]></frontName>
</args>
</adminhtml>
</routers>
</admin>

 

Now, replace admin with your new admin path. This should be something personal which is hard to guess, use only letters or numbers – no special characters, then save the file.

Step 2 – Refresh Cache

The final step is to refresh your cache. Use an FTP client to delete the content of the var/cache/ directory, or use the following SSH command.

rm -rf var/cache/*

Step 3

The change is now complete and you should try to log in via the new admin url – http://domain/adminpath/, replacing ‘adminpath’ with the path you chose in the step above. If everything went fine, you should now be presented with the Admin Panel login screen at the new URL. The old admin login URL should return a 404 error message.

1. Explain Magento’s MVC architecture

First of all, what is MVC?
MVC stands for Model-View-Controller. Any application that separates it’s data access, business logicand user interface is called MVC. There can be two types of MVC: convention-based and configuration-based. Example, cakePHP is convention-based, i.e. you just need to follow the instructions of the core system to get your module ready in just few lines. Magento is configuration-based, i.e. you need to specify each and every thing to your module’s config file in order to get it work. Magento has Controller (for Routing), Block (for Business Logic), Model (for DB access, sql) and Template file (for Presentation i.e. View).

How Magento’s MVC works:
1. When you enter the URL (something like http://mysite.com/frontname/controller/method/param1/value1/param2/value2), this URL is intercepted by one PHP file called index.php which instantiates Magento application
2. Magento application instantiates Front Controller object
3. Further, front controller instantiates Router objects (specified in module’s config.xml, global tag)
4. Now, Router is responsible to “match” the frontname which is in our URL
5. If “match” is found, it sees controller name and method name in the URL, which is finally called.
6. Now depending on what is written in action name (method name), it is executed. If any models are called in it, the controller method will instantiate that model and call the method in it which is requested.
7. Then the controller action (method) instantiate the Layout object, which calls Block specified for this action (method) name (Each controller action name have block and template file associated with it, which can be found at app/design/frontend or adminhtml/namespace/module/layout/module.xml file, name of layout file (module.xml) can be found in config.xml of that module, in layout updates tag).
8. Template file (.phtml) now calls the corresponding block for any method request. So, if you write $this->methodName in .phtml file, it will check “methodName” in the block file which is associated in module.xml file.
9. Block contains PHP logic. It references Models for any data from DB.
10. If either Block, Template file or Controller need to get/set some data from/to database, they can call Model directly like Mage::getModel(‘modulename/modelname’).

More Magento Questions with answers

Q 1. What is Magento?
Ans. Magento is a feature-rich eCommerce platform built on open-source technology that provides online merchants with unprecedented flexibility and control over the look, content and functionality of their eCommerce store. Magentos intuitive administration interface features powerful marketing, search engine optimization and catalog-management tools to give merchants the power to create sites that are tailored to their unique business needs. Designed to be completely scalable and backed by Variens support network, Magento offers companies the ultimate eCommerce solution.

Q 2. What is the difference between Mage::getSingletone() andMage::getModel() in Magento
Ans. Mage::getSingletone() always finds for an existing object if not then create that a newobject but Mage::getModel() always creates a new object.

Q 3. Why Magento use EAV database model ?
Ans. In EAV database model, data are stored in different smaller tables rather than storing in asingle table.product name is stored in catalog_product_entity_varchar tableproduct id is stored in catalog_product_entity_int tableproduct price is stored in catalog_product_entity_decimal tableMagento Use EAV database model for easy upgrade and development as this model givesmore flexibility to play with data and attributes.

Q 4. How to upgrade to the latest version using Magento Connect?
Ans. Upgrading Magento to the latest version is a fairly simple task. Copy and Paste this key magento-core/Mage_All_Latest VIA Magento Connect where it states Paste extension key to install:. This will upgrade Magento to the newest version.

Q 5. Explain about the Modules of Magento?
Ans. Magento supports installation of modules through a web-based interface accessible through the administration area of a Magento installation. Modules are hosted on the Magento eCommerce website as a PEAR server. Any community member can upload a module through the website and is made available once confirmed by a member of the Magento team. Modules are installed by entering a module key, available on the module page, into the web based interface.

There are three categories of modules hosted on Magento Connect:

Core Modules
Community Modules
Commercial Modules
Core and Community modules can be installed via the administration area. Commercial module pages provide price information and a link to an external website.

Q 6. What technology used by Magento?
Ans. Magento uses PHP as a web server scripting language and the MySQL Database. The data model is based on the Entity-attribute-value model that stores data objects in tree structures, thus allowing a change to a data structure without changing the database definition.

Q 7. What is MVC structure in Magento?
Ans. The Model-View-Controller (MVC) architecture traces its
origins back to the Smalltalk Programming language and Xerox
Parc. Since then, there have been many systems that describe
their architecture as MVC. Each system is slightly
different, but all have the goal of separating data access,
business logic, and user-interface code from one another.

Q 8. What is benefit of namespace (package) in magento?
Ans. We can have more than one module with same name but they should be placed in different namespaces. All magento core modules are contained in mage namespace.
core/Mage/Catalog

and all custom modules are placed in

local/CustomModule

Q 9. How to include CMS block in template file(.phtml)?
Ans. Access block’s content from .phtml template file by :

echo $this->getLayout()->createBlock(‘cms/block’)->setBlockId(‘static_block_id’)->toHTML();

Q 10. How to add an external javascript/css file to Magento?
Ans.
css/yourstyle.css
or
skin_jsjs/ yourfile.js
skin_csscss/yourstyle. css

Q 11. What are handles in magento (layout)?
Ans. Handles are basically used for controlling the structure of the page like which block will be displayed and where. First level child elements of the node are called layout handles. Every page request can have several unique Handles. The handle is called for every page. handle for products belongs to virtual product type, PRODUCT_TYPE_simple is called for product details page of simple product type and PRODUCT_TYPE_virtual is called for the virtual product detail page and customer_logged_in handle is called only if customer is logged in. The muster_index_index handle is created by combining the frontName (muster), Action Controller (index), and Action Controller Action Method (index) into a single string and this handle will be called only when /zag/index/index url is accessed.

Q 12. What is in magento?
Ans. The routers tag allow us to decide frontname for each module. The tag is defined in config.xml file of module. For Namespace_MyModule frontname is moduleurl so the url will be like :
websiteurl.com/moduleurl/controllername/actionname

standard
Namespace_MyModule
moduleurl

Q 13. Which factors affect performance of magento?

Ans.
1. EAV structure of magento database, even for retrieving single entity the query becomes very complex .
2. Magento’s template system involves a lot of recursive rendering
3. Huge XML trees built up for layout configuration, application configuration settings

Q 14. How to improve magento performance?
Ans.

Enabled magento caching
MySQL Query caching
Enable Gzip Compression
Disable any unused modules
Disable the Magento log
Optimise your images
Combine external CSS/JS into one file
Enable Apache KeepAlives: Make sure your Apache configuration has KeepAlives enabled.

Q 15. How to get the Total Price of items currently in the Cart?
helper(‘checkout’)->formatPrice(Mage::getSingleton(‘checkout/cart’)->getQuote()->getGrandTotal()); ?>

Q 16. How to set different themes for logged in users?
if(Mage::getSingleton(‘customer/session’)->isLoggedIn()):
Mage::getDesign()->setPackageName(‘package_name’)->setTheme(‘themename’);
endif;

Q 17. How to create magento custom module?
Ans. Steps to create custom magento module:
Namespace : Zag
Module Name : Mymodule
1. Create directory Mymodule in app/code/local/Zag
2. Create Block, controllers, etc, Module directories. Create controller, block and module file as required.
3. Create module configuration file (app/code/local/Zag/Mymodule/etc/config.xml).
4. Create xml file (app/etc/modules/Zag_ Mymodule.xml)to enable/disable module and tell magento system from which code pool that module will be taken.

Q 18. How to set different themes for each store?
Ans. Go to : System>Designs
Then, add new design change or edit existing. You can select Store and Custom Design.

Q 19. How to make product’s custom attribute searchable in adavance search?
Ans. Go to : Catalog > Attribues > Manage Attribues
Edit the attribute and select “Yes” for Use in Advanced Search.

Q 20. How to fetch 5 bestsellers products programmatically?
Ans.
Mage::getResourceModel(‘reports/product_collection’)
->addOrderedQty()
->addAttributeToSelect(‘*’)
->setPage(1, 5)
->load();