Skip to content

Conversation

@kzamanbd
Copy link
Contributor

@kzamanbd kzamanbd commented Mar 20, 2025

All Submissions:

  • My code follow the WordPress' coding standards
  • My code satisfies feature requirements
  • My code is tested
  • My code passes the PHPCS tests
  • My code has proper inline documentation
  • I've included related pull request(s) (optional)
  • I've included developer documentation (optional)
  • I've added proper labels to this pull request

Changes proposed in this Pull Request:

Related Pull Request(s)

Closes

How to test the changes in this Pull Request:

  • Steps or issue link

Changelog entry

  1. Added functionality for product brands, including a new brand selection, brand edit and brand wise product filter option on the vendor dashboard.

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:

  • Code is not following code style guidelines
  • Bad naming: make sure you would understand your code if you read it a few months from now.
  • KISS: Keep it simple, Sweetie (not stupid!).
  • DRY: Don't Repeat Yourself.
  • Code that is not readable: too many nested 'if's are a bad sign.
  • Performance issues
  • Complicated constructions that need refactoring or comments: code should almost always be self-explanatory.
  • Grammar errors.

FOR PR REVIEWER ONLY:

As a reviewer, your feedback should be focused on the idea, not the person. Seek to understand, be respectful, and focus on constructive dialog.

As a contributor, your responsibility is to learn from suggestions and iterate your pull request should it be needed based on feedback. Seek to collaborate and produce the best possible contribution to the greater whole.

  • Correct — Does the change do what it’s supposed to? ie: code 100% fulfilling the requirements?
  • Secure — Would a nefarious party find some way to exploit this change? ie: everything is sanitized/escaped appropriately for any SQL or XSS injection possibilities?
  • Readable — Will your future self be able to understand this change months down the road?
  • Elegant — Does the change fit aesthetically within the overall style and architecture?

Summary by CodeRabbit

  • New Features
    • Introduced a dynamic, search-enabled dropdown for selecting multiple product brands in the product editor.
    • Added brand-based filtering options in product listings for easier product discovery.
    • Enabled product brand assignment during product updates to streamline brand management.

@kzamanbd kzamanbd self-assigned this Mar 20, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 20, 2025

Walkthrough

This 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

File(s) Change Summary
assets/src/js/product-editor.js Added new jQuery Select2 dropdown for product brands including AJAX configuration, custom templates, and error messages while ensuring coexistence with the existing product tag dropdown.
includes/Ajax.php Registered a new AJAX action (dokan_json_search_products_brands) and implemented the corresponding method to fetch product brands with security, including a recursive helper (get_child_terms_recursive) for hierarchical term processing.
includes/Assets.php Extended localized arguments by adding a nonce (search_products_brands_nonce) for securing AJAX requests for product brands.
includes/Dashboard/Templates/Products.php Refined conditional logic in handle_product_add and added brand handling in handle_product_update to save product brand associations using wp_set_object_terms.
includes/functions.php, templates/products/edit-product-single.php, templates/products/listing-filter.php, templates/products/products-listing.php Enhanced the vendor dashboard UI: added a multi-select dropdown for associating brands in the product edit page, incorporated a new brand filter in the listing filter template, and modified the product listing query to support filtering by brand.

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
Loading

Assessment against linked issues

Objective Addressed Explanation
Add/Edit Product page & Product List Filter for brand selection (#4206)
Bulk Edit and CSV Import support for product brands (#4206) Bulk edit functionality and CSV import mapping for brands are not implemented.

Possibly related issues

  • getdokan/dokan-pro#4206: The PR’s introduction of dynamic brand selection and AJAX-based brand search aligns with the vendor dashboard brand management enhancements outlined in this issue.

Suggested labels

Needs: Testing, :+1: Dev Review Done, Dependency With Pro

Suggested reviewers

  • mrabbani

Poem

I hopped through lines of code so bright,
Searching for brands in the soft moonlight.
AJAX and Select2 danced hand in hand,
Making the Dokan dashboard simply grand.
With every brand now clear and in sight,
This rabbit cheers a coder’s delight!
Happy hopping in our code-filled night!

Tip

⚡💬 Agentic Chat (Pro Plan, General Availability)
  • We're introducing multi-step agentic chat in review comments and issue comments, within and outside of PR's. This feature enhances review and issue discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments and add commits to existing pull requests.

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5d2ffc9 and fb118b7.

📒 Files selected for processing (1)
  • includes/Ajax.php (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • includes/Ajax.php
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: e2e tests (1, 3)
  • GitHub Check: e2e tests (3, 3)
  • GitHub Check: api tests (1, 1)
  • GitHub Check: e2e tests (2, 3)

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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 UI

The 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 function

The recursive function effectively handles hierarchical brand structures.

Consider these improvements:

  1. Replace the placeholder @since DOKAN_SINCE with the actual version number
  2. Use consistent indentation (spaces instead of tabs)
  3. 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 functionality

The implementation follows the established pattern in the codebase and properly handles security through nonce verification.

Replace the placeholder @since DOKAN_SINCE with the actual version number for proper documentation.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 33ca11a and 5d2ffc9.

📒 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_nonce secures 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_search class.

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 parameter

The code adds a new parameter product_brand to 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 filtering

This line correctly retrieves, sanitizes, and processes the product_brand parameter from the query string. The code follows security best practices by using intval() and wp_unslash() for proper sanitization.

includes/Dashboard/Templates/Products.php (3)

300-301: Improved conditional logic clarity

Changing from else to elseif improves code readability by making the relationship between conditions explicit.


342-342: Enhanced conditional structure

This change follows the same pattern of replacing else with a more specific elseif condition, improving code clarity.


520-524: Well-implemented product brand support

The 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 action

The new AJAX action for product brands search is properly registered using the WordPress AJAX hook system.

@kzamanbd kzamanbd requested a review from mrabbani March 24, 2025 05:10
@kzamanbd kzamanbd added Needs: Testing This requires further testing Needs: Dev Review It requires a developer review and approval labels Mar 24, 2025
@shohan0120 shohan0120 added QA In Progress 🎉 QA Approved This PR is approved by the QA team and removed Needs: Testing This requires further testing QA In Progress labels Apr 8, 2025
@mrabbani mrabbani added Needs: Author Reply and removed Needs: Dev Review It requires a developer review and approval labels Apr 17, 2025
@kzamanbd kzamanbd requested a review from mrabbani April 18, 2025 06:56
@kzamanbd kzamanbd added Needs: Dev Review It requires a developer review and approval and removed Needs: Author Reply labels Apr 18, 2025
@kzamanbd kzamanbd added the Bump Version Select for the next major version release label Apr 28, 2025
@shohag121 shohag121 merged commit e6106f4 into develop May 2, 2025
3 of 6 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Dec 29, 2025
12 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bump Version Select for the next major version release Needs: Dev Review It requires a developer review and approval 🎉 QA Approved This PR is approved by the QA team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants