From 53e5214e881a5e34dec9b346b57b983c55695fbc Mon Sep 17 00:00:00 2001 From: jacob Date: Thu, 15 Nov 2018 13:30:12 -0600 Subject: [PATCH 1/2] Expand the promotion rules implementation example --- .../promotions/promotion-rules.html.md | 32 ++++++++++++++++--- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/guides/source/developers/promotions/promotion-rules.html.md b/guides/source/developers/promotions/promotion-rules.html.md index 534301b6087..7d998cff06f 100644 --- a/guides/source/developers/promotions/promotion-rules.html.md +++ b/guides/source/developers/promotions/promotion-rules.html.md @@ -103,9 +103,31 @@ You must then register the custom rule in an initializer in your Rails.application.config.spree.promotions.rules << Spree::Promotion::Rules::MyPromotionRule ``` - +The next step is displaying your custom rule in the Solidus admin promotions interface. + +Create a partial for your new rule in `app/views/spree/admin/promotions/rules/_my_promotion_rule.html.erb` + +This partial can be complex or simple. If you've created a simple rule, you can even leave it blank. This is where you can enable the user to set values for your new rule. Check out some of the rule partials provided with Solidus if you need inspiration. + +Finally, your new rule must have a name and description defined for any locales you will be using. You can also define custom error messages. For English, edit `config/locales/en.yml` and add the following: + +```yaml +en: + activerecord: + attributes: + spree/promotion/rules/my_promotion_rule: + # The description for the promotion rule + description: My promotion rule's description + models: + # The presentation name of the promotion rule + spree/promotion/rules/my_promotion_rule: My Promotion Rule + + # If you used a custom error message + spree: + eligibility_errors: + messages: + my_error_message: "This promotion cannot be applied." +``` + +After a server restart, the new rule will be available from the Solidus admin promotion interface. From a78c9bec2bdfc93d1bfdc16709293032f0b7399b Mon Sep 17 00:00:00 2001 From: jacob Date: Thu, 15 Nov 2018 13:32:41 -0600 Subject: [PATCH 2/2] Add a file path for the initializer --- guides/source/developers/promotions/promotion-rules.html.md | 1 + 1 file changed, 1 insertion(+) diff --git a/guides/source/developers/promotions/promotion-rules.html.md b/guides/source/developers/promotions/promotion-rules.html.md index 7d998cff06f..6c3221a955b 100644 --- a/guides/source/developers/promotions/promotion-rules.html.md +++ b/guides/source/developers/promotions/promotion-rules.html.md @@ -100,6 +100,7 @@ You must then register the custom rule in an initializer in your `config/initializers/` directory: ```ruby +# config/initializers/spree.rb Rails.application.config.spree.promotions.rules << Spree::Promotion::Rules::MyPromotionRule ```