Change Magento configurable product to take associated products tax class

Where and how to change the code?

At first, I thought overriding Mage_Catalog_Model_Product_Type_Configurable::getOrderOptions().
Original code

$options['product_calculations'] = self::CALCULATE_PARENT;

change to

$options['product_calculations'] = self::CALCULATE_CHILD;

However, it does not work.

Then I tried to observe the event tax_rate_data_fetch and modify the rateRequest object. But inside rateRequest there is no reference to quoteItem. Only product tax_class_id is there. In the observer class, I do not know when to modify it without reference to quoteItem.

At last, I had to modify the code in class Mage_Tax_Model_Sales_Total_Quote_Tax. There are several places to change depends on System Configuration. Change where is appropriate.
Original code


change to

if ($item->getProductType() == Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE) {
	$child = current($item->getChildren());
else {

It is not a neat approach. Let me know if you have a better idea.

I report very first bug to Magento

Magento 里还是有不少 bugs,我能看出来的就不少。可是我一直懒于 report bug,总觉得我都能发现的 bug,大把有人发现。

今天心血来潮,大概受“莫以善小而不为”驱使,平生第一次 report bug to Magento。事关 js/mage/adminhtml/product.js 文件里第406 行(Magento, 有个笔误,把 readonly 写成了redonly。Associated Products tab of Configurable Products 受此影响,本应只读模式的文本框仍可输入数据。



Reinstate thumbnails in jQuery UI theme switcher

You might have noticed, some tools from jQuery are not fully functional recently. That could be caused by jQuery disabling hotlinks. jQuery UI theme switcher is affected. I call it a bug because jQuery team did not make necessary arrangement before enforcement of hotlink policy.

Nevertheless, how to reinstate thumbnails in jQuery UI theme switcher while waiting for jQuery team to release a hotlink compatible theme switcher? Easy, with my code – Themeswitcher Launcher.

 $('body').prepend('<div id="msdk-themeswitcher"></div>');
 var srcStart = "";
 function() {
 this.src = this.src.replace(srcStart,

Themeswitcher Launcher just does a simple job: replacing images source in theme switcher to another source, which still allow hotlinking. You can replace with your domain if you host these images.

To save your time, I packaged jQuery UI theme switcher with my Themeswitcher Launcher. Please note I changed jQuery UI theme switcher slightly because I need it for Magento sites. I put function themeswitcher() into jQuery namespace to be standard jQuery plugin, so it can be working with javascript prototype framework.

Download msdk-themeswitcher-launcher.js.tar.gz

For those who are interested in my Magento modules: jQuery UI theme switcher and my Themeswitcher Launcher are integrated into my Msdk (Magento SDK) module – it is just an advertisement.

Machine convert xls to csv

Linux is an excellent OS. Today something again proved my choice.

I was looking for a solution to convert Excel xls to csv format. This conversion is required by a Magento dataflow project.

Magento native dataflow comes with an XML Excel parser. For some reasons, it does not convert my xls files. I think it may be due to limited functionality of Magento XML Excel parser class, or encoding problem.

I need something which can reliably convert xls files from 3rd parties, which we have no control over how they produce xls files.

I was thinking of another php independent class called ExcelReader. However, ExcelReader goes beyond what I need. All I need is convert xls to csv, make ready for dataflow.

After a day’s research, finally xls2csv caught my attention. I would have found it earlier if I had searched by “linux command line convert xls to csv” earlier. It runs perfectly well on Fedora and CentOS as I tested.

Installation is straight forward. Run

yum install catdoc

FYI, yum install xls2csv, installs something totally different. I have not figured out what it is.

When I had 31% off on Godaddy

很多网站的促销都是做得不到位的。就是 Godaddy 难免也会有这错那错。比如我刚用它的一个 31% off no minimum voucher code 续了三个域名,付完钱以后她还在喋喋不休说再给个 20% off minimum $45。

When I had 31% off
When I had 31% off

当然 Godaddy 整体促销还是不错的,我写这些只是提醒自己不要犯类似的错误。

I go back to ISP’s nameservers to resolve my domains

很久以前什么都不懂的时候,觉得能自己做 DNS server,为自己的域名解析,是件很了不起的事情。再加那是 ISP 的 Domain Manager 对批量域名的更新支持不足,而自己的 DNS server 能 GUI 和 command line 并举,满足我对批量操作的要求。

今非昔比。我倾向于放弃自行解析,重回 ISP nameservers 的环抱。这主要是基于以下考虑:

  • 自己的服务器是普通的服务器,ISP nameservers 是专业的,似乎它们的解析速度更快。
  • 自己的服务器一机多用,一迁移所有服务都要移,把 DNS 剥离出去可以少掉一项工作。
  • Godaddy Domain Manager GUI 有很大改进,现在批处理能满足我的要求。而我大部分域名在 Godaddy 注册,其他 ISP 不见改进,但我要求也不高,不能批量就一个个来吧。
  • Godaddy 控制面板的响应速度有很大提高,可能是它在荷兰建数据中心的功效。
  • 从节约开支的角度,我不得不降低一些服务器的配置,把 DNS 剥离出去可以减轻服务器负担。

作为一个前期测试,今天先把一个域名交给 Godaddy nameservers 解析,试用一周,如满意就全盘放弃自己的 DNS。

Upgrade a server from Fedora 10 to 14

今天终于把一台服务器从 Fedora 10 升到了 Fedora 14,一开始想用 yum 升级(在 fedora upgrader 的帮助下),尝试跳级升级的,不成功。然后用 Fedora 自身的 major upgrade,分别尝试了跳级升级和不跳级升级,都不成功,最后卡在 Fedora 11 拷贝完升级文件但进不了图形界面完成升级,彻底动弹不得。很懊恼,早知如此还不如一开始就全新安装,就是想绕开重建 server 的麻烦,但这看来是绕不开的。

稍后我列出此次升级的 checklist(以前陆续也写过,但有两年没干这活了,变化还是很大)。

此次升级损失了 DNS slave zones 的文件。本以为主 Server 有备份,但主 Server 几次搬家,什么时候把那些文件搬丢了也没印象了。

升级的起因是我需要 php ssh2,却发现 Zend Server 暂不支持。不想经历自行往 Zend Server 添加 php ssh2 的麻烦,就想回到 Fedora 管理下的 php。不久前说过,我觉得 Zend Server 是鸡肋,这下更坚定我的看法。