Axure RP9 shopping cart with global variables

Hi everyone,

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.

below is the file
supelivery.rp (1.5 MB)

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.

I hope you have my example. Good luck to you.

@conrad8027,

Your English is good.

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:

image

…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.

supelivery.rp (1.2 MB)

2 Likes

Thank you Serge, will try it later

Thank you so much, it works now!

hi @mbc66

i tried your '‘cancel’ button, but i clicked last “cancle” buttton then showed text “Total_Price - Item.money_list”.

i dont know what’s the problem

here’s my axure file

shopping cart.rp (1.4 MB)

good luck to you

thanks

@mbc66

There was an error in the order of interaction.

I solved the interaction order by deleting the row at the bottom.