Tuesday 18 June 2013

multistore with magento


<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/osl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @category   Mage
 * @package    Mage
 * @copyright  Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
 * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */

if (version_compare(phpversion(), '5.2.0', '<')===true) {
    echo  '<div style="font:12px/1.35em arial, helvetica, sans-serif;">
<div style="margin:0 0 25px 0; border-bottom:1px solid #ccc;">
<h3 style="margin:0; font-size:1.7em; font-weight:normal; text-transform:none; text-align:left; color:#2f2f2f;">
Whoops, it looks like you have an invalid PHP version.</h3></div><p>Magento supports PHP 5.2.0 or newer.
<a href="http://www.magentocommerce.com/install" target="">Find out</a> how to install</a>
 Magento using PHP-CGI as a work-around.</p></div>';
    exit;
}

/**
 * Error reporting
 */
error_reporting(E_ALL | E_STRICT);

/**
 * Compilation includes configuration file
 */
define('MAGENTO_ROOT', getcwd());

$compilerConfig = MAGENTO_ROOT . '/includes/config.php';
if (file_exists($compilerConfig)) {
    include $compilerConfig;
}

$mageFilename = MAGENTO_ROOT . '/app/Mage.php';
$maintenanceFile = 'maintenance.flag';

if (!file_exists($mageFilename)) {
    if (is_dir('downloader')) {
        header("Location: downloader");
    } else {
        echo $mageFilename." was not found";
    }
    exit;
}

if (file_exists($maintenanceFile)) {
    include_once dirname(__FILE__) . '/errors/503.php';
    exit;
}

require_once $mageFilename;

#Varien_Profiler::enable();

if (isset($_SERVER['MAGE_IS_DEVELOPER_MODE'])) {
    Mage::setIsDeveloperMode(true);
}

#ini_set('display_errors', 1);

umask(0);

/* Store or website code */
$mageRunCode = isset($_SERVER['MAGE_RUN_CODE']) ? $_SERVER['MAGE_RUN_CODE'] : '';

/* Run store or run website */
$mageRunType = isset($_SERVER['MAGE_RUN_TYPE']) ? $_SERVER['MAGE_RUN_TYPE'] : 'store';

/*$url_xyz=$main_url= $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
if($url_xyz=='www.willowdalebotanicalscience.com' || $url_xyz=='http://www.willowdalebotanicalscience.com')
{
Mage::run("willowdalebotanicalscience","store");
}
elseif($url_xyz=='www.celluvati.com' || $url_xyz=='http://www.celluvati.com')
{
Mage::run("celluvati","store");
}
else
{
Mage::run("default", "store");
}*/



//Mage::run("celluvati","store");


//Mage::run($mageRunCode, $mageRunType);


   $x= $_SERVER['HTTP_HOST'];
 
switch ($x)
{
case 'celluvati.com':
 Mage::run("celluvati","store");
  break;
case 'www.celluvati.com':
 Mage::run("celluvati","store");
  break;
  case 'http://www.celluvati.com':
 Mage::run("celluvati","store");
  break;
  case 'https://www.celluvati.com':
 Mage::run("celluvati","store");
  break;


case 'wbscience.com':
  Mage::run("wbscience","store");
  break;
  case 'www.wbscience.com':
  Mage::run("wbscience","store");
  break;
  case 'http://www.wbscience.com':
  Mage::run("wbscience","store");
  break;
  case 'https://www.wbscience.com':
  Mage::run("wbscience","store");
  break;

 case 'willowdalebotanicalscience.com':
  Mage::run("default","store");
  break;
  case 'www.willowdalebotanicalscience.com':
  Mage::run("default","store");
  break;
  case 'http://www.willowdalebotanicalscience.com':
  Mage::run("default","store");
  break;
  case 'https://www.willowdalebotanicalscience.com':
  Mage::run("default","store");
  break;

default:
 Mage::run("default","store");
}



?>

how to configure multy store || multy domain website in magento

-:Replace this code with index.php file and change your domain name according to store name:-


<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/osl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @category   Mage
 * @package    Mage
 * @copyright  Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
 * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */

if (version_compare(phpversion(), '5.2.0', '<')===true) {
    echo  '<div style="font:12px/1.35em arial, helvetica, sans-serif;">
<div style="margin:0 0 25px 0; border-bottom:1px solid #ccc;">
<h3 style="margin:0; font-size:1.7em; font-weight:normal; text-transform:none; text-align:left; color:#2f2f2f;">
Whoops, it looks like you have an invalid PHP version.</h3></div><p>Magento supports PHP 5.2.0 or newer.
<a href="http://www.magentocommerce.com/install" target="">Find out</a> how to install</a>
 Magento using PHP-CGI as a work-around.</p></div>';
    exit;
}

/**
 * Error reporting
 */
error_reporting(E_ALL | E_STRICT);

/**
 * Compilation includes configuration file
 */
define('MAGENTO_ROOT', getcwd());

$compilerConfig = MAGENTO_ROOT . '/includes/config.php';
if (file_exists($compilerConfig)) {
    include $compilerConfig;
}

$mageFilename = MAGENTO_ROOT . '/app/Mage.php';
$maintenanceFile = 'maintenance.flag';

if (!file_exists($mageFilename)) {
    if (is_dir('downloader')) {
        header("Location: downloader");
    } else {
        echo $mageFilename." was not found";
    }
    exit;
}

if (file_exists($maintenanceFile)) {
    include_once dirname(__FILE__) . '/errors/503.php';
    exit;
}

require_once $mageFilename;

#Varien_Profiler::enable();

if (isset($_SERVER['MAGE_IS_DEVELOPER_MODE'])) {
    Mage::setIsDeveloperMode(true);
}

#ini_set('display_errors', 1);

umask(0);

/* Store or website code */
$mageRunCode = isset($_SERVER['MAGE_RUN_CODE']) ? $_SERVER['MAGE_RUN_CODE'] : '';

/* Run store or run website */
$mageRunType = isset($_SERVER['MAGE_RUN_TYPE']) ? $_SERVER['MAGE_RUN_TYPE'] : 'store';

/*$url_xyz=$main_url= $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
if($url_xyz=='www.willowdalebotanicalscience.com' || $url_xyz=='http://www.willowdalebotanicalscience.com')
{
Mage::run("willowdalebotanicalscience","store");
}
elseif($url_xyz=='www.celluvati.com' || $url_xyz=='http://www.celluvati.com')
{
Mage::run("celluvati","store");
}
else
{
Mage::run("default", "store");
}*/



//Mage::run("celluvati","store");


//Mage::run($mageRunCode, $mageRunType);


   $x= $_SERVER['HTTP_HOST'];
  
switch ($x)
{
case 'celluvati.com':
 Mage::run("celluvati","store");
  break;
case 'www.celluvati.com':
 Mage::run("celluvati","store");
  break;
  case 'http://www.celluvati.com':
 Mage::run("celluvati","store");
  break;
  case 'https://www.celluvati.com':
 Mage::run("celluvati","store");
  break;


case 'wbscience.com':
  Mage::run("wbscience","store");
  break;
  case 'www.wbscience.com':
  Mage::run("wbscience","store");
  break;
  case 'http://www.wbscience.com':
  Mage::run("wbscience","store");
  break;
  case 'https://www.wbscience.com':
  Mage::run("wbscience","store");
  break;

 case 'willowdalebotanicalscience.com':
  Mage::run("default","store");
  break;
  case 'www.willowdalebotanicalscience.com':
  Mage::run("default","store");
  break;
  case 'http://www.willowdalebotanicalscience.com':
  Mage::run("default","store");
  break;
  case 'https://www.willowdalebotanicalscience.com':
  Mage::run("default","store");
  break;

default:
 Mage::run("default","store");
}



?>

Show brands in magento


<?php
$manufacturers = $this->getAllBrands();
?>


<?php /*?><h4><?php echo $this->__('Brands')?></h4><?php */?>
 <select class="brand" id="select1" onchange="goToPage('select1')">
<option selected="selected">Brand</option>
<?php foreach($manufacturers as $k=>$v): ?>
<option value="<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK) ?>shopbybrand?brand=<?php echo $v['value']?>" <?php if($_REQUEST['brand']==$v['value']) { ?> selected="selected" <?php } ?> ><?php echo $v['label']?></option>
<?php endforeach; ?>
</select>

<script>
  function goToPage( id ) {
var node = document.getElementById( id );
 window.location.href = node.options[node.selectedIndex].value;
}
</script>

Show all categories in magento


<?php //Display all category in all page  ?>

<?php foreach ($this->getStoreCategories() as $_category): ?>
<li>
<a href="<?php echo $this->getCategoryUrl($_category) ?>">
<?php echo $this->htmlEscape($_category->getName()) ?>
</a>
<?php
$_catid = $_category->getId();
$category = Mage::getModel('catalog/category')->load($_catid);
$subcategory = $category->getAllChildren(true);
array_shift($subcategory);
if($subcategory!=null)
{?>
<ul>
<?php
foreach ($subcategory as $sub)
{
$sub1 = Mage::getModel('catalog/category')->load($sub);
?>
<li class="lvel<?php echo $sub1->getLevel(); ?>">
<a href="<?php echo $sub1->getUrl();?>"><span><?php echo $sub1->getName(); ?></span></a>
</li>
<?php } ?>
</ul>
<?php }?>
</li>
<?php endforeach ?>

Wednesday 8 May 2013

Re-Indexing in magento || Re-indexing of Product Flat Data in magento:


You have to truncate all the 'catalog_product_flat_i' table:
where 'i' can be 1,2,3,4,....

In my case there are 3 table so i fire this query to my phpmyadmin:
TRUNCATE `catalog_product_flat_1`;
TRUNCATE `catalog_product_flat_2`;
TRUNCATE `catalog_product_flat_3`;

Delete all order from magento, Truncate all order in magento


SET FOREIGN_KEY_CHECKS=0;

TRUNCATE `sales_flat_order`;
TRUNCATE `sales_flat_order_address`;
TRUNCATE `sales_flat_order_grid`;
TRUNCATE `sales_flat_order_item`;
TRUNCATE `sales_flat_order_payment`;
TRUNCATE `sales_flat_order_status_history`;

TRUNCATE `sales_flat_creditmemo`;
TRUNCATE `sales_flat_creditmemo_comment`;
TRUNCATE `sales_flat_creditmemo_grid`;
TRUNCATE `sales_flat_creditmemo_item`;

TRUNCATE `sales_flat_invoice`;
TRUNCATE `sales_flat_invoice`;
TRUNCATE `sales_flat_invoice_grid`;
TRUNCATE `sales_flat_invoice_item`;

TRUNCATE `sales_flat_quote`;
TRUNCATE `sales_flat_quote_address`;
TRUNCATE `sales_flat_quote_address_item`;
TRUNCATE `sales_flat_quote_item`;
TRUNCATE `sales_flat_quote_item_option`;
TRUNCATE `sales_flat_order_item`;

TRUNCATE `sales_flat_shipment`;
TRUNCATE `sales_flat_shipment_comment`;
TRUNCATE `sales_flat_shipment_grid`;
TRUNCATE `sales_flat_shipment_item`;
TRUNCATE `sales_flat_shipment_item`;
TRUNCATE `sales_flat_shipment_track`;

TRUNCATE `sendfriend_log`;
TRUNCATE `tag`;
TRUNCATE `tag_relation`;
TRUNCATE `tag_summary`;
TRUNCATE `wishlist`;
TRUNCATE `log_quote`;
TRUNCATE `report_event`;

ALTER TABLE `sales_flat_order` AUTO_INCREMENT=0;
ALTER TABLE `sales_flat_order_address` AUTO_INCREMENT=0;
ALTER TABLE `sales_flat_order_grid` AUTO_INCREMENT=0;
ALTER TABLE `sales_flat_order_item` AUTO_INCREMENT=0;
ALTER TABLE `sales_flat_order_payment` AUTO_INCREMENT=0;
ALTER TABLE `sales_flat_order_status_history` AUTO_INCREMENT=0;

ALTER TABLE `sales_flat_creditmemo` AUTO_INCREMENT=0;
ALTER TABLE `sales_flat_creditmemo_comment` AUTO_INCREMENT=0;
ALTER TABLE `sales_flat_creditmemo_grid` AUTO_INCREMENT=0;
ALTER TABLE `sales_flat_creditmemo_item` AUTO_INCREMENT=0;

ALTER TABLE `sales_flat_invoice` AUTO_INCREMENT=0;
ALTER TABLE `sales_flat_invoice` AUTO_INCREMENT=0;
ALTER TABLE `sales_flat_invoice_grid` AUTO_INCREMENT=0;
ALTER TABLE `sales_flat_invoice_item` AUTO_INCREMENT=0;

ALTER TABLE `sales_flat_quote` AUTO_INCREMENT=0;
ALTER TABLE `sales_flat_quote_address` AUTO_INCREMENT=0;
ALTER TABLE `sales_flat_quote_address_item` AUTO_INCREMENT=0;
ALTER TABLE `sales_flat_quote_item` AUTO_INCREMENT=0;
ALTER TABLE `sales_flat_quote_item_option` AUTO_INCREMENT=0;
ALTER TABLE `sales_flat_order_item` AUTO_INCREMENT=0;

ALTER TABLE `sales_flat_shipment` AUTO_INCREMENT=0;
ALTER TABLE `sales_flat_shipment_comment` AUTO_INCREMENT=0;
ALTER TABLE `sales_flat_shipment_grid` AUTO_INCREMENT=0;
ALTER TABLE `sales_flat_shipment_item` AUTO_INCREMENT=0;
ALTER TABLE `sales_flat_shipment_item` AUTO_INCREMENT=0;
ALTER TABLE `sales_flat_shipment_track` AUTO_INCREMENT=0;

ALTER TABLE `sendfriend_log` AUTO_INCREMENT=0;
ALTER TABLE `tag` AUTO_INCREMENT=0;
ALTER TABLE `tag_relation` AUTO_INCREMENT=0;
ALTER TABLE `tag_summary` AUTO_INCREMENT=0;
ALTER TABLE `wishlist` AUTO_INCREMENT=0;
ALTER TABLE `log_quote` AUTO_INCREMENT=0;
ALTER TABLE `report_event` AUTO_INCREMENT=0;

TRUNCATE `eav_entity_store`;
ALTER TABLE  `eav_entity_store` AUTO_INCREMENT=0;

SET FOREIGN_KEY_CHECKS=1;

Delete Products, Customer, category in magento


Truncate all order and reset id from 1
TRUNCATE TABLE `catalog_product_bundle_option`;
TRUNCATE TABLE `catalog_product_bundle_option_value`;
TRUNCATE TABLE `catalog_product_bundle_selection`;
TRUNCATE TABLE `catalog_product_entity_datetime`;
TRUNCATE TABLE `catalog_product_entity_decimal`;
TRUNCATE TABLE `catalog_product_entity_gallery`;
TRUNCATE TABLE `catalog_product_entity_int`;
TRUNCATE TABLE `catalog_product_entity_media_gallery`;
TRUNCATE TABLE `catalog_product_entity_media_gallery_value`;
TRUNCATE TABLE `catalog_product_entity_text`;
TRUNCATE TABLE `catalog_product_entity_tier_price`;
TRUNCATE TABLE `catalog_product_entity_varchar`;
TRUNCATE TABLE `catalog_product_link`;
TRUNCATE TABLE `catalog_product_link_attribute`;
TRUNCATE TABLE `catalog_product_link_attribute_decimal`;
TRUNCATE TABLE `catalog_product_link_attribute_int`;
TRUNCATE TABLE `catalog_product_link_attribute_varchar`;
TRUNCATE TABLE `catalog_product_link_type`;
TRUNCATE TABLE `catalog_product_option`;
TRUNCATE TABLE `catalog_product_option_price`;
TRUNCATE TABLE `catalog_product_option_title`;
TRUNCATE TABLE `catalog_product_option_type_price`;
TRUNCATE TABLE `catalog_product_option_type_title`;
TRUNCATE TABLE `catalog_product_option_type_value`;
TRUNCATE TABLE `catalog_product_super_attribute`;
TRUNCATE TABLE `catalog_product_super_attribute_label`;
TRUNCATE TABLE `catalog_product_super_attribute_pricing`;
TRUNCATE TABLE `catalog_product_super_link`;
TRUNCATE TABLE `catalog_product_enabled_index`;
TRUNCATE TABLE `catalog_product_website`;
TRUNCATE TABLE `catalog_product_entity`;

TRUNCATE TABLE `cataloginventory_stock`;
TRUNCATE TABLE `cataloginventory_stock_item`;
TRUNCATE TABLE `cataloginventory_stock_status`;

INSERT  INTO `catalog_product_link_type`(`link_type_id`,`code`) VALUES (1,'relation'),(2,'bundle'),(3,'super'),(4,'up_sell'),(5,'cross_sell');
INSERT  INTO `catalog_product_link_attribute`(`product_link_attribute_id`,`link_type_id`,`product_link_attribute_code`,`data_type`) VALUES (1,2,'qty','decimal'),(2,1,'position','int'),(3,4,'position','int'),(4,5,'position','int'),(6,1,'qty','decimal'),(7,3,'position','int'),(8,3,'qty','decimal');
INSERT  INTO `cataloginventory_stock`(`stock_id`,`stock_name`) VALUES (1,'Default');
=======================================================================================================
Truncate all Categories:
......................
TRUNCATE TABLE `catalog_category_entity`;
TRUNCATE TABLE `catalog_category_entity_datetime`;
TRUNCATE TABLE `catalog_category_entity_decimal`;
TRUNCATE TABLE `catalog_category_entity_int`;
TRUNCATE TABLE `catalog_category_entity_text`;
TRUNCATE TABLE `catalog_category_entity_varchar`;
TRUNCATE TABLE `catalog_category_product`;
TRUNCATE TABLE `catalog_category_product_index`;

INSERT  INTO `catalog_category_entity`(`entity_id`,`entity_type_id`,`attribute_set_id`,`parent_id`,`created_at`,`updated_at`,`path`,`POSITION`,`level`,`children_count`) VALUES (1,3,0,0,'0000-00-00 00:00:00','2009-02-20 00:25:34','1',1,0,1),(2,3,3,0,'2009-02-20 00:25:34','2009-02-20 00:25:34','1/2',1,1,0);
INSERT  INTO `catalog_category_entity_int`(`value_id`,`entity_type_id`,`attribute_id`,`store_id`,`entity_id`,`value`) VALUES (1,3,32,0,2,1),(2,3,32,1,2,1);
INSERT  INTO `catalog_category_entity_varchar`(`value_id`,`entity_type_id`,`attribute_id`,`store_id`,`entity_id`,`value`) VALUES (1,3,31,0,1,'Root Catalog'),(2,3,33,0,1,'root-catalog'),(3,3,31,0,2,'Default Category'),(4,3,39,0,2,'PRODUCTS'),(5,3,33,0,2,'default-category');

/**** Magento ver. 1.6.x.x ****/

TRUNCATE TABLE `catalog_category_entity`;
TRUNCATE TABLE `catalog_category_entity_datetime`;
TRUNCATE TABLE `catalog_category_entity_decimal`;
TRUNCATE TABLE `catalog_category_entity_int`;
TRUNCATE TABLE `catalog_category_entity_text`;
TRUNCATE TABLE `catalog_category_entity_varchar`;
TRUNCATE TABLE `catalog_category_product`;
TRUNCATE TABLE `catalog_category_product_index`;

INSERT  INTO `catalog_category_entity`(`entity_id`,`entity_type_id`,`attribute_set_id`,`parent_id`,`created_at`,`updated_at`,`path`,`POSITION`,`level`,`children_count`) VALUES (1,3,0,0,'0000-00-00 00:00:00','0000-00-00 00:00:00','1',1,0,1), (2,3,3,1,'0000-00-00 00:00:00','0000-00-00 00:00:00','1/2','1','1','0');
INSERT  INTO `catalog_category_entity_int`(`value_id`,`entity_type_id`,`attribute_id`,`store_id`,`entity_id`,`value`) VALUES (1,3,32,0,2,1),(2,3,36,0,2,1),(3,3,61,0,2,1),(4,3,44,0,2,NULL),(5,3,45,0,2,1),(6,3,62,0,2,1),(7,3,63,0,2,1),(8,3,64,0,2,NULL);
INSERT  INTO `catalog_category_entity_varchar`(`value_id`,`entity_type_id`,`attribute_id`,`store_id`,`entity_id`,`value`) VALUES (1,3,31,0,1,'Root Catalog'),(2,3,35,0,2,'Default Category'),(3,3,37,0,2,'default-category'),(4,3,40,0,2,NULL),(5,3,43,0,2,'PRODUCTS'),(6,3,52,0,2,NULL),(7,3,55,0,2,NULL);

/**** Magento ver. 1.6.x.x ****/

================================================================================================
Truncate All Customers:
.......................................
TRUNCATE TABLE `customer_address_entity`;
TRUNCATE TABLE `customer_address_entity_datetime`;
TRUNCATE TABLE `customer_address_entity_decimal`;
TRUNCATE TABLE `customer_address_entity_int`;
TRUNCATE TABLE `customer_address_entity_text`;
TRUNCATE TABLE `customer_address_entity_varchar`;
TRUNCATE TABLE `customer_entity`;
TRUNCATE TABLE `customer_entity_datetime`;
TRUNCATE TABLE `customer_entity_decimal`;
TRUNCATE TABLE `customer_entity_int`;
TRUNCATE TABLE `customer_entity_text`;
TRUNCATE TABLE `customer_entity_varchar`;
=======================================================================================================

shipping and handing in cart page in magento


Go to this path
app/code/core/Mage/Sales/Model/Quote/Address/Total/
open shipping.php
there is a function fetch()
In this see the $title value content the 'Shipping & Handling' change it to your custom text.

Tuesday 7 May 2013

Decode MD5 in php, magento


?php
function decode_md5($hash)
{
  //simple check for md5 hash
  if(!preg_match('/^[a-f0-9]{32}$/i',$hash))return '';

  //make request to service
  $pass=file_get_contents('http://md5.darkbyte.ru/api.php?q='.$hash);

  //not found
  if(!$pass)return '';

  //found, but not valid
  if(md5($pass)!=strtolower($hash))return '';

  //found :)
  return $pass;
}

function encode_md5($pass)
{
  //add padding, if str length eq 32
  if(strlen($pass)==32)$pass.='=';
 
  //make request to service
  return file_get_contents('http://md5.darkbyte.ru/api.php?q='.urlencode($pass));
}
?>

<?php
echo $pass=decode_md5('b70d2c477ff9129a937efc41f2424ae0'); ?>

Monday 6 May 2013

Show all category subcategory with thumbnail images in magento


First create cms static block in magento back-end and put this code in your static block
{{block type="catalog/navigation" name="catalog.category" template="catalog/category/myallcat.phtml"}}
----------------------------------------------------------------------------------------------
How to call your static block in phtml page and cms page like home page
In CMS page: <div>{{block type="cms/block" block_id="your block id"}}</div>
in phtml file: echo $this->getLayout()->createBlock('cms/block')->setBlockId('block id')->toHtml();
--------------------------------------------------------
Create PHTML file for showing category with thumbnail in directory:
app/design/frontend/default/default/template/catalog/category/myallcat.phtml
And past my bellow code:

<ul>
<?php
$children = Mage::getModel('catalog/category')->getCategories(2); // put your main root category id here
foreach ($children as $category):
$category=Mage::getModel('catalog/category')->load($category->getId());
echo '<li><a href="' . $category->getUrl() . '">' . $category->getName() . '</a></li>'; ?>
<img src="<?php echo Mage::getBaseUrl('media')?>catalog/category/<?php echo $category->getThumbnail() ?>" height="100" width='100'>
<?php 
$children = Mage::getModel('catalog/category')->getCategories($category->getId());
foreach ($children as $category):
$category=Mage::getModel('catalog/category')->load($category->getId());
echo '<li><a href="' . $category->getUrl() . '">' . $category->getName() . '</a></li>'; ?>
<img src="<?php echo Mage::getBaseUrl('media')?>catalog/category/<?php echo $category->getThumbnail() ?>" height="100" width='100'>

<?php 
$children = Mage::getModel('catalog/category')->getCategories($category->getId());
foreach ($children as $category):
$category=Mage::getModel('catalog/category')->load($category->getId());
echo '<li><a href="' . $category->getUrl() . '">' . $category->getName() . '</a></li>'; ?>
<img src="<?php echo Mage::getBaseUrl('media')?>catalog/category/<?php echo $category->getThumbnail() ?>" height="100" width='100'>
<?php
endforeach;
?>

<?php
endforeach;
?>


<?php
endforeach;
?>
</ul>

Friday 3 May 2013

facebook,twitter,testimonial extension


http://www.magentocommerce.com/magento-connect/twitter-profile-box.html

  http://www.magentocommerce.com/magento-connect/facebook-fan-box.html

http://ext.2magento.com/Sandipan_Testimonialmanager.html

Testimonials slider


<!-- include jQuery library -->
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
<!-- include Cycle plugin -->
<script type="text/javascript" src="http://cloud.github.com/downloads/malsup/cycle/jquery.cycle.all.latest.js"></script>
<script type="text/javascript">
$(document).ready(function() {
   $('#testimonials')
.before('<div id="nav">')
.cycle({
        fx: 'fade', // choose your transition type, ex: fade, scrollUp, scrollRight, shuffle
pager:  '#nav'
     });
});
</script>


<style>
#testimonials {
width:330px;
background:#E7E9E6 url(images/bg-testimonials.png) left top repeat-x;
border:1px solid #D8D9D6;
margin:10px 0;

}
#testimonials blockquote{
padding:10px;
width:300px !important;
font-family:Georgia, "Times New Roman", Times, serif;
font-style:italic;
color:#808080;
display:block;
}

#testimonials blockquote p{
margin: 0 !important;padding: 5px!important;

}
#testimonials blockquote cite {
font-style: normal;
display: block;

text-transform: uppercase;
font-weight: bold;
font-style:italic;
color: #555;
padding-left:5px;
margin-top:10px;
}
</style>



<h1>Testimonials</h1>
<div id="testimonials">

 <blockquote><p>"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. "
                <cite>&ndash;Martin - NY</cite></p></blockquote>

                <blockquote><p>"Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
                <cite>&ndash;Sandra - LA</cite></p></blockquote>

                <blockquote><p>"Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
                <cite>&ndash;Jason - MA</cite></p></blockquote>

</div><!--end testimonials-->

Saturday 13 April 2013

How to update price and special price according to sku in magento

<?php
/**
 * @author      MagePsycho <info@magepsycho.com>
 * @website     http://www.magepsycho.com
 * @category    Export / Import
 */
$mageFilename = 'app/Mage.php';
require_once $mageFilename;
Mage::setIsDeveloperMode(true);
ini_set('display_errors', 1);
umask(0);
Mage::app('admin');
Mage::register('isSecureArea', 1);
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);

set_time_limit(0);
ini_set('memory_limit','1024M');

/***************** UTILITY FUNCTIONS ********************/
function _getConnection($type = 'core_read'){
    return Mage::getSingleton('core/resource')->getConnection($type);
}

function _getTableName($tableName){
    return Mage::getSingleton('core/resource')->getTableName($tableName);
}

function _getAttributeId($attribute_code = 'price'){
    $connection = _getConnection('core_read');
    $sql = "SELECT attribute_id
                FROM " . _getTableName('eav_attribute') . "
            WHERE
                entity_type_id = ?
                AND attribute_code = ?";
    $entity_type_id = _getEntityTypeId();
    return $connection->fetchOne($sql, array($entity_type_id, $attribute_code));
}
function _getAttributeId1($attribute_code = 'special_price'){
    $connection = _getConnection('core_read');
    $sql = "SELECT attribute_id
                FROM " . _getTableName('eav_attribute') . "
            WHERE
                entity_type_id = ?
                AND attribute_code = ?";
    $entity_type_id1 = _getEntityTypeId();
    return $connection->fetchOne($sql, array($entity_type_id1, $attribute_code));
}

function _getEntityTypeId($entity_type_code = 'catalog_product'){
    $connection = _getConnection('core_read');
    $sql        = "SELECT entity_type_id FROM " . _getTableName('eav_entity_type') . " WHERE entity_type_code = ?";
    return $connection->fetchOne($sql, array($entity_type_code));
}

function _getIdFromSku($sku){
    $connection = _getConnection('core_read');
    $sql        = "SELECT entity_id FROM " . _getTableName('catalog_product_entity') . " WHERE sku = ?";
    return $connection->fetchOne($sql, array($sku));

}


function _checkIfSkuExists($sku){
    $connection = _getConnection('core_read');
    $sql        = "SELECT COUNT(*) AS count_no FROM " . _getTableName('catalog_product_entity') . " WHERE sku = ?";
    $count      = $connection->fetchOne($sql, array($sku));
    if($count > 0){
        return true;
    }else{
        return false;
    }
}

function _updatePrices($data){
    $connection     = _getConnection('core_write');
    $sku            = $data[0];
    $newPrice       = $data[1];
 $specialPrice   = $data[2];
    $productId      = _getIdFromSku($sku);
    $attributeId    = _getAttributeId();
 $attributeId1    = _getAttributeId1();

    $sql = "UPDATE " . _getTableName('catalog_product_entity_decimal') . " cped
                SET  cped.value = ?
            WHERE  cped.attribute_id = ?
            AND cped.entity_id = ?";
$sql1 = "UPDATE " . _getTableName('catalog_product_index_price') . " cpip
                SET  cpip.final_price = ?
            WHERE cpip.entity_id = ?";


    $connection->query($sql, array($newPrice, $attributeId, $productId));
 $connection->query($sql, array($specialPrice, $attributeId1, $productId));
 $connection->query($sql1, array($specialPrice, $productId));

}

/***************** UTILITY FUNCTIONS ********************/

$csv                = new Varien_File_Csv();
$data               = $csv->getData('var/import/local50.csv'); //path to csv
array_shift($data);

$message = '';
$count   = 2;
foreach($data as $_data){
    if(_checkIfSkuExists($_data[0])){
        try{
            _updatePrices($_data);
            $message .= $count . '> Success:: While Updating Price (' . $_data[1] . ') of Sku (' . $_data[0] . '). <br />';
_updatePrices($_data);
            $message .= $count . '> Success:: While Updating Price (' . $_data[2] . ') of Sku (' . $_data[0] . '). <br />';

        }catch(Exception $e){
            $message .=  $count .'> Error:: While Upating  Price (' . $_data[1] . ') of Sku (' . $_data[0] . ') => '.$e->getMessage().'<br />';
$message .=  $count .'> Error:: While Upating  Price (' . $_data[2] . ') of Sku (' . $_data[0] . ') => '.$e->getMessage().'<br />';
        }
    }else{
        $message .=  $count .'> Error:: Product with Sku (' . $_data[0] . ') does\'t exist.<br />';
    }
    $count++;
}
echo $message;
?>

Wednesday 10 April 2013

show all records in Excel formate from mysql in php


<?php
ob_start();
ob_flush();
$conn = mysql_connect("localhost","root","")
    or die("Connecting to MySQL failed");

mysql_select_db('sugan_php')
    or die("Selecting MySQL database failed");


?>


<?php
 
$showtablequery = "SHOW TABLES FROM sugan_php";

$showtablequery_result    = mysql_query($showtablequery);
while($showtablerow = mysql_fetch_array($showtablequery_result))
{
    echo $showtablerow[0]."<br />";
}


exit;
?>

<?php
$file_name="mycsv";
$header="";
$data="";
//create query to select as data from your table
$select = "SELECT * FROM test1";

//run mysql query and then count number of fields
$export = mysql_query ( $select )
       or die ( "Sql error : " . mysql_error( ) );
$fields = mysql_num_fields ( $export );

//create csv header row, to contain table headers
//with database field names
for ( $i = 0; $i < $fields; $i++ ) {
    $header .= mysql_field_name( $export , $i ) . ",";
}

//this is where most of the work is done.
//Loop through the query results, and create
//a row for each
while( $row = mysql_fetch_row( $export ) ) {
    $line = '';
    //for each field in the row
    foreach( $row as $value ) {
        //if null, create blank field
        if ( ( !isset( $value ) ) || ( $value == "" ) ){
            $value = ",";
        }
        //else, assign field value to our data
        else {
            $value = str_replace( '"' , '""' , $value );
            $value = '"' . $value . '"' . ",";
        }
        //add this field value to our row
        $line .= $value;
    }
    //trim whitespace from each row
    $data .= trim( $line ) . "\n";
}
//remove all carriage returns from the data
$data = str_replace( "\r" , "" , $data );
//$mydate=date("Y-m-d");


//create a file and send to browser for user to download

header("Content-type: application/vnd.ms-excel");
header("Content-disposition: csv" . date("Y-m-d") . ".csv");
header( "Content-disposition: filename=".$file_name.".csv");
print "$header\n$data";
exit;
?>