Enable Template Path Hints in Magento Admin

SQL:
  1. UPDATE core_config_data SET value = 0 WHERE scope = ‘default’ AND scope_id = 0 AND path =’dev/debug/template_hints’

If you love template path hints in Magento for quickly figuring out which template file or block you need to edit or override and have a requirement for some admin side coding, you are going to love this.

You might not have thought it was possible to enable template path hints in admin, but it is!

Just run this query:

SQL:

  1. INSERT INTO core_config_data (scope, scope_id, path, value)
  2. VALUES (‘default’, 0, ‘dev/debug/template_hints’, 1),
  3. (‘default’, 0, ‘dev/debug/template_hints_blocks’, 1);
To disable them again, run this query
SQL:

  1. UPDATE core_config_data SET value = 0 WHERE scope = ‘default’ AND scope_id = 0 AND path =’dev/debug/template_hints’
To enable again run this query
SQL:

  1. UPDATE core_config_data SET value = 1 WHERE scope = ‘default’ AND scope_id = 0 AND path =’dev/debug/template_hints’

Do not forget clear cache!!!

Posted in Uncategorized | Leave a comment

Magento admin URL change

It is very easy to change admin URL for magento
If you want to change URL from

http://www.example.com/index.php/admin or http://www.example.com/admin
TO
http://www.example.com/index.php/siteadmin or http://www.example.com/siteadmin
Here’s what I did (worked for me on 1.3.1):

1) Open <magento_install_dir>/app/etc/local.xml
2) Find this code:

<config>
.
.
.
<admin>
<routers>
<adminhtml>
<args>
<frontName><![CDATA[admin]]></frontName>
</args>
</adminhtml>
</routers>
</admin>
.
.
.
</config>

3) In that snippit of code, change
<frontName><![CDATA[admin]]></frontName>
to
<frontName><![CDATA[siteadmin]]></frontName>
4) Save the local.xml file

5) Remove everything under <magento_install_dir>/var/cache/
6) Remove everything under <magento_install_dir>/var/session/

Update:
7) Don’t forget to change permissions for the local.xml to read only. I would recommend chmod 444.

Leave a comment

Magent custom attribute value

<?php echo $this->htmlEscape($_product->getData('attribute_code')); ?>
Leave a comment

Magento: Displaying Custom Attributes on Product ViewHow to Obtain Custom Attribute Values in Magento

How to Obtain Custom Attribute Values in Magento

Today let’s talk about Magento and custom attributes. With Magento you can create as many custom attributes for your products as you like, and there are different attribute types such as:

  • Text Field
  • Text Area
  • Date
  • Yes/No
  • Multiple Select
  • Dropdown
  • Price
  • Gallery
  • Media Image
  • Fixed Product Tax

Because there are different types of attributes there are also different ways of obtaining an attributes value. If we were to create a new custom attribute called “theme_color” and the attribute was of a “Text Field” type, we could do something like the following at a product level (meaning a product is loaded) to obtain its value.

<?php
echo $_product->getThemeColor();
?>

$_product is the product of question we have loaded up and ready to work with, and we use “getThemeColor();” because our attribute was named “theme_color”. It’s important to realize that when calling out the value of an attribute with this method, we start with “get” and then capitalize the first letter of each word that is divided by a “_”.

Now this method would give us the value of a simple “Text Field” attribute but what if the attribute was a “Dropdown or a Multiple Select” type? Well if you try to use this “getYourAttributesName()” method on a none “Text Field” or “Textarea” attribute type you will most likely get nothing.

So how do we obtain the value of a “Dropdown or a Multiple Select” attribute type you ask? Well some would argue that you would do so via this method:

<?php
echo $_product->getAttributeText('theme_color');
?>

However, what this would do is return an array of the “Dropdown or Multiple Select” options instead of the value of the selected option you would have set. There is another way to obtain these types of attributes selected value and it looks like this:

<?php
$attributes = $_product->getAttributes();
$themeColor = $attributes['theme_color']->getFrontend()->getValue($_product);
echo $themeColor;
?>

With this method we are simply creating a new variable called “$attributes” and pointing to our “$_product” to then using the “getAttributes()” function to gather all the attributes of this product.

Once we have all the product’s attributes inside of the “$attributes” variable, we make another new variable called “$themeColor”. “$themeColor” then assigns its self to our “$attributes” array that we in turn call out our custom attribute [‘theme_color’].

Once we have pointed to the custom attribute in the “$attributes” array, we simply run through the front end via the function “getFrontend()” and then pull the value down via “getValue($_product)”.

If we then echo our “$themeColor” you should get the value of your custom Drop Down or Multiple Select attribute to do what you will with it.

So to recap:

<?php echo $_product->getThemeColor() ?>

Would get the value of an attribute wholes type is of Text Field or Text Area’s

<?php echo $_product->getAttributeText('theme_color')  ?>

That will not give a value of a Text Field or Text Area attribute type but rather gather an array of all options in a Drop Down or Multiple Select attribute type.

<?php
$attributes = $_product->getAttributes();
$themeColor = $attributes['theme_color']->getFrontend()->getValue($_product);
?>

That will give you the value of any type of attribute, even the value from “Drop Down or Multiple Select” attribute types.

Posted in Uncategorized | Leave a comment

Migrating Magento to another server

Migrating the Magento platform to another server is relatively a simple task. I have detailed the steps below:

  1. From the admin, go to Configuration -> Web -> and change the (Unsecure and Secure) fields to {{base_url}}.
  2. From the admin, go to System -> Tools -> Backups and click on the backup button. This will create a backup of your database.
  3. Make a copy your Magento root.
  4. Move all data over to the new server.
  5. Restore the database on the new host.
  6. If you have a different username, password or database name. You’ll need to update that as well. You can find the file in (‘magento_root/app/etc/local.xml’) and make the required changes.
  7. Navigate to your Magento root, and delete all of the files and folders in, (i.e. /var/www/magento/var) except for the .htaccess file.

Hope this helps someone :)

Posted in Uncategorized | Leave a comment

htaccess 301 Redirect

Redirect 301 /redirectpage2.html http://www.yoursite.com/folder/
Leave a comment

How to display a static block directly on the template file.

<?getLayout()->createBlock('cms/block')->setBlockId('block_name')->toHtml() ?>
Leave a comment

Show SKU Code

<?php htmlEscape($_product->getSku()) ?>
Leave a comment

How to show cart total

<?php getQuote();
$total = $quote->getGrandTotal();
// format total in order to have a user friendly price
$total = $this->helper('checkout')->formatPrice($total); ?>
Leave a comment

RESET MAGENTO FILE PERMISSIONS VIA SSH

find . -type f -exec chmod 644 {} \;
find . -type d -exec chmod 755 {} \;
chmod o+w var var/.htaccess includes includes/config.php app/etc
chmod 550 pear
chmod -R o+w med
Leave a comment