Calling Developers!
We are reenergizing our code contribution process! Learn More

How can I attach something like postPersist on a spy product entity when created/updated?

Options
ivan-jurisic
ivan-jurisic Senior Spryker developer Posts: 25 🧑🏻‍🚀 - Cadet

The background is that akeneo importer uses dynamic entity feature which writes directly to db and avoids methods from the facade so I can't attach postCreate or postUpdate plugins. How can I handle that in order to do something when product is being created/updated via dynamic entity feature?

Answers

  • fsmeier
    fsmeier Senior Software Engineer & Developer Enablement Advocate Sprykee Posts: 1,029 ⚖️ - Guardians (admin)
    Options

    Heyhey,

    I have not tested it bymyself, but have you tried to create your own propel-behavior? I could imagine that you can hook into that by doing this, similar how Spryker created the behaviors.

    All the best,

    Florian

  • ivan-jurisic
    ivan-jurisic Senior Spryker developer Posts: 25 🧑🏻‍🚀 - Cadet
    Options

    Hey, it is okay about behavior. Spy_product table has behavior, it saves events in spy_event_behavior_change table. But I am not able to consume it and handle it. Do you have an idea why?

  • fsmeier
    fsmeier Senior Software Engineer & Developer Enablement Advocate Sprykee Posts: 1,029 ⚖️ - Guardians (admin)
    Options

    Heyhey,
    I didnt mean to reuse the "event" behavior of Spryker - but now that I think about it this could also be a way to go. Initially I thought about creating your own behavior.

    What have you tried so far to consume it?

    All the best,

    Florian

  • ivan-jurisic
    ivan-jurisic Senior Spryker developer Posts: 25 🧑🏻‍🚀 - Cadet
    Options

    Hey, first of all thank you for trying to understand and willingness to help.

    I tried to attach listener on Entity.spy_product.create event and write my own code for handling it. I also tried to find already any listener consuming that event but couldn't catch it in debugger. Do you have an idea why?

  • fsmeier
    fsmeier Senior Software Engineer & Developer Enablement Advocate Sprykee Posts: 1,029 ⚖️ - Guardians (admin)
    edited November 2023
    Options

    Heyhey,

    so normally I used the "event" behavior just for Publish&Synchronize. And I think this is still the most common use-case.

    The latest best practise for Pub&Sync is to register the event handler in the Zed Publisher module (DependencyProvider) like shown in our elearning on Spryker Safari.

    BUT: you dont want to do Pub&Sync here. So the old way of handling events for Pub&Sync could be the place to look for. Have a look at src/Pyz/Zed/Event/EventDependencyProvider.php and define your own subscriber and listener. I think if this is properly defined, your change/create event will be placed on a queue you defined (by default likely "event"-queue) and it will be processed via the background task. But instead of doing the publish/Sync to your event you can have your own logic then.

    All the best,

    Florian

  • ivan-jurisic
    ivan-jurisic Senior Spryker developer Posts: 25 🧑🏻‍🚀 - Cadet
    Options

    Awesome. I will let you know how that went 😀 Thanks! This sounds like good.