- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-07-2022 06:22 AM
Is there a way to calculate the total for this? The quantity will still need to be multiplied based on the price per size of the drink and I wanted to store the total into another variable that is not inside the multi-row variable set.
Is there also a way so that every time they click add It'll update the total variable outside of the MRVS
Solved! Go to Solution.
- Labels:
-
Studio
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-08-2022 02:34 AM
Thread closed:
Please refer to this link for displaying the data: How to display data from a client script to an HTML widget and display its value in a text field.
In short, for the calculation and displaying of data. I used a custom with label variable and created a widget
with the following client script:
api.controller = function($scope) {
/* widget controller */
var c = this;
$scope.$watch(function() {
//Internal Name of Variable Set 'item_details'
return $scope.page.g_form.getValue('choose_your_drink_s');
}, function(value) {
if (value) {
var mrvsData = JSON.parse(value.replace(/'/g, ''));
console.log(value);
var totalCost = 0;
for (var i = 0; i < mrvsData.length; i++) {
var mrvs = mrvsData[i];
totalCost += parseFloat(mrvs.pricePerSize) * parseFloat(mrvs.quantity);
alert('Calculating: ' + totalCost + ' for --> ' + mrvs.pricePerSize);
}
//Set Value in the Total Cost
alert(totalCost);
c.data.cost = totalCost;
$scope.page.g_form.setValue('total_amount',totalCost);
alert(c.data.cost);
}
});
};
and HTML:
<div>
<input type="text" value ={{c.data.cost}} readonly>
</div>
To achieve this:
~Melvin B.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-18-2022 01:29 AM
Thank you for the details with the code, a quick follow question, how can we send this "value" back to the catalog client script on the catalog item. In the client controller code, console.log displays very well the MRVS content on every change, but how do I get this changed value of MRVS to be used in the catalog client script ?
console.log(value);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-13-2022 02:50 AM
Hello,
This is so helpfull but i have a question.
My "Total amount" don't take decimal in count.
For exemple, i have 10 computers at 189,50 euros each one.
In total amount, it write 1890 instead of 1895.
How can i correct this please?
Thanks in advance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-31-2022 05:50 PM
Here is a more generic solution.
Generic Widget (Can re-use for any MRVS or other use cases potentially):
api.controller = function($scope) {
/* widget controller */
var c = this;
$scope.$watch(function(){return MrvsValueMonitor();}, function(value) { MrvsValueChanged(value);});
};
Catalog Client Script (OnLoad) for specific use case:
function onLoad() {
//Usual onload logic here...
}
//Create a function with named "MrvsValueMonitor" for the widget to monitor for changes
MrvsValueMonitor = function(){
return g_form.getValue('catering_items');
};
//Create a function named "MrvsValueChanged " for the widget to fire when it detects changes.
MrvsValueChanged = function(value){
alert('The value of the catering items MRVS has changed to: ' + value);
};
If anyone sees any major issues with this approach please let me know.
Thanks!