-
Notifications
You must be signed in to change notification settings - Fork 805
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
Widgets: Fix the Simple Payments widget in the widgets.php page #9848
Closed
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Copons
added
[Type] Bug
When a feature is broken and / or not performing as intended
[Feature] Extra Sidebar Widgets
[Status] In Progress
Simple Payments
labels
Jul 3, 2018
Copons
added
[Status] Needs Review
To request a review from fellow Jetpack developers. Label will be renamed soon.
and removed
[Status] In Progress
labels
Jul 3, 2018
For Jetpack folks looking 👀this PR is experimental and is not aimed at a particular release yet. If this is distracting we can temporarily close this PR. |
All good as it is now @gwwar. Thanks for the heads-up |
Copons
force-pushed
the
try/simple-payments-widgets-page
branch
from
July 16, 2018 09:49
69b7f31
to
255c5e2
Compare
This PR needs a rebase |
brbrr
removed
the
[Status] Needs Review
To request a review from fellow Jetpack developers. Label will be renamed soon.
label
Aug 7, 2018
I'll close this and move it back to our backlog for now! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
[Feature] Extra Sidebar Widgets
[Feature] Pay with PayPal
aka Simple Payments
[Type] Bug
When a feature is broken and / or not performing as intended
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes Automattic/wp-calypso#25576
The newly introduced Simple Payments widget heavily relies on the Customizer JS API and therefore it doesn't work in the Widgets (
widgets.php
) page.This PR is an attempt to make it work in both pages flawlessly.
My initial attempt consisted in revers engineer the Customizer itself, to figure out when and why all widget events are triggered, in order to emulate them in the Widgets page.
This was sort of possible, but required an amount of hacks and workarounds several orders of magnitude larger than what I'm comfortable with.
This is the second attempt, and it's completely independent from the Customizer JS API.
It relies entirely on the event delegation, which is easy and performant enough to pull off with jQuery.
I haven't modified the existing
form.php
andcustomizer.js
files, but instead opted to write two new files from scratch in order to keep both version always open side by side, trying to stay as true to the original code as possible, while also rewriting it and learning from it.The idea behind this attempt is that we observe the widgets container, and only react when one of the buttons in a Simple Payments widget is clicked. From there, that widget becomes the context where everything happens.
Clicking on "Add New" will simply open an empty form.
Clicking on "Edit Selected" will fetch via AJAX the details of the selected product to populate the form.
Saving will simply save via AJAX whatever is in the form, and update the products selector accordingly.
Deleting will delete the product and update the products selector.
Closing the form will simply hide and clear it.
Bar corner cases and polish, this works fine in both the Widgets page and the Customizer.
There is one gotcha that I haven't got the time to study because I caught it too late before my AFK time.
When adding a new product or editing an existing one, the Customizer does not refresh accordingly until the product is saved.
This happens because the selective refresh relies on the values returned by the
WP_Widget::update()
method. In this case, the only values actually needed for the widget are the title and a product ID.All the product details (name, price, image, etc.) are saved via AJAX and stored in their own posts of CPT
jp_pay_product
.I know for a fact that @rodrigoi solved this issue, but for my poor understanding of the selective refresh magic, I can't seem to figure out exactly how.
Since my AFK is near, I'm leaving this PR here hoping it will be of some inspiration to fix that nasty issue.
Changes proposed in this Pull Request:
Testing instructions: