Magento Introduction And Architectural
Magento Introduction And Architectural
目录:
Magento Introduction
Magento Technology stack
Architectural basics overview
Architectural layers overview
Magento components
Logical view overview
Reference
Magento Basic Introduce
The Magento Framework is integrated with the following software layers:
Presentation layer provides both view components (layouts, blocks, templates) and controllers, which process commands to and from the user interface
Service layer, through the use of service contracts, defines the overall interface for interacting with business logic (for example, creating customers and getting tax rates).
Domain layer provides core business logic and functionality in base classes, resource models, and data access capabilities that you can extend and customize. Business logic rules, which define how data is retrieved from the database and manipulated, are stored in the Business Logic layer.
Ease of extensibility - Magento uses dependency injection and service contracts to simplify the process of supplying a new implementation of a defined API.
Modularity - Modules form the basic functional unit of a Magento system. Magento modules contain the logic to execute required actions and functions. You extend the core feature set of Magento by writing and incorporating new modules into your installation
Mangeto Technology Stack
Name | Description |
---|---|
Web servers | Apache/nginx |
Languange | PHP - Composer (dependency management package for PHP) |
Database | MySQL/MySQL Percona |
HTTP accelerator | Varnish |
Cache Storage | Redis/Memcache |
Search | Solr (Magento Enterprise Edition only)/Elasticsearch (Magento Enterprise Edition version 2.1.x only) |
Additional technologies | HTML5/CSS3(LESS)/jQuery/RequireJS/Knockout.js/Third-party libraries (Zend Framework 1, Zend Framework 2, Symfony) |
Optional stack components | Varnish (caching)/Redis (used for page caching) |
Magento also provides automated testing suites that include unit, integration, functional and performance test scripts, as well as JavaScript tests and tools for static code analysis. Components include PHPUnit for the unit test framework and Selenium for the functional test framework.
Architectural basics overview
Extensibility and modularity
architectural principles that guide product structure
* oftware development is the practice of replacing or extending core code rather than editing it
open-source software to create and manage extensions
* Composer
coding standards - Magento Coding Standards
upgrade and versioning strategies
Ease of frontend customization
The Magento frontend is designed to optimize storefront customization. Merchants are encouraged to use Magento components to customize the look-and-feel of their storefronts.Magento Blank theme
* The Magento blank theme template provides a launchpad for storefront customization.
Magento UI components
* The Magento UI library is a set of generic web components and Magento-specific patterns, which simplifies the process of Magento theme creation and customization.
Magento Admin pattern library
* A pattern library is a collection of user interface (UI) design patterns that can be re-used in locations throughout your product installation.
Global features that support extensibility
Modularity - The concept of the module is the heart of Magento extension development, and modular design of software components (in particular, modules, themes, and language packages) is a core architectural principle of the product.
Reliance on popular design patterns - Magento product architecture incorporates many well known patterns, but Model-View-Controller (MVC) holds particular interest for extension developers.
Coding standards - Magento developers should familiarize themselves with our coding standards
Rich product ecosystem - The wider Magento ecosystem provides an extensive community and rich third-party marketplace for extensions
Flexible attribute types
1. EAV (Entity-Attribute-Value) attributes are site-specific attributes that you can define for a local site using the Magento Admin. 2. Custom attributes are a subset of EAV attributes. Objects that use EAV attributes typically store values in several MySQL tables. The Customer and Catalog modules use EAV attributes. 3. Extension attributes often use more complex data types than custom attributes. These attributes do not appear in the storefront. Extension attributes are introduced by modules.
Web APIs - Magento or third-party services can be configured as a web API (REST or SOAP) with some simple XML integrate CRM CMS ERP
Service contracts, dependency injection, and dependency inversion - Service contracts provide a new way to access public API endpoints.
Plug-ins - Plug-ins, like modules, are a mechanism for adding features to the core Magento product
Storefront customization strategies
Extend Magento-Provided CSS - Magento supplies a default theme and a LESS-based CSS set of styles.
Replace PHTML template files - In addition to extending the default CSS, you can generate different HTML markup.
Replace Magento - Provided CSS - Rather than edit the default CSS provided by Magento, you might decide to replace all the default storefront CSS code with your own.
Replace Magento - Provided CSS, HTML, and JavaScript - Delivering a sharply different shopping experience than the default Magento installation provides is a more substantial task.
Architectural layers overview
Presentation layer
Who uses the Presentation layer?
* **Web users** These users work within the (frontend) area * **System administrators** customizing a storefront can indirectly manipulate the presentation layer by * **Web API** calls can be made through HTTP just like browser requests, and can be made via AJAX calls from the user interface.
Service layer
The service layer provides a bridge between the presentation layer and the model layer of domain logic and resource-specific dataWho accesses the service layer?
* Controllers (initiated by actions of users of the storefront) * Web services (SOAP and REST API calls) * Other Magento modules through service contracts
Domain layer
The domain layer holds the business logic layer of a Magento module.
Best practice: Use service contracts to communicate to the domain layer by passing data types through strongly typed objects. This practice can help you avoid the need to replace presentation layer code when replacing business layer logic.
1. Who accesses the domain layer?
* Service contracts are the recommended way for one module to access another module’s domain-level code.
* A module can directly call into another module.
* Domain layer code in one module can also plug itself into another module by:
1. event hooks
2. plugins
3. `di.xml` files (with an SPI contract)
Persistence layer
Magento uses an active record pattern strategy for persistenceExecuting all CRUD (create, read, update, delete) requests. The resource model contains the SQL code for completing these requests.
Performing additional business logic
Magento components
Module overview
Module purpose - The purpose of each module is to provide specific product features by implementing new functionality or extending the functionality of other modules.
Module components - A module is a directory that contains the PHP and XML files (blocks, controllers, helpers, models) that are related to a specific business feature,
Where do modules live?
* Modules typically live in the `app/code` directory of a Magento installation, in a directory with the following PSR-0 compliant format: `app/code/<Vendor>/<ModuleName>`
Module Magento area types
Magento Admin (adminhtml): entry point for this area is
index.php
orpub/index.php
.Storefront (frontend): entry point for this area is
index.php
orpub/index.php
Basic (base): used as a fallback for files absent in
adminhtml
andfrontend
areas.Web API REST (webapi_rest): entry point for this area is
index.php
orpub/index.php
.Web API SOAP (webapi_soap): entry point for this area is
index.php
orpub/index.php
.Quick view of module/area interactions
* Modules should not depend on other modules’ areas. * Disabling an area does not result in disabling the modules related to it. * Areas are registered in the Dependency Injection framework `di.xml` file.
Module Name and declare the module in the
module.xml
file.
Magento themes
Custom theme development is one of two main methods of modifying Magento behavior and storefront appearance. (Extending modules is the other primary way, and the main way to tailor Magento behavior.)Theme location
* The location of a theme in your Magento installation depends upon how you installed your theme. Magento knows to look in both `vendor` and `app/design` for themes. In Magento 2.0, each module and theme contain a `registration.php` file, which defines location information.
Location of themes when installing with Composer
Location of custom themes - not recommended
* While developing a theme, place it under app/design. If you’ve defined the theme for a local project (that is, you intend to install it in one project only), place it under app/design
Language packages and translation
Magento language packages
1. `.csv` file contains the actual strings that comprise the language dictionary. 2. `composer.json` file contains any dependencies for the language package and a mapping to its defined locale. 3. `language.xml` file, where you declare a language package and establish any inheritance rules, if you are installing multiple language packages.
Logical view overview
Magento libraries
Magento Framework
Magento Framework organization -
Lib/ ../Internal ../Magento ../Framework
* `/lib/internal` contains some non-PHP as well as PHP components. Non-PHP framework libraries includes JavaScript and LESS/CSS. * `/lib/internal/Magento/Framework` contains only PHP code. * `/lib/web` contains JavaScript and CSS/LESS files. * `lib/internal/Magento/Framework` directory maps to the `Magento\Framework` namespace.
Magento Framework Function - Magento Framework Function