Sunday 20 March 2016

Magento : How to Rename the Attribute Code?

Connect to your Magento database using your favourite database GUI (PHPMyAdmin, HeidiSQL, MySQL Workbench, etc.).
Caution: backup your database
Go to the table eav_attribute and edit the column attribute_code. You can rename the attribute code here.
Once you have renamed the attribute code in the database, go to the Magento admin and re-index (System > Index Management) all indexes.

Magento : Get Logged In Customer’s Group ID

<?php
/* Check if customer is logged in */
$isLoggedIn = Mage::getSingleton('customer/session')->isLoggedIn();
/* If customer is logged in */
if($isLoggedIn) :
    /* Get the logged in customer's group ID */
    $customerGroupId = Mage::getSingleton('customer/session')->getCustomerGroupId();
    /* Check if the logged in customer's group ID matches with the ID you are after */
    /* Customer group IDs are listed against each group under Admin > Customers > Customer Groups */
    if($customerGroupId == 3) :
        echo 'Welcome Retailer';
    endif;
endif;
?>

You can also write static blocks or custom variables to contain group specific information. You can name the static block identifier based on the $customerGroupId and retrieve it on the front end.

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!