---
title: "How to Get All Active Catalog Rules Collection using Root Script in Magento 2?"
url: "https://magecomp.com/blog/get-all-active-catalog-rules-collection-using-root-script-magento-2/"
date: "2023-11-10T13:42:51+00:00"
modified: "2025-02-13T04:44:00+00:00"
author:
  name: "Dhiren Vasoya"
  url: "https://magecomp.com/"
categories:
  - "How To"
  - "Magento 2"
word_count: 308
reading_time: "2 min read"
summary: "Hello Magento Friends,"
description: "Learn How to Get All Active Catalog Rules Collection using Root Script in Magento 2"
keywords: "How To, Magento 2"
language: "en"
schema_type: "Article"
related_posts:
  - title: "How to Add a Column to Tier Price in Magento 2 Admin?"
    url: "https://magecomp.com/blog/add-column-to-tier-price-magento-2-admin/"
  - title: "How to Programmatically Export CSV File Category Name with Parent Category Name using Root Script in Magento 2?"
    url: "https://magecomp.com/blog/programmatically-export-csv-file-category-name-with-parent-category-name-using-root-script-magento-2/"
  - title: "Magento 2: Regenerate Catalog Product Cache Images Programmatically"
    url: "https://magecomp.com/blog/magento-2-regenerate-catalog-product-cache-images-programmatically/"
---

# How to Get All Active Catalog Rules Collection using Root Script in Magento 2?

_Published: November 10, 2023_  
_Author: Dhiren Vasoya_  

![How to Get All Active Catalog Rules Collection using Root Script in Magento 2](https://magecomp.com/blog/wp-content/uploads/2023/11/How-to-Get-All-Active-Catalog-Rules-Collection-using-Root-Script-in-Magento-2-1024x512.webp)

**Hello Magento Friends,**

In today’s blog, I will explain How to Get All Active Catalog Rules Collection using Root Script in Magento 2.
[![Magento Malware Removal](https://magecomp.com/blog/wp-content/uploads/2025/02/Magento-Malware-Removal-CTA-3.webp)](https://magecomp.com/magento-malware-removal.html)

Magento 2, a powerful and versatile e-commerce platform, allows you to manage and apply catalog rules to control the pricing and visibility of products on your online store. Learn – [**How to Create a Catalog Price Rule in Magento 2**](https://magecomp.com/blog/create-a-catalog-price-rule-magento-2/).
If you need to retrieve all active catalog rules programmatically, you can create a root script to fetch and display this information. In this blog post, we’ll guide you through the process step by step.
## Steps to Get All Active Catalog Rules Collection using Root Script in Magento 2:
**Step 1:** Create **CatalogruleCollection.php** file in the Magento root path and then add the below code.
```
<?php

use MagentoFrameworkAppInterface;

try {
   require __DIR__ . '/../app/bootstrap.php';
} catch (Exception $e) {
    echo 'Autoload error: ' . $e->getMessage();
    exit(1);
}

try
{
 	$bootstrap = MagentoFrameworkAppBootstrap::create(BP, $_SERVER);
	$objectManager = $bootstrap->getObjectManager();
	$appState = $objectManager->get('MagentoFrameworkAppState');
	$appState->setAreaCode('frontend');

	$objectManager = MagentoFrameworkAppObjectManager::getInstance();
	$ruleCollectionFactory = $objectManager->create('MagentoCatalogRuleModelResourceModelRuleCollectionFactory')->create();
	$catalogActiveRule = $ruleCollectionFactory->addFieldToFilter('is_active', 1);
        foreach($catalogActiveRule as $rule) {
            echo "";
            print_r($rule ->getData());
            echo "";
	}
  }

catch(Exception $e){
    print_r($e->getMessage());
}
```

[![Magento 2 Speed & Performance Optimization Services](https://magecomp.com/blog/wp-content/uploads/2025/02/Magento-2-Speed-Performance-Optimization-Services-CTA-3.webp)](https://magecomp.com/magento-performance-optimization.html)

**Step 2:** After adding the above code, run the URL below to check whether the Catalog Rules Data was retrieved.
[https://yourdomain/pub/CatalogruleCollection.php/](https://yourdomain/pub/CatalogruleCollection.php/)
## Conclusion:
Creating a root script to retrieve all active catalog rules in Magento 2 is a straightforward process. This script provides a starting point, and you can customize it based on your specific requirements. Understanding the structure of the script and the Magento 2 components involved will empower you to perform more advanced operations in your e-commerce endeavors.
[![hyva theme development](https://magecomp.com/blog/wp-content/uploads/2025/02/hyva-theme-development-CTA-3.webp)](https://magecomp.com/services/hyva-theme-development/)

**Happy Coding!**


---

_View the original post at: [https://magecomp.com/blog/get-all-active-catalog-rules-collection-using-root-script-magento-2/](https://magecomp.com/blog/get-all-active-catalog-rules-collection-using-root-script-magento-2/)_  
_Served as markdown by [Third Audience](https://github.com/third-audience) v3.5.3_  
_Generated: 2026-08-21 18:31:06 UTC_  
