Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Recommended the API over a decorator for relaxing address rules

Damian Legawiec5582976d96e3
diff --git a/docs/developer/customization/validations.mdx b/docs/developer/customization/validations.mdx
index 5383e6ed89..7e396f7cdd 100644
--- a/docs/developer/customization/validations.mdx
+++ b/docs/developer/customization/validations.mdx
@@ -52,27 +52,6 @@ Both cart keys appear above because adding to a cart and setting a quantity are
different flows. See [Services & Workflows](/developer/customization/workflows)
for the full hook list.
-## Adding a rule to a model
-
-For rules about the shape of a record, a decorator is the supported route:
-
-```ruby
-# app/models/spree/product_decorator.rb
-module MyStore
- module ProductDecorator
- def self.prepended(base)
- base.validates :external_id, presence: true, uniqueness: true
- end
- end
-end
-
-Spree::Product.prepend(MyStore::ProductDecorator)
-```
-
-Decorators couple you to Spree internals, so prefer a hook when the rule is
-really about an operation. See
-[Decorators](/developer/customization/decorators).
-
## Relaxing a rule Spree ships
Never call `clear_validators!` — it wipes every validation on the model,
@@ -113,17 +92,6 @@ curl -X PATCH 'https://api.mystore.com/api/v3/admin/store' \
is API-only for now.
</Note>
-### Changing when a rule applies
-
-Most conditional rules on an address are gated on a predicate — `require_name?`,
-`require_street?`, `require_postal_code?`, `require_phone?` and
-`require_company?`. Overriding one changes *when* the rule applies without
-removing it, which is safer than dropping the validation outright.
-
-This is the one case here that needs Ruby. See
-[decorators](/developer/customization/decorators) for how to override a model
-method.
-
### The address validator registry
Address rules are regional and business-specific, so addresses carry a registry
diff --git a/docs/docs.json b/docs/docs.json
index 1dc21c627b..4ca6d08633 100644
--- a/docs/docs.json
+++ b/docs/docs.json
@@ -882,12 +882,12 @@
"developer/customization/configuration",
"developer/customization/workflows",
"developer/customization/validations",
+ "developer/customization/checkout",
"developer/customization/dependencies",
+ "developer/customization/api",
"developer/customization/model-preferences",
"developer/customization/metadata",
"developer/customization/permissions",
- "developer/customization/api",
- "developer/customization/checkout",
"developer/customization/decorators"
],
"icon": "code"