Loading...

Programming standards

We no longer maintain the Knowledge Base since version 4.3.x. All the latest user and developer documentation for 4.3.x and newer versions is now available at docs.cs-cart.com.

  • This article applies to CS-Cart versions:
  • 3.0.x

Standards

Programming standards

  • If there is a table with checkboxes for selecting several elements in a template (e.g. Manage products), checkboxes should be named as the object primary key in a plural form.

For example, for products - product_ids

1
<input type="checkbox" name="product_ids[]" value="{$product.product_id"} />
  • if it is necessary to create a link by clicking on which javascript is executed, href="#" should not be defined for this link.
1
2
<a class="ajax" coords="...">Save</a>
<a onclick="click_me();">Click me</a>
  • a special parameter redirect_url can be passed in a request. In this case after all controllers are processed there will be a redirect to the URL specified in this parameter.
  • selected_section, page are attached automatically in the URL during a redirect if such variables are got with a request.
  • descr_sl should not be attached to the URL at all.
  • all_languages is renamed to languages, is stored in Registry, the current language – the constant CART_LANGUAGE
  • currencies are stored in Registry, current currencies - CART_PRIMARY_CURRENCY, CART_SECONDARY_CURRENCY (in templates they are still variables).
  • modes with the prefix do_ cannot be used anymore
  • if the function requires a language transfer, ideally the parameter with the language should be placed at the end, but necessarily not at the beginning of an arguments list. Also the deafult value CART_LANGUAGE should be assigned to it:
1
function fn_get_products($params, $get_totals, $lang_code = CART_LANGUAGE) {}
  • NEVER PASS PARTS OF SQL REQUESTS TO THE FUNCTION

Getting several objects

It is carried out through functions. Name has the following format:

1
fn_get_[objects]

 

For example:

1
fn_get_products, fn_get_categories, fn_get_pages

 

The first parameter passed to such functions is ALWAYS an array of selection criteria. In the general case all that is received through GET request is passed there, for example:
1
fn_get_products($_REQUEST);

 

The function should return values as an array for further processing through the function list. For more details see Object selection standards.

Templates standards

All parameters of functions/operators, etc. must be enclosed in double quotes:

1
2
3
{foreach from=$array item="item" key="key"}
{include file="common_templates/tpl.tpl" param1="param" param2="param"}
{/foreach}

 

Modes of operation with objects

Base object

Updating an onbject list - m_update

Deleting objects - delete

Updating an object - update

Adding an object - add

 

Additional object characteristics

Updating a list of object characteristics - m_update_[suffix]

Deleting objects characteristics - delete_[suffix]

Updating object characteristics - update_[suffix]

Adding object characteristics - add_[suffix]


It will be made clearer by the example of shipping methods
  • Adding a method - add
  • Updating a method - update
  • Updating a list of methods - m_update
  • Deleting taxes - delete
  • Adding a rate - add_rate
  • Deleting rates - delete_rates
  • Updating rates - m_update_rates
  • Updating a rate - update_rate

Formatting standards

If table data should be displayed and the data is absent – only the table header and the text "No data found" are displayed.


Language variables

It is not allowed to compose phrases of several variables. There could be some difficulties when translating into other languages, for example:
WRONG
1
var message = lang.pages + ' ' + lang.added;

RIGHT
1
var message = lang.pages_added;

 

<< Read previous Read next >>
Home / Docs / Appendix / Coding Standards / Programming standards