Customizing Magento 2 Admin Grid Filter for Wishlist Items by Customer Segment

Customizing Magento 2 Admin Grid Filter for Wishlist Items by Customer Segment

Struggling to track which customer groups want specific products? Magento 2 admin grid filter solves this issue.

This tutorial explains how to build custom wishlist filters by customer segment.

Key Takeaways

  • Customer segment filtering creates targeted marketing opportunities through custom admin grids.

  • Building wishlist grid modules requires five essential configuration steps.

  • Performance optimization handles large datasets with proper indexing.

  • ACL security controls protect the admin panel access from unauthorized users.

  • Database joins combine data from six related tables for complete information.

How to Set Up a Magento 2 Module for Customizing Wishlist Grid?

1. Create Module Directory Structure

  • Set up the main folder structure under app/code/Vendor/WishlistGrid/ directory path.

  • Create the etc folder to store XML configuration files and module declarations.

  • Add the Controller folder that processes admin page requests and user actions.

  • Include the Model folder containing business logic and data operation classes.

  • Build the view folder to store UI components, templates, and layout files.

2. Register the Module

  • Create registration.php in the root directory to declare your module to Magento.

  • Use the ComponentRegistrar class to handle the registration process the right way.

  • Magento scans and loads this file during the system initialization phase.

  • The file connects your module to Magento's module management system.

3. Define Module Configuration

  • Create module.xml in the etc folder with the module name and setup_version attribute.

  • Declare dependencies on the Magento_Wishlist module for core wishlist functions.

  • Add the Magento_Customer dependency to access customer data and profiles.

  • Include Magento_Backend and Magento_Ui modules for admin grid features.

  • Use semantic versioning format (major.minor.patch) for version numbers.

4. Specify Dependencies

  • List all required packages in composer.json for the module installation to work. For example, include dependencies like:

magento/module-wishlist": "103.0.8,

magento/module-customer": "103.0.8,

magento/module-backend": "103.0.8,

magento/module-ui": "103.0.8

  • Include optional packages that add extra features when installed on the system.

  • Identify conflicting packages to prevent installation problems and errors.

  • Add development dependencies for testing and quality assurance processes.

5. Enable Module in Magento

  • Run the bin/magento module:enable Vendor_WishlistGrid command to activate the module.

  • Execute the bin/magento setup:upgrade command to run database installation scripts.

  • Clear cache with the bin/magento cache:flush command for fresh configuration loading.

  • Check module status with bin/magento module:status command to confirm successful activation.

Data visualizations provide customer segment information. Use these for wishlist analytics:

Visualization Type Use Case Display Method Purpose Example
Bar Chart Compare segment preferences Vertical bars Product popularity Wholesale segment prefers "Jackets"
Pie Chart Show segment distribution Circular segments Customer group share 40% of wishlists from Retail
Line Graph Track trends over time Connected points Activity changes Wishlist adds spiked in Q4
Heat Map Highlight product interest Color gradients Segment hotspots High interest in "Shoes" by VIPs
Table Summary List detailed metrics Grid rows Raw data review 500 items added by the General group
Funnel Chart Show conversion paths Tapered segments Buying intent 20% of wishlist items bought

How to create a Wishlist Analytics Dashboard in Admin Grid?

1. Create Dashboard XML File

  • Place the wishlist_analytics.xml file in the view/adminhtml/ui_component/ directory.

  • Define the data source connection to link the dashboard with the wishlist collection.

  • Configure the loading indicator to show the data processing status to users.

  • Configure visualization dependencies in the XML to ensure proper rendering order.

2. Configure Dashboard Metrics

  • Add the Popular Products metric to show wishlist items by segment.

  • Include Segment Activity metric to track wishlist additions per group.

  • Create a Trend Analysis metric to display changes over periods.

  • Add Customer Engagement metric to measure interaction frequency.

  • Include Store View metric for multi-store performance comparison.

3. Add Customer Segment Filter

  • Build the dropdown filter with the Magento\Customer\Model\Customer\Source\Group class.

  • Map filter selections to dashboard queries for exact data display.

  • Let marketing teams analyze segment-specific wishlist trends.

  • Provide options to compare several segments in one view.

4. Set Visualization Options

  • Add the chart type selector to switch between bar, pie, and line displays.

  • Include the date range controls to filter data by time frames.

  • Create an export feature to save analytics in CSV and XML formats. Configure export in wishlist_analytics.xml:

<exportButton name=export\_button

\<export\>

\<fileFormat type="csv"/\>

\<fileFormat type="xml"/\>

\</export\>

5. Define Analytics Source

  • Connect the dashboard to the data source using virtual type configuration.

  • Configure metric fields for accurate data aggregation in visuals.

  • Map URL parameters to save custom dashboard view settings.

  • Set up data aggregation for segment trend updates.

Building Custom Wishlist Collection with Customer Segment Joins

1. Create Custom Collection Class

  • Extend the Magento\Wishlist\Model\ResourceModel\Item\Collection class as the foundation.

  • Use the wishlist_item_id as the primary key for the records.

  • Override the _construct method to add custom initialization logic.

  • Add new methods for data manipulation and custom query building.

2. Join Wishlist Item Table

  • Link to the wishlist_item table for product IDs and catalog data access.

  • Access timestamps that show when customers added items to lists.

  • Retrieve quantity information for bulk order pattern analysis.

  • Include description fields that contain customer notes and preferences.

3. Join Wishlist Table

  • Connect to the main wishlist table for customer ID reference data.

  • Access sharing settings that control public wishlist visibility.

  • Track update timestamps for checking recent activity changes.

  • Support several wishlists per customer using the name field data.

4. Join Customer Entity Table

  • Add the customer_entity table to retrieve full customer information.

  • Access the first and last name fields for formatting customer names in the output.

  • Access email addresses for direct marketing communication needs.

  • Filter by the store_id field for multi-store customer segmentation.

5. Join Customer Group Table

  • Join the customer_group table to activate segment filtering features.

  • Use group codes as technical identifiers in database queries.

  • Display readable group names in the admin interface panels.

  • Link tax classes for applying group-specific pricing rules.

Setting Up Wishlist Segment Notification System

1. Define Notification Model

  • Create the Notification.php model in the Model directory to handle email logic.

  • Set the customer group ID as the primary filter for targeting segments.

  • Configure email templates for wishlist activity notifications.

  • Link the model to the wishlist collection for data-driven messages.

2. Configure Email Sender

  • Build the sender class in the Sender directory to dispatch segment emails.

  • Set sender identity using store configuration for brand consistency.

  • Include product details from wishlist items in email content.

  • Check recipient email addresses before sending messages.

3. Add Notification Trigger

  • Create a cron job in crontab.xml to schedule segment notifications.

  • Set trigger conditions based on wishlist activity by customer group.

  • Let the admin toggle to activate or deactivate notifications.

  • Log notification history for tracking and audit purposes.

4. Set Email Template

  • Add email_template.xml in the etc directory to define the notification format.

  • Include fields for customer names and wishlist items.

  • Configure template styles to match store branding guidelines.

  • Test template rendering with sample segment data.

5. Check Notification Delivery

  • Test email dispatch with sample customer segment data sets.

  • Check that the email content displays the correct wishlist item details.

  • Confirm notifications reach the intended segment recipients.

  • Track cron job execution for consistent delivery timing.

Configuring Wishlist Segment Report Access

1. Define Report Route

  • Create routes.xml file in etc/adminhtml directory with a unique report identifier.

  • Set the front name to construct clear URLs for report access.

  • Link the route to the module for accurate controller processing.

  • Use an admin router for built-in security protections.

2. Create Report Controller

  • Build a controller class extending Magento\Backend\App\Action.

  • Set the report title in the execute method for browser display.

  • Return the page result to render the wishlist segment report interface.

  • Check permissions before processing report data.

3. Set Up Report Menu

  • Add the menu entry in menu.xml under the marketing section.

  • Set the sort order to position the menu item for easy access.

  • Define ACL resource for report access restrictions.

  • Link action to the defined report route path.

4. Configure Report Permissions

  • Create the permission structure in the acl.xml configuration file.

  • Use names to clarify the report access purpose for admins.

  • Map permissions to marketing roles for targeted access.

  • Set titles to display in admin permission settings.

Note: You need full admin permissions to configure modules and ACL settings.

5. Verify Report Access

  • Clear caches to apply new configuration changes.

  • Test menu item visibility for authorized marketing users.

  • Check report loads without errors or broken elements.

  • Confirm unauthorized users receive access denied messages.

These database tables work together to support wishlist queries:

Table Name Primary Key Foreign Keys Purpose Critical Fields
wishlist wishlist_id customer_id Stores the main wishlist data updated_at, shared, customer_id
wishlist_item wishlist_item_id wishlist_id, product_id Individual wishlist items added_at, description, qty
customer_entity entity_id group_id, store_id Customer account records email, firstname, lastname
customer_group customer_group_id - Defines customer segments, referenced by customer_entity via group_id customer_group_code, tax_class_id
catalog_product_entity entity_id - Stores product data, referenced by wishlist_item via product_id sku, type_id, created_at
cataloginventory_stock_item item_id product_id Inventory stock levels qty, is_in_stock, manage_stock

Testing and Performance Optimization

1. Verify Grid Display

 Magento 2 admin grid interface verifying wishlist filter display for customer segments

  • Check grid renders without any JavaScript console error messages.

  • Test all columns show data using the correct display formats.

  • Confirm filter inputs respond to user actions without delays.

  • Check pagination displays accurate total record count numbers.

2. Test Customer Group Filter

  • Check that each segment filter returns the correct customer sets.

  • Test different filter combinations to work without data conflicts.

  • Check empty results display helpful user messages. For empty wishlists, make sure the grid displays a 'No results found' message.

  • Confirm filter settings persist across page navigation actions.

3. Check Data Accuracy

Magento 2 wishlist analytics dashboard checking data accuracy for customer segment trends

  • Compare grid output data against direct SQL query results.

  • Check export files contain complete and accurate data sets.

  • Test edge cases, including empty wishlists and null values. For null values, use COALESCE in SQL queries, e.g.,:

COALESCE(customer_group_code, 'Unknown')

  • Check that timezone handling works right for all date fields.

4. Database Query Optimization

  • Before adding new indexes, check for existing ones to avoid redundancy. Then, add database indexes on columns used in join operations.

  • For example:

ALTER TABLE wishlist ADD INDEX idx_customer_id (customer_id);

ALTER TABLE wishlist_item ADD INDEX idx_wishlist_product (wishlist_id, product_id);

ALTER TABLE customer_entity ADD INDEX idx_group_store (group_id, store_id);

  • Use the EXPLAIN command to identify slow query components.

  • Limit SELECT statements to fetch the required data fields.

  • Set up query caching for repeated data requests.

Note: You need SQL query access to add indexes and perform optimization.

5. Verify Scalability

Magento 2 wishlist module scalability test results for customer segment performance

  • Load test using production-level data volumes and user counts.

  • Check response times during peak usage period simulations.

  • Track memory consumption during large data export operations.

  • Test concurrent user access patterns and connection limits.

FAQs

1. How do I troubleshoot the filter for the Magento 2 grid performance issues?

Review the SQL queries generated by your filter in the collection’s query log. Verify index usage on filtered columns. Review the argument configuration in your collection class. Poor performance often stems from missing indexes or incorrect join definitions.

2. Can I track wishlist conversion rates by customer segment?

Yes, build conversion tracking into your wishlist grid module. Join the order tables with wishlist data to see sale rates. Track which segments convert wishlists to sales most often. Export this data for marketing analysis.

3. What's the approach to add a custom filter to the Magento grid?

Define a filter in Magento 2 by modifying your collection class. Add proper PHP namespace structure for the organization. Configure the filter for the product grid using virtual types. This approach maintains a clean code architecture.

4. How do I handle deleted products in wishlist grids?

Check product status before displaying wishlist items. Add validation to skip deleted or disabled products. Show a message when products become unavailable. This prevents broken links and data accuracy.

5. Can wishlist grids work with multi-store setups?

Yes, filter wishlists by store view using the store_id field. Each store can have unique customer segments. Configure separate ACL permissions per store. Admin users see only their assigned store data.

6. How do I schedule automatic wishlist reports for marketing teams?

Create cron jobs to generate segment reports. Schedule daily or weekly exports based on needs. Send reports via email to marketing managers. Include trend analysis comparing current and previous periods.

7. What happens to wishlist data during customer group changes?

Wishlist items remain linked to customers when groups change. Historical data stays intact for analysis. New wishlist additions reflect the updated segment. Configure your joins to track both current and historical segments.

Summary

Magento 2 admin grid filter transforms wishlist management from basic to powerful. This implementation integrates a modular architecture with high performance.

  • Module structure provides a clean and organized code architecture.

  • Analytics dashboards create insightful segment trend visuals.

  • Custom collections make complex data relationships possible.

  • Database optimization maintains fast query execution speeds.

  • Security controls protect sensitive customer information.

Power your custom wishlist grids with high-performance Managed Magento Hosting infrastructure.

Vidya Raner
Vidya Raner
Technical Writer

Vidya Raner is a seasoned technical writer with a deep understanding of Magento and eCommerce. She creates clear, concise, and practical content focused on Magento performance, scalability, and best practices. At MGT-Commerce, she simplifies complex concepts to support both developers and store owners.


Get the fastest Magento Hosting! Get Started