Blog

  • Be careful: Magento layer filter label is not html escaped

    我发现 Magento 1.4.1.1 app/design/frontend/base/default/template/catalog/layer/filter.phtml 是这么写的:

    <ol>
    <?php foreach ($this->getItems() as $_item): ?>
    <li>
    <?php if ($_item->getCount() > 0): ?>
    <a href="<?php echo $this->urlEscape($_item->getUrl()) ?>"><?php echo $_item->getLabel() ?></a>
    <?php else: echo $_item->getLabel() ?>
    <?php endif; ?>
    (<?php echo $_item->getCount() ?>)
    </li>
    <?php endforeach ?>
    </ol>
    

    我觉得不太好,因为 staff 在设置 filter label 通常会忽视 html escape,所以最好是

    $this->htmlEscape($_item->getLabel());
    

    但这样一来把 price filter 正常的 html 输出给搞乱了。要兼顾普通 filter 和 price filter,我还没有一个比较 neat 的方案,只好要求 staff 做好 filter label 的 html escape。

    同样的问题在 app/design/frontend/base/default/template/catalog/layer/state.phtml 中也存在。

  • Limit table column width in IE6

    I have a 2×2 table coded like this:

    <table>
    <tr>
    <th id="r1c1">
    Short heading
    </th>
    <th id="r1c2">
    Short heading
    </th>
    </tr>
    <tr>
    <td id="r2c1">
    Very very long content blah blah blah
    </td>
    <td id="r2c2">
    Short content
    </td>
    </tr>
    </table>
    

    In the td cell r2c1, if the content does wrap, it takes more width than r1c1, say r1c1 requires 100px width, and r2c1 requires 300px.

    But I want r2c1 content words wrap and its width limits to 100px. I put width style in the first row, i.e.:

    <th id="r1c1" style="width:100px">
    

    It does not work in IE6.

    Then I put width attribute on col, i.e.:

    <table>
    <col width="100"/>
    <col width="100"/>
    ...
    

    It does not work in IE6, either.

    Then I put width attribute in r2c1, i.e.:

    <th id="r2c1" width="100">
    

    It does not work in IE6, either.

    At last, I put width style in r2c1, i.e.:

    <th id="r2c1" style="width:100px">
    

    Finally it works in IE6.

    I knew td’s width attribute is deprecated but I didn’t know deprecated IE6 does not read deprecated attribute.

  • Brand name for a new wine

    突然想给一种未上市的酒取名叫小人醴,大家觉得怎么样?

  • Open source for a purpose

    我花了一年多时间写了一个 branded made to order 的程序。整个结构多次变化,经历了多次从繁到简,再到繁,再到简。直到今天,结构变得非常简单、却能应付不预知的复杂行业。

    刚开始写时,我也没想要写一个行业无关的程序,只想有一个能用在我所在的行业就可以了;我也没想结构可以重构得如此简单,如果跳过过程看结果的话,10 分钟(不夸张)就可以读懂结构,只有我自己知道这样的结构是凭无数次的灵感堆积起来的。

    言归正传,这个程序设计成 magento module,最初我也想开源发布的。但时至今日,我想敝帚自珍了。我本身非常崇尚开源,这是我第一个不想开源的程序,为什么我有这样的想法?我演绎了一下:

    • 开源项目都有使用门槛,人人会用的项目就不开源了;
    • 就如,谁都预测不了彩票,所以才有这么多的彩票预测公司。
  • xls is the best data import format for phpmyadmin

    尽管我挺不愿意看到这个结果,但事实是 xls () 是在 phpmyadmin 中导入大量数据的最佳选择。xls 优于 csv 和 ods (Open Document Spreadsheet) 格式,尤其是在行数据差异比较大时(比如有 empty cell)。

    尽管我用 Open Office Calc 生成原始数据,但保存为 Open Office 嫡出的 ods 格式再导入时,数据变得参差不齐。我正绝望时,试着保存为 xls 格式再导入,一切 OK。

    回想 microsoft 所出的各种应用程序,确实有它强大的地方,至少有一点无人能及——在各应用程序间流畅地拷贝、粘贴。

  • Manifest module for Magento

    Manifest module for Magento is developed for a Chinese takeaway restaurent to produce a manifest with order items’ product name in a language recognizable by chefs, no matter what languages store front are using.

    Manifest module utilises Magento valuable multiple-website-storegroup-store structure. It is easy to use as long as you have precedent knowledge of implementing multiple stores in Magento. Let’s go through it step by step.

    Firstly, you must have a store or stores selling products. (sure you have)

    Secondly, create a store in a language recognizable by chefs. If this language is one of those enabled for store front, you can skip the step. Otherwise, just create a store but you do not have to enable this store. The purpose of this store is storing the product name in a store specific language.

    Lastly, map store languages. In System >> Configuration >> Manifest >> Manifest Storeview, choose a store which has manifest information. If you have newly installed Manifest module, you must log out and log in again to access configuration section.

    That’s it. Sales Order now has a tab called Manifest.

    Known issue: manifest does not produce order item custom options or bundle-simple product selection information. Currently I have no intention of further development.

    Download Manifest module here Manifest.tar.gz

  • phpMyAdmin 2002 error

    最近把家里的测试服务器 Zend Server php 5.2 卸载了,重新安装了 5.3。phpMyAdmin 随着 5.2 卸载也被卸载了。我用

    yum install phpMyAdmin

    重新安装了 phpMyAdmin。在 config.inc.php 设置了必要的参数,但 phpMyAdmin prompted:

    #2002 – The server is not responding (or the local MySQL server’s socket is not correctly configured)

    phpMyAdmin 2002 error
    phpMyAdmin 2002 error

    我浪费了很多时间检查了所有可能的错误,却解决不了问题。最后在 phpmyadmin.net 下载了源码,使用同样的 config.inc.php,顺利登录!

  • Access denied with my own google documents

    Google Apps 404 page
    Google Apps 404 page
    Cannot view pdf in Google Docs
    Cannot view pdf in Google Docs

    如果 google 帐号和 google app 帐号同时登录时,无法查看app docs,除非 app docs 给 google 帐号访问权限,换句话说 google 帐号的登录状态会掩盖 google app 帐号的登录状态。

    如果多个 google app 帐号同时登录,最先登录的域会阻止进入其他域(可以 retrieve docs list,但有时不能打开文档),有些情况下阻止,有些情况下不阻止,情况比较微妙,实在没空多研究。

  • Solve media type differencing after VirtualBox upgrade to 3.2.8

    Virtualbox Disks Inaccessible
    Virtualbox Disks Inaccessible

    我在 VirtualBox 升级到 3.2.8 以后发现其中的 Windows XP Guest OS 无法启动,其他 Guest OS 正常。Windows XP Guest OS 用到的两个 harddisk 文件也显示 inaccessible,而且也 release 不了它们,强行访问还给一个错误信息。

    Medium type of ‘/path/to/harddiskfile’ is differencing but it is not associated with any parent medium in the media registry (‘/path/to/.VirtualBox/VirtualBox.xml’).

    我也没怎么上心,觉得是 VirtualBox 升级版中的 bug,指望在后续版本中把它修复。可是好久没见 Oracle 出更新,只好 google 求帮助。

    我发现跟我有同样遭遇的人还不少,原因或许是 Host OS 使用了 ext4 文件系统导致不兼容。可为什么只影响 Windows Guest OS?管不了那么多,找解决办法要紧。

    解决方案众说纷纭。最后真正解决我的问题的是:

    Step 1: 去下载一个 fix 工具。我下载了 for linux VBoxFixHdd-Linux.tar.gz,其他的去 http://www.virtualbox.org/download/VBoxFixHdd/ 找。

    Step 2: 运行一下
    VBoxFixHdd --filename /path/to/image.vdi --zeroparentuuid

    其中 /path/to/image.vdi 就是 access 不了、release 不掉的问题文件,当然后缀不一定是 vdi,我的是 vmdk(不知道还有别的吗)。

  • CSS styling without images

    I am quite surprised with the styling effect achieved by pure CSS without the help of images. I can round corner and rotate html elements without creating any background images.

    See the result I get.

    Comprehensive styling using pure CSS
    Comprehensive styling using pure CSS

    And this is the ONLY product image in this CSS styling demo:

    Halloin 3D gift bags
    Halloin 3D gift bags

    Although the effect is comprehensive, but with the help of jQuery plugins, the syntax is very simple. Just a few lines of text.