0

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?

1
  • Did my answer help? If so, I'd appreciate if you'd consider marking it as the accepted answer by clicking the checkmark next to it...
    – tjons
    Dec 7, 2016 at 2:31

1 Answer 1

1

I would use the cataloginventory_stock_item_save_after event for this. You can then check if the qty is below zero, or whatever threshold you want for a backorder (some merchants prefer to mark an item as "backordered" before the qty reaches zero). Then, you can call the functions you were talking about above.

If you have any questions, please ask in the comments and I'm happy to help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.