Pages

Thursday, July 4, 2013

getBaseUrl – Magento URL Path

When developing in Magento and playing arround with Magento Themes there is some functions you should know.

If you want to get the source url of an image, javascript or file, call one of this functions adding your own path at the end.

Under every function there is an example of the output value:

http://example.com/
<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB); ?>

http://example.com/js/
<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_JS); ?>

http://example.com/index.php/
<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK); ?>

http://example.com/media/
<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA); ?>

http://example.com/skin/
<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN); ?>

How to Remove Add to Compare Magento

Do you want to remove the add to compare list in your Magento site?

There is only bad news to do that.

First of all there is no an easy-admin-button to turn it off. Yeah Magento rocks…

And of course you will have to to into some code. But don’t worry is quite simple.
0. Turn cache Off

Turn off the Magento Cache just to be sure the changes work. You can turn it on again once you’re done.

Reminder: System-> Cache Management
1. reports.xml

Open the app/design/frontend/deafult/YourTheme/layout/reports.xml

Look for and comment or delete this line:
<block type="reports/product_compared" before="right.permanent.callout" name="right.reports.product.compared" template="reports/product_compared.phtml" />

And also this one:
<block type="reports/product_viewed" before="right.permanent.callout" name="right.reports.product.viewed" template="reports/product_viewed.phtml" />
2. catalog.xml

Open the app/design/frontend/deafult/YourTheme/layout/catalog.xml

Comment or delete this line:
<block type="core/template" before="cart_sidebar" name="catalog.compare.sidebar" template="catalog/product/compare/sidebar.phtml"/>
3. addto.phtml

Open the file app/design/frontend/default/YourTheme/template/catalog/product/view/addto.phtml

Comment or delete this line:
<?php if($_compareUrl=$this->helper('catalog/product_compare')->getAddUrl($_product) ): ?>
<li><span class="pipe">|</span> <a href="<?php echo $_compareUrl ?>"><?php echo $this->__('Add to Compare') ?></a></li>
<?php endif; ?>
Done!

The add to compare list should not be there anymore.

I’ve tested this tutorial in a Magento 1.4 version.

Create a Subdomain to Parallelize Downloads

One of that problems is Parallelize Downloads. When you have JS, CSS, IMAGE and all those kind of files serving from 1 single domain it slows down the speed.

Did you heard about Content Delivery Networks?

A CDN serves the static content of your site from multiple servers arround the world depending on where your reader is.

As you can imagine this services are expensive and if you’re like me you can’t pay for that.

There is a solution to cheat on Google’s Page Speed.

1. Create a Sub Domain

Create a subdomain like I did cdn.quicoto.com.
1. Upload static content

Upload the static content there (some CSS, JS and IMAGES).
Am I speeding up my site?

[UPDATE] Well in fact you’re. Check out the comment for the full explanation ;)

Magento Easy Lightbox Extension

Like every CMS / e-commerce software there is some plugins / extensions you have to install at the first place.
Every time I start a Magento Site I install the Magento Easy Lightbox Extension.
Nothing much to say. It adds the lightbox function to your product images.
Automatically replace the ugly image resizer for this cool lightbox.
How much is it?
It’s free ;)
Where can I get it?
Get the extension key and install it from the Magento Connect.
http://www.magentocommerce.com/extension/1487/magento-easy-lightbox

Magento Country codes for table rate

I was getting mad trying to figure out how to know the Magentro Country Codes.

When you want to upload a Shipping Table Rate (csv file) you need to enter those codes in your file.

Looks like they don’t give the info in a easy way. Luckily, I’ve found a dirty solution that just works.

I went to the admin section and I got the code from one of those “Specific Countries” select input.

Here’s the list, enjoy ;)

AF - Afghanistan
AL - Albania
DZ - Algeria
AS - American Samoa
AD - Andorra
AO - Angola
AI - Anguilla
AQ - Antarctica
AG - Antigua and Barbuda
AR - Argentina
AM - Armenia
AW - Aruba
AU - Australia
AT - Austria
AZ - Azerbaijan
BS - Bahamas
BH - Bahrain
BD - Bangladesh
BB - Barbados
BY - Belarus
BE - Belgium
BZ - Belize
BJ - Benin
BM - Bermuda
BT - Bhutan
BO - Bolivia
BA - Bosnia and Herzegovina
BW - Botswana
BV - Bouvet Island
BR - Brazil
IO - British Indian Ocean Territory
VG - British Virgin Islands
BN - Brunei
BG - Bulgaria
BF - Burkina Faso
BI - Burundi
KH - Cambodia
CM - Cameroon
CA - Canada
CV - Cape Verde
KY - Cayman Islands
CF - Central African Republic
TD - Chad
CL - Chile
CN - China
CX - Christmas Island
CC - Cocos [Keeling] Islands
CO - Colombia
KM - Comoros
CG - Congo - Brazzaville
CD - Congo - Kinshasa
CK - Cook Islands
CR - Costa Rica
HR - Croatia
CU - Cuba
CY - Cyprus
CZ - Czech Republic
CI - Côte d’Ivoire
DK - Denmark
DJ - Djibouti
DM - Dominica
DO - Dominican Republic
EC - Ecuador
EG - Egypt
SV - El Salvador
GQ - Equatorial Guinea
ER - Eritrea
EE - Estonia
ET - Ethiopia
FK - Falkland Islands
FO - Faroe Islands
FJ - Fiji
FI - Finland
FR - France
GF - French Guiana
PF - French Polynesia
TF - French Southern Territories
GA - Gabon
GM - Gambia
GE - Georgia
DE - Germany
GH - Ghana
GI - Gibraltar
GR - Greece
GL - Greenland
GD - Grenada
GP - Guadeloupe
GU - Guam
GT - Guatemala
GG - Guernsey
GN - Guinea
GW - Guinea-Bissau
GY - Guyana
HT - Haiti
HM - Heard Island and McDonald Islands
HN - Honduras
HK - Hong Kong SAR China
HU - Hungary
IS - Iceland
IN - India
ID - Indonesia
IR - Iran
IQ - Iraq
IE - Ireland
IM - Isle of Man
IL - Israel
IT - Italy
JM - Jamaica
JP - Japan
JE - Jersey
JO - Jordan
KZ - Kazakhstan
KE - Kenya
KI - Kiribati
KW - Kuwait
KG - Kyrgyzstan
LA - Laos
LV - Latvia
LB - Lebanon
LS - Lesotho
LR - Liberia
LY - Libya
LI - Liechtenstein
LT - Lithuania
LU - Luxembourg
MO - Macau SAR China
MK - Macedonia
MG - Madagascar
MW - Malawi
MY - Malaysia
MV - Maldives
ML - Mali
MT - Malta
MH - Marshall Islands
MQ - Martinique
MR - Mauritania
MU - Mauritius
YT - Mayotte
MX - Mexico
FM - Micronesia
MD - Moldova
MC - Monaco
MN - Mongolia
ME - Montenegro
MS - Montserrat
MA - Morocco
MZ - Mozambique
MM - Myanmar [Burma]
NA - Namibia
NR - Nauru
NP - Nepal
NL - Netherlands
AN - Netherlands Antilles
NC - New Caledonia
NZ - New Zealand
NI - Nicaragua
NE - Niger
NG - Nigeria
NU - Niue
NF - Norfolk Island
KP - North Korea
MP - Northern Mariana Islands
NO - Norway
OM - Oman
PK - Pakistan
PW - Palau
PS - Palestinian Territories
PA - Panama
PG - Papua New Guinea
PY - Paraguay
PE - Peru
PH - Philippines
PN - Pitcairn Islands
PL - Poland
PT - Portugal
PR - Puerto Rico
QA - Qatar
RO - Romania
RU - Russia
RW - Rwanda
RE - Réunion
BL - Saint Barthélemy
SH - Saint Helena
KN - Saint Kitts and Nevis
LC - Saint Lucia
MF - Saint Martin
PM - Saint Pierre and Miquelon
VC - Saint Vincent and the Grenadines
WS - Samoa
SM - San Marino
SA - Saudi Arabia
SN - Senegal
RS - Serbia
SC - Seychelles
SL - Sierra Leone
SG - Singapore
SK - Slovakia
SI - Slovenia
SB - Solomon Islands
SO - Somalia
ZA - South Africa
GS - South Georgia and the South Sandwich Islands
KR - South Korea
ES - Spain
LK - Sri Lanka
SD - Sudan
SR - Suriname
SJ - Svalbard and Jan Mayen
SZ - Swaziland
SE - Sweden
CH - Switzerland
SY - Syria
ST - São Tomé and Príncipe
TW - Taiwan
TJ - Tajikistan
TZ - Tanzania
TH - Thailand
TL - Timor-Leste
TG - Togo
TK - Tokelau
TO - Tonga
TT - Trinidad and Tobago
TN - Tunisia
TR - Turkey
TM - Turkmenistan
TC - Turks and Caicos Islands
TV - Tuvalu
UM - U.S. Minor Outlying Islands
VI - U.S. Virgin Islands
UG - Uganda
UA - Ukraine
AE - United Arab Emirates
GB - United Kingdom
US - United States
UY - Uruguay
UZ - Uzbekistan
VU - Vanuatu
VA - Vatican City
VE - Venezuela
VN - Vietnam
WF - Wallis and Futuna
EH - Western Sahara
YE - Yemen
ZM - Zambia
ZW - Zimbabwe
AX - Åland Islands
2 and 3 letter relation

Maybe the 2 letters code is not working for you.

Here you have the 3 letter code:
AA - AAA
AD - AND
AE - ARE
AF - AFG
AG - ATG
AI - AIA
AL - ALB
AM - ARM
AN - ANT
AO - AGO
AQ - ATA
AR - ARG
AS - ASM
AT - AUT
AU - AUS
AW - ABW
AX - ALA
AZ - AZE
BA - BIH
BB - BRB
BD - BGD
BE - BEL
BF - BFA
BG - BGR
BH - BHR
BI - BDI
BJ - BEN
BL - BLM
BM - BMU
BN - BRN
BO - BOL
BR - BRA
BS - BHS
BT - BTN
BU - BUR
BV - BVT
BW - BWA
BY - BLR
BZ - BLZ
CA - CAN
CC - CCK
CD - COD
CF - CAF
CG - COG
CH - CHE
CI - CIV
CK - COK
CL - CHL
CM - CMR
CN - CHN
CO - COL
CR - CRI
CS - SCG
CU - CUB
CV - CPV
CX - CXR
CY - CYP
CZ - CZE
DD - DDR
DE - DEU
DJ - DJI
DK - DNK
DM - DMA
DO - DOM
DZ - DZA
EC - ECU
EE - EST
EG - EGY
EH - ESH
ER - ERI
ES - ESP
ET - ETH
FI - FIN
FJ - FJI
FK - FLK
FM - FSM
FO - FRO
FR - FRA
FX - FXX
GA - GAB
GB - GBR
GD - GRD
GE - GEO
GF - GUF
GG - GGY
GH - GHA
GI - GIB
GL - GRL
GM - GMB
GN - GIN
GP - GLP
GQ - GNQ
GR - GRC
GS - SGS
GT - GTM
GU - GUM
GW - GNB
GY - GUY
HK - HKG
HM - HMD
HN - HND
HR - HRV
HT - HTI
HU - HUN
ID - IDN
IE - IRL
IL - ISR
IM - IMN
IN - IND
IO - IOT
IQ - IRQ
IR - IRN
IS - ISL
IT - ITA
JE - JEY
JM - JAM
JO - JOR
JP - JPN
KE - KEN
KG - KGZ
KH - KHM
KI - KIR
KM - COM
KN - KNA
KP - PRK
KR - KOR
KW - KWT
KY - CYM
KZ - KAZ
LA - LAO
LB - LBN
LC - LCA
LI - LIE
LK - LKA
LR - LBR
LS - LSO
LT - LTU
LU - LUX
LV - LVA
LY - LBY
MA - MAR
MC - MCO
MD - MDA
ME - MNE
MG - MDG
MF - MAF
MH - MHL
MK - MKD
ML - MLI
MM - MMR
MN - MNG
MO - MAC
MP - MNP
MQ - MTQ
MR - MRT
MS - MSR
MT - MLT
MU - MUS
MV - MDV
MW - MWI
MX - MEX
MY - MYS
MZ - MOZ
NA - NAM
NC - NCL
NE - NER
NF - NFK
NG - NGA
NI - NIC
NL - NLD
NO - NOR
NP - NPL
NR - NRU
NT - NTZ
NU - NIU
NZ - NZL
OM - OMN
PA - PAN
PE - PER
PF - PYF
PG - PNG
PH - PHL
PK - PAK
PL - POL
PM - SPM
PN - PCN
PR - PRI
PS - PSE
PT - PRT
PW - PLW
PY - PRY
QA - QAT
QM - QMM
QN - QNN
QO - QOO
QP - QPP
QQ - QQQ
QR - QRR
QS - QSS
QT - QTT
QU - QUU
QV - QVV
QW - QWW
QX - QXX
QY - QYY
QZ - QZZ
RE - REU
RO - ROU
RS - SRB
RU - RUS
RW - RWA
SA - SAU
SB - SLB
SC - SYC
SD - SDN
SE - SWE
SG - SGP
SH - SHN
SI - SVN
SJ - SJM
SK - SVK
SL - SLE
SM - SMR
SN - SEN
SO - SOM
SR - SUR
ST - STP
SU - SUN
SV - SLV
SY - SYR
SZ - SWZ
TC - TCA
TD - TCD
TF - ATF
TG - TGO
TH - THA
TJ - TJK
TK - TKL
TL - TLS
TM - TKM
TN - TUN
TO - TON
TP - TMP
TR - TUR
TT - TTO
TV - TUV
TW - TWN
TZ - TZA
UA - UKR
UG - UGA
UM - UMI
US - USA
UY - URY
UZ - UZB
VA - VAT
VC - VCT
VE - VEN
VG - VGB
VI - VIR
VN - VNM
VU - VUT
WF - WLF
WS - WSM
XA - XAA
XB - XBB
XC - XCC
XD - XDD
XE - XEE
XF - XFF
XG - XGG
XH - XHH
XI - XII
XJ - XJJ
XK - XKK
XL - XLL
XM - XMM
XN - XNN
XO - XOO
XP - XPP
XQ - XQQ
XR - XRR
XS - XSS
XT - XTT
XU - XUU
XV - XVV
XW - XWW
XX - XXX
XY - XYY
XZ - XZZ
YD - YMD
YE - YEM
YT - MYT
YU - YUG
ZA - ZAF
ZM - ZMB
ZR - ZAR
ZW - ZWE
ZZ - ZZZ

How to add Social Links Magento

One nice thing you should add to your Magento site is the Social Links.

Let your customers promote your products on twitter, facebook and more.
ShareThis

You can grab his code and paste it to your site http://xyz.com/
Your own code

This one is my favorite option. You can code the social links by your own.

Let’s digg into this second option:

First of all Set template path hints to yes and you’ll see wich file you’ll have to edit. It just depens in your theme and where you want to place the code.

System -> Configuration -> Advanced -> Developer

I wanted to place my social links in the product detail page. I found my view.phtml.

It’s very easy. We just need to know wich format the social network needs (facebook, twitter…).

I’m using 2 functions from magento:

Store URL
<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB); ?>

Product Name (if needed)
<?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?>
Examples

3 examples using Facebook, Twitter and Delicious.
 
  <a href="http://www.facebook.com/share.php?u=<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB); ?>< ?=substr($_SERVER['REQUEST_URI'], 1)?>"><img src="<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN); ?/>frontend/base/theme156/images/facebook.jpg" alt="" /></a>
  
 <a href="http://twitter.com/home?status=<?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?>+<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB); ?>< ?=substr($_SERVER['REQUEST_URI'], 1)?>"><img src="<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN); ?/>frontend/base/theme156/images/twitter.jpg" alt="" /></a>
   
<a href="http://xyz.com/post?url=<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB); ?>< ?=substr($_SERVER['REQUEST_URI'], 1)?>&title=<?php echo str_replace(" ", "+", $_helper->productAttribute($_product, $_product->getName(), 'name'));?>"><img src="<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN); ?/>frontend/base/theme156/images/delicious.jpg" alt="" /></a>

How to change Default Sort Order Magento



I’ll be clear… Magento is not good as you could imagine. In fact sucks in so many ways.

Today i’m showing you one. There is no backend option to change the Default Sort Order in your product listing (catalog).

Lucky there is an easy solution.
The Toolbar

Look for the file toolbar.php located in:

/app/code/core/Mage/Catalog/Block/Product/List
Create the Local folder

Create the same folder structure in the local. Now the future upgrades will not affect your changes.

Should be like:

/app/code/local/Mage/Catalog/Block/Product/List
Edit the Toolbar

Now you have to change 1 single stupid line.

Look for:
  /**
     * Default direction
     *
     * @var string
     */
    protected $_direction           = 'asc';

And change it for:
  /**
     * Default direction
     *
     * @var string
     */
    protected $_direction           = 'desc';

How to Backup Product Images Magento

Having an up to date backup can save you from many troubles. Using Magento I would suggest you to backup the entire site. You can use your hosting panel and create a compressed .zip of all your public folders.

Perhaps this option will force you to download a couple of GB’s of files and folders. The Media folder Surf your site using a FTP client and go to /media/catalog Backup that folder wich contains all the product images. Database Backup You can use the build-in feature to create a database backup from the Magento admin panel.

Go to System -> Tools -> Backups Now you have to Create a Backup and then download it.

How to fix – Unable to submit your request. Please, try again later – Contact Form

It just shows an error Unable to submit your request. Please, try again later Solution Add the following line to the form.phtml The location of the file will depend on wich theme are you using (base, blank…). /app/design/frontend/base/default/template/contacts/form.phtml Add this between the form tags:

How to add Store codes in URL Magento

Today we’ll see how to add the store code in the Magento URL from the admin panel

Go to System -> Configuration -> General -> Web

Then URL Options -> Add Store Code to Urls -> Yes