Вопрос

I have a symfony2 web app using postgresql. My (simplified) app displays products that have 3 features - price, date available till, and weight. Users can search for products on these 3 parameters and save the query to their profile. The query easily runs when they click on the link in their profile.

I want to add new functionality to email the user when there is a change to the results of their saved query. This can happen if a new product is listed and fits their parameters, or if an existing product that matches their query has a change - say either a price change or the date it is available till is changed.

I am thinking that I need to create a new entity in Symfony2 which will contain all of the product attributes along with the query ID since there can be many products for each query. Next, I will need to create an event that runs each time a product is either added or changed, that way I can send an email to the user and specify what changed.

Perhaps to simplify this, I could add an updatedAt field to the product entity and instead of including all of the product attributes in the new entity, I will only save product ID and will only tell the user product changed.

Is there a better way to do this than creating a new entity that stores the results of each saved query? I can add code to show what I am doing, but feel I am at a major fork and could use many different possibilities that may not even involve creating new entities.

Это было полезно?

Решение

I solved this by adding a little more functionality as suggested by CBroe. I added an active flag and am now keeping a history of the product entity when important changes are made. This way it is simple to query the active products and still query the product that was purchased back in time. I am now beginning to add a scheduled task to run at set intervals instead of sending out notifications right away for performance purposes, but that is a separate issue. Thanks for the idea of using the active flag and suggestion for keeping a history since that will be used down the road.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top