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] update dev docs

Damian Legawiec2a6bd9b46eb1
diff --git a/docs/developer/contributing/creating-an-extension.mdx b/docs/developer/contributing/creating-an-extension.mdx
index a8956f762c..17e0883106 100644
--- a/docs/developer/contributing/creating-an-extension.mdx
+++ b/docs/developer/contributing/creating-an-extension.mdx
@@ -11,13 +11,7 @@ description: Learn how to create a Spree extension.
Let's build a simple extension. Suppose we want the ability to mark certain products as being on sale. We'd like to be able to set a sale price on a product and show products that are on sale on a separate products page. This is a great example of how an extension can be used to build on the solid Spree foundation.
-Before we start, let's make sure we have Spree CLI installed by running:
-
-```bash
-gem install spree_cli
-```
-
-So let's start by generating the extension. Run the following command from a directory of your choice outside of our Spree application:
+Run the following command from a directory of your choice outside of our Spree application:
```bash
spree extension simple_sales
@@ -83,23 +77,21 @@ Now we need to extend `Spree::HomeController` and add an action that selects "on
Make sure you are in the `spree_simple_sales` root directory and run the following command to create the directory structure for our controller decorator:
```bash
-mkdir -p app/controllers/spree_simple_sales/spree
+mkdir -p app/controllers/spree_simple_sales
```
Next, create a new file in the directory we just created called `home_controller_decorator.rb` and add the following content to it:
```ruby
module SpreeSimpleSales
- module Spree
- module HomeControllerDecorator
- def sale
- @products = ::Spree::Product.joins(:variants_including_master).where('spree_variants.sale_price is not null').distinct
- end
+ module HomeControllerDecorator
+ def sale
+ @products = Spree::Product.joins(:variants_including_master).where.not(sale_price: nil).distinct
end
end
end
-Spree::HomeController.prepend SpreeSimpleSales::Spree::HomeControllerDecorator
+Spree::HomeController.prepend SpreeSimpleSales::HomeControllerDecorator
```
This will select just the products that have a variant with a `sale_price` set.
@@ -142,27 +134,19 @@ Now, follow the steps I take in selecting a product and updating its master vari
Let's fix our extension so that it uses the `sale_price` when it is present.
-First, create the required directory structure for our new decorator:
-
-```bash
-mkdir -p app/models/spree_simple_sales/spree
-```
-
-Next, create the file `app/models/spree_simple_sales/spree/variant_decorator.rb` and add the following content to it:
+Next, create the file `app/models/spree_simple_sales/variant_decorator.rb` and add the following content to it:
```ruby
module SpreeSimpleSales
- module Spree
- module VariantDecorator
- def price_in(currency)
- return super unless sale_price.present?
- ::Spree::Price.new(variant_id: self.id, amount: self.sale_price, currency: currency)
- end
+ module VariantDecorator
+ def price_in(currency)
+ return super unless sale_price.present?
+ Spree::Price.new(variant_id: self.id, amount: self.sale_price, currency: currency)
end
end
end
-Spree::Variant.prepend SpreeSimpleSales::Spree::VariantDecorator
+Spree::Variant.prepend SpreeSimpleSales::VariantDecorator
```
If there is a `sale_price` present on the product's master variant, we return that price. Otherwise, we call the original implementation of `price_in` using `return super`.
diff --git a/docs/developer/contributing/developing-spree.mdx b/docs/developer/contributing/developing-spree.mdx
index 0e68dda5e5..002a01e1ee 100644
--- a/docs/developer/contributing/developing-spree.mdx
+++ b/docs/developer/contributing/developing-spree.mdx
@@ -195,7 +195,7 @@ This section will help you troubleshoot common issues with Spree.
#### libvips error
-If you are using Spree 4.5 or higher, you may encounter the following libvips error:
+If you encounter the following libvips error:
```bash
LoadError: Could not open library 'vips.so.42'
diff --git a/docs/developer/contributing/quickstart.mdx b/docs/developer/contributing/quickstart.mdx
index 7ea5af020b..34ad08b5a3 100644
--- a/docs/developer/contributing/quickstart.mdx
+++ b/docs/developer/contributing/quickstart.mdx
@@ -23,10 +23,6 @@ To find issues you can tackle on we recommend visiting [Spree Contribute page](h
Extensions provide additional features and integrations for your Spree store. You can create your own and share with the rest of the community. Before doing so please check our [Extension directory](/developer/customization/extensions) if your desired extension does not exist already. If not [follow Extensions tutorial](../contributing/extensions_tutorial) to learn how to create one.
-## Upgrading old extensions to recent Spree versions
-
-If you found an extension that does not work with the current Spree version you can read the [Updating Extensions for Spree guide](updating-extensions) to bring it up to speed.
-
## Helping others on Spree slack
Last but not least, you're invited to [join our slack](http://slack.spreecommerce.org) to help and receive guidance from fellow Spree developers including Spree Core Team.
diff --git a/docs/developer/contributing/updating-extensions.mdx b/docs/developer/contributing/updating-extensions.mdx
index e12fb24f39..415ca7d866 100644
--- a/docs/developer/contributing/updating-extensions.mdx
+++ b/docs/developer/contributing/updating-extensions.mdx
@@ -1,6 +1,7 @@
---
title: Updating Extensions
description: How to upgrade your Spree extension to work with Spree 4
+version: v4
---
## Zeitwerk compatibility
diff --git a/docs/developer/customization/decorators.mdx b/docs/developer/customization/decorators.mdx
index b71efa03c5..45c3369cd7 100644
--- a/docs/developer/customization/decorators.mdx
+++ b/docs/developer/customization/decorators.mdx
@@ -65,17 +65,19 @@ end
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 g migration CreateSpreeVideos url:string product:references
bin/rails db:migrate
```
-In the model code add the association to `Spree::Product`:
+Create a model and add the association to `Spree::Product`:
```ruby
-class Video < ApplicationRecord
- belongs_to :product, class_name: 'Spree::Product'
+module Spree
+ class Video < Spree.base_class
+ belongs_to :product, class_name: 'Spree::Product'
- has_one_attached :video_file
+ has_one_attached :video_file
+ end
end
```
@@ -85,7 +87,7 @@ Finally add the association in `ProductDecorator` in `app/models/spree/product_d
module Spree
module ProductDecorator
def self.prepended(base)
- base.has_many :videos, class_name: 'Video', foreign_key: 'product_id', dependent: :destroy
+ base.has_many :videos, class_name: 'Spree::Video', dependent: :destroy
end
end