Magento – Database Queries

Share
Posted on May 11th, 2013 | Posted by admin

Magento is a complete and awesome MVC application. It’s fully moduler and easy to extend its features and functionality. All the CRUD operations are performed using the modules, model classes. But many a time it requires a developer to execute the db query in traditional form.

Here is the list of methods and queries.

In magento to Read or Write any query we need database connection.

<?php
//database read adapter
$read = Mage::getSingleton('core/resource')->getConnection('core_read')
//database write adapter
$write = Mage::getSingleton('core/resource')->getConnection('core_write');
?>

These connections return special instances of the Mage_Core_Model_Resource class, that contains functions used to execute raw Database Queries.

Magento language pack installation

Share
Posted on May 10th, 2013 | Posted by admin

Installing a second language in magento is easy as long as you follow the next steps:

1. download language files and place them into the right folders (app > local)
2. Login to admin panel and go to System > Manage stores
3. Create a new store view
4. Login to admin panel and go to System > Configuration > General
and select each store view from “Current Configuration Scope” drop down menu at the upper left corner of the window.
Set the corresponding locale for each store view

How to Clean Magento Cache Properly

Share
Posted on May 9th, 2013 | Posted by admin

One of the most important tasks you need to remember after each major change (and before Magento upgrade) is to clean up your Magento cache.

  1. Login to Admin Panel
  2. Go to System Cache Management
  3. Select all Cache Types, choose Refresh from the Action dropdown and click on Submit button
  4. Click on Flush Magento Cache
  5. Click on Flush Cache Storage
  6. Click on Flush Catalog Images Cache
  7. Click on Flush JavaScript/CSS Cache

Magento custom form validation

Share
Posted on May 8th, 2013 | Posted by admin

Custom validation method

Adding a new validation rule into a form in Magento is easy as adding a “required” class for a input form. While existing validation rules can be seen in file js/prototype/prototype.js there is an easy way to add your own validation rule.

Add following inline JavaScript into template or load it in separate file.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<script type="text/javascript">
//<![CDATA[
Validation.add('required-classname','<?php echo __('Please enter valid value.'); ?>',function(value){
if(value == null)
{
return false;
}
/*
* Your code here
* Return true if you like the value
*/
});
//]]>
</script>

First parameter is the classname for your input element. The second parameter is the error message for invalid input. Third parameter is a function where your code lies. The function should return false on invalid value.

How to determine Store ID for multi-type Magento site

Share
Posted on May 7th, 2013 | Posted by admin

Here is a quick reference for you, if you run Magento under Multi-language, Multi-Currency or Multi-Domain (Multi-Website).

Sometime you need pick up the Store ID do some (IF…ELSE…) work. Here is the code:

1
<?php $store_id = $this->helper('core')->getStoreId(); echo $store_id; ?>
Page 3 of 154«12345»102030...Last »