1

On my site I have a category with adult products. When you click on it you going to have a popup that says you must be 18 to enter, everything is good there, but here's my problem:

Every time I update the adult products they are showing up on the "new in the store" block. How can I filter that category, so it never shows up on this block on the home page?

I’m using Magento 1.9.2

1 Answer 1

0

Good question, it's not possible by default but you can achieve it with a small custom module.

I assume that you use the "new products" widget with the "All products" option, that shows recently added products. Otherwise the solution would be trivial, just don't set the "new from" and "new to" attributes for adult products.

You could create your own widget based on the default one, but to tailor your specific use case, it's enough to rewrite the existing one so that it always filters the category.

  1. create a new module (if you don't know how to start, there are plenty tutorials)
  2. create a new block inside your module, like this:

    class Stack_Adult_Block_Widget_New extends Mage_Catalog_Block_Product_Widget_New
    {
        const ADULT_CATEGORY_ID = 42;
        protected function _getProductCollection()
        {
            $collection = parent::_getProductCollection();
            $collection->getSelect()->join(array('cats' => 'catalog_category_product'), 'cats.product_id = e.entity_id');
            $collection->getSelect()->where('cats.category_id != ?', self::ADULT_CATEGORY_ID);
        }
    }
    
  3. register that block as rewrite for catalog/product_widget_new in your module's config.xml:

    <global>
         <blocks>
             <rewrite>
                 <catalog>
                     <product_widget_new>Stack_Adult_Block_Widget_New</product_widget_new>
                 </catalog>
             </rewrite>
         </blocks>
    </global>
    

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.