Author: 芳草苑主

  • Manage magento catalog images on the local server

    Magento 的 Image / Media / Gallery 模型非常好用,可以迅速在全站范围内调整输出图片的尺寸。如果用户习惯于用上传图片的方式管理图片库,他会觉得 Magento 很方便。Magento 自动把上传的图片保存到 media/catalog/product/(文件名首字母)/(文件名第二字母)/(文件名或拖尾_1, _2, … 以防重名)。

    在产品库初建时,要输入大量的图片路径。虽然 product import dataflow 也很好用,但图片的保存位置规则跟上传时一样,我觉得不够好。因为:

    1. 原始图片是静态文件,可以独立于 Magento,存放在服务器的某个本地路径,也方便共享给其他程序使用;
    2. 如果 Magento 自行保存图片,浪费了服务器空间(对我来说,这倒没什么,服务器上空了好几百 G),而且按 media/catalog/product/(文件名首字母)/(文件名第二字母)/(文件名或拖尾_1, _2, … 以防重名) 去查找图片非常不方便,产品图片理应按 category 归入各个子目录。

    所以,我想把 Magento 的 Image / Media / Gallery 模型改进一下,做到:

    1. 原始图片存放于 static_file_server/catalog/product/category_1/subcategory_1/image_name。
    2. Magento 不保存原始图片,只要记牢原始图片在服务器上的某个位置。
    3. 喜欢 upload 的用户仍可以使用 upload,但为喜欢 ftp / ssh 的用户增加指定 local path 的功能。
    4. import product 接受 local_path。
    5. Magento 缓存图片的机制不变。
  • How magento deducts stock level

    我心里一直有个疑问,收到订单后,Magento 是怎么更新库存数量的?是直接用一个新库存数字去更新,还是用 upadte magento_cataloginventory_stock_item set qty=qty-qty_ordered 之类的办法。

    通过跟踪 sql 语句,我感觉前者的可能性很大。

    UPDATE `magento_cataloginventory_stock_item` SET `item_id` = '125', `product_id` = '125', `stock_id` = '1', `qty` = '93.000000', `min_qty` = '0.000000', `use_config_min_qty` = '1', `is_qty_decimal` = '0', `backorders` = '1', `use_config_backorders` = '0', `min_sale_qty` = '1.000000', `use_config_min_sale_qty` = '1', `max_sale_qty` = '0.000000', `use_config_max_sale_qty` = '1', `is_in_stock` = '1', `low_stock_date` = NULL, `notify_stock_qty` = '0.000000', `use_config_notify_stock_qty` = '1', `manage_stock` = '1', `use_config_manage_stock` = '0', `stock_status_changed_automatically` = '0', `shelf` = '' WHERE (item_id='125')
    

    这样很不好,如果几个人同时买同一个产品,会搞乱库存数。不知道被破坏的几率有多大,有空要搞一个并发下单的测试。

  • I am with Android

    出于对 google 技术的无限喜爱,我就在 android 手机里挑了一款 motorola dext,升级了我的手机。

    但是,我已经老了,新手机刚到手,摆弄了几下,明知道有很多新鲜的功能等我去发掘,已没有了新鲜劲。我只是把联系人、email、wifi 设置了一下,就丢开她了——我是不是老了?

    尽管如此,我已有感觉,这是一款非常非常 open and user friendly 的手机,比 iphone 强多了。电池不经用?跟 android 带来的强烈享受相比,瑕不掩瑜——毕竟电池不是 google 挑的。

  • Tag everything

    在管理文件时,我经常碰到这样一个问题:目前树形结构的文件系统,一个文件只能放在一个地方,决定了它只能被单维度管理。虽然有软连接、硬连接、快捷方式辅助,还是非常不方便:要去多个目录下建立连接就费时费力,而且目标文件移动了位置,这些连接统统都失效。多维度的文件管理,我能想到的办法就是用类似于数据库的技术,具体而言:

    1. 一个文件就是一条记录。
    2. 套用 EAV 模型,让用户可以自定义属性,称之为 attribute 也好,tag 也好,都是为了归类文件。
    3. 用属性的排列组合去过滤出想要找的文件集(inspired by Magento’s Grid),如果文件集过大,一次也不用全都显示出来,免得过度消耗资源,一次显示 20-50 个文件足矣。用户可以选择设置更多的属性进行深度过滤,或翻页浏览。以我的眼力,如果在超过50条记录的一屏里找一条记录,就有烦躁情绪,来回扫描还经常漏过那条记录。这就是“过多的信息就是没有信息”的道理,所以定义适合自己的过滤条件去找文件集才是王道。
    4. 用户浏览传统树形结构的文件系统,但浏览模式在新的文件系统中并不好用,必须配合过滤。其实层层浏览和过滤是异曲同工,只是后者更灵活,但需要更多操作键盘甚于鼠标。如果一个上网用户喜欢浏览多于搜索,他通常觉得鼠标比键盘好用,那么他可以自定义 view,即把常用的过滤条件保存下来,减少键盘操作。搜索模式得以保留,能搜索过滤前或过滤后的结果。

    其实 tag 化的文件管理系统已经有了很多,比如相片管理、视频管理、MP3管理、电子书籍管理等等。但这些系统都自称一套体系,没有可移植性,比如,不能把一组相片连同 tag 信息传输给别人(除非把相片管理系统也传输给别人)。我想要的是在 OS 文件系统层得到支持的 tag 存储,或者是根植于 Nautilus / windows explorer 的 tag 操作。有了她,相片管理系统、视频管理系统、MP3管理系统、电子书籍管理系统统统都没有销路了。

    其实 Google docs 就是这个干的,如果能应用到本地就好了。

    tag2find 基本可以实现我想要功能,但这个软件看上去不够大气,又只支持 windows,也非根植于 windows explorer,所以不足以打动我。

  • If you missed anything after customising all email templates in Magento

    To double check if you missed anything after customising all email templates in Magento, you can do a File Search on Selected resources (app/locale/(locale_code)/template/email in eclipse with these keywords:

    • (555) 555-0123
    • magento
    • demo

    By the way, eclipse can do Replace on Selected resources, which is an equivalent tool of File & Replace in Folder using Notepad++. I am sure a single linux command can also do the job but I can’t remember the syntax. Let’s just use eclipse, straight forward.

  • Add a section in Magento system configuration

    Want to add a section in Magento system configuration? It seems very easy as mentioned by others. No coding but editing xml files. Magento takes care of the rest. However, it still took me two hours to find the way out. So I think I need tell the world the caveats.

    • A section will not be shown if it is empty (no fields inside). Ditto tab or group.
    • acl must be defined per section in config.xml, otherwise you get Access Denied message.
    • Re-login is required, otherwise you still get Access Denied message.
  • Wysiwyg on individual page basis

    Html wysiwyg editing is good, but the html wysiwyg editors do not always format text as I wish. Sometimes they transforms some characters which I want to keep them intact.

    For example, I wanted to rewrite some of my posts on this blog by hand coding the post. But I must turn off wysiwyg editing in WordPress globally before I can save my post. Another “but” is I do not want to turn it off globally because it is a handy tool for writing some other posts. So I want wysiwyg on and off on individual page basis.

    For another example, Magento 1.4 now has wysiwyg editor built-in. However, it can’t recognise Magento’s mark-up tags for CMS block or CMS page. It wasted me an hour’s work by stripping these tags in a second after I clicked “Save”.

    In short, for people like me enjoying hand coding, I think a wysiwyg on-off attribute for each page basis would give me the best of both worlds.

  • Magento order fulfilment templates

    I said Magento was week at backend, that might be wrong. Of course compared with any accounting or ERP software, Magento is lack of some facilities to control the work flow of order fulfilment. When I dive into Magento backend, I think it should be sufficient for most of business. Most of business do not need an extension to fulfil orders, only need to customise the templates involved.

    Supprisingly, the templates are separated. I mean, Magento does not offer an overall template to generate different but related documents. For example, I must go through all the areas in the following table to change what to show up as order items detail.

      Frontend Backend
      Screen Print Email Screen Pdf
    Order thead          
    tbody          
    tfoot          
    totals          
    Invoice thead          
    tbody          
    tfoot          
    totals          
    Credit Memo thead          
    tbody          
    tfoot          
    totals          
    Shipment thead          
    tbody          
    tfoot          
    totals          

    Separating those templates make the programming less hassle, and the template changer can understand them easily. However, if I am that template changer, I hate copy & paste. As a programmer, I do my best to avoid delivering a program which require people to copy & paste.

    More importantly, if a template changer forgets to go through the above checklist to make a simple change in the order items detail, admin and customer get different view of the same order on screen, in email, or print-out when ordered, invoiced, credited, or shipped. I do not think this approach is acceptable. It is on my agenda to write an extension to make these documents under control.

  • Create FTP users on Godaddy free products

    前文讲到 Godaddy 随域名附送的免费空间非常强大,不嫌广告烦的话,做个个人网站绝对没有问题。

    既然可以建网站,就可以作文件服务器,支持 FTP,能自助创建多达50个 FTP user。

    Create FTP user in Godaddy hosting account
    Create FTP user in Godaddy hosting account

    Godaddy hosting account username / password 本身也是 FTP account。如果是合作伙伴要求上传或下载文件,当然不可以把自己的 username / password 告诉别人,应该分别为他们创建单独的帐号。Godaddy 需要十几分钟完成帐号同步,所以要等帐号状态从 Pending Setup 到 Setup 才能用。

  • Eclipse XML formatter

    Magento 有个我早就知道的 bug:读入 module config.xml 时,class name 必须在和 xml opening tag & closing tag 写在一行上,而且中间不能有 white space。这个 bug 直到最近的 Magento 1.4.0.1 都还有,可能 Magento 认为这不重要,重要的是如何书写 config.xml。所以我写 config.xml 一直都很小心。

    <catalog>
    	<rewrite>
    		<convert_adapter_category>MyNamespace_MyModule_Model_Eav_Convert_Adapter_Category</convert_adapter_category>
    	</rewrite>
    </catalog>
    

    但最近一次写完了 config.xml 下意识地按了 Ctrl + Shift + F 格式化了 config.xml,而这一行很长,eclipse XML formatter 自动把它换行书写了,造成 Magento 无法正确读入 class name。页面出不来了,什么原因?!我花了差不多一天时间才找到原因,一看到是这个原因,我又非常地懊恼——都是因为我懒,没有好好设置 eclipse 为我所用。

    Preferences for Eclipse XML formatter
    Preferences for Eclipse XML formatter

    于是亡羊补牢,我花了几分钟找到设置所在,把 Line width 设定一个足够大的数字就不怕它换行了。Aptana plugin 也带一个 Aptana XML Editor,另有地方设置,这里不多说了。