Skip to content

Instantly share code, notes, and snippets.

@shanwixcode

shanwixcode/mcPage.rb

Last active Jun 28, 2020
Embed
What would you like to do?
import wixData from 'wix-data';
import wixUsers from 'wix-users';
export function dataset2_ready() {
$w("#forex").value = 'USD';
}
export function repeater1_itemReady($item, itemData, index) {
$item("#price").text = "USD " + itemData.price;
}
export function forex_change(event) {
calculateForex();
}
function calculateForex() {
wixData.query("forex")
.eq('currency', $w("#forex").value)
.find()
.then((results) => {
let Item = results.items[0];
getFinalRates(Item);
});
}
function getFinalRates(Item) {
$w("#repeater1").onItemReady( ($item, itemData, index) => {
let newprice = Math.round((Number(Item.rate)) * (Number(itemData.price))).toFixed(0);
$item('#price').text = String($w("#forex").value + ' ' + newprice);
$item("#actualprice").text = String(newprice);
});
}
export async function addToCart_click(event) {
let $item = $w.at(event.context);
$item("#addToCart").disable();
let user = wixUsers.currentUser.id;
let clickedItem = $item("#dataset1").getCurrentItem();
let data = {
productName: clickedItem.name,
image: clickedItem.mainMedia,
quantity: 1,
price: Number($item("#actualprice").text),
currency: $w("#forex").value,
userId: user
};
await wixData.insert('cart', data);
$item("#addToCart").enable();
}
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.