Magento – Get product attribute’s select option id/label/value

magento-checklist_mini
If you have a select dropdown for any product attribute, to get the value from label or vice versa is always needed in order to display or get value for further processing, etc. Every now and then you will require this values while working on product attributes. There are many ways you can achieve it but the best, in terms of performance and simplicity is what I will tell you here. Get product attribute’s value from label, label from value easily in Magento.
Suppose, you have an product attribute called “color” in Magento. You have the label (e.g. Red), and you want to find it’s value. The below code will help you get the value for it.

Continue reading

Magento EE – Punch Hole in Full Page Cache

hole

Magento is slow, it’s a truth . because of its slowness, Magento have some cache mechanisms to make your site faster, so your customers will be happy. Many people choose to use all of caching options available. according to their opinions, the best cache solution for Magento is Full Page Cache (FPC), and it’s one feature from Magento Enterprise.

implementing FPC means you will have all your page content cached. it’s good for speed, but what will happen when you have several block that need to be updated after each request, or may be you want a shorter cache life for it ? The following tutorial will show you how to punch some holes in your FPC pages so you can solve above problems.

Continue reading

Magento – creating custom breadcrumbs for CMS pages

breadcrumb

I wanted to create a subordinate set of CMS pages in Magento so that the breadcrumb navigation at the top of the page looks like this:

Home > Parent CMS Page > Child CMS Page

Even though I can specify a hierarchical relationship with the URL key field, it seems to be that all CMS pages in Magento are listed in the root directory by default:

Home > Child CMS Page

To override the default, you have 2 options :

Continue reading

Magento – Fix integrity constraint violation issue

Database-banner

Sometimes, you face database issues like this ‘integrity constraint violation: 1062 Duplicate entry ‘100000001’ for key’ . if you are not familiar with Magento, may be you will feel blind (like i was), debugging won’t go smoothly as usual.

After studying Magento deeper to its core, i found that Magento numbering system depends on a table called ‘eav_entity_store’. this table stores increment ids of many entities from Magento.

Continue reading

Magento – price helper code snippet

This piece of codes will help you get final price with tax and formatted nicely using your store currency


<?php
$_coreHelper = $this->helper(’core’);
$_taxHelper = $this->helper(’tax’);
$_finalPriceInclTax = $_taxHelper->getPrice($_product, $_product->getFinalPrice(), true);
$_finalPriceInclTaxNicelyFormated = $_coreHelper->currency($_finalPriceInclTax,true,false);
echo $_finalPriceInclTaxNicelyFormated;

?>

Hope you find it useful ! 😀

Magento – fix the 404 error on the admin dashboard

When I changed the URI to access to my dashboard, when I logged in again, there was a 404 error on the admin dashboard. It seems is something related to permissions and can be easily solved executing the following commands:

find . -type d -exec chmod 755 {} ;
find . -type f -exec chmod 644 {} ;
chmod o+w var media -R

If this doesn’t work, maybe the login form is not redirecting correctly. In that case we need to change the action url in the app/design/adminhtml/default/default/template/login.phtml file. Look for the «form» start tag:

<form method="post" action="" id="loginForm">

Change it to:

<form method="post" action="<?php echo $this->getUrl('adminhtml') ?>" id="loginForm">

that’s it, you have you familiar dashboard back 😀

Design patterns which are used in Magento

A design pattern in architecture and computer science is a formal way of documenting a solution to a design problem in a particular field of expertise.

from wikipedia.

Factory:

$product = Mage::getModel(‘catalog/product’);

Singleton:

$category = Mage::getSingleton(‘catalog/session’);
Continue reading

Redirect Magento with global messages

Open the controller that contains your logic, put these lines at terminate point of your code:


Mage::getSingleton('core/session')->addError('your message goes here');

$this->_redirect('redirect location');

return;

Above example will redirect and dispay an Error message, you can also display other type of message with the following methods from singleton Core/session

  • addWarning
  • addNotice
  • addSuccess