Last active
June 28, 2020 04:46
-
-
Save shanwixcode/cd5fca0e61054f453d3f4fdd96e28414 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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