0

How do I assign a category to new products automatically?

  • How you created the products by programatically or by admin side? – saravanavelu Sep 16 '15 at 7:17
  • @saravanavelu if this possible for admin side or pragmatically – Arvind Jha Sep 16 '15 at 7:21
  • you have to create custom module for it. – Arunendra Sep 16 '15 at 7:57
0

you can create an observer for the event catalog_product_save_before that can look like this:

public function setDefaultCategory($observer)
{
    $product = $observer->getEvent()->getProduct();
    //if the product is not new do nothing
    if ($product->getId()) {
         return $this;
    }
    $categoryId = your category id here
    $categoryIds = $product->getCategoryIds(); 
    if (!is_array($categoryIds)) {
        $categoryIds = array();
    }
    if (!in_array($categoryId, $categoryIds)) {
        $categoryIds[] = $categoryId;
        $product->setCategoryIds($categoryIds);
    }
}
| improve this answer | |
2

There's a module that can do this: http://www.proxiblue.com.au/premium-modules/magento-dynamic-category-products.html

It automatically assigns products to a category based on certain conditions you define in the category. I use it on quite a few websites and have a positive experience with it.

| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.