Contents
OpenCart
A simple open-source online shop: controllers, models, Twig templates, modules and events.
1.Getting started
- What OpenCart isOpenCart 4 in plain words: what the engine does, which version the course covers, what it needs and what you will build.
- InstallationInstalling OpenCart 4 on a local server: files, database, the setup wizard, the console installer and the first steps after it.
- Storefront, admin panel and project foldersThe folders of an OpenCart 4 project: the catalog and admin applications, extension, system, storage and the two configuration files.
- Core conceptsThe ideas behind OpenCart 4: MVC-L, the registry and objects available through this, extensions, events and the differences from version 3.
2.Storefront pages
- The first controllerHow to create a storefront page in OpenCart 4: the controller file, its namespace and class, and how the route in the address maps to the file.
- Methods, request, links and redirectsSeveral methods in one OpenCart 4 controller, reading GET and POST data, building links with url->link and redirecting.
- Language filesWhere OpenCart 4 keeps the texts of a page, how to create a language file, load it in a controller and add a second language.
- Twig templatesWhere OpenCart 4 templates live, how to pass variables from a controller, use conditions and loops and include the header and the footer.
- JSON responses and AJAX formsHow forms work in OpenCart 4: a controller method that answers in JSON and a form sent without reloading the page.
- Models and the databaseWhere OpenCart 4 models live, how to write a query with db->query, read the result, protect values and call the model from a controller.
- Core models: products, categories, images, pricesUsing the ready models of OpenCart 4: reading products and categories, resizing images and formatting a price with tax and currency.
- Page title, breadcrumbs and paginationThe document object of OpenCart 4, the breadcrumbs array and page-by-page output through the common/pagination controller.
3.Your own extension
- Creating an extensionThe folder structure of an OpenCart 4 extension, the install.json file, packaging into an ocmod.zip archive and installing in the admin panel.
- The settings page of a moduleThe admin controller of an OpenCart 4 module: a settings form, saving with the setting/setting model and reading the values with config->get.
- Permissions and the user tokenHow the OpenCart 4 admin panel protects pages: user groups with access and modify permissions, the hasPermission check and user_token in links.
- Install, uninstall and your own tablesThe install and uninstall methods of an OpenCart 4 extension: creating and dropping your own table through an admin model.
- Showing a module on the storefrontThe storefront controller of an OpenCart 4 module that returns HTML, and placing the module on pages through layouts in the admin panel.
- Events: triggers and registrationThe event system of OpenCart 4: what a trigger is, how to register an event during installation and write the first handler.
- Events: changing data, output and argumentsWhat an OpenCart 4 event handler receives and how to change template data, ready HTML and the arguments of a model method.
- Forms, validation and securityA callback form in an OpenCart 4 module: checking fields, protection from SQL injection and XSS, and a token against request forgery on the storefront.
4.Customer, cart and orders
- Sessions, the customer and login checksThe session and the customer object in OpenCart 4: storing data between requests, reading customer data and closing a page for guests.
- The cartThe cart object of OpenCart 4: reading the products and totals, adding a product from code and the difference from the checkout/cart controller.
- OrdersOrders in OpenCart 4 code: reading an order and its products, statuses, the addHistory method and the moment an order counts as placed.
- An order total extensionHow the order total is calculated in OpenCart 4 and how to add your own line to it with an extension of the total type.
- A shipping extensionHow to add a shipping method to OpenCart 4: an extension of the shipping type with a getQuote model that returns options and prices.
- A payment extensionHow a payment method works in OpenCart 4: the getMethods model, the controller with the confirm button and the confirm method that places the order.
5.Growing the project
- Themes and overriding templatesHow to change the look of an OpenCart 4 shop without editing core templates: the theme editor, replacing a template through an event and adding your own styles.
- SEO URLsShort readable addresses in OpenCart 4: turning them on, web server rules, keywords for products and for your own pages.
- Settings and cacheThe config and cache objects of OpenCart 4: reading shop settings, where they are stored, and saving the result of a slow query in the cache.
- Cron jobsScheduled tasks in OpenCart 4: the list of cron jobs in the admin panel, a task controller in an extension, registering it and the system scheduler.
- An API endpoint for integrationsHow to exchange data between OpenCart 4 and an external system: your own controller with an access key, and what the built-in API is.
- Sending mailThe Mail class of OpenCart 4: mail settings in the admin panel, sending a text and an HTML letter from an extension.
- OCMOD in version 4What OCMOD is in OpenCart 4, when it is still needed, what a modification file looks like and why events are preferred.
- Deployment and a security checklistMoving an OpenCart 4 shop to a production server: files, database, the two configuration files and a list of checks before launch.
- Updating the shopHow to update OpenCart 4 safely: a backup, a test copy, replacing core files, the upgrade script and checking extensions.