spree_api 4.2.0.rc4 → 4.2.0.rc5

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: 7c7b8ebf1a65cf7fb7063b4811c8d6226298c6435b5fdb9a60fd0c9a0579567d
4
- data.tar.gz: 33ab903daaec69fdcb23340146c6e78be7dc64dbe760d2885353518d977887d3
3
+ metadata.gz: 4d89085eb3c34e7174431d231b1e9a883b6cbf3d7ee838d633125c352bd3a6db
4
+ data.tar.gz: 3402c8e857912d6655aea610e7092c4f749faf2f0b31a9f0c3f8601b292c43ba
5
5
  SHA512:
6
- metadata.gz: 4f108ec0840bcfdf1aa5f15a8cf7f1de53fc7420bc0d0fc93072786ce139f60afcf5506470dca75c32cfac4b70221b4a9858e8b0a528b643e3f411c892cd46c9
7
- data.tar.gz: 75d052059dda3df22fd17236878a14b9ca9a07da5bb287b0df03c11ea347a02abadabf75e2f7f7da950cd9e8bfdb56e96294d0a14ec46049797a63a69da58711
6
+ metadata.gz: bef7abadbdf0a40b95b04b45811eade8884c5f782c9720a3b009e90aabc133b9384122e65fcc443245102b6e444636e30f423d357efefebc8e63910240525efe
7
+ data.tar.gz: a1824c2bccb63b030b8d6cfe64237b1ce3b57dfd36adacdf71367b5a0408cec84a7d019bec4017c4d83f273a2de0e595d734cf506cb517b03b78932f9a871285
@@ -34,10 +34,6 @@ module Spree
34
34
  )
35
35
  end
36
36
 
37
- def supported_currencies
38
- current_store.supported_currencies_list
39
- end
40
-
41
37
  def serialize_order(order)
42
38
  resource_serializer.new(order.reload, include: resource_includes, fields: sparse_fields).serializable_hash
43
39
  end
@@ -6,6 +6,8 @@ module Spree
6
6
  include Spree::Api::ControllerSetup
7
7
  include Spree::Core::ControllerHelpers::Store
8
8
  include Spree::Core::ControllerHelpers::StrongParameters
9
+ include Spree::Core::ControllerHelpers::Locale
10
+ include Spree::Core::ControllerHelpers::Currency
9
11
 
10
12
  attr_accessor :current_api_user
11
13
 
@@ -37,7 +37,7 @@ module Spree
37
37
  invalid_resource!(@taxon) and return
38
38
  end
39
39
 
40
- @taxon.parent_id = taxonomy.root.id unless params[:taxon][:parent_id]
40
+ @taxon.parent_id = taxonomy.root_id unless params[:taxon][:parent_id]
41
41
 
42
42
  if @taxon.save
43
43
  respond_with(@taxon, status: 201, default_template: :show)
@@ -5,12 +5,12 @@ module Spree
5
5
  include CanCan::ControllerAdditions
6
6
  include Spree::Core::ControllerHelpers::StrongParameters
7
7
  include Spree::Core::ControllerHelpers::Store
8
+ include Spree::Core::ControllerHelpers::Locale
9
+ include Spree::Core::ControllerHelpers::Currency
8
10
  rescue_from ActiveRecord::RecordNotFound, with: :record_not_found
9
11
  rescue_from CanCan::AccessDenied, with: :access_denied
10
12
  rescue_from Spree::Core::GatewayError, with: :gateway_error
11
13
 
12
- before_action :set_user_language
13
-
14
14
  def content_type
15
15
  Spree::Api::Config[:api_v2_content_type]
16
16
  end
@@ -84,6 +84,10 @@ module Spree
84
84
  fields.presence
85
85
  end
86
86
 
87
+ def serializer_params
88
+ { currency: current_currency, store: current_store, user: spree_current_user }
89
+ end
90
+
87
91
  def record_not_found
88
92
  render_error_payload(I18n.t(:resource_not_found, scope: 'spree.api'), 404)
89
93
  end
@@ -95,10 +99,6 @@ module Spree
95
99
  def gateway_error(exception)
96
100
  render_error_payload(exception.message)
97
101
  end
98
-
99
- def set_user_language
100
- I18n.locale = current_store.default_locale
101
- end
102
102
  end
103
103
  end
104
104
  end
@@ -17,13 +17,14 @@ module Spree
17
17
  def serialize_collection(collection)
18
18
  collection_serializer.new(
19
19
  collection,
20
- collection_options(collection)
20
+ collection_options(collection).merge(params: serializer_params)
21
21
  ).serializable_hash
22
22
  end
23
23
 
24
24
  def serialize_resource(resource)
25
25
  resource_serializer.new(
26
26
  resource,
27
+ params: serializer_params,
27
28
  include: resource_includes,
28
29
  fields: sparse_fields
29
30
  ).serializable_hash
@@ -0,0 +1,43 @@
1
+ module Spree
2
+ module Api
3
+ module V2
4
+ module DisplayMoneyHelper
5
+ extend ActiveSupport::Concern
6
+
7
+ class_methods do
8
+ def find_price(product_or_variant, currency)
9
+ product_or_variant.price_in(currency)
10
+ end
11
+
12
+ def price(product_or_variant, currency)
13
+ price = find_price(product_or_variant, currency)
14
+ return nil if price.new_record?
15
+
16
+ format('%.2f', price.amount)
17
+ end
18
+
19
+ def display_price(product_or_variant, currency)
20
+ price = find_price(product_or_variant, currency)
21
+ return nil if price.new_record?
22
+
23
+ Spree::Money.new(price.amount, currency: currency).to_s
24
+ end
25
+
26
+ def compare_at_price(product_or_variant, currency)
27
+ price = find_price(product_or_variant, currency)
28
+ return nil if price.new_record? || price.compare_at_amount.blank?
29
+
30
+ format('%.2f', price.compare_at_amount)
31
+ end
32
+
33
+ def display_compare_at_price(product_or_variant, currency)
34
+ price = find_price(product_or_variant, currency)
35
+ return nil if price.new_record? || price.compare_at_amount.blank?
36
+
37
+ Spree::Money.new(price.compare_at_amount, currency: currency).to_s
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -2,11 +2,11 @@ module Spree
2
2
  module V2
3
3
  module Storefront
4
4
  class ProductSerializer < BaseSerializer
5
+ include ::Spree::Api::V2::DisplayMoneyHelper
6
+
5
7
  set_type :product
6
8
 
7
- attributes :name, :description, :price, :currency, :display_price,
8
- :compare_at_price, :display_compare_at_price, :available_on,
9
- :slug, :meta_description, :meta_keywords, :updated_at
9
+ attributes :name, :description, :available_on, :slug, :meta_description, :meta_keywords, :updated_at
10
10
 
11
11
  attribute :purchasable do |product|
12
12
  product.purchasable?
@@ -24,6 +24,26 @@ module Spree
24
24
  product.available?
25
25
  end
26
26
 
27
+ attribute :currency do |_product, params|
28
+ params[:currency]
29
+ end
30
+
31
+ attribute :price do |product, params|
32
+ price(product, params[:currency])
33
+ end
34
+
35
+ attribute :display_price do |product, params|
36
+ display_price(product, params[:currency])
37
+ end
38
+
39
+ attribute :compare_at_price do |product, params|
40
+ compare_at_price(product, params[:currency])
41
+ end
42
+
43
+ attribute :display_compare_at_price do |product, params|
44
+ display_compare_at_price(product, params[:currency])
45
+ end
46
+
27
47
  has_many :variants
28
48
  has_many :option_types
29
49
  has_many :product_properties
@@ -2,10 +2,11 @@ module Spree
2
2
  module V2
3
3
  module Storefront
4
4
  class VariantSerializer < BaseSerializer
5
+ include ::Spree::Api::V2::DisplayMoneyHelper
6
+
5
7
  set_type :variant
6
8
 
7
- attributes :sku, :price, :currency, :display_price, :weight, :height,
8
- :width, :depth, :is_master, :options_text
9
+ attributes :sku, :weight, :height, :width, :depth, :is_master, :options_text
9
10
 
10
11
  attribute :purchasable do |variant|
11
12
  variant.purchasable?
@@ -19,6 +20,26 @@ module Spree
19
20
  variant.backorderable?
20
21
  end
21
22
 
23
+ attribute :currency do |_product, params|
24
+ params[:currency]
25
+ end
26
+
27
+ attribute :price do |product, params|
28
+ price(product, params[:currency])
29
+ end
30
+
31
+ attribute :display_price do |product, params|
32
+ display_price(product, params[:currency])
33
+ end
34
+
35
+ attribute :compare_at_price do |product, params|
36
+ compare_at_price(product, params[:currency])
37
+ end
38
+
39
+ attribute :display_compare_at_price do |product, params|
40
+ display_compare_at_price(product, params[:currency])
41
+ end
42
+
22
43
  belongs_to :product
23
44
  has_many :images
24
45
  has_many :option_values
@@ -7,7 +7,14 @@ Doorkeeper.configure do
7
7
 
8
8
  resource_owner_from_credentials do
9
9
  user = Spree.user_class.find_for_database_authentication(email: params[:username])
10
- user if user&.valid_for_authentication? { user.valid_password?(params[:password]) }
10
+
11
+ return nil if user.nil?
12
+
13
+ if defined?(Spree::Auth::Config) && Spree::Auth::Config[:confirmable] == true
14
+ user if user.active_for_authentication? && user.valid_for_authentication? { user.valid_password?(params[:password]) }
15
+ elsif user&.valid_for_authentication? { user.valid_password?(params[:password]) }
16
+ user
17
+ end
11
18
  end
12
19
 
13
20
  admin_authenticator do |routes|
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spree_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.2.0.rc4
4
+ version: 4.2.0.rc5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Bigg
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-01-20 00:00:00.000000000 Z
11
+ date: 2021-02-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jsonapi-rspec
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - '='
32
32
  - !ruby/object:Gem::Version
33
- version: 4.2.0.rc4
33
+ version: 4.2.0.rc5
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - '='
39
39
  - !ruby/object:Gem::Version
40
- version: 4.2.0.rc4
40
+ version: 4.2.0.rc5
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rabl
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -147,6 +147,7 @@ files:
147
147
  - app/controllers/spree/api/v2/storefront/taxons_controller.rb
148
148
  - app/helpers/spree/api/api_helpers.rb
149
149
  - app/helpers/spree/api/v2/collection_options_helpers.rb
150
+ - app/helpers/spree/api/v2/display_money_helper.rb
150
151
  - app/models/concerns/spree/user_api_authentication.rb
151
152
  - app/models/concerns/spree/user_api_methods.rb
152
153
  - app/models/spree/api_configuration.rb
@@ -308,9 +309,9 @@ licenses:
308
309
  - BSD-3-Clause
309
310
  metadata:
310
311
  bug_tracker_uri: https://github.com/spree/spree/issues
311
- changelog_uri: https://github.com/spree/spree/releases/tag/v4.2.0.rc4
312
+ changelog_uri: https://github.com/spree/spree/releases/tag/v4.2.0.rc5
312
313
  documentation_uri: https://guides.spreecommerce.org/
313
- source_code_uri: https://github.com/spree/spree/tree/v4.2.0.rc4
314
+ source_code_uri: https://github.com/spree/spree/tree/v4.2.0.rc5
314
315
  post_install_message:
315
316
  rdoc_options: []
316
317
  require_paths: