Magento: get skin url, get media url, get base url, get store url

Magento Mage Core, Admin Static Blocks, or Phtml edits are usually includes getting url path such images, javascript, base url, media and store url. There are different ways to retrieve mentioned URL paths depending on where section you’re editing.

To Retrieve URL path in STATIC BLOCK

To get SKIN URL

{{skin url='images/sampleimage.jpg'}}

To get Media URL

{{media url='/sampleimage.jpg'}}

To get Store URL

{{store url='mypage.html'}}

To get Base URL

{{base url='yourstore/mypage.html'}}

TO Retrieve URL path in PHTML

Note: In editing PHTML don’t forget to enclode the following code with PHP tag
Not secure Skin URL:

<?php echo $this->getSkinUrl('images/sampleimage.jpg') ?>

Secure Skin URL

<?php echo $this->getSkinUrl('images/ sampleimage.gif', array('_secure'=>true)) ?>

Get  Current URL

$current_url = Mage::helper('core/url')->getCurrentUrl();

Get Home URL

$home_url = Mage::helper('core/url')->getHomeUrl();

Get Magento Media Url

Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK);


Get Magento Media Url

Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA);

Get Magento Skin Url

Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN);

Get Magento Store Url

Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);

Get Magento Js Url

Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_JS);
Source:
http://www.webdosh.net/2011/04/magento-get-skin-url-get-media-url-get.html

Add Custom JavaScript and Stylesheet in wordpress

We can directly put it in the header section as we normal does but sometime it maynot work in case of admin.
We can include following code in function.php

function mytheme_custom_scripts() {

	if ( ! is_admin() ) {
		$scriptsrc = get_stylesheet_directory_uri() . '/js/';
		wp_register_script( 'myhandle', $scriptsrc . 'myscript.js', 'jquery', false );
		wp_enqueue_script( 'myhandle' );
	}

}
add_action( 'wp_enqueue_scripts', 'mytheme_custom_scripts' );

and for case of css add the following code

 wp_enqueue_style('thickbox', get_bloginfo('siteurl') . 'wp-includes/js/thickbox/thickbox.css', false, false, 'screen');
        wp_enqueue_script('mthickbox');
Source:http://wordpress.org/support/topic/how-can-i-add-custom-javascript-and-stylesheet-in-headerphp-file-1

Magento Internal server error (500) in live server

While moving the localhost magento site to live hosting , everytime i get Internal server error (500) error .
To Overcome this error we need to follow certain steps.
->set permission 755 for magento folder and index.php
->Sometimes this can be related to the .htaccess rewritebase rule , while working on localhost host its may consist the folder in the path but while it is live we install it in the root directory so .htacces should be pointed to base …

RewriteBase / 

Magento Category Navigation or Vertical category menu in sidebar

Here are the steps to retrive the category in the sidenbar
Step1. PHP Code to retrieve top level categories for navigation and save it at the following location.
in short this file contain code related to catalog Navigation Model which retrieves top level categories and show it in proper manner
Magento\app\design\frontend\base\default\template\catalog\navigation\categorymenu.phtml

&lt;?php

/**
 * Left Category menu for store
 * We are showing  jsut the top level categorioes
 * @see Mage_Catalog_Block_Navigation
 */
?&gt;
&lt;div class=&quot;block block-category&quot;&gt;
	&lt;div class=&quot;inside-box&quot;&gt;
		&lt;div class=&quot;block-title block-category-title&quot;&gt;
			&lt;h3&gt;&lt;?php echo $this-&gt;__('Our Categories') ?&gt;&lt;/h3&gt;
		&lt;/div&gt;
		&lt;div class=&quot;block-category-navigation&quot;&gt;
			&lt;ul id=&quot;category-nav&quot;&gt;
			&lt;?php foreach ($this-&gt;getStoreCategories() as $_category): ?&gt;
			&lt;?php if($_category-&gt;name!=&quot;&quot;):  ?&gt;
				&lt;li&gt;&lt;?php echo $this-&gt;drawItem($_category) ?&gt;&lt;/li&gt;
				&lt;?php endif?&gt;
				&lt;?php endforeach ?&gt;
			&lt;/ul&gt;
		&lt;/div&gt;
	&lt;/div&gt;
&lt;/div&gt;

Step2. Change the page.xml to include category navigation menu.

So let’s start with the home page, as in most of the cases. Magento home page is simple CMS page, therefore, we have to locate the page related layout XML file . that exists in our layout folder of selected theme. We are taking example as the default theme. So have to open the following file:

&lt;block type=&quot;catalog/navigation&quot; name=&quot;catalog.categorymenu&quot; after=&quot;top.search&quot; template=&quot;catalog/navigation/categorymenu.phtml&quot;/&gt;
Source : http://www.time2php.com/magento/magento-category-navigation-or-vertical-category-menu-in-sidebar

Deleting Order and Customer Data with SQL

During the development and testing process we create different customer and different order in Magento , after the site goes live we need to delete that . So  here are the simple ways to do it with the query below

SET FOREIGN_KEY_CHECKS=0;

##############################
# SALES RELATED TABLES
##############################
TRUNCATE `#_sales_flat_creditmemo`;
TRUNCATE `#_sales_flat_creditmemo_comment`;
TRUNCATE `#_sales_flat_creditmemo_grid`;
TRUNCATE `#_sales_flat_creditmemo_item`;
TRUNCATE `#_sales_flat_invoice`;
TRUNCATE `#_sales_flat_invoice_comment`;
TRUNCATE `#_sales_flat_invoice_grid`;
TRUNCATE `#_sales_flat_invoice_item`;
TRUNCATE `#_sales_flat_order`;
TRUNCATE `#_sales_flat_order_address`;
TRUNCATE `#_sales_flat_order_grid`;
TRUNCATE `#_sales_flat_order_item`;
TRUNCATE `#_sales_flat_order_payment`;
TRUNCATE `#_sales_flat_order_status_history`;
TRUNCATE `#_sales_flat_quote`;
TRUNCATE `#_sales_flat_quote_address`;
TRUNCATE `#_sales_flat_quote_address_item`;
TRUNCATE `#_sales_flat_quote_item`;
TRUNCATE `#_sales_flat_quote_item_option`;
TRUNCATE `#_sales_flat_quote_payment`;
TRUNCATE `#_sales_flat_quote_shipping_rate`;
TRUNCATE `#_sales_flat_shipment`;
TRUNCATE `#_sales_flat_shipment_comment`;
TRUNCATE `#_sales_flat_shipment_grid`;
TRUNCATE `#_sales_flat_shipment_item`;
TRUNCATE `#_sales_flat_shipment_track`;
TRUNCATE `#_sales_invoiced_aggregated`;            # ??
TRUNCATE `#_sales_invoiced_aggregated_order`;        # ??
TRUNCATE `#_log_quote`;

ALTER TABLE `#_sales_flat_creditmemo_comment` AUTO_INCREMENT=1;
ALTER TABLE `#_sales_flat_creditmemo_grid` AUTO_INCREMENT=1;
ALTER TABLE `#_sales_flat_creditmemo_item` AUTO_INCREMENT=1;
ALTER TABLE `#_sales_flat_invoice` AUTO_INCREMENT=1;
ALTER TABLE `#_sales_flat_invoice_comment` AUTO_INCREMENT=1;
ALTER TABLE `#_sales_flat_invoice_grid` AUTO_INCREMENT=1;
ALTER TABLE `#_sales_flat_invoice_item` AUTO_INCREMENT=1;
ALTER TABLE `#_sales_flat_order` AUTO_INCREMENT=1;
ALTER TABLE `#_sales_flat_order_address` AUTO_INCREMENT=1;
ALTER TABLE `#_sales_flat_order_grid` AUTO_INCREMENT=1;
ALTER TABLE `#_sales_flat_order_item` AUTO_INCREMENT=1;
ALTER TABLE `#_sales_flat_order_payment` AUTO_INCREMENT=1;
ALTER TABLE `#_sales_flat_order_status_history` AUTO_INCREMENT=1;
ALTER TABLE `#_sales_flat_quote` AUTO_INCREMENT=1;
ALTER TABLE `#_sales_flat_quote_address` AUTO_INCREMENT=1;
ALTER TABLE `#_sales_flat_quote_address_item` AUTO_INCREMENT=1;
ALTER TABLE `#_sales_flat_quote_item` AUTO_INCREMENT=1;
ALTER TABLE `#_sales_flat_quote_item_option` AUTO_INCREMENT=1;
ALTER TABLE `#_sales_flat_quote_payment` AUTO_INCREMENT=1;
ALTER TABLE `#_sales_flat_quote_shipping_rate` AUTO_INCREMENT=1;
ALTER TABLE `#_sales_flat_shipment` AUTO_INCREMENT=1;
ALTER TABLE `#_sales_flat_shipment_comment` AUTO_INCREMENT=1;
ALTER TABLE `#_sales_flat_shipment_grid` AUTO_INCREMENT=1;
ALTER TABLE `#_sales_flat_shipment_item` AUTO_INCREMENT=1;
ALTER TABLE `#_sales_flat_shipment_track` AUTO_INCREMENT=1;
ALTER TABLE `#_sales_invoiced_aggregated` AUTO_INCREMENT=1;
ALTER TABLE `#_sales_invoiced_aggregated_order` AUTO_INCREMENT=1;
ALTER TABLE `#_log_quote` AUTO_INCREMENT=1;

#########################################
# DOWNLOADABLE PURCHASED
#########################################
TRUNCATE `#_downloadable_link_purchased`;
TRUNCATE `#_downloadable_link_purchased_item`;

ALTER TABLE `#_downloadable_link_purchased` AUTO_INCREMENT=1;
ALTER TABLE `#_downloadable_link_purchased_item` AUTO_INCREMENT=1;

#########################################
# RESET ID COUNTERS
#########################################
TRUNCATE `#_eav_entity_store`;
ALTER TABLE  `#_eav_entity_store` AUTO_INCREMENT=1;

##############################
# CUSTOMER RELATED TABLES
##############################
TRUNCATE `#_customer_address_entity`;
TRUNCATE `#_customer_address_entity_datetime`;
TRUNCATE `#_customer_address_entity_decimal`;
TRUNCATE `#_customer_address_entity_int`;
TRUNCATE `#_customer_address_entity_text`;
TRUNCATE `#_customer_address_entity_varchar`;
TRUNCATE `#_customer_entity`;
TRUNCATE `#_customer_entity_datetime`;
TRUNCATE `#_customer_entity_decimal`;
TRUNCATE `#_customer_entity_int`;
TRUNCATE `#_customer_entity_text`;
TRUNCATE `#_customer_entity_varchar`;
TRUNCATE `#_tag`;
TRUNCATE `#_tag_relation`;
TRUNCATE `#_tag_summary`;
TRUNCATE `#_tag_properties`;            ## CHECK ME
TRUNCATE `#_wishlist`;
TRUNCATE `#_log_customer`;

ALTER TABLE `#_customer_address_entity` AUTO_INCREMENT=1;
ALTER TABLE `#_customer_address_entity_datetime` AUTO_INCREMENT=1;
ALTER TABLE `#_customer_address_entity_decimal` AUTO_INCREMENT=1;
ALTER TABLE `#_customer_address_entity_int` AUTO_INCREMENT=1;
ALTER TABLE `#_customer_address_entity_text` AUTO_INCREMENT=1;
ALTER TABLE `#_customer_address_entity_varchar` AUTO_INCREMENT=1;
ALTER TABLE `#_customer_entity` AUTO_INCREMENT=1;
ALTER TABLE `#_customer_entity_datetime` AUTO_INCREMENT=1;
ALTER TABLE `#_customer_entity_decimal` AUTO_INCREMENT=1;
ALTER TABLE `#_customer_entity_int` AUTO_INCREMENT=1;
ALTER TABLE `#_customer_entity_text` AUTO_INCREMENT=1;
ALTER TABLE `#_customer_entity_varchar` AUTO_INCREMENT=1;
ALTER TABLE `#_tag` AUTO_INCREMENT=1;
ALTER TABLE `#_tag_relation` AUTO_INCREMENT=1;
ALTER TABLE `#_tag_summary` AUTO_INCREMENT=1;
ALTER TABLE `#_tag_properties` AUTO_INCREMENT=1;
ALTER TABLE `#_wishlist` AUTO_INCREMENT=1;
ALTER TABLE `#_log_customer` AUTO_INCREMENT=1;

##############################
# ADDITIONAL LOGS
##############################
TRUNCATE `#_log_url`;
TRUNCATE `#_log_url_info`;
TRUNCATE `#_log_visitor`;
TRUNCATE `#_log_visitor_info`;
TRUNCATE `#_report_event`;
TRUNCATE `#_report_viewed_product_index`;
TRUNCATE `#_sendfriend_log`;
### ??? TRUNCATE `#_log_summary`

ALTER TABLE `#_log_url` AUTO_INCREMENT=1;
ALTER TABLE `#_log_url_info` AUTO_INCREMENT=1;
ALTER TABLE `#_log_visitor` AUTO_INCREMENT=1;
ALTER TABLE `#_log_visitor_info` AUTO_INCREMENT=1;
ALTER TABLE `#_report_event` AUTO_INCREMENT=1;
ALTER TABLE `#_report_viewed_product_index` AUTO_INCREMENT=1;
ALTER TABLE `#_sendfriend_log` AUTO_INCREMENT=1;
### ??? ALTER TABLE `#_log_summary` AUTO_INCREMENT=1;

SET FOREIGN_KEY_CHECKS=1;

Customer detail can be deleted from the magento admin > Manage Customer.

http://www.magentocommerce.com/wiki/import-export_and_data_manipulation/deleting_order_and_customer_data_with_sql

Related products on product page in Magento

Move related products from default sidebar location into main product page in Magento.

1. Open catalog.xml, found in
app/design/frontend/default/YOURTEMPLATEFOLDER/layout/

2. In catalog.xml find the catalog_product_view section, around line 205. In the section, remove or comment out:

&lt;block type=&quot;catalog/product_list_related&quot; name=&quot;catalog.product.related&quot; before=&quot;-&quot; template=&quot;catalog/product/list/related.phtml&quot;/&gt;

and replace with:

&lt;reference name=&quot;content&quot;&gt;
&lt;block type=&quot;catalog/product_view&quot; name=&quot;product.info&quot; template=&quot;catalog/product/view.phtml&quot;&gt;
&lt;block type=&quot;catalog/product_list_related&quot; name=&quot;catalog.product.related&quot; as=&quot;related&quot; template=&quot;catalog/product/list/related.phtml&quot;/&gt;
&lt;/block&gt;
&lt;/reference&gt;

3. Now in your catalog/product/view.phtml you can print out the related products using

&lt;?php echo $this-&gt;getChildHtml('related'); ?&gt;

To edit the look of that list, edit catalog/product/list/related.phtml

Source : http://www.voodish.co.uk/articles/related-products-on-product-page-in-magento/

Adding static block into the header area of Magento Site

Steps to add static block into the header area of Magento Site

Steps for adding block in Admin Panel

1. Go to “CMS &gt; Static Blocks”

2. Click the “Add New” button.

3. Enter the Block Title like “Header Menu”

4. Enter identifier like enter “header-menu”. (all letters will be small)

5. Select the store view.

6. Set status to “Enabled”.

7. Add you block content.

8. Click on “Save Block” button.

Steps for changing in page.xml file

1. Open file “/app/design/frontend/default/yourtheme/layout/page.xml” file.

2. Find header block

top-bar

&lt;label&gt;Page Header&lt;/label&gt;
top-container

3. Now add the following block in just before the closing block &lt;/block&gt; tag
&lt;block type=”cms/block” name=”header-menu”&gt;&lt;action method=”setBlockId”&gt;&lt;block_id&gt;header-menu&lt;/block_id&gt;&lt;/action&gt;&lt;/block&gt;

Steps for changing in header.phtml file

1. Open file “/app/design/frontend/default/yourtheme/page/html/template/header.phtml” file.
2. Just add the following code where you want to add the block
&lt;?php echo $this-&gt;getChildHtml(‘header-menu’) ?&gt;

Source : http://bmehla.wordpress.com/2011/05/04/magento-steps-to-add-static-block-into-the-header-area-of-magento-site/

How to remove the ‘Shop By’ box from the left column in Magento

To activate and deactivate widgets in Magento like the Newsletter option, it’s pretty easy. You just go to System/Configuration/Advanced and select ‘disable’ next to the ‘Mage_Newsletter’ item.

But what if you want to disable something that has no apparent widget control? I couldn’t find a widget that controlled the ‘Shop By’ option in the left column. If there is a widget that controls this, please let me know!

The first way to remove an item – edit the code from the referenced PHTML file

What I did was to first identify the name of the DIV that contained it .To do this, visit a page containing the item on your testing or live server, select ‘view source’, copy the source code in its entirety and paste it into a new, blank HTML Dreamweaver file. Working in Split View, you can click on DIVs in the Design Pane and see what they are called in the Code Pane.

I established that the code in question was within the “block block-layered-nav” DIV. In Dreameaver Files, select the app/design/frontend/base directory and perform a search for “block block-layered-nav” in the source code of all selected files. Click ‘Find All’.

The search showed that two files contained this css string – the view.phtml and left.phtml files. Upon inspection, the view.phtml file contained the ‘Shop By’ title, so this was the one to edit. You could either comment out all the PHP and HTML, or (as I did) empty the file after making a copy of it for later reinstatement if required.

Upload the file to app/design/frontend/default/yourtheme/template/catalog/layer and the item should disappear from the left column.

If you are wondering why we retrieved the view.phtml from the Base theme rather than your theme, it’s because sometimes not all the phtml files exist in a theme, and when this happens Magento defaults to the Base theme to find one. By uploading it to the same location in your theme, it overrides the default Base version.

Of course, if you have a view.phtml already in your theme, edit that one.

The second way to remove an item – edit the code from the referencing XML file

Now you know where the code resides, you can perform a new search of the app/design’frontend/base directory for the filename, ‘view.phtml’. This showed quite a few files referencing view.phtml, but only two which were referenced view.phtml in the layer directory: catalog.xml and catalogsearch.xml.

Just focusing on the catalog.xml file (which affects more pages), locate the reference of layer/view.phtml in the code. It appeared just once on line 115. Comment out the code that references the file, replacing this:

with this:

Save the catalog.xml file to the corresponding directory in your theme (if it doesn’t already exist): app/design/frontend/default/yourtheme/layout

Now the Shop By option should have left the site.

Source : http://tinstardesign.wordpress.com/2010/12/01/how-to-remove-the-%E2%80%98shop-by%E2%80%99-box-from-the-left-column-in-magento/

How to get the login & logout url in magento?

Following is the code to get the login & logout link.

//check the user is loggedon or not
if (! Mage::getSingleton('customer/session')-&gt;isLoggedIn()){
//if user logged on show the logout link - add this code within anchor tag
echo Mage::helper('customer')-&gt;getLoginUrl();
}
else{
//if user is not logged on yet show the login link - add this code within anchor tag
echo Mage::helper('customer')-&gt;getLogoutUrl();
}

Here are more variable’s that may you need to get the customer data on the frontend.

bool customerHasAddresses ()
string getAccountUrl ()
Mage_Customer_Model_Customer getCurrentCustomer ()
Mage_Customer_Model_Customer getCustomer ()
string getCustomerName ()
string getDashboardUrl ()
string getEditPostUrl ()
string getEditUrl ()
string getEmailConfirmationUrl ([string $email = null])
string getForgotPasswordUrl ()
Mage_Customer_Model_Entity_Group_Collection getGroups ()
string getLoginPostUrl ()
string getLoginUrl ()
string getLogoutUrl ()
string getRegisterPostUrl ()
string getRegisterUrl ()
bool isConfirmationRequired ()
bool isLoggedIn ()
bool isRegistrationAllowed ()
Source : www.adeelishfaq.com/blog/how-to-get-the-login-logout-url-in-magento/

Remove magento footer links.

If you want to remove the “Help Us to Keep Magento Healthy – Report All Bug” from footer, navigate to

app/design/frontend/default/default/template/page/html/footer.phtml 

of your theme assuming that you are using default magento theme . Otherwise navigate to your related theme file and remove the following line

&lt;p class=&quot;bugs&quot;&gt;&lt;?php echo $this-&gt;__('Help Us to Keep Magento Healthy') ?&gt; - &lt;a href=&quot;http://www.magentocommerce.com/bug-tracking&quot; onclick=&quot;this.target='_blank'&quot;&gt;&lt;strong&gt;&lt;?php echo $this-&gt;__('Report All Bugs') ?&gt;&lt;/strong&gt;&lt;/a&gt; &lt;?php echo $this-&gt;__('(ver. %s)', Mage::getVersion()) ?&gt;&lt;/p&gt;

If you want to remove the menus seens in the footer like “Site Map, Search Terms, Advanced Search, Orders and Returns, Contact Us” Then remove the following code from page.xml

&lt;block type=&quot;page/template_links&quot; name=&quot;footer_links&quot; as=&quot;footer_links&quot; template=&quot;page/template/links.phtml&quot;/&gt;