-
Notifications
You must be signed in to change notification settings - Fork 215
Feat/wc product brand #2622
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
Feat/wc product brand #2622
Conversation
WalkthroughThis pull request introduces a new product brand selection feature in the Dokan vendor dashboard. It adds a jQuery Select2 dropdown to the product editor for dynamically searching and selecting product brands, along with the necessary AJAX functionality to fetch hierarchical brand data. The changes extend the vendor dashboard by updating product add/update handlers, template interfaces for editing products and filtering product listings, and localized arguments for securing AJAX requests. Existing product tag functionality remains unaffected. Changes
Sequence Diagram(s)sequenceDiagram
participant U as User
participant FE as Product Editor Page
participant JS as Select2 Dropdown
participant AJAX as Dokan AJAX Endpoint
participant Server as Ajax.php Handler
U->>FE: Opens product add/edit page
FE->>JS: Initialize brand dropdown via Select2
JS->>AJAX: Sends AJAX request (dokan_json_search_products_brands) with search term and nonce
AJAX->>Server: Validates nonce and processes request
Server->>Server: Queries brands (including child terms recursively)
Server-->>AJAX: Returns JSON data with brand options
AJAX-->>JS: Delivers brand data
JS->>FE: Populates the dropdown with fetched brands
Assessment against linked issues
Possibly related issues
Suggested labels
Suggested reviewers
Poem
Tip ⚡💬 Agentic Chat (Pro Plan, General Availability)
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms (4)
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 0
🧹 Nitpick comments (3)
assets/src/js/product-editor.js (1)
212-295: Good implementation of product brand dropdown UIThe implementation of the Select2 dropdown for product brands follows good practices and mirrors the existing pattern for product tags. The code properly handles hierarchical brand data and includes comprehensive error handling.
There's a minor optimization opportunity in the pagination logic:
pagination: { - more: options.length == 0 ? false : true + more: options.length > 0 },🧰 Tools
🪛 Biome (1.9.4)
[error] 241-241: Unnecessary use of boolean literals in conditional expression.
Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with(lint/complexity/noUselessTernary)
includes/Ajax.php (2)
718-749: Well-structured hierarchical term retrieval functionThe recursive function effectively handles hierarchical brand structures.
Consider these improvements:
- Replace the placeholder
@since DOKAN_SINCEwith the actual version number- Use consistent indentation (spaces instead of tabs)
- Add a depth limit parameter to prevent performance issues with deeply nested hierarchies:
- public function get_child_terms_recursive( int $parent_id, array &$brands, int $level ) { + public function get_child_terms_recursive( int $parent_id, array &$brands, int $level, int $max_depth = 5 ) { + // Stop recursion if max depth is reached + if ( $level >= $max_depth ) { + return; + } // Rest of the function... // When making recursive call: - $this->get_child_terms_recursive( $child->term_id, $brands, $level + 1 ); + $this->get_child_terms_recursive( $child->term_id, $brands, $level + 1, $max_depth );
750-791: Solid implementation of brand search functionalityThe implementation follows the established pattern in the codebase and properly handles security through nonce verification.
Replace the placeholder
@since DOKAN_SINCEwith the actual version number for proper documentation.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (8)
assets/src/js/product-editor.js(1 hunks)includes/Ajax.php(2 hunks)includes/Assets.php(1 hunks)includes/Dashboard/Templates/Products.php(3 hunks)includes/functions.php(2 hunks)templates/products/edit-product-single.php(1 hunks)templates/products/listing-filter.php(2 hunks)templates/products/products-listing.php(1 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
assets/src/js/product-editor.js
[error] 241-241: Unnecessary use of boolean literals in conditional expression.
Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with
(lint/complexity/noUselessTernary)
⏰ Context from checks skipped due to timeout of 90000ms (4)
- GitHub Check: e2e tests (3, 3)
- GitHub Check: e2e tests (1, 3)
- GitHub Check: e2e tests (2, 3)
- GitHub Check: api tests (1, 1)
🔇 Additional comments (11)
includes/Assets.php (1)
1052-1052: Properly added security nonce for product brands search.The addition of the
search_products_brands_noncesecures AJAX requests for brand searches by implementing WordPress security best practices. This nonce will work in conjunction with the brand search functionality implemented elsewhere.templates/products/products-listing.php (1)
177-184: Added product brand filtering functionality.This code correctly implements filtering products by brand in the vendor dashboard. The implementation properly sanitizes the input with
intval()and follows the same pattern as the existing category filter above it, ensuring consistency throughout the codebase.templates/products/edit-product-single.php (1)
391-403: Brand selection interface added to product edit form.The implementation adds a multi-select dropdown for assigning brands to products. The code correctly retrieves existing product brands and pre-selects them in the dropdown. The UI is consistent with other taxonomies like tags.
Note that this interface will likely be enhanced with Select2 functionality through JavaScript (not shown in this file), as indicated by the
product_brand_searchclass.templates/products/listing-filter.php (2)
7-7: Added product brand parameter documentation.Good practice to document the variable type in the PHPDoc block.
64-86: Implemented product brand filter dropdown.The code correctly implements a hierarchical dropdown for filtering products by brand, using WordPress' built-in
wp_dropdown_categories()function. The implementation follows the same pattern as the category dropdown above it and properly applies filters to allow customization.includes/functions.php (2)
2197-2197: Added new product brand filter parameterThe code adds a new parameter
product_brandto the template arguments with a default value of-1, which enables product filtering by brand in the vendor dashboard.
2207-2207: Properly implemented GET parameter handling for product brand filteringThis line correctly retrieves, sanitizes, and processes the product_brand parameter from the query string. The code follows security best practices by using
intval()andwp_unslash()for proper sanitization.includes/Dashboard/Templates/Products.php (3)
300-301: Improved conditional logic clarityChanging from
elsetoelseifimproves code readability by making the relationship between conditions explicit.
342-342: Enhanced conditional structureThis change follows the same pattern of replacing
elsewith a more specificelseifcondition, improving code clarity.
520-524: Well-implemented product brand supportThe implementation for setting product brands follows the same pattern as product tags, maintaining consistency in the codebase.
includes/Ajax.php (1)
49-49: Properly registered AJAX actionThe new AJAX action for product brands search is properly registered using the WordPress AJAX hook system.
All Submissions:
Changes proposed in this Pull Request:
Related Pull Request(s)
Closes
How to test the changes in this Pull Request:
Changelog entry
Before Changes
Describe the issue before changes with screenshots(s).
After Changes
Describe the issue after changes with screenshot(s).
Feature Video (optional)
Link of detailed video if this PR is for a feature.
PR Self Review Checklist:
FOR PR REVIEWER ONLY:
Summary by CodeRabbit