solidusio / solidus

🛒 Solidus, the open-source eCommerce framework for industry trailblazers.
https://solidus.io
Other
4.96k stars 1.28k forks source link

Raise "Price is not valid" after I set default currency to UAH #2639

Open kraken-ua opened 6 years ago

kraken-ua commented 6 years ago

Steps to reproduce

How can you make this happen:

  1. Set in spree.rb config.currency = "UAH".
  2. Create new product.
  3. Go on product page.
  4. Click on "Add to cart"

Expected behavior

Redirect to cart with chosen product in it.

Actual behavior

Redirect to home page with flash message - "Price is not valid" 56 string from Orders controller raise it:

begin
      @line_item = @order.contents.add(variant, quantity)
rescue ActiveRecord::RecordInvalid => e
      @order.errors.add(:base, e.record.errors.full_messages.join(", "))
end

System configuration

Gemfile:

# Solidus and extensions:
gem 'solidus'
gem 'solidus_auth_devise'
gem 'solidus_i18n', github: 'solidusio-contrib/solidus_i18n', branch: 'master'
gem 'solidus_globalize', github: 'solidusio-contrib/solidus_globalize'
gem 'solidus_slider', github: 'samanmohamadi/solidus_slider'
jacobherrington commented 6 years ago

I am able to replicate this issue.

I think the error is the result of validates :price, numericality: true in line_item.rb on line 35. For some reason when I change the currency, restart the server, and create a new product, the new line_item has a price of nil which fails validation.

Looking into this, but I don't really understand it. Has anyone seen this before?

Ruberto commented 6 years ago

👍 It does the same thing if you set the currency to ZAR.

I have also set the default currency in the system settings on the admin page while the app was running with no change.

jacobherrington commented 6 years ago

This bug seems to occur with most currencies actually.

Ruberto commented 6 years ago

I managed to get around the issue, I did some byebug's and found that the line_item on the order was not valid, just as you mentioned @jacobherrington. I also noticed the currency in the line_item was set to the previous currency. I deleted all the orders/line_items in the DB, and now I can add things to my cart just fine.

aitbw commented 5 years ago

I'm unable to reproduce this issue with the latest master revision (7a33685), but I did come across this:

screenshot_2018-12-04 sample store

On the Admin panel, products are listed but their master price is set to zero, and the input for it (when editing) is empty.

Update (12/05/2018)

The problem is caused by the sample data we use for the sandbox because we're only creating Price instances for USD and EUR; any other currency we configure for the sandbox will fail to show the products on the storefront unless the database records are updated accordingly.

kennyadsl commented 5 years ago

@aitbw this is not ideal. What would we need to update in order to use other currencies?

aitbw commented 5 years ago

I think the easiest solution for that would be to create sample price data for the most traded currencies in the world (see this) and add documentation explaining why products don't show up with certain currencies to avoid confusion between newcomers, @kennyadsl. WDYT?