您需要创建一个新模块。
叫它Easylife_Meta
。
app/etc/modules/Easylife_Meta.xml
-声明文件
<?xml version="1.0"?>
<config>
<modules>
<Easylife_Meta>
<codePool>local</codePool>
<active>true</active>
<depends>
<Mage_Catalog />
</depends>
</Easylife_Meta>
</modules>
</config>
app/code/local/Easylife/Meta/etc/config.xml
-配置文件
<?xml version="1.0"?>
<config>
<modules>
<Easylife_Meta>
<version>0.0.1</version>
</Easylife_Meta>
</modules>
<global>
<models>
<easylife_meta>
<class>Easylife_Meta_Model</class>
</easylife_meta>
</models>
</global>
<adminhtml>
<events>
<catalog_product_save_before><!-- observe the event -->
<observers>
<easylife_meta>
<class>easylife_meta/observer</class>
<method>autoMetaDescription</method>
</easylife_meta>
</observers>
</catalog_product_save_before>
</events>
</adminhtml>
</config>
app/code/local/Easylife/Meta/Model/Observer.php
-观察班
<?php
class Easylife_Meta_Model_Observer {
public function autoMetaDescription($observer) {
$product = $observer->getEvent()->getProduct();
$metaDescription = "Buy ". $product->getName()." for Rs ".number_format($product->getFinalPrice(), 2)." at sitename.com | New Book | Authorised seller for ". $product->getAttributeText('publisher');
$product->setMetaDescription($metaDescription);
}
}
完成后清除缓存。