-
Notifications
You must be signed in to change notification settings - Fork 10.7k
Add/34000 attribute select control #34744
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
Conversation
| } | ||
| } | ||
|
|
||
| $('select.wc-attribute-search').on('select2:select', function (e) { |
There was a problem hiding this comment.
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 () { |
There was a problem hiding this comment.
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' ), |
There was a problem hiding this comment.
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.
New hook, template, or database changes in this PRNew hooks:
|
| $found_product_categories = array(); | ||
|
|
||
| foreach ( $attributes as $attribute_obj ) { | ||
| if ( ! $search_text || false !== stripos( $attribute_obj->attribute_label, $search_text ) ) { |
There was a problem hiding this comment.
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.
Test Results SummaryCommit SHA: 38fce14
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. |
| var minimumInputLength = 3; | ||
|
|
||
| if ( $( this ).data( 'minimum_input_length' ) !== undefined ) { | ||
| minimumInputLength = $( this ).data( 'minimum_input_length' ); | ||
| } |
There was a problem hiding this comment.
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;
There was a problem hiding this comment.
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
There was a problem hiding this 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.
41c7902 to
9cf74f8
Compare
|
@octaedro thanks for the review, I addressed your feedback.
I am kinda confused with what you mean here? Where are we showing a maximum of 6? the page size is 50. |
octaedro
left a comment
There was a problem hiding this 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 🚀
59054b1 to
84fa056
Compare
octaedro
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀
|
Hi @louwie17, thanks for merging this pull request. Please take a look at these follow-up tasks you may need to perform:
|
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... |

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:
mu-plugin->add_filter( 'woocommerce_attribute_taxonomy_filter_threshold', function() { return 1; } )Other information:
pnpm changelog add --filter=<project>?FOR PR REVIEWER ONLY: