valken-shipping 2.0.6 → 2.1.1

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: facbbed02fb6c396fc8d3ac4b5337f594e2de0cbe20e8fd37b0ff7306a447ad5
4
- data.tar.gz: 96c4bd79d896be2a57108a03ee97eb79ba9115899fa0697cf48d7ba4e22cdaf9
3
+ metadata.gz: b7149c7876c47dd7fd68ee128eb7f413d94ee777701a28a2c9e91359d1da6695
4
+ data.tar.gz: a7758713ae839296e086eed9aa57cf5532f00dabfe446b20d0e5f817b1fb3e12
5
5
  SHA512:
6
- metadata.gz: 8a787f46ac3afab8fb25d440947ed897fe6bbae8e5c24166ef4446bbbe7144e9e2784dc64144bf90ab27a04245ca62ca75a071584e03d405ba24fcb8735afcfa
7
- data.tar.gz: 7ca413454ff6e3d406101074318ea9e3313d051f676fd1a1b69ddc66d1d2aff0c40d9ecf64fb35a1680b27726071f4e37e076d3a1778fe24f8ceb24d1af51e7f
6
+ metadata.gz: 0a84318084bb273cb89745cff6b41cbcea9987fde4efce13a4b4f6c7357520335c701143aca2fd650b1de8a45be9033d34ab603749a4850d50413336267d5c61
7
+ data.tar.gz: 861c462c265b64a73481507abcf63694d0adb60e280459a3741521885b588206f60d84327006180c8a92a428827bf061d67223579e9fd2150e56c13fba3d63da
@@ -12,7 +12,14 @@ module Workarea
12
12
  .map { |id, region| [region.translations[I18n.locale.to_s] || region.name, id] }
13
13
  .sort_by { |name, id| name || id }
14
14
 
15
- memo << [country.name, regions]
15
+ if country.name == "United States of America"
16
+ region = regions.reject do |state|
17
+ Workarea.config.shipping_state_exclude.include?(state.last)
18
+ end
19
+ memo << [country.name, region]
20
+ else
21
+ memo << [country.name, regions]
22
+ end
16
23
  memo
17
24
  end
18
25
  end
@@ -40,7 +47,6 @@ module Workarea
40
47
  postalcode: address.postal_code,
41
48
  country: address.country.alpha2
42
49
  }
43
-
44
50
  address_format = address.country.address_format || Country['US'].address_format
45
51
  result = pieces.reduce(address_format) do |memo, (name, value)|
46
52
  memo.gsub(/{{#{name}}}/, html_escape(value.to_s))
@@ -41,6 +41,10 @@ module Workarea
41
41
 
42
42
  return default_options(packaging.packages) if Workarea.config.gateways.ups_carrier.class == ActiveShipping::Workarea
43
43
 
44
+ if is_special_region?
45
+ return [get_shipping_for_special_region]
46
+ end
47
+
44
48
  shipping_options_api = get_final_shipping_options(collect_carrier_data)
45
49
  return [] if @error.present?
46
50
 
@@ -48,7 +52,7 @@ module Workarea
48
52
 
49
53
  if Workarea.config.gateways.ups_carrier.class != ActiveShipping::Workarea
50
54
  carrier_data.push(get_ltl_shipping)
51
- carrier_data.push(get_free_shipping) if Workarea.config.show_free_shipping
55
+ carrier_data.push(get_free_shipping) if is_free_ship
52
56
  else
53
57
  return []
54
58
  end
@@ -151,6 +155,30 @@ module Workarea
151
155
  )
152
156
  end
153
157
 
158
+ def get_shipping_for_special_region
159
+ puts "weight_convertion",weight_convertion
160
+ weight_price = 0
161
+ case weight_convertion
162
+ when 0..15
163
+ weight_price = 50
164
+ when 15..200
165
+ weight_price = (1 * weight_convertion)
166
+ when 200..2500
167
+ weight_price = 200
168
+ else
169
+ weight_price = ((weight_convertion / 2500).ceil()) * 200
170
+ end
171
+
172
+ ShippingOption.new(
173
+ carrier: "LTL Shipping",
174
+ name: "Valken Standard",
175
+ sub_name: "3 - 5 Business Days",
176
+ service_code: "LTL01",
177
+ price: Money.new(weight_price * 100, "USD"),
178
+ tax_code: "TAX01"
179
+ )
180
+ end
181
+
154
182
  # Returns the total weight.
155
183
  def weight_convertion
156
184
  packaging = Packaging.new(order, shipping)
@@ -253,7 +281,32 @@ module Workarea
253
281
  product_carrier_type = product_details.map{ |item| item[:en][ground_ship_attribute] }.flatten
254
282
  product_carrier_type.include?("true")
255
283
  end
256
-
284
+
285
+ def is_special_region?
286
+ Workarea.config.special_region.include?(@shipping.address.region)
287
+ end
288
+
289
+ # if any of the product is NO FREE SHIPPING = TRUE then return false
290
+ # if free shipping config is then return true
291
+ # if user applies free shipping promo code then return true
292
+ def is_free_ship
293
+ free_ship_attribute = Workarea.config.shipping_attributes[:no_free_shipping]
294
+ product_carrier_type = product_details.map{ |item| item[:en][free_ship_attribute] }.flatten
295
+ return false if product_carrier_type.include?("true")
296
+
297
+ return true if Workarea.config.show_free_shipping
298
+
299
+ test_order = order.clone
300
+ test_shipping = shipping.clone
301
+ test_shipping.apply_shipping_service(get_free_shipping.to_h)
302
+
303
+ price_adjustments = Pricing.find_shipping_discounts(
304
+ test_order,
305
+ test_shipping
306
+ )
307
+ return price_adjustments.present? && price_adjustments.any?
308
+ end
309
+
257
310
  def product_details
258
311
  # product_attributes = @order.items.map(&:product_attributes)
259
312
 
@@ -5,8 +5,14 @@ Workarea::Configuration.define_fields do
5
5
  default: {
6
6
  'usa_only' => 'usa only',
7
7
  'carrier_type' => 'Type',
8
- 'ground_shipping_only' => 'ground shipping only'
8
+ 'ground_shipping_only' => 'ground shipping only',
9
+ 'no_free_shipping' => 'no free shipping'
9
10
  },
10
11
  description: 'Mapping of product details keys with shipping logic. Note: This maps only the keys not the values.'
12
+
13
+ field 'Shipping State Exclude',
14
+ type: :array,
15
+ default: ["AK", "HI", "PR"],
16
+ description: 'Shipping Excluded States'
11
17
  end
12
18
  end
@@ -1,5 +1,5 @@
1
1
  module Valken
2
2
  module Shipping
3
- VERSION = '2.0.6'
3
+ VERSION = '2.1.1'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: valken-shipping
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.6
4
+ version: 2.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - sushmitha02
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-09-18 00:00:00.000000000 Z
11
+ date: 2020-10-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails