Skip to content
Tutorials Center
My learning

Topics

Lesson 26 of 27 ยท Interviews and reference

OpenCart Developer Interview Questions

Prepare for an OpenCart 4 developer interview: concise answers on architecture, events vs OCMOD, the registry, payment flow, security, upgrades and performance, with runnable stand-ins.

An OpenCart interview mixes concept questions ("what is the registry?") with judgment questions ("how would you add a badge to product pages without touching core files?"). Good answers are short, name the trade-off, and say what you would check in the real code. Interviewers rarely want trivia; they want to hear that you know why OpenCart 4 is built the way it is and which tool fits which job.

This lesson collects common questions with compact answers, grouped by topic and linked to the lessons that explain each idea in depth. Where behaviour differs between 4.0.x releases, the answer says so, because "it depends on the version, and here is where I would look" is a strong answer. OpenCart cannot run on this site, so real code is read-only; the three runnable examples at the end are plain-PHP stand-ins, not OpenCart code. Cover the answers, say yours out loud, then compare.

flowchart TD
    Q["Interview topics"] --> A["Architecture<br/>MVC-L, registry, loader"]
    Q --> B["Extending<br/>events vs OCMOD"]
    Q --> C["Commerce<br/>payment, shipping, totals"]
    Q --> D["Quality<br/>security, testing, upgrades"]
    Q --> E["Scenarios<br/>what would you do?"]

Five areas that cover most OpenCart developer interviews.

Architecture

What does MVC-L mean in OpenCart?

Model, View, Controller and Language. Controllers handle a route, models talk to the database, views are Twig templates, and language files hold the text so a store can be translated without touching code. A request goes through the front controller, which resolves the route to a controller method. See Routing and Controllers.

What changed from OpenCart 3 to 4?

Namespaces (Opencart\Catalog\Controller\...), Twig as the only template engine (no .tpl), the extension installer and install.json format, extensions living under extension/{vendor}/, the dot as the method separator in routes (4.0.2 and later; 4.0.0 and 4.0.1 used a pipe), and no vQmod. OCMOD still exists, but events are the preferred way to change behaviour. See OpenCart 4 and Extension Development.

What is the registry?

A shared container of services such as db, config, session, request, response, cache, language, load, event, customer, cart and user. Controllers and models extend a base class whose magic property access reads from the registry, which is why $this->db works anywhere. It is a service locator, not constructor injection: convenient, but it hides dependencies. See Models, the Registry and the Database.

What does the loader do?

$this->load->model('catalog/product') creates the model and exposes it as $this->model_catalog_product. $this->load->language(...) merges a language file into $this->language, and $this->load->view(...) renders a Twig template with data. In OpenCart 4 the loader wraps models and calls so events can run before and after them; check the loader class of your release for exactly which calls are wrapped.

Where do extensions live, and why does the storage folder matter?

Extension files live under extension/{vendor}/ (with admin/, catalog/ and system/ inside). The storage directory holds logs, cache, uploads and downloads and should sit outside the web root, so a visitor cannot request a log or upload by URL. See Setting Up a Development Store.

Events and OCMOD

What is an event?

A row in the event table with a trigger (such as catalog/view/product/product/before), an action (a route to a handler), a status and a sort order. When the core calls a controller, model, view or language action, matching events run. Handlers receive the route and the arguments by reference, so a before event can change the data and an after event can change the output. See Events.

Events versus OCMOD: which and why?

Events run at runtime, are enabled or disabled in admin, do not modify files and survive most upgrades because they depend on a trigger name rather than on markup. OCMOD rewrites copies of files by searching for text and inserting code, so it breaks when the searched text changes and two modifications can conflict. Use events first; use OCMOD when no trigger exists for what you must change. See OCMOD Modifications.

How do you add a badge to the product page without editing core files?

Register an event on the product view (for example catalog/view/product/product/before or the matching after trigger), compute the badge in the handler, and add it to the view data or output. If the template has to show it, provide your own template through a theme or a template-route event. The badge project builds this end to end.

What is the danger of a wildcard trigger?

It runs for every matching call, on every page. A slow handler on catalog/view/*/before slows the whole store. Be as specific as possible and keep handlers cheap.

How do you debug an event that does not fire?

Check that the row exists and has status 1, that the trigger string matches exactly (including before or after), that the action route resolves to a real class and method, and that the event cache is not stale. Then log from the handler's first line.

Extension types and commerce

How does a payment extension work, step by step?

At checkout OpenCart asks each enabled payment extension for its methods for the customer's address and total (the method name and signature differ between 4.0.x releases). The customer picks one; on confirm the extension creates the order history, redirects to a hosted page or calls the gateway, and a callback or webhook later reports the result. See Building a Payment Extension.

Why verify a payment callback instead of trusting the redirect?

The customer's browser can be sent anywhere, and anyone can call a public callback URL. Verify a signature over the raw body with a shared secret, compare with hash_equals, check that the amount and currency match the order, and make processing idempotent because gateways retry. See Webhooks and Signatures and Idempotency.

What is the contract of a shipping extension?

It returns a quote array (a code, a title, a list of quote lines with cost and display text, a sort order and an error). Return an empty result when the method does not apply, for example outside its geo zone. See Building a Shipping Extension.

How do order total extensions interact?

They run in sort_order. Each receives the shared totals list, the tax pool and the running total by reference, appends its line and updates the total. A discount before the tax step reduces the taxable base; a fee after it does not unless it feeds the tax pool. Keep money in integer minor units where you can. See Order Total Extensions.

Where do settings live and how are they named?

In the setting table as code/key/value rows, keyed with a type prefix: module_, payment_, shipping_ or total_ plus the extension name, for example payment_hosted_pay_status. Admin forms save them with the setting model's editSetting. See Admin Settings Forms.

Security and quality

List the main security duties of an extension developer.

Escape output (Twig does by default; never use raw on request data), escape strings in SQL and cast numbers, check the user_token and the modify permission on every admin action, validate uploads by type and size, keep secrets out of templates and logs, and verify callbacks. See Security for Extension Developers.

What is user_token?

A per-session token added to every admin URL and form. Admin controllers redirect to login when it is missing or wrong, which blocks cross-site requests that cannot guess it. It is not a replacement for permission checks.

How do you test extension logic?

Keep business rules (rates, badge rules, signature checks) in plain classes with no registry calls, then unit-test them with a fake database and fake config. The controller stays thin. See Testing and Debugging Extensions.

How do you make an extension upgrade-safe?

Never edit core files, use events and your own extension folder, record the version in install.json and a setting, write idempotent upgrade steps, and test on the oldest and newest 4.0.x you support. See Packaging, Marketplace and Upgrades.

Performance

What are the usual OpenCart performance problems?

Queries inside loops (an N+1 on product lists), missing indexes on custom tables, no caching of expensive reads, heavy handlers on wildcard events, and uncompressed images. Fix with joins or batched IN queries, indexes, the cache class with explicit invalidation, and narrow triggers. See Performance in Extensions.

Scenario questions

A customer was charged twice. Where do you look?

At the callback handler: is processing idempotent (keyed by the gateway's event or payment id), and does the order status guard against a second "paid" transition? Check gateway retry logs against your own log.

Your extension works on 4.0.2.3 but fails on 4.1. What do you do?

Diff the core files you call (loader, model methods, event signatures, the payment and total interfaces) between the two releases, isolate version-specific code behind a small adapter, and add the supported range to your documentation and marketplace listing.

Two OCMOD files patch the same line. What happens?

One search may no longer match after the other has modified the text, so one modification is skipped or logged as failed. Prefer events, make searches small and unique, and read the modification log after a refresh.

Three runnable stand-ins

These imitate the ideas behind the answers above. They are not OpenCart code.

Registry and magic property access

PHP A service locator behind $this

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with fgets(STDIN)), it gets the next line from this box.

The controller never receives config or language in its constructor; they appear through __get. That convenience is also the weakness: a missing service shows up as null at call time, not as a clear error at construction.

Event versus text patch

PHP Why events outlast text patches

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with fgets(STDIN)), it gets the next line from this box.

The patch searched for </p> and silently stopped working when core changed. The event did not care about markup. Real events are not magic either: they depend on trigger names and argument shapes, so they can also change between releases, but those are far more stable than HTML.

Verifying a payment callback

PHP Signature, amount and idempotency

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with fgets(STDIN)), it gets the next line from this box.

The order of the checks is the point: authenticate first, then deduplicate, then compare business data. A real extension also stores processed event ids in a table, so duplicates are still caught after a restart.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. What is the main reason to prefer events over OCMOD?

    OCMOD searches for text in files; events hook named triggers at runtime, which are more stable than markup.
  2. 2. Why does $this->db work inside any controller?

    The registry is a shared service container that the base class exposes through __get.
  3. 3. In a payment callback, which check should come first?

    Authenticate the sender before trusting anything in the payload, then deduplicate and compare business data.
  4. 4. A handler on catalog/view/*/before is slow. What is the effect?

    A wildcard trigger matches many routes, so its handler runs on all of them.
  5. 5. What does the user_token in admin URLs protect against?

    Requests without the session's token are redirected to login; permission checks are still required separately.

Summary

  • OpenCart is MVC-L with a registry (service locator), a loader and Twig views; version 4 uses namespaces and extension/{vendor}/ folders.
  • Prefer events to OCMOD; OCMOD patches text and breaks when the text changes.
  • Verify payment callbacks by signature, then dedupe, then compare amounts; make processing idempotent.
  • Escape output, cast numbers, check user_token and modify permission on every admin action.
  • Keep logic out of controllers so it can be tested, and keep money in integer units.
  • Watch for N+1 queries, missing caches and wildcard event handlers.
  • When behaviour differs between 4.0.x releases, say so and name the file you would read.

Next, keep the lookup tables handy in the OpenCart Extension Cheat Sheet.