solidus_me 3.0.2 → 3.2.0

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: 9ee90fa75f6efce0402e68f7992665696df6f0fc0fea34c1098489216bfa462d
4
- data.tar.gz: 130f9dec9c6ca3730f25a07e062d22172368967cf752ebce0c131cfbf418c56c
3
+ metadata.gz: 7038411a1992fbe76be03e3ea54363e0a9a53bb813377951dad557aa718f3e09
4
+ data.tar.gz: 710ff6fccbe6dd9c9419fae66cd9ae77e14acb44f7a6a559f5b046d2651e670a
5
5
  SHA512:
6
- metadata.gz: '08327213cb9db79a153e56150d7d70ad364148e28cfa4d92dc2c14e80199b27f1da0dc5e5dda75a78cbda68c49b1ccc70fb364359080130a51d8be0bbd27babd'
7
- data.tar.gz: c34ecfaa9435d0603d86e156a1d950463e7e187f59229b69bc1b74f4f09f114e882a9c86222b49eb5d37996f3b5cb286474d1e3b0bd864024a4b9dadf2659700
6
+ metadata.gz: 3d1d04d17d6f872b078bcd1a038bd048ad766bc8294a5ed075bf08e5f3b60af050234e15be9b92dd8b4040288591b54b04d7fd2406f0e8886f210392744f197c
7
+ data.tar.gz: bdb62ee68a0920a1cae31658760649bb4c5f6148f09afaa1a4d0920afc77323de282eea87d8ce97b2ffc387ad0cd5f09c06a1b8c65c1c51f0a0d029ef7b34142
@@ -44,7 +44,7 @@ module SolidusMe
44
44
  melhor_envio_rates = get_rates_from_melhor_envio(package)
45
45
  shipping_rates = melhor_envio_rates.map do |melhor_envio_rate|
46
46
  build_shipping_rate(melhor_envio_rate, package)
47
- end
47
+ end.compact
48
48
 
49
49
  shipping_rates
50
50
  end
@@ -70,14 +70,18 @@ module SolidusMe
70
70
  end
71
71
 
72
72
  def build_shipping_rate(melhor_envio_rate, package)
73
+ return unless melhor_envio_rate.max_delivery_time
73
74
  shipping_method = Spree::ShippingMethod.find_by(code: self.class.generate_code(melhor_envio_rate.id))
75
+ estimate_prose = "Chegará em até #{ActionController::Base.helpers.pluralize(melhor_envio_rate.max_delivery_time, "dia", plural: "dias")} úteis"
74
76
 
75
77
  Spree::ShippingRate.new(
76
78
  shipment: package.shipment,
77
79
  shipping_method: shipping_method,
78
80
  cost: melhor_envio_rate.price,
79
- min_delivery_time: (Time.now + melhor_envio_rate.delivery_range["min"].days),
80
- max_delivery_time: (Time.now + melhor_envio_rate.delivery_range["max"].days)
81
+ min_delivery_time: melhor_envio_rate.min_delivery_time.business_days.from_now,
82
+ max_delivery_time: melhor_envio_rate.max_delivery_time.business_days.from_now,
83
+ estimate_prose: estimate_prose,
84
+ expires_in: Time.now + 2.hours
81
85
  )
82
86
  end
83
87
 
@@ -32,7 +32,8 @@ module SolidusMe
32
32
  length_cm = length(variants)
33
33
 
34
34
  zipcode = package.order.ship_address.zipcode
35
- services = @me_account.services.blank? ? ["SEDEX", "PAC", "Mini Envios", ".Package", ".Com"] : @me_account.services
35
+ services = @me_account.services.presence || ["SEDEX", "PAC", "Mini Envios", ".Package",
36
+ ".Com"]
36
37
 
37
38
  rates = @me_client.rates(
38
39
  from: @me_account.postal_code_from,
@@ -41,7 +42,7 @@ module SolidusMe
41
42
  contents_value_brl: price
42
43
  )
43
44
  rates.select { |rate| rate.price > 0 && services.include?(rate.service_name) }
44
- rescue
45
+ rescue StandardError
45
46
  [default_rate]
46
47
  end
47
48
 
@@ -55,35 +56,40 @@ module SolidusMe
55
56
  shipping_method.shipping_categories = Spree::ShippingCategory.all
56
57
  shipping_method.available_to_users = true
57
58
  end
59
+ estimate_prose = "Chegará em até #{ActionController::Base.helpers.pluralize(melhor_envio_rate.max_delivery_time,
60
+ 'dia', plural: 'dias')} úteis"
58
61
 
59
62
  Spree::ShippingRate.new(
60
63
  shipment: package.shipment,
61
64
  shipping_method: shipping_method,
62
65
  cost: melhor_envio_rate.price,
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)
66
+ min_delivery_time: melhor_envio_rate.min_delivery_time.business_days.from_now,
67
+ max_delivery_time: melhor_envio_rate.max_delivery_time.business_days.from_now,
68
+ estimate_prose: estimate_prose,
69
+ expires_in: Time.now + 2.hours
65
70
  )
66
71
  end
67
72
 
68
73
  def default_rate
69
- default_rate = Data.define(:price, :service_name, :carrier_name, :delivery_range)
74
+ default_rate = Data.define(:price, :service_name, :carrier_name, :min_delivery_time, :max_delivery_time)
70
75
  default_rate.new(
71
76
  price: 15.00,
72
77
  service_name: "",
73
78
  carrier_name: "Frete padrão",
74
- delivery_range: {"min" => 5, "max" => 5}
79
+ min_delivery_time: 5,
80
+ max_delivery_time: 7,
75
81
  )
76
82
  end
77
83
 
78
- def height variants
84
+ def height(variants)
79
85
  variants.pluck(:height, :width, :depth).map(&:max).compact.max
80
86
  end
81
87
 
82
- def width variants
88
+ def width(variants)
83
89
  variants.pluck(:height, :width, :depth).map { |dimensions| dimensions.sort[1] }.compact.max
84
90
  end
85
91
 
86
- def length variants
92
+ def length(variants)
87
93
  variants.pluck(:height, :width, :depth).map(&:min).compact.sum
88
94
  end
89
95
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SolidusMe
4
- VERSION = "3.0.2"
4
+ VERSION = "3.2.0"
5
5
  end
data/lib/solidus_me.rb CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  require "me_api"
4
4
  require "solidus_brazilian_adaptations"
5
+ require "business_time"
5
6
  require "solidus_me/configuration"
6
7
  require "solidus_me/version"
7
8
  require "solidus_me/engine"
data/solidus_me.gemspec CHANGED
@@ -32,6 +32,7 @@ Gem::Specification.new do |spec|
32
32
  spec.add_dependency "solidus_support", "~> 0.5"
33
33
  spec.add_dependency "me_api"
34
34
  spec.add_dependency "solidus_brazilian_adaptations"
35
+ spec.add_dependency "business_time"
35
36
 
36
37
  spec.add_development_dependency "solidus_dev_support", "~> 2.7"
37
38
  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.2
4
+ version: 3.2.0
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-09-11 00:00:00.000000000 Z
11
+ date: 2024-10-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: solidus_core
@@ -72,6 +72,20 @@ dependencies:
72
72
  - - ">="
73
73
  - !ruby/object:Gem::Version
74
74
  version: '0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: business_time
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ type: :runtime
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
75
89
  - !ruby/object:Gem::Dependency
76
90
  name: solidus_dev_support
77
91
  requirement: !ruby/object:Gem::Requirement