I'm kind of new in Magento and I'm working on a cron job that removes a product in a specific category after the date that was assigned. With work and the help of Stackoverflow, I came up with this code:
require_once 'app/Mage.php';
Mage::app();
$date = Mage::getModel('core/date')->date('Y-m-d H:i:s');
$collection = Mage::getModel('catalog/product')->getCollection();
$collection->addfieldtofilter('news_to_date', array(array('to' => $date)));
foreach($collection as $product) {
$product->setStatus(Mage_Catalog_Model_Product_Status::STATUS_DISABLED);
$product->save();
}
This checks the actual date and compares it with the date of the products. If the date has passed, the product is disabled. What I need is that instead of disabling the product, the code should remove the product of the category (in this case the category is 'Sales')
I hope you guys can help me!
Thanks in advance!