Skip to content

Instantly share code, notes, and snippets.

@shanwixcode

shanwixcode/mcck.rb

Last active Jun 28, 2020
Embed
What would you like to do?
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
You can’t perform that action at this time.