I'm currently in the process of messing about with Magento, and I'm just wondering if anyone knows where I can modify the collection that is used for Mage_Adminhtml_Catalog_ProductController
(app/code/core/Mage/Adminhtml/controllers/Catalog/ProductController.php)? Which method am I rewriting/creating to change the products to show?
EDIT1: I'd rather have a way of using observers, I.e. which event do I need to apply my code to?
EDIT2: best to add here what I'm trying to achieve; I've added an extra attribute to products which holds which admin added that specific product. Now In the admin panel, when a user views the list of products, they only see the products where the that attribute is their admin id.
EDIT3: I just stumbled upon catalog_product_load_after
event observer, and I'm not sure if this is the right one, but this is what I have:
confix.xml
<?xml version="1.0"?>
<config>
<adminhtml>
<events>
<catalog_product_load_after> <!-- Name of Event -->
<observers>
<load_after> <!-- Any Unique Identifier -->
<type>singleton</type>
<class>Drench_Admindetails_Model_Observer</class> <!-- Over Model Class -->
<method>loadAfter</method> <!-- name of function -->
</load_after>
</observers>
</catalog_product_load_after>
</events>
</adminhtml>
</config>
and Model/Observer.php
<?php
class Drench_Admindetails_Model_Observer{
public function loadAfter(){
fb('testasd'); // this just a firephp call
}
}
You could listen to catalog_product_collection_load_before
or catalog_product_collection_load_after
.
To find the event you're interested in, use Alan Storm's technique: edit app/Mage.php dispatchEvent() method, adding this line at the beginning:
Mage::log('Event: ' . $name, null, 'events.log');
This will write all events in an /var/log/events.log file.
I'd put a link to Alan's original post, but I can't find it right now: if anyone find it I'll update my answer.