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

Show message in Inventory tab for variable products #37185

Merged
merged 7 commits into from Mar 13, 2023

Conversation

octaedro
Copy link
Contributor

@octaedro octaedro commented Mar 12, 2023

All Submissions:

Changes proposed in this Pull Request:

This PR adds the code to show a message in the Inventory tab when the product is type variable.

Screenshot 2023-03-07 at 23 00 55

Closes #37119.

How to test the changes in this Pull Request:

  1. Checkout this branch.
  2. Go to Products> Add New > Product data > Inventory.
  3. Verify that the message Settings below apply to all variations without manual stock management enabled. [Learn more](https://woocommerce.com/document/variable-product/) is not visible.
  4. Select Variable product and check that now the message is visible.

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 created a changelog file for each project being changed, ie pnpm --filter=<project> changelog add?
  • Have you included testing instructions?

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 Mar 12, 2023
@octaedro octaedro changed the title Dev/37119 show message for variable products Show message in Inventory tab for variable products Mar 12, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Mar 12, 2023

Test Results Summary

Commit SHA: 4175251

Test 🧪Passed ✅Failed 🚨Broken 🚧Skipped ⏭️Unknown ❔Total 📊Duration ⏱️
API Tests25900202610m 55s
E2E Tests189006019516m 32s

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.

@codecov
Copy link

codecov bot commented Mar 12, 2023

Codecov Report

Merging #37185 (4175251) into trunk (c6e6f87) will not change coverage.
The diff coverage is 37.1%.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff            @@
##             trunk   #37185   +/-   ##
========================================
  Coverage     46.7%    46.7%           
  Complexity   17191    17191           
========================================
  Files          429      429           
  Lines        64845    64845           
========================================
  Hits         30275    30275           
  Misses       34570    34570           
Impacted Files Coverage Δ
...ocommerce/includes/abstracts/abstract-wc-order.php 86.7% <0.0%> (ø)
...ce/includes/abstracts/abstract-wc-settings-api.php 56.3% <0.0%> (ø)
...ocommerce/includes/admin/class-wc-admin-assets.php 0.0% <0.0%> (ø)
...oocommerce/includes/admin/class-wc-admin-menus.php 14.7% <0.0%> (ø)
...ommerce/includes/admin/class-wc-admin-settings.php 16.8% <0.0%> (ø)
...ocommerce/includes/admin/class-wc-admin-status.php 12.2% <0.0%> (ø)
...ludes/admin/notes/class-wc-notes-run-db-update.php 78.0% <ø> (ø)
...ocommerce/includes/admin/wc-meta-box-functions.php 0.0% <0.0%> (ø)
...ugins/woocommerce/includes/class-wc-post-types.php 2.8% <0.0%> (ø)
...oocommerce/includes/react-admin/core-functions.php 33.3% <ø> (ø)
... and 6 more

Comment on lines 13 to 17
<div class="inline notice woocommerce-message show_if_variable">
<p>
<?php echo esc_html_e( 'Settings below apply to all variations without manual stock management enabled. ', 'woocommerce' ); ?> <a target="_blank" href="https://woocommerce.com/document/variable-product/"><?php esc_html_e( 'Learn more', 'woocommerce' ); ?></a>
</p>
</div>
Copy link
Contributor Author

@octaedro octaedro Mar 12, 2023

Choose a reason for hiding this comment

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

We can abstract this (and every use of this kind of message) in a follow-up PR. We might create a method like woocommerce_wp_notice or woocommerce_wp_message here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Any reason not to just abstract it in this PR? Do you question whether it should be abstracted?

I don't feel strongly whether it should be at this point, but would lean slightly towards doing so in this PR.

@octaedro octaedro marked this pull request as ready for review March 12, 2023 18:00
@octaedro octaedro self-assigned this Mar 12, 2023
@octaedro octaedro requested a review from a team March 12, 2023 18:00
@mattsherman mattsherman self-requested a review March 13, 2023 12:06
@mattsherman
Copy link
Contributor

I'll review this

Copy link
Contributor

@mattsherman mattsherman left a comment

Choose a reason for hiding this comment

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

Tested. Overall, works as expected.

There are a few minor styling tweaks that should be made to ensure that this message looks ideal.

@@ -959,12 +959,16 @@
}

#variable_product_options #message,
#inventory_product_data .notice,
#variable_product_options .notice {
display: flex;
margin: 10px;
background-color: #ffffff;
> p {
width: 85%;
Copy link
Contributor

Choose a reason for hiding this comment

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

This width: 85% results in the notice looking odd when it goes to two or more lines.

I think it can just be removed.

Before (made the text longer to simulate a longer translation or different user settings that would result in more lines):

Screenshot 2023-03-13 at 09 23 26

After:

Screenshot 2023-03-13 at 09 24 10

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 couldn't delete it because we will need the 85% when there is a button, like here:

Screenshot 2023-03-13 at 11 48 43

But I added the code we need for that case in the commit 5108e42.

Copy link
Contributor

Choose a reason for hiding this comment

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

That explicit 85%/15% sizing is not ideal, and results in display issues. But, that's really outside the scope of this PR I suppose... I'll create a separate PR later today to fix that up...

Before:

Screenshot 2023-03-13 at 11 50 57

After removing explicit widths:

Screenshot 2023-03-13 at 11 53 09

#variable_product_options .notice {
display: flex;
margin: 10px;
background-color: #ffffff;
> p {
width: 85%;
a {
text-decoration: none;
Copy link
Contributor

Choose a reason for hiding this comment

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

Ideally there shouldn't be a line break in the middle of this link. We should set white-space: nowrap on it.

Before (again, text made longer to simulate translation, etc.):

Screenshot 2023-03-13 at 09 28 50

After:

Screenshot 2023-03-13 at 09 29 01

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!


<div class="inline notice woocommerce-message show_if_variable">
<p>
<?php echo esc_html_e( 'Settings below apply to all variations without manual stock management enabled. ', 'woocommerce' ); ?> <a target="_blank" href="https://woocommerce.com/document/variable-product/"><?php esc_html_e( 'Learn more', 'woocommerce' ); ?></a>
Copy link
Contributor

Choose a reason for hiding this comment

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

There is an errant space at the end of the translated message. enabled. That space is not needed.

Comment on lines 13 to 17
<div class="inline notice woocommerce-message show_if_variable">
<p>
<?php echo esc_html_e( 'Settings below apply to all variations without manual stock management enabled. ', 'woocommerce' ); ?> <a target="_blank" href="https://woocommerce.com/document/variable-product/"><?php esc_html_e( 'Learn more', 'woocommerce' ); ?></a>
</p>
</div>
Copy link
Contributor

Choose a reason for hiding this comment

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

Any reason not to just abstract it in this PR? Do you question whether it should be abstracted?

I don't feel strongly whether it should be at this point, but would lean slightly towards doing so in this PR.

@octaedro
Copy link
Contributor Author

octaedro commented Mar 13, 2023

Any reason not to just abstract it in this PR? Do you question whether it should be abstracted?

@mattsherman Yes, I think that it should be refactored but that refactor implies also touching code in 4 different files (wc-admin-functions, html-product-data-attributes, html-product-data-variations, and html-product-data-inventory). I prefer to wrap those changes in a different PR and only add the message in this one, to keep this PR small.

@octaedro
Copy link
Contributor Author

Hey @mattsherman,
Thank you for reviewing this PR. I just addressed the suggestions you made.
Could you take another look at this PR?

@mattsherman
Copy link
Contributor

Any reason not to just abstract it in this PR? Do you question whether it should be abstracted?

@mattsherman Yes, I think that it should be refactored but that refactor implies also touching code in 4 different files (wc-admin-functions, html-product-data-attributes, html-product-data-variations, and html-product-data-inventory). I prefer to wrap those changes in a different PR and only add the message in this one, to keep this PR small.

Makes sense.

Copy link
Contributor

@mattsherman mattsherman 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 things up, @octaedro ! Nice work. Approved.

white-space: nowrap;
}
}
> p:not( :last-child ) {
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, this explicit width causes issues but it outside the scope of this PR, so I'm good with this fix for now!

@octaedro octaedro merged commit b1a0d31 into trunk Mar 13, 2023
28 of 29 checks passed
@octaedro octaedro deleted the dev/37119_show_message_for_variable_products branch March 13, 2023 21:26
@github-actions github-actions bot added this to the 7.6.0 milestone Mar 13, 2023
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.

[Enhancement]: Show a message for variable products
2 participants