Merge pull request #11863 from abdellani/11862-fix-product-shoud-not-be-priceless

product should not be priceless
This commit is contained in:
Filipe
2023-12-01 10:43:30 +00:00
committed by GitHub
6 changed files with 8 additions and 4 deletions

View File

@@ -50,9 +50,8 @@ module Spree
flash[:success] = flash_message_for(@object, :successfully_updated)
redirect_to spree.admin_product_variants_url(params[:product_id], @url_filters)
else
redirect_to spree.edit_admin_product_variant_url(params[:product_id],
@object,
@url_filters)
load_data
render :edit
end
end

View File

@@ -67,6 +67,7 @@ module Spree
validates :variant_unit_name,
presence: { if: ->(p) { p.variant_unit == 'items' } }
validate :validate_image
validates :price, numericality: { greater_than_or_equal_to: 0, if: ->{ new_record? } }
accepts_nested_attributes_for :variants, allow_destroy: true
accepts_nested_attributes_for :image

View File

@@ -72,6 +72,7 @@ module Spree
}
validates :unit_value, numericality: { greater_than: 0 }
validates :price, numericality: { greater_than_or_equal_to: 0 }
validates :unit_description, presence: true, if: ->(variant) {
variant.product&.variant_unit.present? && variant.unit_value.nil?

View File

@@ -24,6 +24,7 @@ module Spree
new_product.created_at = nil
new_product.deleted_at = nil
new_product.updated_at = nil
new_product.price = 0
new_product.unit_value = %w(weight volume).include?(product.variant_unit) ? 1.0 : nil
new_product.product_properties = reset_properties
new_product.image = duplicate_image(product.image) if product.image

View File

@@ -102,7 +102,8 @@ describe Api::V0::ProductsController, type: :controller do
expect(response.status).to eq(422)
expect(json_response["error"]).to eq("Invalid resource. Please fix errors and try again.")
errors = json_response["errors"]
expect(errors.keys).to match_array(["name", "primary_taxon", "supplier", "variant_unit"])
expect(errors.keys).to match_array(["name", "primary_taxon", "supplier", "variant_unit",
"price"])
end
it "can update a product" do

View File

@@ -71,6 +71,7 @@ describe Spree::Core::ProductDuplicator do
expect(new_product).to receive(:sku=).with("")
expect(new_product).to receive(:product_properties=).with([new_property])
expect(new_product).to receive(:created_at=).with(nil)
expect(new_product).to receive(:price=).with(0)
expect(new_product).to receive(:unit_value=).with(nil)
expect(new_product).to receive(:updated_at=).with(nil)
expect(new_product).to receive(:deleted_at=).with(nil)