May 21

magento — remove h1 heading from cms page

how to remove the title that appears above the cms content of cms page? from the cms.xml layout file i found the code below:

just remove this line

<block type="core/template" name="page_content_heading" template="cms/content_heading.phtml"/>
Source code    
<cms_page translate="label">
        <label>CMS Pages (All)</label>
        <reference name="content">
            <block type="core/template" name="page_content_heading" template="cms/content_heading.phtml"/>
            <block type="page/html_wrapper" name="cms.wrapper" translate="label">
                <label>CMS Content Wrapper</label>
                <action method="setElementClass"><value>std</value></action>
                <block type="cms/page" name="cms_page"/>
            </block>
        </reference>
    </cms_page>

then the h1 title of all the cms page will go.but what if you want to do this only to some specific page?you have two choice,first,you can make use of magento layout update feature for cms page.

Goto menu CMS => Pages => Click the page you want to edit => Design => Layout Update XML

add the xml code below:

Source code    
<reference name="content">
            <remove name="page_content_heading"/>
</reference>

the other way is update the cms.xml file directly in your theme layout folder.

Apr 21

magento — remove “Home page” from magento cms home page

The quickest way to remove “Home page” is edit the cms home page from magento backend,and remove it from the content. you need to put a whitespace in html(&nbsp;) or you can not save it.but this way still keep the cms container html tag like:

Source code    
<div class="std"> </div>

you can remove all uneeded html tag by edit the cms.xml layout code:

Source code    
<reference name="content">
		    <remove name="cms.wrapper"/>
            </reference>

 

Feb 15

magento — translate words into other language for payment module

my new mangento payment module need multiple language support.Magento interface is translated with CSV localization files which was stored at the location of app/locale/[lang_folder],ie app/locale/en_us.OR you can use the built-in Inline translation tool which store the translation pair into database.it’s much more convenience to translate via Csv localization files than the inline translation tool when you want to translate lots of string at a time.

First, i create an empty csv file named Mzcart_Pagbrasil.csv in app/locale/en_us/.I add a translation for test purpose:

“Powered by Pagbrasil”,”Powered by Pagbrasil—-”

Second,to make the new added csv localization file visible to magento, i need to update the config xml file of this module.add the config below to config.xml file under  config >> frontend path.

<translate>
<modules>
<Mzcart_Pagbrasil>
<files>
<default>Mzcart_Pagbrasil.csv</default>
</files>
</Mzcart_Pagbrasil>
</modules>
</translate>

However,  the string “Powered by Pagbrasil” was not translated. I did clear the cache. After googling for a long time without any clue, i added a new string and it was translated,but the first string still not changed.

“Powered by Pagbrasil”,”Powered by Pagbrasil—-”        >>>>>>> still not translated.
“Please pay your order now”,”Please pay your order now@@@@@@@@@@@@”

what’s the problem?the problem is that php does not support utf8 with bom. a BOM-ed UTF-8 string will start with the three following bytes EF BB BF. php will treat this bytes as file content.this lead to the mismatch of the first string. you may find that all lang file provided by magento all encoded in utf8 without bom.

For more info you may refer to http://stackoverflow.com/questions/2223882/whats-different-between-utf-8-and-utf-8-without-bom

Feb 13

magento — how to get Vat number/tax id

i am developing a new payment module under magento.Everything going through well as usual.However, this new payment module require a cutomer tax id. by default,magento didn’t show this field for customer.To make it available for all customer,log into magento backend, goto

System > Configuration > Customers > Customer Configuration > Create New Account Options [tab]

change the config of “Show VAT Number on Frontend” to “yes”.

so how to get the new added filed — customer vat number/taxt id.you need to get billing or shipping model first.the code below as an example.

$billing  = $this->getOrder()->getBillingAddress();
$billing->getVatId();

 

 

Oct 17

linux — forward user email

To forward user’s email,just put an .forward file with the email addr in the user’s home diretory.If this not work for your server,Make sure the .forward file is belong to the user you want to forward email.for example,if you want to forward all email for user testuser, change current working directory to /home/testuser,touch a .forward file.

# cd /home/testuser
# touch .forward
# echo ‘abctest@abc.com’ >> .forward
# chown testuser.testuser .forward
# chmod 664 .forward

if this not work,you may check the log file located at /var/log/maillog for more info.

And keep in mind,only in a Postfix/Sendmail system it is sendmail command that utilies this file.For other situation,you may check the related document.

 

Apr 25

Linux — how to know if php run as cgi or module

For some reason you want to know how is php working with web server like apache. if you are the people who config the server,you got the answer in your head. what if you are not? well,php have a function for this:

php_sapi_name

Per php manual,call this function will returns the type of interface between web server and PHP

Source code    
<?php
php_sapi_name();
?>

The section below is take from the php manual:
Although not exhaustive, the possible return values include aolserver, apache, apache2filter, apache2handler, caudium, cgi (until PHP 5.3), cgi-fcgi, cli, continuity, embed, isapi, litespeed, milter, nsapi, phttpd, pi3web, roxen, thttpd, tux, and webjames.

When php run in CGI mode( or any other mode other that module mode), you can not set php config via php_value directive in the .htaccess file.

you can also take a look at the phpinfo page to decide how php is working with your webserver.

Mar 25

zen cart — How to Add a Sidebox to Zen Cart

One of the best way to customize Zen Cart is to create a new Sidebox.A Zen Cart sidebox is what displays various contents in the left or right columns of your Zen Cart store. By default numerous sideboxes will show in either the left or right column of a Zen Cart online store. The followings are some of the most popular zen cart sidebox — The categories sidebox, the search sidebox, and the information sidebox. Zen cart comes with some builtin sidebox which could be a good tutor to start to learn how to add a new sidebox to Zen Cart.

A sidebox consists of three files which are located in the includes directory:

  1. modules/sideboxes/YOUR_TEMPLATE/new_sidebox.php
  2. languages/english/extra_definitions/YOUR_TEMPLATE/new_sidebox_defines.php
  3. templates/YOUR_TEMPLATE/sideboxes/tpl_new_sidebox.php

The ‘new’ up there should be replaced with your own sidebox name.

includes/modules/sideboxes/YOUR_TEMPLATE/new_sidebox.php

Source code    
<?php
 $show_new_sidebox = true;
 if ($show_new_sidebox == true){
   require($template->get_template_dir('tpl_new_sidebox.php',DIR_WS_TEMPLATE,
   $current_page_base,'sideboxes'). '/tpl_new_sidebox.php');
   $title =  BOX_HEADING_NEW_SIDEBOX;
   //do some db query and other processing here
 
   $left_corner = false;
   $right_corner = false;
   $right_arrow = false;
   require($template->get_template_dir($column_box_default, DIR_WS_TEMPLATE,
   $current_page_base,'common') . '/' . $column_box_default);
 }
?>

includes/languages/english/extra_definitions/YOUR_TEMPLATE/new_sidebox_defines.php

Source code    
<?php
  define('BOX_HEADING_NEW_SIDEBOX', 'Gallery');
?>

includes/templates/YOUR_TEMPLATE/sideboxes/tpl_new_sidebox.php

Source code    
<?php
 $content = <<< End_Of_Quote
  Enter your sidebox content here
 End_Of_Quote;
?>
Dec 06

linux — How to extract specified file/directory from a tar ball

well,you got a big tar ball file,but in fact you only need some special file or directory.Then you don’t want to extract  all files from the tar ball if it’s a big file.so how to get specified file or directory from a tar ball?

tar command allows to extract a single file or directory using the following format. It works under UNIX, Linux, and BSD operating systems.

tar xvf big.tar filename
tar -zxvf abc.tar.gz directory-name
tar -zxvf abc.tar.gz path/to/directory-name -C /tmp

Keep in mind that both the filename and directory-name should be existed in the tar ball file,and the path is relative to the tar ball root.

Aug 23

linux — how to exclude directory or files when bakup with rsync

rsync has been heavily used in server daily backup.I am not going to list all option of rsync. i just don’t want to backup some useless file such as cache and log file.

In a typical backup situation, you might want to exclude one or more files (or directories) from the backup. You might also want to exclude a specific file type from rsync.

To exclude a special directory,take a look at the command below:

Source code    
rsync -avze 'ssh -p7788' --exclude 'dir_abc'  /home/www  root@ip:/home/bak/

This command will not sync the /home/www/dir_abc

You can use * to match multiple directory to exclude like this:

Source code    
rsync -avze 'ssh -p7788' --exclude 'dir_*'  /home/www  root@ip:/home/bak/

You can also use multiple –exclude option to exclude:

Source code    
rsync -avze 'ssh -p7788' --exclude 'dir_abc' --exclude 'webcache' --exclude '*.log' /home/www  root@ip:/home/bak/

Keep in mind that rsync will always treat the value of the –exclude option as relative to the bakup dir even though you specified a absolute path,so

if there is a dir1 directory in /home/www

Source code    
rsync -avze --exclude '/home/www/dir1' /home/www /home/bak

rsync will explain /home/www/dir1 as /home/www/home/www/dir1,but this is not what you want.when you specified the path for –exclude option,make sure it’s relative to the source data diretory.this action will not be affected by add / to the exclude path.