Tuesday, 4 February 2014

Magento Add Custom Breadcrumbs In custom Module.

Add following code in you modules block file.

public function _prepareLayout()
{
    $breadcrumbs = $this->getLayout()->getBlock('breadcrumbs');
    $breadcrumbs->addCrumb('home', array('label'=>Mage::helper('cms')->__('Home'), 'title'=>Mage::helper('cms')->__('Home Page'), 'link'=>Mage::getBaseUrl()));
    $breadcrumbs->addCrumb('an_alias', array('label'=>'Your label', 'title'=>'Your title', 'link'=>Mage::getUrl("your_module/your_block")));

    return parent::_prepareLayout();
}

Friday, 31 January 2014

Magento Disable Cache For Particular Block Useing XML.

In my case i have disable cache for footer.

<block type="page/html_footer" name="footer" as="footer" template="page/html/footer.phtml">

    <action method="unsetData"><key>cache_lifetime</key></action>
    <action method="unsetData"><key>cache_tags</key></action>
               
</block>

Tuesday, 7 January 2014

Magento Add Rel Canonical Url

To apply simply click on System > Configuration > Catalog > Search Engine Optimizations Section

Then simply change from no to yes and then click on the “Save Config” button in the top right hand corner.


Monday, 23 December 2013

Magento Add "addAttributeToFilter() function" with Conditionals.

1) Equals: eq

 $_products->addAttributeToFilter('status', array('eq' => 1));

 2) Not Equals - neq

 $_products->addAttributeToFilter('sku', array('neq' => 'test-product'));

 3) Like - like

 $_products->addAttributeToFilter('sku', array('like' => 'UX%'));

 4) Not Like - nlike

 $_products->addAttributeToFilter('sku', array('nlike' => 'err-prod%'));

 5) In - in

 $_products->addAttributeToFilter('id', array('in' => array(1,4,98)));

 6) Not In - nin

 $_products->addAttributeToFilter('id', array('nin' => array(1,4,98)));

 7) NULL - null

 $_products->addAttributeToFilter('description', 'null');

 8) Not NULL - notnull

 $_products->addAttributeToFilter('description', 'notnull');

 9) Greater Than - gt

 $_products->addAttributeToFilter('id', array('gt' => 5));

 10) Less Than - lt

 $_products->addAttributeToFilter('id', array('lt' => 5));

 11) Greater Than or Equals To- gteq

 $_products->addAttributeToFilter('id', array('gteq' => 5));

 12) Less Than or Equals To - lteq

 $_products->addAttributeToFilter('id', array('lteq' => 5));

Magento Arrange Collection in Specific Range Like A-D, 0-9 etc.

Add this code after any collection.

<?php $collection_AtoD->getSelect()->where("name like 'A%' or name like 'B%' or name  like 'C%' or name  like 'D%'"); ?>

Magento Show Discount in Special Price.

Add this code in template > catalog > product > price.phtml

<?php if($_finalPrice < $_price): ?>    
<?php $_savePercent = 100 - round(($_finalPrice / $_price) * 100); $_saveAmount = number_format(($_price - $_finalPrice), 2); ?>        
<p class="yousave">           
    <span class="price-label label">You Save: </span>           
    <span class="price">
        <strong class="save-amount">$<?php echo $_saveAmount; ?></strong> (<?php echo $_savePercent; ?>%)
    </span>
</p>   
<?php endif; ?>

Friday, 22 November 2013

Add Quantity Increment Decrement Buttons In Magento

app\design\frontend\default\your theme\template\catalog\product\view\addtocart.phtml

<?php $_product = $this->getProduct(); ?>
<?php $buttonTitle = $this->__(‘Add to Cart’); ?>
<?php if($_product->isSaleable()): ?>
<div>
<?php if(!$_product->isGrouped()): ?>
<div>
<label for=”qty”><?php echo $this->__(‘Qty:’) ?></label>
<span> <a href=”javascript:void(0)” onclick=”decrementQty(‘qty’);”><img src=”<?php echo $this->getSkinUrl(‘images/qty_mns_btn.jpg’) ?>” alt=”minus” /></a></span>
<span> <input type=”text” name=”qty” id=”qty” maxlength=”6″ value=”1″ title=”Antal” /></span>
<?php endif; ?>
<span> <a href=”javascript:void(0);” onclick=”incrementQty(‘qty’);”><img src=”<?php echo $this->getSkinUrl(‘images/qty_plus_btn.jpg’) ?>” alt=”minus” /></a></span>
</div>
<button title=”<?php echo $buttonTitle ?>” onclick=”productAddToCartForm.submit(this)”><span><span><?php echo $buttonTitle ?></span></span></button>
<?php echo $this->getChildHtml(”, true, true) ?>
</div>
<?php endif; ?>
<script type=”text/javascript”>
//<![CDATA[
function decrementQty(id) {
var val = parseInt($(id).getValue());
if(val != 1)
document.getElementById(id).value = val - 1;
}
function incrementQty(id) {
var val = parseInt($(id).getValue());
document.getElementById(id).value = val + 1;
}
//]]>
</script>