Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v2.8] Backport for some required bugfixes #3194

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ Spree.Views.Stock.EditStockItemRow = Backbone.View.extend({
"click .submit": "onSubmit",
"submit form": "onSubmit",
"click .cancel": "onCancel",
'input [name="count_on_hand"]': "countOnHandChanged"
'input [name="count_on_hand"]': "countOnHandChanged",
'input [name="backorderable"]': "backorderableChanged"
},

template: HandlebarsTemplates['stock_items/stock_location_stock_item'],
Expand Down Expand Up @@ -43,6 +44,20 @@ Spree.Views.Stock.EditStockItemRow = Backbone.View.extend({
this.render();
},

onChange: function() {
var count_on_hand_changed = this.previousAttributes.count_on_hand != this.model.attributes.count_on_hand;
var backorderable_changed = this.previousAttributes.backorderable != this.model.attributes.backorderable;
var changed = count_on_hand_changed || backorderable_changed;

this.$el.toggleClass('changed', changed);
},

backorderableChanged: function(ev) {
this.model.set("backorderable", ev.target.checked);

this.onChange();
},

countOnHandChanged: function(ev) {
var diff = parseInt(ev.currentTarget.value), newCount;
if (isNaN(diff)) diff = 0;
Expand All @@ -56,7 +71,8 @@ Spree.Views.Stock.EditStockItemRow = Backbone.View.extend({
this.model.set("count_on_hand", newCount);
this.$count_on_hand_display.text(newCount);
}
this.$el.toggleClass('changed', diff !== 0);

this.onChange();
},

onSuccess: function() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Make color very close to white
@function very-light($color, $adjust: 3){
@function very-light($color, $adjust: 3){
@if type-of($adjust) == 'number' and $adjust > 0 {
@for $i from 0 through 100 {
@if lighten($color, $i) == white and ($i - $adjust) > $adjust {
Expand All @@ -10,6 +10,7 @@
@else {
@debug "Please correct $adjust value. It should be number and larger then 0. Currently it is '#{type-of($adjust)}' with value '#{$adjust}'"
}
@return $color;
};

// Quick fix for dynamic variables missing in SASS
Expand Down
17 changes: 17 additions & 0 deletions backend/spec/features/admin/products/stock_management_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@
expect(stock_item.stock_movements.first.quantity).to eq(-4)
end

it "can toggle backorderable", js: true do
toggle_backorderable(value: false)

click_link "Product Stock"
within("tr#spree_variant_#{variant.id}") do
expect(find(:css, "input[type='checkbox']")).not_to be_checked
end
end

def adjust_count_on_hand(count_on_hand)
within("tr#spree_variant_#{variant.id}") do
find(:css, "input[type='number']").set(count_on_hand)
Expand All @@ -65,6 +74,14 @@ def adjust_count_on_hand(count_on_hand)
expect(page).to have_content('Updated Successfully')
end

def toggle_backorderable(value: true)
within("tr#spree_variant_#{variant.id}") do
find(:css, "input[type='checkbox']").set(value)
click_icon :check
end
expect(page).to have_content('Updated Successfully')
end

context "with stock locations that don't have stock items for variant yet" do
before do
create(:stock_location, name: 'Other location', propagate_all_variants: false)
Expand Down
3 changes: 2 additions & 1 deletion core/app/models/spree/store_credit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class Spree::StoreCredit < Spree::PaymentSource
before_validation :associate_credit_type
before_validation :validate_category_unchanged, on: :update
before_destroy :validate_no_amount_used
validate :validate_no_amount_used, if: :discarded?
before_discard :validate_no_amount_used

attr_accessor :action, :action_amount, :action_originator, :action_authorization_code, :store_credit_reason

Expand Down Expand Up @@ -268,6 +268,7 @@ def validate_category_unchanged
def validate_no_amount_used
if amount_used > 0
errors.add(:amount_used, 'is greater than zero. Can not delete store credit')
throw :abort
end
end

Expand Down