Social Icons

twitterfacebookgoogle pluslinkedinemail

Thursday, 11 April 2013

Encode or Decode url in magento

you want to encode url very simple friend just simnple write following code and you can Encode url.

$url = "" ;


you want to decode url very simple friend just simnple write following code and you can Decode url.


How to get all post data from wordpress using custom query

get all post using custom or select query using following code
 $querystr = "
    SELECT $wpdb->posts.*
    FROM $wpdb->posts, $wpdb->postmeta
    WHERE $wpdb->posts.ID = $wpdb->postmeta.post_id
    AND $wpdb->postmeta.meta_key = 'tag'
    AND $wpdb->postmeta.meta_value = 'email'
    AND $wpdb->posts.post_status = 'publish'
    AND $wpdb->posts.post_type = 'post'
    AND $wpdb->posts.post_date < NOW()
    ORDER BY $wpdb->posts.post_date DESC

Wednesday, 10 April 2013

custom query in magento

Database connection in magento

   // Get the resource model
    $resource = Mage::getSingleton('core/resource');
    // Retrieve the read connection

    $readConnection = $resource->getConnection('core_read');
     // Retrieve the write connection

    $writeConnection = $resource->getConnection('core_write');

     //get table name

    $tableName = $resource->getTableName('catalog_product_entity');

 // or get table name from an entity name

Get Only Column , First item , Last item , or convert to xml from Collection

if you want to get only one column from product collection. you can write look like.

$product_collection = Mage::getModel('catalog/product')


get product with name anant


get first or last item/row from the collection

echo $product_collection->getFirstItem()->getName();

echo $product_collection->getLastItem()->getName();

get Collection data as XML or convert collection in xml

var_dump($product_collection->getFirstItem()->toXml() );

How to send mail from magento

you can send custom mail from magento. its very easy to send mail from magento just write below code and modify as your requirement

Send mail from magento


$mail = Mage::getModel('core/email');
$mail->setToName('Your Name');
$mail->setToEmail('Youe Email');
$mail->setBody('Mail Text / Mail Content');
$mail->setSubject('Mail Subject');
$mail->setFromEmail('Sender Mail Id');
$mail->setFromName("Msg to Show on Subject");
$mail->setType('html');// YOu can use Html or text as Mail format

also you can use

$emailTemplate  = Mage::getModel('core/email_template')->load(1);   //1  isTransactional Emails id
$emailTemplate->send('','Anu', '');

if you want to more info, click on belove link

Tuesday, 9 April 2013

Export large database in mysql

go to run

c:\wamp\bin\mysql\mysql5.1.36\bin>mysql -u root database_name > file1.sql

---if password---

c:\wamp\bin\mysql\mysql5.1.36\bin>mysql -u root -p psw database_name > file1.sql

Import large database in mysql

put file1.sql in c:\wamp\bin\mysql\mysql5.1.36\bin

go to run

c:\wamp\bin\mysql\mysql5.1.36\bin>mysql -u root database_name < file1.sql

---if password---

c:\wamp\bin\mysql\mysql5.1.36\bin>mysql -u root -p psw database_name < file1.sql

Saturday, 6 April 2013

Remove the Newsletter sign up Module or other Module and disable functionality

Please Follow the following step

System->Configuration->Advanced->name of module->disable
ADMIN: System → Configuration → Advanced tab. Set “Mage_Newsletter” to "Disable."

get Base, Skin ,Media , JS , Store ,Current URL and also get url in cms pages

1. Get Base Url :


2. Get Skin Url :


(a) Unsecure Skin Url :


(b) Secure Skin Url :

$this->getSkinUrl('images/imagename.gif', array('_secure'=>true));

3. Get Media Url :


4. Get Js Url :


5. Get Store Url :


6. Get Current Url


Get Url in cms pages or static blocks

1. Get Base Url :

{{store url=""}}

2. Get Skin Url :

{{skin url='images/imageName.jpg'}}

3. Get Media Url :

{{media url='/imageName.jpg'}}

4. Get Store Url :

{{store url='ourpage.html'}}

How to create simple Product with dropdown attribute in magento


// Set an Admin Session

// Then we see if the product exists already, by SKU since that is unique to each product
$product = Mage::getModel('catalog/product')

      // we will create new product
      $product = new Mage_Catalog_Model_Product();

    $product->setSku('UNIQUE SKU HERE');
    $product->setTaxClassId(0); // class id
    $product->setWebsiteIDs(array(0)); // your website ids
    $product->setStoreIDs(array(0));  // your store ids
        'is_in_stock' => 1,
        'qty' => 99999,
        'manage_stock' => 0,

// set the rest of the product information here that can be set on either new/update
$product->setAttributeSetId(9); // the product attribute set to use
$product->setName('Product Title/Name');
$product->setCategoryIds(array(0,1,2,3)); // array of categories it will relate to
$product->setShortDescription('Short Description');

// set the product images as such
// $image is a full path to the image. I found it to only work when I put all the images I wanted to import into the {magento_path}/media/catalog/products - I just created my own folder called import and it read from those images on import.
$image = '/path/to/magento/media/catalog/products/import/image.jpg';

$product->setMediaGallery (array('images'=>array (), 'values'=>array ()));
$product->addImageToMediaGallery ($image, array ('image'), false, false);
$product->addImageToMediaGallery ($image, array ('small_image'), false, false);
$product->addImageToMediaGallery ($image, array ('thumbnail'), false, false);

// setting custom attributes. for example for a custom attribute called special_attribute
// custome_attribute will be used on all examples below for the various attribute types
$product->setCustomeAttribute('value here');

// setting a Yes/No Attribute

// setting a Selection Attribute
$attribute_model = Mage::getModel('eav/entity_attribute');
        $attribute_options_model = Mage::getModel('eav/entity_attribute_source_table');
        $attribute_code = $attribute_model->getIdByCode('catalog_product', $attribut_name);
        $attribute = $attribute_model->load($attribute_code);
        $options = $attribute_options_model->getAllOptions(false);
        // determine if this option exists
        $value_exists = false;
        foreach($options as $option) {
            if (strtolower($option['label']) == strtolower($arg_value)) {
                return   $vid =  $option['value'];

$product->setSpecialAttribute($vid); //specify the ID of the attribute option, eg you creteated an option called Blue in special_attribute it was assigned an ID of some number. Use that number.

// setting a Mutli-Selection Attribute
$data['special_attribute'] = '101 , 102 , 103'; // coma separated string of option IDs. As ID , ID (mind the spaces before and after coma, it worked for me like that)

} catch(Exception $e){
    echo $e->getMessage();
    //handle your error
This code has been testen in magento 1.6.X if you have any error about this code write your comment

Free Advertisement

Free Advertisement

Free Advertisement

Free Advertisement