For Developers: Extending Multivendor

Multivendor is built on Ka Extensions and kamod: override its controllers and models, add vendor menu items and product form tabs. This page is for developers who write their own modules or adapt a theme.

How the module is built

  • The module lives in extension/ka_extensions/ka_multivendor folders of admin, catalog and system/library.
  • It changes OpenCart with kamod overrides of Ka Extensions: classes in .../ka_multivendor/controller/... and .../ka_multivendor/model/... extend the OpenCart classes with the same path (for example catalog/controller/extension/ka_extensions/ka_multivendor/controller/checkout/cart.php), and *.php.xml / *.twig.xml files patch PHP files and templates.
  • A few default-theme templates and core files are changed by the OCMOD modification of the package (install.xml).
  • The module does not use OpenCart events. To change its behaviour, override its classes in the same way.
  • Shared code is in system/library/extension/ka_extensions/ka_multivendor/ (abstract models such as amodelorder.php, amodelvendor.php, amodelvendorreview.php, amodelvendortransaction.php, vendor models in vendor/).

Extension points

Our other modules extend Multivendor through these points; for example, the Licenses module adds its own tab to the vendor product form. A module on Ka Extensions can override Multivendor classes and templates with kamod; set install_after = ka_extensions/ka_multivendor in its kamod.ini.

Point How
Vendor menu account.twig includes extension/ka_extensions/ka_multivendor/account/extra.twig if it exists. Provide this template from your module to add <li> items to My Vendor Account.
Vendor product form tabs vendor/product_form.twig includes vendor/product_form/tab_extra_header.twig (tab titles) and vendor/product_form/tab_extra_content.twig (tab panes) if they exist.
Vendor product fields Override getProductFields() of the vendor product controller (catalog/controller/.../ka_multivendor/vendor/product.php, class extension\ka_extensions\ka_multivendor\vendor\ControllerProduct) and the saving in the vendor product model (getVendorProductFields(), saveProduct()).
Fields that keep the approval Override getApprovalFreeFields() of the vendor product model.
API data Override collectProductData($product, &$data) of the API controller (.../ka_multivendor/api/product.php) to read your own POST fields.
Vendor order page tabs The vendor order page renders extra tabs from the tabs data array (code, title, content).

Keep overrides small: call the parent method and change its result.

Data model

Table / field Content
ka_vendor One row per vendor: customer_id (= vendor ID), vendor_status, product_limit, store_commission, vendor_custom_field (JSON), vendor_logo, apikey, rating cache.
ka_vendor_description Public name and description per language.
ka_vendor_order Vendor orders: vendor_order_id, main_order_id, vendor_id, delivery_status_id, shipping method, code and cost, store_commission (rate), commission_total, total.
ka_vendor_review Vendor reviews: status (P, A, R), obsolete flag, vendor reply.
ka_category_attribute_groups Attribute groups offered for a category.
product.vendor_id The product owner; 0 = store product.
product.vendor_approval, product.vendor_decline_reason Approval status ('' draft, W waiting, A approved) and the decline reason.
category.allow_for_vendor The Allow For Vendor flag.
order_product.vendor_id, order_history.vendor_order_id The vendor of an order line; history records of a vendor order (delivery statuses).
customer_transaction Vendor credits, take-backs and payouts (standard OpenCart table).
customer_approval (type vendor) Vendor applications waiting for approval.

With Custom Shipping Methods, vendor shipping methods are its methods with a vendor owner; their shipping codes are ka_smethods_<id>.

Adapting a theme

The storefront templates of the module are in catalog/view/theme/default/template/extension/ka_extensions/ka_multivendor/ (vendor area, vendor list and page, cart, checkout shipping, customer order blocks, emails). OpenCart uses them for other themes too, unless your theme has its own copies.

The modification changes these default-theme templates. Repeat the changes in your theme if it has its own versions of them:

Template Change
account/account.twig Includes the My Vendor Account block.
account/order_info.twig Shows vendor orders with delivery statuses and Confirm Delivery.
product/product.twig Shows "Vendor: name" with the rating.
common/header.twig Adds the Register Vendor link.
extension/total/shipping.twig Shows the shipping estimate per vendor in the cart.

Look for the //karapuz (Multivendor) blocks in install.xml of the package for the exact code. After changes, refresh Extensions > Modifications and clear the theme cache.