Skip to main content

Services overview

A service is a class that does one job of the shop and is the only place that does it: write an order, change an order's status, record a payment, issue a document, calculate a cart. Screens, the REST API and plugins all end up in the same service, so the same rules apply whoever asked.

Most services are core's own. An extension does not call them. It takes part through a door: an event it handles, a method of the base class it extends, or a reader object that Alfa hands it. This page lists the service areas and names the door for each.

Read How events reach a plugin first. The words "commit", "ledger" and "background work" are in the Glossary.

What it does​

The services live in two folders:

FolderWhat is in it
administrator/src/Service21 folders and the file PriceIndexSyncService.php. The services that write: orders, payments, shipments, documents, stock, background work.
site/src/Service13 folders and the file Router.php. The storefront's services: the cart, the checkout, prices, and the readers that plugins receive.

The column For extensions? in the tables below has three answers:

AnswerWhat it means
Yes, with a doorAn extension takes part, through the event, base class or class named
Read onlyAlfa hands the extension an object of this area to read. The object has no method that changes anything.
No, core's ownThis manual documents no door into the area in 2.2.0. Do not call its classes.

When it is used​

Use this page when you know what you want to do and need to know where to start. Use the other pages of this section when you need to understand what a service guarantees, so that your plugin does not work against it.

The areas under administrator/src/Service​

AreaWhat it is forFor extensions?Read more
CardThe cards Alfa itself puts on the store's home screen (CoreCardProvider)Yes, through the event onAlfaCollectCardsDashboard cards
CartEvery write to the cart tables (CartRepository), whose cart it is and who operates it (CartSubject), the cart's lifetime, and the objects that cart events hand to plugins (Cart/Plugin)Read only, plus one builder: the charge a plugin declares in onCartTotalsCart and checkout
CatalogWho may see which items and categories (CatalogAccessPolicy), and the notices sent when that changesYes, through the events onCatalogVisibilityChanged and onAlfaCatalogEntityChangedItem and catalogue events
ClearDataHow core calls an extension's Clear Data and records it (ClearDataExtensions)Yes, through the event onClearDataAddressed to one plugin
CreditCustomer credit, as a list of entries that is only added to (CustomerCreditLedger)No, core's own
DocumentIssuing and voiding sales documents (DocumentIssuer), drawing them as a page or a PDFYes, through three events. The code does not settle whether an extension may call DocumentIssuer.Documents
DocumentTypesThe list of document types (DocumentTypeRegistry)Yes, through the event onCollectDocumentTypeProvidersAdding a document type
DownloadDownload access for bought files: granting, removing and serving it (Entitlements)No, core's own
InventoryStock. InventoryService is the only writer of stock.Yes, through the stock events and a stock allocation providerStock, Stock events
ItemFieldsTurns an item field or value id into its display name (ItemFieldDisplayResolver)No, core's own
LogEvery log category Alfa writes to, registered in one place (AlfaLog)No, core's own. A payment or shipping plugin logs through its base class.Payment plugins: Logging
Maintenance"Clear everything" and "Reset to default" (FactoryReset, ResetToDefault)No, core's own. Your data is cleared through onClearData.
MediaMaking the gallery thumbnails again (ThumbnailRecreation)No, core's ownMedia plugins
OrderWriting orders (OrderCreator), changing their status (Transition), the two ledgers, the status e-mailsYes, through the payment and shipping base classes and the order eventsOrders, Payments and shipments
PriceIndexSyncService.phpBuilds and maintains the stored prices (the price index)Yes, through the event onAlfaPricesChangedPricing, Item and catalogue events
ProjectionSends an item change to everything that stores data derived from the item (ProjectionManager)Yes, through the event onCollectCatalogProjectionsSearch engine plugins
SearchCatalogue search, and which search engine serves it (CatalogSearchService, SearchEngineRegistry)Yes, as a search engine pluginSearch engine plugins
SetupThe component's own setup checks and the steps of an installationYes, through the event onAlfaCollectSetupChecksSetup checks
StatsThe figures behind core's dashboard cards (DashboardStatsService)No, core's own
TaskBackground work: what a change owes after its save is final, and long work done a part at a time (Tasks, Runner)No, core's own. In 2.2.0 a plugin cannot register a task of its own.
ToolsThe component's own tools on the Tools screen (CoreToolProvider)Yes, through the events onGetToolActions and onExecuteToolActionOther things a plugin can add
ValuePoolThe values a rule builder offers for one fieldNo, core's own

The areas under site/src/Service​

AreaWhat it is forFor extensions?Read more
CartWhat an application may ask of a cart (CartService), its totals, and the cart as a plugin reads it (Cart, CartLine)Read only in events. A module may call CartService.Cart and checkout
CartRulesWorks out which cart rules and coupons apply to a cart (CartRulesEngine)No, core's ownCart and checkout
CheckoutPlacing an order from a cart (OrderPlacement)No, core's own. A plugin takes part through the placement events.Cart and checkout
DataOne reader for the data a plugin keeps on a payment or shipment row (PluginPayload)Read onlyShipping plugins: Facts of your own on a parcel
FacetSorts item field values into the groups a filter shows (FacetGroupResolver)Yes, through an item field plugin's event onItemFieldValueFacetGroupsItem field plugins
FieldStateThe state a page builds once for fields that depend on each other (StateBag)No, core's own
OrderThe order, the payment and the shipment as a plugin reads them (Order, Payment, Shipment)Read onlyOrders
PlaceThe tree of countries, regions and towns, read once per request (PlaceTree)No, core's own
PricingPrice calculation, and the Money object every amount is handed over asRead only: plugins receive and pass MoneyPricing
Router.phpThe storefront's address routingNo, core's own
ShippingA shipping charge with its tax (ShippingCharge), and which tax rules a charge carriesNo, core's own. A shipping plugin answers the price in onCalculateShippingCost.Shipping plugins
ShowOnDecides on the server whether a conditional field is shownNo, core's own
SummaryOne labelled line of a money summary (SummaryRow)No, core's own
VariantFinds the combination that matches a shopper's choice of field values (CombinationResolver)No, core's own

Which door do I use​

I want toUseRead
Record a payment, settle it, or refund itThe payment base class (PaymentsPlugin). Never the ledger itself.Payments and shipments
Record a parcel, its tracking number or its statusThe shipping base class (ShipmentsPlugin)Payments and shipments
React to a new orderThe event onAlfaOrderPlacedOrder and cart events
React to a status changeThe event onOrderStatusChangeOrder and cart events
Refuse an order before it is placedThe event onOrderPlaceValidateOrder and cart events
Add a charge to the cartThe event onCartTotals and its builderOrder and cart events
Read the cart in a moduleCartService::ambient()->read(CartResolution::Current)Cart and checkout
Move an order to another statusFrom a payment plugin: orderTransition(). From a feature plugin: Transition, which no shipped plugin calls. For a shipping plugin the code does not settle it.Orders
Create an order without a cartOrderCreator::create(). The code expects a plugin as a caller, and no shipped extension calls it. Read the limits first.Orders
Read an order's lines, addresses, payments and parcelsThe Order reader an event hands youOrders
Follow or refuse a stock movementThe stock eventsStock events
Change or refuse a document before it is issuedThe event onDocumentBeforeIssueDocument events
Add a document typeA document type providerDocument events
Tell staff about something that needs themNotificationHelper::push()Notifications
Keep my own copy of prices or of the catalogueonAlfaPricesChanged, or a projectionItem and catalogue events

What you must provide​

Nothing for this page. Each door names what it needs on the page it links to.

What happens next​

When you go through a door, the service behind it does its checks, saves, and tells the other plugins. That is what makes two plugins from two authors work on one order without knowing about each other.

What can go wrong​

What you doWhat happens
Write to an Alfa table yourself (#__alfa_orders, #__alfa_order_payments, #__alfa_order_shipments, the stock tables)None of the service's checks run, nothing is written to the order's History, no event is announced and no follow-up work is recorded. The totals, the stock and the documents can stop agreeing with each other.
Call a class marked "No, core's own"It may work today. Its methods can change in any release without a note in this manual.
Call a ledger from a payment or shipping plugin instead of the base classThe row does not record your plugin as its plugin of record, so your later changes to it are refused.

Changed in 2.2.0​

  • Changed in 2.2.0. The helper classes of 2.1 and earlier (CartHelper, OrderPlaceHelper, OrderStockHelper, OrderPaymentHelper, OrderShipmentHelper) no longer exist. Their work is done by CartService, OrderPlacement, StockPolicy, PaymentLedger and ShipmentLedger.

Not documented yet​

  • The areas marked "No, core's own" have no page. The table gives each one line only, taken from the comment at the top of the area's main class.
  • The task engine and the REST API have pages of their own outside this section.
  • Customer credit, download access and the dashboard figures: whether an extension may read them, and how.