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.

[skip ci] documentation - added routes customization gude and adding spree to existing rails app

Damian Legawiec175313316fd7
diff --git a/docs/developer/advanced/existing_app_tutorial.mdx b/docs/developer/advanced/existing_app_tutorial.mdx
deleted file mode 100644
index 5e5af47b49..0000000000
--- a/docs/developer/advanced/existing_app_tutorial.mdx
+++ /dev/null
@@ -1,86 +0,0 @@
-# Adding Spree to an existing Rails application
-
-### Add Spree gems to your `Gemfile`
-
-```ruby
-gem 'spree' # core and API
-gem 'spree_backend' # Admin panel (optional)
-gem 'spree_frontend' # Storefront (optional)
-gem 'spree_emails' # transactional emails (optional)
-gem 'spree_sample' # dummy data like products, taxons, etc
-gem 'spree_auth_devise' # Devise integration (optional)
-gem 'spree_gateway' # payment gateways eg. Stripe, Braintree (optional)
-gem 'spree_i18n' # translation files (optional)
-
-# only needed for MacOS and Ruby 3+
-gem 'sassc', github: 'sass/sassc-ruby', branch: 'master'
-```
-
-### Install gems
-
-```bash
- bundle install
-```
-
-### Use the install generators to set up Spree
-
-```
-bin/rails g spree:install --user_class=Spree::User
-bin/rails g spree:backend:install
-bin/rails g spree:frontend:install
-bin/rails g spree:auth:install
-bin/rails g spree_gateway:install
-```
-
-### Installation options
-
-By default, the installation generator (`rails g spree:install`) will run migrations as well as adding seed. This can be disabled using
-
-```bash
-bin/rails g spree:install --migrate=false --sample=false --seed=false
-```
-
-You can always perform any of these steps later by using these commands.
-
-```bash
-bin/rake railties:install:migrations
-bin/rails db:migrate
-bin/rails db:seed
-bin/rake spree_sample:load
-```
-
-### Mounting the Spree engine
-
-When `rails g spree:install` is run inside an application, it will install Spree, mounting the `Spree::Core::Engine` component by inserting this line automatically into `config/routes.rb`:
-
-```ruby
-mount Spree::Core::Engine, at: '/'
-```
-
-By default, all Spree routes will be available at the root of your domain. For example, if your domain is `http://localhost:3000`, Spree’s `/products` URL will be available at `http://localhost:3000/products`.
-
-You can customize this simply by changing the `:at` specification in `config/routes.rb` to be something else. For example, if you would like Spree to be mounted at `/shop`, you can write this:
-
-```ruby
-mount Spree::Core::Engine, at: `/shop`
-```
-
-The different parts of Spree (API, Admin) will be mounted there as well, eg. `http://localhost:3000/shop/admin`.
-
-### Use your existing authentication
-
-[Spree Auth Devise](https://github.com/spree/spree_auth_devise) is the default authentication that comes with Spree but you can swap it for your own, please [follow this guide](../customization/authentication)
-
-### Hello, Spree Commerce
-
-You now have a functional Spree application after running only a few commands!
-
-To stop the webserver, hit Ctrl-C in the terminal window where it's running. In development mode, Spree does not generally require you to stop the server; changes you make in files will be automatically picked up by the server.
-
-#### Logging Into the Admin Panel
-
-The next thing you'll probably want to do is to log into the admin interface. Use your browser window to navigate to [http://localhost:3000/admin](http://localhost:3000/admin). You can log in with the username `[email protected]` and password `spree123`.
-
-Upon successful authentication, you should see the admin screen:
-
-Feel free to explore some of the Admin Panel features that Spree has to offer and to verify that your installation is working properly.
diff --git a/docs/developer/customization/logic.mdx b/docs/developer/customization/logic.mdx
deleted file mode 100644
index 258fd05142..0000000000
--- a/docs/developer/customization/logic.mdx
+++ /dev/null
@@ -1,121 +0,0 @@
----
-title: Business Logic
-section: customization
-order: 4
----
-
-# Business Logic
-
-## Overview
-
-It is highly recommended to use [Dependencies](dependencies) and [Extensions](../extensions/extensions) first rather than to apply patches to Spree Core. Still if you don't find those to be efficient you can pretty much overwrite any part of Spree following this guide.
-
-## Extending Classes
-
-All of Spree's business logic models, controllers, helpers, etc can easily be extended or overridden to meet your exact requirements using standard Ruby idioms.
-
-Standard practice for including such changes in your application or extension is to create a file within the relevant **app/models/spree** or **app/controllers/spree** directory with the original class name with **_decorator** appended.
-
-## Extending Models
-
-Adding a custom method to the [Product](https://github.com/spree/spree/blob/master/core/app/models/spree/product.rb) model: `app/models/spree/product_decorator.rb`
-
-```ruby
-module Spree
- module ProductDecorator
- def self.prepended(base)
- base.before_validation :strip_whitespaces
- end
-
- def some_method
- ...
- end
-
- protected
-
- def strip_whitespaces
- ...
- end
- end
-
- Product.prepend(ProductDecorator)
-end
-```
-
-#### Adding new associations to existing models
-
-Assume you want to add a new model called `Video` associated to `Spree::Product`. Let's start with creating a database migration:
-
-```bash
-bin/rails g migration CreateVideos url:string product:references
-bin/rails db:migrate
-```
-
-Add new model to `app/models/videos.rb`:
-
-```ruby
-class Video < ApplicationRecord
- belongs_to :product, class_name: 'Spree::Product'
-
- has_one_attached :video_file
-end
-```
-
-Finally add the association in `ProductDecorator` in `app/models/spree/product_decorator.rb`:
-
-```ruby
-module Spree
- module ProductDecorator
- def self.prepended(base)
- base.has_many :videos, class_name: 'Video', foreign_key: 'product_id', dependent: :destroy
- end
- end
-
- Product.prepend(ProductDecorator)
-end
-```
-
-## Extending Controllers
-
-Adding a custom action to the [ProductsController](https://github.com/spree/spree/blob/master/frontend/app/controllers/spree/products_controller.rb): `app/controllers/spree/products_controller_decorator.rb`
-
-```ruby
-module Spree
- module ProductsControllerDecorator
- def some_action
- ...
- end
- end
-
- ProductsController.prepend(ProductsControllerDecorator)
-end
-```
-
-The exact same format can be used to redefine an existing method.
-
-### Accessing Product Data
-
-If you extend the Products controller with a new method, you may very well want to access product data in that method. You can do so by using the `:load_data before_action`.
-
-```ruby
-module Spree
- module ProductsControllerDecorator
- def self.prepended(base)
- base.before_action :load_data, only: :some_action
- end
-
- def some_action
- ...
- end
- end
-
- ProductsController.prepend(ProductsControllerDecorator)
-end
-```
-
-`:load_data` will use `params[:id]` to lookup the product by its permalink.
-
-## Replacing Models or Controllers
-
-If your customizations are so large that you overwrite the majority of a given Model or Controller we recommend to drop the `_decorator` pattern and overwrite the Model or Controller completely in your project. This will make future Spree upgrades easier.
-
diff --git a/docs/developer/customization/routes.mdx b/docs/developer/customization/routes.mdx
new file mode 100644
index 0000000000..b50249c0c1
--- /dev/null
+++ b/docs/developer/customization/routes.mdx
@@ -0,0 +1,40 @@
+---
+title: Routes
+description: Learn how to customize the routes in Spree
+---
+
+## Default configuration
+
+By default Spree is mounted at the root of your domain, this code will be inserted into `config/routes.rb`:
+
+```ruby
+mount Spree::Core::Engine, at: '/'
+```
+
+This means that Spree will be available at the root of your domain, for example `http://localhost:3000`.
+
+## Customizing the mount point
+
+You can customize this simply by changing the `:at` specification in `config/routes.rb` to be something else. For example, if you would like Spree to be mounted at `/shop`, you can write this:
+
+```ruby
+mount Spree::Core::Engine, at: `/shop`
+```
+
+The different parts of Spree (API, Admin) will be mounted there as well, eg. `http://localhost:3000/shop/products`.
+
+## Customizing admin panel path
+
+<Info>
+Remember to have the `spree_backend` installed.
+</Info>
+
+By default, Spree Admin is mounted at `/admin` and is accessible at `http://localhost:3000/admin`.
+
+You can change the path of the admin panel by setting the `admin_path` option in your `config/initializers/spree.rb` file, eg.
+
+```ruby
+Spree.admin_path = '/dashboard'
+```
+
+This will change the path of the Spree Admin to `http://localhost:3000/dashboard`.
\ No newline at end of file
diff --git a/docs/developer/getting-started/adding_spree_to_rails_app.mdx b/docs/developer/getting-started/adding_spree_to_rails_app.mdx
new file mode 100644
index 0000000000..ce7ecbad9e
--- /dev/null
+++ b/docs/developer/getting-started/adding_spree_to_rails_app.mdx
@@ -0,0 +1,105 @@
+---
+title: Adding to an existing Rails app
+description: This guide will show you how to add Spree to an existing Ruby on Rails application.
+---
+
+<Note>
+If you followed the [Quickstart guide](quickstart) you can skip this page and go to the [Core Concepts](../core-concepts) section.
+</Note>
+
+## Overview
+
+If you already have a Ruby on Rails application, you can add Spree to it by following these steps.
+
+## 1. Installing Spree
+
+<AccordionGroup>
+ <Accordion icon="gem" title="Add Spree gems">
+ Add these lines to your project `Gemfile`:
+
+ ```ruby
+ gem 'spree', '~> 4.7' # core and API
+ gem 'spree_backend', '~> 4.7' # Admin panel (optional)
+ gem 'spree_frontend', '~> 4.7' # Storefront (optional)
+ gem 'spree_emails', '~> 4.7' # transactional emails (optional)
+ gem 'spree_sample', '~> 4.7' # dummy data like products, taxons, etc (optional)
+ gem 'spree_auth_devise', '~> 4.6' # Devise integration (optional)
+ gem 'spree_gateway', '~> 3.11' # payment gateways eg. Stripe, Braintree (optional)
+ ```
+
+ And run the following command to install the gems:
+
+ ```bash
+ bundle install
+ ```
+ </Accordion>
+
+ <Accordion icon="terminal" title="Run the install generators">
+ These commands will run generators which will perform operations required for Spree to work properly.
+
+ ```bash
+ bin/rails g spree:install --user_class=Spree::User
+ bin/rails g spree:backend:install
+ bin/rails g spree:frontend:install
+ bin/rails g spree:auth:install
+ bin/rails g spree_gateway:install
+ ```
+
+ ### Installation options
+
+ By default, the installation generator (`rails g spree:install`) will run migrations as well as adding seed. This can be disabled using
+
+ ```bash
+ bin/rails g spree:install --migrate=false --sample=false --seed=false
+ ```
+
+ You can always perform any of these steps later by using these commands.
+
+ ```bash
+ bin/rake railties:install:migrations
+ bin/rails db:migrate
+ bin/rails db:seed
+ ```
+ </Accordion>
+
+ <Accordion icon="box" title="Adding sample data">
+
+ To add sample data to your store, run:
+
+ ```bash
+ bin/rake spree_sample:load
+ ```
+
+ This will add a some products, categories, and will setup a checkout flow to your store.
+ </Accordion>
+</AccordionGroup>
+
+## 3. Exploring Your Store
+
+Feel free to explore your store. You can do so because Spree comes with a default pre-built Storefront and Admin Panel.
+
+<AccordionGroup>
+ <Accordion icon="key" title="Logging into the Admin Dashboard">
+ Use your browser window to navigate to [http://localhost:3000/admin](http://localhost:3000/admin). You can log in with the default credentials:
+ - login: `[email protected]`
+ - password: `spree123`
+
+ Upon successful authentication, you should see the admin screen:
+
+ ![](/images/admin_panel_978-2x.jpg)
+
+ Feel free to explore some of the Admin Panel features that Spree has to offer and to verify that your installation is working properly.
+ </Accordion>
+
+ <Accordion icon="palette" title="Browsing Storefront">
+
+ Spree comes with a default pre-built Storefront. You can access it by navigating to [http://localhost:3000](http://localhost:3000).
+
+ You can later customize this Storefront or choose another one if you prefer Next.js or Vue.js.
+
+ </Accordion>
+</AccordionGroup>
+
+### All Done!
+
+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 [[email protected]](mailto:[email protected]).
diff --git a/docs/developer/getting-started/quickstart.mdx b/docs/developer/getting-started/quickstart.mdx
index 46e27ee5a8..3da241d16e 100644
--- a/docs/developer/getting-started/quickstart.mdx
+++ b/docs/developer/getting-started/quickstart.mdx
@@ -16,6 +16,10 @@ description: 'Start building awesome e-commerce applications with Spree'
Welcome to the Spree Commerce documentation guide. Follow the instructions below to learn how to build and deploy your Spree Commerce store.
+<Info>
+ If you want to add Spree to your existing Rails application, you can skip this page and go to the [Adding to an existing Rails app](adding_spree_to_rails_app) section.
+</Info>
+
### 1. Installing Spree
<AccordionGroup>
diff --git a/docs/mint.json b/docs/mint.json
index 28d792481b..cdc277e5c4 100644
--- a/docs/mint.json
+++ b/docs/mint.json
@@ -72,7 +72,8 @@
{
"group": "Getting started",
"pages": [
- "developer/getting-started/quickstart"
+ "developer/getting-started/quickstart",
+ "developer/getting-started/adding_spree_to_rails_app"
]
},
{
@@ -102,7 +103,8 @@
"developer/customization/checkout",
"developer/customization/permissions",
"developer/customization/dependencies",
- "developer/customization/decorators"
+ "developer/customization/decorators",
+ "developer/customization/routes"
]
},