An upgrade package is an archive that contains all the files necessary to upgrade a customer’s add-on automatically. Normally this archive includes:
Upgrade packages can be installed in the Upgrade Center in one of the ways:
This article tells how add-on developers can create upgrade packages for their add-ons.
If you want to build upgrade packages via the Marketplace, please follow this structure when developing an add-on:
├── app
│ └── addons
│ └── [sample_addon]
│ ├── addon.xml
│ ├── config.php
│ ├── func.php
│ └── upgrades
│ ├── [version1]
│ │ ├── migrations
│ │ │ ├── 467676233_migration1.php
│ │ │ └── 467676233_migration2.php
│ │ │
│ │ ├── validators
│ │ │ ├── validator1.php
│ │ │ └── validator2.php
│ │ │
│ │ ├── scripts
│ │ │ ├── pre_script.php
│ │ │ └── post_script.php
│ │ │
│ │ ├── extra_files
│ │ │ ├── extra_file1.php
│ │ │ └── extra_file2.php
│ │ │
│ │ └── extra
│ │ └── extra.php
│ │
│ ├── [version2]
│ │ ├── migrations
│ │ │ ├── 467676233_migration1.php
│ │ │ └── 467676233_migration2.php
│ │ │
│ │ ├── validators
│ │ │ ├── validator1.php
│ │ │ └── validator2.php
│ │ │
│ │ ├── scripts
│ │ │ ├── pre_script.php
│ │ │ └── post_script.php
│ │ │
│ │ ├── extra_files
│ │ │ ├── extra_file1.php
│ │ │ └── extra_file2.php
│ │ │
│ │ ├── extra
│ │ │ └── extra.php
...
Files and folders in app/addons/[sample_addon]/upgrades/[version] aren’t required. For example, if the new version has no changes in the database, there’s no need to create a folder with migrations.
Hint
Learn more about the components of an upgrade package here.
Create an upgrade package as described in this article. Instead of creating an upgrade connector you’ll need a Marketplace connector. It must be located in the app/addons/[addon_name]/Tygh/UpgradeCenter/Connectors/[AddonName]/Connector.php and have the following content:
Important
In this example the connector is located in app/addons/sample_addon/Tygh/UpgradeCenter/Connectors/SampleAddon/Connector.php. Replace sample_addon and SampleAddon with the name of your add-on both in the path and in the connector code. ADDON_IDENTIFIER
is what you have in the <id>
section of addon.xml. The identifier must be the same as the name of your add-on’s folder.
<?php
namespace Tygh\UpgradeCenter\Connectors\SampleAddon;
use Tygh\Addons\SchemesManager;
use Tygh\Registry;
use Tygh\UpgradeCenter\Connectors\BaseAddonConnector;
/**
* Marketplace add-on upgrade connector
*/
class Connector extends BaseAddonConnector
{
/**
* Put your add-on identifier here
*/
const ADDON_IDENTIFIER = 'sample_addon';
/**
* @var string Version of product addon runs in
*/
protected $environment_version;
/**
* Prepares request data for request to Upgrade server (Check for the new upgrades)
*
* @return array Prepared request information
*/
public function getConnectionData()
{
$request_data = parent::getConnectionData();
$request_data['url'] = $this->updates_server;
$request_data['data']['product_id'] = $this->addon_id;
$request_data['data']['dispatch'] = 'product_packages.get_upgrades';
// "ver" is used for addon version
// while "product_version" is for environment version
$request_data['data']['product_version'] = $this->environment_version;
return $request_data;
}
/**
* Downloads upgrade package from the Upgade server
*
* @param array $schema Package schema
* @param string $package_path Path where the upgrade pack must be saved
* @return bool True if upgrade package was successfully downloaded, false otherwise
*/
public function downloadPackage($schema, $package_path)
{
$package_url = fn_url(
$this->updates_server . (strpos($this->updates_server, '?') !== false ? '&' : '?') .
http_build_query(array(
'dispatch' => 'product_packages.get_package',
'package_id' => $schema['package_id'],
'product_id' => $this->addon_id,
'license_number' => $this->license_number
))
);
$data = fn_get_contents($package_url);
if (!empty($data)) {
fn_put_contents($package_path, $data);
$result = array(true, '');
} else {
$result = array(false, __('text_uc_cant_download_package'));
}
return $result;
}
/**
* Gets Marketplace product identifier from addon.xml scheme
*/
public static function getMarketplaceProductId()
{
$scheme_path = Registry::get('config.dir.addons') . self::ADDON_IDENTIFIER . '/addon.xml';
if (file_exists($scheme_path)) {
$scheme = @simplexml_load_file($scheme_path);
// <marketplace_product_id> is automatically added into addon.xml by Marketplace
if (isset($scheme->marketplace_product_id)) {
return (int) $scheme->marketplace_product_id;
}
}
return 0;
}
public function __construct()
{
parent::__construct();
// Initial settings
$this->addon_id = self::getMarketplaceProductId();
$addon_scheme = SchemesManager::getScheme(self::ADDON_IDENTIFIER);
$this->updates_server = Registry::get('config.resources.marketplace_url');
$this->product_name = $addon_scheme->getName();
$this->product_version = $addon_scheme->getVersion();
$this->environment_version = PRODUCT_VERSION;
$this->product_edition = PRODUCT_EDITION;
$this->license_number = Registry::get('addons.' . self::ADDON_IDENTIFIER . '.marketplace_license_number');
}
}
Note
The Marketplace connector will be built in CS-Cart & Multi-Vendor starting with version 4.4.1. That means you won’t have to create upgrade connectors for these versions.
Important
To be able to build upgrade packages via the Marketplace, please follow the recommended structure of an add-on.
The list of upgrade packages is available on the Product packages tab of your add-on:
A manually-uploaded upgrade package has the Active status by default, i.e. it is available to customers. Upgrades built with the Marketplace have the Disabled status by default, i.e. they are not available to customers.
Customers who downloaded an add-on from the Marketplace, installed it, and specified the marketplace license number, will see the active upgrades in the Upgrade Center.
If you want to test a disabled upgrade package, add the following line to your store’s local_conf.php:
$config['resources']['marketplace_url'] .= '?access_token=/*your token here*/';
You’ll find the access token on your profile editing page in the Marketplace:
Questions & Feedback
Have any questions that weren't answered here? Need help with solving a problem in your online store? Want to report a bug in our software? Find out how to contact us.