Saturday 10 August 2013

How to Configure Magento for Development / Debug Mode

1. Disable Cache
System > Cache Management > Select All [check-boxes] > Actions = Disable > Submit
2. Re-Index All
System > Index Management > Select All [check-boxes] > Actions = Reindex Data > Submit
3. Disable Compilation
System > Tools > Compilation > Disable
Note: By default compilation mode is disabled. So just check if the Compiler Status is Enabled or not.
4. Turn on Error Reporting
a> Open index.php and un-comment the following line
1
#ini_set('display_errors', 1);
b> Open .htaccess and add the following line at the end
1
SetEnv MAGE_IS_DEVELOPER_MODE "true"
5. Turn on Logging
System > Configuration > Advanced > Developer > Log Settings > Enabled => Yes
6. Configuring Mangeto Error Page
rename errors/local.xml.sample to errors/local.xml

7. Install ‘Easy Template Path Hints’
Install Easy Template Path Hints for turning on/off the template path hints for frontend and backend easily & securely.

Friday 9 August 2013

Custom search engine friendly (SEF) URL In Magento.


Custom SEF helper method

class <Namespace>_<Module>_Helper_Data extends Mage_Core_Helper_Abstract
{
function custom_sef_url($id_path, $request_path, $target_path, $store_id ="0", $is_system=false){
$isrewrite = Mage::getModel('core/url_rewrite')->load($id_path,id_path);
    if($isrewrite->url_rewrite_id !=""){
      throw new Exception("Your Id path must be unique, given id path already in use !");
    }
      $rewrite = Mage::getModel('core/url_rewrite');
      $rewrite->setStoreId($store_id)
        ->setIdPath($id_path)
        ->setRequestPath($request_path)
        ->setTargetPath($target_path)
        ->setIsSystem($is_system)
        ->save();       
return;
}
}

Where should I call Custom SEF helper method?

Normally we need to create the custom URL once the new item is created, so we need to call this method in your “saveAction()” function after saving process. Let’s take FAQ items as example.

public function saveAction()
{

// .... faq saving process

try{
  $id_path = "faq/".$id;  // Id path must be unique
  $request_path = "fag/".$fag_title;
  $target_path  = "fag/index/index/id/".$id;

   Mage::helper('<module>')-&gt;custom_sef_url($id_path, $request_path, $target_path);
}
catch (Exception $e) {

 Mage::getSingleton('adminhtml/session')-&gt;addError($e-&gt;getMessage());

}

}

Saturday 20 July 2013

Call Direct Template page from controller in magento.

Call Direct Template page from controller.

if ($this->getRequest()->getParam('result') > 0) {
$this->loadLayout();
            if((bool) $this->getRequest()->getParam('result')){
                $this->_initLayoutMessages('customer/session');
                $this->_initLayoutMessages('catalog/session');
                 if ($block = $this->getLayout()->getBlock('root')) {
                    $block->setRefererUrl($this->_getRefererUrl());
                }
                $this->getLayout()->getBlock('root')->setTemplate('quiz/result_rating.phtml'); //changes the root which if you want template.
            }
            $this->renderLayout();
            return $this;
}

Friday 19 July 2013

Get product price in Magento

<?php
// assuming that you have known product object, $_product
//get product price snippet
echo $this->getPriceHtml($_product, true);
//get $_product price
echo $_product->getPrice();
echo number_format($_product->getPrice(), '2', '.', ',');
//get $_product special price
echo $_product->getSpecialPrice();
echo number_format($_product->getSpecialPrice(), '2', '.', ',');
//get $_product final price
echo $_prodcut->getFinalPrice();
echo number_format($_product->getFinalPrice(), '2', '.', ',');
//get $_product Msrp
echo $_product->getMsrp();
echo number_format($_product->getMsrp(), '2', '.', ',');
?>

Saturday 14 July 2012

Magento 1.7 to 1.9 Add To Cart Multi Products

<!--  copy this file and past your list.phtml in catalog/product   -->

<?php
    $_productCollection=$this->getLoadedProductCollection();
    $_helper = $this->helper('catalog/output');
?>
<?php if(!$_productCollection->count()): ?>
<p class="note-msg"><?php echo $this->__('There are no products matching the selection.') ?></p>
<?php else: ?>
<div class="category-products">
    <?php echo $this->getToolbarHtml() ?>

 <!--  <button class="button btn-allcart" type="button" title="Add all to cart" onclick="AddAllToCart();"> -->

    <?php // List mode ?>
    <?php if($this->getMode()!='grid'): ?>
    <?php $_iterator = 0; ?>
    <ol class="products-list" id="products-list">
    <button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart" onclick="AddAllToCart();"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button>
          <button onclick="AddAllToCart();" class="button btn-cart" type="button" title="Add all to cart">
<span>
<span>Add all to cart</span>
</span>
</button>

    <?php foreach ($_productCollection as $_product): ?>
    <?php echo $_product->getId();?>
        <li class="item<?php if( ++$_iterator == sizeof($_productCollection) ): ?> last<?php endif; ?>">
            <?php // Product Image ?>
            <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" class="product-image"><img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(135); ?>" width="135" height="135" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" /></a>
            <?php // Product description ?>
            <div class="product-shop">
                <div class="f-fix">
                    <?php $_productNameStripped = $this->stripTags($_product->getName(), null, true); ?>
                    <h2 class="product-name"><a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $_productNameStripped; ?>"><?php echo $_helper->productAttribute($_product, $_product->getName() , 'name'); ?></a></h2>
                    <?php if($_product->getRatingSummary()): ?>
                    <?php echo $this->getReviewsSummaryHtml($_product) ?>
                    <?php endif; ?>
                    <?php echo $this->getPriceHtml($_product, true) ?>
                    <?php if($_product->isSaleable()): ?>
                 
                    <fieldset class="add-to-cart-box">
                        <input type="hidden" name="products[]" value="<?php echo $_product->getId() ?>" />
                        <legend><?php echo $this->__('Add Items to Cart') ?></legend>
                        <span class="qty-box"><label for="qtybox_id_<?php echo $_product->getId() ?>"><?php echo $this->__('Qty') ?>:</label>
                        <!--<input name="qty<?php echo $_product->getId() ?>" type="text" class="input-text qty" id="qtybox_id_<?php echo $_product->getId() ?>" maxlength="12" value="" />--></span>
                       <!--<input type="checkbox" class="input-checkbox add" name="add_<?php echo $_iterator; ?>" id="add_<?php echo $_iterator; ?>" />-->
                     

<!------------------------------------------------- Start 1st part Add to cart Multiple products ------------------------------------------------->

<input type="hidden" class="add" name="url_<?php echo $_iterator; ?>" id="url_<?php echo $_iterator; ?>" value="<?php echo $this->getAddToCartUrl($_product) ?>" />
<?php if(!$_product->isGrouped()): ?>
     <input type="text" class="input-text qty" name="qty_<?php echo $_iterator; ?>" id="qty_<?php echo $_iterator; ?>" maxlength="12" value="<?php echo $this->getMinimalQty($_product) ?>" />
<!----------------------------------------------- End 1st part Add to cart Multiple products ------------------------------------------------------->


<?php endif; ?>

                    </fieldset>
                       <!-- <p><button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button></p>
                       -->
                    <?php else: ?>
                        <p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
                    <?php endif; ?>
                    <div class="desc std">
                        <?php echo $_helper->productAttribute($_product, $_product->getShortDescription(), 'short_description') ?>
                        <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $_productNameStripped ?>" class="link-learn"><?php echo $this->__('Learn More') ?></a>
                    </div>
                    <ul class="add-to-links">
                        <?php if ($this->helper('wishlist')->isAllow()) : ?>
                            <li><a href="<?php echo $this->helper('wishlist')->getAddUrl($_product) ?>" class="link-wishlist"><?php echo $this->__('Add to Wishlist') ?></a></li>
                        <?php endif; ?>
                        <?php if($_compareUrl=$this->getAddToCompareUrl($_product)): ?>
                            <li><span class="separator">|</span> <a href="<?php echo $_compareUrl ?>" class="link-compare"><?php echo $this->__('Add to Compare') ?></a></li>
                        <?php endif; ?>
                    </ul>
                </div>
            </div>
        </li>
     
<!------------------------------------------------- Start 2nd part Add to cart Multiple products ------------------------------------------------->
     
        <script type="text/javascript">
    function processNext(urls, i) {
        var next = i + 1;
        $('processing-text').update('Processing item ' + next);
        if (next < urls.size()) {
            new Ajax.Request(urls[i], {
              method: 'get',
              onComplete: function(transport) {
                processNext(urls, next);
              }
            });
        } else {
            new Ajax.Request(urls[i], {
              method: 'get',
              onComplete: function(transport) {
                window.location.href='checkout/cart'
              }
            });
        }
    }

    function addItemsToCart() {
        $('add-items-to-cart').hide();
        $('waiting').show();

        var addToCartUrls = [];
        $$('input.add').each(function(e){
var id = e.readAttribute('id').split('_')[1];
//alert(id);
var qty = Number($('qty_' + id).value);
            if(qty > 0) {
//alert(qty);
                addToCartUrls.push($('url_' + id).value + 'qty/' + qty);
            }
        });

        if (addToCartUrls.size() > 0) {
            processNext(addToCartUrls, 0);
        } else {
            $('add-items-to-cart').show();
            $('waiting').hide();
            alert('Please add quantity for product then click add to cart button');
        }
    }
</script>
<!----------------------------------------------- End 2nd part Add to cart Multiple products ------------------------------------------------------->

    <?php endforeach; ?>
<!------------------------------------------------- Start 3rd part Add to cart Multiple products ------------------------------------------------->
 
    <div style="margin-bottom:5px; text-align:right;">
    <button id="add-items-to-cart" class="form-button" onclick="addItemsToCart()"><span><?php echo $this->__('Add Items to Cart') ?></span></button>
    <div id="waiting" style="height:22px; display:none; line-height:22px;"><span id="processing-text">Processing...</span> <img src="<?php echo $this->getSkinUrl().'ajaxlog_loader.gif'; ?>" width="22" height="22" style="display:inline; vertical-align:middle;"/></div></div>

    </ol>
    <script type="text/javascript">decorateList('shopping-cart-table')</script>
 
<!----------------------------------------------- End 3rd part Add to cart Multiple products ------------------------------------------------------->
 
<button onclick="AddAllToCart();" class="button btn-allcart" title="Add all to cart" type="button"><span><span>Add all to cart</span></span></button>



    <?php else: ?>

    <?php // Grid Mode ?>

    <?php $_collectionSize = $_productCollection->count() ?>
    <?php $_columnCount = $this->getColumnCount(); ?>
    <?php $i=0; foreach ($_productCollection as $_product): ?>
        <?php if ($i++%$_columnCount==0): ?>
        <ul class="products-grid">
        <?php endif ?>
            <li class="item<?php if(($i-1)%$_columnCount==0): ?> first<?php elseif($i%$_columnCount==0): ?> last<?php endif; ?>">
                <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" class="product-image"><img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(135); ?>" width="135" height="135" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" /></a>
                <h2 class="product-name"><a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($_product->getName(), null, true) ?>"><?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?></a></h2>
                <?php if($_product->getRatingSummary()): ?>
                <?php echo $this->getReviewsSummaryHtml($_product, 'short') ?>
                <?php endif; ?>
                <?php echo $this->getPriceHtml($_product, true) ?>
                <div class="actions">
                    <?php if($_product->isSaleable()): ?>
                        <button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button>
                    <?php else: ?>
                        <p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
                    <?php endif; ?>
                    <ul class="add-to-links">
                        <?php if ($this->helper('wishlist')->isAllow()) : ?>
                            <li><a href="<?php echo $this->helper('wishlist')->getAddUrl($_product) ?>" class="link-wishlist"><?php echo $this->__('Add to Wishlist') ?></a></li>
                        <?php endif; ?>
                        <?php if($_compareUrl=$this->getAddToCompareUrl($_product)): ?>
                            <li><span class="separator">|</span> <a href="<?php echo $_compareUrl ?>" class="link-compare"><?php echo $this->__('Add to Compare') ?></a></li>
                        <?php endif; ?>
                    </ul>
                </div>
            </li>
        <?php if ($i%$_columnCount==0 || $i==$_collectionSize): ?>
        </ul>
        <?php endif ?>
        <?php endforeach ?>
        <script type="text/javascript">decorateGeneric($$('ul.products-grid'), ['odd','even','first','last'])</script>
    <?php endif; ?>

    <div class="toolbar-bottom">
        <?php echo $this->getToolbarHtml() ?>
    </div>
</div>
<?php endif; ?>

    <!--
    <button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart" onclick="AddAllToCart();"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button>
          <button onclick="AddAllToCart();" class="button btn-cart" type="button" title="Add all to cart">
         <button class="button btn-allcart" type="button" title="Add all to cart" onclick="AddAllToCart();"> -->

Saturday 26 May 2012

Get URL With Id ex : id="1500" in Joomla

JRequest::getVar

<?php $itemid = JRequest::getVar('Itemid');
if($itemid == '50')
{
    echo '<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>';

}
?>