Skip to content

Conversation

@octaedro
Copy link
Contributor

@octaedro octaedro commented Oct 4, 2022

All Submissions:

Changes proposed in this Pull Request:

This PR aims to introduce an easy way for users to add the variation price. It also modifies a few styles to show the action buttons for the variations without hovering over the rows.

Closes #33554.

How to test the changes in this Pull Request:

  1. Go to Products > Add New.
  2. Add a product name and a description.
  3. In the Product data section select Variable product.
  4. Go to Attributes and create (or select) a product attribute to use for variations.
  5. Go to Variations and add a few variations (don't modify them).
  6. Press Save changes.
  7. Verify that a warning is shown with the number of variations without price.

Screen Shot 2022-10-19 at 17 13 28

  1. Press Add price. A modal like the one below will be visible.
    Screen Shot 2022-10-19 at 16 03 45

  2. Verify the currency matches the currency used on the site.

  3. Add a text (not numbers) and verify that the validation fails. Add a number with multiple decimal points and verify that the error text says: Please enter a value with one decimal point (%s) without thousand separators.

  4. After adding a valid number the button OK should be enabled.

  5. Add a valid number and press Add prices.

  6. Verify that the Regular price for every variation is set with the number added in the modal.

  7. Verify that the accordion expands after pressing Edit.

  8. Press Save changes. The warning should disappear.

  9. Publish the product.

  10. Add another variation. Press Save changes. The warning should be shown again.

  11. Now add another value and verify that the new value has been added to the new variation without modifying the other variations' values.

Now create a new product but select Variable subscription instead of Variable product in step 3, and continue with the other steps.

Other information:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes, as applicable?
  • Have you successfully run tests with your changes locally?
  • Have you created a changelog file for each project being changed, ie pnpm --filter=<project> run changelog add?

FOR PR REVIEWER ONLY:

  • I have reviewed that everything is sanitized/escaped appropriately for any SQL or XSS injection possibilities. I made sure Linting is not ignored or disabled.

@github-actions github-actions bot added the plugin: woocommerce Issues related to the WooCommerce Core plugin. label Oct 4, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Oct 4, 2022

Test Results Summary

Commit SHA: fc2777a

Test 🧪Passed ✅Failed 🚨Broken 🚧Skipped ⏭️Unknown ❔Total 📊Duration ⏱️
API Tests25900302621m 15s
E2E Tests186006019215m 14s

To view the full API test report, click here.
To view the full E2E test report, click here.
To view all test reports, visit the WooCommerce Test Reports Dashboard.

@octaedro octaedro force-pushed the add/33554_variation-price branch from 13dc88e to a1aee3d Compare October 13, 2022 19:24
@github-actions github-actions bot added the release: highlight Issues that have a high user impact and need to be discussed/paid attention to. label Oct 18, 2022
@octaedro octaedro changed the title Add/33554 variation price Product creation experience: shortcut to add variation price Oct 19, 2022
@octaedro octaedro requested a review from a team October 19, 2022 20:52
@octaedro octaedro marked this pull request as ready for review October 19, 2022 20:53
.on(
'click',
'button.add_price_for_variations',
this.open_modal_to_set_variations_price
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just underlining the lines added to this file. The lint modified a lot of things here.

Comment on lines 270 to 302
/**
* Sets a price for every variation
*/
set_variations_price: function () {
var variation_price = $( '.wc_input_variations_price' ).val();
var product_type = $( 'select#product-type' ).val();
var input_type =
'variable-subscription' === product_type
? 'variable_subscription_sign_up_fee'
: 'variable_regular_price';
var input = $( `.wc_input_price[name^=${ input_type }]` );

// We don't want to override prices already set
input.each( function ( index, el ) {
if ( '0' === $( el ).val() || '' === $( el ).val() ) {
$( el ).val( variation_price ).trigger( 'change' );
}
} );
},

/**
* Opens the modal to set a price for every variation
*/
open_modal_to_set_variations_price: function () {
$( this ).WCBackboneModal( {
template: 'wc-modal-set-price-variations',
} );
$( '.add_variations_price_button' ).on(
'click',
wc_meta_boxes_product_variations_actions.set_variations_price
);
},
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These lines have been added too.

'.wc_input_price[type=text], .wc_input_decimal[type=text], .wc-order-totals #refund_amount[type=text]',
function() {
var regex, decimalRegex,
'.wc_input_price[type=text], .wc_input_decimal[type=text], .wc-order-totals #refund_amount[type=text], ' +
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Everything related to the class wc_input_variations_price in this file has been added by this PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

Is this part suppose to handle the number parsing?
When I enter a number of 1231231.1231231 it gets used as is, and doesn't get formatted nor does the decimal get trimmed.

Copy link
Contributor Author

@octaedro octaedro Oct 24, 2022

Choose a reason for hiding this comment

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

Is this part suppose to handle the number parsing?

Nope, it has the same behavior that the variations fields have. The numbers aren't formatted, we were only checking the thousands and decimal pointing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure if it will worth adding that validation to the old product management experience, but if you think that we need it I'll be happy to add it in a follow-up PR.

Copy link
Contributor

@louwie17 louwie17 left a comment

Choose a reason for hiding this comment

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

Stellar work on this @octaedro, this was testing very well.
I did notice the number formatting wasn't working for me though, also left a comment in the code about that.

I also have a couple suggestions:

  • Update the copy of the Modal to be more specific that we are only updating the variations that don't have a price
  • Triggering Save changes after the user clicks OK in the add price modal, so the notice disappears automatically and this would follow inline with the Set regular prices action.
  • Lastly if we should change the OK in the modal to be more specific? like Add prices? This is not a must, as I assume we are trying to simulate the same thing as a window.confirm which usually only contains cancel and ok.

One last thing I noticed, the wireframe updated the Default Form Values: copy to Default Variations:, something that wasn't explicitly mentioned in the issue, but I guess should also be added as part of this? cc @jarekmorawski
Just note that if we update this name, we should update the popover to, to reflect his name change. As the popover explicitly mentioned default form values.

Although I find both Default Form Values or Default Variations semi confusing, the tooltip seems to be really necessary.

</div>
<div class="woocommerce-usage-modal__wrapper">
<div class="woocommerce-usage-modal__message">
<span>Add price to all variations (<?php echo esc_attr( get_woocommerce_currency_symbol() ); ?> <?php echo esc_textarea( get_woocommerce_currency() ); ?>)</span>
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we want to update this copy to be a bit more specific, given we won't be updating the price of all variations, if some of the variations already contain a price.
Maybe we should tag on: that don't have a price:
Add price to all variations that don't have a price?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I like this suggestion. If it's ok with @jarekmorawski I'll change the text to Add price to variations that don't have a price.

'.wc_input_price[type=text], .wc_input_decimal[type=text], .wc-order-totals #refund_amount[type=text]',
function() {
var regex, decimalRegex,
'.wc_input_price[type=text], .wc_input_decimal[type=text], .wc-order-totals #refund_amount[type=text], ' +
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this part suppose to handle the number parsing?
When I enter a number of 1231231.1231231 it gets used as is, and doesn't get formatted nor does the decimal get trimmed.

?>
</p>
<div class="woocommerce-add-variation-price-container">
<button type="button" class="button add_price_for_variations"><?php esc_html_e( 'Add price', 'woocommerce' ); ?></button>
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we potentially hide the Add price button after the price has been added?
Or maybe we want to auto trigger the Save changes button, just like what happens when a user clicks Go for the Set regular prices option, this in turn auto triggers a save changes.
This would also auto hide the notice and provide a better feedback loop to the user.

As the Save changes is not very obvious and its confusing for the user to see the notice of the prices still missing after they just added them.

Copy link
Contributor Author

@octaedro octaedro Oct 24, 2022

Choose a reason for hiding this comment

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

Could we potentially hide the Add price button after the price has been added?

Good idea!

Copy link
Contributor

Choose a reason for hiding this comment

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

As mentioned above, could we change Add price to Add prices depending if their are multiple or not?

@jarekmorawski
Copy link

Thanks for the ping, y'all! I can see great work has happened here, but I wonder why we've decided to build a custom modal instead of the browser's default one? It is already used for bulk variation editing and it'd be good to keep these actions consistent.

image

Update the copy of the Modal to be more specific that we are only updating the variations that don't have a price

The yellow notice already mentions the number of variations that don't have the price added yet. We could show it in the modal, too (image above).

Triggering Save changes after the user clicks OK in the add price modal, so the notice disappears automatically and this would follow inline with the Set regular prices action.

I agree and confirm that this is the expected behavior.

Lastly if we should change the OK in the modal to be more specific? like Add prices? This is not a must, as I assume we are trying to simulate the same thing as a window.confirm which usually only contains cancel and ok.

I wasn't sure if that's possible for browser-managed modals. 🤔 If it is, we should definitely change OK to Add.

One last thing I noticed, the wireframe updated the Default Form Values: copy to Default Variations:, something that wasn't explicitly mentioned in the issue, but I guess should also be added as part of this?

It's a very minor change, so we can leave it out for now.

@octaedro
Copy link
Contributor Author

octaedro commented Oct 21, 2022

Hi @jarekmorawski, thank you for your feedback.

I wonder why we've decided to build a custom modal instead of the browser's default one?

We didn't build a custom modal. The modal we use is the same one we use to add a product and add taxes when creating an order, but I get your point. I was confused because my prompt modal has a black background and the one in the design was white 😄.

Screen Shot 2022-10-21 at 16 51 46

If we lean towards the prompt modal, we won't be able to add the on-the-fly validation that we are using for the price inputs. Is that expected?
This PR also adds a validation that disables the OK button.

Screen Capture on 2022-10-21 at 16-54-12

Lastly if we should change the OK in the modal to be more specific? like Add prices? This is not a must, as I assume we are trying to simulate the same thing as a window.confirm which usually only contains cancel and ok.
I wasn't sure if that's possible for browser-managed modals. 🤔 If it is, we should definitely change OK to Add.

I think that there is a little confusion here; the window.confirm was meant for boolean answers. On the other hand the window.prompt allows asking a question but it doesn't allow setting the buttons' texts.

IMO the modal used in this PR provides a better user experience, it allows us to add the on-the-fly validation (it feels pretty handy), the button renaming, and the OK button enabling/disabling when the field is empty.

@jarekmorawski
Copy link

Good call. I didn't want to add the extra work, but it looks better with our version of the modal. 😃 Let's change the button's label from OK to Add prices and wrap up. Nice work on this, @octaedro!

@octaedro
Copy link
Contributor Author

Hi @louwie17, thank you for your review!
I just addressed the changes you mentioned. Could you give this PR another look?

Copy link
Contributor

@louwie17 louwie17 left a comment

Choose a reason for hiding this comment

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

Thanks for the updates @octaedro, those updates look good!
I just noticed one piece of text not wrapped around the translation function, and was curious if we could update the Add price to Add prices and the other way around depending on how many variations need prices.

</div>
<div class="woocommerce-usage-modal__wrapper">
<div class="woocommerce-usage-modal__message">
<span>Add price to all variations that don't have a price (<?php echo esc_attr( get_woocommerce_currency_symbol() ); ?> <?php echo esc_textarea( get_woocommerce_currency() ); ?>)</span>
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be surround with the esc_html_e right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice catch! I add it in commit 6af604f

</div>
<div class="woocommerce-usage-modal__actions">
<button class="modal-close components-button is-secondary"><?php esc_html_e( 'Cancel', 'woocommerce' ); ?></button>
<button class="modal-close button components-button add_variations_price_button is-primary" disabled><?php esc_html_e( 'Add prices', 'woocommerce' ); ?></button>
Copy link
Contributor

Choose a reason for hiding this comment

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

Does PHP provide a helper function for esc_html_e for multiple as well?
It might be nice to show either Add price or Add prices depending on how many are missing their price.
Same in the notice, the notice might be easier to do given you already have access to the count.

This is not a must, but might be nice, if it's not to difficult.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @louwie17,

This change is not trivial and it would imply calling the database again.

The number of variations without price is calculated here. Because html-product-data-variations.php is being loaded before wc-admin-functions.php we're not able to use a global variable, since the value is calculated after the first file is processed.

I'm not sure if the change is worth the effort. What do you think about merging this PR as it is and maybe tackling that change in a follow-up PR?

Copy link
Contributor

Choose a reason for hiding this comment

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

A follow-up PR sounds good with me.

?>
</p>
<div class="woocommerce-add-variation-price-container">
<button type="button" class="button add_price_for_variations"><?php esc_html_e( 'Add price', 'woocommerce' ); ?></button>
Copy link
Contributor

Choose a reason for hiding this comment

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

As mentioned above, could we change Add price to Add prices depending if their are multiple or not?

@github-actions github-actions bot removed the release: highlight Issues that have a high user impact and need to be discussed/paid attention to. label Oct 27, 2022
@octaedro octaedro force-pushed the add/33554_variation-price branch from 0773200 to 6c6c75b Compare October 27, 2022 21:55
Copy link
Contributor

@louwie17 louwie17 left a comment

Choose a reason for hiding this comment

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

Thanks for the updates @octaedro, this is very close to done, I noticed one tiny issue with the styling especially on larger screens, see comment below.
After that fix, this looks good to me.

.woocommerce-add-variation-price-container {
width: 15%;
display: flex;
justify-content: center;
Copy link
Contributor

Choose a reason for hiding this comment

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

We may want to use flex-end here? the spacing on the right looks a little weird, this seems to happen on larger screens it appears.
Screen Shot 2022-10-28 at 10 23 26 AM

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea! I fixed it in the commit 82e59b8

@octaedro octaedro force-pushed the add/33554_variation-price branch from f445c95 to 82e59b8 Compare October 28, 2022 16:25
louwie17
louwie17 previously approved these changes Oct 28, 2022
Copy link
Contributor

@louwie17 louwie17 left a comment

Choose a reason for hiding this comment

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

Thanks @octaedro this looks good, appreciate all your hard work on this!

In terms of the failing Github action it does show as required, so I do hope you can still merge without it passing, otherwise you maybe have to fix all those lint errors, or add an exception for that file for now.

Copy link
Contributor

@louwie17 louwie17 left a comment

Choose a reason for hiding this comment

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

@octaedro thanks for the rebase, but something may have gone slightly wrong the add price button styling is off now within the Modal:
Screen Shot 2022-10-31 at 2 50 24 PM

@octaedro octaedro force-pushed the add/33554_variation-price branch from 8dad80b to 3de4b8c Compare November 1, 2022 18:29
louwie17
louwie17 previously approved these changes Nov 1, 2022
Copy link
Contributor

@louwie17 louwie17 left a comment

Choose a reason for hiding this comment

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

Thanks for the final update and adding those exceptions for the PHP errors.

louwie17
louwie17 previously approved these changes Nov 1, 2022
Copy link
Contributor

@louwie17 louwie17 left a comment

Choose a reason for hiding this comment

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

LGTM 🚀

Copy link
Contributor

@louwie17 louwie17 left a comment

Choose a reason for hiding this comment

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

Thanks for fixing the lint errors, LGTM 🚀

@octaedro octaedro merged commit d77f8fc into trunk Nov 2, 2022
@octaedro octaedro deleted the add/33554_variation-price branch November 2, 2022 12:31
@github-actions github-actions bot added this to the 7.2.0 milestone Nov 2, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Nov 2, 2022

Hi @octaedro, thanks for merging this pull request. Please take a look at these follow-up tasks you may need to perform:

  • Add the release: add testing instructions label

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

plugin: woocommerce Issues related to the WooCommerce Core plugin.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Product creation experience: shortcut to add variation price

4 participants