[TomatoCart] – Use composer to manage php dependency in tomatocart

Composer is a new generation of dependency manager for php. It is free open source and easy to use.


  • You could find any package at https://packagist.org/ and use it just with one command: composer require vendor/package. You needn’t to use include or require the class in your code anymore. Composer will do that boring thing for you automatically.
  • You could write a cool package and publish it. So, the other developers could find it in the packagist and use it immediately.

In this article, i will teach you how to use composer in the tomatocart.

Installing Composer

  1. Composer could run in PHP 5.3.2+. So, please ensure that your php version is 5.3.2+.
  2. Run following command to download composer and install it. The –install-dir is used to specify which directory the composer will be installed into.
    <code>curl -sS <span class="hljs-symbol">https:</span>/<span class="hljs-regexp">/getcomposer.org/installer</span> | php -- --install-dir=bin</code>
  3. You could also install it globally with following command:
    curl -sS https://getcomposer.org/installer | php
    mv composer.phar /usr/local/bin/composer

Create composer.json file for Tomatocart

Generally, you could run composer init in the tomatocart project to create the composer.json file. But, it means you need to enter a lot configuration by yourself. It’s not effecient. So, i have created a composer.json for you.

  1. Go into your TomatoCart root directory.
  2. Create a file named composer.json.
  3. Copy following content into it:
        "name": "tomatocart/v1",
        "description": "TomatoCart is User Friendly. It is implemented with ExtJS RIA framework. The web desktop application mimics the user experience of a desktop Operating System, offering features and applications similar to a PC environment so that users can easily start work.",
        "version": "",
        "type": "project",
        "keywords": [
            "ecommerce cart",
            "shopping cart"
        "homepage": "http://www.tomatocart.com",
        "license": "GPL",
        "authors": [
                "name": "Lei Zheng",
                "email": "info@tomatocart.com",
                "homepage": "http://www.tomatocart.com",
                "role": "Founder"
                "name": "Jack Yin",
                "email": "jack.yin@tomatocart.com",
                "homepage": "http://www.tomatocart.com",
                "role": "Core Founder"
        "support": {
            "email": "support@tomatocart.com",
            "issues": "https://github.com/tomatocart/TomatoCart-v1/issues",
            "source": "https://github.com/tomatocart/TomatoCart-v1",
            "forum":  "http://www.tomatocart.com/community/forum.html",
            "docs": "http://www.tomatocart.com/documentation/index.html"
        "autoload": {
            "classmap": ["includes/classes/"]
        "config": {
            "vendor-dir": "ext"
        "require": {}
  4. Run composer install command to install it.
  5. Open includes/application_top.php and find following code:
    // define the project version
      define('PROJECT_VERSION', 'TomatoCart v1.1.8.6');

— Add following code line after it:

include DIR_FS_CATALOG . 'ext/autoload.php';

Once installed it:

  • The vendor packages from packagist.org will be installed automatically into etc directory. You just need to use it in your code.
  • Classmap for TomatoCart store front is generated. The classes existing in the includes/classes directory will be loaded automatically. It means that you needn’t to include the class manually in your script. Just use it.


Note: If you install other packages in your tomatocart project, don’t forget to run following command when release the project in your live server:

composer dump-autoload --optimize

This will cache the classmap for the PSR-4 autoloader or PSR-0 autoloader. So, it will enhance the performance to load the classes.

Find Word

Composer is really cool. If you need more details about it, please read their document at https://getcomposer.org/doc/.

Looking for quality TomatoCart hosting? Check out Arvixe Web Hosting

Tags: , | Posted under TomatoCart | RSS 2.0

Author Spotlight

Jack Yin

TomatoCart Developer & Co Founder - Arvixe Web Hosting / TomatoCart Community Liaison

Leave a Reply

Your email address will not be published. Required fields are marked *