-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add store promotion rule #2552
Merged
Merged
Add store promotion rule #2552
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
backend/app/views/spree/admin/promotions/rules/_store.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<div class="field"> | ||
<label><%= t("spree.store_rule.choose_stores" ) %></label> | ||
<%= select_tag "#{param_prefix}[store_ids][]", | ||
options_from_collection_for_select(Spree::Store.all, :id, :name, promotion_rule.store_ids), | ||
multiple: true, class: "select2 fullwidth" %> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
module Spree | ||
class Promotion | ||
module Rules | ||
class Store < PromotionRule | ||
has_many :promotion_rule_stores, class_name: "Spree::PromotionRuleStore", | ||
foreign_key: :promotion_rule_id, | ||
dependent: :destroy | ||
has_many :stores, through: :promotion_rule_stores, class_name: "Spree::Store" | ||
|
||
def applicable?(promotable) | ||
promotable.is_a?(Spree::Order) | ||
end | ||
|
||
def eligible?(order, _options = {}) | ||
stores.none? || stores.include?(order.store) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module Spree | ||
class PromotionRuleStore < Spree::Base | ||
self.table_name = "spree_promotion_rules_stores" | ||
|
||
belongs_to :promotion_rule, class_name: "Spree::PromotionRule" | ||
belongs_to :store, class_name: "Spree::Store" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
core/db/migrate/20180202190713_create_promotion_rule_stores.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
class CreatePromotionRuleStores < ActiveRecord::Migration[5.1] | ||
def change | ||
create_table :spree_promotion_rules_stores do |t| | ||
t.references :store, foreign_key: { to_table: "spree_stores" } | ||
t.references :promotion_rule, foreign_key: { to_table: "spree_promotion_rules" } | ||
|
||
t.timestamps | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
require "rails_helper" | ||
|
||
RSpec.describe Spree::Promotion::Rules::Store, type: :model do | ||
let(:rule) { described_class.new } | ||
|
||
context "#eligible?(order)" do | ||
let(:order) { Spree::Order.new } | ||
|
||
it "is eligible if no stores are provided" do | ||
expect(rule).to be_eligible(order) | ||
end | ||
|
||
it "is eligible if stores include the order's store" do | ||
default_store = Spree::Store.new(name: "Default") | ||
other_store = Spree::Store.new(name: "Other") | ||
|
||
rule.stores = [default_store, other_store] | ||
order.store = default_store | ||
|
||
expect(rule).to be_eligible(order) | ||
end | ||
|
||
it "is not eligible if order is placed in a different store" do | ||
default_store = Spree::Store.new(name: "Default") | ||
other_store = Spree::Store.new(name: "Other") | ||
|
||
rule.stores = [other_store] | ||
order.store = default_store | ||
|
||
expect(rule).not_to be_eligible(order) | ||
end | ||
end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it seems really weird to check
stores.none?
hereThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is a little odd. I'm not sure why it was originally written this way in
solidus_multi_domain
, but I figured it would be best to keep it the same.