solidus_sample 4.7.2 → 4.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c687ee43071b93a7602f68bc1a7f89436c935158906df60b4223776ddb4f1938
4
- data.tar.gz: d99baa4d375a92e94f304915bc835e4c0ea615d224283008952501e76b8402c9
3
+ metadata.gz: c07e22c80ab8197674c8d3d63fe28f6d55e37a1a0330094ff5821d4ce43ab9c3
4
+ data.tar.gz: 52d0d3e269bcdf51df19e271c3d98e957919094a8bb7b00083aa17f8139673c1
5
5
  SHA512:
6
- metadata.gz: aeeb7812e4bc5a5620bf80a1ce65defdd291a29e2653544ef5021acd8c54713e1399f11fcad9848d2fbdc62ffb87c63796349cca670c2d8e1ca4bc58d144e67d
7
- data.tar.gz: ffe4e2739b5b57793ce649abc0488e3c2986b7fbc7ead5b280f936fce67c07cda3c3c516b4c92369e4ab50238090bba6863f0f785eb4c51eadcfa596163baaa6
6
+ metadata.gz: fd73c0950043860b0b7927c071966210b4ebb6350c16fd97d43c0190f04e21be7008c9009abf60ded81023b0305074a1849eb16f8ce42865a17d9b9a8cf0101e
7
+ data.tar.gz: 38dcde6a2c3c3d270058fc9605f824a5237d0795cc2170303e89d64470bc046b1c47629e4686cbd6159df7e3e2bc8bc5b5793844e774de0159f17afb8adc8fd1
data/LICENSE CHANGED
@@ -1,6 +1,9 @@
1
1
  Copyright (c) 2007-2014, Spree Commerce, Inc. and other contributors
2
2
  All rights reserved.
3
3
 
4
+ Copyright (c) 2015-2026, Solidus contributors
5
+ All rights reserved.
6
+
4
7
  Redistribution and use in source and binary forms, with or without modification,
5
8
  are permitted provided that the following conditions are met:
6
9
 
@@ -5,8 +5,7 @@ new_york = Spree::State.find_by!(name: "New York")
5
5
 
6
6
  names = ["Sterling Torp", "Jennette Vandervort", "Salome Stroman", "Lyla Lang",
7
7
  "Lola Zulauf", "Cheree Bruen", "Hettie Torp", "Barbie Gutmann",
8
- "Amelia Renner", "Marceline Bergstrom", "Keeley Sauer", "Mi Gaylord",
9
- "Karon Mills", "Jessika Daugherty", "Emmy Stark"]
8
+ "Amelia Renner", "Marceline Bergstrom"]
10
9
  street_addresses = ["7377 Jacobi Passage", "4725 Serena Ridges",
11
10
  "79832 Hamill Creek", "0746 Genoveva Villages",
12
11
  "86717 D'Amore Hollow", "8529 Delena Well",
@@ -24,15 +23,15 @@ phone_numbers = ["(392)859-7319 x670", "738-831-3210 x6047",
24
23
  "(855)317-6523", "1-529-214-7315 x90865",
25
24
  "(662)877-7894 x703", "689.578.8564 x72399"]
26
25
 
27
- 2.times do
28
- Spree::Address.create!(
29
- name: names.sample,
30
- address1: street_addresses.sample,
31
- address2: secondary_addresses.sample,
32
- city: cities.sample,
26
+ names.length.times do |i|
27
+ Spree::Address.find_or_create_by!(
28
+ name: names[i],
29
+ address1: street_addresses[i],
30
+ address2: secondary_addresses[i],
31
+ city: cities[i],
33
32
  state: new_york,
34
33
  zipcode: 16_804,
35
34
  country: united_states,
36
- phone: phone_numbers.sample
35
+ phone: phone_numbers[i]
37
36
  )
38
37
  end
data/db/samples/assets.rb CHANGED
@@ -97,9 +97,17 @@ images = {
97
97
  ]
98
98
  }
99
99
 
100
+ def available_image_count(key, color)
101
+ index = 1
102
+ index += 1 while image("#{key}_#{color}_#{index}", "png")
103
+ index - 1
104
+ end
105
+
100
106
  products.each do |key, product|
101
107
  product.reload.variants.each do |variant|
102
108
  color = variant.option_value("clothing-color").downcase
109
+ next if variant.images.count >= available_image_count(key, color)
110
+
103
111
  index = 1
104
112
 
105
113
  loop do
@@ -116,6 +124,8 @@ products.each do |key, product|
116
124
  end
117
125
 
118
126
  images.each do |variant, attachments|
127
+ next if variant.images.count >= attachments.length
128
+
119
129
  shell.say_status :sample, "images for #{variant.product.name}"
120
130
  attachments.each do |attachment|
121
131
  File.open(attachment[:attachment]) do |f|
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- Spree::OptionType.create!([
3
+ [
4
4
  {
5
5
  name: "clothing-size",
6
6
  presentation: "Size",
@@ -11,4 +11,8 @@ Spree::OptionType.create!([
11
11
  presentation: "Color",
12
12
  position: 2
13
13
  }
14
- ])
14
+ ].each do |attrs|
15
+ Spree::OptionType.find_or_create_by!(name: attrs[:name]) do |option_type|
16
+ option_type.assign_attributes(attrs)
17
+ end
18
+ end
@@ -5,7 +5,7 @@ Spree::Sample.load_sample("option_types")
5
5
  size = Spree::OptionType.find_by!(presentation: "Size")
6
6
  color = Spree::OptionType.find_by!(presentation: "Color")
7
7
 
8
- Spree::OptionValue.create!([
8
+ [
9
9
  {
10
10
  name: "Small",
11
11
  presentation: "S",
@@ -54,4 +54,8 @@ Spree::OptionValue.create!([
54
54
  position: 4,
55
55
  option_type: color
56
56
  }
57
- ])
57
+ ].each do |attrs|
58
+ Spree::OptionValue.find_or_create_by!(name: attrs[:name], option_type: attrs[:option_type]) do |option_value|
59
+ option_value.assign_attributes(attrs)
60
+ end
61
+ end
data/db/samples/orders.rb CHANGED
@@ -8,42 +8,44 @@ store = Spree::Store.first!
8
8
 
9
9
  orders = []
10
10
 
11
- orders << Spree::Order.create!(
12
- number: "R123456789",
13
- email: "spree@example.com",
14
- item_total: 150.95,
15
- adjustment_total: 150.95,
16
- total: 301.90,
17
- ship_address: Spree::Address.first,
18
- bill_address: Spree::Address.last
19
- )
20
-
21
- orders << Spree::Order.create!(
22
- number: "R987654321",
23
- email: "spree@example.com",
24
- item_total: 15.95,
25
- adjustment_total: 15.95,
26
- total: 31.90,
27
- ship_address: Spree::Address.first,
28
- bill_address: Spree::Address.last
29
- )
30
-
31
- orders[0].line_items.create!(
32
- variant: Spree::Product.find_by!(name: "Solidus Water Bottle").master,
33
- quantity: 1,
34
- price: 15.99
35
- )
36
-
37
- orders[1].line_items.create!(
38
- variant: Spree::Product.find_by!(name: "Solidus cap").master,
39
- quantity: 1,
40
- price: 22.99
41
- )
11
+ orders << Spree::Order.find_or_create_by!(number: "R123456789") do |order|
12
+ order.email = "spree@example.com"
13
+ order.item_total = 150.95
14
+ order.adjustment_total = 150.95
15
+ order.total = 301.90
16
+ order.ship_address = Spree::Address.first
17
+ order.bill_address = Spree::Address.last
18
+ end
19
+
20
+ orders << Spree::Order.find_or_create_by!(number: "R987654321") do |order|
21
+ order.email = "spree@example.com"
22
+ order.item_total = 15.95
23
+ order.adjustment_total = 15.95
24
+ order.total = 31.90
25
+ order.ship_address = Spree::Address.first
26
+ order.bill_address = Spree::Address.last
27
+ end
28
+
29
+ orders[0].line_items.find_or_create_by!(
30
+ variant: Spree::Product.find_by!(name: "Solidus Water Bottle").master
31
+ ) do |line_item|
32
+ line_item.quantity = 1
33
+ line_item.price = 15.99
34
+ end
35
+
36
+ orders[1].line_items.find_or_create_by!(
37
+ variant: Spree::Product.find_by!(name: "Solidus cap").master
38
+ ) do |line_item|
39
+ line_item.quantity = 1
40
+ line_item.price = 22.99
41
+ end
42
42
 
43
43
  orders.each do |order|
44
- order.payments.create!(payment_method:)
44
+ order.payments.find_or_create_by!(payment_method:)
45
45
  order.update(store:)
46
46
 
47
- order.next! until order.can_complete?
48
- order.complete!
47
+ unless order.completed?
48
+ order.next! until order.can_complete?
49
+ order.complete!
50
+ end
49
51
  end
@@ -1,17 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- Spree::PaymentMethod::BogusCreditCard.create!(
4
- {
5
- name: "Credit Card",
6
- description: "Bogus payment gateway",
7
- active: true
8
- }
9
- )
3
+ Spree::PaymentMethod::BogusCreditCard.find_or_create_by!(name: "Credit Card") do |payment_method|
4
+ payment_method.description = "Bogus payment gateway"
5
+ payment_method.active = true
6
+ end
10
7
 
11
- Spree::PaymentMethod::Check.create!(
12
- {
13
- name: "Check",
14
- description: "Pay by check.",
15
- active: true
16
- }
17
- )
8
+ Spree::PaymentMethod::Check.find_or_create_by!(name: "Check") do |payment_method|
9
+ payment_method.description = "Pay by check."
10
+ payment_method.active = true
11
+ end
@@ -7,11 +7,17 @@ method = Spree::PaymentMethod.where(name: "Credit Card", active: true).first
7
7
  # reference it as such. Make it explicit here that this table has been renamed.
8
8
  Spree::CreditCard.table_name = "spree_credit_cards"
9
9
 
10
- creditcard = Spree::CreditCard.create(cc_type: "visa", month: 12, year: 2.years.from_now.year, last_digits: "1111",
11
- name: "Sean Schofield", gateway_customer_profile_id: "BGS-1234")
10
+ creditcard = Spree::CreditCard.find_or_create_by!(cc_type: "visa", last_digits: "1111", name: "Sean Schofield") do |cc|
11
+ cc.month = 12
12
+ cc.year = 2.years.from_now.year
13
+ cc.gateway_customer_profile_id = "BGS-1234"
14
+ end
12
15
 
13
16
  Spree::Order.all.each_with_index do |order, _index|
14
17
  order.recalculate
15
- payment = order.payments.create!(amount: order.total, source: creditcard.clone, payment_method: method)
16
- payment.update_columns(state: "pending", response_code: "12345")
18
+ payment = order.payments.find_or_create_by!(payment_method: method) do |p|
19
+ p.amount = order.total
20
+ p.source = creditcard.clone
21
+ end
22
+ payment.update_columns(state: "pending", response_code: "12345") if payment.previously_new_record?
17
23
  end
@@ -181,15 +181,17 @@ products = [
181
181
  ]
182
182
 
183
183
  products.each do |product_attrs|
184
+ next if Spree::Product.exists?(name: product_attrs[:name])
185
+
184
186
  eur_price = product_attrs.delete(:eur_price)
185
- Spree::Config[:currency] = "USD"
187
+ Spree::Config.currency = "USD"
186
188
 
187
189
  product = Spree::Product.create!(default_attrs.merge(product_attrs))
188
- Spree::Config[:currency] = "EUR"
190
+ Spree::Config.currency = "EUR"
189
191
  product.reload
190
192
  product.price = eur_price
191
193
  product.shipping_category = shipping_category
192
194
  product.save!
193
195
  end
194
196
 
195
- Spree::Config[:currency] = "USD"
197
+ Spree::Config.currency = "USD"
@@ -16,31 +16,46 @@ end
16
16
  # Mark the order paid and shipped
17
17
  order.payments.pending.each(&:complete)
18
18
  order.shipments.each do |shipment|
19
+ next if shipment.shipped?
20
+
19
21
  shipment.suppress_mailer = false
20
22
  shipment.ship!
21
23
  end
24
+ inventory_unit.reload
22
25
 
23
26
  # Create a return authorization
24
- return_item = Spree::ReturnItem.new(
25
- inventory_unit:,
26
- preferred_reimbursement_type:
27
- )
27
+ return_authorization = order.return_authorizations.first
28
+
29
+ if return_authorization.nil?
30
+ return_item = Spree::ReturnItem.new(
31
+ inventory_unit:,
32
+ preferred_reimbursement_type:
33
+ )
34
+
35
+ return_authorization = order.return_authorizations.create!(
36
+ reason: return_reason,
37
+ return_items: [return_item],
38
+ stock_location:
39
+ )
40
+ end
28
41
 
29
- order.return_authorizations.create!(
30
- reason: return_reason,
31
- return_items: [return_item],
32
- stock_location:
33
- )
42
+ return_item = return_authorization.return_items.first
34
43
 
35
44
  # Create a customer return and mark it as received
36
- customer_return = Spree::CustomerReturn.create!(
37
- return_items: [return_item],
38
- stock_location:
39
- )
40
- return_item.reload
41
- return_item.receive!
42
- customer_return.process_return!
45
+ customer_return = return_item&.customer_return
46
+
47
+ if customer_return.nil?
48
+ customer_return = Spree::CustomerReturn.create!(
49
+ return_items: [return_item],
50
+ stock_location:
51
+ )
52
+ return_item.reload
53
+ return_item.receive! unless return_item.received?
54
+ customer_return.process_return!
55
+ end
43
56
 
44
57
  # Accept the customer return and reimburse it
45
- reimbursement = Spree::Reimbursement.build_from_customer_return(customer_return)
46
- reimbursement.return_all(created_by: admin_user)
58
+ if customer_return.reimbursements.empty?
59
+ reimbursement = Spree::Reimbursement.build_from_customer_return(customer_return)
60
+ reimbursement.return_all(created_by: admin_user)
61
+ end
@@ -12,43 +12,42 @@ tax_category = Spree::TaxCategory.find_by!(name: "Default")
12
12
  europe_vat = Spree::Zone.find_by!(name: "EU_VAT")
13
13
  shipping_category = Spree::ShippingCategory.find_or_create_by!(name: "Default")
14
14
 
15
- Spree::ShippingMethod.create!([
15
+ [
16
16
  {
17
17
  name: "UPS Ground (USD)",
18
18
  zones: [north_america],
19
- calculator: Spree::Calculator::Shipping::FlatRate.create!,
20
19
  tax_category:,
21
20
  shipping_categories: [shipping_category]
22
21
  },
23
22
  {
24
23
  name: "UPS Two Day (USD)",
25
24
  zones: [north_america],
26
- calculator: Spree::Calculator::Shipping::FlatRate.create!,
27
25
  tax_category:,
28
26
  shipping_categories: [shipping_category]
29
27
  },
30
28
  {
31
29
  name: "UPS One Day (USD)",
32
30
  zones: [north_america],
33
- calculator: Spree::Calculator::Shipping::FlatRate.create!,
34
31
  tax_category:,
35
32
  shipping_categories: [shipping_category]
36
33
  },
37
34
  {
38
35
  name: "UPS Ground (EU)",
39
36
  zones: [europe_vat],
40
- calculator: Spree::Calculator::Shipping::FlatRate.create!,
41
37
  tax_category:,
42
38
  shipping_categories: [shipping_category]
43
39
  },
44
40
  {
45
41
  name: "UPS Ground (EUR)",
46
42
  zones: [europe_vat],
47
- calculator: Spree::Calculator::Shipping::FlatRate.create!,
48
43
  tax_category:,
49
44
  shipping_categories: [shipping_category]
50
45
  }
51
- ])
46
+ ].each do |attrs|
47
+ Spree::ShippingMethod.find_or_create_by!(name: attrs[:name]) do |shipping_method|
48
+ shipping_method.assign_attributes(attrs.merge(calculator: Spree::Calculator::Shipping::FlatRate.create!))
49
+ end
50
+ end
52
51
 
53
52
  {
54
53
  "UPS Ground (USD)" => [5, "USD"],
data/db/samples/stock.rb CHANGED
@@ -7,8 +7,12 @@ location = Spree::StockLocation.first_or_create! name: "default", address1: "Exa
7
7
  location.active = true
8
8
  location.save!
9
9
 
10
+ initial_stock_quantity = 10
11
+
10
12
  Spree::Variant.all.find_each do |variant|
11
13
  variant.stock_items.each do |stock_item|
12
- Spree::StockMovement.create(quantity: 10, stock_item:)
14
+ next if stock_item.stock_movements.exists?
15
+
16
+ Spree::StockMovement.create!(quantity: initial_stock_quantity, stock_item:)
13
17
  end
14
18
  end
@@ -2,14 +2,15 @@
2
2
 
3
3
  north_america = Spree::Zone.find_by!(name: "North America")
4
4
  clothing = Spree::TaxCategory.find_by!(name: "Default")
5
- tax_rate = Spree::TaxRate.create(
6
- name: "North America",
7
- zone: north_america,
8
- amount: 0.05
9
- )
10
- tax_rate.calculator = Spree::Calculator::DefaultTax.create!
11
- tax_rate.save!
12
- Spree::TaxRateTaxCategory.create!(
5
+ tax_rate = Spree::TaxRate.find_or_initialize_by(name: "North America", zone: north_america)
6
+
7
+ if tax_rate.new_record?
8
+ tax_rate.amount = 0.05
9
+ tax_rate.calculator = Spree::Calculator::DefaultTax.create!
10
+ tax_rate.save!
11
+ end
12
+
13
+ Spree::TaxRateTaxCategory.find_or_create_by!(
13
14
  tax_rate:,
14
15
  tax_category: clothing
15
16
  )
@@ -6,5 +6,5 @@ taxonomies = [
6
6
  ]
7
7
 
8
8
  taxonomies.each do |taxonomy_attrs|
9
- Spree::Taxonomy.create!(taxonomy_attrs)
9
+ Spree::Taxonomy.find_or_create_by!(taxonomy_attrs)
10
10
  end
data/db/samples/taxons.rb CHANGED
@@ -119,7 +119,13 @@ taxons = [
119
119
 
120
120
  taxons.each do |taxon_attrs|
121
121
  if taxon_attrs[:parent]
122
- taxon_attrs[:parent] = Spree::Taxon.find_by!(name: taxon_attrs[:parent])
123
- Spree::Taxon.create!(taxon_attrs)
122
+ # parent lookup is scoped to the taxonomy to avoid ambiguity between same-named taxons
123
+ taxon_attrs[:parent] = taxon_attrs[:taxonomy].taxons.find_by!(name: taxon_attrs[:parent])
124
+ products = taxon_attrs.delete(:products) || []
125
+
126
+ taxon = Spree::Taxon.find_or_create_by!(taxon_attrs.slice(:name, :taxonomy, :parent)) do |t|
127
+ t.assign_attributes(taxon_attrs)
128
+ end
129
+ taxon.products |= products
124
130
  end
125
131
  end
@@ -322,7 +322,11 @@ masters = {
322
322
  }
323
323
  }
324
324
 
325
- Spree::Variant.create!(variants)
325
+ variants.each do |variant_attrs|
326
+ Spree::Variant.find_or_create_by!(sku: variant_attrs[:sku]) do |variant|
327
+ variant.assign_attributes(variant_attrs)
328
+ end
329
+ end
326
330
 
327
331
  masters.each do |product, variant_attrs|
328
332
  product.master.update!(variant_attrs)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solidus_sample
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.7.2
4
+ version: 4.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Solidus Team
@@ -15,14 +15,14 @@ dependencies:
15
15
  requirements:
16
16
  - - '='
17
17
  - !ruby/object:Gem::Version
18
- version: 4.7.2
18
+ version: 4.8.0
19
19
  type: :runtime
20
20
  prerelease: false
21
21
  version_requirements: !ruby/object:Gem::Requirement
22
22
  requirements:
23
23
  - - '='
24
24
  - !ruby/object:Gem::Version
25
- version: 4.7.2
25
+ version: 4.8.0
26
26
  description: Sample data (including images) for use with Solidus.
27
27
  email: contact@solidus.io
28
28
  executables: []
@@ -100,7 +100,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
100
100
  - !ruby/object:Gem::Version
101
101
  version: 1.8.23
102
102
  requirements: []
103
- rubygems_version: 4.0.10
103
+ rubygems_version: 4.0.20
104
104
  specification_version: 4
105
105
  summary: Sample data (including images) for use with Solidus.
106
106
  test_files: []