it might be best if you can upload your .rp file here. That is usually the easiest and fastest way for others here to help you.
It sounds like you can do this already, but I’ll touch on details of this later on…
In general, there are several basic methods to calculate a tally of repeater row values, depending on how you structure your repeaters and handle user interactions (adding/changing/choosing items) as well as if both repeaters are on the same page or different pages. You can store totals in global variable(s) or the text value of widget(s) either inside or outside the repeater–but if you need to refer to these values on another page then you must use global variables.
The widgets which show these totals should be outside both repeaters.
Here are some basic methods to keep track of totals. Each has its own advantages and disadvantages.
- Update a running total “on the fly” as a direct result of user interactions in the “product catalog” repeater–typically via the Click or Tap event of a widget in the repeater, like a button, or Text Changed event of a Text Field. As a very simple example, let’s say you have a repeater with two columns in its data sheet: “Product” and “Price”, and in the repeater cell, a widget for each of these, along with an “Add To Cart” button.
- You can create a global variable to store the running Cart total, let’s say it is named, “VarCartTotal”. (Its default value is zero, which you can set either in the Page Loaded event or the repeater’s Loaded event.)
- The “Add To Cart” widget has a Click or Tap which would include a Set Variable Value action like,
"Set Variable Value of VarCartTotal to [[VarCartTotal + Item.Price]]"(along with action to add or update a row in the cart repeater.) - If you have a widget showing the number of items and/or a repeater column to store this number, you can have a set of conditional cases to handle a change to 1 (e.g. first time “Add To Cart” is clicked) --to add a row to the cart; and greater than 1–to update an existing row in the cart; and less than 1 (or “equal to 0”) --to delete a row in the cart repeater. For example,
If text on MyProductCount equals "1" Add Row to CartRepeater
Else if text on MyProductCount is greater than "1" Update Row of CartRepeater
…(with rule like “[[TargetItem.Product == Item.Product]]”
Else if text on MyProductCount is less than "1" Delete Row of CartRepeater
…with same rule to match rows. - This method is pretty straightforward, but it will fail if you alter the catalog repeater in any way, such as sorting, filtering, adding or removing rows, etc. because each of these actions would trigger the repeater’s Item Loaded event, thus resetting everything to default, thus losing any user selections.
- Or you can use the Item Loaded event with conditional cases. This lets the repeater automatically calculate totals in a self-contained way. This requires a column per each value you need to track–like the number of items per product. Instead of just directly setting the text value or global variable value when an item is added/edited, you update the row in the same repeater (as well as adding/updating a row in the cart repeater.) This method takes a little more setup time and forethought, but is more reliable and flexible as it supports sorting, filtering and other catalog changes.
- The “Add To Cart” button would have an action like,
Update This Row…where you select the column to update, like “Count” with expression like,[[Item.Count + 1]] - The repeater’s Item Loaded would have a set of conditional cases like,
If [[Item.isFirst]] equals "true" Set Variable Value of VarCartTotal equal to "0"
If true Set Text (of your repeater widgets)
…Set Variable Value of VarCartTotal equal to [[VarCartTotal + (Item.Count * Item.Price)]]- Thus, every time the item repeater is updated it runs through each row, first initializing the running total (VarCartTotal global variable) to zero, then adding the cost of each item (multiplied by the selected number per item)
- You could also build in the logic to update the cart repeater, here in the Item Loaded event rather than the “Add To Cart” button (and whatever else controls you might have like ‘+’ and ‘-’ buttons, text entry, a “Remove” button, etc.)
- Or, you can calculate the “final price” per item and the totals (price, VAT, price with VAT) all in the cart repeater, based purely on the items in the cart. This method works if both repeaters are on the same page. If the cart repeater is on a different page, the product repeater (or a “mini cart” repeater on first page) would first need to set some global variables for the totals.
- The catalog repeater adds/updates/removes rows to the cart repeater as described above. But, it is not concerned with any totals. This approach can help keep the functions and logic separated, which should be more reliable, easier to debug, and more reusable. So basically, the function of the catalog repeater is just to show products (along with names, prices, images, descriptions etc.) and allow them to be added to the cart–that’s it. The function of the cart repeater is to show selected products and calculate totals (as well as change counts of products, remove them, etc. as needed)
- The cart repeater would have columns for (at least) Product, Price, Count.
- The cart repeater’s Item Loaded event would contain the conditional cases to initialize the total value(s), and update these totals for each row (using the same logic as shown in method 2 above.)
- If you have a catalog repeater on one page (or multiple pages) and a cart repeater on its own separate page, you could also set up one global variable per possible product, or use one global variable to store an array of selected products, their prices and item counts. Now, Axure does not support true arrays (unfortunately) but you can kind of manually create one as a “hash string” and then on the cart page you can parse this string to construct the cart repeater and its running totals. This is a fairly advanced method, so I’ll just point to a forum thread which demonstrates it. This method works if you have many pages that need to refer to “cart details” --such as multiple catalog/product pages, and/or separate “checkout” pages that might need to access, edit and/or recreate a cart.
Good luck, and if you have any specific questions or would like to see some examples of these methods, reply here and I’ll post some examples.