Skip to content

Conversation

@ricardotejedorsanz
Copy link
Collaborator

@ricardotejedorsanz ricardotejedorsanz commented Nov 7, 2025

Add Return Reason Management to Product Taxonomy

This PR introduces support for managing return reasons in the product taxonomy, including commands to add return reasons and associate them with product categories.

New Commands

Add Return Reason

bundle exec ./bin/product_taxonomy add_return_reason NAME DESCRIPTION

Creates a new return reason with the specified name and description, generating appropriate identifiers.

  1. Creates a new return reason with auto-generated identifiers:
    • id: Next available numeric ID
    • friendly_id: Parameterized from name (e.g., "size-too-small")
    • handle: Kebab-case version (e.g., "size-too-small")
  2. Validates uniqueness across all existing return reasons (ID, name, handle, friendly_id)
  3. Appends the new return reason to data/return_reasons.yml
  4. Triggers automatic updates:
    • Regenerates English localizations
    • Updates distribution files (JSON, TXT)
    • Regenerates documentation

Add Return Reasons to Categories

bundle exec ./bin/product_taxonomy add_return_reasons_to_categories RETURN_REASON_FRIENDLY_IDS CATEGORY_IDS

Associates one or more return reasons with one or more product categories. Supports optional inclusion of descendant categories.

  1. Maps specified return reasons to specified categories
  2. Optionally cascades to descendant categories with --include-descendants flag
  3. Validates that all referenced return reasons exist
  4. Auto-sorts return reasons alphabetically with Unknown/Other last
  5. Updates category YAML files with new mappings
  6. Triggers automatic regeneration of:
    • Distribution files (JSON, TXT)
    • Documentation files

Dump Return Reasons

bundle exec ./bin/product_taxonomy dump_return_reasons

Exports all return reasons to a YAML file for persistence.

  1. Loads all return reasons from memory
  2. Serializes them to YAML format using the data serializer
  3. Overwrites data/return_reasons.yml with the current state
  4. Preserves the structure: id, name, handle, friendly_id, description

Features

  • Return Reason Creation: Creates return reasons with auto-generated IDs, friendly IDs, and handles
  • Category Association: Links return reasons to appropriate product categories
  • Hierarchical Support: Option to apply return reasons to all descendant categories
  • Intelligent Sorting: Maintains alphabetical order with special reasons ("unknown", "other") at the end
  • Validation: Prevents duplicate return reasons and ensures data integrity
  • Data Persistence: Automatically updates YAML files and localizations

Implementation Details

  • Follows existing taxonomy command patterns for consistency
  • Includes comprehensive test coverage for all new commands
  • Maintains proper sorting of return reasons within categories
  • Handles whitespace in comma-separated input lists
  • Updates all affected data files automatically

The PR provides a complete solution for managing product return reasons through the CLI, enabling teams to maintain this taxonomy data programmatically.

Copy link
Collaborator Author

ricardotejedorsanz commented Nov 7, 2025

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

@ricardotejedorsanz ricardotejedorsanz marked this pull request as ready for review November 7, 2025 12:21
@KaiKitJeffreyChan KaiKitJeffreyChan changed the base branch from rt/return-reasons-models-and-dist to graphite-base/791 November 10, 2025 20:13
@KaiKitJeffreyChan KaiKitJeffreyChan force-pushed the rt/return-reasons-add-command branch from 45ca2c2 to bffba00 Compare November 10, 2025 20:13
@KaiKitJeffreyChan KaiKitJeffreyChan changed the base branch from graphite-base/791 to rt/return-reasons-sync-localizations November 10, 2025 20:14
@KaiKitJeffreyChan KaiKitJeffreyChan force-pushed the rt/return-reasons-add-command branch from bffba00 to aead00a Compare November 10, 2025 21:18
@KaiKitJeffreyChan KaiKitJeffreyChan force-pushed the rt/return-reasons-sync-localizations branch from 7ac44ab to 6407bfb Compare November 10, 2025 21:18
@KaiKitJeffreyChan KaiKitJeffreyChan changed the title Add CLI command for creating return reasons Add CLI command for return reasons Nov 11, 2025
@KaiKitJeffreyChan KaiKitJeffreyChan force-pushed the rt/return-reasons-sync-localizations branch from 6407bfb to 2a5b30e Compare November 11, 2025 20:17
@KaiKitJeffreyChan KaiKitJeffreyChan force-pushed the rt/return-reasons-add-command branch from 7ef040a to 141afab Compare November 11, 2025 20:17
@jmignac jmignac force-pushed the rt/return-reasons-add-command branch from 141afab to ee04fbd Compare November 12, 2025 15:00
@jmignac jmignac force-pushed the rt/return-reasons-sync-localizations branch 2 times, most recently from 9cab054 to 0cba42e Compare November 12, 2025 15:52
@jmignac jmignac force-pushed the rt/return-reasons-add-command branch from ee04fbd to ebcd6bd Compare November 12, 2025 15:52
@Hetul-Patel-2 Hetul-Patel-2 force-pushed the rt/return-reasons-add-command branch from ebcd6bd to 894327a Compare November 12, 2025 18:14
@jmignac jmignac force-pushed the rt/return-reasons-add-command branch 2 times, most recently from ebcd6bd to 325e803 Compare November 12, 2025 18:29
@jmignac jmignac force-pushed the rt/return-reasons-sync-localizations branch from 0cba42e to 496e3a1 Compare November 12, 2025 18:29
@Hetul-Patel-2 Hetul-Patel-2 force-pushed the rt/return-reasons-add-command branch from 325e803 to 085d693 Compare November 12, 2025 21:55
@KaiKitJeffreyChan KaiKitJeffreyChan force-pushed the rt/return-reasons-add-command branch from 085d693 to b28b2c7 Compare November 13, 2025 21:37
@Hetul-Patel-2 Hetul-Patel-2 force-pushed the rt/return-reasons-add-command branch from b28b2c7 to b6ff8fa Compare November 13, 2025 21:40
@Hetul-Patel-2 Hetul-Patel-2 force-pushed the rt/return-reasons-sync-localizations branch from 09991bd to 95e05cc Compare November 13, 2025 21:40
@KaiKitJeffreyChan KaiKitJeffreyChan force-pushed the rt/return-reasons-add-command branch from b6ff8fa to d158482 Compare November 13, 2025 21:43
@KaiKitJeffreyChan KaiKitJeffreyChan force-pushed the rt/return-reasons-sync-localizations branch from 95e05cc to 09991bd Compare November 13, 2025 21:43
@Hetul-Patel-2 Hetul-Patel-2 force-pushed the rt/return-reasons-sync-localizations branch from 09991bd to 95e05cc Compare November 13, 2025 21:45
@Hetul-Patel-2 Hetul-Patel-2 force-pushed the rt/return-reasons-add-command branch from d158482 to babf7f6 Compare November 13, 2025 21:45
@KaiKitJeffreyChan KaiKitJeffreyChan force-pushed the rt/return-reasons-sync-localizations branch from 95e05cc to 09991bd Compare November 14, 2025 20:02
@KaiKitJeffreyChan KaiKitJeffreyChan force-pushed the rt/return-reasons-add-command branch 2 times, most recently from 544da27 to a5f2a9b Compare November 17, 2025 16:41
@KaiKitJeffreyChan KaiKitJeffreyChan force-pushed the rt/return-reasons-sync-localizations branch from 09991bd to 4f42381 Compare November 17, 2025 16:41
@jmignac jmignac force-pushed the rt/return-reasons-sync-localizations branch from 4f42381 to e71dcc6 Compare November 17, 2025 16:52
@jmignac jmignac force-pushed the rt/return-reasons-add-command branch from a5f2a9b to 86e945d Compare November 17, 2025 16:52
@KaiKitJeffreyChan KaiKitJeffreyChan force-pushed the rt/return-reasons-sync-localizations branch from e71dcc6 to 4f42381 Compare November 17, 2025 19:35
@KaiKitJeffreyChan KaiKitJeffreyChan force-pushed the rt/return-reasons-add-command branch from 86e945d to 65bcbb2 Compare November 17, 2025 19:35
@Hetul-Patel-2 Hetul-Patel-2 self-requested a review November 17, 2025 19:38

Choose a reason for hiding this comment

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

Do we want to separate the create return reasons and dump commands?

Current workflow is that running the create and attach commands will create the return reasons object and will modify the yaml directly. Do we want to separate it so that one command will create it, one command will dump it?

If this follows the existing workflow with categories where creating a category will automatically add it to the yaml then we can discard this feedback.


def execute
add_return_reasons_to_categories!
update_data_files!
Copy link

@Hetul-Patel-2 Hetul-Patel-2 Nov 17, 2025

Choose a reason for hiding this comment

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

Since this attaches the objects and also writes to the yaml, do we want some sort of rollback or atomic transaction where if it fails to write the yaml then it also detaches it from the object?

Attaches the two objects -> writes to yaml
Attaches the two objects -> error writing to yaml -> rollback attaching the objects and signal that command failed

It could also be the case that these operations are something we can confidently say will work and not need to implement this rollback logic.

@Hetul-Patel-2 Hetul-Patel-2 force-pushed the rt/return-reasons-add-command branch from 65bcbb2 to a298db4 Compare November 18, 2025 15:58
@Hetul-Patel-2 Hetul-Patel-2 force-pushed the rt/return-reasons-sync-localizations branch 2 times, most recently from 08cc077 to 8bf62c6 Compare November 18, 2025 19:51
@Hetul-Patel-2 Hetul-Patel-2 force-pushed the rt/return-reasons-add-command branch from a298db4 to 7160261 Compare November 18, 2025 19:51
@KaiKitJeffreyChan KaiKitJeffreyChan force-pushed the rt/return-reasons-add-command branch from 7160261 to 67b8038 Compare November 18, 2025 20:21
@KaiKitJeffreyChan KaiKitJeffreyChan force-pushed the rt/return-reasons-sync-localizations branch from 8bf62c6 to 3c0e3ac Compare November 18, 2025 20:21
- Add add_return_reason_command.rb for creating new return reasons
- Auto-generates identifiers (friendly_id, handle) from name
- Validates uniqueness of IDs, names, handles, friendly_ids
- Triggers automatic updates: localizations, dist files, docs
- Register add_return_reason command in cli.rb
- Add dump_return_reasons_command.rb
- Exports in-memory return reasons to YAML format
- Uses data_serializer for consistent output
- Enables bulk editing workflows
- Register command in cli.rb
- Add add_return_reasons_to_categories_command.rb
- Maps specified return reasons to specified categories
- Validates return reason references
- Auto-sorts alphabetically with Unknown/Other last
- Supports --include-descendants flag for cascade
- Register command in cli.rb
@Hetul-Patel-2 Hetul-Patel-2 force-pushed the rt/return-reasons-sync-localizations branch from 3c0e3ac to f0ee5dd Compare November 19, 2025 20:29
@Hetul-Patel-2 Hetul-Patel-2 force-pushed the rt/return-reasons-add-command branch from 67b8038 to 324fcdc Compare November 19, 2025 20:29
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.

3 participants