No results found

Try a different search query

Popular searches:

Add to Cart

Cart

You have no purchases yet

Browse Marketplace
Original Subtotal:
Product discounts:
Quantity Discount:
Total:
View Cart
Building extensions

OpenCart Module Types: module, payment, shipping, total, feed, report in 3.0 and 4.1

What extension types exist in OpenCart 3.0 and 4.1, how the core calls each of them, and which type to choose for your module.

11 min read OC 3.0 OC 4.1

OpenCart extension types determine when and how the core calls your code. A module is plugged into a page layout. Payment and shipping appear during checkout. Totals calculate cart lines, feeds export data outward, and reports appear in the admin panel. Choose the type before you write the first line of code, because it determines file paths, key names in the setting table, and the methods the core expects.

Examples are for OpenCart 4.1; in 4.0.x, model triggers and event handling differ.

What is an extension type and where is it visible in the admin?

In the admin, all extensionsAdditional functionality: a module, a payment or shipping method, a feed, or a theme. They are managed in "Extensions → Extensions." More in the glossary → are gathered on the Extensions → Extensions page. This page corresponds to the marketplace/extension route. At the top of the page there is a dropdown list of types, and the selected type shows its own table with Install and Uninstall buttons. The list of types is not hardcoded: the marketplace/extension controller simply scans the directory.

  • OpenCart 3.0: the core takes files from admin/controller/extension/extension/*.php. Each file, for example payment.php, handles its own type. The extensions themselves are located in admin/controller/extension/{тип}/{код}.php.
  • OpenCart 4.1: the type controllers were moved to admin/controller/extension/{тип}.php, and extensions now live separately from the core: extension/{папка_розширення}/admin/controller/{тип}/{код}.php. Built-in extensions are located in the extension/opencart/ folder.

The menu item and the type itself are shown only if the user group has the access permission for the type controller (extension/extension/payment in 3.0, extension/payment in 4.1). For more about these checks, read the article how user_group checks module access.

Сторінка «Розширення → Розширення»: випадний список типів і таблиця модулів
Extensions → Extensions page: type dropdown list and module table · OpenCart 4.1.0.4

The core keeps track of every installed extension in the extension table. In 3.0, it has the type and code columns. In 4.1, the extension column was added with the name of the folder where the extension is located, so the core knows which directory to load files from. Extension settings are stored in the setting table with keys such as {тип}_{код}_status, for example payment_cod_status or module_account_status.

What extension types exist in OpenCart 3.0 and 4.1?

The core has more types than the six in the heading, but these six are what developers write most often. The table below lists the types from the standard OpenCart 3.0.4.1, 3.0.5.1, and 4.1.0.4 source code, along with how the core calls each of them.

TypeName in the adminWho calls itKey method
moduleModules (Modules)Layout positions: common/content_top, column_left, etc.index() of the catalog controller
paymentPayments (Payments)Payment method selection stepgetMethod() in 3.0, getMethods() in 4.1
shippingShipping (Shipping)Shipping selection stepgetQuote()
totalOrder Totals (Order Totals)Calculation of the cart and ordergetTotal()
feedFeeds (Feeds)External request by routeindex() of the catalog controller
reportReports (Reports)Reports page in the adminreport() of the admin controller

Besides these, both versions have the analytics, captcha, currency (currency rates), dashboard (dashboard widgets), fraud, and theme types. OpenCart 3.0: additionally there is advertise. OpenCart 4.1: language (language packs as extensions) and other have appeared, where extensions that do not fit any other type are placed.

How does the core call a module-type extension?

The module type provides a block on the page: a banner, a slider, a list of recommended products. A module does not have its own page; it is displayed by a layout position. The common/content_top, common/column_left, and other controllers take the module codes of the current layout from the layout_module table and execute the corresponding controllers.

The code in layout_module can take one of two forms, and this determines where the settings come from:

  • Single module (for example, account). The code has no number, and the core checks the module_{код}_status key.
  • Module with instances (featured, banner, html). Each instance is a row in the module table with the module_id, name, code, and setting columns (settings in JSON format). The code in the layout contains the instance number, and the core passes the controller an array of settings for that specific instance.

OpenCart 3.0: the code in the layout looks like featured.28, and the route extension/module/featured is called. OpenCart 4.1: at the beginning of the code there is also the extension folder name, for example opencart.featured.28, and the route becomes extension/opencart/module/featured.

The general file structure of such a module is described in the article anatomy of an OpenCart extension. A step-by-step example is in the material how to create your first module from scratch.

How do payments, shipping, and totals work during checkout?

These three types have no storefrontWhat the customer sees: the home page, categories, product page, and cart. More in the glossary → pages or controllers of their own that display anything. The core calls methods of their models when it collects the lists of payment and shipping methods and calculates the total. Therefore, the main file for them is not a catalog controller but a model.

flowchart TD
  A["Cart"] --> B["total: getTotal() of each total by sort_order"]
  B --> C["shipping: getQuote(address)"]
  C --> D["payment: getMethod() in 3.0 / getMethods() in 4.1"]
  D --> E["Order confirmation"]
  E --> F["Payment controller: button or redirect to provider"]

Payment (payment)

The core goes through all installed payment extensions and calls the model only for those with payment_{код}_status enabled. The model decides whether the method is available for this address and this cart: this is where geo zone, minimum amount, and presence of shipping are checked. If the method is unavailable, it returns an empty array.

  • OpenCart 3.0: getMethod($address, $total) returns one method: an array with code, title, terms, and sort_order.
  • OpenCart 4.1: getMethods(array $address = []): array returns a method with a nested option array. This way one extension can offer several payment options, and option codes look like cod.cod.

Example

<?php
namespace Opencart\Catalog\Model\Extension\Mymodule\Payment;
class Invoice extends \Opencart\System\Engine\Model {
	public function getMethods(array $address = []): array {
		$this->load->language('extension/mymodule/payment/invoice');

		if (!$this->cart->hasShipping()) {
			return [];
		}

		return [
			'code'       => 'invoice',
			'name'       => $this->language->get('heading_title'),
			'option'     => ['invoice' => ['code' => 'invoice.invoice', 'name' => $this->language->get('heading_title')]],
			'sort_order' => $this->config->get('payment_invoice_sort_order')
		];
	}
}

Shipping (shipping)

The getQuote($address) method returns a shipping methodAn extension that calculates the cost: "Extensions → Extensions," type "Shipping." More in the glossary → with an quote array, where each option has an code of the form flat.flat, cost, tax_class_id, and a formatted text. The title key also differs here: in 3.0 it is title, in 4.1 name. This is where the cost calculation via the carrier's API goes. For how this looks in ready-made solutions for Nova PoshtaThe most popular carrier in Ukraine. The integration usually pulls cities and branches through an API. More in the glossary → and Ukrposhta, see the comparison in the review of shipping modules for OpenCart.

Totals (total)

Before the call, the core sorts totals by the total_{код}_sort_order key, and then each of them adds its own line and changes the grand total. Order matters: tax is calculated after the product subtotal, and a coupon discount comes before or after shipping depending on which sort order numbers are set in the admin.

  • OpenCart 3.0: getTotal($total) receives an array with references totals, taxes, and total, adds a line to $total['totals'][], and changes $total['total'].
  • OpenCart 4.1: getTotal(array &$totals, array &$taxes, float &$total): void, that is, three separate parameters by reference.

How do feed and report differ?

These two types are often confused with modules, although they work quite differently.

Feed (feed) is a controller in the catalog that provides data not to the buyer but to another system: a price list for a marketplace, XML for an advertising network, a sitemap. An external service accesses the route directly. The controller sets the required header through $this->response->addHeader('Content-Type: application/xml') and outputs XML instead of an HTML page. OpenCart 3.0: out of the box there are google_base and google_sitemap feeds under the extension/feed/{код} route. OpenCart 4.1: the type is in the list, but there are no standard feeds in the distribution, so all feeds are added as separate extensions. An example of such an extension is AI LLM Feed, which exports the catalog in a format for language models.

Report (report) lives only in the admin. The Reports page collects installed reports that have report_{код}_status enabled and for which the user has the access permission. It displays the selected report by calling its report method. OpenCart 3.0: the route has the form extension/report/{код}/report. OpenCart 4.1: the route is extension/{папка}/report/{код}.report, where the method is separated by a dot. For more on this route separation, read the article how the core finds a controller by route.

Сторінка «Звіти»: випадний список встановлених звітів
Reports page: dropdown list of installed reports · OpenCart 4.1.0.4

What happens when you click Install?

Installation is the same for all types, and it is what turns files on disk into a working extension:

  1. The core adds a row to the extension table with the type and code, and in 4.1 also with the folder name.
  2. The current user's group is granted the access and modify permissions: in 3.0 for extension/{тип}/{код}, in 4.1 for extension/{папка}/{тип}/{код}.
  3. If the extension controller has an install method, the core calls it. This is where custom tables are created and events are registered.

Uninstall does the reverse. The core removes the row from extension and all extension keys from setting, and for modules also their instances from the module table. Then it calls the extension's uninstall method. Permissions are handled differently across versions. OpenCart 3.0: the type controller removes permissions for the extension route from all groups. OpenCart 4.1: the standard module controller does not remove permissions. The core does not touch the data in your own tables in any version: it is removed by the module's own uninstall method. Therefore, before uninstalling, warn the administrator that the settings will disappear. Installation does not enable the extension yet: until you save the settings form with the "Enabled" status, the {тип}_{код}_status key does not exist in setting, and the storefront does not see the extension.

During startup, the core loads store settings from the setting table into the config object. In 3.0, this is done by the startup/startup startup controller; in 4.1, by startup/setting. The extension code then reads them via $this->config->get('ключ'), and this method takes values from the already loaded config, not from the database. How settings from the database get into the config is described in the article file configs and database settings.

Which type should you choose for your module?

Choose the type based on the point where the core must call your code, not on how the module looks. A few practical guidelines:

  • A block on a page (banner, widget, subscription form) is a module (module). It is added to a layout via Design → Layouts.
  • A payment methodAn extension such as card or cash payment. More in the glossary →, for example LiqPay, installment payments, or payment by bank details with QR, is a payment extension (payment), even if it has its own thank-you page.
  • Shipping cost calculated by address is a shipping extension (shipping). A directory of branches and creating waybills in the admin are usually done by the same extension through additional controllers.
  • A line in the totals (commission, a conditional discount, a packaging fee) is a total (total).
  • Data export for an external service is a feed (feed), and a data table for a manager is a report (report).
  • Changing core behavior without its own storefront interface, for example an event handler. In 4.1 there is a type for it, other; in 3.0 this is usually implemented as module without output.

One extension can combine several roles if you add several files to different type folders. For example, shipping together with a report on shipments. Each type is installed separately and has its own keys in setting.

Summary

  • The extension type defines who calls your code and when: module is shown by a layout position, payment, shipping, and total are called by checkout, feed is called by an external request, and report is shown on the Reports page.
  • For payments, shipping, and totals, the main file is a catalog model with a fixed method. In 4.1 the signatures are typed, and payment returns getMethods() with options.
  • In 4.1, extensions live separately from the core, in extension/{папка}/, and this folder is part of the routes, permissions, and layout codes.
  • Installation only registers the extension and grants permissions. It starts working after the settings are saved with the "Enabled" status.

Next, learn how the files of the chosen type are organized and build your first working module. The remaining topics in this section are collected on the page creating extensions for OpenCart.

FAQ

Can I change the type of an extension that's already written?
Yes, but it's effectively a new extension. The folder, routes, class names and setting key prefixes will change, so the old one has to be removed and the settings transferred manually.
Why isn't my extension in the list even though the files are uploaded?
The core only looks for files in the directory of the matching type: in 3.0 it's admin/controller/extension/{type}/, in 4.1 it's extension/{folder}/admin/controller/{type}/. Check the path, the file name and the group's permissions for the type itself.
Can I create my own extension type?
Technically yes: the list of types is built from controller files in admin/controller/extension, so a new file will appear in the dropdown. In practice this means editing the core, so for non-standard tasks in 4.1 it's better to use the other type.
Does a payment module need a controller in catalog?
Yes. The model only reports that the method is available, while the controller shows the button or form at the confirmation step and confirms the order or redirects the buyer to the provider.
Was this article helpful?
Thanks for your feedback!

Related articles

Didn't find the answer?

Ask the community: OpenCart developers answer on the forum.

Ask on the forum
We use cookies

We use cookies and similar technologies to improve your experience, analyse traffic, and show personalised ads. Read our Cookie Policy for details.