ShopX

Menu

24/7 Support
Back to Blog
OpenCart module development
Composer in OpenCart 3: dependencies and autoloading

Composer in OpenCart 3: dependencies and autoloading

A module can use Composer without changing the OpenCart core. Pick a namespace for your own code and a controlled location for the module's autoloader. Decide whether dependencies are shared by the installation or bundled with an independently deployed extension. Two bundled versions of the same public package can still collide, even when the extension's own classes have unique namespaces.

Practical check. Use a clean CI workspace and test deployment with production dependencies only. Rehearse restoring the previous bundle on staging.

Define the dependency boundary

composer.json defines the allowed dependency versions, while composer.lock records the resolved set used by the build. Run updates in a reviewed development workflow and inspect the lock-file diff. For an independently deployed application or module artifact, install from its lock file. A library's lock file does not control how a consuming project's dependencies are resolved.

CheckWhat it showsWhere to verify
composer updateResolve and review changesDevelopment or CI update workflow
composer installInstall the locked versionsClean build runner
check-platform-reqsCheck actual CLI PHP requirementsMatching PHP environment
Module smoke testVerify autoloading in the normal entry pointStaging

Build and test the release

On the build runner use composer install --no-dev --prefer-dist --optimize-autoloader. Review plugins and scripts before granting them access to the build environment. Use composer check-platform-reqs --no-dev to check the Composer runtime, then verify the storefront's PHP-FPM version and extensions independently. Keep the module and its verified dependencies in one release artifact when the target host does not run Composer.

Exercise the module through the same entry points that will load the dependency in production. Include the admin route, a storefront route and any scheduled job that uses it. A smoke test should instantiate a class and perform a small representative operation. Keep the previous module and dependency bundle together so a rollback does not mix files from different releases.

Frequently asked questions

What belongs in version control?

Keep the manifest and the lock file for reproducible application builds. Include the assembled vendor directory in the deployment artifact if production will not run Composer.

Where should autoload.php be required?

Load it once at a defined module entry point using a reliably resolved path.

Can Composer verify PHP-FPM directly?

Its platform check uses the PHP executable that runs Composer. Verify the FPM pool separately.

Share:
← Previous
crm prom: a practical guide to connecting and processing orders

Related Posts

Instant deliveryFiles immediately after payment
Regular updatesLatest module versions
Secure paymentProtected purchase
Technical supportWe will help with the setup