Sunday, 20 March 2016

Magento : Check if CMS Static Block is Enabled / Active

Static blocks in Magento are really useful. They offer an easy way to insert content into various parts of the template. You are only limited by your imagination. You can check if the static blocks are enabled, before printing them to screen.
<?php 
if(Mage::getModel('cms/block')->load('static-block-identifier')->getIsActive()) : 
    echo Mage::app()->getLayout()->createBlock('cms/block')->setBlockId('static-block-identifier')->toHtml(); 
endif; 

?>

Magento : Get CMS Static Block Model Data (Title, Status, Content)

You can store template and HTML data in Magento’s static blocks. If you want to pull it into your PHTML templates, just call load up the model and use the data fields.

<?php
$staticBlock = Mage::getModel('cms/block')->load('static-block-identifier');
echo $staticBlock->getTitle();
echo $staticBlock->getIdentifier();
echo $staticBlock->getIsActive();
echo $staticBlock->getContent();

?>

Magento : Get Current Package Name and Theme Name

// To get the current package name of the Magento store / site
Mage::getSingleton('core/design_package')->getPackageName();

// To get the current theme of the Magento store / site
Mage::getSingleton('core/design_package')->getTheme('frontend');

// You can pass 'locale', 'layout', 'template', 'default', or 'skin' into the above function.

Magento : Disable Toolbar Sort / Order By Memory Cookie

<reference name="product_list_toolbar">
    <action method="disableParamsMemorizing"/>
</reference>

Magento : Get Current Store Details (ID, Code, Name and Status)

// Gets the current store's details
$store = Mage::app()->getStore();

// Gets the current store's id
$storeId = Mage::app()->getStore()->getStoreId();
// Gets the current store's code
$storeCode = Mage::app()->getStore()->getCode();
// Gets the current website's id
$websiteId = Mage::app()->getStore()->getWebsiteId();
// Gets the current store's group id
$storeGroupId = Mage::app()->getStore()->getGroupId();
// Gets the current store's name
$storeName = Mage::app()->getStore()->getName();
// Gets the current store's sort order
$storeSortOrder = Mage::app()->getStore()->getSortOrder();
// Gets the current store's status
$storeIsActive = Mage::app()->getStore()->getIsActive();
// Gets the current store's locale
$storeLocaleCode = Mage::app()->getStore()->getLocaleCode();
// Gets the current store's home url
$storeHomeUrl = Mage::app()->getStore()->getHomeUrl();

Saturday, 5 March 2016

WordPress : Remove Version Query Strings From JavaScript JS and CSS Stylesheet Files

In efforts to increase the performance of a WordPress website, tools like Google Page Speed and Yahoo YSlow may direct you to remove the query string from JavaScript and CSS files. Most scripts and stylesheets called by WordPress include a query string identifying the version. This can cause issues with caching and such, which will result in less than optimal load times.

For instance, jQuery.js may show up like:

/wp-includes/js/jquery/jquery.js?ver=1.4.2


there is a very simple function that can be added to remove all query strings from script and css files.
In your theme’s function file (Appearance > Editor > Functions.php), add the following code before the closing PHP tag (%>) at the bottom of the file:


function _remove_script_version( $src ){
$parts = explode( '?', $src );
return $parts[0];
}
add_filter( 'script_loader_src', '_remove_script_version', 15, 1 );
add_filter( 'style_loader_src', '_remove_script_version', 15, 1 );


Hope you find this helpful!

Thursday, 19 February 2015

Magento : How to get customer group Id and group name in Magento?

It is very simple in Magento. Please follow my below code.


$login = Mage::getSingleton( ‘customer/session’ )->isLoggedIn(); //Check if User is Logged In
if($login)
{
$groupId = Mage::getSingleton(‘customer/session’)->getCustomerGroupId(); //Get Customers Group ID
echo “Group ID ::  “.$groupId;
$group = Mage::getModel(‘customer/customer_group’)->load($groupId);
echo “Group Name :: “.$group->getName();
}



Hope it will help you.