Day: January 28, 2011

  • What does backend type static mean in Magento?

    About a year ago, I noticed some category or product attributes, for example, sku, path, etc., were given backend type “static” in class Mage_Catalog_Model_Resource_Eav_Mysql4_Setup. But I failed to find out what static meant here, or I did not know what the difference was between static and datetime/decimal/int/text/varchar. All I knew at that time was if I gave my user defined attribute a “static” type, the attribute values were stored in _varchar table.

    Recently, I dived deeper into Magento EAV module. Now I can answer my question.

    An entity can have some “static” attributes, whose values are stored in entity main table. Take sku for example, sku values are stored in catalog_product_entity table. Although sku is varchar type, its values are not stored in catalog_product_entity_varchar. Magento does not lookup catalog_product_entity_varchar for sku values because in eav_attribute table, sku backend type is defined as “static”.

    It also explains why I can get sku values without add it to select, but I can not do the same with non static attributes.

    $collection = Mage::getModel('catalog/product')->getCollection();
    echo $collection->getFirstItem()->getSku();
    

    It will output the sku.

    $collection = Mage::getModel('catalog/product')->getCollection();
    echo $collection->getFirstItem()->getName();
    

    It will not output the name.

    $collection = Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect('name');
    echo $collection->getFirstItem()->getName();
    

    Calling addAttributeToSelect is a must to retrieve non static attribute values.

    For user defined attributes of existing entity, if I do not change the structure of main entity table, even I specify backend as “static” in entity setup class, Magento has nowhere to store their values to but fallback to _varchar table.

  • Establish a protocol of post tags

    尽管在 WordPress 里新增一个 post tag 是件很容易的事情,但我不想每次想到一个 tag 就增一个,上千个 posts 就有几千个 tag,搞得 posts 之间的 tag 联系很松散。所以,我很久不新增 tag 了,写完 post 就在已有的 tags 里挑一个或几个 tags 出来。

    时代在发展,新生事物不断出现,如果我老用几年前敲定的 tags 而不与时俱进,blog 就显得 out 了,也不利于芳草苑在新新名词方面的排名。比如,刚才一篇,想用 chrome,结果发现有 firefox 而没有 chrome,只好暂时 tag 一个 firefox,等我整理好一份 tag waiting list 再更新 post tags。

    初步想删 office, outlook 等,因为 windows 已经 out 了,我也没在 office, outlook 主题上浸淫许久,这类 posts 干脆合并一个 microsoft 或 windows software 得了。

    初步想增加 android, html5, css3, jquery, 因为它们或是日渐热门,或是已经热门,我三天两头都会讲到这类主题。现在统称为 google, html, css, javascript 似乎对它们不公平。

  • Dolphin does not work with HTML5 drag and drop

    I use Dolphin in the office, and Nautilus at home. I feel managing files in Dolphin is a little more efficient than in Nautilus, but only a marginal better.

    Today I find Dolphin does not support files drag and drop into browser for browser to upload. Drag and drop is an exciting feature of HTML5 and Google has implemented it to Chrome. I quite enjoy using it uploading files to Google Documents.

    I would like to use this feature as much as possible but at moment I have to use Nautilus to drag and drop to Chrome. I believe soon I can also use Dolphin to drag and drop to Firefox.