Calcbuilder extended:calculator integrated in Hikashop product:using and saving product parameters

  • Font size: Larger Smaller
  • Hits: 40503
  • Print

Following with our last post which showed how to integrate a calculator inside a Hikashop product page using the CB Price Calculator plugin, this tutorial will explain how you can access to the default parameters of the product at the calculation step. This is useful if you want for example, use the default price, weight, size, etc at your calculation to get your new price/quantity. We will also learn how you can store at your product the properties you may be calculating dynamically (for, ex, the final name of the product or its weight)

Recovering values

At the code section you have available one object that contains all properties of the Hikashop product for which the calculator is running, that is called 'productData'. You can access the product properties using their names, the names of the properties are the ones you can see at the db table #__hikashop_product:

You may have additional/different fields at your database table, depending on the custom fields you have created for the table 'product', they can be recovered using its name as well. So, you can use at your code :

This object also contains information about the original price of the product. As products in Hikashop can contain multiple prices, you must use the array syntax to get this information:


Storing new values

The basic function of the plugin is to calculate new prices and/or quantities for your products, but you may also want to store new values for other fields that are calculated at the code section. For this purpouse, you can create an array called 'hk_calculatedparams' that you can fill with any property of the table 'product'. This property will be modified when product is added to the cart.

In order to use this new array you must ensure the custom field 'calculatedparams' is enabled for the table 'item' at your hikashop configuration. Then you can use a code like the following:

$hk_calculatedparams["product_name"]="new name";

With this example we'll be setting a new product name and also the new code will be the result of a calculation

Using these functions you'll have available a powerful tool to build complex calculators inside a Hikashop product page. Enjoy!

Last modified on

Lo que nuestros clientes opinan de nosotros