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 = "http://anantprajapati.blogspot.in/" ;

Mage::helper('core')->urlEncode($url);

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

Mage::helper('core')->urlDecode($url);

How to get all post data from wordpress using custom query

get all post using custom or select query using following code
<?php
 $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
<?php  

   // 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')
->getCollection()
->addAttributeToSelect('*');




var_dump($product_collection->getColumnValues('name'));


get product with name anant

var_dump($product_collection->getItemsByColumnValue('name','anant'));





get first or last item/row from the collection



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

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

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
$mail->send();
?>

also you can use

$emailTemplate  = Mage::getModel('core/email_template')->load(1);   //1  isTransactional Emails id
$emailTemplate->setSenderEmail('anantprajapati111@gmail.com');
$emailTemplate->setSenderName('Anant');
$emailTemplate->send('test@gmail.com','Anu', '');

if you want to more info, click on belove link
http://stackoverflow.com/questions/5595202/sending-e-mail-programmatically-in-magento-is-failing

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
Ex
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 :

Mage::getBaseUrl();

2. Get Skin Url :

Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN);

(a) Unsecure Skin Url :

$this->getSkinUrl('images/imagename.jpg');

(b) Secure Skin Url :

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

3. Get Media Url :

Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA);

4. Get Js Url :

Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_JS);

5. Get Store Url :

Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);

6. Get Current Url

Mage::helper('core/url')->getCurrentUrl();

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

<?php
require_once('app/Mage.php');
umask(0);

// Set an Admin Session
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);

// Then we see if the product exists already, by SKU since that is unique to each product
$product = Mage::getModel('catalog/product')
   ->loadByAttribute('sku',$_product['sku']);

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

    $product->setTypeId('simple');
    $product->setWeight(1.0000);
    $product->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH);
    $product->setStatus(1);
    $product->setSku('UNIQUE SKU HERE');
    $product->setTaxClassId(0); // class id
    $product->setWebsiteIDs(array(0)); // your website ids
    $product->setStoreIDs(array(0));  // your store ids
    $product->setStockData(array(
        '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->setDescription('Description');
$product->setShortDescription('Short Description');
$product->setPrice(9.99);

// 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
$product->setSpecialField(1);

// 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);
   
        $attribute_options_model->setAttribute($attribute);
        $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'];
                break;
            }
        }

$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)
$product->setData($data);

try{
    $product->save();
} 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