HOW TO CHECK IF CURRENT PAGE IS HOMEPAGE?

In Magento, in order for you to check the current page if you are in home page / index page of your site, the following code work perfectly.

<?php if(
Mage::getSingleton('cms/page')->getIdentifier() == 'home'  &&
Mage::app()->getFrontController()->getRequest()->getRouteName() == 'cms' 
) : ? >

//insert your code here 

<?php endif; ?>

GET SKIN URL, GET MEDIA URL, GET BASE URL, GET STORE URL IN MAGENTO

To Retrieve URL path in STATIC BLOCK

To get SKIN URL

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

To get Media URL

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

To get Store URL

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

To get Base URL

{{base url='yourstore/mypage.html'}}

Get Magento Media Url

Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK);


Get Magento Media Url

Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA);

Get Magento Skin Url

Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN);

Get Magento Store Url

Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);

Get Magento Js Url

Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_JS);

TO Retrieve URL path in PHTML

Note: In editing PHTML don't forget to enclode the following code with PHP tag
Not secure Skin URL:
<?php echo $this->getSkinUrl('images/sampleimage.jpg') ?>
Secure Skin URL
<?php echo $this->getSkinUrl('images/ sampleimage.gif', array('_secure'=>true)) ?>
Get  Current URL
$current_url = Mage::helper('core/url')->getCurrentUrl();
Get Home URL
$home_url = Mage::helper('core/url')->getHomeUrl();

magento search result is not working in 1.7.

Go to Path app/code/core/mage/catalogsearch/block/result.php

step 1 ) Uncomment lines 149 and 150

$this->getListBlock()
->setCollection($this->_getProductCollection());

step 2 ) Modify the line 172

change this line
$this->_productCollection = $this->getListBlock()->getLoadedProductCollection();

to

$this->_productCollection = Mage::getSingleton(‘catalogsearch/layer’)->getProductCollection();

when you will fix your code, goto the admin  panel (System -> Index Management) and select all the

Indexes > Pick action is “Reindex data” > and the press “submit” button.

And also one thing in admin panel is catalog search setting

Goto the System -> Config -> Catalog -> “Catalog Search”

Here, you can change your search type like, fulltext or both as you need.

Now goto the frontside and check i hope its work.

 

Drupal 6 node save with taxonomy term with php

 

global $user;

$tid = id of taxonomy term;

$new_node = new stdClass();
$new_node->type = ‘tips_for_life’; //Content type of node
$new_node->uid = $user->uid; //you can specify some other userID here if you want
$new_node->name = $user->name;
$new_node->title = ‘Tips 4 Life’;
$new_node->body = ‘test’;
$new_node->taxonomy = array($tid);
$new_node->field_tip_text[‘0’][‘value’] = $value;
$new_node->status = 1; // published
$node = node_save($new_node);
$done = node_submit($node);

Adding custom fields to products in Ubercart

Create a custom module

In mymodule.install, use db_add_field() like so:

mymodule_enable() {
  $ret = array();
  db_add_field($ret, 'uc_orders', 'newfield', array(
    'type'=>'varchar',
    'length'=>50)
  );
}

Simple! So now I’ve added a field to the database. Calling uc_order_load() works fine: the new fields are part of the order object since it just reads from the orders table; however, calling uc_order_save() will not update the new field.

There’s one more thing I needed to do. uc_order_save() calls drupal_write_record(), which depends on the schema. So mymodule needs to add its new field to the schema, using hook_schema_alter():

So what you do is write the following in mymodule.module:

mymodule_schema_alter(&$schema) {
  $schema['uc_orders']['fields']['newfield'] = array(
    'type' => 'varchar',
    'length' => 50,
    'description' => 'custom field',
  );
}

make image using php

In this program we will create image using php.In the imagecreate is used to create the image space.

<?php
header(“Content-Type: image/png”);

$im = @imagecreate(500, 120)

or die(“Cannot Initialize new GD image stream”);

$background_color = imagecolorallocate($im, 0, 0, 0);

$text_color = imagecolorallocate($im, 233, 14, 91);

imagestring($im, 1, 10, 10, “Online tutorial”, $text_color);

imagepng($im);

imagedestroy($im);

?>

The difference Between Document.Ready() v/s Window.Load

$(document).ready(function() { is jQuery event that is fired when DOM is loaded, so it’s fired when the document structure is ready.

$(document).ready(function() {
alert(“document ready occurred!”);
});

$(window).load() event is fired after whole content is loaded.

$(window).load(function() {
alert(“window load occurred!”);
});

Placing the contents of a block in any location with module_Invoke

If you want to embed the contents of a block into a node, a custom block, or a page template, you can use the following snippets.

D6 and earlier:

<?php
$block = module_invoke('module_name', 'block', 'view', 'block_delta');
print $block['content'];
?>

D7:

<?php
$block = module_invoke('module_name', 'block_view', 'block_delta');
print render($block['content']);
?>

To specify which block from which module, you simply edit the two following variables in the first line:

‘module_name’ = The machine name of the module (i.e. the module’s folder name). This is true for core modules too, so for instance ‘search’, ‘user’ and ‘comment’ would all work here.

‘block_delta’ = The machine name of the block. You can determine what this is by visiting the block administration page and editing the block. The URL for editing a webform block, for instance, would be something like:

Drupal 6: admin/build/block/configure/webform/client-block-11
Drupal 7: admin/structure/block/manage/webform/client-block-11/configure

In this example, ‘client-block-11’ is the block’s delta.

Custom blocks will have module name of ‘block’ and a number for a delta, which you can also find by editing the block.

Examples

Display who is a new user.

D6 and earlier:

<?php
$block = module_invoke('user', 'block', 'view', 2);
print $block['content'];
?>

D7:

<?php
$block = module_invoke('user', 'block_view', '2');
print render($block['content']);
?>

Duplicate a custom block you’ve created.

D6 and earlier:

<?php
$block = module_invoke('block', 'block', 'view', 1);
print $block['content'];
?>

D7:

<?php
$block = module_invoke('block', 'block_view', '1');
print render($block['content']);
?>

Display the Font Size module’s block (note the name is ‘fontsize’ — the same as the module’s folder).

D6 and earlier:

<?php
$block = module_invoke('fontsize', 'block', 'view', 0);
print $block['content'];
?>

D7:

<?php
$block = module_invoke('fontsize', 'block_view', '0');
print render($block['content']);
?>