I am working on a project in school which is making an app for a delivery thing. So I use the global variables in order to calculate the total price in the shopping cart. But it doesn’t work for me that whenever i pressed the add button, the total price doesn’t change ( it is still 0.00 ). Can anyone help me with this problem? Many thanks and sorry for the bad English writing as I am a international student.
Hi, I’ve seen a bit of your problem, well I’m not an expert on Axure rp but, I think you have to create a value for the total number of products add to the cart before all.
And then you will be able to calculate the total price of the number of products add to the basket according to the number of existing products in the basket.
EX: onclick - set variable - numberOfProducts - set to - text - function (numberOfProducts +1)
Then: set text - text0fNumberProduct - to value variable - numberOfProduct. (to calculate the number of products add)
Finally: set text - target (textOfTotalPrice) - set to - value - (in a function) PriceOfProduct * numberOfProducts.
(All this will be calculated with your variables: PriceOfProducts, NumberOfProducts.
So, when you click an Add button, you update the global variable, “Total_Price” which is good. You then need to update the text of the widget, “TotalPrice” which is in the “shopping cart list” group. You can just set that to the value of [[Total_Price]] (and include the £ character).
A few little improvements which would be good: If your prices will have cents, it is best to convert text values to numbers with two decimal places–to match currency formatting. Otherwise, when adding and subtracting your Total_Price you can end up with some rounding errors with results like (£ 20.99999999998). To do this in Axure, use the math function .toFixed(2) when setting the value of Total_Price. Here are the changes I made to the Add button in product repeater:
…in which the first action is: [[ (Total_Price + Item.product_price).toFixed(2) ]]
Likewise, I added code to the “cancel” button in the cart to adjust the value of Total_Price and the text value of TotalPrice.