Wednesday 5 March 2014

Magento Custom Breadcrumbs for particular CMS page

Paste this code in CMS Page > Design > Page layout > Layout Update XML

<reference name="top.bar">
<action method="unsetChild"><alias>breadcrumbs</alias></action>
<block type="page/html_breadcrumbs" name="breadcrumbs" as="breadcrumbs">
    <action method="addCrumb">
        <crumbName>home</crumbName>
        <crumbInfo><label>Home page</label><title>Home page</title><link>/</link></crumbInfo>
    </action>
    <action method="addCrumb">
        <crumbName>myparentpage</crumbName>
        <crumbInfo><label>My Parent Page</label><title>My Parent Page</title><link>/myparentpage/</link></crumbInfo>
    </action>
    <action method="addCrumb">
        <crumbName>mysubpage</crumbName>
        <crumbInfo><label>My Sub Page</label><title>My Sub Page</title></crumbInfo>
    </action>
</block>
</reference>

Magento How to show/hide template path hints of admin panel/backend.

To show template path hints in admin panel of magento you need to login to your phpmyadmin then run the following sql command.

INSERT INTO core_config_data (scope, scope_id, path, value) VALUES ('default', 0, 'dev/debug/template_hints', 1),
('default', 0, 'dev/debug/template_hints_blocks', 1);

To hide template path hints of admin panel or backed just run the top code by changing 1 to 0, then the template path hints will be hide.
You also can run the following sql command to hide template path hints.


UPDATE core_config_data SET value = '0' WHERE core_config_data.path ='dev/debug/template_hints' OR core_config_data.path ='dev/debug/template_hints_blocks';

Now if you want to show again template path hints in admin panel of magento then run the following sql command.

UPDATE core_config_data SET value = '1' WHERE core_config_data.path ='dev/debug/template_hints' OR core_config_data.path ='dev/debug/template_hints_blocks';

Magento Get methods of an object.

First, use get_class to get the name of an object’s class.

<?php $class_name = get_class($object); ?>

Then, pass that get_class_methods to get a list of all the callable methods on an object

<?php
$class_name = get_class($object);
$methods = get_class_methods($class_name);
foreach($methods as $method)
{
    var_dump($method);
}
?>
 

Magento Check if customer is logged in.

<?php
    $_customer = Mage::getSingleton('customer/session')->isLoggedIn();
    if ($_customer) {}
?>

Magento Get products id, name, price, quantity, etc. present in your cart.

<?php
    $items = Mage::getSingleton('checkout/session')->getQuote()->getAllItems();
   
    foreach($items as $item) {
        echo 'ID: '.$item->getProductId().'<br />';
        echo 'Name: '.$item->getName().'<br />';
        echo 'Sku: '.$item->getSku().'<br />';
        echo 'Quantity: '.$item->getQty().'<br />';
        echo 'Price: '.$item->getPrice().'<br />';
        echo "<br />";
    }
?>

Magento Load Products by Category ID

<?php
$_category = Mage::getModel('catalog/category')->load(47);
$_productCollection = $_category->getProductCollection();
if($_productCollection->count()) {
    foreach( $_productCollection as $_product ):
        echo $_product->getProductUrl();
        echo $this->getPriceHtml($_product, true);
        echo $this->htmlEscape($_product->getName());
    endforeach;
}
?>

Magento Get Current Url

<?php echo Mage::helper('core/url')->getCurrentUrl(); ?>