Thursday, October 15, 2015

Use google map with multiple marker


  => We already aware of google map very well. Here I'll show you how can we show a dynamic map with multiple/single marker in your html page.

  •  Single Marker Map :  Here we'll pass the locations with latitude and longitude. see the below code:
                        <script src='https://maps.googleapis.com/maps/api/js?v=3.exp'></script>
<div style='overflow:hidden;height:350px;width:100%;'>
 <div id='gmap_holder' style='height:350px;width:100%;'></div>
</div>
<a href='http://www.maps-generator.com/'>maps-generator</a>
<script type='text/javascript' src='https://embedmaps.com/google-maps-authorization/script.js?id=36146cb0ad5227f5dc8c1bfb291b91c0f83c0c6d'></script> 
<script type='text/javascript'>
function init_map() {
var myOptions = {
zoom: 12,
center: new google.maps.LatLng(22.5736132, 88.3483409),
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById('gmap_holder'), myOptions);
marker = new google.maps.Marker({
map: map,
position: new google.maps.LatLng(22.5736132, 88.3483409)
});
infowindow = new google.maps.InfoWindow({
content: '<strong>Jayanta Roy</strong><br>Kolkata, IN<br>'
});
google.maps.event.addListener(marker, 'click', function() {
infowindow.open(map, marker);
});
infowindow.open(map, marker);  // remove it to show the marker on click only
}
google.maps.event.addDomListener(window, 'load', init_map);
</script> 

         Here change the latitude and longitude shown as bold.
         You can get the latitude and longitude of your location here:    http://maps.googleapis.com/maps/api/geocode/json?address=YOUR ADDRESS/ZIP&sensor=false

  • Multiple Marker Map :  Here we'll create an array of the locations with latitude and longitude. see the below code:
        <script src='https://maps.googleapis.com/maps/api/js?v=3.exp'></script>
        <div style='overflow:hidden;height:350px;width:100%;'>
          <div id='gmap_holder' style='height:350px;width:100%;'></div>
        </div>
        <a href='http://www.maps-generator.com/'>maps-generator</a>
        <script type='text/javascript' src='https://embedmaps.com/google-maps-authorization/script.js?id=36146cb0ad5227f5dc8c1bfb291b91c0f83c0c6d'></script> 
        <script type='text/javascript'>
var locations = [
['Jayanta 1', 22.5683534, 88.36157129999999],
['Jayanta 2', 22.5418011, 88.3600216],
['Jayanta 3', 22.5736132, 88.3483409]
];
        function init_map(locations) {
            var myOptions = {
                zoom: 12,
                center: new google.maps.LatLng(22.5736132, 88.3483409),
                mapTypeId: google.maps.MapTypeId.ROADMAP
            };
            map = new google.maps.Map(document.getElementById('gmap_holder'), myOptions);
            var infowindow = new google.maps.InfoWindow();
var marker, i;
for (i = 0; i < locations.length; i++) {  
marker = new google.maps.Marker({
map: map,
position: new google.maps.LatLng(locations[i][1], locations[i][2])
});
google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {
 infowindow.setContent(locations[i][0]);
 infowindow.open(map, marker);
}
})(marker, i));
infowindow.open(map, marker);
}
        }
        google.maps.event.addDomListener(window, 'load', init_map(locations));
        </script> 


   

Saturday, October 10, 2015

How to know the order can ship OR not in Magento


=> In Magento if your order contains virtual and downloadable products then the shipping section in chekout step will hide. For your custom condition you can use the below code:


$quote = Mage::getSingleton('checkout/session')->getQuote();
if($quote->isVirtual()){
echo "No Ship";
}else{
echo "Ship";
}

Monday, March 30, 2015

Generate static block dropdown in System Configuration in Magento

>    First you need to create the system configuration menu. You'll find many tutorial to create system configuration menu. So, in your system.xml you need add a Source Model like "module/system_config_source_cms_block". Now create a directory in your module: YoureModule/Model/System/Config/Source/Cms/Block.php

Now your Block.php looks like below :

<?php
class CompanyName_YourModule_Model_System_Config_Source_Cms_Block
{

    protected $_options;

    public function toOptionArray()
    {
        if (!$this->_options) {

$collection = Mage::getModel('cms/block')->getCollection();
$staticBlock = array(''=>'-- Select Static Block --');
foreach($collection as $block){
$staticBlock[$block->getIdentifier()] = $block->getTitle();
}

            $this->_options = $staticBlock;
        }
        return $this->_options;
    }

}
?>

Refresh cache to see changes.


Wednesday, March 19, 2014

Magento :: $_product->getAttributes() not working in listing page

     
>>  With the following code every-time you'll get same attributes as it first load the attributes of product and store in a variable. Then from the second time it'll check the variable for the attributes.

        $attributes = $_product->getAttributes();
        foreach ($attributes as $attribute) {
            if ($attribute->getIsVisibleOnFront()) {
                $value = $attribute->getFrontend()->getValue($_product);
                $attributeLabel = $attribute->getFrontendLabel();
                $attributeCode = $attribute->getAttributeCode();
            }
        }
       
        In the above code you'll get the product attribute details and value in listing page if the attribute_set_id for all products in listing page is same. But if the attribute_set_id of all products are different, you need to change your code:
                $attributes = $_product->getAttributes();  
                //Replace this with the following
                $attributes = Mage::getModel('catalog/product')->getResource()
                                      ->loadAllAttributes()
                                      ->getSortedAttributes($_product->getAttributeSetId());



Friday, March 14, 2014

get catalog rule applied price of product in Magento


 >> We use to get product price like :
                       $_product->getPrice();
                       $_product->getFinalPrice();
     
      Here you can get the catalog rule applied price like:
            $store_id = Mage::app()->getStore()->getId();
            $discounted_price = Mage::getResourceModel('catalogrule/rule')->getRulePrice(
                                                      Mage::app()->getLocale()->storeTimeStamp($store_id),
                                                      Mage::app()->getStore($store_id)->getWebsiteId(),
                                                      Mage::getSingleton('customer/session')->getCustomerGroupId(),
                                                                      $_product->getId());
               
           
            if ($discountedPrice===false) { // if no rule applied for the product
                $discountedPrice = $_product->getFinalPrice();
            }else{
                $discountedPrice = number_format($discountedPrice,2);
            }




Thursday, February 6, 2014

Convert special character to normal character in PHP

   
    > You need to convert special character to normal character. Below are the list of some special character:
   
    $special_chars = array(
        'À','à','Á','á','Â','â','Ã','ã','Ä','ä','Å','å','Ă','ă','Ą','ą',
        'Ć','ć','Č','č','Ç','ç',
        'Ď','ď','Đ','đ',
        'È','è','É','é','Ê','ê','Ë','ë','Ě','ě','Ę','ę',
        'Ğ','ğ',
        'Ì','ì','Í','í','Î','î','Ï','ï',
        'Ĺ','ĺ','Ľ','ľ','Ł','ł',
        'Ñ','ñ','Ň','ň','Ń','ń',
        'Ò','ò','Ó','ó','Ô','ô','Õ','õ','Ö','ö','Ø','ø','ő',
        'Ř','ř','Ŕ','ŕ',
        'Š','š','Ş','ş','Ś','ś',
        'Ť','ť','Ť','ť','Ţ','ţ',
        'Ù','ù','Ú','ú','Û','û','Ü','ü','Ů','ů',
        'Ÿ','ÿ','ý','Ý',
        'Ž','ž','Ź','ź','Ż','ż');
       
         Now try the below code to convert these to normal character :
       
        $text = "éèçâñüÄ";
        $htmlchar = htmlentities($text, ENT_COMPAT, 'UTF-8');  //éèçâñüÄ
        $text = preg_replace("/&([a-z])[a-z]+;/i", "$1", htmlentities($text, ENT_COMPAT, 'UTF-8'));  //eecanuA

           
       
       

Tuesday, January 21, 2014

Uses of $this->getChildHtml() in Magento


        >> $this->getChildHtml() is a known features to include a child block in a page. I'm simplifying this with an example:
     
      In your XML : 
       <block type="core/template" name="parent_block" template="example/test.phtml">
             <block type="core/template" name="child_block" template="example/test_child.phtml"/>
       </block>

      Now in your test.phtml you can include the child block like : 
             <?php echo $this->getChildHtml('child_block'); ?>

      
       >> You can also pass a variable to this block. I've shown this in my previous post. Now if you want to pass dynamic value to the child block, here's it:

           <?php
                $this->getChild('child_block')->setData('product_id', $productId);
                echo $this->getChildHtml('child_block', false);
            ?>


         Here $productId is your dynamic value and you need to pass "false" (Block Caching No) as  additional parameter in childHtml(). By default it takes "true" (Block Caching Yes).
     
        You can get the product id in test_child.phtml with $this->getProductId()