<?php /** * file path: * magento_root/app/code/local/Some/Extension/Model/Observer.php */ class Some_Extension_Model_Observer { public function someMethod( $observer ) { /** *Do some stuff here */ return $observer; } } ?>
Overriding Magento observers
As you may know, we need to override the Magento observers when we deal with the extension’s conflicts or want to disable (or modify) a part of some extension’s functionality. Usually, there is no difference between the observer’s overriding and overriding of any other regular model. But sometimes we can face with the issues working with the simple override. How should we act then to keep it conventionally? Let’s check the following step by step instruction for Magento observers overriding.
First of all, we should pay attention to the naming. Let’s assume that we have some 3rd party extension. It is named Some_Extension, and this extension has the following observer:
Labels:
Magento
Some useful and important code in magento
Some useful and important code in magento :-
<?php Magento Home URL - Mage::getBaseUrl(); Magento Home Directory - Mage::getBaseDir(); URL of a file in the skin directory - $this->getSkinUrl('images/myfile.png'); // in a template or Block - Mage::getDesign()->getSkinUrl('images/myfile.png'); // from anywhere Format a price value - Mage::helper('core')->formatPrice($amount);
Labels:
Magento
How to insert,update,delete and show data in Magento
Suppose, I have a module named mynews. Here follows the code to select, insert, update, and delete data from the news table
1. INSERT DATA
$data contains array of data to be inserted. The key of the array should be the database table’s field name and the value should be the value to be inserted.
1. INSERT DATA
$data contains array of data to be inserted. The key of the array should be the database table’s field name and the value should be the value to be inserted.
<?php $data = array('title'=>'hello there','content'=>'how are you? i am fine over here.','status'=>1); $model = Mage::getModel('mynews/mynews')->setData($data); try { $insertId = $model->save()->getId(); echo "Data successfully inserted. Insert ID: ".$insertId; } catch (Exception $e){ echo $e->getMessage(); } ?>
Labels:
Magento
How to insert your block into any place in Magento
Hello guys, it’s time to tell you how to insert block into any place you want in Magento. As you know, very often we need to set some block into selected weird place without editing template, so we’ll try to describe the way how to do this using layouts and observers.In our case, for such experiments will be used category page. Let’s say, you need to place your block inside the other one and this block is instance of the Mage_Core_Block_Text_List class. That means, the block renders his children automatically, what’s easy. Then, you just need to follow the steps which are below:
This block will be displayed after all content of the “left“ block. But, what if we need it to be displayed before all content – just add the “before” directive. See below such example:
Labels:
Magento
Subscribe to:
Posts (Atom)