Skip to content

Conversation

@ricardotejedorsanz
Copy link
Collaborator

Add category comparison command

This PR adds a new CLI command to compare category changes between different versions of the taxonomy.

What it does

  • Compares full_names.yml from a specific version folder against dist/en/categories.txt
  • Detects three types of changes:
    • Additions: New categories in the current taxonomy
    • Archived: Categories that were removed/archived
    • Renames: Categories with the same ID but different names
  • Outputs results to a timestamped CSV file in the exports/ folder

Usage

# Basic usage
bundle exec ruby -I lib bin/product_taxonomy compare_categories 2025-03

# With custom output directory
bundle exec ruby -I lib bin/product_taxonomy compare_categories 2024-10 --output-dir exports

# Show help
bundle exec ruby -I lib bin/product_taxonomy help compare_categories

Files changed

  • Added dev/lib/product_taxonomy/commands/compare_categories_command.rb
  • Updated CLI to include the new command
  • Added exports/ folder to .gitignore

Example output

The command generates CSV files with columns: type, id, old_name, new_name

image

Copy link
Collaborator

@danielpgross danielpgross left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approach looks good overall. What stood out:

  • this approach can't recognize relocations, it will report them as archive + add new category. Maybe that's okay, but good to be aware of.
  • Did you consider using mappings for this? They were built to capture basically this same information and are better because they capture relocations

We would also need unit tests added before merging

end

desc "compare_categories VERSION_FOLDER", "Compare category changes between full_names.yml and categories.txt"
option :output_dir, type: :string, default: "exports", desc: "Output directory for CSV file"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be more flexible and idiomatic to accept the full output path of the CSV file (filename included), not just output dir

AddValueCommand.new(options.merge(name:, attribute_friendly_id:)).run
end

desc "compare_categories VERSION_FOLDER", "Compare category changes between full_names.yml and categories.txt"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can make the description clearer, maybe something like this:

Suggested change
desc "compare_categories VERSION_FOLDER", "Compare category changes between full_names.yml and categories.txt"
desc "compare_categories VERSION_FOLDER", "Generate a CSV report showing category changes between the current taxonomy and Shopify taxonomy VERSION"


desc "compare_categories VERSION_FOLDER", "Compare category changes between full_names.yml and categories.txt"
option :output_dir, type: :string, default: "exports", desc: "Output directory for CSV file"
def compare_categories(version_folder)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find version_folder confusing here, isn't it just the version?

Suggested change
def compare_categories(version_folder)
def compare_categories(version)

Comment on lines +6 to +8

# Ignore exports folder
/exports
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to add an exports folder, the user can choose to export the CSV to wherever they want. Let's remove this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants