I have a database of gift card numbers that I would like my customers to be able to search for their card number and get a balance. I’ve uploaded all my card number into a database (GiftCardDatabase) in wix with the “sCardNumber” and “sRemainingBalance” headers.
Any help would be awesome!
Here is the site and a card number I know to have a balance:
https://p44904.wixsite.com/giftcards2020/balance
Card Number - # 2087010042842273
Remaining Balance $32.42
I wrote the following code but when I execute the search, nothing shows up in my result table.
import wixData from “wix-data” ;
export function balancebutton_click(event) {
wixData.query( “GiftCardDatabase” )
.contains( “sCardNumber” , $w( “#searchbox” ).value)
.find()
.then(res => {
$w( "#resultsTable" ).rows = res.items;
});
$w.onReady( function () {
$w( “#resultsTable” ).columns = [{
“id” : “col1” ,
“sCardNumber” : “Card Number” ,
“label” : “Card Number” ,
“visible” : true ,
“type” : “string” ,
}, {
“id” : “col2” ,
“sRemainingBalance” : “Remaining Balance” ,
“label” : “Remaining Balance” ,
“visible” : true ,
“type” : “string” ,
},];
});
}
Hello Daniel,
Take a look at this one…
https://russian-dima.wixsite.com/meinewebsite/card-number
import wixData from 'wix-data';
$w.onReady(function () { });
export function button1_click(event) {xxx()}
function xxx (parameter) {
wixData.query("Card-Number")
.eq("title" ,$w('#input14').value)
.find()
.then( (results) => {
if(results.items.length > 0) {
let firstItem = results.items[0];
$w('#table4').rows = results.items
$w('#IMAGE').src = firstItem.neuesFeld
} else {
// handle case where no matching items found
}
} )
.catch( (err) => {
let errorMsg = err;
} );
}
That looks like it would work! I’m a bit confused on what to replace and what not to replace though.
@daniel51537
Copy&PASTE this code to your site/page.
Modify all inputs, elements and dataset, for your own.
Everything what is BLUE, you have to modify!
- How is called your DATABASE ?
wixData.query("Card-Number")
- In which COLUMN are you searching? / Which VALUE?
.eq("title" ,$w('#input14').value)
- How is called your TABLE ?
$w('#table4').rows = results.items
- How is called the COLUMG/REFERENCE in you DATABASE for IMAGES ?
$w('#IMAGE').src = firstItem.neuesFeld
@russian-dima The only element i’m struggling with is the " #IMAGE ".src What images are you referring to? I’m not calling any images.
@daniel51537
Yes i know, because i upgradted my example a little bit. I assume you do not have user-images in your database (but you could create them
), or you can simply DELETE this function and work without images.
Side note, how did you integrate the redemption of the cards and how does it subtract the balance and apply to purchase total?
This here was the CODE for the EXAMPLE…
import wixData from 'wix-data';
$w.onReady(function () { });
export function button1_click(event) {xxx()}
function xxx (parameter) {
wixData.query("Card-Number")
.eq("title" ,$w('#input14').value)
.find()
.then( (results) => {
if(results.items.length > 0) {
let firstItem = results.items[0];
console.log(results.items[0].neuesFeld)
$w('#table4').rows = results.items
$w('#IMAGE').src = results.items[0].neuesFeld
} else {
// handle case where no matching items found
}
} )
.catch( (err) => {
let errorMsg = err;
} );
}
There isn’t any integrated substraction-function. But you can expand the CODE and add this function, or any other function.
And here you can see the used DATABASE for this example…
@russian-dima good morning, I am trying to follow this but I am having issue. Can you assist?
I have the following:
import wixData from ‘wix-data’ ;
$w.onReady( function () { });
export function button5_click(event) {xxx()}
function xxx (parameter) {
wixData.query( “GCBalance” )
.eq( “cardNumber” ,$w( ‘#sGCNumber’ ).value)
.find()
.then( (results) => {
if (results.items.length > 0 ) {
let firstItem = results.items[ 0 ];
$w( '#resultsTable' ).rows = results.items
$w( '#cardOwner' ).text = firstItem.neuesFeld
$w( '#resultsTable' ).show();
} **else** {
// handle case where no matching items found
$w( ‘#sInvalid’ ).show();
}
} )
. catch ( (err) => {
let errorMsg = err;
$w( ‘#sInvalid’ ).show();
} );
}
Where “GCBalance” is my database collection, “cardNumber” is the title of the column on the collection, “#sGCNumber” is the input box.
“#resultsTable” is the table on the site page, and “#cardOwner” is the primary column on the collection.
I don’t want the table to display until after data is retrieved, so I had a “.show” function at the end, then two error message options should the database either encounter an error or not find the data entered.
This is my currently published page this is referenced on. Can you assist? I added a preset in the collection that is “1234567890” but no matter what I enter I get “Error: Invalid Card Number” (my #sInvalid response).
Appreciate any ideas!
@russian-dima fixed it! I looked back at my database and realized my Card Numbers were listed as numbers. Changed to Text and now it works.
@amentowasso
Well done. I have seen your message just right now. I am too late
(you are too fast
).
@russian-dima I’m persistent and determined haha. Do you by chance have any tips for integrating the gift card usage itself with Wix Checkout?
@amentowasso
Sorry, i am not really using all the Wix-Apps, so i am not sure if i can help at this topic.