2. app/code/local/Kim/Syncmedia/controllers/indexController.php [codesyntax lang="php"]
class Kim_Syncmedia_IndexController extends Mage_Core_Controller_Front_Action
{
public function indexAction()
{
$params = $this->getRequest()->getParams();
$model = Mage::getModel('syncmedia/observer');
var_dump($params);
var_dump($model);
exit();
}
}
[/codesyntax]3. app/code/local/Kim/Syncmedia/etc/config.xml [codesyntax lang="xml"]
<?xml version="1.0"?>
<config>
<!-- base configurations -->
<modules>
<Kim_Syncmedia>
<!-- module version -->
<version>0.1.0</version>
</Kim_Syncmedia>
</modules>
<!-- global configurations -->
<global>
<!-- enable models and resources -->
<models>
<syncmedia>
<class>Kim_Syncmedia_Model</class>
<!-- <resourceModel>weblog_mysql4</resourceModel> -->
</syncmedia>
</models>
<!-- events hooks -->
<events>
<cms_page_save_after>
<observers>
<kim_catalog_observer>
<type>singleton</type>
<class>syncmedia/observer</class>
<method>sync_cms_image</method>
</kim_catalog_observer>
</observers>
</cms_page_save_after>
<catalog_category_save_after>
<observers>
<kim_catalog_observer>
<type>singleton</type>
<class>syncmedia/observer</class>
<method>sync_category_image</method>
</kim_catalog_observer>
</observers>
</catalog_category_save_after>
<catalog_product_save_after>
<observers>
<kim_catalog_observer>
<type>singleton</type>
<class>syncmedia/observer</class>
<method>sync_product_image</method>
</kim_catalog_observer>
</observers>
</catalog_product_save_after>
</events>
</global>
<!-- frontend configurations -->
<frontend>
<routers>
<syncmedia>
<!-- module route -->
<use>standard</use>
<args>
<module>Kim_Syncmedia</module>
<frontName>syncmedia</frontName>
</args>
</syncmedia>
</routers>
</frontend>
[/codesyntax]4. app/code/local/Kim/Syncmedia/Model/Observer.php [codesyntax lang="php"]
class Kim_Syncmedia_Model_Observer
{
protected function _construct()
{
$this->_init('syncmedia/observer');
}
public function sync_cms_image($observer)
{
system('cp -Ru /data/vhosts/magento/public_html/media/*[.a-z] /data/vhosts/magento2/public_html/media/ &');
system('chmod -R g+w /data/vhosts/magento2/public_html/media/ &');
return $this;
}
public function sync_product_image($observer)
{
system('cp -Ru /ddata/vhosts/magento/public_html/media/catalog/product/* /ddata/vhosts/magento2/public_html/media/catalog/product/ &');
system('chmod -R g+w /data/vhosts/magento2/public_html/media/catalog/product/ &');
return $this;
}
public function sync_category_image($observer)
{
system('cp -Ru /data/vhosts/magento/public_html/media/catalog/category/* /data/vhosts/magento2/public_html/media/catalog/category/ &');
system('chmod -R g+w /data/vhosts/magento2/public_html/media/catalog/category/ &');
return $this;
}
}
[/codesyntax]5. Finally you need to enable the module with : app/etc/modules/Kim_Syncmedia.xml [codesyntax lang="xml"]
<?xml version="1.0"?>
<config>
<modules>
<Kim_Syncmedia>
<active>true</active>
<codePool>local</codePool>
</Kim_Syncmedia>
</modules>
</config>
[/codesyntax]
HI Kim, It’s really very informative & useful article. I wanted to know more about event-observer model of Magento. Currently I am focussing on sales order placement event. I have created one custom table in Magento that contains different sales order related columns(like increment id from sales_flat_order, item_name,sku from sales_flat_order_item etc.). I connected to mysql database through PHP. I join these table to form a single query & put this query which fetches & inserts data into custom table. Now my ultimate aim is once customer places order, this php file must get called so that all data fetched through that query get inserted into custom table… So how event-observer model I can use for the same…do u have any sample code for the same… Plz guide me… Regards, Prat
Hi! Thanks for your post, it is helpful. Our team has also solution of this topic that is described here http://www.atwix.com/magento/observers-reality-or-fiction/ Nice to share our achievements with others We are glad to see your comments and responses