How Light fits together
The parts of Light, a request to a Light page, the three ways to plug in, and the public API, as diagrams.
Light is a set of Magento modules. Your module talks to it the Magento way: DI items in pools, blocks in named containers, and a handful of @api interfaces. This page draws how those parts connect. The recipes show how to use each one.
The parts
- Light core is the 15 modules of
Surface::CORE_MODULES. They ship together with one API version. - Packs (
packages/) are modules outside core that fill core's pools and containers:Mrx_CountryNlholds what is Dutch,Mrx_PaymentsMollieandMrx_PaymentsPaynlconnect a payment provider, andMrx_ProductBundles,Mrx_ProductGroupPagesandMrx_ProductDownloadsadd kinds of product. Core names none of them, so a shop installs the packs it needs. The doctor and the compatibility gate check a pack like any module (Ship it as a pack). - The catalogue lists every extension point: the pools your
di.xmladds items to, the layout containers and handles, the seven editor forms, the public JS modules and the events. Extension targets prints it. - The compatibility gate reads the Light API range each module declares and hides what an out-of-range module adds, before any pool is read (Versioning).
- The
-hyvamodules hold the Hyvä storefront code of core modules, so Light itself never needs Hyvä (Hyvä code in a -hyva module). - The checks keep all of it honest: the doctor reads what every module registers, the surface snapshot keeps the API stable, and the guards prove a module landed without a change to core (Testing).
Kinds of product
A merchant chooses what to add before the editor opens. The kinds are a pool, and the editor, the list and the order screen read it without naming any pack:
Kindsis the poolproduct_kinds. It drops an item whose Magento module is off, one the admin has no ACL resource for, and one whose type Magento doesn't register, then sorts bysort_order.forType()is how the list, the editor and the Stock redirect learn which kind owns a type.- The way in shows only when a pack is installed: a second button on the product list, a quiet link under the title of Add product, and a chooser with a card for each kind. One pack skips the chooser.
- The editor knows its kind through
ProductKindContextInterface, bound to the same view model asProductPageContextInterface. A pack's card shows itself for its own kind, and its form extension runs inside the editor's transaction like any other (Fields on a Light editor). - Orders reads the pool
draft_product_typesfor the product types it doesn't handle itself, so a bundle or a group page can go on a manual order without Orders naming either. - Without a pack nothing here is missing in the product list: a bundle or group page that already exists opens read-only with a link to the advanced view, and the doctor warns
product_kind_pack.
Add a kind of product and Draft orders for a product type show both halves in code.
A request to a Light page
Every Light page is a controller on the admin front name light. Nothing of it answers before a complete sign-in: signed in and, where Magento_TwoFactorAuth is on, past the second factor (Model\Auth\AdminAccess). Where admins sign in with an Adobe ID (Magento_AdminAdobeIms), Magento skips its own second factor and Light counts that sign-in as complete. The gate answers 404 for a controller whose module is off or hidden, and the blocks read the pools through ModuleGate, so an item of a hidden module never renders:
Light asks Magento_TwoFactorAuth itself whether the second factor is done, so a module that skips Magento's two-factor check without granting the session keeps Light closed while stock pages open. Light keeps sending you to the two-factor screen has the fix. The same check decides whether Light reads anything of the admin: their own theme, their pinned apps and their counts wait for the complete sign-in too.
A shared page: og:image and the card
The storefront half of Light is small: one block and one template write the og: tags, and two pools decide the image. The admin shows the same answer in the editors' preview (A share image for your page):
- The page names its kind. Light's layout files set
category,cmsandsearch, andcms_index_indexsets the argumenthome(true), which turns the merged kindcmsintohome; the default isother; the product page usesproduct; a module sets its own kind with the layout argumentkindin its frontend handle. - With Mage-OS SEO, one writer per tag.
MageOsShareTagscloses Light's block on the three handles Mage-OS SEO covers while its Open Graph switch is on for the store view. Mage-OS SEO's compositor writes the texts; the bridge'sShareImageProviderwraps its product, category and CMS page providers, replaces onlyog:imagewith the pool's answer and adds the sizes. On a shop without Mage-OS SEO or the bridge nothing changes (With Mage-OS SEO). - Sources give images or cards. A source returns a finished URL or asks for a card with a kind, a title and a product photo. It never builds a card URL:
CardUrlchecks the kind, cuts the title to 160 characters, checks the photo's format and signs the URL with the shop's key. - The card controller is strict. It draws only the URL
CardUrlwrites, for the store view in the URL, and checks every answer of a renderer (type, at most 5 MB, exactly 1200 × 630 pixels). Behind Magento's Varnish the year-long copy of a card lives in Varnish only. - Light reads no field of its own. The
share_imageof a product, a category and a CMS page belongs toMrx_CatalogandMrx_Content, which add their source to the pool.
A list request, with filters
A Light list is one page and one data route. The page prints the list's config once, with its filters and the filters already in the URL, so the first rows come with it. After that, every change of a tab, search, sort, page or filter asks light/table/data and writes the same state to the page URL with history.pushState. A filter with a long option list asks light/table/options once, when the merchant opens it:
- Light validates, the provider binds.
FilterParserchecks each value against the list's own definitions beforegetRows()runs, so a provider readsQuery::getFilterValue($key)and never parses a string. An invalid value is dropped and the list still opens. - Another module's filter is one subselect.
FilterExtensionInterface::getMatchingIds()returns aSelectof row ids, and the list ANDs<row id> IN (...)to its rows and count queries. The provider's own aliases stay its own. - Counting is bounded. A short first page ends the list without a count. A filtered or searched list counts up to 10,000 and answers
total_capped, which the pager shows as "10,000+". That count runs under a time limit of 200 ms (MariaDB'smax_statement_time, MySQL'sMAX_EXECUTION_TIME): when the limit stops it, as for a rare value on a big shop, the count is skipped, the provider answerstotal_knownfalse and the pager shows "1–50" with Next on while pages come back full. The page past a capped or unknown total is asked as it is, never clamped. A list that skipped its total shows a "Count" button in the footer (since 0.17.0): it callslight/table/count, which counts exactly that view under a longer limit and answerstotal,totalCappedandtotalKnown. - Time is measured on the server.
Timingcollectsrows,count,extandtotalfor the request, andlight/table/dataandlight/table/optionssend them asServer-Timing. The browser's network panel shows them; Light lists says what to check.
AI: the cost flow and the translation records
Light owns no AI table. Two flows show where its screens end and the Disrex packages begin.
The cost calculator. Settings > AI renders its rows from the pool ai_calculator_jobs and makes no request. One press of
"Work it out" asks light/settings/aicalculator once; Mrx_Settings prices every row by hand from one
CostProfileInterface::forPurposes() call and the translation row from CatalogCostEstimateInterface, the code the bulk dry
run uses. A row with another unit (option names) asks its UnitCounterInterface, which only passes Disrex_AiCatalog's dry
run on. The browser multiplies and follows a model the merchant picks; "Measure with your own products" is the one path
that spends money.
The translation records. Disrex_AiCatalog keeps three records of its own next to the SDK's job tables
(disrex_ai_job, disrex_ai_job_item, disrex_ai_usage): the translation log (every translation with its text before
and after, its origin and, with review on, its waiting state), the state of each text (what it was translated from) and
the coverage tables (per store view and type, the counts the overview shows). Light's Products > Translations page only
reads them through services and posts decisions back.
A module that adds a translatable type adds a coverage source, its mview view and its indexer; the overview lists the type without a template edit (AI in your module, step 13).
The admin assistant on Disrex AI
With disrex/module-ai-mago installed, Mago's chat calls the model through Disrex AI, so it uses the key, limits and usage report of Settings > AI. A plugin routes only the consumer mago_assistant; every other ai-base consumer runs as before.
Emails and documents
Mrx_Documents gives every customer email one look from one brand kit: the store's logo, the owner's accent colour, the footer text and the company details, in one of the formats of the formats pool. A module writes only the body; the stock header and footer includes lead into Light's shell:
ApplyEmailTexts puts the subject, opening text and button text the owner saved in Settings > Customer emails into a body of the emails pool as it loads, MapShellIds maps the stock header and footer ids to Light's when the shop uses Light's emails (under "keep" it loads the stock ids back for every body in the light_bodies pool, and ShellScope keeps Light's shell around Light's own emails), SwapCssTokens fills the __MRX_*__ tokens of the email CSS with the brand kit of the mail's store, and Emogrifier inlines the result. When the mail is sent, AddPlainTextPart adds a plain-text part made from the HTML. RememberEmailContext notes the template id and what the vars say about the order while the mail is built, and KeepSentCopy stores an exact copy of a customer mail about an order in mrx_documents_sent_email once it went out. The order page's timeline reads those copies and links each mail's line to it (Copies of sent mails). Your module's email and document is the contract.
DocumentsChoiceInterface holds the merchant's choice, one pair of switches per shop, and every plugin that replaces a Magento email or PDF asks it first; installing Light leaves both off (Keep or Light's). The same brand kit prints the PDFs. Every stock caller of an invoice, credit memo or packing slip PDF (the print buttons, the mass actions with "Print All", Light's "Print invoices", the accountant ZIP) calls getPdf(), and an around plugin answers it without the stock drawing code:
A document type in the documents pool supplies the data and the body template, the item_lines pool the rows of the items table, and the document_sections pool blocks from other modules after the parties, items or totals. The order confirmation has no stock PDF, so only the download route and DocumentRendererInterface reach it; the picklist reads bin locations from the pick_locations pool. Engine renders each store view's documents in that store's language, at most 25 to a dompdf run, and merges the runs. DocumentPdf hands the bytes back as a \Zend_Pdf, whose render() returns them as they are and whose pages "Print All" merges with the packing slips, which are dompdf documents too.
The same PDFs reach the customer two more ways. AttachingSenderBuilder replaces the SenderBuilder of Magento's seven sales senders and adds the invoice, credit memo or order confirmation PDF to the email. One setting, mrx_documents/invoice/send_with, decides which email carries the invoice: the shipping confirmation (the default), "Payment received" or none, and the refund email carries the credit memo. mrx_documents_invoice_mailed remembers which invoices went out, so each travels once. Returns' own EmailSender puts the return slip on the customer's approval mail with MessageAttacher, the class the builder attaches with. In My Account and the guest order view, ServePdfOnPrint answers "Print invoice" and "Print refund" with the PDF once the stock controller has checked the order (PDFs on customer emails).
Customer text in two forms
Dutch and German address a customer two ways, and the merchant picks one per language of a channel. Magento builds the dictionary of a store in layers, and the variant files take the pack's slot:
PreferModulePhrases runs first: for the phrases in the pool prefer_phrases it writes the named module's row over the language pack's, where a pack gets a phrase wrong for Light (German "Returns" as "Details anzeigen"). FormOfAddressRows is an afterGetDictionary plugin on Magento\Framework\App\Language\Dictionary. In a customer area (storefront, REST, GraphQL) and in store emulation, it merges the variant file for the store's form from every enabled module into the pack's rows. Every mail and PDF renders in store emulation, so they follow the form too. The admin keeps its own dictionary. A theme's CSV and the merchant's inline edits load later and win. js-translation.json is one static file per theme and locale, so KeepJsDictionaryNeutral builds it from the base rows only (Channels and store views).
Countries
Core knows three things about a country: the home country in Business details, the One Stop Shop for an EU home country, and the identifiers a country module supplies through the pool country_rules. The Taxes page runs on Magento's own tax tables, so a shop anywhere can add its rates, switch "Prices include tax" and say it doesn't charge tax. A country module adds what is specific to its country in three places: an item in country_rules for the business registration number, the tax ID and the postcode; cards in the containers mrx.settings.taxes.preset, mrx.settings.taxes.cross_border, mrx.settings.business.registration and mrx.settings.payments.providers; and block arguments that change the wording of a core card. Carriers and legal page drafts are pools too (carriers, legal_page_templates and legal_page_types). The Dutch parts live in the pack Mrx_CountryNl (packages/module-country-nl): the Dutch VAT setup, the KvK number and Dutch VAT number checks, the postcode, the address order, PostNL and the Dutch tracking links, and the legal page drafts. A shop in another country runs core on its neutral defaults, and the doctor rule country_pack warns when a known pack for the shop's country isn't enabled. A settings page from your system.xml shows each place.
Reverse charge: the net price
Settings > Taxes has a switch "Business customers in other EU countries". Light leaves the VAT number check to Magento (it moves a customer to the group the check names) and adds one plugin, because Magento charges a 0% customer the gross price while cross-border trade is on, and Light keeps that on for OSS. A customer in the group who orders abroad without a VAT number on the delivery or the billing address pays the VAT a consumer pays, so the plugin swaps to the retail class for that calculation too. The plugin works only inside a tax calculation for the Business EU class, and a delivery inside the home country never gets it.
The rule reads the order's amounts, addresses and VIES check, never its customer group (Magento's last address pass sets that) or the class of today, so a document printed years later says the same.
The VAT outcome check
Settings > Taxes asks Magento what each kind of customer pays in each EU country and compares it with the mode the merchant chose. It never calculates VAT itself, and only the panel on that page runs it. The OSS card and the rates table read the kept result without calculating. The Dutch pack asks Magento the same question through a smaller check of its own (VatProbe), and Home's step and the status badge follow that check, until 0.11.0 gives the pack the core one.
A cell that could not be asked (an empty tax class or country) or failed is "could not check", never 0%. A result with a failed calculation serves that request only.
Locations and pickup
A location is a source of Magento's Multi-Source Inventory (MSI). Mrx_Locations adds Settings > Locations and reads the sources for the rest of Light, on a shop that has MSI; every write goes through MSI's own services, so a module that reads MSI sees what Light did:
- Simple mode. With MSI off or removed, or MSI on and one enabled source, a shop has one location: the business address. Every screen and every write is the single-quantity one, and pickup is Light's own carrier at the business address (
carriers/mrxpickup). - Locations mode. The first "Add location" runs the conversion: the business address becomes a source, the stock of the
defaultsource is copied to it, a stock Light makes (the Light stock) links both, the open orders' reservations and every channel move to it, anddefaultis set to 0. From then on stock is kept per location, a shipment carries the location it ships from, and pickup is Magento's In-Store Pickup at the locations that offer it (with Magento's in-store pickup modules off, Light's own carrier stays at the business address). - Module graph.
Mrx_Locationsdepends onMrx_Light,Mrx_Settings,Mrx_Catalog,Mrx_OrdersandMrx_Home; none of them depends on it, so a shop without MSI never loads it. Settings declaresLocationsInterfaceand the internalPickupProviderInterfacewith their simple-mode defaults, Catalog and Orders declare the small stock interfaces with defaults on Magento's own stock, and Locations replaces each preference with its MSI class. Only Locations names an MSI type. Documents and Returns read where a parcel shipped from through Orders.
Locations and pickup has the contract and the plugins Light adds on MSI.
Three ways to plug in
- Pattern A keeps the module you bridge untouched. Every call into it sits under
Model/Backend/, and a unit test holds that line. - Pattern B1 is XML only: scalar DI items on Light classes and layout on Light handles. Without Light, Magento ignores them, so the module installs on any shop.
- Pattern B2 is the PHP that needs Light types. Its range guard leaves it unregistered on a shop without Light, or with a Light outside its range.
Getting started builds both in about 15 minutes.
The public API
Everything your PHP may name is @api. The diagrams group the types by the job they do; API reference lists every type with every member, and the doctor reports private_api for anything else.
A ? in front of a return type in the code means the method may return null: getBadgeValue(): ?Badge answers null at 0. The diagrams leave the ? out.
Last updated on