load($saleid); $productRef = Mage::getModel('catalog/product'); $todayDate = $productRef->getResource()->formatDate(time()); //Get all products which are valid sales $products = $productRef->getCollection() ->addAttributeToFilter('special_to_date', array('date'=>true, 'from'=> $todayDate)); foreach ($products as $product) { $categories = $product->getCategoryIds(); if (array_search($saleid, $product->getCategoryIds())===FALSE) { //Not set so assign the product $categoryApi->assignProduct($saleid, $product->getId()); echo $product->getSku().'(A) '; } } //Get all products which are expired $products = $productRef->getCollection() ->addAttributeToFilter('special_to_date', array('date'=>true, 'to'=> $todayDate)); foreach ($products as $product) { $categories = $product->getCategoryIds(); if (array_search($saleid, $product->getCategoryIds())!==FALSE) { //Expired so remove the product $categoryApi->removeProduct($saleid, $product->getId()); echo $product->getSku().'(E) '; } } //Get all products which are invalid $products = $productRef->getCollection() ->addCategoryFilter($category) ->addAttributeToFilter('special_to_date', array('is' => new Zend_Db_Expr('null'))); foreach ($products as $product) { $categories = $product->getCategoryIds(); if (array_search($saleid, $product->getCategoryIds())!==FALSE) { //Expired so remove the product $categoryApi->removeProduct($saleid, $product->getId()); echo $product->getSku().'(I) '; } } ?>