Magento: $_product->getData() VS. $_product->getAttributeName()

here are two main ways of displaying product attributes on the product list, and the product view. Let’s say for this example that our attribute code is ‘customAttribute’. The two ways you’d expect to see this attribute displayed are:

<?php  echo  $_product->  getData('customAttribute') ?>
<?php  echo  $_product->  getAwesomeDude() ?>

Both of these produce the same result. However, they have somewhat significant differences:

getData()
In most cases, this is the method you should use. Of the two options, this one is actually faster and more efficient. If you have no need to modify the output, and just want to display the value, use getData(). However, there are attributes that may not work properly with getData() such as the product price. Though I haven’t tested it yet, getData(‘price’) will most likely end up producing different results than getPrice().

getAttributeName()
You should really only use this method if you are needing to override the method in your block to add functionality to how the data is displayed/formatted. Magento needs to take some additional steps in rendering the data when you use this method, so it is a slightly slower process than displaying data using getData(). So, by using $_product->getAwesomeDude(), I am able to add a function to the product view block for example to modify the data before it is output to the screen:

public function getAttributeName()
{
  // code to do something with the data
  return $yournewdata;
}

From prattski.com

Kyle.

Categories: Magento | Leave a comment

How To Enable Friendly URLs in Magento

In order to use Magento’s feature for more user and search-engine friendly URLs, you have to login to the Magento’s administration area (usually * http://YourDomainName.com/admin/* ), click on the *Configuration* button, under the *System* navigation menu, switch to the *Web* page from the sub-navigation panel on the left side of the page.

When the page loads, you will see blue lines, which represents closed settings tablets. Click on the *Search Engines Optimization* tab, and turn on the *Use Web Server Rewrites* (mark as *Yes)*. Click on the *Save Config*button and you are done.

Now you have enabled user-friendly URLs in Magento.

Kyle.

Categories: Magento | Leave a comment

Call to undefined method Mage_Catalog_Helper_Data::canApplyMsrp() in template/checkout/cart/item/default.phtml

Symptoms

Shopping cart page is not loaded or loaded blank or partially blank, the following error message is shown in PHP error log:
PHP Fatal error: Call to undefined method Mage_Catalog_Helper_Data::canApplyMsrp() in template/checkout/cart/item/default.phtml
Cause

Mage_Catalog_Helper_Data::canApplyMsrp() method is implemented since Magento 1.6 version, attempts to use this method in earlier Magento versions, like Magento 1.5.1.0 or Magento 1.5.0.1 will result in fatal error.

Solution

The proper fix is to prepend any calls to canApplyMsrp() method with if method_exists call.
before:
$canApplyMsrp = Mage::helper(‘catalog’)->canApplyMsrp($_item->getProduct(), Mage_Catalog_Model_Product_Attribute_Source_Msrp_Type::TYPE_BEFORE_ORDER_CONFIRM);
after:
if (method_exists(Mage::helper(‘catalog’)->canApplyMsrp))
$canApplyMsrp = Mage::helper(‘catalog’)->canApplyMsrp($_item->getProduct(), Mage_Catalog_Model_Product_Attribute_Source_Msrp_Type::TYPE_BEFORE_ORDER_CONFIRM);

The exact file name to be patched is shown in PHP error log.
Another fix can be upgrade to Magento 1.6 or later version.

Kyle.

Categories: Magento | Leave a comment

Hello world!

Welcome to WordPress.com! This is your very first post. Click the Edit link to modify or delete it, or start a new post. If you like, use this post to tell readers why you started this blog and what you plan to do with it.

Happy blogging!

Categories: Prestashop | 1 Comment

Blog at WordPress.com.