Pregunta

Intro: I'm a Python(Django) developer who is working at a company where we use Magento in the backend to sell products on our website. I'm not really experienced in Magento. We are using Magento version 1.7.0.2.

What I want: On certain events like new product/order/customer create, I want Magento to do some functions. Eg: For new product create, I want magento to call a celery task which will check certain conditions and send an email to the site merchandiser if some data is wrong.

What I have done: As far as I understand, Magento has an event like _save_after which is triggered after a new product is saved. Using this, Magento is calling the celery task with the entity_id of the product on this even trigger. When the celery task is triggered, I'm querying the database(catalog_product_entity table) for the product using the entity_id sent from Magento.

Issue: In some cases, when I'm querying the database for the newly created product, the database returns 0 rows. This happens almost all the time.

What I think: I think, there might be some sort of asynchronous queueing done in Magento which is causing this issue. Can someone give me an explanation to this and let me know how to fix this issue?

I've searched a lot about this and still not able to figure what caused this.

¿Fue útil?

Solución

What I think: I think, there might be some sort of asynchronous queueing done in Magento which is causing this issue. Can someone give me an explanation to this and let me know how to fix this issue?

You are on the wrong track here. What happens: The product is saved within a transaction. To do something after the change has been commited to the database, you can use the catalog_product_save_commit_after event instead of catalog_product_save_after.

But just to fetch the ID it should not be necessary, because Magento already retrieves the inserted ID and assigns it to the object (see Mage_Core_Model_Resource_Db_Abstract::save())

So in the observer for catalog_product_save_after, you can retrieve it:

$observer->getProduct()->getId()
Licenciado bajo: CC-BY-SA con atribución
No afiliado a magento.stackexchange
scroll top