Implementing Deep Copy for Bundle Duplication in Shopify Apps

Merchants often need to create multiple bundles with similar configurations. Rebuilding every step, rule, and design from scratch can take unnecessary time.
A duplication feature solves this problem by copying an existing configuration and creating a separate draft that can be edited independently.
However, implementing duplication correctly requires more than copying the main database record.
Why deep copying matters
Consider a bundle that contains:
- A main bundle record
- Multiple steps
- Several configuration rules
- Design settings
If an application copies only the main bundle record, the new bundle may not contain the configuration required to work as expected.
A deep copy needs to include the related records that define the bundle.
How bundle duplication works
Cruxtab Bundle Builder implements duplication in bundleDuplicate.server.js.
The application creates a deep copy of:
- The original bundle
- Its steps
- Its rules
- Its design
The duplicated bundle is saved as a draft.
This gives the merchant a separate starting point without immediately making the duplicate live.
Why the duplicate should be independent
A duplicated bundle should not accidentally share mutable child records with the original.
For example, editing a rule in the duplicate should not unintentionally modify the original bundle's rule.
A deep-copy operation should therefore create new related records and associate them with the new bundle.
Saving the duplicate as a draft
Saving the duplicated bundle as a draft is an important lifecycle decision.
It allows merchants to:
- Review the copied configuration
- Change bundle steps
- Adjust rules
- Update the design
- Validate the configuration before publishing
The original bundle remains separate from this editing process.
Engineering considerations
A robust duplication implementation should consider:
Relationship mapping: Every copied step, rule, and design record must reference the new bundle rather than the original.
Unique identifiers: New database records need their own identifiers.
Selective copying: Some values may be suitable for copying, while identifiers or external references may need to be regenerated or reviewed.
Consistency: If duplication fails halfway through, the application should avoid leaving an incomplete draft.
Testing: Verify that changes to the duplicate do not alter the original and that all expected related records are present.
Conclusion
Deep copying makes bundle creation more efficient while preserving configuration structure. Cruxtab Bundle Builder duplicates the bundle, its steps, rules, and design, then saves the result as a draft for further editing.
Explore Cruxtab Bundle Builder & BYOB.
Comments
Join the discussionNo comments yet. Be the first to comment.




