Advanced product price calculation

Advanced product price calculation (calculator)

Advanced product price calculation (calculator)

The add-on calculates the product price by a formula you define. Every product has its own formula, and the variables in it are the options chosen by the customer, numeric product features, global variables (constants shared by all products) and the parameters of the product itself: the base price, the list price, the ordered quantity, the stock level and the popularity. This is how products are priced when the price depends on dimensions, area, length, print run or a combination of several parameters: furniture, glass, fabrics, printing, building materials.

The price is recalculated wherever the CS-Cart core applies option modifiers: on the product page on every option change (without reloading the page), in the cart and at checkout, and also when an administrator creates or edits an order. The formula calculates the price of one unit; the line total is obtained by the core as usual, by multiplying it by the quantity. For a product with an active formula the price is fully defined by the formula — the standard modifiers of option variants are not added on top of it, they only serve as variable values.

The add-on has two modes. In the simple mode the formula is an arithmetic expression of variables and numbers. In the professional mode the formula is written in PHP: conditions, rounding, any checks of the intermediate result. Besides formulas, the add-on adds a new option type, Number (Add-on): a field for entering a number with a range, a step and preset values.

The add-on settings are on the Add-ons → CS-Commerce Addons → Advanced Price Calculation page; formulas are defined on the product editing page in the Advanced Price Calculation tab. The workflow: add the required options to the product (the Adding options to a product section), then write the formula (the Adding a formula to a product section).

The formula is defined separately for every product. The add-on changes nothing for products without an active formula — their price is calculated by the core as usual.
Compatibility

The add-on works with CS-Cart and Multi-Vendor starting from version 4.0.1 and supports the CS-Cart, CS-Cart Ultimate, Multi-Vendor, Multi-Vendor Plus and Multi-Vendor Ultimate editions. Starting from version 4.4.0 the add-on is compatible with PHP 8.3.

On the storefront the add-on plugs into the options block of the product page: it overrides the views/products/components/product_options.tpl template of the Responsive theme with its own copy that has an extra hook for the numeric option type, and extends the quantity field and the cart rows through the standard products:qty and checkout:items_list hooks. Themes based on Responsive work without changes. If your theme has heavily reworked the product options template, the options block may change its look after the add-on is installed — in that case please contact our support center.

The add-on manifest declares a conflict with the price_calculation add-on: the two cannot be installed together.

We cannot guarantee that the add-on will work correctly on projects with a large number of custom or third-party add-ons.

Add-on installation

After success payment, your order will be automatically marked as Paid within a few minutes. Once order changed to Paid status - add-on License activation passed success and you will received an e-mail with confirmation the receipt of payment and a second e-mail with a  download add-on link. You can also download the add-on in our License Management section of our website. To install the add-on on your website, please follow these steps:

  1. Download the latest version of the add-on on our website in the "License Management" section or via the link sent by e-mail.
  2. Go to Add-ons → Manage Add-ons and in the gear button, select Manual Installation.
  3. Select the downloaded file and complete the installation of the add-on.

Add-on installation is completed.

Setting up the add-on

After installation the add-on is ready to work with the default settings. They can be changed on the Add-ons → CS-Commerce Addons → Advanced Price Calculation page; the same page opens from the settings button of the add-on in the Add-ons → Manage add-ons list. The settings are global for the whole store: on CS-Cart Ultimate and Multi-Vendor they are not split by storefront or vendor.

General settings

Mode — the way formulas are written. Simple (the default): the formula is an arithmetic expression of variables, numbers, operators and brackets; the formula field of a product is a single line. Professional: the formula is a fragment of PHP code whose result is assigned to the $price variable; the formula field is multi-line. The mode applies to all products at once, so after switching it the formulas of all products have to be written in the new style. An example formula for the selected mode is shown under the setting.

Debug errors — enabled by default. If a formula contains invalid characters or a syntax error, refers to a variable the product does not have, or its result is not a number, an error notification is shown with the product ID and the formula text after value substitution. The notification is seen both by the administrator in the panel and by the customer on the storefront, so once the formulas are debugged the setting can be disabled — on an error the add-on simply leaves the product price unchanged.

Check amount — disabled by default. Enable it if your formulas use the [amount] variable: then a quantity change on the product page recalculates the price immediately, with an AJAX request, just like an option change. Without this setting the quantity does not reach the formula on the product page and is taken into account only when the cart is recalculated.

Hide formula tab for vendors — the setting exists on Multi-Vendor only and is disabled by default. See the Multi-Vendor section.

Click Save after changing the values.

Simple mode

Simple mode.

Professional mode

Professional mode.

Version and subscription block

The right side of the settings page shows the state of the add-on: the installed version, whether a new version is available and the term of the upgrade subscription. When an update is available, you can go to the Upgrade center from here and open the changelog; when the subscription is ending or has expired — renew it. Below are links to rate the add-on, to other CS-Commerce add-ons, to the documentation and to feedback. On Multi-Vendor the block is visible to the marketplace administrator only.

Adding options to a product

Product options serve as formula variables. Options of three standard types — Select box, Radio group and Checkbox — and options of the numeric Number (Add-on) type added by the add-on (the Additional numeric type section) can be used. Options of the text input, text area and file types do not take part in formulas. An option can be either the product's own option or a global option linked to the product.

For options with variants the value of the variable is taken from the Modifier field of the selected variant — this is where the number that should get into the formula is written. The modifier type (absolute or percent) is ignored by the add-on: the number is substituted as is, and what to do with it is up to the formula. For a checkbox option the variant modifier gets into the formula when the box is checked, and 0 when it is unchecked.

The variants of Select box and Radio group options provide a second number for the formula as well — the Weight modifier field: the [opt_Xw] variable, with the letter w after the option ID. This way one variant can hold, for example, a surcharge and a coefficient.

Let us take an example. If the required option does not exist yet, go to the Products → Options page and click Add option.

New option

We create the Size option of the Select box type and give it three variants (S — 0, M — 2, L — 3).

The variant value is written in the Modifier field.

Option variants

Click Save. Then open the product editing page, the Options tab, and add the option to the product.

Choosing the option

Click Save. The option is added to the product, and its variable has appeared in the Advanced Price Calculation tab.

Product options

Adding a formula to a product

The formula is defined on the product editing page in the Advanced Price Calculation tab. The tab consists of four blocks: global variables, options, features and the formula itself. Next to every variable its index in square brackets and the + icon (Add to formula) are shown; the icon appends the variable to the end of the formula field.

Variables

  • Global variables [glb_N] — named constants shared by all products: an exchange rate, a labour cost, a coefficient. They are created right here: enter a name and a value in the Add new global variable row and save the product. The value is a number with up to two decimal places. Changing a global variable affects every formula that uses it; a variable is deleted with the cross in its row.
  • Options [opt_N] — the active options of the product, own and global; N is the option ID. What is substituted for the variable is described in the Adding options to a product section.
  • Features [ftr_N] — numeric product features (the Number style, with an entered value or a value selected from a list) that have a value filled in for the product; N is the feature ID. The feature value of this product is substituted, so one formula gives different prices for products with different features. Non-numeric features are not listed.
  • Other variables — product parameters: [price] — the price the core starts the calculation from (taking into account the wholesale price for the ordered quantity and the user group, but without option modifiers); [list_price] — the list price; [amount] — the ordered quantity (on the product page — the minimum order quantity or 1, and with the Check amount setting enabled — the quantity entered by the customer; in the cart — the quantity in the row); [in_stock] — the stock level; [popularity] — the product popularity by the core counter (1 if there is no data).

Writing the formula

Set the formula Status to Active and write the formula in the Formula to calculate new price field. An Example for the current mode is shown under the field.

In the simple mode the formula is an arithmetic expression: variables, numbers (with a dot as the decimal separator), the + - * / operators and brackets; the field does not accept other characters. The result of the expression becomes the product price. Percentages are written as a multiplier: a 15% markup is [price]*1.15, a percentage markup from an option is [price]+[price]*[opt_12]/100.

If the formula refers to a variable the product does not have (the option was deleted, the feature has no value), in the simple mode the add-on shows a notification about the missing variable and calculates the formula without it: such a variable is dropped from a product or a division, in other cases 0 is substituted for it.

In the example below the formula increases the product price by the percentage written in the modifier of the selected variant of the Size option.

Formula

Click Save. The result can be checked on the product page on the storefront: when the option variant changes, the price is recalculated without reloading the page.

Product on the storefront

Hide quantity

The Hide quantity checkbox in the formula block removes the quantity selector on the product page and in the cart — for products where the quantity makes no sense or is already built into the formula (for example, the area in square metres is entered through an option). The customer orders one unit of the product at the calculated price.

Good to know

  • the formula calculates the price of one unit and replaces the standard option modifiers: for a product with an active formula the variant modifiers are not added to the price, they only serve as variable values;
  • in product lists and storefront blocks the price is shown for the default option variants; the exact price appears on the product page once the options are selected;
  • the price in an order is fixed at checkout; when an administrator creates or edits an order, the formula is applied again with the options selected in the order;
  • when a product is cloned the formula is copied to the copy, when variations are generated — to the variations; formulas can be enabled and disabled in bulk and transferred by import (the Bulk editing, import and copying section).

Professional mode

To have formulas executed as code, set Mode to Professional in the add-on settings and save. The formula field of products becomes multi-line.

In this mode the formula is a fragment of PHP code. The rules:

  • before execution the add-on substitutes the numeric values for the [opt_N], [ftr_N], [glb_N], [price], [amount] and other variables, so in the code they are used as numbers: $price = [price] * [opt_3];;
  • the result is assigned to the $price variable; its last value becomes the product price. Every statement ends with a semicolon;
  • if / elseif / else conditions, arithmetic and PHP functions are available: round($price, 2) for rounding, max() and min() to limit the price from below and above, ceil() to round up;
  • if a variable the product does not have is left in the formula, the code contains a syntax error, or $price is not a number in the end, the add-on shows a notification (with the Debug errors setting enabled) and leaves the product price unchanged.

An example formula: a markup by options and a global variable, a 10% discount when the price is above 50, a 20% surcharge when the option value is above 15, rounding to cents.

$price = ([price]+[opt_1])*[opt_2]*[opt_3]*[glb_1];
if ($price > 50){
  $price = $price*0.9;
}
if ([opt_1] > 15){
  $price = $price*1.2;
}
$price = round($price, 2);

Another example — the tax rate depends on the selected product size. Open the Advanced Price Calculation tab of the product, write the rates into global variables and save.

Global variables

The formula checks the size in the conditions, assigns the required tax coefficient and multiplies the price by it.

Formula in the professional mode

In the professional mode the formula is executed on the server as PHP code. Give access to the formula tab only to those you trust to edit the store code; on Multi-Vendor the tab can be hidden from vendors with an add-on setting.

Additional numeric type

The add-on adds a new option type — Number (Add-on). It is a field where the customer enters a number: a length, a width, an area, a print run. The entered value is substituted into the formula as the [opt_N] option variable, and in the cart and in the order it is shown instead of the variant name.

The type is selected in the general settings of the option — on the Products → Options page or in the Options tab of a product. Two extra tabs appear for it.

New option type

The Settings tab

  • Default value — is put into the field when the product page opens;
  • Min. value and Max. value — the allowed range. If the customer enters a number outside it, the nearest limit is substituted;
  • Step — the value granularity: the entered number is rounded up to the nearest value of the form «minimum + step × k».

Instead of a number, any of these fields can hold a feature variable [ftr_N] — then the limit or the step is taken from the feature of the particular product (for example, the maximum width — from the «Roll width» feature). The list of features with their indexes is shown under the fields when the option is edited from the product page. On the storefront a hint is built from the filled values under the field: Enter value from … to … step ….

Settings of the numeric type

The Variants tab

Here preset values for quick selection are defined: every variant has a position, a name, a value and a status. On the storefront the variants are shown as a list above the input field; the last item of the list — Enter your value — opens the field for an arbitrary number. If there are no variants, only the field is shown.

Variants of the numeric type

Click Save. Then the option is used in the formula as usual, for example [price]*[opt_N].

On the storefront the field looks like this:

Numeric option on the storefront

The field accepts digits and a dot only, a comma is replaced with a dot. The price is recalculated right after the input — when the field loses focus or on the Enter key.

Before version 4.5.0, for a product whose only option was a numeric one, the price on the storefront did not update after a value was entered. This is fixed in 4.5.0: for a product with an active formula the recalculation runs on any option change.

Multi-Vendor

On Multi-Vendor formulas are defined both by the marketplace administrator and by vendors — each for their own products. The specifics:

  • Hide formula tab for vendors — an add-on setting that appears on Multi-Vendor only. When it is enabled, vendors do not see the Advanced Price Calculation tab of products and the formula field in bulk editing; formulas defined by the administrator keep working. This keeps the formulas under the control of the marketplace administrator.
  • Global variables are split by owner. Variables created by the administrator are visible to everyone and are substituted into the formulas of any products; a vendor's variables are visible in the vendor's products only. A vendor can change and delete only their own variables, the administrator's variables are shown to them read-only. The administrator editing a vendor's product sees both the shared variables and the variables of that vendor.
  • Common Products for Vendors: if a vendor's product is created from a common product that has a formula, a copy icon with the Click to insert formula from master product hint is shown next to the Formula to calculate new price field. It puts the formula of the common product into the field; after saving, the formula works for the vendor's product independently of the common one.

Bulk editing, import and copying

Bulk editing

On the Products → Products page select the products, choose Edit selected in the actions menu and tick Advanced price calculation in the list of fields. The Formula status field appears in the bulk editing form. Click Apply values to all the selected products, tick Formula status in the panel that opens, choose Active or Disabled and click Apply — this is how formulas are enabled or disabled for a group of products at once. The formula text is not set in bulk editing: every product has its own.

Import and export

In the standard product import and export (Administration → Import data and Export data, the Products section) the add-on adds two fields: Formula — the formula text, and Formula status — its status, A (active) or D (disabled). This is how formulas are transferred between stores and edited in a spreadsheet.

Cloning products and variations

  • when a product is cloned (the Clone action) the formula and its status are copied to the new product together with the numeric options and their settings;
  • the Advanced Price Calculation tab is also available for product variations: a formula can be set separately for every variation. When variations are generated, the formula of the source product is copied to the variations that do not have their own formula yet.

Upgrade an add-on

In order to have access to add-on upgrades, you must have an active upgrade subscription. If the subscription period has expired, you will only have access to upgrades released before the expiration date of your subscription. You can renew your upgrades subscription in the "License Management" section on our website.

The add-on supports instant upgrades via the CS-Cart Upgrade Center. The built-in CS-Cart Notification Center (bell) will notify you about new versions release of the add-on. Upgrades via Upgrades Center will allow you to switch to a newer version without losing add-on data and settings.

Before start an upgrade process, it is highly recommended to make a full backup of the site (database and files) of your store using the server or hosting methods. 

 Upgrade through the Upgrade Center

  1. In the top menu, go to Administration → Upgrade Center;
  2. In the gear menu, click "Refresh available upgrades"
  3. Find and add-on on list of available upgrades and click the Download button and than Install button;
  4. Follow all the instructions that will be shown during the upgrade process;
  5. It is recommended to clear the CS-Cart templates cache after the upgrades are installed by deleting the var/cache folder on your server or adding the ctpl parameter to the address bar (example: https://domain.com/admin.php?ctpl).

Addon Reinstallation by uninstall old and install new:

Reinstalling an add-on means deleting the add-on's settings and data. Reinstallation will allow you to get a clean installation of the latest addon version. To reinstall the add-on with saving the add-on settings and data, please contact us via our Support Center to provide this service.

To completely reinstall an add-on without saving data, follow these steps:

  1. Go to Add-ons → Manage add-ons and find the old installed add-on.
  2. Click the delete button in the gear menu of the add-on.
  3. Download the latest version of the add-on on our website in the "License Management" section.
  4. Go to Add-ons → Manage add-ons and in the gear menu select Manual Installation. Select the previously downloaded file and complete the installation of the add-on.

Technical support

The technical support of the add-on is already included in its price. Before contacting the support center, please make sure you are using the latest released version of the add-on. Old versions of the add-on are not supported by technical support.

To use our technical support, follow these steps:

  1. On our support center site https://helpdesk.cs-commerce.com/, log in with your account;
  2. Click on the "Create ticket" button;
  3. Fill in all the required fields and create ticket (you will receive a confirmation email);
  4. Expect a response from a specialist (a notification will be sent to your e-mail about the response) in accordance with the regulations of the technical support service.

If you have not received an answer within the time frame specified in the regulations, write us a message to the e-mail [email protected] with the subject of the ticket and we will try to resolve your issue as soon as possible.

Technical support via chat on the site, direct phone calls or e-mail letters is not provided. All help discuss goes through the support center. Carefully study the documentation for the add-on and the terms of technical support before creating a ticket. 

Limitations and Warnings

We recommend that you familiarize with the general restrictions:

  1. Fragments of code or some files of an add-on may have a private (encoded) part. The coded part does not create problems on add-on customizations;
  2. The add-on will work only on those domains that are specified in the user's license. If you try to use the solution the domains of which are not included in the license, the add-on will be automatically disabled;
  3. Installing on local machines is not allowed by the licensing system. For the add-on to work on an additional domain (alias), specify this alias on the license management page. Up to three aliases are allowed per domain for testing and development purposes. You can change the main license domain yourself on the license management page.
To have possibility to add or change license domains and aliases, the upgrade subscription must be active. To change the license domain of an expired upgrades subscription, you must first renew your subscription.  

Changelog

Version 4.5.0 of September 22, 2026

  • [!] Fixed price recalculation on the storefront: when a product had only a numeric calculator option (and no other options with price modifiers), the price did not update after entering a value;
  • [*] Updated the version and subscription information block in the add-on settings;
  • [+] Added PHP 8.3 compatibility.

Version 4.4.0 of March 3, 2026

  • [!] Fixed a compatibility issue with the Product Bundles add-on;
  • [+] Added the ability to hide the product quantity selection field on the storefront;
  • [+] Added compatibility with PHP 8.3;
  • [*] Basic security updates of the add-on components.

Version 4.3.2 of March 28, 2025

  • [!] Fixed a PHP warning on some configurations.

Version 4.3.1 of October 28, 2024

  • [*] Added a class to style the option description;
  • [*] The value input field: if the entered value is greater or less than the specified range, the limit value is substituted;
  • [*] Basic security updates.

Version 4.3.0 of March 12, 2024

  • [!] Fixed the possibility for a vendor to edit a global variable (Multi-Vendor);
  • [+] Added the possibility to copy the formula from a common product (Multi-Vendor);
  • [+] Added the possibility to hide the formula tab from vendors (Multi-Vendor).

Version 4.2.1 of November 24, 2023

  • [*] Basic security updates of the add-on.

Version 4.2.0 of July 17, 2023

  • [!] Fixed an issue with the Common Products for Vendors add-on on Multi-Vendor;
  • [*] Basic security updates.

Version 4.1.2 of October 19, 2022

  • [!] Fixed an issue when adding an option from the product page on the latest CS-Cart versions;
  • [+] Added compatibility with PHP 8.0.

Version 4.1.1 of September 7, 2022

  • [+] Added the possibility to disable formula error notifications.

Version 4.1.0 of September 5, 2022

  • [+] When a product is cloned, its formula is copied to the new product;
  • [+] When a product variation is created, the formula of the original product is copied to the variation.

Version 4.0.12 of July 19, 2022

  • [+] Added a setting to enable or disable price recalculation on a quantity change before adding the product to the cart;
  • [*] Basic security update.

Version 4.0.11 of June 9, 2022

  • [+] Added the possibility to use the formula calculation with common products (Multi-Vendor).

Version 4.0.10 of April 5, 2022

  • [!] Fixed an issue on the order editing page with a calculated option.

Version 4.0.9 of March 17, 2022

  • [!] Fixes related to the build error of the previous release.

Version 4.0.8 of March 15, 2022

  • [+] Added the possibility to set a calculation formula for a product variation;
  • [!] Fixed an issue with duplicated tabs on CS-Cart 4.14.x.