Best online selling solutions
Developer tools

What are formulas for calculating prices in JavaScript?

The module of formulas for calculating prices in JavaScript gives the possibility to run JavaScript mini-programs in the cards of the offered products, which can be an extension for the variants module or operate independently, giving the possibility to define even the most advanced logic of calculating their prices.

When does it make sense to use the module?

By using the formula module for calculating prices in JavaScript, you can define any attributes (formula parameters) of any combination (e.g. describing a roller blind, offered both in standard and non-standard dimensions, where personalisation will have a significant impact on its price), as well as even very advanced mathematical functions (formula functions) calculating the price of the offered merchandise taking into account the complex configuration of its specific attributes (e.g. calculating the price of such a roller blind, which will grow with its length or width, and will be an exponential function). Such functionality cannot be achieved with standard "clickable" configurations.

Why is this solution unique and interesting?

Thanks to the possibility of using JavaScript price formulas, you don't have to use open-source software, modifying the way prices are calculated, to non-linear. You can continue to use all the advantages of SaaS and at the same time, add your own pricing program.

How does it work in the IdoSell store?

On the product card (projector)
The parameters specified by the developer in the formula structure are returned on the product card in the shop mask in the form of selectors, inputs, radiobutons or checkboxes (an individual component in the mask is required). The buyer shall specify in which parameter configuration he wants to purchase the product by selecting their values. The values are then transferred by the mask to the API gateway, which processes them according to the logic stored in the formula function. The customer shall return in response to the customer's active or inactive discounts in the shop the correct price at which the customer can purchase the selected product.

In the purchasing process (COP)
Parameters and their values selected by the buyer on the commodity card are passed on in the mask as multi-variants and their values throughout the entire purchasing process until the order is placed in the store (a standard component in the mask is used). When calculating the price of a given product, the server runs the code of the formula used in it directly on its side, thus taking care of the correct course of the whole process and its compliance with the adopted logic, while not allowing any unauthorized attempts to modify it.

How to start working with JavaScript price formulas?

Go to the new card page of the selected product in the IdoSell panel and on the tab Prices set, so that the Price calculation mode shows the option Formulas calculating the price. You will then be able to edit and enter the prepared formula code.

After completing it, you will also be able to check whether your formula is working properly and that its execution time does not exceed the allowed standards. All you need to do is to use the Editable Check the entered formula button. As a result, the system will show you a preview of the form of the available attributes you specified in the formula, where after selecting the values appropriate for them, the system will calculate the final price of the product and check whether the calculation time does not exceed the acceptable standard for 2 seconds.

Go to detailed description of the formula structure for calculating prices in JavaScript

Safety and restrictions

In order to protect you from dishonest customers who would like to modify the price calculated for them before placing their order, we have introduced a security feature consisting in the fact that the code of the prepared formula is not executed on the browser side but directly on the shop's server.

For correct handling of the module JavaScript price formulas, a server is required DEDICATED CLOUD.

In addition, in order to ensure smooth operation of the shop, two restrictions have been introduced:

  • maximum allowable time of execution of a given formula, which is 2 seconds,
  • the maximum quantity used by the memory formula, which for 1024MB.