Skip to content

Maho Admin Module

The Mageaustralia_Storefront module connects the Maho admin to the Cloudflare Workers storefront, keeping KV data in sync automatically.

Overview

When a merchant saves a product, category, CMS page, or store config in the Maho admin, an event observer captures the change and queues it in the core_flag table. A cron job runs every minute to process the queue, pushing only the changed entities to Cloudflare KV via the Worker's /sync endpoint. This means KV data is typically less than 1 minute behind the admin.

Event Observers

The module listens to 8 Maho events:

EventTrigger
catalog_product_save_afterProduct created or updated
catalog_product_delete_afterProduct deleted
catalog_category_save_afterCategory created or updated
catalog_category_delete_afterCategory deleted
cms_page_save_afterCMS page created or updated
cms_page_delete_afterCMS page deleted
core_config_data_save_afterStore config changed
store_save_afterStore view settings changed

Each observer writes a debounced entry to the sync queue. Multiple saves of the same entity within a cron cycle are collapsed into a single sync operation.

Sync Queue

The queue uses Maho's core_flag table:

Flag code: storefront_sync_queue
Flag data: JSON array of {type, id, action} entries

The cron job (storefront_process_queue) runs every minute:

  1. Reads and clears the queue atomically
  2. Groups changes by entity type
  3. Calls the Worker's /sync endpoint for each group
  4. Logs results to storefront_activity_log table

API Clients

Storefront API Client

Model/Api/Storefront.php — communicates with the Cloudflare Worker:

MethodEndpointPurpose
syncProducts($ids)POST /syncPush product data to KV
syncCategories($ids)POST /syncPush category data to KV
syncCmsPages($ids)POST /syncPush CMS pages to KV
syncConfig()POST /syncPush store config to KV
fullSync()POST /syncFull catalog sync
purgeCache($urls)POST /cache/purgePurge edge-cached URLs

Cloudflare API Client

Model/Api/Cloudflare.php — communicates directly with the Cloudflare API:

MethodPurpose
listKvKeys($prefix)List KV keys by prefix
deleteKvKeys($keys)Delete specific KV keys
purgeZoneCache($urls)Purge Cloudflare zone cache
createDnsRecord($name, $content)Add DNS record

Uses Symfony HttpClient (not cURL or Prototype.js).

Admin Dashboard

The module adds an admin section under System > Storefront with four controllers:

Dashboard

Overview of sync status, last sync time, KV key count, and recent activity log.

Sync Controller

Step-by-step sync interface:

  • Quick Sync — process pending queue items
  • Full Sync — re-sync all catalog data (products, categories, CMS, config)
  • Selective Sync — sync specific entity types

Cache Controller

  • Purge URLs — purge specific edge-cached URLs
  • Purge All — purge entire edge cache via Cloudflare API
  • Delete KV Keys — remove specific keys from KV

Onboard Controller

Multi-step provisioning for new stores:

  1. Create DNS record (CNAME to Workers)
  2. Configure Worker routes
  3. Initial full sync
  4. Verify storefront responds

Includes automatic rollback on failure.

Activity Logging

All sync operations are logged to the storefront_activity_log table:

ColumnDescription
actionsync, purge, delete, onboard
entity_typeproduct, category, cms_page, config
entity_idsJSON array of affected IDs
statussuccess, error
messageResult details or error message
created_atTimestamp

Configuration

Admin config under System > Configuration > Mageaustralia > Storefront:

FieldDescription
Storefront URLWorker URL (e.g., https://demo.mageaustralia.com.au)
Sync SecretShared secret for authenticating sync requests
Cloudflare API KeyFor direct CF API operations
Cloudflare EmailCF account email
Cloudflare Zone IDFor cache purge and DNS operations
Auto Sync EnabledEnable/disable observer-driven sync
Sync Cron ScheduleCron expression (default: * * * * *)

Source: app/code/local/Mageaustralia/Storefront/