Pregunta

¿Hay un evento único que puedo crear un observador para que se activa cuando un producto se carga, ya sea usando getModel oa través de una colección?

El caso de uso exacto que tengo es que tengo un atributo del producto a medida, pero con el fin de devolver el resultado correcto, más lógica que hay que hacer, que es la base de otros factores? entonces yo estoy planeando para calcular esta lógica después de la carga y almacenarla en otro miembro. Si alguien tiene una alternativa me gustaría también estar agradecidos por este consejo.

¿Fue útil?

Solución

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.

Otros consejos

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

Licenciado bajo: CC-BY-SA con atribución
No afiliado a magento.stackexchange
scroll top