Tag: magento

  • Magento attribute’s attribute frontend_class

    Magento EAV framework is very promising, but not easy to understand. When the code is mixed with typos, it becomes even more confusing.

    Mage_Catalog_Model_Resource_Eav_Mysql4_Setup provides a template for setting up an attribute.

    'name' => array(
    'type'              => 'varchar',
    'backend'           => '',
    'frontend'          => '',
    'label'             => 'Name',
    'input'             => 'text',
    'class'             => '',
    'source'            => '',
    'global'            => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
    'visible'           => true,
    'required'          => true,
    'user_defined'      => false,
    'default'           => '',
    'searchable'        => false,
    'filterable'        => false,
    'comparable'        => false,
    'visible_on_front'  => false,
    'unique'            => false,
    )
    

    However, ‘class’ is wrong. It should be ‘frontend_class’. It refers to DOM class attribute assigned to this entity attribute output html. It can be used for value validation before submission. The possible classes can be found in js/prototype/validation.js. But frontend_class can be set anything you like for css styling or other purposes.

  • Update index after moving category in Magento

    这介于 bug 与 usability issue 之间:

    Moving category 使 category url 发生变化后,该 category 所属产品无法 add to compare,Compare, Compared, Viewed sidebars 统统不正常。

    我在 Magento 1.4.2.0 上发现这个问题,或许早先版本一直存在这个问题。我认为它象 bug,是因为 moving category 后 Magento 不提示 reindex index。

    解决办法也很简单,就是 moving category 后,用 System >> Index Management reindex 一下。

  • Magento sitewatch module

    在 ebuyer 上关注 OCZ 120GB RevoDrive SSD 很久了,它的价格一直在 £245 左右,比第二选择 OCZ 120GB Vertex 2E SSD 贵出近 £70。RevoDrive 比其他 SSD 的 data transfer rate 要快一倍左右,但我吃不准这一倍的快速能否在我的电脑上体现,所以一直犹豫着。

    今天中午无意中上 ebuyer 又看了一下,发现 RevoDrive 突然降到 £230,这降价让我觉得多时的观望得到回报,刺激我立马就买了它。

    下午,收到 dabs 的 newsletter,其中提示 DrayTek Vigor 2820 从 £155.78 降为 £134.99。我三天前刚从 broadbandbuyer 买过 Vigor 2820n,当时还上 dabs 比较过价格,所以对 Vigor 2820 系列比较敏感。幸好当时买的不是 Vigor 2820,否则现在有遗憾了,broadbandbuyer 目前 Vigor 2820 的价格是 £146.81 (还要另加 £4 邮费,dabs free shipping)。

    废话讲了一堆。我想做一个 site watch 的程序,对一些想买又不急着买的产品价格进行跟踪,一旦价位合适,就在第一时间动手。象 ebuyer 故意每天有事没事搞一点价格波动,通常幅度在一两镑,纯属吊人眼球,如果我真每天用眼球去看,感觉就被人牵着鼻子走(或许这是一种市场手段?只是我不喜欢),所以想到用程序去看,直到一个实质性降价的时刻再用眼球去看。

    Price watcher 有人做过,但只能跟踪几个名气大的网站,不对我胃口。我也写过一个简陋型的 sitewatch,但被我跟踪的网站 layout 变动比较快,它们一改我就要改程序,说明我的程序写得不好,所以用了几天就不用了。今天重拾这个话题,这次我想把 sitewatch 做成 Magento module。虽然 sitewatch module 跟 Magento ecommerce 风马牛不相及,只用到了 adminhtml 一些 GUI 和 crontab,但基于 Magento framework 的开发可以省我不少时间。

  • Magento layout handle name is misleading

    在 Magento app/design/frontend/base/default/layout/catalog.xml 文件里有一段让我费解的配置:

    <catalog_category_layered_nochildren translate="label">
        <label>Catalog Category (Without Subcategories)</label>
        <remove name="right.reports.product.viewed" />
        <reference name="right">
            <block type="reports/product_viewed" before="right.permanent.callout" name="left.reports.product.viewed" template="reports/product_viewed.phtml" />
        </reference>
    </catalog_category_layered_nochildren>
    

    catalog_category_layered_nochildren,从字面上看,应该是只对 is_anchor == 1 并没有子目录的目录有效;但事实上,它对所有没有子目录的目录有效,所以我想,handle 应该取名 catalog_category_nochildren 更合适。Mage_Catalog_CategoryController::viewAction() 里有一段

    if (!$category->hasChildren()) {
        $update->addHandle('catalog_category_layered_nochildren');
    }
    

    由此可见这里仅检验 hasChildren,未检验 getIsAnchor。

    catalog.xml 里把 right.reports.product.viewed 移除又添加,重新添加后 block 叫 left.reports.product.viewed,但实际位置仍在右边。这么做有什么意义?我费神地看了半天,得出的结论是:

    没有意义。大概 Magento 是借此演示一下 layout syntax。

    虽然没有意义,但是影响还是有的,有这一段,nochildren 的 category page sidebar 排序为 Compare, Compared, Viewed;否则排序为 Compare, Viewed, Compared。

    Sidebar in the sequence of Compare, Compared, Viewed
    Sidebar in the sequence of Compare, Compared, Viewed
    Sidebar in the sequence of Compare, Viewed, Compared
    Sidebar in the sequence of Compare, Viewed, Compared

  • Ajax Layer Navigation module for Magento

    有人要我对 Magento layer navigation 做些小修改,我觉得修修补补没有意义,要做就做一系列的修改,于是按我觉得可以改进的方向,列了以下几点。

    Add ajax load/change products on page loads or filter changes (TODO)

    Add option to show/hide category filter

    Add option to show price filter as slidebar (TODO)

    Add option to control price accuracy

    Add up to 3 sort by’s (TODO)
    (Someone already asked for a second sort by)

    Add option to show/hide sort by’s (TODO)

    Add option to or not to merge sort asc/desc into sort by dropdown (TODO)

    Add sort by’s position (TODO)
    (Magento native code can control filter attributes’ position, but cannot control sort by attributes’ position)

    Add recursive walk-through function to sort by settings for category and its child categories (TODO)

  • Keep pace with Magento

    I tried Magento 1.4.2.0 RC1 today, and noticed it had added “Include in Navigation Menu” option in Manage Category.

    I am very happy seeing this because I made it happen before Magento did. I call it “Exclude in Top Navigation”. I also have added an option “Exclude in Sitemap” which is not available in newest version of Magento.

    So, I keep pace with Magento, and vice versa?

  • How is customer_logged_in/out handle added to Magento layout?

    I was wondering how Magento merge or handle into handle in layout.

    I was expecting something like

    <default>
        <update handle="customer_logged_in" if="logged_in"/>
        <update handle="customer_logged_out" if="logged_out"/>
    </default>
    

    Obviously, there is not such codes in layouts.

    I searched within Magento folder for keyword “customer_logged_in”, but only occurrences I could find in layout/customer.xml.

    So, how is customer_logged_in/out handle added to Magento layout?

    At last, I found

    class Mage_Customer_Model_Observer
    {
        public function beforeLoadLayout($observer)
        {
            $loggedIn = Mage::getSingleton('customer/session')->isLoggedIn();
    
            $observer->getEvent()->getLayout()->getUpdate()
               ->addHandle('customer_logged_'.($loggedIn?'in':'out'));
        }
    }
    

    by tracing addHandle() in app/core/Mage/Core/Model/Layout/Update.php.

    I must say using observer adding layout handle makes very easy for other modules to detect customer login status.

  • Never use dotless domain for Magento installation

    Magento 说不要使用 localhost 安装,我也就不用,也没深究原因。

    我为了在本地调试一个网站,先拿了生产网站 euro-bags.eu 的一个子域名。后来该子域名被挪作他用,那时我想,如果换个子域名再被挪作他用,我干脆用一个用于域名保护而未建站的域名,于是开始用 euro-bags.com 来调试。

    没过很久,Euro Bags 要在生产网站上实施一条网站提速实践:静态文件使用单独的 cookieless domain。因为 euro-bags.eu 使用了顶级域名,顶级域名上使用了 cookie,那么子域名上无法实现 cookieless。Euro Bags 也不想依赖第三方服务 cookieless domain,于是启用 euro-bags.com 专门为生产网站提供静态文件。

    我的调试域名再次被挪作他用。为了防止此类不可预测的事情发生,我想到干脆用一个不可能用于生产网站的域名来完成调试,于是想到用 euro-bags。

    一开始没发现问题,用了几天后想登录 euro-bags admin area 发现登录不了,输入密码后总是弹回到登录页。

    百思后才得其解,原来在 Magento 里使用任何 dotless hostname 都犯了跟使用 localhost 同样的禁忌。Magento 基于安全考虑在 cookie 里打上 domain 烙印,而大部分浏览器用拒绝接受含 dotless hostname 的domain 烙印。虽然可以 comment out app/code/core/Mage/Core/Model/Session/Abstract/Varien.php 某些行让 Magento 在 cookie 里不打 domain 烙印,从而让浏览器接受它的 cookie,但我觉得这么做是南辕北辙:不含 domain 烙印的 cookie 固然通行,但 open to cookie hijacking。Magento 最值我称道的就是每个细节(我没见其它 ecommerce software 有如 Magento 的周到)。

    既然 Magento 要在 cookie 里打 domain 烙印,而大部分浏览器又不接受 cookie 里有 dotless hostname,那我就不要用 dotless hostname 来安装 Magento 不就得了。于是我最新启用euro-bags.net 来继续本地调试,因为未有迹象表明 Euro Bags 要把 euro-bags.net 纳入域名保护,也没有要用这个域名来提供服务的计划,所以我不用再频频更换调试域名了。

  • public static or static public

    在 php 中,public static 或 static public 怎么写都可以,所以我一直不知道哪种是正统的写法(象我这样追求正统的人,或许 python 更适合我?)。

    今天费点时间看看别人是怎么看待 public static or static public 这个问题的。我的结论是 public static 是正统的写法,于是我想把以前随意写成的 static public 都更新成 public static。所幸的是,以前一直用的都是 public static。倒是在 magento 的源码里找到一堆 static public,或许 magento developers 没被要求一定要怎么写,所以源码里混合了 public static 和 static public。

    我觉得 inconsistency 是最糟糕的,或许我在这个问题上吹毛求疵了。

  • Full page caching preparer module for Magento

    I am planning a project called Fpcp (Full Page Caching Preparer) to improve Magento performance. Yeah, it is called Fpcp and very similar to another module Cpfp (Cms Page Foot Print).

    I have a bit research on Magento Enterprise only features, and pick full page caching as my next interested project. I do not know how Magento Enterprise implements full page caching, but my idea is rewriting all blocks containing session related content with an ajax get method.