4

For example I have:

Mobile -> Apple
Mobile -> HTC
Mobile -> Nokia

I want to give 5% discount for all product in these categories.

Is there any way to do it without creating a catalog price rule for each of them without explicit list?

1
  • 1
    Maybe it works, if the parent category is anchor. If this doesn't work I don't see any option beside a list of categories, except using any other thing to identify the products, like a sku(prefix/suffix), special attribute, whatever... Jan 13, 2014 at 12:46

3 Answers 3

1

If it would be acceptable to write a single rule then you can simple do this using the condition:

Is One Of

This will allow you to select multiple options for a single product attribute. In this case you can selected more than one category.

The following screenshot should help:Is One Of Condition

4
  • Yes it is posible. But before Tim edited my post, my question is: "Is there any way to do it without that I enumerated them all?" You post is way but too hard if i have about 1 000 categories.
    – MiMo
    Oct 15, 2013 at 7:08
  • @MiMo, sorry, fixed the initial question.
    – user487772
    Oct 15, 2013 at 7:11
  • Ah I see, I did think it was a bit easy :) Oct 15, 2013 at 7:12
  • 2
    Couldn't you add the products to the parent category "mobile" as well and then use one rule for this category? Nov 14, 2013 at 8:32
1

Here is a dirty hack for it, but it should point you in the right direction to do this cleaner (i.e. in its own extension).

Add this piece of code in Mage_Rule_Model_Abstract::_beforeSave before the // Serialize conditions part (around line 105);

$totalSubCategoryIds = array();
$conditions = $this->getConditions();
foreach($conditions['conditions'] as &$condition) {
    if($condition->getAttribute() == 'category_ids') {
        $categoryIds = explode(',', $condition->getValue());
        if($categoryIds) {
            $categoryIds = array_map('trim', $categoryIds);
            if(count($categoryIds)) {
                foreach ($categoryIds as $categoryId) {
                    $category = Mage::getModel('catalog/category')->load($categoryId);
                    if ($category->getIsAnchor()) {
                        $subCategoryIds = $category->getResource()->getChildren($category, true);
                        $totalSubCategoryIds = array_merge($totalSubCategoryIds,$subCategoryIds);
                    }
                }
            }
        }
        $totalCategoryIds = array_merge($categoryIds, array_unique($totalSubCategoryIds));
        $condition->setValue(implode(',', $totalCategoryIds));
    }
}

It will automatically search for all subcategories for all of the chosen categories and it will add those to the list, so you won't have to click all of them (particularly handy when you have a lot of subcategories).

0

You can alter the method Mage_CatalogRule_Model_Rule_Condition_Product::validate which is in charge of checking the rule.

With a nice rewrite you can do :

public function validate(Varien_Object $object)
{
    if ('category_ids' == $$this->getAttribute()) {
        return $this->validateAttribute($object->getResource()->getCategoryIdsWithAnchors($object));
    }

    return parent::$this->validate($object);
}

This site is temporarily in read-only mode and not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .