Wednesday, November 30, 2011

Magento: Exception printing is disabled by default for security reasons

When I go to any product detail page, I get the following error:-
    There has been an error processing your request
    Exception printing is disabled by default for security reasons.

I don’t get the detailed information about the error as I used to get in previous versions of Magento.
Solution:
In your magento root, there is a folder called errors.
Go inside the errors folder.
There is a file named local.xml.sample.
Rename it to local.xml
Hence, the problem is solved. Now, I am able to see detailed error information.

Thursday, November 24, 2011

Custom Module


List of created files:
app/etc/modules/Flexsin_Helloworld.xml
app/code/local/Flexsin/Helloworld/Block/Helloworld.php
app/code/local/Flexsin/Helloworld/controllers/IndexController.php
app/code/local/Flexsin/Helloworld/etc/config.xml
app/code/local/Flexsin/Helloworld/Model/Helloworld.php
app/code/local/Flexsin/Helloworld/Model/Mysql4/Helloworld.php
app/code/local/Flexsin/Helloworld/Model/Mysql4/Helloworld/Collection.php
app/code/local/Flexsin/Helloworld/Model/Status.php
app/code/local/Flexsin/Helloworld/sql/helloworld_setup/mysql4-install-0.1.0.php
app/design/frontend/flexsin/default/layout/helloworld.xml
app/design/frontend/flexsin/default/template/helloworld/helloworld.phtml
app/code/local/Flexsin/Helloworld/Block/Adminhtml/Helloworld.php
app/code/local/Flexsin/Helloworld/Block/Adminhtml/Helloworld/Edit.php
app/code/local/Flexsin/Helloworld/Block/Adminhtml/Helloworld/Grid.php
app/code/local/Flexsin/Helloworld/Block/Adminhtml/Helloworld/Edit/Form.php
app/code/local/Flexsin/Helloworld/Block/Adminhtml/Helloworld/Edit/Tabs.php
app/code/local/Flexsin/Helloworld/Block/Adminhtml/Helloworld/Edit/Tab/Form.php
app/code/local/Flexsin/Helloworld/controllers/Adminhtml/HelloworldController.php
app/code/local/Flexsin/Helloworld/Helper/Data.php
app/design/adminhtml/flexsin/default/layout/helloworld.xml

Wednesday, November 23, 2011

Magento Files and Folders Structure


The files and folders included in the main directory are as follows:
.htaccess - contains mod_rewrite rules, which are essential for the Search Engine Friendly URLs. There you can also find standard web server and php directives that can improve your web site performance.

.htaccess.sample - this is a backup of the .htaccess file. If you modify .htaccess it can be used in order to get the default settings.

404 (directory) - The folder stores the default 404 template and skin for Magento.

app (directory) - This folder contains the modules, themes, configuration and translation files. Also there are the template files for the default administration
theme and the installation.

cron.php - a Cron Job should be set for this file. Executing of the file on a defined time period will ensure that the complicated Magento caching system will not affect the web site performance.

downloader (directory) - This is the storage of the web downloader files. They are used for the installation and upgrade of Magento through your browser.

favicon.ico - the default favicon for Magento. A small icon that is shown in the browser's tool bar once your web site is loaded.

index.php - the main index file for Magento.

index.php.sample - A backup of the default index file. It can be used to revert the changes in a case of a index.php modification.

js (directory) - Contains the pre-compiled libraries of the JavaScript code included in Magento.

lib (directory) - The Magento core code is located in this folder. It contains the software's PHP libraries.

LICENSE_AFL.txt - The Academic Free License under which the Magento software is distributed.

LICENSE.txt - The Open Software License under which the Magento software is distributed.

media (directory) - This is the storage of the Magento media files - images out of the box, generated thumbnails, uploaded products images. It is also used as a container for importing images through the mass import/export tools.

pear - The file controls the automatic update through the downloader script and SSH. It handles the update of each individual Magento module.

php.ini.sample - This file contains sample php directives that can be used in order to modify your PHP setup. If you want to alter the default setup edit the file and then rename it to php.ini.

pkginfo (directory) - Contains files with information regarding the modules upgrades' changes.

report (directory) - This folder contains the skin of the Magento errors reports.

skin (directory) - There are located the themes files - images, JavaScript files, CSS files, Flash files. Also there can be found the skin files for the installation of skins and administration templates.

var (directory) - Cache, sessions, database backups, data exports and cached error reports can be found in this directory.

If you want to modify an existing template or set a new one you should know that the template files are separated in 3 folders:
/app/design/frontend/default/YOUR_TEMPLATE_NAME/layout/ - Contains the .xml files that define which modules should be called by the template files and loaded in defined areas on the site.
/app/design/frontend/default/YOUR_TEMPLATE_NAME/template/ - Contains files and subfolders that structure the final output for the users using the functions located in the layout/ folder.
/skin/frontend/default/YOUR_TEMPLATE_NAME/ - Contains the CSS, images, JavaScript and Flash files related to the template.

Adding and removing javascript / css when and where you need it


Adding and removing javascript and css is handled separately within Magento. CSS is added in the usual fashion, where you have a <link rel=”stylesheet”… />. However, any included javascript (unless linked to “by hand” from a theme’s skin) is pulled via a php files which reads through the “js” folder in the root directory (root/js/index.php is responsible for this).
That is all well and good for Magento. The real question is how we, as developers, add these items when we need them. How you as a developer add css or javascript is, luckily, handled the same.
In this post, we will show how to add and remove javascript and css to a CMS page (and anywhere else) that you may need.
Method 1: Layout xml.
a) For files you want to include on every page
For css or js files you want to add to every page, you edit the page. xml files located in your layout folder (app/design/frontend/default/your_theme/layout/page.xml). Within this file, at the top you will find the <default> area with the <block name=”root” … >. This block has a child named “head” which contains the included css and js elements.


<block type="page/html_head" name="head" as="head">
<action method="addJs"><script>prototype/prototype.js</script></action>
<action method="addJs" ifconfig="dev/js/deprecation"><script>prototype/deprecation.js</script></action>
<action method="addJs"><script>prototype/validation.js</script></action>
<action method="addJs"><script>scriptaculous/builder.js</script></action>

...

</block>
Here you can add your javascript and css. Note that any Js files you add are relative to the “js” folder in your root directory. The css files are included from the skin files of the current and default templates (skin/frontend/default/your_template(& default)/css).
b) Specific areas
If you want to include css or js on only certain areas (such as the checkout process or catalog pages), you can do that also. For instance, if you want it in a single product view (product view vs product list), you can open up catalog.xml, find <catalog_product_view> area (near line 168 in vs 1.2.1).  Add your code in there – notice that we are using the <reference> tag rather than <block> tags. We use the “reference” tag to reference other blocks that are in other areas of the template.


<reference name="head">
<action method="addJs"><script>varien/product.js</script></action>

<action method="addItem"><type>js_css</type><name>calendar/calendar-win2k-1.css</name><params/><!--<if/><condition>can_load_calendar_js</condition>--></action>
<action method="addItem"><type>js</type><name>calendar/calendar.js</name><!--<params/><if/><condition>can_load_calendar_js</condition>--></action>
<action method="addItem"><type>js</type><name>calendar/lang/calendar-en.js</name><!--<params/><if/><condition>can_load_calendar_js</condition>--></action>
<action method="addItem"><type>js</type><name>calendar/calendar-setup.js</name><!--<params/><if/><condition>can_load_calendar_js</condition>--></action>
</reference>

The use of can also be used in your layout XML areas in the admin backend (CMS pages, category and product designs). This can accomplish the same thing, as well as adding or removing other blocks.
Method 2: Block Code
We can accomplish all of this in code as well. These functions are defined within Mage_Page_Block_Html_Head. So, we can use this code with in a block class (not a .phtml file!):

$headBlock = $this->getLayout()->getBlock('head');
$headBlock->addJs('somefolder/yay.js');

I suggest looking over the page. xml file as long as finding the removeItem syntax ($type, $name for the method, for the xml), which will be very handy for you for adding or removing assets as and when you need them!
<action method="removeItem"><type>js</type><name>calendar/calendar.js</name</action>

$this->getLayout->getBlock('head')->removeItem('js', 'calendar/calendar.js');


Adding and removing javascript / css when and where you need it


Adding and removing javascript and css is handled separately within Magento. CSS is added in the usual fashion, where you have a <link rel=”stylesheet”… />. However, any included javascript (unless linked to “by hand” from a theme’s skin) is pulled via a php files which reads through the “js” folder in the root directory (root/js/index.php is responsible for this).
That is all well and good for Magento. The real question is how we, as developers, add these items when we need them. How you as a developer add css or javascript is, luckily, handled the same.
In this post, we will show how to add and remove javascript and css to a CMS page (and anywhere else) that you may need.
Method 1: Layout xml.
a) For files you want to include on every page
For css or js files you want to add to every page, you edit the page.xml files located in your layout folder (app/design/frontend/default/your_theme/layout/page.xml). Within this file, at the top you will find the <default> area with the <block name=”root” … >. This block has a child named “head” which contains the included css and js elements.

Saturday, November 19, 2011

web services using php as JSON format


Create a php file with following code:

$hostname="localhost";
$username="bhoopendra";
$password="";
$database="my_db";
$table='comment';
$con=mysql_connect($hostname, $username, $password) or die(mysql_error());
mysql_select_db($database, $con) or die(mysql_error());
$result=mysql_query("SELECT * FROM ".$table) or die(mysql_error());

while($row = mysql_fetch_assoc($result)) {
$data[]=$row;
 
}

$file=fopen("web.xml", "w");
if(fwrite($file,json_encode($data))){
//header('location: web.xml');
}

web services using php as xml format


Create a php file with following code:
$hostname="localhost";
$username="bhoopendra";
$password="";
$database="my_db";
$table='comment';
$con=mysql_connect($hostname, $username, $password) or die(mysql_error());
mysql_select_db($database, $con) or die(mysql_error());
$result=mysql_query("SELECT * FROM ".$table) or die(mysql_error());
$doc = new DomDocument('1.0');
$root = $doc->createElement('root');
$root = $doc->appendChild($root);

while($row = mysql_fetch_assoc($result)) {
$occ = $doc->createElement($table);
  $occ = $root->appendChild($occ);
  foreach ($row as $fieldname => $fieldvalue) {
$child = $doc->createElement($fieldname);
$child = $occ->appendChild($child);
$value = $doc->createTextNode($fieldvalue);
$value = $child->appendChild($value);
 }
}
$xml_string = $doc->saveXML();
//echo $xml_string;
$file=fopen("web.xml", "w");
if(fwrite($file,$xml_string)){
header('location: web.xml');
}