### Example main.json for Single CS-Cart Installation
Source: https://docs.cs-cart.com/4.19.x/developer_guide/getting_started/server_ansible_playbooks.html
An example of a main.json file configured for a single CS-Cart or Multi-Vendor installation without additional storefronts. Remember to replace domain names and database credentials with your own.
```json
{
"stores_dir": "/var/www/html",
"stores":
{
"doctorzoid.tk":
{
"cart":
{
"storefronts": []
},
"database":
{
"name": "doctorzoid_tk",
"user": "doctorzoid_tk",
"password": "0NkpV5t9VcUYpKtM"
}
}
}
}
```
--------------------------------
### Example GET Request for a Product
Source: https://docs.cs-cart.com/4.19.x/developer_guide/api/entities/products.html
This snippet shows an example of how to make a GET request to retrieve product information by its ID.
```HTTP
GET request to /api/products/12
```
--------------------------------
### Run Console Installation
Source: https://docs.cs-cart.com/4.19.x/install/install_via_console.html
Execute the PHP script in the install directory via the console to start the standard installation process.
```bash
php index.php
```
--------------------------------
### Add-on Installation Database Query
Source: https://docs.cs-cart.com/4.19.x/developer_guide/addons/scheme/scheme3.0_structure.html
An example SQL query to create a table for an add-on during its installation. This query is executed only when the 'for' parameter is set to 'install' or is not specified.
```sql
CREATE TABLE `?:addon_test_123456789` (
`queue_id` mediumint NOT NULL auto_increment,
PRIMARY KEY (`queue_id`)
) ENGINE=MyISAM DEFAULT CHARSET=UTF8
```
--------------------------------
### Example Upgrade Log File
Source: https://docs.cs-cart.com/4.19.x/upgrade/upgrade.html
This log file shows the step-by-step execution of the upgrade process, including package installation, validator execution, and database migrations. It can be used to identify the cause of upgrade failures.
```log
2015-03-27 12:01:13: Start installation of the "core" upgrade package
2015-03-27 12:01:13: ================================================
2015-03-27 12:01:13: Get all available validators
2015-03-27 12:01:13: Execute "collisions" validator
2015-03-27 12:01:13: Upgrade stopped: Awaiting resolving validation errors: collisions
2015-03-27 12:01:21:
2015-03-27 12:01:56: Start installation of the "core" upgrade package
2015-03-27 12:01:56: ================================================
2015-03-27 12:01:56: Get all available validators
2015-03-27 12:01:56: Execute "collisions" validator
2015-03-27 12:01:56: Execute "permissions" validator
2015-03-27 12:01:56: Execute "restore" validator
2015-03-27 12:01:56: Backup files and Database
2015-03-27 12:01:56: Copy package files
2015-03-27 12:01:56: Run migrations
2015-03-27 12:01:56: Phinx by Rob Morgan - http://phinx.org. version 0.3.7
2015-03-27 12:01:56:
2015-03-27 12:01:56: using config file ./app/Tygh/UpgradeCenter/Migrations/config.migrations.php
2015-03-27 12:01:56: using config parser php
2015-03-27 12:01:56: using migration path /Users/alexions/www/git/work/var/upgrade/packages/core/content/migrations
2015-03-27 12:01:56: using environment development
2015-03-27 12:01:56: using adapter mysql
2015-03-27 12:01:56: using database alexions_staging
2015-03-27 12:01:56:
2015-03-27 12:01:56: == 20150317072105 CoreChangePrivelegeName: migrating
2015-03-27 12:01:56: == 20150317072105 CoreChangePrivelegeName: migrated 0.0034s
2015-03-27 12:01:56:
2015-03-27 12:01:56: All Done. Took 0.1739s
2015-03-27 12:01:56: Install langauges from the upgrade package
2015-03-27 12:01:56: Install the "en" language
2015-03-27 12:01:56: Upgrade completed
```
--------------------------------
### Example Theme Settings Overrides
Source: https://docs.cs-cart.com/4.19.x/designer_guide/theme_tutorial/change_settings.html
This example demonstrates how to override general, appearance, and thumbnail settings for a theme. It includes examples for boolean, string, array, and numeric settings.
```json
"settings_overrides": {
"General": {
"enable_compare_products": false
},
"Appearance": {
"default_products_view": "products_without_options",
"default_product_details_view": "bigpicture_template",
"thumbnails_gallery": true,
"enable_quick_view": false,
"available_product_list_sortings": [
"product-asc",
"product-desc",
"price-asc",
"price-desc"
]
},
"Thumbnails": {
"product_lists_thumbnail_width": 300,
"product_lists_thumbnail_height": 300
}
}
```
--------------------------------
### Example: Retrieving Menu Scheme
Source: https://docs.cs-cart.com/4.19.x/developer_guide/core/schemes.html
This example demonstrates how to call `fn_get_schema` to get the 'menu' scheme of type 'php'. The function searches for the main scheme file and includes add-on specific schemes.
```php
$menu = fn_get_schema('menu', 'menu', 'php');
```
--------------------------------
### Example MySQL Import Command
Source: https://docs.cs-cart.com/4.19.x/install/moving_to_another_server.html
An example of the MySQL import command, demonstrating how to substitute your specific username and database name.
```bash
mysql -uroot -p test < my_database_backup.sql
```
--------------------------------
### Add-on Installation Functions
Source: https://docs.cs-cart.com/4.19.x/developer_guide/addons/scheme/scheme3.0_structure.html
This snippet lists user-defined functions to be called after the add-on installation process, before activation.
```xml
- fn_google_export_add_features
- fn_google_export_add_feed
```
--------------------------------
### Example: Querying Data from an Additional Database
Source: https://docs.cs-cart.com/4.19.x/developer_guide/core/db/additional_dbs.html
This example demonstrates how to initiate a connection to a backup database, switch to it, and then query data from a table using a custom table prefix. The data will be retrieved from the specified external database.
```php
$params = array(
'dbc_name' => 'backup',
'table_prefix' => 'cscart'
);
db_initiate('localhost', 'db_user', 'db_password', 'cscart_backup', $params);
db_connect_to($params, 'cscart_backup');
$data = db_get_array("SELECT * FROM ?:products");
```
--------------------------------
### Example config.local.php Structure
Source: https://docs.cs-cart.com/4.19.x/user_guide/manage_products/promotions/promotion_recalculation.html
This shows how the new tweak should be integrated within the existing `$config['tweaks']` array in the `config.local.php` file.
```php
$config['tweaks'] = array (
'...' => ...,
'...' => ...,
'do_not_apply_promotions_on_order_update' => true,
'...' => ...,
'...' => ...,
);
```
--------------------------------
### Navigate to CS-Cart Directory
Source: https://docs.cs-cart.com/4.19.x/install/nginx.html
Changes the current directory to the CS-Cart installation path. Ensure you replace 'example.com' with your actual directory name.
```bash
cd /var/www/html/example.com
```
--------------------------------
### Private Property Declaration Example
Source: https://docs.cs-cart.com/4.19.x/developer_guide/core/coding_standards/php.html
Example of declaring private properties in a class, adhering to the rule of not starting names with an underscore.
```php
class Api
{
/**
* Current request data
*
* @var Request $request
*/
private $request = null;
/**
* Sample var
*
* @var array $sample_var
*/
private $sample_var = array();
}
```
--------------------------------
### Get a Specific Language
Source: https://docs.cs-cart.com/4.19.x/developer_guide/api/entities/languages.html
Retrieves the details of a specific installed language by its ID.
```APIDOC
## Get a Specific Language
### Description
Retrieves the details of a specific installed language by its ID.
### Method
GET
### Endpoint
/api/languages//
### Parameters
#### Path Parameters
- **lang_id** (integer) - Required - The unique identifier of the language to retrieve.
### Response
#### Success Response (200 OK)
- **lang_id** (string) - The unique identifier of the language.
- **lang_code** (string) - The two-letter language code.
- **name** (string) - The name of the language.
- **status** (string) - The status of the language (`A` - active, `H` - hidden, `D` - disabled).
- **country_code** (string) - The ISO code of the country.
- **direction** (string) - The writing direction (`ltr` or `rtl`).
#### Error Response (404 Not Found)
Returned if the specified language does not exist.
### Response Example
```json
{
"lang_id": "1",
"lang_code": "en",
"name": "English",
"status": "A",
"country_code": "US",
"direction": "ltr"
}
```
```
--------------------------------
### List Installed Languages
Source: https://docs.cs-cart.com/4.19.x/developer_guide/api/entities/languages.html
Send a GET request to the /api/languages/ endpoint to retrieve a list of all installed languages. Pagination parameters like 'page' and 'items_per_page' can be added to control the response.
```http
GET /api/languages/
```
```http
GET /api/languages/?page=2&items_per_page=2
```
--------------------------------
### Update HTTP Host in config.local.php
Source: https://docs.cs-cart.com/4.19.x/install/moving_to_another_server.html
Replace 'example.com' with your store's domain name in config.local.php. Ensure the domain points to the new server.
```php
$config['http_host'] = 'example.com';
```
--------------------------------
### Request Products API
Source: https://docs.cs-cart.com/4.19.x/developer_guide/api/entities/products.html
Example of a GET request to the Products API to retrieve a limited number of products. Use this to fetch product data from the API.
```http
GET /api/products?items_per_page=2
```
--------------------------------
### Run LVEmp 7.3 Playbook (Varnish + Nginx + MySQL + PHP 7.3)
Source: https://docs.cs-cart.com/4.19.x/developer_guide/getting_started/server_ansible_playbooks.html
Execute this playbook for a setup that includes Varnish, Nginx, MySQL, and PHP 7.3. The command requires being in the ~/playbooks/ directory.
```bash
cd ~/playbooks/ && ansible-playbook -e @config/main.json -c local -i inventory_varnish73 lvemp73.yml
```
--------------------------------
### Upgrade Package Information
Source: https://docs.cs-cart.com/4.19.x/upgrade/upgrade.html
This example demonstrates how to process an XML response from an upgrade server and return an array containing essential upgrade package details. It includes mandatory fields like file, name, description, versions, timestamp, size, and type, along with optional fields.
```php
$data = simplexml_load_string($response);
return array(
'file' => (string) $data->package->file,
'name' => (string) $data->package->name,
'description' => (string) $data->package->description,
'from_version' => (string) $data->package->from_version,
'to_version' => (string) $data->package->to_version,
'timestamp' => (int) $data->package->timestamp,
'size' => (int) $data->package->size,
'my_very_important_field' => (string) $data->package->my_sha_key,
'custom_field' => (string) $data->package->custom_field,
);
```
--------------------------------
### Get Specific Block Response
Source: https://docs.cs-cart.com/4.19.x/developer_guide/api/entities/blocks.html
Example JSON response for a specific block, including its ID, type, properties, company ID, language code, name, and content.
```json
{
"block_id": "38",
"type": "template",
"properties": {
"template": "blocks/static_templates/404.tpl"
},
"company_id": "1",
"lang_code": "en",
"name": "404",
"content": ""
}
```
--------------------------------
### List Installed Languages Response
Source: https://docs.cs-cart.com/4.19.x/developer_guide/api/entities/languages.html
A successful response to GET /api/languages/ returns a JSON object containing a 'languages' object with language details and a 'params' object for pagination information.
```json
{
"languages": {
"en": {
"lang_id": "1",
"lang_code": "en",
"name": "English",
"status": "A",
"country_code": "US",
"direction": "ltr"
},
"ru": {
"lang_id": "2",
"lang_code": "ru",
"name": "Русский",
"status": "A",
"country_code": "RU",
"direction": "ltr"
}
},
"params": {
"items_per_page": "10",
"page": 1,
"total_items": 2
}
}
```
--------------------------------
### Create a Product
Source: https://docs.cs-cart.com/4.19.x/developer_guide/api/entities/products.html
Creates a product with the minimum required details: name, category ID, and price.
```json
{
"product": "Product Name",
"category_ids": "166",
"price": "1000"
}
```
--------------------------------
### Using __ Function in PHP
Source: https://docs.cs-cart.com/4.19.x/developer_guide/core/language_variables.html
Example of using the `__` function in PHP to get a language variable and set a notification message. Ensure the language variable is defined in your language files.
```php
$confirmed_text = __('email_marketing.subscription_confirmed');
fn_set_notification('I',$confirmed_text, $msg);
```
--------------------------------
### Example package.json File Structure
Source: https://docs.cs-cart.com/4.19.x/upgrade/upgrade.html
This JSON file defines the structure and contents of an upgrade package, including files, their status and hashes, migrations, languages, validators, and scripts.
```json
{
"files": {
"app/addons/upgrade/addon.xml": {"status": "changed", "hash": "b0911a0d64453ab06b0872c9eb6fbc34"},
"app/addons/upgrade/func.php": {"status": "changed", "hash": "4fefb0fed1496f179a14b7e872eb16d9"},
"app/addons/upgrade/robots.txt": {"status": "deleted", "hash": "df32e836628b51af570dd2425cb3e97e"},
"js/addons/upgrade/up.js": {"status": "new"},
"var/themes_repository/responsive/templates/addons/upgrade/hooks/products/image_wrap.post.tpl": {"status": "new"}
},
"migrations": [
"20141022083711_addon_update_version.php"
],
"languages": [
"en"
],
"validators": [
"CheckFileValidator"
],
"scripts": {
"pre": "hello_world.php",
"post": "clear_cache.php"
}
}
```
--------------------------------
### Get Specific Store API Response Example
Source: https://docs.cs-cart.com/4.19.x/developer_guide/api/entities/stores.html
A successful response for a specific store returns a JSON object containing all the store's details. The API consistently uses strings for values, even for numerical or boolean data.
```json
{
"company_id": "1"
"lang_code": "en"
"email": "simtech@example.com"
"company": "Simtech"
"timestamp": "1269610461"
"status": "A"
"storefront": "localhost"
"secure_storefront": "localhost"
"average_rating": null
"company_thread_ids": "1_0"
}
```
--------------------------------
### Install Ansible on Ubuntu 18.04
Source: https://docs.cs-cart.com/4.19.x/developer_guide/getting_started/server_ansible_playbooks.html
Installs Ansible on Ubuntu 18.04. This command updates the package list and then installs the Ansible package.
```bash
sudo apt update
sudo apt install ansible
```
--------------------------------
### Configure Installation Settings
Source: https://docs.cs-cart.com/4.19.x/install/install_via_console.html
Edit the config.php file to set administrator credentials, languages, database details, and server settings for the installation.
```php
return array(
// Add-on names to be installed
// If empty will be installed only addons included by default
'addons' => array(),
'cart_settings' => array (
'email' => 'admin@example.com',
'password' => 'admin',
'secret_key' => 'YOURVERYSECRETCEY',
'languages' => array (
'en', 'da', 'de', 'es', 'fr', 'el', 'it', 'nl', 'ro', 'ru', 'bg', 'no', 'sl',
),
'main_language' => 'en',
'demo_catalog' => true,
'theme_name' => 'basic',
'license_number' => 'CART-1111-1111-1111-1111'
),
'database_settings' => array(
'host' => 'localhost',
'name' => '%DB_NAME%',
'user' => '%DB_USER%',
'password' => '%DB_PASS%',
'table_prefix' => 'cscart_',
'database_backend' => 'mysqli',
'notify' => false,
'allow_override' => 'Y',
),
'server_settings' => array (
'http_host' => '%HTTP_HOST%',
'http_path' => '',
'https_host' => '%HTTP_HOST%',
'https_path' => '',
'correct_permissions' => true,
),
);
```
--------------------------------
### Install PHPUnit and Dependencies
Source: https://docs.cs-cart.com/4.19.x/developer_guide/core/coding_standards/php.html
Install PHPUnit and its required dependencies using Composer. This command should be run from the 'app/lib' directory of your CS-Cart installation.
```bash
cd /path/to/cart/app/lib
composer install --dev
```
--------------------------------
### Install Ansible on CentOS 7
Source: https://docs.cs-cart.com/4.19.x/developer_guide/getting_started/server_ansible_playbooks.html
Installs Ansible and its dependencies on CentOS 7. Ensure you are on a clean OS installation to avoid package conflicts.
```bash
sudo yum -y install epel-release
sudo yum install -y gcc git openssl-devel libffi-devel libselinux-python python-crypto python-jinja2 python-paramiko sshpass PyYAML python-setuptools
sudo rpm -ihv https://releases.ansible.com/ansible/rpm/release/epel-7-x86_64/ansible-2.4.6.0-1.el7.ans.noarch.rpm
```
--------------------------------
### Run LEMP 7.1 Playbook (Nginx + MySQL + PHP 7.1)
Source: https://docs.cs-cart.com/4.19.x/developer_guide/getting_started/server_ansible_playbooks.html
Execute this playbook for a server setup with Nginx, MySQL, and PHP 7.1. Ensure you are in the correct directory before running.
```bash
cd ~/playbooks/ && ansible-playbook -e @config/main.json -c local -i inventory_php7 lemp7.yml
```
--------------------------------
### Get a Specific Langvar (Specific Language)
Source: https://docs.cs-cart.com/4.19.x/developer_guide/api/entities/langvars.html
Send a GET request to /api/languages//langvars/ or use ?sl= to get a langvar for a specific language.
```http
GET /api/languages/1/langvars/access_denied/
```
```http
GET /api/langvars/access_denied/?sl=en
```
--------------------------------
### Run LVEmp 7.1 Playbook (Varnish + Nginx + MySQL + PHP 7.1)
Source: https://docs.cs-cart.com/4.19.x/developer_guide/getting_started/server_ansible_playbooks.html
Use this playbook for a server configuration including Varnish for caching, alongside Nginx, MySQL, and PHP 7.1. Navigate to the playbooks directory first.
```bash
cd ~/playbooks/ && ansible-playbook -e @config/main.json -c local -i inventory_varnish lvemp7.yml
```
--------------------------------
### Run LEMP 7.4 Playbook (Nginx + MySQL + PHP 7.4)
Source: https://docs.cs-cart.com/4.19.x/developer_guide/getting_started/server_ansible_playbooks.html
This playbook sets up a server with Nginx, MySQL, and PHP 7.4. Ensure you are in the ~/playbooks/ directory before running the command.
```bash
cd ~/playbooks/ && ansible-playbook -e @config/main.json -c local -i inventory_php74 lemp74.yml
```
--------------------------------
### Example Product List Template Settings
Source: https://docs.cs-cart.com/4.19.x/developer_guide/addons/tutorials/custom_templates_via_addon.html
Configuration file for a custom product list template, specifying its display name and various product attributes to show.
```smarty
{** template-description:tmpl_modern **}
{* The line above means that the name of the template will be stored
in the language variable called tmpl_modern *}
{* Below are the location and settings of the template. *}
{include file="addons/my_changes/blocks/list_templates/modern_list.tpl"
show_name=true
show_sku=false
show_rating=true
show_features=true
show_prod_descr=true
show_old_price=true
show_price=true
show_clean_price=true
show_list_discount=true
show_discount_label=true
show_product_amount=true
show_product_edp=true
show_add_to_cart=true
show_list_buttons=true
show_descr=true }
```
--------------------------------
### Install Nano Text Editor on CentOS
Source: https://docs.cs-cart.com/4.19.x/developer_guide/getting_started/server_ansible_playbooks.html
Install the nano text editor on CentOS systems. This is a prerequisite for editing configuration files via the command line if nano is not already installed.
```bash
yum install nano
```
--------------------------------
### Create a New Store Example
Source: https://docs.cs-cart.com/4.19.x/developer_guide/api/entities/stores.html
Use this JSON payload to create a new store with basic properties and redirection settings. It specifies the company name, storefront URL, redirection preference, entry page behavior, and a list of countries for redirection.
```json
{
"company": "Example Company",
"storefront": "example.com",
"redirect_customer": "Y",
"entry_page": "none",
"countries_list": [
"DZ", "AS", "AQ", "AG", "AR"
]
}
```
--------------------------------
### Get Theme Area Factory
Source: https://docs.cs-cart.com/4.19.x/developer_guide/addons/compatibility/adapting_4310_to_441.html
Gets the theme factory for a specified area and company.
```php
\Tygh\Themes\Themes::areaFactory($area = AREA, $company_id = null)
```
--------------------------------
### Create a Store and Clone Data Example
Source: https://docs.cs-cart.com/4.19.x/developer_guide/api/entities/stores.html
This JSON payload demonstrates creating a new store while cloning specific data from an existing store. It includes company details, storefront URLs, the ID of the store to clone from, and a list of attributes to clone.
```json
{
"company": "Example Company 2",
"storefront": "example2.com",
"secure_storefront": "example2.com",
"clone_from": "1",
"clone": {
"layouts": "Y",
"settings": "Y",
"products": "Y",
"categories": "Y"
}
}
```
--------------------------------
### Get Data (GET)
Source: https://docs.cs-cart.com/4.19.x/developer_guide/api/index.html
Retrieves data for objects. Supports filtering for specific results.
```APIDOC
## GET /api/:object
### Description
Retrieves a list of objects or a specific object.
### Method
GET
### Endpoint
- `/api/:object` (to retrieve all objects of a certain type)
- `/api/:object/:id` (to retrieve a single object)
- `/api/:object/:id/:nested_object` (to retrieve all nested objects of a certain object)
- `/api/:object/:id/:nested_object/:id` (to retrieve a single nested object)
### Parameters
#### Query Parameters
- **Filtering**: Supports filtering for specific results (details not specified).
### Response
#### Success Response (200)
- Data in JSON format.
### Request Example
```bash
curl -u "admin@example.com:YOUR_API_KEY" -X GET http://example.com/api/product/1/features
```
### Response Example
```json
{
"example": "response body"
}
```
```
--------------------------------
### Get All Discussions
Source: https://docs.cs-cart.com/4.19.x/developer_guide/api/entities/discussions.html
Retrieves a list of all reviews and comments. Supports GET and POST methods.
```bash
curl -X GET 'http://example.com/api/2.0/discussions/'
```