spree_core 2.4.6 → 2.4.7

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
  SHA1:
3
- metadata.gz: 74b9cc11b2915cf6a3cb6aa62104f6eaf77c3c33
4
- data.tar.gz: dd6804ed2e43a0cb6d87b41ed06c4bd27b4638a6
3
+ metadata.gz: 6e70453c69a40765c3da043aaa45500faf53a473
4
+ data.tar.gz: 7f7d4d3f6d687e4ca780d632db70944a51ec4a17
5
5
  SHA512:
6
- metadata.gz: f8cb30c856f1491e29066c9afb33aeaa0791cd904d7bc8be5824b9c4bcb0eeaa9c7589cf4f72e4cf215bc10e46fd58f6c51b9fa6804e36123334ff326f454a03
7
- data.tar.gz: b199cffe7f6c2e46af52e2bb1d68cfeb98a2fa888829f0bf0be962e24b7dd59b2886b4f38d6c693007964cf660b0c0f39f144cc0e2eb74cdb8952860832f4a85
6
+ metadata.gz: 6cb8f296090b301cef84ba89770fb22df0bccb7a5d6e6baab595adb07e607d181d7608db28d8f29f820d5fe6ead85e5bc71411e523f31f6b296ad2e5e725a004
7
+ data.tar.gz: 1fd7c088dc684dd038214c82eee41278b4fd18ce874570adb45532fbe918a9c69bcb110e3628585975e66555f32ce93295026c6ba2f321baa3fb9f75dd95171c
@@ -105,7 +105,7 @@ module Spree
105
105
  end
106
106
 
107
107
  def taxons_tree(root_taxon, current_taxon, max_level = 1)
108
- return '' if max_level < 1 || root_taxon.children.empty?
108
+ return '' if max_level < 1 || root_taxon.leaf?
109
109
  content_tag :ul, class: 'taxons-list' do
110
110
  root_taxon.children.map do |taxon|
111
111
  css_class = (current_taxon && current_taxon.self_and_ancestors.include?(taxon)) ? 'current' : nil
@@ -45,7 +45,7 @@ module Spree
45
45
 
46
46
  def line_item_description_text description_text
47
47
  if description_text.present?
48
- truncate(strip_tags(description_text.gsub('&nbsp;', ' ')), length: 100)
48
+ truncate(strip_tags(description_text.gsub('&nbsp;', ' ').squish), length: 100)
49
49
  else
50
50
  Spree.t(:product_has_no_description)
51
51
  end
@@ -2,7 +2,7 @@ module Spree
2
2
  class Classification < Spree::Base
3
3
  self.table_name = 'spree_products_taxons'
4
4
  acts_as_list scope: :taxon
5
- belongs_to :product, class_name: "Spree::Product", inverse_of: :classifications
5
+ belongs_to :product, class_name: "Spree::Product", inverse_of: :classifications, touch: true
6
6
  belongs_to :taxon, class_name: "Spree::Taxon", inverse_of: :classifications, touch: true
7
7
 
8
8
  # For #3494
@@ -351,6 +351,13 @@ module Spree
351
351
  def outstanding_balance
352
352
  if state == 'canceled'
353
353
  -1 * payment_total
354
+ elsif reimbursements.includes(:refunds).size > 0
355
+ reimbursed = reimbursements.includes(:refunds).inject(0) do |sum, reimbursement|
356
+ sum + reimbursement.refunds.sum(:amount)
357
+ end
358
+ # If reimbursement has happened add it back to total to prevent balance_due payment state
359
+ # See: https://github.com/spree/spree/issues/6229
360
+ total - (payment_total + reimbursed)
354
361
  else
355
362
  total - payment_total
356
363
  end
@@ -1,5 +1,7 @@
1
1
  module Spree
2
2
  class ProductProperty < Spree::Base
3
+ acts_as_list scope: :product
4
+
3
5
  belongs_to :product, touch: true, class_name: 'Spree::Product', inverse_of: :product_properties
4
6
  belongs_to :property, class_name: 'Spree::Property', inverse_of: :product_properties
5
7
 
@@ -39,14 +39,23 @@ module Spree
39
39
  order = options[:order]
40
40
  return unless self.eligible? order
41
41
 
42
+ action_taken = false
42
43
  promotion_action_line_items.each do |item|
43
44
  current_quantity = order.quantity_of(item.variant)
44
- if current_quantity < item.quantity
45
- order.contents.add(item.variant, item.quantity - current_quantity)
45
+ if current_quantity < item.quantity && item_available?(item)
46
+ line_item = order.contents.add(item.variant, item.quantity - current_quantity)
47
+ action_taken = true if line_item.try(:valid?)
46
48
  end
47
49
  end
48
- true
50
+ action_taken
49
51
  end
52
+
53
+ # Checks that there's enough stock to add the line item to the order
54
+ def item_available?(item)
55
+ quantifier = Spree::Stock::Quantifier.new(item.variant)
56
+ quantifier.can_supply? item.quantity
57
+ end
58
+
50
59
  end
51
60
  end
52
61
  end
@@ -91,23 +91,28 @@ module Spree
91
91
  # Promotions without rules are eligible by default.
92
92
  return [] if rules.none?
93
93
  eligible = lambda { |r| r.eligible?(promotable, options) }
94
- specific_rules = rules.for(promotable)
94
+ specific_rules = rules.select { |rule| rule.applicable?(promotable) }
95
95
  return [] if specific_rules.none?
96
96
 
97
+ rule_eligibility = Hash[specific_rules.map do |rule|
98
+ [rule, rule.eligible?(promotable, options)]
99
+ end]
100
+
97
101
  if match_all?
98
102
  # If there are rules for this promotion, but no rules for this
99
103
  # particular promotable, then the promotion is ineligible by default.
100
- unless specific_rules.all?(&eligible)
104
+ unless rule_eligibility.values.all?
101
105
  @eligibility_errors = specific_rules.map(&:eligibility_errors).detect(&:present?)
102
106
  return nil
103
107
  end
104
108
  specific_rules
105
109
  else
106
- unless specific_rules.any?(&eligible)
110
+ unless rule_eligibility.values.any?
107
111
  @eligibility_errors = specific_rules.map(&:eligibility_errors).detect(&:present?)
108
112
  return nil
109
113
  end
110
- specific_rules.select(&eligible)
114
+
115
+ [rule_eligibility.detect { |_, eligibility| eligibility }.first]
111
116
  end
112
117
  end
113
118
 
@@ -120,7 +125,8 @@ module Spree
120
125
  end
121
126
 
122
127
  def adjusted_credits_count(promotable)
123
- credits_count - promotable.adjustments.promotion.where(:source_id => actions.pluck(:id)).count
128
+ adjustments = promotable.is_a?(Order) ? promotable.all_adjustments : promotable.adjustments
129
+ credits_count - adjustments.promotion.where(:source_id => actions.pluck(:id)).count
124
130
  end
125
131
 
126
132
  def credits
@@ -16,6 +16,8 @@ module Spree
16
16
 
17
17
  before_validation :set_cost_zero_when_nil
18
18
 
19
+ validates :stock_location, presence: true
20
+
19
21
  attr_accessor :special_instructions
20
22
 
21
23
  accepts_nested_attributes_for :address
@@ -1,6 +1,7 @@
1
1
  module Spree
2
2
  class Variant < Spree::Base
3
3
  acts_as_paranoid
4
+ acts_as_list
4
5
 
5
6
  include Spree::DefaultPrice
6
7
 
@@ -47,6 +48,10 @@ module Spree
47
48
  joins(:prices).where(deleted_at: nil).where('spree_prices.currency' => currency || Spree::Config[:currency]).where('spree_prices.amount IS NOT NULL')
48
49
  end
49
50
 
51
+ def self.having_orders
52
+ joins(:line_items).distinct
53
+ end
54
+
50
55
  def tax_category
51
56
  if self[:tax_category_id].nil?
52
57
  product.tax_category
@@ -172,7 +177,7 @@ module Spree
172
177
  return 0 unless options.present?
173
178
 
174
179
  options.keys.map { |key|
175
- m = "#{options[key]}_price_modifier_amount".to_sym
180
+ m = "#{key}_price_modifier_amount".to_sym
176
181
  if self.respond_to? m
177
182
  self.send(m, options[key])
178
183
  else
@@ -1,5 +1,12 @@
1
1
  class CreateStoreFromPreferences < ActiveRecord::Migration
2
2
  def change
3
+ # workaround for spree_i18n and Store translations
4
+ Spree::Store.class_eval do
5
+ def self.translated?(name)
6
+ false
7
+ end
8
+ end
9
+
3
10
  preference_store = Spree::Preferences::Store.instance
4
11
  if store = Spree::Store.where(default: true).first
5
12
  store.meta_description = preference_store.get('spree/app_configuration/default_meta_description') {}
@@ -1,5 +1,5 @@
1
1
  module Spree
2
2
  def self.version
3
- "2.4.6"
3
+ "2.4.7"
4
4
  end
5
5
  end
@@ -61,7 +61,9 @@ module Spree
61
61
  :meta_keywords, :price, :sku, :deleted_at, :prototype_id,
62
62
  :option_values_hash, :weight, :height, :width, :depth,
63
63
  :shipping_category_id, :tax_category_id,
64
- :taxon_ids, :option_type_ids, :cost_currency, :cost_price]
64
+ :taxon_ids, :cost_currency, :cost_price,
65
+ option_type_ids: []
66
+ ]
65
67
 
66
68
  @@property_attributes = [:name, :presentation]
67
69
 
@@ -101,8 +103,10 @@ module Spree
101
103
 
102
104
  @@variant_attributes = [
103
105
  :name, :presentation, :cost_price, :lock_version,
104
- :position, :option_value_ids, :track_inventory,
106
+ :position, :track_inventory,
105
107
  :product_id, :product, :option_values_attributes, :price,
106
- :weight, :height, :width, :depth, :sku, :cost_currency, options: [ :name, :value ]]
108
+ :weight, :height, :width, :depth, :sku, :cost_currency,
109
+ options: [:name, :value], option_value_ids: []
110
+ ]
107
111
  end
108
112
  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: 2.4.6
4
+ version: 2.4.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sean Schofield
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-10 00:00:00.000000000 Z
11
+ date: 2015-05-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemerchant
@@ -258,16 +258,16 @@ dependencies:
258
258
  name: rails
259
259
  requirement: !ruby/object:Gem::Requirement
260
260
  requirements:
261
- - - "~>"
261
+ - - '='
262
262
  - !ruby/object:Gem::Version
263
- version: 4.1.8
263
+ version: 4.1.9
264
264
  type: :runtime
265
265
  prerelease: false
266
266
  version_requirements: !ruby/object:Gem::Requirement
267
267
  requirements:
268
- - - "~>"
268
+ - - '='
269
269
  - !ruby/object:Gem::Version
270
- version: 4.1.8
270
+ version: 4.1.9
271
271
  - !ruby/object:Gem::Dependency
272
272
  name: ransack
273
273
  requirement: !ruby/object:Gem::Requirement