May 21

magento — remove h1 heading from cms page

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

just remove this line

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 only do this 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.

May 09

Chrome won’t allow IFRAME to load a html file via http while main page using https

i just found a weird thing that the Chrome browser don’t allow an iframe to load a http url when the current url in the addr bar begin with https.for eample,if the current page’s url is:

https://www.abcdomain.com/abc-xyz.html

and it contains an iframe whose src is

http://www.anotherdomain.com/test-xyz.html

then,it worked ok in Firefox browser but  the iframe break in Chrome.
after google for a while,i get some conclusion when calling a page from other domain with diff protocol,:

page – iframe – status
http – http  – allowed
http – https – allowed
https- http  – not allowed
https- https – not allowed

for more related info,please refer to the following url

http://stackoverflow.com/questions/9280665/insecure-content-in-iframe-on-secure-page

http://stackoverflow.com/questions/18223028/google-chrome-wont-allow-iframe-to-load-a-html-file

 

Apr 28

WooCommerce — how to add customer VAT field for billing and admin view order page

Some payment gateway need a customer VAT field to be sent to make the payment.While i was developing pagbrasil gateway for WooCommerce, i found WooCommerce do not support to add extra field for checkout and order.

Of course, for the sake of updating WooCommerce,i can not change the WooCommerce  code directly. WooCommerce was running as a plugin upon WordPress. i just need another wordpress plugin to insert a VAT field.By the way,the payment gateway for WooCommerce was also build as a pluging for wordpress,just one thing differcence,it denpends on the WooCommerce plugin.

To learning how to develop a wordpress plugin,you need to refer to wordpress docs,there are lots tutor online.i am going to the code part of this work  — add hook and filter for checkout page and order view page :

Source code    
//add VAT field to checkout page
function VAT_override_checkout_fields( $fields ) {
	$fields['billing']['VAT_code'] = array(
	'label'     => __('VAT', 'woocommerce'),
	'placeholder'   => _x('VAT', 'placeholder', 'woocommerce'),
	'required'  => true,
	'class'     => array('form-row-wide'),
	'clear'     => true
	);
 
	return $fields;
}
add_filter( 'woocommerce_checkout_fields' , 'VAT_override_checkout_fields');
 
function VAT_custom_checkout_field_order_meta_keys( $order ) {
	echo "<span><strong>VAT:</strong>" .
	$order->VAT_code . "</span>";
}
add_action( 'woocommerce_admin_order_data_after_billing_address', 'VAT_custom_checkout_field_order_meta_keys' );

 

 

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>

 

Apr 18

WooCommerce — How to clear cart content after payment

Sometimes you want to clear cart content.For example, if the customer was redirected back to your WooCommerce store after payment,you need to clear WooCommerce shopping cart to avoid dumplicated order.so how?

global $woocommerce; $woocommerce->cart->empty_cart(); 

Keep in mind the $woocommerce is a global variable. you need to explicitly declare before you can call it in function or methods.

To clear cart only for some special page, you can detect page with function is_page()  which you can pass any page title, ID or slug.

 

 

 

Apr 08

PHP — PHP Protocol https not supported or disabled in libcurl

While i was developing WooCommerce payment module for Pagbrasil gateway,i got a curl error msg as:

PHP Protocol https not supported or disabled in libcurl

To check if https protocol was supported by the server,i created a script called a.php and put <?php phpinfo(); ?> in it.From the curl section of the phpinfo page, i found  that https protocol were not listed. so the cURL was not built with SSL support.The only way is to recompile the php.

 

 

 

Feb 25

php — how to detect spider/crawler with php

I am going to write a PHP script today that detects whether a search engine spider is crawling a page.With PHP, we can check the value of $_SERVER['HTTP_USER_AGENT'],a predefined variables which store the contents of the User-Agent: header from the current request, if there is one.

$pattern = ‘/(google|msnbot|MSNPTC|yahoo|Slurp|overture.com|del.icio.us|DoCoMo|DoCoMo)/i’;
if ( preg_match($pattern, $_SERVER['HTTP_USER_AGENT'] === FALSE) { // not a spider

} else { // spider

}

You can find a list of search engine spiders/crawlers from  http://www.user-agents.org/.

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();

 

 

Feb 12

apache — password protect your web resource only to external user

Think about  that an IT company would like to protect their example project from Internet user,but allow their customer to access with password.however,the developer would not like to input password.

if you wanted to let people on your network have unrestricted access to a portion of your website, but require that people outside of your network provide a password, you could use a configuration similar to the following:

Require valid-user
Allow from 192.168.1
Satisfy Any

you can put the config directive into a .htaccess file or enclose the config diretive with apache Directory directive.With the Satisfy Any directive the client will be granted access if they either pass the host restriction or enter a valid username and password.But please keep in mind that the config may not work if your server allow all user access by default.we should tweak the config to be more restricted.

Order Allow,Deny
AuthType Basic
AuthName “Restricted Resource”
AuthUserFile /var/users
Require valid-user

Allow from 192.168.1
Satisfy Any

[OR]

Order Deny,Allow
Deny from All
AuthType Basic
AuthName “Restricted Resource”
AuthUserFile /var/users
Require valid-user

Allow from 192.168.1
Satisfy Any