What are “magic methods” in Magento?

Magento uses :

__call(), __get(), __set(), __uns(), __has(), __isset(), __toString(), __construct(), etc. magic methods.

You can find more details inside class Varien_Object
For more information about magic methods:


http://php.net/manual/en/language.oop5.magic.php

How to run Custom Mysql Query in Magento?

 Magento uses Zend framework in very standard manner . It uses singleton methodology to access database.Like many other standard frameworks Magento also uses the concept of ORM (Object Relation Model) approach. To access the database Magento uses resource model where each magento model is divided into two categories
1. Active Record type
2. EAV (Entity Attribute Value) Model
With this resource model we can manipulate the data from our database.
But still if we want to run our own custom mysql query Magento provides a way to do this also. Here are the way to do


Because we need to read the data then we will get connection for core_read.
Suppose you need to insert some data into database then you need to take core_write.

$db = Mage::getSingleton('core/resource')->getConnection('core_read');
//Write your mysql query here
$result = $db->query("SELECT * FROM customerhistory WHERE customer_id = ".$customer->getId()." AND status <> 0 ORDER BY created_time DESC LIMIT 0,100");
//After running check whether data is available or not
if(!$result) {
echo 'No data found';
}
else
{
//Here we are fetching the data
while ($row = $result->fetch(PDO::FETCH_ASSOC))
{
echo $row["content"];
}
}

What Are Blocks in Magento?

In the Magento architecture, a "Block" is one of the first class elements in the structure of Magento layouts. Every page in Magento is decorated by the "Layouts" file and the content is filled up by the "Blocks" of the different modules. Magento blocks are a really powerful and flexible way to plug­ your content into the already existing layouts. On the other hand, you could also use layout XML files to easily remove or Reposition any existing blocks.
We could say that "Structural Blocks" are the containers holding the "Content Blocks". Structural blocks themselves don't have any actual content to display, but they in turn display the content blocks at the end. As the name suggests, they're used to structure the content of the whole page.
For example, "Header", "Footer", "Left" and "Right" are structural blocks in Magento. "Content blocks" are assigned to the different structural positions of the layout of the Magento page, which in turn displays the actual content of the content blocks.
"Content Blocks" are the real fire power, generating the actual content for the display. As we've just discussed in the previous section, you need to assign the content block to one of the structural blocks for the front­-end display. There are some other ways which allow us to insert the content blocks using short codes, but we'll see more on that later.
Content blocks can be of any form, from a simple static content block to a list of the most recent products on the home page! In fact, the majority of the content is generated by the content blocks spread all over the different modules in Magento.
We're going to develop a very basic custom Magento module for the development of our custom block. Our custom block will be a simple block displaying the most recent products available in the store.
I assume that you're familiar with the basic structure and conventions of the Magento module files. Now, let's see the file structure we'll need to implement for our custom block.
  • app/etc/modules/Envato_All.xml: It's a file used to enable our custom module.
  • app/code/local/Envato/Recentproducts/etc/config.xml: It's a module configuration file.
  • app/code/local/Envato/Recentproducts/Model/Recentproducts.php: It's a model file which provides the array of most recent products.
  • app/code/local/Envato/Recentproducts/Block/Recentproducts.php: It's the main block file for our custom block.
  • app/design/frontend/default/default/template/recentproducts/recentproducts.phtml: It's a template file which contains the XHTML-related stuff.

How To Add Lightbox To Magento Theme.

Steps To Add Lightbox To Magento Theme (Prerequisites)

Following are the steps to add Lightbox to your Magento Theme

Download Lightbox from here :

 Make a directory called /lightbox under /skin/frontend/default/default/js/ and copy the entire lighbox code under that directory. Once done, your directory will look like /skin/frontend/default/default/js/lightbox (all code under this directory)
    copy the lightbox.js under /magento/js/lightbox (create a folder under js directory and name it lightbox). If you installation is under root directory then copy it under /root/js/lightbox
    Now, you should copy the lightbox.css to /skin/frontend/default/default/css directory.
    Create a folder called lightbox under /skin/frontend/default/default/images. Your directories for images will finally look like /skin/frontend/default/default/images/lightbox. Copy all the images from source lightbox directory here.

Download Magento files.

Magento Community Edition : 

Here you can get the all data about Magento download with latest versions, Release archieve and You can learn how to get starts with magento.

https://www.magentocommerce.com/download


Hope you got.

Accordion tabs in magento For layered navigation

Hi ,
In this blog I’m going to explain you how to create accordion tabs in magento for layered navigation as displayed below for attributes.


Just navigate to your layered navigation file as shown:

app/design/frontend/default/{your folder}/template/catelog/layer/view.phtml


Then open that that file & paste the following jquery script at the end of the page:



<script>var $j= jQuery.noConflict();// no conflict method
$j (document).ready(function(){
$j("#narrow-by-list > dt").click(function(){
if(false == $j(this).next().is(':visible')) {
$j('#narrow-by-list dd').slideUp(300);
}
$j(this).next().slideToggle(300);
});
$j('#narrow-by-list dd').hide();
$j('#narrow-by-list dd:eq(0)').show();
});
</script>
 
 
NOTE: 
 
#narrow-by-list is the id used in that file( <dl id=”narrow-by-list“>).
 If you used different id’s, replace this with your id and save the 
file. Refresh the cache and reload the browser to see the results. Use 
no-conflict method in magento. It is a good practice to avoid javascript
 conflicts in the page.

Magento install error - Exception printing is disabled

Here is a known error which can occur when installing Magento:

There has been an error processing your request
Exception printing is disabled by default for security reasons.
Error log record number: XXXXXXX

Here is the solution:
  1. Navigate to the "errors" folder.
  2. Change local.xml.sample to local.xml
  3. You should now see a new list of crazy errors all over the Magento page - this is okay.
  4. Open magento/lib/Zend/Cache/Backend/File.php and look for:  
     protected $_options = array(
    'cache_dir' => 'null',   
  5. Change it to: 
     protected $_options = array(
    'cache_dir' => 'tmp/',  
  6. Save it.
  7. Now the final step is to go create a tmp folder in the root Magento folder.
  8. That's it.

Magento : 404 error is showing admin page

Hello, Sometimes we may get the error on admin page once done with the Magento installation. In that scenario, we have to do the following: ...