The module allows you to load a custom script in each product page.
Additionally, you can load a global script which applies to all products with the module enabled.
Path of the global script:
1 |
[root]/js/dynamic/custom.js |
Path of the custom script:
1 |
[root]/js/dynamic/customX.js (where X is the product ID) |
You can use these scripts to extend the module functionality in an easy way.
Each field gets a function that is called when the field value is changed by the customer, here’s an example:
Supposing the field name is “width”, the function name is then “dp_width”.
The “dp_” prefix stands for “Dynamic Product” and aims to prevent any conflict with existing functions.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
function dp_width(value) { // the "value" variable holds the current value of the field // you can use any jQuery function like this: // change another field value getField('height').val(value * 2); // hide another field's parent (necessary to hide the label and the info icon) getParent('field_name').hideField(); //change min max and value and step getField('field_name').data('min', 50).apply(); getField('field_name').data('max', 100).apply(); // or in a chain getField('field_name').data('min', 50).data('max', 100).data('step', 0.5).val(60).apply(); } // An example function for a dropdown list named "type" function dp_type(value, id_option) { // the "id_option" variable holds the current id of the selected dropdown option // this is necessary if you have multiple options with the same value // you can get every option ID in the dropdown options popup in the backoffice product page } // more info: // A value of a checkbox is either 1 or 0 depending on the state of the checkbox // These custom functions are triggered when the field value changes and also on the page load |
Hidden fields will have a null value (0 for numeric fields, an empty string for text and date fields)