VOOZH about

URL: https://deepwiki.com/MahoCommerce/maho/14.4-helper-classes

⇱ Helper Classes | MahoCommerce/maho | DeepWiki


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

Helper Classes

Helper classes in Maho provide utility functions and common functionality that can be reused across models, blocks, and controllers. They are singleton objects accessed through the Mage::helper() factory method and typically contain stateless utility methods for formatting, validation, data transformation, and other cross-cutting concerns.

For information about the core Mage static class and its factory methods, see Mage Static Class For configuration system details, see Configuration API

Purpose and Scope

Helper classes serve as utility repositories that:

  • Provide reusable functionality across different layers of the application.
  • Encapsulate common operations like formatting, encryption, and validation.
  • Offer translation and localization support via the __() method app/code/core/Mage/Core/Helper/Abstract.php165-171
  • Act as service-oriented helpers for specific modules.
  • Maintain stateless operations using the singleton pattern through Mage::helper().

Sources: app/code/core/Mage/Core/Helper/Data.php19-48 app/code/core/Mage/Core/Helper/Abstract.php12-33

Helper Architecture

The following diagram illustrates how helpers are positioned within the Maho architecture and how they are accessed by other system components.

Helper Component Mapping


Sources: app/code/core/Mage/Core/Helper/Data.php19-20 app/code/core/Mage/Core/Helper/Abstract.php12-13 app/code/core/Mage/Core/Block/Abstract.php251 app/code/core/Mage/Adminhtml/Helper/Sales.php12 app/code/core/Mage/Adminhtml/Helper/Dashboard/Data.php12

Helper Instantiation Flow

Helpers are instantiated lazily. When Mage::helper('alias/path') is called, the system resolves the class name based on the module configuration and stores the instance in a static registry to ensure it remains a singleton for the duration of the request.

Instantiation Sequence


Sources: app/code/core/Mage/Core/Block/Abstract.php251 app/code/core/Mage/Core/Helper/Abstract.php105-112

Accessing Helpers

Helpers are accessed via the Mage::helper() static method with an alias string. Each helper is instantiated once and cached in the internal registry.


Sources: app/code/core/Mage/Core/Block/Abstract.php251 app/code/core/Mage/Core/Helper/Abstract.php105-112

Core Helper Classes

Mage_Core_Helper_Data

The primary helper for core functionality, handling currency, dates, and encryption. It also manages complex tasks like table re-encryption during system security updates.

Key Methods:

MethodPurposeImplementation
currency($value, ...)Convert and format price value for current storeapp/code/core/Mage/Core/Helper/Data.php88-91
formatDate($date, ...)Format date using current locale and timezoneapp/code/core/Mage/Core/Helper/Data.php152-155
getEncryptor()Lazy-load the encryption model instanceapp/code/core/Mage/Core/Helper/Data.php65-78
recryptTable(...)Iterates through a table to re-encrypt sensitive columnsapp/code/core/Mage/Core/Helper/Data.php518-568

Constants:

Sources: app/code/core/Mage/Core/Helper/Data.php21-568

Mage_Adminhtml_Helper_Sales

Provides specialized logic for displaying prices and filtering collections within the administrative interface.

Key Methods:

MethodPurposeImplementation
displayPrices(...)Generates HTML for both base and order currency pricesapp/code/core/Mage/Adminhtml/Helper/Sales.php46-72
applySalableProductTypesFilter(...)Filters collections based on allowed admin product typesapp/code/core/Mage/Adminhtml/Helper/Sales.php80-99
escapeHtmlWithLinks(...)Escapes HTML while preserving and validating <a> tagsapp/code/core/Mage/Adminhtml/Helper/Sales.php108-143

Sources: app/code/core/Mage/Adminhtml/Helper/Sales.php12-144

Common Usage Patterns

In Template Files (.phtml)

Helpers are frequently used in templates for localized output and formatting. Blocks often delegate specific formatting tasks to helpers.


Sources: app/code/core/Mage/Adminhtml/Block/Sales/Order/View/History.php79-82 app/code/core/Mage/Adminhtml/Helper/Sales.php108-143

During System Events (Encryption Key Rotation)

Helpers are used in observers to perform complex data transformations. A prominent pattern in Maho is listening to the encryption_key_regenerated event to re-encrypt module-specific data via the CLI command sys:encryptionkey:regenerate lib/MahoCLI/Commands/SysEncryptionKeyRegenerate.php25-29

Observers in modules like Mage_Payment use the core helper to update encrypted fields when the system key changes app/code/core/Mage/Payment/Model/Observer.php166-184


Sources: app/code/core/Mage/Payment/Model/Observer.php166-184 lib/MahoCLI/Commands/SysEncryptionKeyRegenerate.php126-130

Encryption Helper Logic

The Mage_Core_Helper_Data class manages the encryption subsystem by lazily loading the encryption model defined in the system configuration.

Encryption Model Resolution


Sources: app/code/core/Mage/Core/Helper/Data.php65-78

Helper Inheritance Structure

All helpers must inherit from Mage_Core_Helper_Abstract to gain access to the translation system and basic request utilities.


Sources: app/code/core/Mage/Core/Helper/Data.php19 app/code/core/Mage/Core/Helper/Abstract.php12 app/code/core/Mage/Adminhtml/Helper/Sales.php12 app/code/core/Mage/Adminhtml/Helper/Dashboard/Data.php12