Saturday 31 August 2013

Methods for removing jquery conflict in magento or other cms


<script>
$.noConflict();
jQuery(document).ready(function($) {});
</script>

<script type="text/javascript">
  $.noConflict(); //Use no conflict here instead of js file
  // Code that uses other library's $ can follow here.
</script>

<script type="text/javascript" >
    jQuery.noConflict();
</script >

Above are those methods which helps to solve jquery conflicts in different-2 situation.

Or If its all does not work:

Please check the front-end with rename the library file of jquery.
May be its already include with other conflict script.

Tuesday 27 August 2013

How to overwrite magento controller in local pool


For Example you have to overwrite Mage/Contacts/controller/IndexController.php

Step 1: First you have to make a xml in app/etc/modules/
with name CompanyName_NameSpace.xml

<?xml version="1.0"?>
<config>
  <modules>
    <CompanyName_NameSpace>
      <active>true</active>
      <codePool>local</codePool>
      <version>0.1.0</version>
    </CompanyName_NameSpace>
  </modules>
</config>



Step2: You have to create the folders if not exist in
local/CompanyName/NameSpace/etc/
local/CompanyName/NameSpace/controllers/

In etc folder you have to create a config.xml file
<?xml version="1.0" encoding="utf-8"?>
<config>
    <frontend>
        <routers><!--Depending on the controllers area "frontend" or "admin" -->
            <contacts><!-- base module to rewrite -->
                <args>
                    <modules>
                         <CompanyName_NameSpace before="Mage_Contacts">Shweta_Newscontacts</CompanyName_NameSpace>
                    </modules>
                </args>
            </contacts>
        </routers>
    </frontend>
</config>




In controllers folder copy the Mage/Contacts/controller/IndexController.php file and include the lines:

include_once('Mage/Contacts/controllers/IndexController.php');
and
change the class name as:
class CompanyName_NameSpace_IndexController extends Mage_Core_Controller_Front_Action


Now apply changes in the file you wanted.
Now also, Magento take local pool file instead of core pool.

To show a perticular root category's sub categories with thumbnail images in magento


<div class="product">

<?php
$children = Mage::getModel('catalog/category')->getCategories(3);
$j=1;
?>

<ul>

<?php
foreach ($children as $category):
$category=Mage::getModel('catalog/category')->load($category->getId());
?>
<li>
<div class="new_product">
<div class="pro_detail">
<p><?php echo $category->getName() ?> </p>
</div>
<div class="pro_img"> <a href="<?php echo $category->getUrl() ?>"> <img src="<?php echo Mage::getBaseUrl('media').'catalog/category/'.$category->getThumbnail()  ?>" width="54" height="66" /> </a>
</div>



</div>
</li>
<?php if($j%4=='0') {?>
</ul>
<ul>
<?php } $j++;  endforeach;  ?>
</ul>


</ul>
</div>

Monday 19 August 2013

how to find shipping amount| How to display shipping and handing separately


Add This lines to any where in template file.

This is for getting the full array shipping:

<?php $carriers = Mage::getStoreConfig('carriers', Mage::app()->getStore()->getId());
foreach ($carriers as $carrierCode => $carrierConfig) {

print_R($carrierConfig);

}
?>


This is for getting the flat rate shipping and handling:


  <?php $carriers = Mage::getStoreConfig('carriers', Mage::app()->getStore()->getId());
foreach ($carriers as $carrierCode => $carrierConfig) {
if($carrierConfig[model]=='shipping/carrier_flatrate') {
print_R($carrierConfig[price]);
echo "<br/>";
print_R($carrierConfig[handling_fee]);
}
}
?>

Wednesday 7 August 2013

How to Get Current Url/media,skin,js,home url In magento


To get Current Url
<?php
$currentUrl = $this->helper('core/url')->getCurrentUrl();
?>



Get Magento Url including index.php if not rewrited.

e.g. http://www.example.com/index.php/
Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK);


Get Magento Media Url

e.g. http://www.example.com/media/
Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA);


Get Magento Skin Url

e.g. http://www.example.com/skin/
Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN);


Get Magento Store Url

e.g. http://www.example.com/
Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);



Get Magento Js Url

e.g. http://www.example.com/js/
Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_JS);



Get Home URL
$magento_home_url = Mage::helper('core/url')->getHomeUrl();


Get not secure Skin URL:
$image = $this->getSkinUrl('images/magento-image.jpg');



Get secure Skin URL
$image = $this->getSkinUrl('images/magento-image.jpg', array('_secure'=>true));


Magento Syntaxes to use in CMS Content.


Get SKIN URL
{{skin url='images/magento-image.jpg '}}
Get Media URL
{{media url='/magento-image.jpg'}}
Get Store URL
{{store url='magento-page.html'}}
Get Base URL
{{base url='magento-page.html'}}


Get full Skin Url inside code

e.g. http://www.example.com/skin/frontend/default/default/
Mage::app()->getLayout()->getBlock('head')->getSkinUrl();

How to exclude/Remove state from shipping in magento


Go to /app/code/core/Mage/Directory/Helper/data.php
Overwrite the default function with this

public function getRegionJson()
{
$exclude_regions = array ('AL','NJ','NY','CT','AS','AK','AA'); //this is the code of excluded state

Varien_Profiler::start('TEST: '.__METHOD__);
if (!$this->_regionJson) {
$cacheKey = 'DIRECTORY_REGIONS_JSON_STORE'.Mage::app()->getStore()->getId();
if (Mage::app()->useCache('config')) {
$json = Mage::app()->loadCache($cacheKey);
}
if (empty($json)) {
$countryIds = array();
foreach ($this->getCountryCollection() as $country) {
$countryIds[] = $country->getCountryId();
}
$collection = Mage::getModel('directory/region')->getResourceCollection()
->addCountryFilter($countryIds)
->load();
$regions = array();
foreach ($collection as $region) {

$rg = $region->getCode();

//if ($rg!=’AL’){
if(!in_array($rg, $exclude_regions)) {

if (!$region->getRegionId()) {
continue;
}
$regions[$region->getCountryId()][$region->getRegionId()] = array(
'code' => $region->getCode(),
//’name’ => $region->getName()
'name' => $this->__($region->getName())
);
}

}
$json = Mage::helper('core')->jsonEncode($regions);

if (Mage::app()->useCache('config')) {
Mage::app()->saveCache($json, $cacheKey, array('config'));
}
}
$this->_regionJson = $json;
}

Varien_Profiler::stop('TEST: '.__METHOD__);
return $this->_regionJson;
}