solidus_me 3.0.0 → 3.0.2

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: 18b2087c7138f439e7653a3c01bb919fec8db078ad8581c9684f8129377c3a51
4
- data.tar.gz: c54e202d154f70b7f3124a5d86d6ca7d1af6626979d1ac4beb9672344bb6ea99
3
+ metadata.gz: 9ee90fa75f6efce0402e68f7992665696df6f0fc0fea34c1098489216bfa462d
4
+ data.tar.gz: 130f9dec9c6ca3730f25a07e062d22172368967cf752ebce0c131cfbf418c56c
5
5
  SHA512:
6
- metadata.gz: 65c235b6adc9de111a611df497368e8cee192c1c730812975b0bf5c9fde645d889aa9a9979ecbffd6d18b12d0325c5b928bc55af7832a2c83e934bbf2b138cf0
7
- data.tar.gz: f210df49830604944ce755fda0f83a664a088756c9ea89c5158650653ffb2ccfe403ec7e4bccac64b6028590751882d59827cce13087345eabe88b1a0a282a7d
6
+ metadata.gz: '08327213cb9db79a153e56150d7d70ad364148e28cfa4d92dc2c14e80199b27f1da0dc5e5dda75a78cbda68c49b1ccc70fb364359080130a51d8be0bbd27babd'
7
+ data.tar.gz: c34ecfaa9435d0603d86e156a1d950463e7e187f59229b69bc1b74f4f09f114e882a9c86222b49eb5d37996f3b5cb286474d1e3b0bd864024a4b9dadf2659700
@@ -1,13 +1,39 @@
1
1
  module SolidusMe
2
2
 
3
3
  class MelhorEnvio
4
-
4
+ SHIPPING_METHODS = [
5
+ { name: "Correios PAC", carrier: "Correios", service_level: "PAC", external_id: 1 },
6
+ { name: "Correios SEDEX", carrier: "Correios", service_level: "SEDEX", external_id: 2 },
7
+ { name: "Correios Mini Envios", carrier: "Correios", service_level: "Mini Envios", external_id: 17 },
8
+ { name: "Jadlog .Package", carrier: "Jadlog", service_level: ".Package", external_id: 3 },
9
+ { name: "Jadlog .Com", carrier: "Jadlog", service_level: ".Com", external_id: 4 }
10
+ ]
11
+
5
12
  attr_accessor :package, :shipping_methods
6
13
  def initialize(package, shipping_methods)
7
14
  @package = package
8
15
  @shipping_methods = shipping_methods
9
16
  end
10
17
 
18
+ def self.generate_code external_id
19
+ (self.name.underscore + "_#{external_id}").downcase
20
+ end
21
+
22
+ def self.install
23
+ SHIPPING_METHODS.each do |provider_method|
24
+ Spree::ShippingMethod.find_or_create_by(code: generate_code(provider_method[:external_id])) do |shipping_method|
25
+ shipping_method.name = provider_method[:name]
26
+ shipping_method.carrier = provider_method[:carrier]
27
+ shipping_method.service_level = provider_method[:service_level]
28
+ shipping_method.code = generate_code(provider_method[:external_id])
29
+ shipping_method.calculator = Spree::Calculator::Shipping::FlatRate.create
30
+ shipping_method.shipping_categories = [Spree::ShippingCategory.first]
31
+ shipping_method.available_to_users = false
32
+ shipping_method.provider_id = SolidusTecEstimator::Provider.find_by(class_name: self.to_s).id
33
+ end
34
+ end
35
+ end
36
+
11
37
  def shipping_rates
12
38
  @me_account = Account.first
13
39
  return [] if @me_account.blank?
@@ -19,7 +45,6 @@ module SolidusMe
19
45
  shipping_rates = melhor_envio_rates.map do |melhor_envio_rate|
20
46
  build_shipping_rate(melhor_envio_rate, package)
21
47
  end
22
- shipping_rates = shipping_rates.select { |rate| shipping_methods.include?(rate.shipping_method) }
23
48
 
24
49
  shipping_rates
25
50
  end
@@ -30,13 +55,8 @@ module SolidusMe
30
55
  price = package.contents.map { |content| content.price }.sum
31
56
  weight = package.weight
32
57
 
33
- variants = package.contents.map { |content| content.variant }
34
- height_cm = height(variants)
35
- width_cm = width(variants)
36
- length_cm = length(variants)
37
-
38
58
  zipcode = package.order.ship_address.zipcode
39
- services = @me_account.services.blank? ? ["SEDEX", "PAC", "Mini Envios", ".Package", ".Com"] : @me_account.services
59
+ available_shipping_method_codes = @shipping_methods.pluck(:code)
40
60
 
41
61
  rates = @me_client.rates(
42
62
  from: @me_account.postal_code_from,
@@ -44,22 +64,13 @@ module SolidusMe
44
64
  weight_kg: (weight / 1000.00),
45
65
  contents_value_brl: price
46
66
  )
47
- rates.select { |rate| rate.price > 0 && services.include?(rate.service_name) }
67
+ rates.select { |rate| rate.price > 0 && available_shipping_method_codes.include?(self.class.generate_code(rate.id)) }
48
68
  rescue
49
69
  []
50
70
  end
51
71
 
52
72
  def build_shipping_rate(melhor_envio_rate, package)
53
- shipping_method = Spree::ShippingMethod.find_or_create_by(
54
- carrier: melhor_envio_rate.carrier_name,
55
- service_level: melhor_envio_rate.service_name
56
- ) do |shipping_method|
57
- shipping_method.name = "#{melhor_envio_rate.carrier_name} #{melhor_envio_rate.service_name}"
58
- shipping_method.calculator = Spree::Calculator::Shipping::FlatRate.create
59
- shipping_method.shipping_categories = [Spree::ShippingCategory.first]
60
- shipping_method.available_to_users = true
61
- shipping_method.provider_id = SolidusTecEstimator::Provider.find_by(class_name: self.class.to_s).id
62
- end
73
+ shipping_method = Spree::ShippingMethod.find_by(code: self.class.generate_code(melhor_envio_rate.id))
63
74
 
64
75
  Spree::ShippingRate.new(
65
76
  shipment: package.shipment,
@@ -70,18 +81,6 @@ module SolidusMe
70
81
  )
71
82
  end
72
83
 
73
- def height variants
74
- variants.pluck(:height, :width, :depth).map(&:max).compact.max
75
- end
76
-
77
- def width variants
78
- variants.pluck(:height, :width, :depth).map { |dimensions| dimensions.sort[1] }.compact.max
79
- end
80
-
81
- def length variants
82
- variants.pluck(:height, :width, :depth).map(&:min).compact.sum
83
- end
84
-
85
84
  end
86
85
 
87
86
  end
@@ -60,8 +60,8 @@ module SolidusMe
60
60
  shipment: package.shipment,
61
61
  shipping_method: shipping_method,
62
62
  cost: melhor_envio_rate.price,
63
- min_delivery_time: melhor_envio_rate.delivery_range["min"],
64
- max_delivery_time: melhor_envio_rate.delivery_range["max"]
63
+ min_delivery_time: (Time.now + melhor_envio_rate.delivery_range["min"].days),
64
+ max_delivery_time: (Time.now + melhor_envio_rate.delivery_range["max"].days)
65
65
  )
66
66
  end
67
67
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SolidusMe
4
- VERSION = "3.0.0"
4
+ VERSION = "3.0.2"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solidus_me
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
4
+ version: 3.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hamilton Tumenas Borges
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-08-09 00:00:00.000000000 Z
11
+ date: 2024-09-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: solidus_core