Skip to content

Conversation

@louwie17
Copy link
Contributor

@louwie17 louwie17 commented Sep 20, 2022

All Submissions:

Changes proposed in this Pull Request:

This PR enables the select2 typeahead field for the attribute dropdown and the terms dropdown within the individual product attributes.
Currently I added a threshold for the attribute dropdown of 20, if more it will show the async typeahead field. This is similar to what is done for the category dropdown in the product list page. I could remove this condition if we don't think this is necessary.

Kapture.2022-09-20.at.10.54.33.mp4

Partially address #34000

How to test the changes in this Pull Request:

  1. Load and build this PR and finish the onboarding, adding several products and attributes (an easy way is to import the sample products CSV).
  2. Either edit an existing product or create a new one and select the Attributes tab
  3. Assume you still have attributes less then 20, the normal dropdown should show.
  4. Add the color attribute and add some terms. Notice how the terms are loaded on the fly and filtered as you type.
  5. Now either add more then 20 different attributes (would probably have to be done manually) or add this filter to your mu-plugin -> add_filter( 'woocommerce_attribute_taxonomy_filter_threshold', function() { return 1; } )
  6. It should now show a Add custom attribute button and a typeahead dropdown in the Attributes tab.
  7. Test out the Add custom attribute button, it should add the custom item.
  8. Now search for existing attributes and upon selection it should add the attribute to the product
  9. Try searching for your previously selected item, it should be disabled now.
  10. Now remove the attribute, the dropdown should not show it as disabled anymore.
  11. Saving the attributes and persisting by refreshing the page should work the same as usual.

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 changelog add --filter=<project>?

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 Sep 20, 2022
}
}

$('select.wc-attribute-search').on('select2:select', function (e) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

callback for when user selects something from the dropdown field.

});

// Add rows.
$( 'button.add_attribute' ).on( 'click', function () {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same callback as before just moved down and using the add_attribute function

'search_customers_nonce' => wp_create_nonce( 'search-customers' ),
'search_categories_nonce' => wp_create_nonce( 'search-categories' ),
'search_taxonomy_terms_nonce' => wp_create_nonce( 'search-taxonomy-terms' ),
'search_product_attributes_nonce' => wp_create_nonce( 'search-product-attributes' ),
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 only added the above two, but had to re-indent everything to re-align correctly.

@github-actions
Copy link
Contributor

New hook, template, or database changes in this PR

New hooks:

  • file: /plugins/woocommerce/includes/admin/meta-boxes/views/html-product-data-attributes.php
    • NOTICE - 'woocommerce_attribute_taxonomy_filter_threshold' introduced in 7.0.0: Filter for the attribute taxonomy filter dropdown threshold.

@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 Sep 20, 2022
$found_product_categories = array();

foreach ( $attributes as $attribute_obj ) {
if ( ! $search_text || false !== stripos( $attribute_obj->attribute_label, $search_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.

I end up resorting to filtering by getting the entire list (which is cached) and just sorting through this on the back-end.

I browsed around for a while and it turns out we do not have any logic in place to search for attribute taxonomies. We seem to always retrieve the entire list and cache this. To keep things simple I did it this way.
But I would foresee us needing this in the future and also adding this functionality to the Woo REST api (as it currently doesn't support this either).

I could still add this as part of this issue, but it felled slightly out of scope, as it will require the addition of a whole new attribute taxonomy Query class.

@github-actions
Copy link
Contributor

github-actions bot commented Sep 20, 2022

Test Results Summary

Commit SHA: 38fce14

Test 🧪Passed ✅Failed 🚨Broken 🚧Skipped ⏭️Unknown ❔Total 📊Duration ⏱️
API Tests15300201550m 40s
E2E Tests187002018917m 53s

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 requested review from octaedro and removed request for a team September 29, 2022 15:07
Comment on lines 311 to 315
var minimumInputLength = 3;

if ( $( this ).data( 'minimum_input_length' ) !== undefined ) {
minimumInputLength = $( this ).data( 'minimum_input_length' );
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we use here a ternary operator as the line before?
It would look like this:

var minimumInputLength = $( this ).data( 'minimum_input_length' ) !== undefined ? $( this ).data( 'minimum_input_length' ) : 3;

Another good option would be:

var minimumInputLength = $( this ).data( 'minimum_input_length' ) ?? 3;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed as part of: 9cf74f8

Copy link
Contributor

@octaedro octaedro left a comment

Choose a reason for hiding this comment

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

You did a really nice job here @louwie17! This is testing well on my end and the code looks mostly good. I just left a small comment.
As a side note, we should probably do something similar with the attribute terms since it seems like we show a maximum of 6.

Screen Capture on 2022-09-29 at 16-24-41

@louwie17 louwie17 force-pushed the add/34000_attribute_select_control branch from 41c7902 to 9cf74f8 Compare October 3, 2022 17:46
@louwie17
Copy link
Contributor Author

louwie17 commented Oct 3, 2022

@octaedro thanks for the review, I addressed your feedback.

As a side note, we should probably do something similar with the attribute terms since it seems like we show a maximum of 6.

I am kinda confused with what you mean here? Where are we showing a maximum of 6? the page size is 50.

@louwie17 louwie17 requested a review from octaedro October 3, 2022 17:49
octaedro
octaedro previously approved these changes Oct 5, 2022
Copy link
Contributor

@octaedro octaedro left a comment

Choose a reason for hiding this comment

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

Thank you @louwie17 for the changes. LGTM 🚀

@louwie17 louwie17 force-pushed the add/34000_attribute_select_control branch from 59054b1 to 84fa056 Compare October 6, 2022 11:57
Copy link
Contributor

@octaedro octaedro left a comment

Choose a reason for hiding this comment

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

🚀

@louwie17 louwie17 merged commit f28a467 into trunk Oct 6, 2022
@louwie17 louwie17 deleted the add/34000_attribute_select_control branch October 6, 2022 17:27
@github-actions github-actions bot added this to the 7.1.0 milestone Oct 6, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Oct 6, 2022

Hi @louwie17, 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

@florianmastacan
Copy link

@octaedro thanks for the review, I addressed your feedback.

As a side note, we should probably do something similar with the attribute terms since it seems like we show a maximum of 6.

I am kinda confused with what you mean here? Where are we showing a maximum of 6? the page size is 50.

Hi there, may I ask why the page size was limited to 50? We have a client who is using 186 colours containing the "green" word and thus when he tries to add attributes to a product in order to build the relevant variations he cannot get to the items from positions 51+ and above...

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. release: add testing instructions PRs that have not had testing instructions added to the wiki. [auto] release: highlight Issues that have a high user impact and need to be discussed/paid attention to.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants