We are currently using the extension of Ext4Mage
which does a neat job. However, sometimes products aren't redirected, when they are ouf of stock.
We are now trying to create an extension, that observers the products and when they are out of stock, redirect them to their first maintained category.
For example:
Product 1
has Stock 1
. A customer checks out with this product, now it has Qty 0
.
The Product is bound to Category 1
, 2
and somewhat else
. I want my observer to create a new redirect for Product 1
's slug to the URL of Category 1
, since its the first category maintained in the product settings.
If Product 1
is in stock again, I want my product to be available again, and removing the further created 301 redirect.
What I'm thinking about:
I guess I need a observer, which checks a specific event, right now I'm not sure which event. The observer gets a few functions to deal with the aboves requirements and if the conditions match (i.e. product's out of stock
) it should trigger the functions.
How can I do that?