Skip to content

Addresses Refactor#111

Merged
duncanmcclean merged 14 commits intomainfrom
addresses
Jan 17, 2026
Merged

Addresses Refactor#111
duncanmcclean merged 14 commits intomainfrom
addresses

Conversation

@duncanmcclean
Copy link
Owner

@duncanmcclean duncanmcclean commented Jan 17, 2026

This pull request changes how addresses are stored.

Previously, every address field was a separate key in the cart/order's data array. Now, addresses are their own arrays, with subkeys for the various fields:

- shipping_name: 'David Hasselhoff'
- shipping_line_1: '742 Evergreen Coast Road'
- shipping_line_2: 'Unit 404'
- shipping_city: 'Los Angeles'
- shipping_postcode: 90001
- shipping_country: USA
- shipping_state: CA
+ shipping_address:
+   name: 'David Hasselhoff'
+   line_1: '742 Evergreen Coast Road'
+   line_2: 'Unit 404'
+   city: 'Los Angeles'
+   postcode: 90001
+   country: USA
+   state: CA

There were two reasons behind this change:

  1. It makes the YAML look more organised 😎
  2. It means we can use a custom fieldtype for addresses behind the scenes

Breaking Changes

This PR introduces a handful of breaking changes. Please review the steps below and update your project accordingly:

  • Addresses in existing carts and orders should be migrated to the new format automatically when updating.
    • If not, run php please updates:run v1.0.0-alpha.15 --package="duncanmcclean/statamic-cargo".
  • If you've published the Packing Slip view, copy the changes from this commit into your project.
  • If you're using the Pre-built Checkout flow, copy the changes from this commit into your project.
  • If you're not using the Pre-built Checkout flow, update your input names, like this:
    • Previously: name="shipping_line_1"
    • Now: name="shipping_address[line_1]"
  • If you're referencing billing or shipping address fields in your templates, update your code to reference the new billing_address and shipping_address arrays, like this:
    • Previously: {{ cart:shipping_line_1 }}
    • Now: {{ cart:shipping_address:line_1 }}
  • If you're getting/setting address fields manually in PHP, you'll need to refactor your code to work with the new array format.
  • If you're listening to the OrderBlueprintFound event to modify address fields, you should use the new fields hook on the fieldtype:
    use DuncanMcClean\Cargo\Fieldtypes\Address;
    
    Address::hook('fields', function ($payload, $next) {
        $payload->fields = array_filter($payload->fields, function ($field) {
            return $field['handle'] !== 'state';
        });
    
        return $next($payload);
    });

@duncanmcclean duncanmcclean changed the title Refactor Addresses Addresses Refactor Jan 17, 2026
@marcorieser
Copy link
Contributor

Add a hook for Marco 😂❤️

@duncanmcclean duncanmcclean marked this pull request as ready for review January 17, 2026 15:56
@duncanmcclean duncanmcclean merged commit d838f6e into main Jan 17, 2026
13 checks passed
@duncanmcclean duncanmcclean deleted the addresses branch January 17, 2026 15:56
@github-actions
Copy link

Released as part of v1.0.0-alpha.15.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants