solidus icon indicating copy to clipboard operation
solidus copied to clipboard

Nil variant shipping category not handled properly in form

Open Roman2K opened this issue 1 year ago • 0 comments

Solidus Version: v3.4.6 (should still be relevant in v4.3.2)

To Reproduce

  1. Go to the admin backend
  2. Go to Products > Products > [any product] > Variants
  3. Edit any variant that has a nil shipping category

Current behavior The selected value is the product's shipping category.

Expected behavior The selected value should be "Use Product Shipping Category".

Screenshots N/A

Desktop (please complete the following information):

  • OS: Linux
  • Browser: Firefox
  • Version: 121.0b9

Smartphone (please complete the following information): N/A (not tested)

Additional context After editing a variant, the inherited shipping category is saved in the variant, taking the product's value at the time of saving. From that point on, it's no longer dynamically inherited after the product's shipping category is changed.

The bug is caused by the collection_select in backend/app/views/spree/admin/variants/_form.html.erb that gets its selected value by calling @variant.shipping_category_id (inherited from the product if nil, instead of the actual nil value in the database).

The fix should be as simple as passing selected: @variant[:shipping_category_id] in the first options hash (ends up in the :selected option passed to options_from_collection_for_select).

Side note: the tax category select field above it should not be impacted by the same bug because Variant#tax_category_id doesn't have the same fallback.


EDIT: Fixed steps to reproduce

Roman2K avatar Feb 28 '24 17:02 Roman2K