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

Exception when trying to edit a variant without a default price #2924

Closed
oneiros opened this issue Oct 24, 2018 · 3 comments
Closed

Exception when trying to edit a variant without a default price #2924

oneiros opened this issue Oct 24, 2018 · 3 comments
Labels
confirmed Validated report

Comments

@oneiros
Copy link

oneiros commented Oct 24, 2018

Steps to reproduce

Configure a default currency in config/initializers/spree.rb:

  config.currency = "EUR"

Log into the admin backend, select a product and on the tab "Variants" add a new variant.

Go to the tab "Prices" and under "Variant Pricing" edit the price of the newly created variant.

Set the Currency to "USD" and save the price.

Go back to the "Variants" tab and edit the variant.

Expected behavior

At the very least, no exception should be raised

Actual behavior

The following exception is raised:

ActionView::Template::Error (undefined method `currency' for nil:NilClass):
    65:       <div class="col-3">
    66:         <div class="field" data-hook="price">
    67:           <%= f.label :price %>
    68:           <%= render "spree/admin/shared/number_with_currency", f: f, amount_attr: :price, currency: @variant.default_price.currency %>
    69:         </div>
    70:       </div>
    71: 
  
solidus_backend (2.7.0) app/views/spree/admin/variants/_form.html.erb:68:in `_779db0d19337b31fccae3d69b3329154'

The reason is quite obvious: The partial expects a default_price to always be present. The default_price is being determined in solidus/core/app/models/concerns/spree/default_price.rb using, amongst others, the scope with_default_attributes. This in turn uses the configured currency. So if no price exists for the configured currency, no default_price can be found.

I guess a possible solution would be to fix the view partial to not raise an exception (and I would be happy to prepare a PR for that), but I wonder if it should even be possible for a variant to not have a default_price. If no, the actual fix would be quite different.

System configuration

Solidus Version: 2.7.0

Extensions in use:

  • 'solidus_product_assembly'
  • 'solidus_print_invoice'
  • 'solidus_reviews'
@jacobherrington
Copy link
Contributor

I think not raising an exception is a good idea. I'm not too familiar with doing international stores, so anyone can correct me, but I think people should be able to edit prices for different currencies in this way.

@jtapia
Copy link
Contributor

jtapia commented Jan 31, 2019

I was able to reproduced it and created this PR #3067, this fixed the issue, let me know your thoughts

@kennyadsl
Copy link
Member

Closed with #2504, thanks for reporting the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed Validated report
Projects
None yet
Development

No branches or pull requests

4 participants