문제

Is there a single event that I can create an observer for that gets fired when a product is loaded either using getModel or through a collection?

The exact use case i have is that i have a custom product attribute, but in order to return the correct result, further logic needs to be done which is based on other factors? I am then planning to compute this logic after load and store it in another member. If someone has an alternative i would be also grateful for this advice.

도움이 되었습니까?

해결책

You don't need an observer to do this. You can use the attribute backend_model to handle your logic.

If you specify a backend_model with your attribute and you extend the Mage_Eav_Model_Entity_Attribute_Backend_Abstract class within your backend model class you can use the afterLoad, beforeSave, afterSave, beforeDelete or afterDelete methods to execute your own logic.

Using the backend_model is the correct way to implement this sort of logic and is how native Magento attributes do it where they have similiar requirements.

다른 팁

Sadly it looks like you might have to use two here :(

Product: catalog_product_load_after
Collection: catalog_product_collection_load_after

The collection event gives you a 'collection' object to work with. You can loop through this and make your changes on a product level. If you move your code into a helper or use the same Observer.php for both events then you should be able to limit the amount of duplicate code.

Try

<catalog_product_load_after>
     <observers>
      ...

See https://stackoverflow.com/questions/15763829/magento-load-product-event-observer

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 magento.stackexchange
scroll top