Skip to content

AI Content Generation Admin

Flow ID: AD-47 | Module(s): Ai (domain layer), ai (legacy module) | Complexity: High Last Updated: 2026-04-04

Business Context

The AI content generation system integrates OpenAI (and potentially other LLM providers) to help administrators generate product descriptions, blog content, category descriptions, and other text content directly within the admin panel. The system has two major subsystems:

  1. Content Generation: The actual text generation pipeline, backed by OpenAI's completion API. Administrators provide a prompt, and the system generates text that can be applied to product fields, blog articles, or other entity fields. Every generation is logged for audit.

  2. AI Positions: Configuration for AI-powered product recommendation widgets on the storefront. Each "position" defines a placement on a specific page (product detail, cart, homepage, etc.) with parameters for recommendation type, minimum items, and request limits.

Both subsystems have full modern domain layers with REST CRUD APIs, while the content generation also has a legacy library layer that integrates directly with OpenAI.


API Reference

REST Endpoints -- Content Generation

MethodPathActionDescription
GET/rest/ai/content-generationindexList generation log entries (paginated)
GET/rest/ai/content-generation/itemitemGet single entry by filter
GET/rest/ai/content-generation/{id}showGet entry by ID
POST/rest/ai/content-generationstoreCreate/log a generation entry
POST/rest/ai/content-generation/{id}updateUpdate a generation entry
DELETE/rest/ai/content-generation/{id}destroyDelete a generation entry

Filters: id (exact), user (exact), field (exact), entityType (exact), lang (exact) Sorts: id

REST Endpoints -- AI Position

MethodPathActionDescription
GET/rest/ai/positionindexList positions (paginated)
GET/rest/ai/position/itemitemGet single position by filter
GET/rest/ai/position/{id}showGet position by ID
POST/rest/ai/positionstoreCreate a position
POST/rest/ai/position/{id}updateUpdate a position
DELETE/rest/ai/position/{id}destroyDelete a position

Filters: id (exact), slug (exact), recommendationType (exact), page (exact), active (exact), title.{locale} (partial via MUI) Sorts: id, slug, title.{locale}Relations: translations (one_to_many)

Legacy Admin Routes

AI settings and content generation are managed through the legacy AI module controllers:

RouteControllerPurpose
settings/advisable-ai/(.+)AdvAdvisableAiSettingsAI provider settings page
xml/advisable_aiAdvAdvisableAIXmlAI data feed XML export

Code Flow

Content Generation (Legacy Library)

  1. Admin triggers content generation from a product/entity edit page.
  2. The admin page calls the AdvContentGeneration library with a prompt string.
  3. generate($content, $user, $provider): a. If no provider specified, creates getDefaultProvider() using OpenAI with registry-stored config. b. Calls $provider->generateCompletion($content, $user) which sends the prompt to OpenAI's completions API. c. Returns the generated text.
  4. The calling controller logs the generation in ai_content_generation table via the model.
  5. The generated text is returned to the admin UI for review and application.

Content Generation (REST API)

The REST API primarily serves as a log/audit layer for content generation records:

  1. POST /rest/ai/content-generation with:
    json
    {
      "user": "admin@example.com",
      "field": "description",
      "entityType": "product",
      "prompt": "Write a description for...",
      "generatedText": "Generated content...",
      "lang": "el"
    }
  2. Controllers\ContentGeneration::store() -> WriteService::create().
  3. WriteData::fromArray() maps to entity columns.
  4. Inserts into ai_content_generation with automatic timestamps.

AI Position Management

  1. GET /rest/ai/position?filter[active]=1&with=translations
  2. Returns active recommendation positions with localized titles.
  3. Storefront recommendation widgets query positions by slug to determine which recommendation types to display and how many items to request.

Domain Layer

ContentGeneration (src/Domains/Ai/ContentGeneration/)

ComponentClassDescription
EntityRepository\Entityid, user, field, entity_type, prompt, generated_text, entry_date, entry_datetime, lang
RepositoryRepository\RepositoryTable ai_content_generation
RepositoryConfiguratorRepository\RepositoryConfiguratorNo relations
ServiceServiceRead service
WriteServiceWriteServiceFull CRUD
WriteDataWriteDataAll entity fields as writable properties
ValidatorValidatorStub validator

Position (src/Domains/Ai/Position/)

ComponentClassDescription
EntityRepository\Entityid, slug, recommendation_type, page, min_items, request_limit, active. Implements FilterTranslation
MuiEntityRepository\MuiEntityMUI translations for position titles
RepositoryRepository\RepositoryTable ai_position
MuiRepositoryRepository\MuiRepositoryTranslation repository
ServiceServiceRead service with MUI filter/sort
WriteServiceWriteServiceFull CRUD with MUI writes
WriteDataWriteDataslug, recommendationType, page, minItems, requestLimit, active
MuiWriteDataMuiWriteDataTranslation write data
FilterByTranslationSpecification\FilterByTranslationMUI join for title filtering
SortByTranslationSpecification\SortByTranslationMUI join for title sorting

REST Layer (src/Rest/Ai/)

ComponentClassDescription
ControllerControllers\ContentGenerationFull CRUD with HandlesWriteActions
ControllerControllers\PositionFull CRUD with HandlesWriteActions
ResourceResources\ContentGeneration\ResourceGeneration log entry resource
ResourceResources\Position\ResourcePosition resource with translations
MuiResourceResources\Position\MuiResourcePosition translation resource

DI Container (src/Domains/Ai/container.php)

Registers all ContentGeneration and Position domain services, repositories, write services, and validators.


Architecture

Legacy AI Module (ecommercen/ai/)

ComponentPathPurpose
AdvContentGenerationecommercen/ai/libraries/AdvContentGeneration.phpOpenAI integration library
AdvAIConnectorecommercen/ai/libraries/AdvAIConnector.phpHTTP client for AI service
CoreAIConnectorecommercen/ai/libraries/CoreAIConnector.phpCore connector abstraction
AdvAdvisableAIecommercen/ai/libraries/AdvAdvisableAI.phpAdvisable AI recommendation engine client
AdvAIRecommendationPagesecommercen/ai/libraries/AdvAIRecommendationPages.phpPage type definitions for recommendations
AdvAIRecommendationTypesecommercen/ai/libraries/AdvAIRecommendationTypes.phpRecommendation algorithm types
AdvAIRecommendationViewModelecommercen/ai/libraries/AdvAIRecommendationViewModel.phpView model for recommendation widgets
AdvAiContentGenerationecommercen/ai/models/AdvAiContentGeneration.phpLegacy model for generation log
AdvAIPagePositionsecommercen/ai/models/AdvAIPagePositions.phpLegacy model for position management
aiContentGenerationTraitecommercen/ai/traits/aiContentGenerationTrait.phpShared trait for content generation
AdvAdvisableAiSettingsecommercen/ai/controllers/AdvAdvisableAiSettings.phpAI settings admin controller

Modern Layer

ComponentPathPurpose
Domain containersrc/Domains/Ai/container.phpDI registration
REST containersrc/Rest/Ai/container.phpREST controller registration
REST routesapplication/config/rest_routes.php:1249-1278Content generation and position routes

Data Model

ai_content_generation

ColumnTypeDescription
idint (PK)Auto-increment primary key
uservarcharUsername who triggered generation
fieldvarchar (nullable)Target entity field (description, title, etc.)
entity_typevarchar (nullable)Entity type (product, blog, category)
prompttext (nullable)AI prompt used for generation
generated_texttextAI-generated text output
entry_datedate (nullable)Generation date
entry_datetimedatetime (nullable)Generation timestamp
langvarcharLanguage code of generated content

ai_position

ColumnTypeDescription
idint (PK)Auto-increment primary key
slugvarcharUnique slug identifier for the position
recommendation_typevarcharAI algorithm type (similar, complementary, trending, etc.)
pagevarcharStorefront page (product, cart, home, category)
min_itemsintMinimum items needed to display the widget
request_limitintMaximum items to request from the AI engine
activetinyintWhether the position is enabled (1=yes, 0=no)

ai_position_mui

ColumnTypeDescription
position_idint (FK)Position ID
titlevarcharLocalized widget title (e.g., "You may also like")
langvarcharLanguage code

Configuration

Registry Keys (OpenAI Provider)

GroupKeyDescription
AI_CONTENT_GENERATION_PROVIDER_OPEN_AIIS_ENABLEDFeature toggle for OpenAI
AI_CONTENT_GENERATION_PROVIDER_OPEN_AIAPI_KEYOpenAI API key
AI_CONTENT_GENERATION_PROVIDER_OPEN_AICOMPLETIONS_API_URLAPI endpoint URL
AI_CONTENT_GENERATION_PROVIDER_OPEN_AITIMEOUTRequest timeout (seconds)
AI_CONTENT_GENERATION_PROVIDER_OPEN_AIMODELModel name (e.g., gpt-4)
AI_CONTENT_GENERATION_PROVIDER_OPEN_AIMAX_TOKENSMaximum tokens per response
AI_CONTENT_GENERATION_PROVIDER_OPEN_AITEMPERATURECreativity parameter (0-2)
AI_CONTENT_GENERATION_PROVIDER_OPEN_AITOP_PNucleus sampling parameter
AI_CONTENT_GENERATION_PROVIDER_OPEN_AINNumber of completions
AI_CONTENT_GENERATION_PROVIDER_OPEN_AISTREAMWhether to use streaming
AI_CONTENT_GENERATION_PROVIDER_OPEN_AILOGPROBSLog probability setting
AI_CONTENT_GENERATION_PROVIDER_OPEN_AIECHOEcho prompt in response
AI_CONTENT_GENERATION_PROVIDER_OPEN_AISTOPStop sequences
AI_CONTENT_GENERATION_PROVIDER_OPEN_AIPRESENCE_PENALTYPresence penalty (0-2)
AI_CONTENT_GENERATION_PROVIDER_OPEN_AIFREQUENCY_PENALTYFrequency penalty (0-2)
AI_CONTENT_GENERATION_PROVIDER_OPEN_AIBEST_OFBest-of sampling
AI_CONTENT_GENERATION_PROVIDER_OPEN_AISUFFIXCompletion suffix

Client Extension Points

  • Override AdvContentGeneration: Add custom AI providers by extending the library and adding provider cases to getProvider().
  • Override Position RepositoryConfigurator: Add custom relations to positions.
  • Custom prompts: Client repos can customize prompt templates in their admin controllers.
  • Override WriteService: Add custom post-generation hooks (e.g., auto-apply generated content to entities).

Business Rules

  1. Provider abstraction: The CompletionAI interface allows plugging in different AI providers, though only OpenAI is currently implemented.
  2. Audit logging: Every content generation is logged with the user, prompt, output, target field, entity type, and language.
  3. Position activation: Positions have an active flag -- disabled positions are ignored by storefront widgets.
  4. Minimum items threshold: The min_items field prevents showing recommendation widgets when too few items match.
  5. Request limit: The request_limit caps how many items the AI engine returns, controlling API costs and response size.
  6. Language-aware: Content generation is language-specific, allowing generation in any configured language.

Wiki Guide: Advisable AI Guide -- developer reference for the AI integration system