Google+

Pages

Monday, July 30, 2012

Hide Attributes which have no value in Magento

If you don't provide a value of attribute for a product in Magento, it displays as 'No' rather than hiding that attribute. This means attributes that aren't relevant for a product will still appear confusing the user. Which is a bad impression of your website.

To hide these unnecessary attributes, do the following:


Open attribute.phtml, which is located in app/design/frontend/[your package]/[your theme]/template/catalog/product/view folder, and find code like this:



<?php foreach ($_additional as $_data): ?>
    <tr>
        <th><?php echo $this->htmlEscape($this->__($_data['label'])) ?></th>
        <td><?php echo $_helper->productAttribute($_product, $_data['value'], $_data['code']) ?></td>
    </tr>
<?php endforeach; ?>


Now replace this by:



<?php foreach ($_additional as $_data): ?>
    <?php $_attribute = $_product->getResource()->getAttribute($_data['code']);
    if (!is_null($_product->getData($_attribute->getAttributeCode())) && ((string)$_attribute->getFrontend()->getValue($_product) != ")) { ?>
        <tr>
            <th><?php echo $this->htmlEscape($this->__($_data['label'])) ?></th>
            <td><?php echo $_helper->productAttribute($_product, $_data['value'], $_data['code']) ?></td>
        </tr>
    <?php } ?>
<?php endforeach; ?>


and you are done.. enjoy.. :)


Get The Current Category in Magento


Try below code to get currently loaded product id:

$category_id = Mage::getSingleton('catalog/layer')
               ->getCurrentCategory()
               ->getId();

When you don’t have access to $this, you can use Magento registry:

$category_id Mage::registry('current_category')->getId();

Enjoy.. :)

Get Last Order ID From The Session in Magento

If you want to get last order Id from session, just use this code:


Mage::getSingleton('checkout/session')->getLastOrderId();


This will give you last order id.


That's all.. :)

Friday, July 27, 2012

Getting records between dates using addAttributeToFilter


To get records between two dates using addAttributeToFilter, use code like this:

$collection->addAttributeToFilter('start_date', array('date' => true, 'to' => $todaysDate))
    ->addAttributeToFilter('end_date', array(array(
        array('date' => true, 'from' => $todaysDate),
        array('null' => true)
    ), 'left');

Note: Where $collection is collection from your model.
Note: $todaysDate can be replaced by date of your choice.

That's all.. cheers.. :)

Tuesday, July 24, 2012

How to change the Magento Admin Panel Title?

If you want to change default title of Magento Admin, there is an easy solution:
Just open the main.xml file, which is located in app/design/adminhtml/default/default/layout folder.
Find line like below: 
<action method="setTitle" translate="title"><title>Magento Admin</title></action>
 and replace the words Magento Admin with the words you like to be in default title.

That's all.. Enjoy.. :)

Monday, July 23, 2012

FIX: Magento Contact Form Email showing HTML

Some times we face a problem with Magento contact form, where the contact email shows all the HTML code.

In order to fix this problem, try this:

Go to [Magento Root Folder]/app/locale folder, then go to your language folder (such as en_US) and place the contactemail.html file in template/email folder from base language package.


Thats all.. Enjoy.. :)

Sunday, July 22, 2012

Magento: Disable category from top menu if list is empty for that category

Hi friends,

Many times we face a problem that we add categories to our magento store, but for one or more categories, we don't have products to show customer at that time.

In that case, we may not want to show that category in top menu, as it gives a bad impression to customers that there is no product in category.

You can hide that particular category from Top Menu, if it has no product. To do this, go to:

app/code/core/Mage/Catalog/Block Folder and copy Navigation.php Override Navigation.php in your local package.

Open Navigation.php of your package and paste below code in this file:


if ($category->getIsActive()) {
    $cat = Mage::getModel('catalog/category')->load($category->getId());
    $products = Mage::getResourceModel('catalog/product_collection')->addCategoryFilter($cat);
    Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($products);
    Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($products);
    Mage::getSingleton('cataloginventory/stock')->addInStockFilterToCollection($products);
    if(count($products)==0)
       return;
}

Save file and enjoy.. :)

Sunday, July 15, 2012

Magento: How to add Google Analytics

Google Analytics (GA) is a free service offered by Google, that allows website administrators to monitor their website's traffic.

Magento supports two types of tracking:

E-commerce Tracking: which lists the customers that made purchase on that particular store and also tells what they bought.
and
Page View Tracking: which lists the origin from which your web store visitors linked to your store.

To use Google Analytics for any of these cases, first you will need to sign-up for Google Analytics account on Google.(URL: http://www.google.com/analytics/sign_up.html)

Obviously, above step is necessary for those who don't have Google Analytics Account yet.(Otherwise you can use your existing account also)

Here you will need to add Account NameWebsite's URL and Time zone.

As soon as you fill these fields and sign up, you will be redirected to the page where you will get Tracking ID for your website.

Now copy this Tracking ID and login to your website's admin panel.

now go to System-->Configuration-->Google API.

Click on Google Analytics tab in content area.



Here you need to select Enabled to Yes, paste the Tracking ID, that you copied earlier in Account Number field.

Now save your configuration.

That's all set now.. Cheers.. :)

Wednesday, July 11, 2012

Magento Fix: Add to Cart button adds the item twice in Internet Explorer

Sometimes in Internet Explorer, when we click on "Add to Cart" button, it adds product twice in the cart. This problem can occur due to many different reasons. Some of quick checks to resolve this problem are:

Solution 1:
Go to:
app/design/frontend/default/default/template/catalog/product/view folder, and copy addtocart.phtml and paste it into app/design/frontend/[your_package]/[your_theme]/template/catalog/product/view folder.

Now find some thing like this:

onclick="productAddToCartForm.submit();"

and replace it with:

onclick="productAddToCartForm.submit(); return false;"

 
Solution 2:
Go to:

app/design/frontend/default/default/template/catalog/product/view folder, and copy addtocart.phtml and paste it into app/design/frontend/[your_package]/[your_theme]/template/catalog/product/view folder.

Now find some thing like this:

onclick="productAddToCartForm.submit();"

and replace it with:

onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"

Note:Where $_product is object, by which we are getting product information.

Hopefully, one of these will solve your problem.

Enjoy.. :)

Magento: How to add Pin it button on product pages

Hi all,

To add Pin it button on product pages, just use the following process:

Add the following code, right where you want to show the pin it button:

<a href="http://pinterest.com/pin/create/button/?url=<?php echo $this->helper('core/url')->getCurrentUrl(); ?>&media=<?php echo $productImage; ?>" class="pin-it-button" count-layout="horizontal"><img border="0" src="//assets.pinterest.com/images/PinExt.png" title="Pin It" /></a>

Note: Where $productImage is the url of product image.

Add the following code to add pinit.js once just above after the above code:

<script type="text/javascript" src="//assets.pinterest.com/js/pinit.js"></script>

Note: Remember that you have to include this line only once on whole page.

Note: horizontal can be replaced by vertical or none


That's it.. Enjoy :)

Monday, July 9, 2012

Unable to get to Magento backend after changing default website

If you've tried to change the default website other than the website which has the base URL, and now you are unable to get your website's backend. Do not worry..


Here is a simple solution to get your admin panel back.
  1. Login to your Magento MySQL database.
  2. Open the table [database_prefix]core_config_data.(e.g. mage_core_config_data)
  3. Now find row with entry:  'web/url/redirect_to_base'.
  4. Change the value from 1 to 0.
  5. Now your original admin URL should work fine.
 Try [your_website's_previous_base_url]/[admin]

Note:  Where [your_website's_previous_base_url] should be replaced by URL, which you were using as Base URL.
and [admin] should be replaced by appropriate admin trailer(which you use to get access to your admin panel)
You can now change the settings back to before the collapse.

Sunday, July 8, 2012

How to get current currency code in Magento

To get current currency code in magento, use it:

<?php echo Mage::app()->getStore()->getCurrentCurrencyCode(); ?>

That's it.. Enjoy :)

How to get currency symbol in Magento

To get currency symbol for current store:

<?php echo Mage::app()->getLocale()->currency(Mage::app()->getStore()->getCurrentCurrencyCode())->getSymbol(); ?>


or if you want to pass a certain currency code to get currency symbol, then use it:

<?php echo Mage::app()->getLocale()->currency('[CURRENCY_CODE]')->getSymbol(); ?>


Where CURRENCY_CODE should be replaced by currency code of your store:For Example:


<?php echo Mage::app()->getLocale()->currency('AUD')->getSymbol(); ?>


That's it.. Enjoy :)

Wednesday, July 4, 2012

How to call .phtml file in CMS page in magento

To call a phtml file in a cms page or cms static block:

{{block type="core/template" template="templateFolder/your_template.phtml"}}

If you know, where the block file(php file) for your phtml file resides, then you can use it as type.

Example: Suppose you want to call new.phtml file that resides in catalog/product folder, and you know that its corresponding Block file(php file) resides in Catalog/Product folder, then you can use:

{{block type="catalog/product" template="catalog/product/new.phtml"}}

Magento: How to change Admin URL Path

In general, magento admin url path looks like this:

[store_url]/admin

For security reason, you may want to change admin path. To do this:

Open app/etc/local.xml and find code like this:

<admin>
    <routers>
            <adminhtml>
                <args>
                    <frontName><![CDATA[admin]]></frontName>
                </args>
            </adminhtml>
        </routers>
</admin>
You have to change below line:
<frontName><![CDATA[admin]]></frontName>
to:
 
<frontName><![CDATA[backstore]]></frontName> 
Note: Where backstore can be replaced by the word of your choice.

Now save the file.

Clear your magento cache from System-->Cache Management
Now you are ready to use your new admin url path.

Enjoy :)