4. Presentation Layer
What is the Magento Presentation layer?
When you communicate with the Magento web interface, you interact with the presentation layer code. The presentation layer is the top layer of the four layers (presentation, service, domain, and persistence layers) defined in the Magento architecture.
Who uses the Presentation layer?
Magento makes web service calls efficiently by loading only the dependent code that is needed for the specific type of user. The presentation layer code is interacted with by three types of Magento users:
Users communicate with the storefront, which displays Magento’s View model of data and allows them to interact with product UI elements to request data for viewing and manipulation. These users are in control of the frontend.
By adding themes or widgets to the frontend, system administrators may indirectly control the presentation layer while customizing a storefront.
Web API calls can be made via HTTP just like browser requests and can be made via AJAX calls from the user interface.
Components of the Presentation layer
One useful way to consider the components of the Magento presentation layer is to examine the themes of Magento. Magento themes coordinate both the visual component of your storefront and some aspects of product behavior.
Each theme resides in a specific directory and includes custom page layouts, templates, skins, and language files that function together to create a unique user experience.
See the Frontend Developer Guide for an extensive introduction to theme elements and an overview of how to expand and override the default Magento themes.
GraphQL is a data query language developed internally by Facebook in 2012 before being published publicly in 2015. Magento implements GraphQL to provide an alternative to the frontend web APIs for REST and SOAP.
GraphQL allows you to specify the structure of the data you need, and the server only returns the data you need. Each GraphQL-capable module contains a declarative schema that specifies the query syntax that the module supports, as well as the attributes that can be returned. If you run a REST call, such as GET/V1/products/:sku, on a simple product, the device can collect more than 100 lines of data. If all you need is the current price, the call returned considerably more information than you need. With GraphQL, a query against the same SKU could only return the price.
Progressive Web Applications
Magento creates the HTML for a page that can be viewed from the view tree to the user.
View items fall into two major categories: blocks and containers.
Blocks can generate dynamic content and can contain named child view elements that are similar to arguments passed in. (The as attribute stores the names of the child view elements so that the parent block may refer to them.)
Containers hold a collection of children’s view components that are arranged in a specific order.
By instructing the view element tree to turn itself into HTML, the browser creates a product web page. Containers and blocks emit HTML that correctly encloses their children. Static HTML, Knockout JS files, and PHTML can all be used to create content for blocks.
How does Presentation code communicate with other layers?
Usually, presentation code refers to service contracts, particularly for a storefront. Presentation code, on the other hand, is often dependent on a particular implementation that allows the presentation code to call the domain layer directly. The Admin UI displays, for example, are often tied to a particular implementation and are not universally applicable.
To get information about the state of the program, the View layer calls code from the Model layer (for example, the price of a product). It usually uses service contracts to gain access to the Model.
Flow of the presentation layer
Web-users communicate with presentation layer components to choose behaviors that cause calls to the underlying layers. Components in the presentation layer make calls to the service layer, which sends requests to the domain layer.