Skip to content
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

Created promotion seed #8726

Merged
merged 1 commit into from May 14, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 23 additions & 0 deletions core/db/default/spree/promotions.rb
@@ -0,0 +1,23 @@
Spree::Sample.load_sample('option_values')
Spree::Sample.load_sample('products')

product = Spree::Product.find_by(name: 'Ruby on Rails Baseball Jersey')
size = Spree::OptionValue.find_by(name: 'Small')
color = Spree::OptionValue.find_by(name: 'Red')
eligible_values = "#{size.id},#{color.id}"

promotion = Spree::Promotion.where(
name: 'free shipping',
usage_limit: nil,
path: nil,
match_policy: 'any',
description: ''
).first_or_create

Spree::PromotionRule.where(
promotion_id: promotion.id,
type: 'Spree::Promotion::Rules::OptionValue',
preferences: { match_policy: 'any', eligible_values: { product.id.to_s => eligible_values } }
).first_or_create

Spree::Promotion::Actions::FreeShipping.where(promotion_id: promotion.id).first_or_create