Client Specific Pricing for Dynamic Page

Hello,
I have created this dynamic page which includes blood testing information (image 1).

However, where the circle is, instead of “test code” i would like that to be for “Price”.

Where the page itself is public, but if the client logins in then they can view pricing specific to them. Corresponding to the relevant test code.

There are over 100 tests and each price for every client is different.

I think what i need is a code that after they login will recognize and bind to their corresponding Client field key. How can i bind their login with their client field key so that it grabs their specific pricing?

I’m not sure I understand how you store the client data. Do you create a field per logged in user?

I just added “Client 1” and “Client 2” above as examples. I am not sure whether to store the client data separately or within the same sheet. Ideally it would be within the same sheet with a field per logged in user.

Any ideas on this? Thanks in advance

Hi David, I will try to help you out, I had a similar problem. The below answer assumes the following:
0) that every client logs into Wix using the Wix users standars dialog (you can OK them or not)

  1. that every row into your database carries a unique identifier for a client (I propose email address)
  2. that every row in your database is entered by you, so a future selection on row_owner is useless, because that will carry your ID, not the client´s (therefor email address)
  3. that you have to do two lookups (actually a JOIN): first the correct row from your DB filtered by clients email address (which could have more than 1 result: a client could come back), then fetch the test code from this row and do another lookup, get the price and display it.

@0/1/2) when you enter a row into you database with results, you have to provide the clients email address and, to make it friendly, his name. When the user logs on, you retrieve his email address from Wix-users and you display all rows into a table. This would be somethjing like this: (snippet from a case-selection)
break;
case “Member”:
user.getEmail()
.then((rsemail) => {
let userEmail = rsemail;
wixData.query(“YourCollectionName_NotDatasetName”)
.eq(“email”, userEmail)
.ascending(“title”)
.find()
.then((results) => {
$w(“#tblName fot the table you are using”).rows = results.items;
})
.catch((err) => {
let errorMsg = err;
});

		}); 
	break; 
case "Admin": 

@3) so now the client has selected one of his results from a table. That one is easy, you display all data on a dynamic page.
Then the join. You select the test code like this:
let thistestCode = $w(‘#datasetname’).getCurrentItem().testcode;

assumiing that .testcode is the actual field name in your DB (and NOT the label name)

Now you build a new query, just like the one above, but this time on the Test code collection, with a .eq(thistestCode). You retrieve the Price from this row just like we retrieved the Test code above, you throw it to a text field (or in your case inside that balloon) and voila.

Hope this helps. Good luck.

Thanks so much Giri, unfortunately I’m not too code savy.
I just butchered the whole Code. Hopefully I can get some help.

I created 2 databases

  1. CompleteMenu has all the test information stored
  2. Client Has Client/Member Information: Name, Email, Price and Test Code (Test Code matches test codes in #1)

CompleteMenu Field Codes:
Test code field name= title_id

Client Field Codes:
Email_id
Price_id
Test Code_id
Name_id

Code placed in the Dynamic Page:

David, I see what´s the problem, it´s my fault, I thought you would understand the switch/case part, but I see you assumed this would be a copy/paste thing. It´s not. I will correct the errors, but first you need to give me some pointers on how you want this to work:
a)who may enter your database and request results: if only registered users: who registers the user: you or they?(tip: to make it easier, I advise that you create an account for every client, so you don´t have to approve/deny access every day to every request)
b) who creates the client details, as you described: you or they? (tip: it´s easier if you did that)
c) can clients have more than one test result ( even if one if from a couple of years ago?
d) if more than one, would you like to show also the “old” ones, or just the “new” one. If last, what is definition of new (maybe when it was paid and delivered/sent)?
e) I do not understand your database setup: correct me if I am wrong, but if you define a test code per client, that means he can only have 1 test (thereby giving an answer to question c)
f) Don´t you need at least this: a client collection, a test code collection(that holds pricing per test code) and a test result collection, that holds info on the client, the test results and a link to the test code pricing to retrieve the price?

Sorry to put so many questions to you, but if we want to get it right quickly, I need to know how you envision it to work.
Watching your back.

1 Like

David, one more thing: is this supposed to be an internal application (just for you and your employees) or also external (so clients can grab their results from your web site)?

1 Like

Hi Giri,
I really appreciate the assistance. To clarify, this isn’t for results. This is meant to just show test information. I placed an example below.

a) I will be creating the users
b) I create/input the client details
c) The pricing for the clients is viewable only. They will not be placing orders online. The test code isn’t a result it’s just the code that is unique to the each test. Every client will have the same test code, but different prices. (see example below)
d) They would not be ordering/paying online
e) See example below
f) I hope this clarifies/helps what I think I need is something like: after client logs in if the Test code matches in database 1&2 and also the email in database 2 then it will show the price corresponding to that email that corresponds to the test code.

I have 1 database with the test information this never changes unless new tests are added.

The second database includes the test code, price, email, client name, Client ID.
The unique identifier could be either the Email or Client ID (I think in terms of setting things up the email may be the easiest?)

So let’s say “Client2” logs in and is viewing “test2”. Now the system will know client2@gmail.com is logged in and that he is looking at Test code 5678 thus the price will show $3.69.

This is an example of what the page currently looks like: https://www.ihealthdiagnostics.org/test/7100
Note: “Test code” will be moved to the left and instead will indicate “Price” in the circle.

Also, if no one is logged in then it would either be blank or indicate “Click here to login and view your pricing”

Let me know if you have any other questions I am more than happy to answer them

This is for External application; for clients to view their pricing

Hi David, sorry about late response, I had no Internet all morning. I think I understand what you mean, so what we are going to do is this:

  1. when a user is not logged on, we are going to show a text box saying something like “PLease logon to view your pricing” and a logon button next to it.
  2. if a user is logged on and there is pricing for a text code, we show the price insode the balloon and hide the textbox and button
  3. if a user is logged on and there is no pricing for the test code, we change the text to something like “No pricing available, please contact us” and hide the logon button

How to do it

  1. on the dynamic page, draw a box (container) which we will call “box1” (lets say below the balloon). INside it, put a text box and a button next to it. Textbox will be “txtRemarks”, button will be “btnLogon”. Using a box around these things has 2 purposes: the text and button will stay nicely together on a smartphone screen AND it will allow us to hide the box entirely (including text and button). Fill the text box with the default text for non-logged on visitors (see 1, above)
  2. copy all your current code to a text file (we are going to need it later on) and then delete everything apart from the $w.onready and corresponding curly brace
  3. at the top, thus above the $w.onready, do this

iimport wixUsers from ‘wix-users’;
import wixData from ‘wix-data’;

  1. inside the $w.Onready, do this

let user = wixUsers.currentUser;
let userRole = user.role;
if (userRole = “Member”) {
$w(“#Box1).Hide()”;
user.getEmail()
.then((rsemail) => {
let userEmail = rsemail;
let thistestCode = $w(‘#datasetname’).getCurrentItem().testcode; // TODO:replace datasetname with your dataset name of the dynamic page

			wixData.query("Clients") // change this to the Collection name of your clients db 
				.eq("email_id", userEmail) 
				.eq("testCode_id", thistestCode ) 
				.descending("date_created") //TODO ;lookup the real name in the Admin grid 
				.find() 
				.then((results) => { 
					if ( results.totalCount [TODO:see below]) { 

let items = results.items ;
let firstItem = items[0];
$w(“#txtPrice”) = firstItem.price_Id ;// this puts the price into the balloon
else {
$w(“#Box1).Show()”;
$w(“#btnLogon).Hide()”;
$w("#txtRemarks = “Sorry, no pricing available, please contact us”;
}
}
})
.catch((err) => {
let errorMsg = err; // bogus, never used
});

		}); 

}

  1. I do not know what results.totalCount returns if there is no test code for this user (empty resultset). It could be 0, -1, Null or undefined. You will have to try this out by using a bogus email address and do a console-log of results.totalCount Then test accordingly on 1 of those 4 possibilities.
    Also, you see we allow that a user can have two equal test codes. This could happen when you change your prices per user/testcode and you don´t want to destroy the old info OR you make a mistake and put in two rows with same email/same test code. In this case THE mostrecent is selected , because we sort on creation date
  2. on the onClick event of the button, code a a promptLogin(). That will force a login window.

NOTE: I did not test this code, I typed it in into this forum text window , so it might have a missing ; or } here and there or it needs a little tweek… You will have to find that out for yourself, but this should get you going. The TODO´s are easy. If not, look at w3school for javascripts help and look at the API docs here on Wix. You will have to put some effort into it, otherwise you are not going to understand what you are doing. Believe me when I say that problems that first seemed insurmountable will look pathetically trivial after a couple of weeks of reading and horsing around.

Good luck.
PS do NOT forget to put a dataset.onready inside the page onready (it´s docuemnted everywhere). I did.

Another thing: when testing, you will have to do that on a Published site. As Andreas once explained to me, user-stuff doesnot work in Preview Mode

Hi Giri, I have a small issue with my own website, and its Dynamic pricing, perhaps you could answer my questions? :slight_smile:

thank you so much

Hello, could you maybe help me with dynamic pricing question I posted? https://www.wix.com/velo/forum/coding-with-velo/how-do-i-make-group-appointments-available