@spree/docs 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +54 -0
- package/dist/api-reference/platform/authentication.md +38 -0
- package/dist/api-reference/store-api/authentication.md +188 -0
- package/dist/api-reference/store-api/errors.md +277 -0
- package/dist/api-reference/store-api/idempotency.md +129 -0
- package/dist/api-reference/store-api/introduction.md +34 -0
- package/dist/api-reference/store-api/localization.md +279 -0
- package/dist/api-reference/store-api/metadata.md +160 -0
- package/dist/api-reference/store-api/monetary-amounts.md +65 -0
- package/dist/api-reference/store-api/querying.md +399 -0
- package/dist/api-reference/store-api/rate-limitting.md +103 -0
- package/dist/api-reference/store-api/relations.md +185 -0
- package/dist/api-reference/storefront/authentication.md +88 -0
- package/dist/api-reference/tutorials/adyen-integration-guide-for-android.md +165 -0
- package/dist/api-reference/tutorials/adyen-integration-guide-for-ios.md +194 -0
- package/dist/api-reference/tutorials/quick-checkout-with-stripe.md +248 -0
- package/dist/api-reference/v2/fetching-multiple-resources.md +26 -0
- package/dist/api-reference/v2/filtering-and-sorting.md +53 -0
- package/dist/api-reference/v2/introduction.md +22 -0
- package/dist/api-reference/v2/pagination.md +37 -0
- package/dist/api-reference/webhooks-events.md +883 -0
- package/dist/developer/admin/admin.md +205 -0
- package/dist/developer/admin/authentication.md +59 -0
- package/dist/developer/admin/components.md +711 -0
- package/dist/developer/admin/custom-css.md +243 -0
- package/dist/developer/admin/custom-javascript.md +116 -0
- package/dist/developer/admin/extending-ui.md +1964 -0
- package/dist/developer/admin/form-builder.md +444 -0
- package/dist/developer/admin/helper-methods.md +531 -0
- package/dist/developer/admin/navigation.md +805 -0
- package/dist/developer/admin/tables.md +491 -0
- package/dist/developer/advanced/adding_spree_to_rails_app.md +106 -0
- package/dist/developer/cli/quickstart.md +137 -0
- package/dist/developer/contributing/creating-an-extension.md +258 -0
- package/dist/developer/contributing/developing-spree.md +339 -0
- package/dist/developer/contributing/quickstart.md +32 -0
- package/dist/developer/contributing/updating-extensions.md +67 -0
- package/dist/developer/core-concepts/addresses.md +265 -0
- package/dist/developer/core-concepts/adjustments.md +107 -0
- package/dist/developer/core-concepts/architecture.md +177 -0
- package/dist/developer/core-concepts/calculators.md +323 -0
- package/dist/developer/core-concepts/customers.md +230 -0
- package/dist/developer/core-concepts/events.md +624 -0
- package/dist/developer/core-concepts/imports-exports.md +698 -0
- package/dist/developer/core-concepts/inventory.md +191 -0
- package/dist/developer/core-concepts/markets.md +250 -0
- package/dist/developer/core-concepts/media.md +167 -0
- package/dist/developer/core-concepts/metafields.md +187 -0
- package/dist/developer/core-concepts/orders.md +328 -0
- package/dist/developer/core-concepts/payments.md +710 -0
- package/dist/developer/core-concepts/pricing.md +163 -0
- package/dist/developer/core-concepts/products.md +360 -0
- package/dist/developer/core-concepts/promotions.md +322 -0
- package/dist/developer/core-concepts/reports.md +206 -0
- package/dist/developer/core-concepts/search-filtering.md +237 -0
- package/dist/developer/core-concepts/shipments.md +212 -0
- package/dist/developer/core-concepts/slugs.md +111 -0
- package/dist/developer/core-concepts/staff-roles.md +123 -0
- package/dist/developer/core-concepts/store-credits-gift-cards.md +317 -0
- package/dist/developer/core-concepts/stores.md +117 -0
- package/dist/developer/core-concepts/taxes.md +135 -0
- package/dist/developer/core-concepts/translations.md +120 -0
- package/dist/developer/core-concepts/users.md +299 -0
- package/dist/developer/core-concepts/webhooks.md +378 -0
- package/dist/developer/create-spree-app/quickstart.md +158 -0
- package/dist/developer/customization/api.md +93 -0
- package/dist/developer/customization/authentication.md +88 -0
- package/dist/developer/customization/checkout.md +204 -0
- package/dist/developer/customization/configuration.md +55 -0
- package/dist/developer/customization/decorators.md +523 -0
- package/dist/developer/customization/dependencies.md +232 -0
- package/dist/developer/customization/emails.md +21 -0
- package/dist/developer/customization/extensions.md +92 -0
- package/dist/developer/customization/metadata.md +236 -0
- package/dist/developer/customization/model-preferences.md +130 -0
- package/dist/developer/customization/permissions.md +265 -0
- package/dist/developer/customization/quickstart.md +229 -0
- package/dist/developer/customization/routes.md +24 -0
- package/dist/developer/customization/v4/admin-panel.md +78 -0
- package/dist/developer/customization/v4/authentication.md +210 -0
- package/dist/developer/customization/v4/checkout.md +212 -0
- package/dist/developer/customization/v4/deface.md +251 -0
- package/dist/developer/customization/v4/images.md +86 -0
- package/dist/developer/customization/v4/storefront.md +450 -0
- package/dist/developer/deployment/assets.md +87 -0
- package/dist/developer/deployment/aws.md +335 -0
- package/dist/developer/deployment/caching.md +27 -0
- package/dist/developer/deployment/cdn.md +39 -0
- package/dist/developer/deployment/database.md +155 -0
- package/dist/developer/deployment/docker.md +128 -0
- package/dist/developer/deployment/emails.md +77 -0
- package/dist/developer/deployment/environment_variables.md +111 -0
- package/dist/developer/deployment/heroku.md +51 -0
- package/dist/developer/deployment/render.md +95 -0
- package/dist/developer/getting-started/quickstart.md +82 -0
- package/dist/developer/how-to/custom-payment-method.md +374 -0
- package/dist/developer/how-to/custom-promotion.md +373 -0
- package/dist/developer/how-to/custom-report.md +387 -0
- package/dist/developer/how-to/custom-search-provider.md +230 -0
- package/dist/developer/multi-store/quickstart.md +71 -0
- package/dist/developer/multi-store/setup.md +38 -0
- package/dist/developer/multi-tenant/configuration.md +41 -0
- package/dist/developer/multi-tenant/core-concepts.md +75 -0
- package/dist/developer/multi-tenant/installation.md +96 -0
- package/dist/developer/multi-tenant/quickstart.md +20 -0
- package/dist/developer/multi-vendor/installation.md +45 -0
- package/dist/developer/multi-vendor/quickstart.md +17 -0
- package/dist/developer/sdk/admin/quickstart.md +22 -0
- package/dist/developer/sdk/authentication.md +89 -0
- package/dist/developer/sdk/configuration.md +225 -0
- package/dist/developer/sdk/quickstart.md +82 -0
- package/dist/developer/sdk/store/account.md +67 -0
- package/dist/developer/sdk/store/cart-checkout.md +140 -0
- package/dist/developer/sdk/store/markets.md +151 -0
- package/dist/developer/sdk/store/payments.md +96 -0
- package/dist/developer/sdk/store/products.md +149 -0
- package/dist/developer/sdk/store/wishlists.md +52 -0
- package/dist/developer/security/pci_compliance.md +15 -0
- package/dist/developer/security/security_policy.md +68 -0
- package/dist/developer/storefront/blocks.md +285 -0
- package/dist/developer/storefront/custom-css.md +260 -0
- package/dist/developer/storefront/custom-javascript.md +166 -0
- package/dist/developer/storefront/helper-methods.md +1288 -0
- package/dist/developer/storefront/links.md +298 -0
- package/dist/developer/storefront/nextjs/architecture.md +150 -0
- package/dist/developer/storefront/nextjs/customization.md +141 -0
- package/dist/developer/storefront/nextjs/deployment.md +180 -0
- package/dist/developer/storefront/nextjs/quickstart.md +92 -0
- package/dist/developer/storefront/nextjs/spree-next-package.md +314 -0
- package/dist/developer/storefront/pages.md +163 -0
- package/dist/developer/storefront/sections.md +569 -0
- package/dist/developer/storefront/storefront.md +56 -0
- package/dist/developer/storefront/themes.md +161 -0
- package/dist/developer/tutorial/admin.md +134 -0
- package/dist/developer/tutorial/extending-models.md +380 -0
- package/dist/developer/tutorial/file-uploads.md +121 -0
- package/dist/developer/tutorial/introduction.md +33 -0
- package/dist/developer/tutorial/model.md +41 -0
- package/dist/developer/tutorial/page-builder.md +487 -0
- package/dist/developer/tutorial/rich-text.md +73 -0
- package/dist/developer/tutorial/seo.md +332 -0
- package/dist/developer/tutorial/storefront.md +352 -0
- package/dist/developer/tutorial/testing.md +558 -0
- package/dist/developer/upgrades/2.0-to-2.1.md +46 -0
- package/dist/developer/upgrades/2.1-to-2.2.md +59 -0
- package/dist/developer/upgrades/2.2-to-2.3.md +44 -0
- package/dist/developer/upgrades/2.3-to-2.4.md +42 -0
- package/dist/developer/upgrades/3.0-to-3.1.md +47 -0
- package/dist/developer/upgrades/3.1-to-3.2.md +34 -0
- package/dist/developer/upgrades/3.2-to-3.3.md +70 -0
- package/dist/developer/upgrades/3.3-to-3.4.md +36 -0
- package/dist/developer/upgrades/3.4-to-3.5.md +44 -0
- package/dist/developer/upgrades/3.5-to-3.6.md +40 -0
- package/dist/developer/upgrades/3.6-to-3.7.md +62 -0
- package/dist/developer/upgrades/3.7-to-4.0.md +152 -0
- package/dist/developer/upgrades/4.0-to-4.1.md +92 -0
- package/dist/developer/upgrades/4.1-to-4.2.md +109 -0
- package/dist/developer/upgrades/4.10-to-5.0.md +129 -0
- package/dist/developer/upgrades/4.2-to-4.3.md +100 -0
- package/dist/developer/upgrades/4.3-to-4.4.md +125 -0
- package/dist/developer/upgrades/4.4-to-4.5.md +94 -0
- package/dist/developer/upgrades/4.5-to-4.6.md +119 -0
- package/dist/developer/upgrades/4.6-to-4.7.md +39 -0
- package/dist/developer/upgrades/4.8-to-4.9.md +24 -0
- package/dist/developer/upgrades/4.9-to-4.10.md +24 -0
- package/dist/developer/upgrades/4.x-to-4.8.md +52 -0
- package/dist/developer/upgrades/5.0-to-5.1.md +28 -0
- package/dist/developer/upgrades/5.1-to-5.2.md +127 -0
- package/dist/developer/upgrades/5.2-to-5.3.md +338 -0
- package/dist/developer/upgrades/5.3-to-5.4.md +248 -0
- package/dist/developer/upgrades/quickstart.md +36 -0
- package/dist/integrations/analytics/google-analytics.md +64 -0
- package/dist/integrations/analytics/google-tag-manager.md +78 -0
- package/dist/integrations/integrations.md +39 -0
- package/dist/integrations/marketing/klaviyo.md +99 -0
- package/dist/integrations/payments/adyen.md +90 -0
- package/dist/integrations/payments/paypal.md +41 -0
- package/dist/integrations/payments/razorpay.md +45 -0
- package/dist/integrations/payments/stripe.md +109 -0
- package/dist/integrations/search/meilisearch.md +236 -0
- package/dist/integrations/sso-mfa-social-login/admin-dashboard.md +57 -0
- package/dist/integrations/sso-mfa-social-login/storefront.md +56 -0
- package/package.json +27 -0
|
@@ -0,0 +1,491 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Admin Tables
|
|
3
|
+
sidebarTitle: Tables
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
Spree Admin provides a flexible table system for displaying resource listings with customizable columns, sorting, filtering, and bulk actions. The Tables DSL allows you to define table configurations for your resources and extend existing ones.
|
|
7
|
+
|
|
8
|
+
> **INFO:** The Tables system uses a declarative API accessible via `Spree.admin.tables`. This allows you to programmatically add, modify, and remove table columns and bulk actions directly in your initializers.
|
|
9
|
+
|
|
10
|
+
## Basic Usage
|
|
11
|
+
|
|
12
|
+
### Creating a New Table
|
|
13
|
+
|
|
14
|
+
Register a new table for your resource in `config/initializers/spree.rb`:
|
|
15
|
+
|
|
16
|
+
```ruby config/initializers/spree.rb
|
|
17
|
+
Rails.application.config.after_initialize do
|
|
18
|
+
# Register a new table
|
|
19
|
+
Spree.admin.tables.register(:brands, model_class: Spree::Brand, search_param: :name_cont)
|
|
20
|
+
|
|
21
|
+
# Add columns
|
|
22
|
+
Spree.admin.tables.brands.add :name,
|
|
23
|
+
label: :name,
|
|
24
|
+
type: :link,
|
|
25
|
+
sortable: true,
|
|
26
|
+
default: true,
|
|
27
|
+
position: 10
|
|
28
|
+
|
|
29
|
+
Spree.admin.tables.brands.add :products_count,
|
|
30
|
+
label: :products,
|
|
31
|
+
type: :number,
|
|
32
|
+
sortable: false,
|
|
33
|
+
default: true,
|
|
34
|
+
position: 20,
|
|
35
|
+
method: ->(brand) { brand.products.count }
|
|
36
|
+
|
|
37
|
+
Spree.admin.tables.brands.add :created_at,
|
|
38
|
+
label: :created_at,
|
|
39
|
+
type: :datetime,
|
|
40
|
+
sortable: true,
|
|
41
|
+
default: false,
|
|
42
|
+
position: 30
|
|
43
|
+
end
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Using the Table in Views
|
|
47
|
+
|
|
48
|
+
Render the table in your index view using the `render_table` helper:
|
|
49
|
+
|
|
50
|
+
```erb app/views/spree/admin/brands/index.html.erb
|
|
51
|
+
<%= render_table @collection, :brands %>
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
With additional options:
|
|
55
|
+
|
|
56
|
+
```erb
|
|
57
|
+
<%= render_table @collection, :brands,
|
|
58
|
+
bulk_operations: true,
|
|
59
|
+
export_type: Spree::Exports::Brands %>
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Table Registration Options
|
|
63
|
+
|
|
64
|
+
When registering a table, you can specify these options:
|
|
65
|
+
|
|
66
|
+
- **`model_class`** (`Class`) — The model class for the table (e.g., `Spree::Brand`).
|
|
67
|
+
|
|
68
|
+
- **`search_param`** (`Symbol`) — The Ransack search parameter for the search box.
|
|
69
|
+
|
|
70
|
+
- **`search_placeholder`** (`String`) — Custom placeholder text for the search box.
|
|
71
|
+
|
|
72
|
+
- **`row_actions`** (`Boolean`) — Enable row action buttons (edit/delete dropdown).
|
|
73
|
+
|
|
74
|
+
- **`row_actions_edit`** (`Boolean`) — Show edit action in row actions dropdown.
|
|
75
|
+
|
|
76
|
+
- **`row_actions_delete`** (`Boolean`) — Show delete action in row actions dropdown.
|
|
77
|
+
|
|
78
|
+
- **`new_resource`** (`Boolean`) — Show "New Resource" button when collection is empty.
|
|
79
|
+
|
|
80
|
+
- **`date_range_param`** (`Symbol`) — Enable date range filter for the specified column (e.g., `:created_at`).
|
|
81
|
+
|
|
82
|
+
- **`link_to_action`** (`Symbol`) — Action for link columns (`:edit` or `:show`).
|
|
83
|
+
|
|
84
|
+
## Column Options
|
|
85
|
+
|
|
86
|
+
All columns support the following options:
|
|
87
|
+
|
|
88
|
+
- **`label`** (`Symbol or String`) — The column header label. Can be a symbol (translation key using `Spree.t`) or a string.
|
|
89
|
+
|
|
90
|
+
- **`type`** (`String`) — The column type. Determines how the value is rendered.
|
|
91
|
+
|
|
92
|
+
Available types:
|
|
93
|
+
- `string` - Plain text
|
|
94
|
+
- `number` - Numeric value
|
|
95
|
+
- `date` - Date formatted with `spree_date` helper
|
|
96
|
+
- `datetime` - Relative time with `spree_time_ago` helper
|
|
97
|
+
- `money` - Currency formatted with `Spree::Money`
|
|
98
|
+
- `status` - Badge with status-based styling
|
|
99
|
+
- `link` - Clickable link to resource
|
|
100
|
+
- `boolean` - Active/inactive badge
|
|
101
|
+
- `image` - Thumbnail image
|
|
102
|
+
- `association` - Associated record name(s)
|
|
103
|
+
- `custom` - Custom partial rendering
|
|
104
|
+
|
|
105
|
+
- **`sortable`** (`Boolean`) — Whether the column can be sorted.
|
|
106
|
+
|
|
107
|
+
- **`filterable`** (`Boolean`) — Whether the column appears in the query builder filter options.
|
|
108
|
+
|
|
109
|
+
- **`displayable`** (`Boolean`) — Whether the column can be shown/hidden by users. Set to `false` for filter-only columns.
|
|
110
|
+
|
|
111
|
+
- **`default`** (`Boolean`) — Whether the column is visible by default.
|
|
112
|
+
|
|
113
|
+
- **`position`** (`Integer`) — Column order. Lower numbers appear first.
|
|
114
|
+
|
|
115
|
+
- **`method`** (`Symbol or Lambda`) — Custom method to extract the column value. Can be a method name or lambda.
|
|
116
|
+
|
|
117
|
+
- **`align`** (`String`) — Text alignment: `left`, `center`, or `right`.
|
|
118
|
+
|
|
119
|
+
- **`width`** (`String`) — Column width class (e.g., `"20"` for `w-20`).
|
|
120
|
+
|
|
121
|
+
- **`if`** (`Lambda`) — Conditional visibility. Column only appears if lambda returns true.
|
|
122
|
+
|
|
123
|
+
### Filter-specific Options
|
|
124
|
+
|
|
125
|
+
- **`filter_type`** (`String`) — Override the filter input type. Available: `string`, `number`, `date`, `datetime`, `money`, `status`, `boolean`, `autocomplete`, `select`.
|
|
126
|
+
|
|
127
|
+
- **`ransack_attribute`** (`String`) — Custom Ransack attribute name for filtering/sorting (defaults to column key).
|
|
128
|
+
|
|
129
|
+
- **`operators`** (`Array`) — Available filter operators. Defaults based on column type.
|
|
130
|
+
|
|
131
|
+
- **`value_options`** (`Array or Lambda`) — Options for select/status filters. Array of hashes with `value` and `label` keys.
|
|
132
|
+
|
|
133
|
+
- **`search_url`** (`String | Lambda`) — URL for autocomplete filter type. Use a Lambda for dynamic paths: `search_url: ->(view_context) { view_context.spree.admin_taxons_select_options_path(format: :json) }`.
|
|
134
|
+
|
|
135
|
+
### Custom Sort Options
|
|
136
|
+
|
|
137
|
+
- **`sort_scope_asc`** (`Symbol`) — Custom scope name for ascending sort (bypasses Ransack).
|
|
138
|
+
|
|
139
|
+
- **`sort_scope_desc`** (`Symbol`) — Custom scope name for descending sort (bypasses Ransack).
|
|
140
|
+
|
|
141
|
+
### Custom Partial Options
|
|
142
|
+
|
|
143
|
+
- **`partial`** (`String`) — Partial path for `custom` type columns.
|
|
144
|
+
|
|
145
|
+
- **`partial_locals`** (`Hash or Lambda`) — Additional locals to pass to the partial. Lambda receives the record.
|
|
146
|
+
|
|
147
|
+
## Column Types Examples
|
|
148
|
+
|
|
149
|
+
### String Column
|
|
150
|
+
|
|
151
|
+
```ruby
|
|
152
|
+
Spree.admin.tables.brands.add :name,
|
|
153
|
+
label: :name,
|
|
154
|
+
type: :string,
|
|
155
|
+
sortable: true,
|
|
156
|
+
default: true
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
### Link Column
|
|
160
|
+
|
|
161
|
+
Links to the resource edit or show page:
|
|
162
|
+
|
|
163
|
+
```ruby
|
|
164
|
+
Spree.admin.tables.brands.add :name,
|
|
165
|
+
label: :name,
|
|
166
|
+
type: :link,
|
|
167
|
+
sortable: true,
|
|
168
|
+
default: true
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
### Money Column
|
|
172
|
+
|
|
173
|
+
Displays formatted currency:
|
|
174
|
+
|
|
175
|
+
```ruby
|
|
176
|
+
Spree.admin.tables.products.add :price,
|
|
177
|
+
label: :price,
|
|
178
|
+
type: :money,
|
|
179
|
+
sortable: true,
|
|
180
|
+
default: true,
|
|
181
|
+
align: :right,
|
|
182
|
+
method: ->(product) { product.display_price }
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
### Status Column
|
|
186
|
+
|
|
187
|
+
Displays a colored badge based on the status value:
|
|
188
|
+
|
|
189
|
+
```ruby
|
|
190
|
+
Spree.admin.tables.orders.add :state,
|
|
191
|
+
label: :state,
|
|
192
|
+
type: :status,
|
|
193
|
+
filter_type: :select,
|
|
194
|
+
sortable: true,
|
|
195
|
+
default: true,
|
|
196
|
+
value_options: -> {
|
|
197
|
+
Spree::Order.state_machine(:state).states.map { |s|
|
|
198
|
+
{ value: s.name.to_s, label: s.name.to_s.humanize }
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
Status values are automatically styled:
|
|
204
|
+
- **Green** (`badge-active`): `active`, `complete`, `completed`, `paid`, `shipped`, `available`
|
|
205
|
+
- **Yellow** (`badge-warning`): `draft`, `pending`, `processing`, `ready`
|
|
206
|
+
- **Gray** (`badge-inactive`): `archived`, `canceled`, `cancelled`, `failed`, `void`, `inactive`
|
|
207
|
+
|
|
208
|
+
### Boolean Column
|
|
209
|
+
|
|
210
|
+
```ruby
|
|
211
|
+
Spree.admin.tables.products.add :available,
|
|
212
|
+
label: :available,
|
|
213
|
+
type: :boolean,
|
|
214
|
+
sortable: true,
|
|
215
|
+
default: true
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
### DateTime Column
|
|
219
|
+
|
|
220
|
+
Displays relative time (e.g., "2 hours ago"):
|
|
221
|
+
|
|
222
|
+
```ruby
|
|
223
|
+
Spree.admin.tables.orders.add :completed_at,
|
|
224
|
+
label: :completed_at,
|
|
225
|
+
type: :datetime,
|
|
226
|
+
sortable: true,
|
|
227
|
+
default: true
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
### Association Column
|
|
231
|
+
|
|
232
|
+
For displaying related records:
|
|
233
|
+
|
|
234
|
+
```ruby
|
|
235
|
+
Spree.admin.tables.products.add :taxons,
|
|
236
|
+
label: :taxons,
|
|
237
|
+
type: :association,
|
|
238
|
+
filter_type: :autocomplete,
|
|
239
|
+
sortable: false,
|
|
240
|
+
filterable: true,
|
|
241
|
+
default: false,
|
|
242
|
+
ransack_attribute: 'taxons_id',
|
|
243
|
+
operators: [:in],
|
|
244
|
+
search_url: ->(view_context) { view_context.spree.admin_taxons_select_options_path(format: :json) },
|
|
245
|
+
method: ->(product) { product.taxons.map(&:pretty_name).join(', ') }
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
### Custom Partial Column
|
|
249
|
+
|
|
250
|
+
For complex rendering:
|
|
251
|
+
|
|
252
|
+
```ruby
|
|
253
|
+
Spree.admin.tables.products.add :name,
|
|
254
|
+
label: :name,
|
|
255
|
+
type: :custom,
|
|
256
|
+
sortable: true,
|
|
257
|
+
default: true,
|
|
258
|
+
partial: 'spree/admin/tables/columns/product_name'
|
|
259
|
+
|
|
260
|
+
# With dynamic locals
|
|
261
|
+
Spree.admin.tables.orders.add :customer,
|
|
262
|
+
label: :customer,
|
|
263
|
+
type: :custom,
|
|
264
|
+
default: true,
|
|
265
|
+
partial: 'spree/admin/orders/customer_summary',
|
|
266
|
+
partial_locals: ->(record) { { order: record } }
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
The partial receives `record`, `column`, and `value` locals plus any custom locals.
|
|
270
|
+
|
|
271
|
+
### Filter-only Column
|
|
272
|
+
|
|
273
|
+
Columns that can be filtered but not displayed:
|
|
274
|
+
|
|
275
|
+
```ruby
|
|
276
|
+
Spree.admin.tables.orders.add :sku,
|
|
277
|
+
label: :sku,
|
|
278
|
+
type: :string,
|
|
279
|
+
sortable: false,
|
|
280
|
+
filterable: true,
|
|
281
|
+
displayable: false,
|
|
282
|
+
ransack_attribute: 'line_items_variant_sku'
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
## Modifying Existing Tables
|
|
286
|
+
|
|
287
|
+
### Adding Columns to Existing Tables
|
|
288
|
+
|
|
289
|
+
```ruby config/initializers/spree.rb
|
|
290
|
+
Rails.application.config.after_initialize do
|
|
291
|
+
# Add a custom column to products
|
|
292
|
+
Spree.admin.tables.products.add :vendor,
|
|
293
|
+
label: 'Vendor',
|
|
294
|
+
type: :string,
|
|
295
|
+
sortable: false,
|
|
296
|
+
default: true,
|
|
297
|
+
position: 25,
|
|
298
|
+
method: ->(product) { product.vendor&.name },
|
|
299
|
+
if: -> { defined?(Spree::Vendor) }
|
|
300
|
+
end
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
### Updating Existing Columns
|
|
304
|
+
|
|
305
|
+
```ruby
|
|
306
|
+
Rails.application.config.after_initialize do
|
|
307
|
+
# Change the position of an existing column
|
|
308
|
+
Spree.admin.tables.products.update :price, position: 15
|
|
309
|
+
|
|
310
|
+
# Make a column default
|
|
311
|
+
Spree.admin.tables.products.update :sku, default: true
|
|
312
|
+
|
|
313
|
+
# Change column label
|
|
314
|
+
Spree.admin.tables.orders.update :number, label: 'Order #'
|
|
315
|
+
end
|
|
316
|
+
```
|
|
317
|
+
|
|
318
|
+
### Removing Columns
|
|
319
|
+
|
|
320
|
+
```ruby
|
|
321
|
+
Rails.application.config.after_initialize do
|
|
322
|
+
# Remove a column entirely
|
|
323
|
+
Spree.admin.tables.products.remove :sku
|
|
324
|
+
end
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
### Inserting Columns at Specific Positions
|
|
328
|
+
|
|
329
|
+
```ruby
|
|
330
|
+
Rails.application.config.after_initialize do
|
|
331
|
+
# Insert before an existing column
|
|
332
|
+
Spree.admin.tables.products.insert_before :price, :cost_price,
|
|
333
|
+
label: 'Cost Price',
|
|
334
|
+
type: :money,
|
|
335
|
+
default: false
|
|
336
|
+
|
|
337
|
+
# Insert after an existing column
|
|
338
|
+
Spree.admin.tables.products.insert_after :name, :brand,
|
|
339
|
+
label: 'Brand',
|
|
340
|
+
type: :string,
|
|
341
|
+
default: true,
|
|
342
|
+
method: ->(product) { product.brand&.name }
|
|
343
|
+
end
|
|
344
|
+
```
|
|
345
|
+
|
|
346
|
+
## Bulk Actions
|
|
347
|
+
|
|
348
|
+
Add bulk actions that appear when users select multiple rows:
|
|
349
|
+
|
|
350
|
+
```ruby
|
|
351
|
+
Rails.application.config.after_initialize do
|
|
352
|
+
Spree.admin.tables.products.add_bulk_action :set_active,
|
|
353
|
+
label: 'admin.bulk_ops.products.title.set_active',
|
|
354
|
+
icon: 'circle-check',
|
|
355
|
+
action_path: ->(view_context) { view_context.spree.bulk_status_update_admin_products_path(status: 'active') },
|
|
356
|
+
body: 'admin.bulk_ops.products.body.set_active',
|
|
357
|
+
position: 10,
|
|
358
|
+
if: -> { can?(:activate, Spree::Product) }
|
|
359
|
+
end
|
|
360
|
+
```
|
|
361
|
+
|
|
362
|
+
The modal is automatically rendered via `/admin/bulk_operations/new?kind=:action_key&table_key=:table_key`.
|
|
363
|
+
|
|
364
|
+
### Bulk Action Options
|
|
365
|
+
|
|
366
|
+
- **`label`** (`String`) — Translation key or text for the action button.
|
|
367
|
+
|
|
368
|
+
- **`icon`** (`String`) — Icon name from [Tabler Icons](https://tabler.io/icons).
|
|
369
|
+
|
|
370
|
+
- **`action_path`** (`String | Lambda`) — URL for the bulk action endpoint. Use a Lambda for dynamic paths: `action_path: ->(view_context) { view_context.custom_path }`.
|
|
371
|
+
|
|
372
|
+
- **`method`** (`Symbol`) — HTTP method for the action (`:get`, `:post`, `:put`, `:patch`, `:delete`).
|
|
373
|
+
|
|
374
|
+
- **`position`** (`Integer`) — Order in the bulk actions menu.
|
|
375
|
+
|
|
376
|
+
- **`if`** (`Lambda`) — Conditional visibility based on user permissions.
|
|
377
|
+
|
|
378
|
+
- **`confirm`** (`String`) — Confirmation message before executing the action.
|
|
379
|
+
|
|
380
|
+
- **`button_text`** (`String`) — Custom text for the modal submit button. Supports translation keys. Defaults to "Confirm".
|
|
381
|
+
|
|
382
|
+
- **`button_class`** (`String`) — CSS class for the modal submit button (e.g., `btn-danger` for destructive actions).
|
|
383
|
+
|
|
384
|
+
### Managing Bulk Actions
|
|
385
|
+
|
|
386
|
+
```ruby
|
|
387
|
+
# Update a bulk action
|
|
388
|
+
Spree.admin.tables.products.update_bulk_action :set_active, position: 5
|
|
389
|
+
|
|
390
|
+
# Remove a bulk action
|
|
391
|
+
Spree.admin.tables.products.remove_bulk_action :set_archived
|
|
392
|
+
```
|
|
393
|
+
|
|
394
|
+
## Custom Sorting
|
|
395
|
+
|
|
396
|
+
For columns that need custom database queries:
|
|
397
|
+
|
|
398
|
+
```ruby
|
|
399
|
+
# In your model
|
|
400
|
+
class Spree::Product < Spree.base_class
|
|
401
|
+
scope :ascend_by_price, -> { joins(:master).order('spree_variants.price ASC') }
|
|
402
|
+
scope :descend_by_price, -> { joins(:master).order('spree_variants.price DESC') }
|
|
403
|
+
end
|
|
404
|
+
|
|
405
|
+
# In your initializer
|
|
406
|
+
Spree.admin.tables.products.add :price,
|
|
407
|
+
label: :price,
|
|
408
|
+
type: :money,
|
|
409
|
+
sortable: true,
|
|
410
|
+
default: true,
|
|
411
|
+
sort_scope_asc: :ascend_by_price,
|
|
412
|
+
sort_scope_desc: :descend_by_price,
|
|
413
|
+
method: ->(product) { product.price }
|
|
414
|
+
```
|
|
415
|
+
|
|
416
|
+
## Available Tables
|
|
417
|
+
|
|
418
|
+
Spree registers tables for all built-in resources:
|
|
419
|
+
|
|
420
|
+
| Table Key | Model Class |
|
|
421
|
+
|-----------|-------------|
|
|
422
|
+
| `:products` | `Spree::Product` |
|
|
423
|
+
| `:orders` | `Spree::Order` |
|
|
424
|
+
| `:checkouts` | `Spree::Order` (draft) |
|
|
425
|
+
| `:users` | `Spree.user_class` |
|
|
426
|
+
| `:promotions` | `Spree::Promotion` |
|
|
427
|
+
| `:customer_returns` | `Spree::CustomerReturn` |
|
|
428
|
+
| `:option_types` | `Spree::OptionType` |
|
|
429
|
+
| `:newsletter_subscribers` | `Spree::NewsletterSubscriber` |
|
|
430
|
+
| `:policies` | `Spree::Policy` |
|
|
431
|
+
| `:stock_transfers` | `Spree::StockTransfer` |
|
|
432
|
+
| `:metafield_definitions` | `Spree::MetafieldDefinition` |
|
|
433
|
+
| `:gift_cards` | `Spree::GiftCard` |
|
|
434
|
+
| `:stock_items` | `Spree::StockItem` |
|
|
435
|
+
| `:posts` | `Spree::Post` |
|
|
436
|
+
| `:post_categories` | `Spree::PostCategory` |
|
|
437
|
+
| `:webhook_endpoints` | `Spree::WebhookEndpoint` |
|
|
438
|
+
| `:webhook_deliveries` | `Spree::WebhookDelivery` |
|
|
439
|
+
| `:price_list_products` | `Spree::Product` (nested) |
|
|
440
|
+
|
|
441
|
+
## API Reference
|
|
442
|
+
|
|
443
|
+
### Table Methods
|
|
444
|
+
|
|
445
|
+
```ruby
|
|
446
|
+
table = Spree.admin.tables.products
|
|
447
|
+
|
|
448
|
+
# Column management
|
|
449
|
+
table.add(key, **options) # Add a new column
|
|
450
|
+
table.remove(key) # Remove a column
|
|
451
|
+
table.update(key, **options) # Update column options
|
|
452
|
+
table.find(key) # Find a column by key
|
|
453
|
+
table.exists?(key) # Check if column exists
|
|
454
|
+
table.insert_before(target, key, **options)
|
|
455
|
+
table.insert_after(target, key, **options)
|
|
456
|
+
|
|
457
|
+
# Query columns
|
|
458
|
+
table.available_columns # All displayable columns
|
|
459
|
+
table.default_columns # Columns shown by default
|
|
460
|
+
table.visible_columns(selected, ctx) # Columns for current view
|
|
461
|
+
table.sortable_columns # Columns that can be sorted
|
|
462
|
+
table.filterable_columns # Columns for query builder
|
|
463
|
+
|
|
464
|
+
# Bulk actions
|
|
465
|
+
table.add_bulk_action(key, **options)
|
|
466
|
+
table.remove_bulk_action(key)
|
|
467
|
+
table.update_bulk_action(key, **options)
|
|
468
|
+
table.find_bulk_action(key)
|
|
469
|
+
table.visible_bulk_actions(context)
|
|
470
|
+
table.bulk_operations_enabled?
|
|
471
|
+
```
|
|
472
|
+
|
|
473
|
+
### Registry Methods
|
|
474
|
+
|
|
475
|
+
```ruby
|
|
476
|
+
# Check if a table is registered
|
|
477
|
+
Spree.admin.tables.registered?(:brands)
|
|
478
|
+
|
|
479
|
+
# Get a table
|
|
480
|
+
Spree.admin.tables.get(:products)
|
|
481
|
+
|
|
482
|
+
# Shorthand access
|
|
483
|
+
Spree.admin.tables.products
|
|
484
|
+
```
|
|
485
|
+
|
|
486
|
+
## Related Documentation
|
|
487
|
+
|
|
488
|
+
- [Admin Navigation](/developer/admin/navigation) - Add custom menu items to the admin
|
|
489
|
+
- [Extending Admin UI](/developer/admin/extending-ui) - Inject partials into admin pages
|
|
490
|
+
- [Search & Filtering](/developer/core-concepts/search-filtering) - Add searchable/filterable fields
|
|
491
|
+
- [Customization Quickstart](/developer/customization/quickstart) - Overview of all customization options
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Adding to an existing Rails app
|
|
3
|
+
description: This guide will show you how to add Spree to an existing Ruby on Rails application.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
> **WARNING:** This guide is aimed at advanced users who want to add Spree to an existing Rails application. If you are new to Spree, please follow the [Quickstart guide](/getting-started/quickstart).
|
|
7
|
+
|
|
8
|
+
## Overview
|
|
9
|
+
|
|
10
|
+
If you already have a Ruby on Rails application, you can add Spree to it by following these steps.
|
|
11
|
+
|
|
12
|
+
> **INFO:** Spree works with **PostgreSQL**, **MySQL**, and **SQLite** — whatever database your Rails app already uses. No database migration is needed.
|
|
13
|
+
|
|
14
|
+
## 1. Add Spree gems
|
|
15
|
+
|
|
16
|
+
Add these lines to your project `Gemfile`:
|
|
17
|
+
|
|
18
|
+
```ruby
|
|
19
|
+
spree_opts = { 'github': 'spree/spree', 'branch': 'main' }
|
|
20
|
+
gem 'spree', spree_opts # core, API, and CLI
|
|
21
|
+
gem 'spree_admin', spree_opts # Admin panel (optional)
|
|
22
|
+
gem 'spree_storefront', spree_opts # Storefront (optional)
|
|
23
|
+
gem 'spree_emails', spree_opts # transactional emails (optional)
|
|
24
|
+
gem 'spree_sample', spree_opts # dummy data like products, taxons, etc (optional)
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
And run the following command to install the gems:
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
bundle install
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## 2. Run the install generators
|
|
34
|
+
|
|
35
|
+
Spree uses a modular installation approach. First install the core, then add optional components.
|
|
36
|
+
|
|
37
|
+
### Install core Spree
|
|
38
|
+
|
|
39
|
+
This installs core models, API, CLI, and authentication:
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
bin/rails g spree:install --user_class=Spree::User --authentication=devise
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
**Core installation options:**
|
|
46
|
+
|
|
47
|
+
| Option | Description |
|
|
48
|
+
|--------|-------------|
|
|
49
|
+
| `user_class` | The class for your users, eg. `Spree::User` or `User` |
|
|
50
|
+
| `admin_user_class` | The class for admin users (defaults to `user_class`) |
|
|
51
|
+
| `authentication` | Authentication gem: `devise` or `custom` |
|
|
52
|
+
| `migrate` | Whether to run migrations (default: true) |
|
|
53
|
+
| `seed` | Whether to run the seed file (default: true) |
|
|
54
|
+
| `sample` | Whether to add sample data (default: false) |
|
|
55
|
+
| `admin_email` | Email of the first admin user |
|
|
56
|
+
| `admin_password` | Password of the first admin user |
|
|
57
|
+
|
|
58
|
+
### Install Admin Panel (optional)
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
bin/rails g spree:admin:install
|
|
62
|
+
bin/rails g spree:admin:devise # if using Devise authentication
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### Install Storefront (optional)
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
bin/rails g spree:storefront:install
|
|
69
|
+
bin/rails g spree:storefront:devise # if using Devise authentication
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## 3. Add sample data (optional)
|
|
73
|
+
|
|
74
|
+
To add sample data to your store, run:
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
bin/rake spree_sample:load
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
This will add some products, categories, and will setup a checkout flow to your store.
|
|
81
|
+
|
|
82
|
+
## 4. Exploring Your Store
|
|
83
|
+
|
|
84
|
+
Feel free to explore your store. You can do so because Spree comes with a default pre-built Storefront and Admin Panel.
|
|
85
|
+
|
|
86
|
+
### Logging into the Admin Dashboard
|
|
87
|
+
|
|
88
|
+
Use your browser window to navigate to [http://localhost:3000/admin](http://localhost:3000/admin). You can log in with the default credentials:
|
|
89
|
+
- login: `spree@example.com`
|
|
90
|
+
- password: `spree123`
|
|
91
|
+
|
|
92
|
+
Upon successful authentication, you should see the admin screen:
|
|
93
|
+
|
|
94
|
+

|
|
95
|
+
|
|
96
|
+
Feel free to explore some of the Admin Panel features that Spree has to offer and to verify that your installation is working properly.
|
|
97
|
+
|
|
98
|
+
### Browsing Storefront
|
|
99
|
+
|
|
100
|
+
Spree comes with a default pre-built Storefront. You can access it by navigating to [http://localhost:3000](http://localhost:3000).
|
|
101
|
+
|
|
102
|
+
You can later customize this Storefront or choose another one if you prefer Next.js or Vue.js.
|
|
103
|
+
|
|
104
|
+
## All Done!
|
|
105
|
+
|
|
106
|
+
Congrats! You've set up your Spree Commerce and it's looking amazing! Need support or want to give some feedback? You can join our [community](https://slack.spreecommerce.org/) or drop us an email at [hello@spreecommerce.org](mailto:hello@spreecommerce.org).
|