0

I have created one category for displaying new arrivals and have added all items under this category. Now i need to delete old items (30 days old & 7 days old) from that category. This should happen daily and automatically.

1 Answer 1

1

You can achieve this by two methods.

1) Cron

you need to create a cron which will execute as per your required time frame and make the changes accordingly.

you can follow the following url to create a cron.

Remove product from category using cron

http://inchoo.net/magento/creating-cron-script-in-magento/

2) Observer

you need to create a observer which will execute on controller_action_predispatch event and makes the changes accordingly. for creating observer you can follow the following url.

http://inchoo.net/magento/newsletter-auto-subscribe-create-account-place-order-magento/

how to create an new observer on the event catalog_product_save_before

Code to delete product from category

Mage::getSingleton('catalog/category_api')->removeProduct('7','13409');

where 7 is the category id and 13409 is product id

1
  • This my code : <?php require_once 'app/Mage.php'; Mage::getSingleton('catalog/category_api')->removeProduct('1','3'); ?> its not working
    – zus
    Commented Dec 12, 2017 at 9:54

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.