Apr 11

simple load on the fly

showViewedPropImg: function() {
if(J.s(“.listing”).length == 0) {
return false
}
var a = J.s(“.listing”).eq(0).get().scrollTop;
var b = parseInt(J.s(“.listing”).eq(0).get().style.height);
J.g(“test_div”).down(“.list_li”).each(function(f, g) {
var e = g.down(“.dt_img img”).eq(0);
var d = e.attr(“src”);
if(typeof d === “undefined” || d == null || d.length == 0) {
var c = g.offset();
if((c.y – a) >= 0 && (c.y – a) <= (162 + b)) {
e.attr(“src”, e.attr(“data”)).removeAttr(“data”)
}
}
})
},

J.s(“.listing”).eq(0).on(“scroll”, function(d) {
if(J.g(this).down(“.list2″).length > 0) {
return false
}
if(c == 0) {
if(a) {
clearTimeout(a)
}
a = setTimeout(function() {
b.showViewedPropImg();
c = 0
}, 200);
c = 1
}
});

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 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 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.

 

May 31

javascript – A simple javascript countdown timer

This is a simple but light weight javascript countdown timer,which can be integrated to your zen cart store by uploading the file to the jscript sub folder of your current zen cart template folder.

I name it as jscript_timer.php, so i can  put some php configure variable to the zen cart admin backend. if you dont’ want,you can rename it to jscript_timer.js.  This countdown timer countdown 4 days and it will start over again.so no bother to admin setting once and once again.(:

Source code    
<?php
$path = '/' . DIR_WS_TEMPLATE . 'jscript/';
$img = $path . 'timer.png';
?>
<script language="javascript" type="text/javascript"><!--
var present;
var future;
var tseconds;
var seconds;
var minutes;
var hours;
var days;
var limit;
limit =4;
// ID=setInterval("countdown();", 1000);
 
function countdown() {
	present = new Date();
	present = present.getTime();
	future = new Date("MAY 27, 2015 11:59:59");
 
	tseconds = (future - present)  / 1000;
 
	days = tseconds /24/60/60;
	days = Math.floor(days);
	odays = days;
	days = days%limit;
	tseconds = tseconds - (odays - days) * 24 * 60 * 60 - (days * 24 * 60 * 60);
 
	hours = tseconds /60/60;
	hours = Math.floor(hours);
	tseconds = tseconds - (hours * 60 * 60);
 
	minutes = tseconds /60;
	minutes = Math.floor(minutes);
	tseconds = tseconds - (minutes * 60);
 
	seconds = tseconds;
	seconds = Math.floor(seconds);
	htmlstr = '<span style="font-weight:bold;font-size:16px">' + days + '</span> days <span style="font-weight:bold;font-size:12px">' +  hours + ':' + minutes + ':' + seconds + '</span>  Left';
	document.getElementById('timerdiv').innerHTML = htmlstr;
	//console.info(days + ' days ' + hours + ' hours ' + minutes + ' minutes ' + seconds + ' seconds');
}
window.onload = function () {
    ID=setInterval("countdown();", 1000);
};
//--></script>

Feel free to adapt it to fit your need!!