Skip to content

Conversation

@ricardotejedorsanz
Copy link
Collaborator

@ricardotejedorsanz ricardotejedorsanz commented Nov 7, 2025

This PR implements the Ruby models and serialization layer for return reasons, integrating them into the existing taxonomy distribution pipeline. It also updates the category model to support return reasons. This enables both return reasons and categories (with their return reason mappings) to be published in distribution formats.

What's included:

  1. Return Reason Model: ReturnReason Ruby class with validation, following the same patterns as Attribute and Category

    • Loads from data/return_reasons.yml
    • Validates uniqueness of IDs, names, handles, and friendly_ids
    • Provides lookup methods (find_by!, all)
  2. Return Reason Distribution Serializers: Generate public-facing output files

    • json_serializer.rb: Creates dist/en/return_reasons.json with GIDs, names, handles, descriptions
    • txt_serializer.rb: Creates dist/en/return_reasons.txt in human-readable format
  3. Return Reason Data Serializers: Internal data management

    • data_serializer.rb: Exports to YAML format for data dumps
    • localizations_serializer.rb: Syncs English localizations from data files
  4. Category Model Updates: Enhanced to load and validate return_reasons from YAML

    • category.rb: Loads return_reasons field, returns ReturnReason objects
    • Validates all referenced return reasons exist
  5. Category Serializer Updates: Include return reasons in distribution outputs

    • category/data/data_serializer.rb: Ensures all categories have return_reasons: [] field (even if empty)
    • category/dist/json_serializer.rb: Includes return reasons in categories.json and taxonomy.json
  6. Pipeline Integration: Updates generate_dist_command.rb to include return reasons in the build process

Design decisions:

  • GID format: gid://shopify/ReturnReasonDefinition/{id} (see PR 1 for GID naming discussion and rationale)
  • Mirrored serializer structure from attributes for consistency
  • Alphabetical sorting with special handling: "Unknown" second-to-last, "Other" last
  • Distribution files follow existing taxonomy patterns (JSON + TXT formats)

Generated outputs:

  • dist/en/return_reasons.json: 359 return reasons with full metadata
  • dist/en/return_reasons.txt: Simple GID : Name format for quick reference
  • dist/en/categories.json: Now includes return_reasons array for each category
  • dist/en/taxonomy.json: Regenerated with updated categories

Review notes:

  • Return reason model validation mirrors Attribute validation patterns
  • Category model changes enable loading return_reasons from YAML (added in PR 1)
  • Serializers are structured to support future multi-locale expansion
  • Changes to dev/lib/product_taxonomy.rb add necessary requires for new classes
  • This PR enables bundle exec ./bin/product_taxonomy dist to generate return reasons files
  • Large dist files (categories.json, taxonomy.json) are regenerated with return reasons included
  • Test coverage: Unit tests for models and serializers will be added in follow-up PRs

Files to Include

  • dev/lib/product_taxonomy/models/return_reason.rb
  • dev/lib/product_taxonomy/models/serializers/return_reason/dist/json_serializer.rb
  • dev/lib/product_taxonomy/models/serializers/return_reason/dist/txt_serializer.rb
  • dev/lib/product_taxonomy/models/serializers/return_reason/data/data_serializer.rb
  • dev/lib/product_taxonomy/models/serializers/return_reason/data/localizations_serializer.rb
  • dev/lib/product_taxonomy/models/category.rb (changes to support return_reasons)
  • dev/lib/product_taxonomy/models/serializers/category/data/data_serializer.rb (ensures return_reasons field in YAML)
  • dev/lib/product_taxonomy/models/serializers/category/dist/json_serializer.rb (includes return_reasons in output)
  • dev/lib/product_taxonomy/commands/generate_dist_command.rb
  • dev/lib/product_taxonomy.rb (changes to load return reasons)
  • dist/en/return_reasons.json
  • dist/en/return_reasons.txt
  • dist/en/categories.json (regenerated with return_reasons)
  • dist/en/taxonomy.json (regenerated with return_reasons)

Dependencies

  • PR 1 (requires data files)

Review Focus

  • Return reason implementation: Model, validation, and serializers
  • Category model enhancements: Loading and validating return_reasons from YAML
  • Distribution integration: Both new files (return_reasons.*) and updated files (categories.json, taxonomy.json)
  • Pipeline integration: Updates to generate_dist command
  • Regenerated files: Large JSON files expected (categories.json, taxonomy.json)

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.

Copy link

@jmignac jmignac left a comment

Choose a reason for hiding this comment

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

Added some comments - on top of missing unit tests

@KaiKitJeffreyChan KaiKitJeffreyChan force-pushed the rt/return-reasons-data-and-mappings branch from a9ab689 to fbeff51 Compare November 11, 2025 20:17
@KaiKitJeffreyChan KaiKitJeffreyChan force-pushed the rt/return-reasons-models-and-dist branch from 0bd1887 to b0ea0e1 Compare November 11, 2025 20:17
@jmignac jmignac force-pushed the rt/return-reasons-models-and-dist branch from b0ea0e1 to e95fa02 Compare November 12, 2025 15:00
@jmignac jmignac force-pushed the rt/return-reasons-data-and-mappings branch from fbeff51 to e9e183e Compare November 12, 2025 15:00
@jmignac jmignac force-pushed the rt/return-reasons-models-and-dist branch from e95fa02 to 1c7d788 Compare November 12, 2025 15:52
@KaiKitJeffreyChan KaiKitJeffreyChan force-pushed the rt/return-reasons-data-and-mappings branch from e9e183e to bf3d52a Compare November 13, 2025 21:37
@KaiKitJeffreyChan KaiKitJeffreyChan force-pushed the rt/return-reasons-models-and-dist branch 2 times, most recently from 0c9ee93 to ed70e6b Compare November 17, 2025 16:41
@KaiKitJeffreyChan KaiKitJeffreyChan force-pushed the rt/return-reasons-data-and-mappings branch from bf3d52a to 88ee4c5 Compare November 17, 2025 16:41
@Hetul-Patel-2 Hetul-Patel-2 force-pushed the rt/return-reasons-models-and-dist branch from ed70e6b to f33f738 Compare November 18, 2025 19:51
- Add ReturnReason Ruby model with validation
- Add return reason dist serializers (JSON, TXT)
- Add return reason data serializers (YAML, localizations)
- Update Category model to load and validate return_reasons
- Update category serializers to include return_reasons field
- Integrate return reasons into generate_dist command
- Generate dist files: return_reasons.json, return_reasons.txt
- Regenerate categories.json and taxonomy.json with return_reasons
@KaiKitJeffreyChan KaiKitJeffreyChan force-pushed the rt/return-reasons-data-and-mappings branch from 88ee4c5 to ebcac4b Compare November 18, 2025 20:21
@KaiKitJeffreyChan KaiKitJeffreyChan force-pushed the rt/return-reasons-models-and-dist branch from f33f738 to 6f43dd6 Compare November 18, 2025 20:21
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