# ho-nl/magento2-reachdigital_categoryattributededuplication

`composer require ho-nl/magento2-reachdigital_categoryattributededuplication`

Canonical URL: https://packagento.com/ho-nl/magento2-reachdigital_categoryattributededuplication

## At a glance

- **Vendor**: ho-nl (https://packagento.com/ho-nl.md)
- **Latest version**: 1.0.0 — released 2026-01-09
- **Pricing**: Free
- **Package type**: Magento 2 module
- **Status**: active, accepting new buyers

## Installation

Packagento is licence-gated, so even free packages need a licence on a project before Composer can resolve them.

1. **Sign in or create an account** at https://packagento.com/customer/account/.

2. **Add the package to your account.** Open https://packagento.com/ho-nl/magento2-reachdigital_categoryattributededuplication and complete the free checkout. A licence is minted automatically.

3. **Create or pick a project, then activate the licence on it.**
   - Projects represent the Magento installs you deploy to. Manage them at https://packagento.com/projects/.
   - Activate the new licence on the project you'll deploy this package to. Activation is what generates the Composer credentials scoped to that project.

4. **Add the project credentials to your Magento codebase.**

   Grab the project's public + private key from https://packagento.com/projects/ (open the project, then its Credentials tab), and add them to `auth.json`:

   ```json
   {
     "http-basic": {
       "packagento.com": {
         "username": "ppk_live_...",
         "password": "psk_live_..."
       }
     }
   }
   ```

   Add the Packagento Composer repository to `composer.json`:

   ```json
   {
     "repositories": [
       { "type": "composer", "url": "https://packagento.com" }
     ]
   }
   ```

5. **Install and apply.**

   ```bash
   composer require ho-nl/magento2-reachdigital_categoryattributededuplication:*
   bin/magento setup:upgrade
   bin/magento setup:di:compile
   bin/magento cache:flush
   ```

## README

Removes duplicate store-specific category attribute values that are identical to global
(store_id=0) values.

### Background

> **Q:** Do you know of any known issue or bug in Magento 2.4.x where category attribute values are
> written to store-scope (without this intentionally being done by an admin user)?
>
> **A:** Yes, this is a **well-known and long-standing issue** in Magento 2.
>
> The main culprit: When an admin user edits a category while viewing a specific store scope (not
> "All Store Views"), Magento tends to save **all** attribute values to that store scope, even if:
> - The values weren't actually changed
> - The "Use Default Value" checkbox is checked
>
> This happens because the category save controller/processor doesn't properly filter out unchanged
> values or respect the `use_default` flags in certain scenarios. Over time, this leads to massive
> accumulation of store-scoped rows that are identical to the global values.
>
> **Common triggers:**
> 1. Simply opening a category in a store view and clicking Save
> 2. Mass actions on categories
> 3. Programmatic saves that don't explicitly set `store_id = 0`
> 4. Import processes that don't handle scope correctly
>
> **Related GitHub issues:**
> - https://github.com/magento/magento2/issues/13743

This module provides automated cleanup of these duplicate values.

### Features

- Deduplicates store-specific category attribute values that match global values
- Configurable triggers: after category save (observer) and/or via cron job
- Console command for manual execution
- Dry-run mode to preview changes without deleting data
- Verbose logging option for detailed audit trail
- Configurable attribute exclusion list
- Separate log file: `var/log/category_attribute_deduplication.log`

### Configuration

Navigate to **Stores > Configuration > Reach Digital > Category Attribute Deduplication**

| Setting                    | Description                                               | Default |
|----------------------------|-----------------------------------------------------------|---------|
| Enable After Category Save | Run deduplication automatically after each category save  | No      |
| Enable Cron Job            | Run deduplication for all categories daily at 3:00 AM     | No      |
| Dry Run Mode               | Only log what would be deleted, without actually deleting | Yes     |
| Verbose Logging            | Log detailed information about each duplicate found       | No      |
| Excluded Attribute Codes   | Additional attributes to exclude (comma-separated)        | (empty) |

**Note:** `url_path` is always excluded from deduplication regardless of configuration.

### Console Command

The console command always runs in dry-run mode by default (ignores config setting).

```bash
## Dry-run for all categories (default)
bin/magento reach:category:deduplicate-attributes

## Actually delete duplicates
bin/magento reach:category:deduplicate-attributes --apply

## Process specific category (dry-run)
bin/magento reach:category:deduplicate-attributes --category-id=123

## Process specific category and apply changes
bin/magento reach:category:deduplicate-attributes --category-id=123 --apply
```

### Logging

All actions are logged to `var/log/category_attribute_deduplication.log`.

**Non-verbose mode:** Logs entity IDs and attribute codes with counts.
```
[DRY-RUN] name: 5 duplicates in entity_ids: 10, 15, 20, 25, 30
```

**Verbose mode:** Logs detailed information about each duplicate.
```
[DRY-RUN] Duplicate: entity_id=10, store_id=1, attribute=name, value_id=123, ...
```

### Installation

```bash
bin/magento module:enable ReachDigital_CategoryAttributeDeduplication
bin/magento setup:upgrade
bin/magento cache:flush
```

---

### Prompt

```
Implement a Magento extension under app/code that can deduplicate these store-specific values for
categories.

Some requirements:
- Needs to have a logger that writes everything it does to its own separate log file. Maybe a
  verbose mode (behind config) that logs literally everything, and a shorter mode where only
  entity_ids along with attribute codes are logged?
- Should exclude url_path attribute. If you know of any other attributes that should be excluded,
  let me know.
- Needs to have a dry-run mode where it only logs what it /would/ do
- Needs to be triggered for a single category after saving (use the right event though, do we need
  the commit after event?)
- Needs to be triggered for all categories from a cronjob and console command
- Add configs to enable or disable either cronjob and observer trigger (i.e. separate configs).
  Leave both disabled by default.

Please include this prompt in the module README and keep it up to date as I provide more
instructions

---

Can you remove the exclusion of url_key? I think it should be okay to deduplicate this - if it's
the same at global and store level, then it must still remain consistent with the url_rewrite
table. If it's not, then this was already an issue, so I don't think deduplicating makes it worse
(or better).

---

Can you change the console command name so that is prefixed with reach-digital?

---

Adjust line-lengths in the README to break at 100 chars

---

Can you move the adminhtml configs to their own section and put them under the Reach Digital tab?
Don't forget to update default value paths and the constants in the code etc.

---

Can you change the console command prefix to `reach`? This is the one we most commonly use

---

Make the console command completely ignore the dry-run config, and make it use dry-run by default.
Invert the existing --dry-run option so can apply deduplication after checking with the default
dry-run mode
```

## Recent Versions

| Version | Released |
|---|---|
| 1.0.0 | 2026-01-09 |

## Dependencies

### Require

| Package | Constraint |
|---|---|
| magento/module-catalog | * |
| php | >=8.1 |

## Quality

Latest release (1.0.0) fails the Packagento QA pipeline. Verdicts below are per-cell (Magento line × PHP version) for the matrixed tools, and run-once for the static / security tiers.


### Compatibility

Each Magento line is installed on its supported PHP versions, then the module is built (DI compile + static-content deploy). Cells show passed / failed / untested; staircase gaps render as `–`.

| Magento | PHP 8.2 | PHP 8.3 | PHP 8.4 | PHP 8.5 |
|---|---|---|---|---|
| 2.4.7 | Pass | Pass | – | – |
| 2.4.8 | – | Pass | Pass | – |
| 2.4.9 | – | – | not tested | Pass |


### Code Quality

Advisory checks against the module's source. Never affect the Compatibility verdict — a phpcs finding can't make a module incompatible.

#### Static Analysis

Coding standards (phpcs), mess detection (phpmd), copy-pasted code (cpd), PHP cross-version compatibility, composer.json validity. Each runs once for the whole module.

| Tool | Status | Findings | Summary |
|---|---|---|---|
| PHPCS | Warning | 4 | 4 warnings (ruleset: Magento2) |
| PHPMD | Warning | 2 | 2 rule violations (CyclomaticComplexity:1, NPathComplexity:1) |
| Cpd | Pass | 0 |  |
| Composer validate | Info | 1 | valid; 1 advisory note (composer validate --strict) |

#### PHPStan

Type-checks the module against a real Magento install. Re-runs per Magento + PHP version because resolvable symbols differ between releases.

| Magento | PHP 8.2 | PHP 8.3 | PHP 8.4 | PHP 8.5 |
|---|---|---|---|---|
| 2.4.7 | 1 | 1 | – | – |
| 2.4.8 | – | 1 | 1 | – |
| 2.4.9 | – | – | 1 | 1 |


### Tests

Unit and integration suites run per Magento + PHP cell. Test failures speak to the module's behaviour, not its compatibility with a line, so they're reported here separately.

#### Unit Tests

| Magento | PHP 8.2 | PHP 8.3 | PHP 8.4 | PHP 8.5 |
|---|---|---|---|---|
| 2.4.7 | N/A | N/A | – | – |
| 2.4.8 | – | N/A | N/A | – |
| 2.4.9 | – | – | N/A | N/A |

#### Integration Tests

| Magento | PHP 8.2 | PHP 8.3 | PHP 8.4 | PHP 8.5 |
|---|---|---|---|---|
| 2.4.7 | N/A | N/A | – | – |
| 2.4.8 | – | N/A | N/A | – |
| 2.4.9 | – | – | N/A | N/A |


### Security

Dependency-advisory audit (composer audit) plus a source malware scan. A malware detection fails the version outright.

| Tool | Status | Findings | Summary |
|---|---|---|---|
| Composer audit | Pass | 0 |  |
| Malware scan | Pass | 0 |  |

## Licence and pricing

Free. A licence is still minted on checkout and bound to your project for Composer access — no payment step.

Refundable within 14 days of first purchase via https://packagento.com/account/refunds/.

## Install via Claude Code or any MCP client

The Packagento MCP server can run the licence + project + Composer steps above in one tool call:

```
purchase_and_install_packages(
  composer_names=["ho-nl/magento2-reachdigital_categoryattributededuplication"],
  project_id="proj_xxx"
)
```

This handles cart, checkout, licence minting, project activation, and writes auth.json credentials. Connect a client with `claude mcp add packagento https://mcp.packagento.com`. Full setup at https://packagento.com/docs/mcp-setup.

## Vendor

ho-nl is a Magento 2 vendor on Packagento. See https://packagento.com/ho-nl.md for their full catalogue.

