Change products controller to clear variants unit description if variant_unit is items

This commit is contained in:
luisramos0
2019-05-31 20:40:25 +01:00
parent ada640b159
commit 1a4e83d633
2 changed files with 29 additions and 7 deletions

View File

@@ -39,6 +39,8 @@ Spree::Admin::ProductsController.class_eval do
delete_stock_params_and_set_after do
super
end
clear_variants_unit_description if @object.variant_unit == 'items'
end
def bulk_update
@@ -154,4 +156,10 @@ Spree::Admin::ProductsController.class_eval do
def set_product_master_variant_price_to_zero
@product.price = 0 if @product.price.nil?
end
def clear_variants_unit_description
@object.variants.each do |variant|
variant.update_attribute :unit_description, ''
end
end
end

View File

@@ -150,17 +150,31 @@ describe Spree::Admin::ProductsController, type: :controller do
end
describe "updating" do
let(:producer) { create(:enterprise) }
let!(:product) { create(:simple_product, supplier: producer) }
before do
@request.env['HTTP_REFERER'] = 'http://test.com/'
login_as_enterprise_user [producer]
end
describe "product variant unit is items" do
it "clears unit description of all variants of the product" do
product.variants.first.update_attribute :unit_description, "grams"
spree_put :update,
id: product,
product: {
variant_unit: "items",
variant_unit_name: "bag"
}
expect(product.reload.variants.first.unit_description).to be_empty
end
end
describe "product properties" do
context "as an enterprise user" do
let(:producer) { create(:enterprise) }
let!(:product) { create(:simple_product, supplier: producer) }
let!(:property) { create(:property, name: "A nice name") }
before do
@request.env['HTTP_REFERER'] = 'http://test.com/'
login_as_enterprise_user [producer]
end
context "when a submitted property does not already exist" do
it "does not create a new property, or product property" do
spree_put :update,