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

Allow changing calculator types and attributes without reloading page #1618

Merged
merged 7 commits into from
Dec 12, 2016

Conversation

jhawthorn
Copy link
Contributor

@jhawthorn jhawthorn commented Nov 25, 2016

Previously, when changing a calculator's type (or creating it for the first time), it was necessary to save and reload the edit page before seeing the calculator's attributes. Now it can all be updated in one go.

After

Before

Changes

To accomplish this all preference inputs for all calculator types are added to the page and are hidden and disabled by JS which hides them from the user and prevents their form submission.

The JS for the two "tiered" calculators needed to be refactored to not have issues when being re-initialized multiple times. This was also an issue with the existing behaviour, just less likely to be triggered.

The accepts_nested_attributes_for from CalculatedAdjustments had update_only: true added. This allows both calculator_type and calculator_attributes to be set at the same time. It also has the side effect of not needing the id specified in calculator_attributes.

@jhawthorn jhawthorn added the changelog:solidus_backend Changes to the solidus_backend gem label Nov 25, 2016
Copy link
Member

@adammathys adammathys left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Great change. Looks good to me.

Copy link
Member

@tvdeyen tvdeyen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome 🤖

This allows us to change the type and assign attributes to the
calculator at the same time. Otherwise it would attempt to build a
calculator (with base class Spree::Calculator) when an id wasn't
specified.
Previously, after changing the type of shipping calculator, the user
would need to save the page before seeing or being able to edit any of
the values for that calculator.

This PR changes the calculator_fields partial to render all values for
all types of preferences, and then hide and disable (which prevents form
submission) the fields for calculator types other than the one selected.
Previously, after changing the type of promotion calculator, the user
would need to save the page before seeing or being able to edit any of
the values for that calculator.

This PR changes the calculator_fields partial to render all values for
all types of preferences, and then hide and disable (which prevents form
submission) the fields for calculator types other than the one selected.
This fixes a couple issues:
* Events are not bound to multiple times when initPromotionActions is
  called (called each time a promotion action is added)
* Multiple tiered calculators can exist on a single page
* Fewer events are listened to on the body, which can be a performance
  issue
@jhawthorn jhawthorn merged commit 1b77bc4 into solidusio:master Dec 12, 2016
@jhawthorn jhawthorn deleted the smart_calculator branch December 12, 2016 23:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog:solidus_backend Changes to the solidus_backend gem
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants