spree_core 3.7.1 → 3.7.2

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: e0dd0bbc96d64d482272852915dfdbb1ddebc7a6cc219bd6401a6f589072a0fe
4
- data.tar.gz: 6daeb36116e792adae64e718e5026d3242f17cba858e0b14bd9b7fd1eca35a4f
3
+ metadata.gz: 2aebe22e0a667ec8af1d2d93c6e8b61e7632b42c3cd5daf6bf9854dce6e8de70
4
+ data.tar.gz: 6436afb8bd363314d87c59062354e62adae62c9ca871d4e61d2211bc59d8fffc
5
5
  SHA512:
6
- metadata.gz: ed5e760973d8dd27db03b90eab449a026b69bbe2fb2693ad2f0e5f9f80d1d725c734f90c80caf90c491da71efb1f2d7934b2c8868faf9541a6a2c6c0c1e75048
7
- data.tar.gz: 12bf3f8c265308aeae44d6953ab2b70ed7387038227948522cb6f7588744b618f1ccecabfc90c100e04fe8a1eb4b2e3d076aeb2096fe1bf6d9421eaaa3278652
6
+ metadata.gz: 9403530f8211a89b26b0d579176a44c444c63279311c996c5b737208dd4b6e952f5940ab8fb49c3290ae7f35efd7b36f17e42947572755746817471e266bfdab
7
+ data.tar.gz: 17a9a46be73ce49d828ea879050539cb5fe6493dc8570db6eedc87ae3f153f9dad121c1500ca674da412136100135ee8cf35a3f52b9582daeb2d4ae1f7401cc3
@@ -4,13 +4,15 @@ module Spree
4
4
  def initialize(scope:, params:, current_currency:)
5
5
  @scope = scope
6
6
 
7
- @ids = String(params.dig(:filter, :ids)).split(',')
8
- @skus = String(params.dig(:filter, :skus)).split(',')
9
- @price = String(params.dig(:filter, :price)).split(',')
10
- @currency = params[:currency] || current_currency
11
- @taxons = String(params.dig(:filter, :taxons)).split(',')
12
- @name = params.dig(:filter, :name)
13
- @options = params.dig(:filter, :options).try(:to_unsafe_hash)
7
+ @ids = String(params.dig(:filter, :ids)).split(',')
8
+ @skus = String(params.dig(:filter, :skus)).split(',')
9
+ @price = String(params.dig(:filter, :price)).split(',')
10
+ @currency = params[:currency] || current_currency
11
+ @taxons = String(params.dig(:filter, :taxons)).split(',')
12
+ @name = params.dig(:filter, :name)
13
+ @options = params.dig(:filter, :options).try(:to_unsafe_hash)
14
+ @deleted = params.dig(:filter, :show_deleted)
15
+ @discontinued = params.dig(:filter, :show_discontinued)
14
16
  end
15
17
 
16
18
  def execute
@@ -20,13 +22,15 @@ module Spree
20
22
  products = by_taxons(products)
21
23
  products = by_name(products)
22
24
  products = by_options(products)
25
+ products = include_deleted(products)
26
+ products = include_discontinued(products)
23
27
 
24
28
  products
25
29
  end
26
30
 
27
31
  private
28
32
 
29
- attr_reader :ids, :skus, :price, :currency, :taxons, :name, :options, :scope
33
+ attr_reader :ids, :skus, :price, :currency, :taxons, :name, :options, :scope, :deleted, :discontinued
30
34
 
31
35
  def ids?
32
36
  ids.present?
@@ -100,6 +104,14 @@ module Spree
100
104
  products.with_option_value(key, value)
101
105
  end.inject(:&)
102
106
  end
107
+
108
+ def include_deleted(products)
109
+ deleted ? products.with_deleted : products.not_deleted
110
+ end
111
+
112
+ def include_discontinued(products)
113
+ discontinued ? products : products.not_discontinued
114
+ end
103
115
  end
104
116
  end
105
117
  end
@@ -11,7 +11,7 @@ module Spree
11
11
  :checkout_remove_store_credit_service, :checkout_get_shipping_rates_service,
12
12
  :coupon_handler, :country_finder, :current_order_finder, :credit_card_finder,
13
13
  :completed_order_finder, :order_sorter, :cart_compare_line_items_service, :collection_paginator, :products_sorter,
14
- :products_finder, :taxon_finder, :line_item_by_variant_finder
14
+ :products_finder, :taxon_finder, :line_item_by_variant_finder, :cart_estimate_shipping_rates_service
15
15
  ].freeze
16
16
 
17
17
  attr_accessor *INJECTION_POINTS
@@ -38,6 +38,7 @@ module Spree
38
38
  @cart_remove_item_service = 'Spree::Cart::RemoveItem'
39
39
  @cart_remove_line_item_service = 'Spree::Cart::RemoveLineItem'
40
40
  @cart_set_item_quantity_service = 'Spree::Cart::SetQuantity'
41
+ @cart_estimate_shipping_rates_service = 'Spree::Cart::EstimateShippingRates'
41
42
 
42
43
  # checkout
43
44
  @checkout_next_service = 'Spree::Checkout::Next'
@@ -0,0 +1,39 @@
1
+ module Spree
2
+ module Cart
3
+ class EstimateShippingRates
4
+ prepend Spree::ServiceModule::Base
5
+
6
+ def call(order:, country_iso: nil)
7
+ country_id = country_id(country_iso)
8
+ dummy_order = generate_dummy_order(order, country_id)
9
+
10
+ packages = ::Spree::Stock::Coordinator.new(dummy_order).packages
11
+ estimator = ::Spree::Stock::Estimator.new(dummy_order)
12
+ shipping_rates = if order.line_items.any? && packages.any?
13
+ estimator.shipping_rates(packages.first)
14
+ else
15
+ []
16
+ end
17
+
18
+ success(shipping_rates)
19
+ end
20
+
21
+ private
22
+
23
+ def country_id(country_iso)
24
+ if country_iso.present?
25
+ ::Spree::Country.by_iso(country_iso)&.id
26
+ else
27
+ ::Spree::Country.default.id
28
+ end
29
+ end
30
+
31
+ def generate_dummy_order(order, country_id)
32
+ dummy_order = order.dup
33
+ dummy_order.line_items = order.line_items
34
+ dummy_order.ship_address = ::Spree::Address.new(country_id: country_id)
35
+ dummy_order
36
+ end
37
+ end
38
+ end
39
+ end
@@ -1,5 +1,5 @@
1
1
  module Spree
2
2
  def self.version
3
- '3.7.1'
3
+ '3.7.2'
4
4
  end
5
5
  end
@@ -2,8 +2,8 @@ FactoryBot.define do
2
2
  factory :country, class: Spree::Country do
3
3
  sequence(:iso_name) { |n| "ISO_NAME_#{n}" }
4
4
  sequence(:name) { |n| "NAME_#{n}" }
5
- iso { 'US' }
6
- iso3 { 'USA' }
5
+ sequence(:iso) { |n| "I#{n}" }
6
+ sequence(:iso3) { |n| "IS#{n}" }
7
7
  numcode { 840 }
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spree_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.7.1
4
+ version: 3.7.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sean Schofield
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-03-01 00:00:00.000000000 Z
11
+ date: 2019-04-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemerchant
@@ -594,6 +594,7 @@ files:
594
594
  - app/paginators/spree/shared/paginate.rb
595
595
  - app/services/spree/cart/add_item.rb
596
596
  - app/services/spree/cart/create.rb
597
+ - app/services/spree/cart/estimate_shipping_rates.rb
597
598
  - app/services/spree/cart/recalculate.rb
598
599
  - app/services/spree/cart/remove_item.rb
599
600
  - app/services/spree/cart/remove_line_item.rb