cancel
Showing results for 
Search instead for 
Did you mean: 

Create a special price page without products from a certain category

Create a special price page without products from a certain category

We have 2 categories with discounted products. I want to keep them separated, so the best way is to filter my special prices page (I think).

We now have all special prices on one page, but now I want to exclude the products from a specific category, how do I do this?

This is my code now:

  <?php
class Mage_Catalog_Block_Product_Special extends Mage_Catalog_Block_Product_List
{
   function get_prod_count()
   {
      //unset any saved limits
      Mage::getSingleton('catalog/session')->unsLimitPage();
      return (isset($_REQUEST['limit'])) ? intval($_REQUEST['limit']) : 9;
   }// get_prod_count
   function get_cur_page()
   {
      return (isset($_REQUEST['p'])) ? intval($_REQUEST['p']) : 1;
   }// get_cur_page
   /**
    * Retrieve loaded category collection
    *
    * @return Mage_Eav_Model_Entity_Collection_Abstract
   **/
   protected function _getProductCollection()
   {
        $todayDate  = Mage::app()->getLocale()->date()->toString(Varien_Date::DATETIME_INTERNAL_FORMAT);
        $tomorrow = mktime(0, 0, 0, date('m'), date('d')+1, date('y'));
        $order = (isset($_REQUEST['order'])) ? $_REQUEST['order'] : "sku";
    $dir = (isset($_REQUEST['dir'])) ? $_REQUEST['dir'] : "asc";
        $dateTomorrow = date('m/d/y', $tomorrow);
        $collection = Mage::getResourceModel('catalog/product_collection');
        $collection->setVisibility(Mage::getSingleton('catalog/product_visibility')->getVisibleInCatalogIds());
        $collection = $this->_addProductAttributesAndPrices($collection)
         ->addStoreFilter()
         ->addAttributeToSort($order, $dir)
         ->addAttributeToFilter('special_from_date', array('date' => true, 'to' => $todayDate))
         ->addAttributeToFilter('special_to_date', array('or'=> array(0 => array('date' => true, 'from' => $dateTomorrow), 1 => array('is' => new Zend_Db_Expr('null')))), 'left')
         ->addAttributeToSelect('weight')
         ->setPageSize($this->get_prod_count())
         ->setCurPage($this->get_cur_page());
        $this->setProductCollection($collection);
        return $collection;
   }// _getProductCollection
}// Mage_Catalog_Block_Product_Special
?>

I don't want the products from category 201 on this page. How can I do this? I have tried other scripts, but I think somehow a filter from this code conflicts with it, because I get an error, or it just does not filter the category from the results.

2 REPLIES 2

Re: Create a special price page without products from a certain category

Hi @The Tankgirl,

 

I don't remember if you can set the "has special price" condition but maybe you could explore this module: https://github.com/firegento/firegento-dynamiccategory

 

Maybe this module allows you to create the specific page using a specific attribute.

Re: Create a special price page without products from a certain category

The extension looks nice, but did not exclude the category unfortunately.
I ended up filtering the titles, by adding this to the special-code:


       ->addAttributeToFilter('name', array('nlike' => '%THT%'))

I'm happy with this, because we already had the THT in the titles (It's 'Best before' in dutch), and these were exactly the products we had to filter.