(For those with CE versions of Magento, if you can help me do this for Catalog Price Rules or Shopping Cart Price Rules that might be good enough.)

I'm looking to extend the EE Target Rules module so that I can specify the category level as a condition. Meaning, right now you can do this:

Products to Display:

Product Category is one of - the Child of the Matched Product Categories

I want to be able to add this

Product Category is equal to or lower than - level 3

Anyone have any idea how I can do this?


You need to define a new attribute 'category_level' to be available at the form.

Then, in the product object, you need to add the category level somehow. After this magento will use comparison function defined in parent classes and you are done!

Now more detailed example, based on one of our extensions:

 * @copyright   Copyright (c) 2009-14 Amasty.com
 * @package Special Promotions
class Amasty_Rules_Model_SalesRule_Rule_Condition_Product extends

    protected function _addSpecialAttributes(array &$attributes)
        $attributes['category_level'] = Mage::helper('amrules')->__('Category Level');

     * Validate Product Rule Condition
     * @param Varien_Object $object
     * @return bool
    public function validate(Varien_Object $object)
        $product = false;
        if ($object->getProduct() instanceof Mage_Catalog_Model_Product) {
            $product = $object->getProduct();
        else {
            $product = Mage::getModel('catalog/product')

        // TODO find the category or categories level here


        return parent::validate($object);
  • Amasty, I'm talking particularly about the 'level' attribute inherent in all categories. Magento can compare that product X and product Y are both assigned to the same category, but if they are both assigned to A > B > C > D, I want to be able to say "only match by category if the category is of level 2 or greater. So a product with category A > B > F wouldn't match because A and B are ignored because their level is too high. – Tyler V. Jul 30 '14 at 23:14
  • Tyler, you can implement this logic in the above mentioned class, instead of //todo placeholder. Once you have the product object, you can get it's categories – Amasty Jul 31 '14 at 20:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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