Thursday, 25 September 2014

url rewrite to hide query sting in php

It rewrite url like :-

http://www.rootdirectory.com/index.php?sate=rajasthan&city=jaipur&land=malviyanagar

to :-

http://www.rootdirectory.com/rajasthan/jaipur/malviyanagar

create a .htaccess file on root directory and paste following code

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^([a-zA-Z0-9]+|)/?$ index.php?state=$1 [QSA]

RewriteRule ^([a-zA-Z0-9]+|)/([a-zA-Z0-9]+|)/?$ index.php?state=$1&city=$2 [QSA]

RewriteRule ^([a-zA-Z0-9]+|)/([a-zA-Z0-9]+|)/([a-zA-Z0-9]+|)/?$ index.php?state=$1&city=$2&land=$3 [QSA]

After used it code you can access your query string value like :-

And last  on http://www.rootdirectory.com/index.php

paste following code :-

<div>

<a href="http://www.rootdirectory.com">home</a>
<a href="http://www.rootdirectory.com/rajasthan">Rajasthan</a>
<a href="http://www.rootdirectory.com/delhi/newdelhi">New Delhi</a>
<a href="http://www.rootdirectory.com/rajasthan/jaipur/malviyanagar">Malviya Nagar</a>
</div>


<?php

echo "<h2>".$_GET['state']."</h2>";
echo "<h2>".$_GET['city']."</h2>";

echo "<h2>".$_GET['land']."</h2>";

?>

Monday, 22 September 2014

Add get directions maps to website

<!DOCTYPE html>
<html>
  <head>
    <title> Lalit Get Directions service</title>
    <style>
      html, body, #map-canvas {
        height: 600px;
        width: 600px;
       margin-left:150px;
       top:60px;
        padding: 0px
      }
      #panel {
        position: absolute;
        top: 5px;
        left: 50%;
        margin-left: -180px;
        z-index: 5;
        background-color: #fff;
        padding: 5px;
        border: 1px solid #999;
      }
    </style>
    <script src="https://maps.googleapis.com/maps/api/js?v=3.exp"></script>
    <script>
var directionsDisplay;
var directionsService = new google.maps.DirectionsService();
var map;

function initialize() {
  directionsDisplay = new google.maps.DirectionsRenderer();
  var chicago = new google.maps.LatLng(41.850033, -87.6500523);
  var mapOptions = {
    zoom:7,
    center: chicago
  };
  map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
  directionsDisplay.setMap(map);
}

function calcRoute() {
  var start = document.getElementById('start').value;
  var end = document.getElementById('end').value;
  var request = {
      origin:start,
      destination:end,
      travelMode: google.maps.TravelMode.DRIVING
  };
  directionsService.route(request, function(response, status) {
    if (status == google.maps.DirectionsStatus.OK) {
      directionsDisplay.setDirections(response);
    }
  });
}

google.maps.event.addDomListener(window, 'load', initialize);

    </script>
  </head>
  <body>
    <div id="panel">
    <b>Start: </b>
    <input type="text" value="jaipur,rajsthan" id="start">
    <b>End: </b>
    <input type="text" id="end">
    <input type="button" onClick="calcRoute();" value="Get Direction">
  
    </div>
    <div id="map-canvas"></div>
  </body>
</html>

how to add google address search map on website

<!DOCTYPE html>
<html>
  <head>
    <title> address search</title>
    <style>
      html, body, #map-canvas {
         height: 600px;
        width: 600px;
        padding: 0px;
        margin-left:100px;
        top:60px;
      }
      #panel {
        position: absolute;
        top: 5px;
        left: 50%;
        margin-left: -180px;
        z-index: 5;
        background-color: #fff;
        padding: 5px;
        border: 1px solid #999;
      }
    </style>
    <script src="https://maps.googleapis.com/maps/api/js?v=3.exp"></script>
    <script>
var geocoder;
var map;
function initialize() {
  geocoder = new google.maps.Geocoder();
  var latlng = new google.maps.LatLng(-34.397, 150.644);
  var mapOptions = {
    zoom: 10,
    center: latlng
  }
  map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
}

function codeAddress() {
  var address = document.getElementById('address').value;
  geocoder.geocode( { 'address': address}, function(results, status) {
    if (status == google.maps.GeocoderStatus.OK) {
      map.setCenter(results[0].geometry.location);
      var marker = new google.maps.Marker({
          map: map,
          position: results[0].geometry.location
      });
    } else {
      alert('Geocode was not successful for the following reason: ' + status);
    }
  });
}

google.maps.event.addDomListener(window, 'load', initialize);

    </script>
  </head>
  <body>
    <div id="panel">
      <input id="address" type="textbox" value="Sydney, NSW">
      <input type="button" value="Geocode" onclick="codeAddress()">
    </div>
    <div id="map-canvas"></div>
  </body>
</html>

Thursday, 18 September 2014

how to get category thumbnail image in magento

<?php  $catId = $_category->getId(); ?>
<?php $thumb = Mage::getModel('catalog/category')->load($catId)->getThumbnail();?>
<img src="<?php echo Mage::getBaseUrl('media').'catalog/category/'.$thumb;?>" >

Wednesday, 17 September 2014

get all sale products from category and show on header top in magento

Note :-It's work only magneto 1.9 version because we used magento default funcnality.



On list page  will be show only simple products and and sale product show on tab.
 and set design according to your theme.

First open list.phtml file and replace all code with following  :-

<?php
    $_productCollection=$this->getLoadedProductCollection();
    $_helper = $this->helper('catalog/output');
?>
<?php if(!$_productCollection->count()): ?>
<p class="note-msg"><?php echo $this->__('There are no products matching the selection.') ?></p>
<?php else:

?>


<div class="header-minicart minicart1">
<a class="skip-link skip-cart " href="#header-cart12">
<span class="icon"></span>
<span class="label">closeout</span>
</a>

<div id="header-cart12" class="block block-cart skip-content">
<div id="minicart-error-message" class="minicart-message"></div>
<div id="minicart-success-message" class="minicart-message"></div>
<div class="minicart-wrapper">
<?php $i="";
$k = 0; ?>
<div>
<ul id="cart-sidebar" class="mini-products-list">
<?php foreach ($_productCollection as $_products): ?>
<?php  $specialprice = $_products->getSpecialPrice();
$specialPriceToDate = $_products->getSpecialToDate();

$specialdate = 1;
$today = 0;
if($specialPriceToDate!="")
{
$today = strtotime(date("Y-m-d"));
$specialdate = strtotime($specialPriceToDate);
}
if($specialprice!="" && $specialdate >= $today) {

$i = 0; ?>
<li class="item last odd" xmlns="http://www.w3.org/1999/html">
<a class="product-image" href="<?php echo $_products->getProductUrl() ?>" title="<?php echo $this->stripTags($this->getImageLabel($_products, 'small_image'), null, true) ?>">
<img height="50" width="50" alt="<?php echo $this->stripTags($this->getImageLabel($_products, 'small_image'), null, true) ?>" src="<?php echo $this->helper('catalog/image')->init($_products, 'small_image')->keepFrame(false)->resize(50); ?>">
</a>
<div class="product-details">
<?php $_productsNameStripped = $this->stripTags($_products->getName(), null, true); ?>
<p class="product-name">
<a href="<?php echo $_products->getProductUrl() ?>" title="<?php echo $_productsNameStripped; ?>"><?php echo $_helper->productAttribute($_products, $_products->getName() , 'name'); ?></a>
</p>
<table class="info-wrapper">
<tbody>
<tr>
<th>Price</th>
<td>
<span class="price"><?php echo $this->getPriceHtml($_products, true) ?></span>
</td>
</tr>

</tbody>
</table>
</div>
</li>
<?php $i++;
$k++;
}

?>
<?php endforeach; ?>

</ul>
<?php if($i==0){
?>
<p class="block-subtitle">No Sale item in this category!</p>
<?php
}
?>

</div>
</div>
</div>

</div>


<div class="category-products">
    <?php echo $this->getToolbarHtml() ?>
    <?php // List mode ?>
    <?php if($this->getMode()!='grid'): ?>
    <?php $_iterator = 0; ?>
    <ol class="products-list" id="products-list">
    <?php foreach ($_productCollection as $_product): ?>
<?php  $specialprices = $_product->getSpecialPrice();
$specialPriceToDate = $_product->getSpecialToDate();
$specialdate = 0;
$today = 1;
if($specialPriceToDate!="")
{
$specialprices="";
$today = strtotime(date("Y-m-d"));
$specialdate = strtotime($specialPriceToDate);
}
if($specialprices=="" && $specialdate < $today) { ?>

        <li class="item<?php if( ++$_iterator == sizeof($_productCollection) ): ?> last<?php endif; ?>">
            <?php // Product Image ?>
            <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" class="product-image">
                <?php /* Based on the native RWD styling, product images are displayed at a max of ~400px wide when viewed on a
                        one column page layout with four product columns from a 1280px viewport. For bandwidth reasons,
                        we are going to serve a 300px image, as it will look fine at 400px and most of the times, the image
                        will be displayed at a smaller size (eg, if two column are being used or viewport is smaller than 1280px).
                        This $_imgSize value could even be decreased further, based on the page layout
                        (one column, two column, three column) and number of product columns. */ ?>
                <?php $_imgSize = 300; ?>
                <img id="product-collection-image-<?php echo $_product->getId(); ?>"
                     src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->keepFrame(false)->resize($_imgSize); ?>"
                     alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" />
            </a>
            <?php // Product description ?>
            <div class="product-shop">
                <div class="f-fix">
                    <div class="product-primary">
                        <?php $_productNameStripped = $this->stripTags($_product->getName(), null, true); ?>
                        <h2 class="product-name"><a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $_productNameStripped; ?>"><?php echo $_helper->productAttribute($_product, $_product->getName() , 'name'); ?></a></h2>
                        <?php if($_product->getRatingSummary()): ?>
                        <?php echo $this->getReviewsSummaryHtml($_product) ?>
                        <?php endif; ?>

                        <?php
                            $_nameAfterChildren = $this->getChild('name.after')->getSortedChildren();
                            foreach($_nameAfterChildren as $_nameAfterChildName):
                                $_nameAfterChild = $this->getChild('name.after')->getChild($_nameAfterChildName);
                                $_nameAfterChild->setProduct($_product);
                        ?>
                            <?php echo $_nameAfterChild->toHtml(); ?>
                        <?php endforeach; ?>
                    </div>
                    <div class="product-secondary">
                        <?php echo $this->getPriceHtml($_product, true) ?>
                    </div>
                    <div class="product-secondary">
                        <?php if($_product->isSaleable() && !$_product->canConfigure()): ?>
                            <p class="action"><button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button></p>
                        <?php elseif($_product->isSaleable()): ?>
                            <p class="action"><a title="<?php echo $this->__('View Details') ?>" class="button" href="<?php echo $_product->getProductUrl() ?>"><?php echo $this->__('View Details') ?></a></p>
                        <?php else: ?>
                            <p class="action availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
                        <?php endif; ?>
                        <ul class="add-to-links">
                            <?php if ($this->helper('wishlist')->isAllow()) : ?>
                                <li><a href="<?php echo $this->helper('wishlist')->getAddUrl($_product) ?>" class="link-wishlist"><?php echo $this->__('Add to Wishlist') ?></a></li>
                            <?php endif; ?>
                            <?php if($_compareUrl=$this->getAddToCompareUrl($_product)): ?>
                                <li><span class="separator">|</span> <a href="<?php echo $_compareUrl ?>" class="link-compare"><?php echo $this->__('Add to Compare') ?></a></li>
                            <?php endif; ?>
                        </ul>
                    </div>
                    <div class="desc std">
                        <?php echo $_helper->productAttribute($_product, $_product->getShortDescription(), 'short_description') ?>
                        <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $_productNameStripped ?>" class="link-learn"><?php echo $this->__('Learn More') ?></a>
                    </div>
                </div>
            </div>
        </li>
<?php } ?>
    <?php endforeach; ?>
    </ol>
    <script type="text/javascript">decorateList('products-list', 'none-recursive')</script>

    <?php else: ?>

    <?php // Grid Mode ?>

    <?php $_collectionSize = $_productCollection->count() ?>
    <?php $_columnCount = $this->getColumnCount(); ?>
    <ul class="products-grid products-grid--max-<?php echo $_columnCount; ?>-col">
        <?php $i=0; foreach ($_productCollection as $_product): ?>
            <?php /*if ($i++%$_columnCount==0): ?>
            <?php endif*/ ?>
<?php  $specialprices = $_product->getSpecialPrice();
$specialPriceToDate = $_product->getSpecialToDate();
$specialdate = 0;
$today = 1;
if($specialPriceToDate!="")
{
$specialprices="";
$today = strtotime(date("Y-m-d"));
$specialdate = strtotime($specialPriceToDate);
}
if($specialprices=="" && $specialdate < $today) { ?>            <li class="item<?php if(($i-1)%$_columnCount==0): ?> first<?php elseif($i%$_columnCount==0): ?> last<?php endif; ?>">
                <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" class="product-image">
                    <?php $_imgSize = 210; ?>
                    <img id="product-collection-image-<?php echo $_product->getId(); ?>"
                         src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize($_imgSize); ?>"
                         alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" />
                </a>
                <div class="product-info">
                    <h2 class="product-name"><a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($_product->getName(), null, true) ?>"><?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?></a></h2>

                    <?php
                        $_nameAfterChildren = $this->getChild('name.after')->getSortedChildren();
                        foreach($_nameAfterChildren as $_nameAfterChildName):
                            $_nameAfterChild = $this->getChild('name.after')->getChild($_nameAfterChildName);
                            $_nameAfterChild->setProduct($_product);
                    ?>
                        <?php echo $_nameAfterChild->toHtml(); ?>
                    <?php endforeach; ?>

                    <?php echo $this->getPriceHtml($_product, true) ?>
                    <?php if($_product->getRatingSummary()): ?>
                    <?php echo $this->getReviewsSummaryHtml($_product, 'short') ?>
                    <?php endif; ?>
                    <div class="actions">
                        <?php if($_product->isSaleable() && !$_product->canConfigure()): ?>
                            <button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button>
                        <?php elseif($_product->isSaleable()): ?>
                            <a title="<?php echo $this->__('View Details') ?>" class="button" href="<?php echo $_product->getProductUrl() ?>"><?php echo $this->__('View Details') ?></a>
                        <?php else: ?>
                            <p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
                        <?php endif; ?>
                        <ul class="add-to-links">
                            <?php if ($this->helper('wishlist')->isAllow()) : ?>
                                <li><a href="<?php echo $this->helper('wishlist')->getAddUrl($_product) ?>" class="link-wishlist"><?php echo $this->__('Add to Wishlist') ?></a></li>
                            <?php endif; ?>
                            <?php if($_compareUrl=$this->getAddToCompareUrl($_product)): ?>
                                <li><span class="separator">|</span> <a href="<?php echo $_compareUrl ?>" class="link-compare"><?php echo $this->__('Add to Compare') ?></a></li>
                            <?php endif; ?>
                        </ul>
                    </div>
                </div>
            </li>
<?php } ?>
            <?php /*if ($i%$_columnCount==0 || $i==$_collectionSize): ?>
            <?php endif*/ ?>
        <?php endforeach ?>
    </ul>
    <script type="text/javascript">decorateGeneric($$('ul.products-grid'), ['odd','even','first','last'])</script>
    <?php endif; ?>

    <div class="toolbar-bottom">
        <?php echo $this->getToolbarHtml() ?>
    </div>
</div>
<?php endif; ?>

<?php
    //set product collection on after blocks
    $_afterChildren = $this->getChild('after')->getSortedChildren();
    foreach($_afterChildren as $_afterChildName):
        $_afterChild = $this->getChild('after')->getChild($_afterChildName);
        $_afterChild->setProductCollection($_productCollection);
    ?>
    <?php echo $_afterChild->toHtml(); ?>
<?php endforeach; ?>


Tuesday, 16 September 2014

how to remove .php from urls with htaccess in php

url :-
http://hostname/product.php

create a .htaccess file on root directory  and paste following code :-

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php

then you can access set your link like :-
 http://hostname/product

Tuesday, 9 September 2014

magento product share on pintrest

 Set following code on product view page:-

<script type="text/javascript">
(function(d){
    var f = d.getElementsByTagName('SCRIPT')[0], p = d.createElement('SCRIPT');
    p.type = 'text/javascript';
    p.async = true;
    p.src = 'http://assets.pinterest.com/js/pinit.js';
    f.parentNode.insertBefore(p, f);
}(document));
</script>

 <a href="http://www.pinterest.com/pin/create/button?url=<?php echo $this->helper('catalog/product')->getProductUrl($_product); ?>&media=<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(600,400) ?>&description=<?php echo $_helper->productAttribute($_product, nl2br($_product->getShortDescription()), 'short_description') ?>" data-pin-do="buttonPin" data-pin-config="above">
        <img src="http://assets.pinterest.com/images/pidgets/pin_it_button.png" />
    </a>