solidus_brazilian_adaptations 1.0.4 → 1.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b356e4123169f20ef2402662b44ceddd5abb97b0b5168ca57f4877928e834b4e
4
- data.tar.gz: 249f242993eca97dd87c7db21cbde15976446274ceb6b56e318cfb841987e5f8
3
+ metadata.gz: abf9b101cad24f96d6b95af4b1c1587666d279a7ec9c38cd6eadf80588c2de3a
4
+ data.tar.gz: cea1c5c853b54b8b10dc962476b05fe04f2f9819155e14cf3e3c5931919c055e
5
5
  SHA512:
6
- metadata.gz: df81e4f22273092889875d3c9cd4b6bbec9779e241af27b869c960a49e5e8f7f3b6349d654ef43a1fc23692d0764bc56c157c2ba52b3f53bb6f13129cf68c30b
7
- data.tar.gz: c1ba5fbc771af841b50dc306e59da2daa85e55a00410bd313ed75309214aa1f86dc8d7a5997c6690df5ca4b2e36ae95669ec5f85539e6147b3e817fa859f5a67
6
+ metadata.gz: df1c8d4801d1a4c440c86ecdf94954145053cbbfd42ca61b365b4f93c22b6c38f0868645b73a0456bd9d0a07abc7b9c3bfb9038ed9998e1502e4a76e8dff15a2
7
+ data.tar.gz: 48da079873137eddebd6b0e1fdaf62605cd11446abaacff3641493429943395b3f187c2337382dad2f9be5c3921e7c0011a365ceefe6319283eab60732e0e5dc
data/db/seeds.rb ADDED
@@ -0,0 +1,18 @@
1
+ require 'thor'
2
+ shell = Thor::Base.shell.new
3
+
4
+ %w[
5
+ stores
6
+ store_credit
7
+ countries
8
+ return_reasons
9
+ states
10
+ stock_locations
11
+ refund_reasons
12
+ roles
13
+ shipping
14
+ payment
15
+ ].each do |seed|
16
+ shell.say_status :seed, seed
17
+ require_relative "spree_br/#{seed}"
18
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'carmen'
4
+
5
+ # Insert Countries into the spree_countries table, checking to ensure that no
6
+ # duplicates are created, using as few SQL statements as possible (2)
7
+
8
+ connection = Spree::Base.connection
9
+
10
+ country_mapper = ->(country) do
11
+ name = connection.quote country.name
12
+ iso3 = connection.quote country.alpha_3_code
13
+ iso = connection.quote country.alpha_2_code
14
+ iso_name = connection.quote country.name.upcase
15
+ numcode = connection.quote country.numeric_code
16
+ states_required = connection.quote country.subregions?
17
+
18
+ [name, iso3, iso, iso_name, numcode, states_required].join(", ")
19
+ end
20
+
21
+ country_values = -> do
22
+ carmen_countries = Carmen::Country.all
23
+
24
+ # find entires already in the database (so that we may ignore them)
25
+ existing_country_isos =
26
+ Spree::Country.where(iso: carmen_countries.map(&:alpha_2_code)).pluck(:iso)
27
+
28
+ # create VALUES statements for each country _not_ already in the database
29
+ carmen_countries
30
+ .reject { |c| existing_country_isos.include?(c.alpha_2_code) || c.alpha_2_code != 'BR' }
31
+ .map(&country_mapper)
32
+ .join("), (")
33
+ end
34
+
35
+ country_columns = %w(name iso3 iso iso_name numcode states_required).join(', ')
36
+ country_vals = country_values.call
37
+
38
+ if country_vals.present?
39
+ # execute raw SQL (insted of ActiveRecord.create) to use a single
40
+ # INSERT statement, and to avoid any validations or callbacks
41
+ connection.execute <<-SQL
42
+ INSERT INTO spree_countries (#{country_columns})
43
+ VALUES (#{country_vals});
44
+ SQL
45
+ end
@@ -0,0 +1,4 @@
1
+ Spree::PaymentMethod::Check.create!(
2
+ name: "Boleto",
3
+ available_to_users: true
4
+ )
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ Spree::RefundReason.find_or_create_by!(name: "Return processing", mutable: false)
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ Spree::ReturnReason.find_or_create_by(name: 'Better price available')
4
+ Spree::ReturnReason.find_or_create_by(name: 'Missed estimated delivery date')
5
+ Spree::ReturnReason.find_or_create_by(name: 'Missing parts or accessories')
6
+ Spree::ReturnReason.find_or_create_by(name: 'Damaged/Defective')
7
+ Spree::ReturnReason.find_or_create_by(name: 'Different from what was ordered')
8
+ Spree::ReturnReason.find_or_create_by(name: 'Different from description')
9
+ Spree::ReturnReason.find_or_create_by(name: 'No longer needed/wanted')
10
+ Spree::ReturnReason.find_or_create_by(name: 'Accidental order')
11
+ Spree::ReturnReason.find_or_create_by(name: 'Unauthorized purchase')
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ Spree::Role.where(name: "admin").first_or_create
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ category = Spree::ShippingCategory.find_or_create_by(name: "Default")
4
+ todo_brasil = Spree::Zone.find_or_create_by!(name: "todo_brasil", description: "Todo Brasil")
5
+ todo_brasil.zone_members.find_or_create_by!(zoneable: Spree::Country.find_by!(iso: "BR"))
6
+
7
+ Spree::ShippingMethod.create!(
8
+ name: "Coruja",
9
+ available_to_all: true,
10
+ code: "CRJ",
11
+ shipping_categories: [category],
12
+ calculator: Spree::Calculator::Shipping::FlatRate.create!(
13
+ preferred_amount: 20.0,
14
+ preferred_currency: "BRL"
15
+ ),
16
+ zones: [todo_brasil]
17
+ )
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ def create_states(subregions, country)
4
+ subregions.each do |subregion|
5
+ Spree::State.where(abbr: subregion.code, country: country).first_or_create!(
6
+ name: subregion.name
7
+ )
8
+ end
9
+ end
10
+
11
+ ActiveRecord::Base.transaction do
12
+ Spree::Country.all.find_each do |country|
13
+ carmen_country = Carmen::Country.coded(country.iso)
14
+ next unless carmen_country.subregions?
15
+
16
+ if Spree::Config[:countries_that_use_nested_subregions].include? country.iso
17
+ create_states(carmen_country.subregions.flat_map(&:subregions), country)
18
+ else
19
+ create_states(carmen_country.subregions, country)
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ Spree::StockLocation.create_with(backorderable_default: true)
4
+ .find_or_create_by!(name: 'default')
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+
4
+ Spree::PaymentMethod.create_with(
5
+ name: "Store Credit",
6
+ description: "Store credit",
7
+ active: true,
8
+ available_to_admin: false,
9
+ available_to_users: false
10
+ ).find_or_create_by!(
11
+ type: "Spree::PaymentMethod::StoreCredit"
12
+ )
13
+
14
+ Spree::StoreCreditType.create_with(priority: 1).find_or_create_by!(name: Spree::StoreCreditType::EXPIRING)
15
+ Spree::StoreCreditType.create_with(priority: 2).find_or_create_by!(name: Spree::StoreCreditType::NON_EXPIRING)
16
+
17
+ Spree::ReimbursementType.create_with(name: "Store Credit").find_or_create_by!(type: 'Spree::ReimbursementType::StoreCredit')
18
+ Spree::ReimbursementType.create_with(name: "Original").find_or_create_by!(type: 'Spree::ReimbursementType::OriginalPayment')
19
+
20
+ Spree::StoreCreditCategory.find_or_create_by!(name: Spree::StoreCreditCategory::GIFT_CARD)
21
+ Spree::StoreCreditCategory.find_or_create_by!(name: Spree::StoreCreditCategory::REIMBURSEMENT)
22
+
23
+ Spree::StoreCreditReason.find_or_create_by!(name: 'Credit Given In Error')
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ unless Spree::Store.where(code: 'sample-store').exists?
4
+ Spree::Store.create!(
5
+ name: "Sample Store",
6
+ code: "sample-store",
7
+ url: "example.com",
8
+ mail_from_address: "store@example.com"
9
+ )
10
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SolidusBrazilianAdaptations
4
- VERSION = "1.0.4"
4
+ VERSION = "1.0.5"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solidus_brazilian_adaptations
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - ulysses-bull
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-10-20 00:00:00.000000000 Z
11
+ date: 2023-10-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: solidus_core
@@ -102,6 +102,17 @@ files:
102
102
  - config/routes.rb
103
103
  - db/migrate/20230911133000_add_tax_id_to_spree_orders.rb
104
104
  - db/migrate/20230911133157_add_number_district_to_addresses.rb
105
+ - db/seeds.rb
106
+ - db/spree_br/countries.rb
107
+ - db/spree_br/payment.rb
108
+ - db/spree_br/refund_reasons.rb
109
+ - db/spree_br/return_reasons.rb
110
+ - db/spree_br/roles.rb
111
+ - db/spree_br/shipping.rb
112
+ - db/spree_br/states.rb
113
+ - db/spree_br/stock_locations.rb
114
+ - db/spree_br/store_credit.rb
115
+ - db/spree_br/stores.rb
105
116
  - lib/generators/solidus_brazilian_adaptations/install/install_generator.rb
106
117
  - lib/generators/solidus_brazilian_adaptations/install/templates/initializer.rb
107
118
  - lib/solidus_brazilian_adaptations.rb