VOOZH about

URL: https://deepwiki.com/MahoCommerce/maho/13.4-customer-segmentation-and-catalog-link-rules

⇱ Customer Segmentation and Catalog Link Rules | MahoCommerce/maho | DeepWiki


Loading...
Last indexed: 15 May 2026 (ea8ab8)
Menu

Customer Segmentation and Catalog Link Rules

This section documents the Maho-specific modules for advanced customer targeting and automated catalog management. These systems extend the core Mage_Rule engine to provide dynamic customer grouping and rule-based product relationships.

Customer Segmentation

The Maho_CustomerSegmentation module allows administrators to group customers dynamically based on various conditions (demographics, purchase history, shopping cart contents). These segments can then be used to target specific shopping cart price rules or trigger automated email sequences.

Core Architecture and Data Flow

The segmentation system relies on a background refresh process that evaluates customers against defined rules and persists the relationships in index tables for high-performance frontend lookups.

Key Classes and Models

  • Maho_CustomerSegmentation_Model_Segment: The primary model representing a segment, containing logic for matching and lifecycle management.
  • Maho_CustomerSegmentation_Model_Resource_Segment: Handles the heavy lifting of SQL-based matching and persistence to the customer_segment and customer_segment_customer tables.

Segmentation Data Schema

The system uses dedicated tables to manage segment definitions and customer memberships:

TablePurpose
customer_segmentStores segment metadata, priority, and serialized rules.
customer_segment_customerIndex table mapping customer_id to segment_id for fast lookups.
customer_segment_email_sequenceConfiguration for automated emails triggered by segment entry/exit.
customer_segment_sequence_progressTracks customer progress through multi-step email drip campaigns.

Segmentation Execution Flow

The following diagram illustrates how a customer is matched against a segment and how that information is utilized by the system.

Segmentation Matching Logic


Email Automation and Coupon Generation

Maho introduces an automated email sequence system within the Customer Segmentation module. This allows for "Drip Campaigns" where customers receive a series of emails after entering or exiting a segment.

Automation Components

  • Trigger Events: Customers can trigger sequences on enter (added to segment) or exit (removed from segment).
  • Step Management: Sequences are composed of steps with specific delay_minutes and max_sends per customer.
  • Coupon Generation: Steps can be configured to generate unique coupons using a coupon_sales_rule_id and optional coupon_prefix. The Mage_SalesRule_Model_Resource_Coupon resource handles persistence of these unique codes app/code/core/Mage/SalesRule/Model/Resource/Coupon.php13-23

Coupon Persistence and Rules

Maho utilizes the standard Mage_SalesRule resource models to manage rule-based pricing and coupons.

Sources: app/code/core/Mage/SalesRule/Model/Resource/Rule.php13-54 app/code/core/Mage/SalesRule/Model/Resource/Coupon.php13-42

Product Relationship Rules

The Maho_CatalogLinkRule module allows for the automated creation of product relationships such as Up-sells, Cross-sells, and Related Products.

Core Logic and Controllers

Admin management of these rules is handled by Maho_CatalogLinkRule_Adminhtml_Cataloglinkrule_RuleController app/code/core/Maho/CatalogLinkRule/controllers/Adminhtml/Cataloglinkrule/RuleController.php14 The controller handles CRUD operations and AJAX rendering for dynamic rule conditions and actions app/code/core/Maho/CatalogLinkRule/controllers/Adminhtml/Cataloglinkrule/RuleController.php182-192

Rules are applied by mapping POST data to the rule model via loadPost($data) app/code/core/Maho/CatalogLinkRule/controllers/Adminhtml/Cataloglinkrule/RuleController.php85

Entity Relationship: Catalog Link Rules


Sources: app/code/core/Maho/CatalogLinkRule/controllers/Adminhtml/Cataloglinkrule/RuleController.php14-112 app/code/core/Maho/CatalogLinkRule/controllers/Adminhtml/Cataloglinkrule/RuleController.php22-23

Directory Region Management

While not a rule engine, Maho provides advanced management for geographic regions via Mage_Directory. This includes a sophisticated import tool for ISO 3166-2 standards.

Region Import System

The system allows importing states/provinces with localized names from a central repository lib/MahoCLI/Commands/SysDirectoryRegionsImport.php27-32

Region Data Flow


Sources: lib/MahoCLI/Commands/SysDirectoryRegionsImport.php27-32 app/code/core/Mage/Core/Model/Translate.php81-122 app/locale/en_US/Mage_Directory.csv69-87

Catalog Rules and Pricing

Catalog rules provide dynamic discounts at the product level, calculated during indexing or on-the-fly for frontend display.

Core Logic and Persistence

Rule Date Handling

Maho handles rule validity periods by converting dates to GMT timestamps and ensuring they cover the full day (up to 23:59:59) for the end date app/code/core/Mage/CatalogRule/Model/Resource/Rule.php170-176 Dates are formatted using the locale's database format app/code/core/Mage/Rule/Model/Resource/Abstract.php43-57

Sources: app/code/core/Mage/CatalogRule/Model/Resource/Rule.php13-72 app/code/core/Mage/CatalogRule/Model/Observer.php13-48 app/code/core/Mage/CatalogRule/Model/Resource/Rule.php163-188 app/code/core/Mage/Rule/Model/Resource/Abstract.php43-61

Summary Table: Rule-Based and Dynamic Systems

FeaturePrimary Model / ControllerPersistence Table
Customer SegmentsMaho_CustomerSegmentation_Model_Segmentcustomer_segment
Product RelationshipsMaho_CatalogLinkRule_Adminhtml_Cataloglinkrule_RuleControllercatalog_link_rule
Catalog Price RulesMage_CatalogRule_Model_Rulecatalogrule
Shopping Cart RulesMage_SalesRule_Model_Rulesalesrule
Region ManagementMage_Directory_Model_Regiondirectory_country_region

Sources: app/code/core/Maho/CatalogLinkRule/controllers/Adminhtml/Cataloglinkrule/RuleController.php35 app/code/core/Mage/CatalogRule/Model/Resource/Rule.php71 app/code/core/Mage/SalesRule/Model/Resource/Rule.php39