Skip to content

Instantly share code, notes, and snippets.

@shanwixcode
Last active June 28, 2020 04:49
Show Gist options
  • Save shanwixcode/c79821e9ea52e049a7066fc31ef17088 to your computer and use it in GitHub Desktop.
Save shanwixcode/c79821e9ea52e049a7066fc31ef17088 to your computer and use it in GitHub Desktop.
import wixUsers from 'wix-users';
import wixData from 'wix-data';
import {createMyPayment} from 'backend/wixPay.jsw';
import wixPay from 'wix-pay';
$w.onReady(function () {
let user = wixUsers.currentUser.id;
wixData.query('cart')
.eq('userId', user)
.find()
.then( (res) => {
let items = res.items;
setItems(items);
let sum = 0;
items.forEach( (item) => {
sum = sum + item.price;
});
amt = sum;
cry = items[0].currency;
$w("#total").text = String('Total: ' + sum + ' ' + items[0].currency);
$w("#repeater1").data = items;
$w("#box1").collapse();
$w("#repeater1").expand();
});
});
function setItems(items) {
items.forEach( (item) => {
let data = {
name: item.productName,
price: item.price,
quantity: item.quantity
};
products.push(data);
});
}
var amt;
var products = [];
var cry;
export function repeater1_itemReady($item, itemData, index) {
$item("#img").src = itemData.image;
$item("#pname").text = itemData.productName;
$item("#qt").text = String(itemData.quantity);
$item("#price").text = '' + itemData.price + ' ' + itemData.currency;
}
export function checkout_click(event) {
createMyPayment(products, amt, cry)
.then( (payment) => {
wixPay.startPayment(payment.id);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment