/** * This file contains the class used to run the E-Commerce cart * @author Incomedia Srl (http://www.incomedia.eu) * @copyright Incomedia Srl * @version 9.0.10.1842 */ _jq.extend(x5engine.imCart, { _restoreSpecialChars: function (str) { return str.replace(/\{1\}/g, "'").replace(/\{2\}/g, "\"").replace(/\{3\}/g, "\\").replace(/\{4\}/g, "<").replace(/\{5\}/g, ">"); }, // Test if cookies are working in the current browser _testCookie: function () { _jq.imCookie("imCookieTest", "test_content"); if (_jq.imCookie("imCookieTest") == "test_content") return true; return false; }, // Get the product array from cookie _getCart: function () { try { if (_jq.imCookie(x5engine.imCart.costants.COOKIE_NAME, null, { path: '/'}) !== null) return _jq.parseJSON(_jq.imCookie(x5engine.imCart.costants.COOKIE_NAME, null, {path: '/'})); else return []; } catch (e) { _jq.imCookie(x5engine.imCart.costants.COOKIE_NAME, {}, { path: '/' }); return []; } }, // Save the product array to the cookie _setCart: function (products) { if (!x5engine.imCart._testCookie()) { alert(x5engine.l10n.getLocalization("cart_err_cookie")); return false; } var json = []; for (var i = 0, j = 0; i < products.length; i++) if (products[i] !== null && products[i] !== undefined) { json[j] = "{\"id\": \"" + products[i].id + "\", \"quantity\": " + products[i].quantity + ", \"option\": \"" + products[i].option + "\"}"; j++; } json = json.join(","); json = "[" + json + "]"; _jq.imCookie(x5engine.imCart.costants.COOKIE_NAME, json, { path: '/' }); }, // Save the form data in a cookie _setFormData: function (post) { var json; for (var i = 0; i < post.length; i++) { post[i] = "{\"id\": \"" + post[i].id + "\", \"val\": \"" + post[i].val + "\"}"; } json = "[" + post.join(",") + "]"; _jq.imCookie(x5engine.imCart.costants.COOKIE_FORM_NAME, json); }, // Get the form data from the cookie _getFormData: function () { try { return _jq.parseJSON(_jq.imCookie(x5engine.imCart.costants.COOKIE_FORM_NAME)); } catch (e) { _jq.imCookie(x5engine.imCart.costants.COOKIE_FORM_NAME, {}); return null; } }, // Set the currency format _setCurrency: function (n, format, currency) { var decsep = ""; var thsep = ""; var integer; var decimal = ""; currency = currency || x5engine.imCart.settings.currency; if (format === null || format === undefined) format = x5engine.imCart.settings.currency_format; var value = ""; // Find the decimal separator decsep = Math.max(format.lastIndexOf("."), format.lastIndexOf(",")); thsep = Math.min(format.indexOf("."), format.indexOf(",")); if (thsep == -1 && format.indexOf(".") != -1) thsep = format.indexOf("."); if (thsep == -1 && format.indexOf(",") != -1) thsep = format.indexOf(","); if (decsep != -1) { integer = format.substr(0, decsep); decimal = format.substr(decsep + 1); } else integer = format; // Set the precision var counter = 0, i; for (i = 0; i < decimal.length; i++) if (decimal.charAt(i) == '@') counter++; value = new Number(n); value = value.toFixed(counter); var int_value = Math.floor(value); var dec_value = value.toString(); dec_value = dec_value.substring(dec_value.length - counter); if (decsep != thsep && thsep != -1) thsep = format.charAt(thsep); else thsep = ""; if (decsep == -1) decsep = ""; else decsep = format.charAt(decsep); // Format the int part int_value += ""; value = ""; for (i = 0; i < Math.max(integer.length, int_value.length); i++) { if (i % 3 === 0 && i !== 0 && (int_value.length - i > 0 || integer.charAt(integer.length - 2 - i) == "@")) { value = thsep + value; } if (int_value.length - 1 - i >= 0) value = int_value.charAt(int_value.length - 1 - i) + value; else if (integer.charAt(integer.length - 1 - i) == "@") value = "0" + value; } if (counter === 0 && dec_value > 0) { counter = 2; decimal = "@@"; } // Add the decimal part value = value + decsep.toString() + dec_value; decimal = decimal.replace("[C]", ""); // Add the currency symbol if (format.indexOf("[C]") === 0) value = currency + value; else if (format.indexOf("[C]") != -1) value += currency; return value; }, // Get the value of the key _getValueFromKey: function (key, array) { var value; if (array["0"] === null || array["0"] === undefined) value = 0; else value = array["0"]; if (key * 1 > 0) for (var property in array) if (property * 1 <= key * 1) value = array[property]; return value; }, // Get the shipping price _getShippingPrice: function (shipping, subtotal, total_quantity, total_weight, vat) { if (vat === null || vat === undefined) vat = true; if (shipping.price !== null && shipping.price !== undefined) { switch (shipping.type) { case "WEIGHT": price = x5engine.imCart._getValueFromKey(total_weight, shipping.price); break; case "QUANTITY": price = x5engine.imCart._getValueFromKey(total_quantity, shipping.price); break; case "AMOUNT": price = x5engine.imCart._getValueFromKey(subtotal, shipping.price); break; default: price = shipping.price; break; } if (shipping.vat !== null && shipping.vat !== undefined && vat) price += price * shipping.vat; return price; } return 0; }, // Set the payment type _setPayment: function (n) { _jq.imCookie(x5engine.imCart.costants.PAYMENT_COOKIE_NAME, n, { path: '/' }); x5engine.imCart.payment_type = n; }, // Get the payment type _getPayment: function () { if ((x5engine.imCart.payment_type === null || x5engine.imCart.payment_type === undefined) && _jq.imCookie(x5engine.imCart.costants.PAYMENT_COOKIE_NAME) !== null && _jq.imCookie(x5engine.imCart.costants.PAYMENT_COOKIE_NAME) !== undefined) { x5engine.imCart.payment_type = _jq.imCookie(x5engine.imCart.costants.PAYMENT_COOKIE_NAME) * 1; x5engine.imCart.email_data.payment = x5engine.imCart.payment_type; } return x5engine.imCart.payment_type; }, // Set the shipping type _setShipping: function (n) { _jq.imCookie(x5engine.imCart.costants.SHIPPING_COOKIE_NAME, n, { path: '/' }); x5engine.imCart.shipping_type = n; }, // Get the shipping type _getShipping: function () { if ((x5engine.imCart.shipping_type === null || x5engine.imCart.shipping_type === undefined) && _jq.imCookie(x5engine.imCart.costants.SHIPPING_COOKIE_NAME) !== null && _jq.imCookie(x5engine.imCart.costants.SHIPPING_COOKIE_NAME) !== undefined) { x5engine.imCart.shipping_type = _jq.imCookie(x5engine.imCart.costants.SHIPPING_COOKIE_NAME) * 1; x5engine.imCart.email_data.shipping = x5engine.imCart.shipping_type; } return x5engine.imCart.shipping_type; }, // Empty the cookie and reset the cart _realEmptyCart: function () { x5engine.imCart._setCart([]); x5engine.imCart.updateWidget(); if (_jq("#imInputTotalPrice").length > 0) x5engine.imCart.showCart(); }, // Create a string ready to be used in an HTML/JS string _htmlOutput: function (str) { return str.replace(/\"/g, "''").replace(/\/g, ">"); }, // Create the order number _createOrderNo: function (format) { if (format === null || format === undefined) format = x5engine.imCart.settings.order_no_format; var date = new Date(); var day = date.getDate(); var month = date.getMonth() + 1; var shortYear = date.getYear().toString(); shortYear = shortYear.substring(shortYear.length - 2); if (parseInt(day, 10) < 10) day = "0" + day; if (parseInt(month, 10) < 10) month = "0" + month; format = format.replace(/\[dd\]/g, day); format = format.replace(/\[mm\]/g, month); format = format.replace(/\[yy\]/g, shortYear); format = format.replace(/\[yyyy\]/g, date.getFullYear()); while (format.match(/\[A-Z\]/)) format = format.replace(/\[A-Z\]/, String.fromCharCode(Math.round(Math.random() * 25 + 65))); while (format.match(/\[a-z\]/)) format = format.replace(/\[a-z\]/, String.fromCharCode(Math.round(Math.random() * 25 + 97))); while (format.match(/\[0-9\]/)) format = format.replace(/\[0-9\]/, Math.round(Math.random() * 9)); return format; }, // Create the correct HTML code for operational purposes _createPaymentHtml: function (paymentHtml) { // Replaces the keywords if (x5engine.imCart.email_data.order_no === null || x5engine.imCart.email_data.order_no === undefined || x5engine.imCart.email_data.order_no === "") x5engine.imCart.email_data.order_no = x5engine.imCart._createOrderNo(); paymentHtml = paymentHtml.replace(/\[ORDER_NO\]/g, x5engine.imCart.email_data.order_no); paymentHtml = paymentHtml.replace(/\[EX_ORDER_NO\]/g, escape(x5engine.imCart.email_data.order_no)); // URL-escaped order number (to be enclosed in a link) paymentHtml = paymentHtml.replace(/\[QUANTITY\]/g, x5engine.imCart.email_data.total_quantity); paymentHtml = paymentHtml.replace(/\[EX_QUANTITY\]/g, escape(x5engine.imCart.email_data.total_quantity)); // URL-escaped quantity paymentHtml = paymentHtml.replace(/\[WEIGHT\]/g, x5engine.imCart.email_data.total_weight); paymentHtml = paymentHtml.replace(/\[EX_WEIGHT\]/g, escape(x5engine.imCart.email_data.total_weight)); // URL-escaped weight var price = x5engine.imCart.email_data.clear_total; // Format the price var format = x5engine.imCart.settings.cart_price; if (format.multiplier !== null && format.multiplier !== undefined) price *= format.multiplier; price = x5engine.imCart._setCurrency(price.toString(), format.format); paymentHtml = paymentHtml.replace(/\[PRICE\]/g, price); paymentHtml = paymentHtml.replace(/\[EX_PRICE\]/g, escape(price)); // URL-escaped price // Unsecaped custom-format price while (paymentHtml.match(/\[PRICE,\s*([0-9]+),\s*([\w#@\.,\[\]]+)\]/)) { price = x5engine.imCart.email_data.clear_total; price *= parseInt(RegExp.$1, 10); price = x5engine.imCart._setCurrency(price.toString(), RegExp.$2); paymentHtml = paymentHtml.replace(/\[PRICE,\s*([0-9]+),\s*([\w#@\.,\[\]]+)\]/, price); } // Escaped custom-format price while (paymentHtml.match(/\[EX_PRICE,\s*([0-9]+),\s*([\w#@\.,\[\]]+)\]/)) { price = x5engine.imCart.email_data.clear_total; price *= parseInt(RegExp.$1, 10); price = x5engine.imCart._setCurrency(price.toString(), RegExp.$2); paymentHtml = paymentHtml.replace(/\[EX_PRICE,\s*([0-9]+),\s*([\w#@\.,\[\]]+)\]/, escape(price)); } //Customer data fields post = x5engine.imCart.email_data.form; if (post != null && post["imCartName_shipping"] != null && post["imCartName_shipping"] != "") { // Unescaped values paymentHtml = paymentHtml.replace(/\[FIRST_NAME\]/g, ((post["imCartName_shipping"] != null) ? x5engine.imCart._htmlOutput(post["imCartName_shipping"].imValue) : "")); paymentHtml = paymentHtml.replace(/\[LAST_NAME\]/g, ((post["imCartLastName_shipping"] != null) ? x5engine.imCart._htmlOutput(post["imCartLastName_shipping"].imValue) : "")); paymentHtml = paymentHtml.replace(/\[ADDRESS1\]/g, ((post["imCartAddress1_shipping"] != null) ? x5engine.imCart._htmlOutput(post["imCartAddress1_shipping"].imValue) : "")); paymentHtml = paymentHtml.replace(/\[ADDRESS2\]/g, ((post["imCartAddress2_shipping"] != null) ? x5engine.imCart._htmlOutput(post["imCartAddress2_shipping"].imValue) : "")); paymentHtml = paymentHtml.replace(/\[CITY\]/g, ((post["imCartCity_shipping"] != null) ? x5engine.imCart._htmlOutput(post["imCartCity_shipping"].imValue) : "")); paymentHtml = paymentHtml.replace(/\[STATE\]/g, ((post["imCartStateRegion_shipping"] != null) ? x5engine.imCart._htmlOutput(post["imCartStateRegion_shipping"].imValue) : "")); paymentHtml = paymentHtml.replace(/\[COUNTRY\]/g, ((post["imCartCountry_shipping"] != null) ? x5engine.imCart._htmlOutput(post["imCartCountry_shipping"].imValue) : "")); paymentHtml = paymentHtml.replace(/\[ZIP\]/g, ((post["imCartZipPostalCode_shipping"] != null) ? x5engine.imCart._htmlOutput(post["imCartZipPostalCode_shipping"].imValue) : "")); paymentHtml = paymentHtml.replace(/\[EMAIL\]/g, ((post["imCartEmail_shipping"] != null) ? x5engine.imCart._htmlOutput(post["imCartEmail_shipping"].imValue) : "")); // Escaped values paymentHtml = paymentHtml.replace(/\[EX_FIRST_NAME\]/g, ((post["imCartName_shipping"] != null) ? escape(x5engine.imCart._htmlOutput(post["imCartName_shipping"].imValue)) : "")); paymentHtml = paymentHtml.replace(/\[EX_LAST_NAME\]/g, ((post["imCartLastName_shipping"] != null) ? escape(x5engine.imCart._htmlOutput(post["imCartLastName_shipping"].imValue)) : "")); paymentHtml = paymentHtml.replace(/\[EX_ADDRESS1\]/g, ((post["imCartAddress1_shipping"] != null) ? escape(x5engine.imCart._htmlOutput(post["imCartAddress1_shipping"].imValue)) : "")); paymentHtml = paymentHtml.replace(/\[EX_ADDRESS2\]/g, ((post["imCartAddress2_shipping"] != null) ? escape(x5engine.imCart._htmlOutput(post["imCartAddress2_shipping"].imValue)) : "")); paymentHtml = paymentHtml.replace(/\[EX_CITY\]/g, ((post["imCartCity_shipping"] != null) ? escape(x5engine.imCart._htmlOutput(post["imCartCity_shipping"].imValue)) : "")); paymentHtml = paymentHtml.replace(/\[EX_STATE\]/g, ((post["imCartStateRegion_shipping"] != null) ? escape(x5engine.imCart._htmlOutput(post["imCartStateRegion_shipping"].imValue)) : "")); paymentHtml = paymentHtml.replace(/\[EX_COUNTRY\]/g, ((post["imCartCountry_shipping"] != null) ? escape(x5engine.imCart._htmlOutput(post["imCartCountry_shipping"].imValue)) : "")); paymentHtml = paymentHtml.replace(/\[EX_ZIP\]/g, ((post["imCartZipPostalCode_shipping"] != null) ? escape(x5engine.imCart._htmlOutput(post["imCartZipPostalCode_shipping"].imValue)) : "")); paymentHtml = paymentHtml.replace(/\[EX_EMAIL\]/g, ((post["imCartEmail_shipping"] != null) ? escape(x5engine.imCart._htmlOutput(post["imCartEmail_shipping"].imValue)) : "")); } else if (post != null) { // Unescaped values paymentHtml = paymentHtml.replace(/\[FIRST_NAME\]/g, ((post["imCartName"] != null) ? x5engine.imCart._htmlOutput(post["imCartName"].imValue) : "")); paymentHtml = paymentHtml.replace(/\[LAST_NAME\]/g, ((post["imCartLastName"] != null) ? x5engine.imCart._htmlOutput(post["imCartLastName"].imValue) : "")); paymentHtml = paymentHtml.replace(/\[ADDRESS1\]/g, ((post["imCartAddress1"] != null) ? x5engine.imCart._htmlOutput(post["imCartAddress1"].imValue) : "")); paymentHtml = paymentHtml.replace(/\[ADDRESS2\]/g, ((post["imCartAddress2"] != null) ? x5engine.imCart._htmlOutput(post["imCartAddress2"].imValue) : "")); paymentHtml = paymentHtml.replace(/\[CITY\]/g, ((post["imCartCity"] != null) ? x5engine.imCart._htmlOutput(post["imCartCity"].imValue) : "")); paymentHtml = paymentHtml.replace(/\[STATE\]/g, ((post["imCartStateRegion"] != null) ? x5engine.imCart._htmlOutput(post["imCartStateRegion"].imValue) : "")); paymentHtml = paymentHtml.replace(/\[COUNTRY\]/g, ((post["imCartCountry"] != null) ? x5engine.imCart._htmlOutput(post["imCartCountry"].imValue) : "")); paymentHtml = paymentHtml.replace(/\[ZIP\]/g, ((post["imCartZipPostalCode"] != null) ? x5engine.imCart._htmlOutput(post["imCartZipPostalCode"].imValue) : "")); paymentHtml = paymentHtml.replace(/\[EMAIL\]/g, ((post["imCartEmail"] != null) ? x5engine.imCart._htmlOutput(post["imCartEmail"].imValue) : "")); // Escaped values paymentHtml = paymentHtml.replace(/\[EX_FIRST_NAME\]/g, ((post["imCartName"] != null) ? escape(x5engine.imCart._htmlOutput(post["imCartName"].imValue)) : "")); paymentHtml = paymentHtml.replace(/\[EX_LAST_NAME\]/g, ((post["imCartLastName"] != null) ? escape(x5engine.imCart._htmlOutput(post["imCartLastName"].imValue)) : "")); paymentHtml = paymentHtml.replace(/\[EX_ADDRESS1\]/g, ((post["imCartAddress1"] != null) ? escape(x5engine.imCart._htmlOutput(post["imCartAddress1"].imValue)) : "")); paymentHtml = paymentHtml.replace(/\[EX_ADDRESS2\]/g, ((post["imCartAddress2"] != null) ? escape(x5engine.imCart._htmlOutput(post["imCartAddress2"].imValue)) : "")); paymentHtml = paymentHtml.replace(/\[EX_CITY\]/g, ((post["imCartCity"] != null) ? escape(x5engine.imCart._htmlOutput(post["imCartCity"].imValue)) : "")); paymentHtml = paymentHtml.replace(/\[EX_STATE\]/g, ((post["imCartStateRegion"] != null) ? escape(x5engine.imCart._htmlOutput(post["imCartStateRegion"].imValue)) : "")); paymentHtml = paymentHtml.replace(/\[EX_COUNTRY\]/g, ((post["imCartCountry"] != null) ? escape(x5engine.imCart._htmlOutput(post["imCartCountry"].imValue)) : "")); paymentHtml = paymentHtml.replace(/\[EX_ZIP\]/g, ((post["imCartZipPostalCode"] != null) ? escape(x5engine.imCart._htmlOutput(post["imCartZipPostalCode"].imValue)) : "")); paymentHtml = paymentHtml.replace(/\[EX_EMAIL\]/g, ((post["imCartEmail"] != null) ? escape(x5engine.imCart._htmlOutput(post["imCartEmail"].imValue)) : "")); } return paymentHtml; }, _updateOption: function (id, old_option, new_option, quantity, obj) { x5engine.imCart.addProduct(id, 0, old_option, true, false); x5engine.imCart.addProduct(id, quantity, new_option); x5engine.imCart.showCart(_jq(obj).attr("id"), 1); }, cartPage: function () { var category = x5engine.utils.getParam("category"); if (category != null && category != "") x5engine.imCart.showCategory(x5engine.utils.getParam("category")); else x5engine.imCart.showCart(); }, // Save the current page and go to the cart gotoCart: function (in_cart) { if (typeof in_cart == "string") { _jq.imCookie("imShopPage", window.location.href, { path: '/' }); location.href = in_cart + "cart/index.html"; return true; } else { if (in_cart == null) in_cart = false; if (!in_cart) { _jq.imCookie("imShopPage", window.location.href, { path: '/' }); location.href = "cart/index.html"; } else { location.href = "index.html"; } } return false; }, gotoCategory: function (id) { _jq.imCookie("imShopPage", window.location.href); location.href = "cart/index.html?category=" + id; }, // Continue shopping button continueShopping: function () { var oldPage = _jq.imCookie("imShopPage", null, { path: '/' }); if (oldPage != null) { window.location.href = oldPage; } else window.location.href = x5engine.imCart.settings.continue_shopping_page; }, // Add a product quantity to the cart // If force is true, quantity overrides the actual quantity in the cart. If force is false the quantity is added to the existing one addProduct: function (id, quantity, option, force, message) { if (message === null || message === undefined) message = true; if (quantity === null || quantity === undefined) quantity = 1; if (force === null || force === undefined) force = false; if (option === null || option === undefined) option = "null"; if (x5engine.imCart.products[id].min_quantity !== null && x5engine.imCart.products[id].min_quantity !== undefined && quantity < x5engine.imCart.products[id].min_quantity && quantity !== 0) { alert((x5engine.l10n.getLocalization("cart_err_quantity")).replace("[QUANTITY]", x5engine.imCart.products[id].min_quantity)); return false; } var products = x5engine.imCart._getCart(); if ((products === null || products === undefined) && quantity > 0) { x5engine.imCart._setCart([{ "id": id, "quantity": quantity, "option": escape(option) }]); } else { var found = false; for (var i = 0; i < products.length; i++) { if (products[i].id == id && unescape(products[i].option) == unescape(option)) { found = true; if (!force) products[i].quantity = products[i].quantity * 1 + quantity * 1; else { if (quantity > 0) products[i].quantity = quantity * 1; else if (message && confirm(x5engine.l10n.getLocalization("cart_remove_q"))) products[i] = null; else if (!message) products[i] = null; } } } if (!found && quantity > 0) products[products.length] = { "id": id, "quantity": quantity, "option": escape(option) }; x5engine.imCart._setCart(products); } }, // Add a product to the cart addToCart: function (id, quantity, in_cart, option) { var product = x5engine.imCart.products[id]; if (quantity == null) quantity = _jq("#" + x5engine.imCart.costants.QUANT_FIELD_NAME.replace("{id}", id)).val(); if (quantity == null) quantity = 1; if (option == null) { if (_jq("#" + x5engine.imCart.costants.OPT_FIELD_NAME.replace("{id}", id)).length > 0) option = _jq("#" + x5engine.imCart.costants.OPT_FIELD_NAME.replace("{id}", id)).val(); else option = "null"; } if (in_cart == null) in_cart = false; if (/^[0-9]+$/.test(quantity) == false) { alert(x5engine.l10n.getLocalization("cart_err_qty")); return false; } x5engine.imCart.addProduct(id, quantity, option); x5engine.imCart.updateWidget(); x5engine.imCart.gotoCart(in_cart); }, // Remove a product from the cart removeFromCart: function (id, option, obj) { x5engine.imCart.addProduct(id, 0, option, true); x5engine.imCart.updateWidget(); x5engine.imCart.showCart(obj, 1); }, // Update the quantity of a product in the cart updateCart: function (id, obj, updateScreen, option) { if (updateScreen == null) updateScreen = false; var quantity = _jq(obj).val(); if (/^[0-9]+$/.test(quantity) == false) { alert(x5engine.l10n.getLocalization("cart_err_qty")); return false; } var products = x5engine.imCart._getCart(); if ( !option ) option = "null"; else option = $("#" + option).val(); var total_quantity = 0; var total_weight = 0; for (var i = 0; i < products.length; i++) { if (products[i].id == id && (products[i].option == "null" || unescape(products[i].option) == unescape(option))) { option = products[i].option; total_weight += x5engine.imCart.products[id].weight * quantity; total_quantity += quantity; } else { total_weight += x5engine.imCart.products[id].weight * products[i].quantity; total_quantity += products[i].quantity; } } x5engine.imCart.addProduct(id, quantity, option, true); x5engine.imCart.updateWidget(); if (updateScreen) x5engine.imCart.showCart(null, 1); x5engine.imCart.updateTotalPrice(total_quantity, total_weight); }, // Update the widget updateWidget: function () { var products = x5engine.imCart._getCart(); var sum = 0; var total_vat = 0; var total = 0; _jq(".widget_quantity_total").each(function () { if (products != null) { for (var i = 0; i < products.length; i++) { if (x5engine.imCart.products[products[i].id] != null) sum += products[i].quantity; } } _jq(this).html(sum); }); _jq(".widget_amount_total").each(function () { if (products != null) { for (var i = 0; i < products.length; i++) { var id = products[i].id; if (x5engine.imCart.products[id] != null) { var quantity = products[i].quantity; var option = products[i].option; var discounts = x5engine.imCart.products[id].discounts; var weight = x5engine.imCart.products[id].weight; if (weight == null) weight = 0; var discount = 0; var subtot = 0; var vat; if (x5engine.imCart.products[id].vat != null) vat = x5engine.imCart.products[id].vat; else if (x5engine.imCart.settings.vat != null) vat = x5engine.imCart.settings.vat; else vat = 0; if (discounts != null) discount = x5engine.imCart._getValueFromKey(quantity, discounts); subtot = quantity * x5engine.imCart.products[id].price; subtot -= (subtot * discount); total_vat += subtot + subtot * vat; } } sum = total_vat; } _jq(this).html(x5engine.imCart._setCurrency(sum)); }); }, // Empty the cart emptyCart: function (getConfirmation) { if (getConfirmation == null) getConfirmation = true; if (getConfirmation == true) { if (confirm(x5engine.l10n.getLocalization("cart_empty"))) x5engine.imCart._realEmptyCart(); } else x5engine.imCart._realEmptyCart(); return false; }, // Show a category showCategory: function (id, obj) { obj = obj || "#imCartContainer"; _jq(obj).empty().prepend("

" + x5engine.l10n.getLocalization('cart_step1') + "

\n
 
" + x5engine.l10n.getLocalization('cart_step1_descr') + "


"); var html = ""; html += ""; html += ""; html += ""; if (!x5engine.imCart.settings.vatincluded) html += ""; html += ""; html += ""; var str_eval = ""; for (var pid in x5engine.imCart.products) { var product = x5engine.imCart.products[pid]; if (product.category == id) { html += ""; html += ""; html += ""; if (!x5engine.imCart.settings.vatincluded) html += ""; html += ""; str_eval += "_jq('#buy_" + pid + "').unbind('click').click(function () { x5engine.imCart.addToCart('" + pid + "', null, true); });"; html += ""; } } html += "
" + x5engine.l10n.getLocalization("cart_descr") + "" + x5engine.l10n.getLocalization("cart_opt") + "" + x5engine.l10n.getLocalization("cart_price") + "" + x5engine.l10n.getLocalization("cart_vat") + "" + x5engine.l10n.getLocalization("cart_qty") + "
" + product.name + "
" + product.description + "
"; if (product.options != null && product.options.length > 0) { html += ""; } html += "" + x5engine.imCart._setCurrency(product.price) + "" + ((product.vat != null && product.vat > 0) ? (product.vat * 100).toFixed(2) + "%" : " - ") + ""; html += "\""
"; html += "
"; html += ""; html += ""; html += "
"; _jq(obj).append(html); eval(str_eval); _jq("#imCartButtonBack").unbind("click").click(x5engine.imCart.continueShopping); _jq("#imCartButtonNext").unbind("click").click(function () { x5engine.imCart.showCart(); }); _jq("#imContent").triggerHandler("change"); }, // Show the cart showCart: function (obj, time) { var email_data = {}; var str_eval = ""; _jq(".imTip").fadeOut(100, function () { _jq(".imTip").remove(); }); obj = obj || "#imCartContainer"; obj = _jq(obj); if (time == null) time = 100; var products = x5engine.imCart._getCart(); var filtered_products = new Array(); // Filter the products (if the cookie contains products not in the cart anymore) for (var i = 0; i < products.length; i++) { if (x5engine.imCart.products[products[i].id] != null) filtered_products[filtered_products.length] = products[i]; } products = filtered_products; if (products != null && products.length > 0) { obj.fadeOut(time, function () { obj.empty().prepend("

" + x5engine.l10n.getLocalization('cart_step2') + "

\n"); var html = "

" + x5engine.l10n.getLocalization('cart_step2_cartlist') + "

"; // Products html += ""; html += ""; html += ""; html += ""; html += ""; html += ""; if (!x5engine.imCart.settings.vatincluded) html += ""; html += ""; var total = 0; var total_vat = 0; var grand_vat = 0; var shipping_total = 0; var shipping_total_vat = 0; var total_quantity = 0; var total_weight = 0; for (var i = 0; i < products.length; i++) { var id = products[i].id; var quantity = products[i].quantity; var option = products[i].option; var discounts = x5engine.imCart.products[id].discounts; var weight = x5engine.imCart.products[id].weight; if (weight == null) weight = 0; var discount = 0; var subtot = 0; var vat; if (x5engine.imCart.products[id].vat != null) vat = x5engine.imCart.products[id].vat; else if (x5engine.imCart.settings.vat != null) vat = x5engine.imCart.settings.vat; else vat = 0; if (discounts != null) discount = x5engine.imCart._getValueFromKey(quantity, discounts); total_weight += weight * quantity; total_quantity += quantity; subtot = quantity * x5engine.imCart.products[id].price; subtot -= (subtot * discount); total += subtot; grand_vat += subtot * vat; total_vat += subtot + subtot * vat; var cart_p = x5engine.imCart.products[id]; email_data[id + "_" + option] = { id_user: cart_p.id_user, name: cart_p.name, description: cart_p.description, single_price: x5engine.imCart._setCurrency(x5engine.imCart.products[id].price - x5engine.imCart.products[id].price * discount), price: x5engine.imCart._setCurrency(subtot), price_vat: x5engine.imCart._setCurrency(subtot + subtot * vat), clean_vat: subtot * vat, option: option, quantity: quantity, vat: vat, vat_f: x5engine.imCart._setCurrency(vat * (x5engine.imCart.products[id].price - x5engine.imCart.products[id].price * discount)) }; html += ""; html += ""; html += ""; html += ""; str_eval += "_jq('#qty_product_" + i + "').unbind('change').change(function () {x5engine.imCart.updateCart('" + id + "', this, true, '" + freeid + "');});"; html += ""; if (!x5engine.imCart.settings.vatincluded) html += ""; html += ""; str_eval += "_jq('#remove_product_" + i + "').click(function () { return x5engine.imCart.removeFromCart('" + id + "', '" + option + "', '#" + _jq(obj).attr('id') + "'); });"; } x5engine.imCart = _jq.extend(x5engine.imCart, { 'product_price_plus_vat': total_vat, 'product_price_no_vat': total, 'product_vat': grand_vat }); if (x5engine.imCart.email_data == null) x5engine.imCart.email_data = {}; x5engine.imCart.email_data.products = email_data; html += "" + (x5engine.imCart.settings.vatincluded ? '' : '') + ""; if (!x5engine.imCart.settings.vatincluded) { html += ""; //html += ""; } html += "
" + x5engine.l10n.getLocalization("cart_descr") + "" + x5engine.l10n.getLocalization("cart_opt") + "" + x5engine.l10n.getLocalization("cart_price") + "" + x5engine.l10n.getLocalization("cart_qty") + "" + x5engine.l10n.getLocalization("cart_subtot") + "" + x5engine.l10n.getLocalization("cart_vat") + "
" + x5engine.imCart.products[id].id_user + (x5engine.imCart.products[id].description != "" ? " - " + x5engine.imCart.products[id].description : "") + ""; var freeid = "product_" + id + "_" + x5engine.utils.imHash(option) + "_opt"; if (option != "null") { html += ""; } html += "" + x5engine.imCart._setCurrency(x5engine.imCart.products[id].price - x5engine.imCart.products[id].price * discount) + "" + x5engine.imCart._setCurrency(subtot) + "" + ((vat) ? x5engine.imCart._setCurrency(subtot * vat) + " (" + (vat * 100).toFixed(2) + "%)" : "-") + "\""
" + x5engine.l10n.getLocalization("cart_total") + "" + x5engine.imCart._setCurrency(total) + "
" + x5engine.l10n.getLocalization("cart_vat") + "" + x5engine.imCart._setCurrency(grand_vat) + "
" + x5engine.l10n.getLocalization("cart_total_vat") + "" + x5engine.imCart._setCurrency(total_vat) + "
"; html += ""; // Payment html += "

" + x5engine.l10n.getLocalization('cart_step2_shiplist') + "

"; html += ""; var payments = x5engine.imCart.payments; for (var i = 0; i < payments.length; i++) { var price = payments[i].price || 0; if (payments[i].vat != null) price += price * payments[i].vat; html += ""; str_eval += "_jq('#cart_payment_" + i + "').unbind('click').click(function () { x5engine.imCart.updatePayment(" + i + ", " + total_quantity + ", " + total_weight + ")});"; if (x5engine.imCart._getPayment() == i) { total_vat += price; x5engine.imCart.updatePayment(i, total_quantity, total_weight); } } html += "
" + x5engine.l10n.getLocalization('cart_payment') + "" + x5engine.l10n.getLocalization("cart_price") + "
" + ((price > 0) ? x5engine.imCart._setCurrency(price) : "-") + "
"; // Shipping html += "
"; html += ""; var shippings = x5engine.imCart.shippings; for (var i = 0; i < shippings.length; i++) { var price = x5engine.imCart._getShippingPrice(shippings[i], x5engine.imCart.product_price_plus_vat, total_quantity, total_weight); html += ""; str_eval += "_jq('#cart_shipping_" + i + "').unbind('click').click(function () {x5engine.imCart.updateShipping(" + i + ", " + total_quantity + ", " + total_weight + ");});"; if (x5engine.imCart._getShipping() == i) { total_vat += price; x5engine.imCart.updateShipping(i, total_quantity, total_weight); } } html += "
" + x5engine.l10n.getLocalization('cart_shipping') + "" + x5engine.l10n.getLocalization("cart_price") + "
" + ((price > 0) ? x5engine.imCart._setCurrency(price) : "-") + "

"; // Price summary html += "
" + x5engine.l10n.getLocalization('cart_total_vat') + ": " + x5engine.imCart._setCurrency(total_vat) + "
"; // Currency conversion disable if (x5engine.utils.isOnline() && false) { var currencies = x5engine.imCart.settings.currencies; if (currencies != null && currencies.length > 0) { html += "
Risultato conversione
"; } } html += "


"; html += "
"; html += ""; html += ""; html += ""; html += "
"; obj.append(html).fadeIn(time, function () { _jq("#imContent").triggerHandler("change"); }); _jq("#imCartButtonBack").unbind("click").click(x5engine.imCart.continueShopping); _jq("#imCartButtonEmpty").unbind("click").click(function () { x5engine.imCart.emptyCart(true); }); _jq("#imCartButtonNext").unbind("click").click(function () { x5engine.imCart.showForm('#' + _jq(obj).attr("id")); }); eval(str_eval); _jq("#imInputTotalPrice").val(total_vat); }); } else { obj.fadeOut(time, function () { obj.empty().prepend("

" + x5engine.l10n.getLocalization('cart_step2') + "

\n
 

"); obj.append("
" + x5engine.l10n.getLocalization("cart_err_emptycart") + "


"); obj.append("
"); _jq("#imCartButtonBack").unbind("click").click(x5engine.imCart.continueShopping); obj.fadeIn(time); }); } return false; }, // Convert currency using Google currencyConversion: function (obj) { if (obj.selectedIndex != 0) { if (x5engine.imCart.email_data.clear_total != null) { _jq.ajax({ url: x5engine.imCart.settings.post_url + "?action=currency&amount=" + x5engine.imCart.email_data.clear_total + "&from=" + x5engine.imCart.settings.currency_id + "&to=" + _jq(obj).val(), type: "GET", dataType: "json", success: function (data) { _jq("#currencyConvResult").html(x5engine.imCart._setCurrency(data.value, x5engine.imCart.settings.currency_format, _jq(obj).val())); }, error: function () { _jq("#currencyConvResult").html(x5engine.l10n.getLocalization("cart_err_currency_conversion")); } }); } else { obj.selectedIndex = 0; } } else { _jq("#currencyConvResult").empty(); } }, // Show the user data form showForm: function (obj) { if (x5engine.imCart._getPayment() == null) { alert(x5engine.l10n.getLocalization("cart_err_payment")); return false; } if (x5engine.imCart._getShipping() == null) { alert(x5engine.l10n.getLocalization("cart_err_shipping")); return false; } if (x5engine.imCart.settings.minimum_amount > 0 && _jq("#imInputTotalPrice").val() * 1 < x5engine.imCart.settings.minimum_amount) { alert(x5engine.l10n.getLocalization('cart_err_minimum_price').replace(/\[PRICE\]/g, x5engine.imCart._setCurrency(x5engine.imCart.settings.minimum_amount))); return false; } obj = obj || "#imCartContainer"; obj = _jq(obj); obj.fadeOut(100, function () { obj.empty().prepend("

" + x5engine.l10n.getLocalization('cart_step3') + "

\n"); var html = "

" + x5engine.l10n.getLocalization('cart_step3_descr') + "

"; html += "
" + x5engine.imCart.html_form + "
"; html += "
"; html += ""; html += ""; html += "
"; obj.append(html).fadeIn(100, function () { _jq("#imContent").triggerHandler("change"); }); _jq("#imCartButtonBack").unbind("click").click(function () { x5engine.imCart.saveForm(obj); x5engine.imCart.showCart('#' + obj.attr("id")); }); _jq("#imCartUserFormSubmit").unbind("click").click(function () { x5engine.imCart.showOrderSummary('#' + obj.attr("id")); }); if (x5engine.imCart.settings.form_autocomplete) { var json = x5engine.imCart._getFormData(); if (json != null) for (var i = 0; i < json.length; i++) _jq("#" + json[i].id).val(json[i].val); } }); }, saveForm: function (obj) { var fields = _jq("#imCartUserDataForm"); var post = {}; var form = []; _jq(fields).find(":input").each(function () { if (_jq(this).attr("id") != null && _jq(this).attr("id") != "" && !_jq(this).is("label") && _jq(this).attr("type") != "submit" && _jq(this).attr("type") != "button" && _jq(this).attr("type") != "reset") { var fieldName = _jq("label[for=" + _jq(this).attr("id") + "] span").html(); try { if (fieldName.charAt(fieldName.length - 1) == ":") fieldName = fieldName.substr(0, fieldName.length - 1); post[_jq(this).attr("id")] = { name: fieldName, imValue: (_jq(this).is(":checkbox") ? (_jq(this).prop("checked") ? "yes" : "no") : x5engine.imCart._htmlOutput(_jq(this).val())) }; form[form.length] = { "id": _jq(this).attr("id"), "val": (_jq(this).is(":checkbox") ? (_jq(this).prop("checked") ? "yes" : "no") : x5engine.imCart._htmlOutput(_jq(this).val())) }; } catch (e) {} } }); if (x5engine.imCart.settings.form_autocomplete) x5engine.imCart._setFormData(form); x5engine.imCart.email_data.form = post; }, // Show the order summary showOrderSummary: function (obj) { obj = obj || "#imCartContainer"; obj = _jq(obj); if (x5engine.imForm.validate("#imCartUserDataForm", { type: x5engine.imCart.settings.form_validation, showAll: true, position: "right" })) { obj.fadeOut(100, function () { var post; x5engine.imCart.saveForm(obj); post = x5engine.imCart.email_data.form; obj.empty().prepend("

" + x5engine.l10n.getLocalization('cart_step4') + "

\n"); /* |-------------- | Summary |-------------- */ // Products var html = "

" + x5engine.l10n.getLocalization('cart_step4_descr') + "

"; html += ""; html += ""; html += ""; html += ""; if (!x5engine.imCart.settings.vatincluded) html += ""; html += ""; html += ""; var data = x5engine.imCart.email_data; for (var product in data.products) { html += ""; html += ""; if (!x5engine.imCart.settings.vatincluded) html += ""; html += ""; html += ""; } html += ""; // Payment var payment = x5engine.imCart.payments[x5engine.imCart._getPayment()]; // Separator html += "" html += ""; html += ""; if (!x5engine.imCart.settings.vatincluded) html += ""; html += ""; html += ""; html += ""; html += ""; if (!x5engine.imCart.settings.vatincluded) { html += ""; html += ""; } else { html += ""; } html += ""; // Shipping var shipping = x5engine.imCart.shippings[x5engine.imCart._getShipping()]; var shipping_price = x5engine.imCart._getShippingPrice(shipping, x5engine.imCart.product_price_plus_vat, x5engine.imCart.email_data.total_quantity, x5engine.imCart.email_data.total_weight, false) * 1; // Separator html += "" html += ""; html += ""; if (!x5engine.imCart.settings.vatincluded) html += ""; if (x5engine.imCart.email_data.shipping.price != null) html += ""; html += ""; html += ""; if (!x5engine.imCart.settings.vatincluded) { html += ""; html += ""; } else { html += ""; } html += ""; // Separator html += "" // Total if (!x5engine.imCart.settings.vatincluded) html += ""; html += ""; html += "
" + x5engine.l10n.getLocalization("cart_descr") + "" + x5engine.l10n.getLocalization("cart_qty") + (x5engine.l10n.getLocalization("cart_single_price") != "" ? " x " + x5engine.l10n.getLocalization("cart_single_price") : "") + "" + x5engine.l10n.getLocalization("cart_vat") + "" + x5engine.l10n.getLocalization("cart_price") + "
" + data.products[product].name + ((data.products[product].option != "null") ? " - " + x5engine.imCart._restoreSpecialChars(unescape(data.products[product].option)) : "") + (data.products[product].description != "" ? "

" + data.products[product].description + "

" : "") + "
" + data.products[product].quantity + " x " + data.products[product].single_price + "" + ((data.products[product].vat != null && data.products[product].vat > 0) ? (x5engine.imCart._setCurrency(data.products[product].clean_vat) + " (" + (data.products[product].vat * 100).toFixed(2) + "%)") : "-") + "" + data.products[product].price + "
" + x5engine.l10n.getLocalization('cart_subtot') + "" + x5engine.imCart._setCurrency(x5engine.imCart.product_price_no_vat) + "
" + x5engine.l10n.getLocalization("cart_payment") + "" + x5engine.l10n.getLocalization("cart_vat") + "" + x5engine.l10n.getLocalization("cart_price") + "
" + payment.name + "

" + payment.description + "

" + (x5engine.imCart.email_data.payment.price != null ? x5engine.imCart._setCurrency(payment.price * payment.vat) + " (" + (payment.vat * 100).toFixed(2) + "%)" : "-") + "" + (x5engine.imCart.email_data.payment.price != null ? x5engine.imCart._setCurrency(payment.price) : "-") + "" + (x5engine.imCart.email_data.payment.price != null ? x5engine.imCart.email_data.payment.price : "-") + "
" + x5engine.l10n.getLocalization("cart_shipping") + "" + x5engine.l10n.getLocalization("cart_vat") + "" + x5engine.l10n.getLocalization("cart_price") + "
" + shipping.name + "
" + shipping.description; html += "

" + x5engine.l10n.getLocalization("cart_shipping_address") + ":

"; if (post["imCartName_shipping"] != null) { html += ((post["imCartCompany_shipping"] != null && post["imCartCompany_shipping"] != "") ? post["imCartCompany_shipping"].imValue + " - " : ""); html += ((post["imCartName_shipping"] != null) ? post["imCartName_shipping"].imValue + " " : ""); html += ((post["imCartLastName_shipping"] != null) ? post["imCartLastName_shipping"].imValue : ""); html += " " + ((post["imCartEmail_shipping"] != null) ? ("(" + post["imCartEmail_shipping"].imValue + ")") : "") + "
"; html += ((post["imCartAddress1_shipping"] != null) ? (post["imCartAddress1_shipping"].imValue + "
") : ""); html += ((post["imCartAddress2_shipping"] != null) ? (post["imCartAddress2_shipping"].imValue + "
") : ""); html += ((post["imCartCity_shipping"] != null) ? (post["imCartCity_shipping"].imValue) : ""); html += ((post["imCartStateRegion_shipping"] != null) ? (" (" + post["imCartStateRegion_shipping"].imValue + ")") : ""); html += ((post["imCartZipPostalCode_shipping"] != null) ? (", " + post["imCartZipPostalCode_shipping"].imValue + "
") : ""); html += ((post["imCartCountry_shipping"] != null) ? (post["imCartCountry_shipping"].imValue + "
") : ""); html += ((post["imCartPhone_shipping"] != null) ? (post["imCartPhone_shipping"].imValue + "
") : ""); } else if (post["imCartName"] != null) { html += ((post["imCartCompany"] != null && post["imCartCompany"] != "") ? post["imCartCompany"].imValue + " - " : ""); html += ((post["imCartName"] != null) ? post["imCartName"].imValue + " " : ""); html += ((post["imCartLastName"] != null) ? post["imCartLastName"].imValue : ""); html += " " + ((post["imCartEmail"] != null) ? ("(" + post["imCartEmail"].imValue + ")") : "") + "
"; html += ((post["imCartAddress1"] != null) ? (post["imCartAddress1"].imValue + "
") : ""); html += ((post["imCartAddress2"] != null) ? (post["imCartAddress2"].imValue + "
") : ""); html += ((post["imCartCity"] != null) ? (post["imCartCity"].imValue) : ""); html += ((post["imCartStateRegion"] != null) ? (" (" + post["imCartStateRegion"].imValue + ")") : ""); html += ((post["imCartZipPostalCode"] != null) ? (", " + post["imCartZipPostalCode"].imValue + "
") : ""); html += ((post["imCartCountry"] != null) ? (post["imCartCountry"].imValue + "
") : ""); html += ((post["imCartPhone"] != null) ? (post["imCartPhone"].imValue + "
") : ""); } html += "
" + (x5engine.imCart.email_data.shipping.price != null ? x5engine.imCart._setCurrency(shipping_price * shipping.vat) + " (" + (shipping.vat * 100).toFixed(2) + "%)" : "-") + "" + (x5engine.imCart.email_data.shipping.price != null ? x5engine.imCart._setCurrency(shipping_price) : "-") + "" + (x5engine.imCart.email_data.shipping.price != null ? x5engine.imCart.email_data.shipping.price : "-") + "
" + x5engine.l10n.getLocalization("cart_vat") + "" + x5engine.imCart._setCurrency(x5engine.imCart.product_vat + payment.price * payment.vat + shipping_price * shipping.vat) + "
" + x5engine.l10n.getLocalization('cart_total_vat') + "" + x5engine.imCart.email_data.total + "
"; // Next/Previous button html += "


"; html += "
"; html += ""; html += ""; obj.append(html).fadeIn(100, function () { _jq("#imContent").triggerHandler("change"); }); _jq("#imCartButtonBack").unbind("click").click(function () { x5engine.imCart.showForm('#' + obj.attr("id")); }); _jq("#imCartUserFormSubmit").unbind("click").click(function () { x5engine.imCart.sendOrderEmail('#' + obj.attr("id")); }); }); } else _jq("#imCartUserFormSubmit").attr("disabled", false); }, // Send the email and shows the payment sendOrderEmail: function (obj) { _jq("#imCartUserFormSubmit").attr("disabled", true); if (x5engine.imCart.email_data.order_no == null || x5engine.imCart.email_data.order_no == "") x5engine.imCart.email_data.order_no = x5engine.imCart._createOrderNo(); var pid = x5engine.imCart._getPayment(); if (x5engine.imCart.payments[pid].html != null) x5engine.imCart.email_data.payment.html = x5engine.imCart._createPaymentHtml(x5engine.imCart.payments[pid].html); if (x5engine.utils.isOnline()) { _jq("#imCartUserFormSubmit").val(x5engine.l10n.getLocalization('cart_order_process')).css({ cursor: "wait" }); _jq("#imCartButtonBack").remove(); _jq.ajax({ type: "POST", url: x5engine.imCart.settings.post_url, data: x5engine.imCart.email_data, success: function (a) { x5engine.imCart.showPayment(obj); }, error: function (XMLHttpRequest, textStatus, errorThrown) { x5engine.imCart.showPayment(obj); } }); } else { x5engine.utils.showOfflineMessage(x5engine.l10n.getLocalization('cart_err_offline_email').replace(/\[MAIL\]/g, x5engine.imCart.email_data.form.imCartEmail.imValue)); x5engine.imCart.showPayment(obj); } }, // Shows the payment method showPayment: function (obj) { var payment = x5engine.imCart.payments[x5engine.imCart._getPayment()]; _jq(obj).empty().prepend("

" + x5engine.l10n.getLocalization('cart_step5') + "

"); var html = "

" + x5engine.l10n.getLocalization('cart_step5_descr') + "

"; html += "
" + x5engine.imCart.email_data.order_no + "
"; html += "

" + payment.name + "
" + payment.description + "

"; html += payment.email + "

"; if (payment.html != null) { html += "

" + x5engine.imCart._createPaymentHtml(payment.html) + "
"; } _jq(obj).fadeOut(100, function () { _jq(obj).append(html).fadeIn(100, function () { x5engine.imCart.emptyCart(false); x5engine.imCart.email_data = null; x5engine.imCart._setShipping(null); x5engine.imCart._setPayment(null); _jq("#imContent").triggerHandler("change"); }); }); }, // Update the shipping type and price updateShipping: function (n, total_quantity, total_weight) { x5engine.imCart._setShipping(n); x5engine.imCart.updateTotalPrice(total_quantity, total_weight); }, // Update the payment type and the price updatePayment: function (n, total_quantity, total_weight) { x5engine.imCart._setPayment(n); x5engine.imCart.updateTotalPrice(total_quantity, total_weight); }, // Update the total price updateTotalPrice: function (total_quantity, total_weight) { var price = x5engine.imCart.product_price_plus_vat; var pid; var sid; var shipping_price = 0; var payment_price = 0; x5engine.imCart.email_data.total_quantity = total_quantity; x5engine.imCart.email_data.total_weight = total_weight; if (x5engine.imCart._getShipping() != null) { sid = x5engine.imCart._getShipping(); shipping_price += x5engine.imCart._getShippingPrice(x5engine.imCart.shippings[sid], x5engine.imCart.product_price_plus_vat, total_quantity, total_weight) * 1; x5engine.imCart.email_data.shipping = { id: sid, price: x5engine.imCart._setCurrency(shipping_price), name: x5engine.imCart.shippings[sid].name, description: x5engine.imCart.shippings[sid].description, email: x5engine.imCart.shippings[sid].email }; if (shipping_price == 0) { x5engine.imCart.email_data.shipping.price = null; } } if (x5engine.imCart._getPayment() != null) { pid = x5engine.imCart._getPayment(); if (x5engine.imCart.payments[pid].price != null) { payment_price += x5engine.imCart.payments[pid].price; if (x5engine.imCart.payments[pid].vat != null) payment_price += x5engine.imCart.payments[pid].price * x5engine.imCart.payments[pid].vat; } x5engine.imCart.email_data.payment = { id: pid, price: x5engine.imCart._setCurrency(payment_price), name: x5engine.imCart.payments[pid].name, description: x5engine.imCart.payments[pid].description, email: x5engine.imCart.payments[pid].email }; if (x5engine.imCart.payments[pid].html != null) x5engine.imCart.email_data.payment.html = x5engine.imCart._createPaymentHtml(x5engine.imCart.payments[pid].html); if (payment_price == 0) { x5engine.imCart.email_data.payment.price = null; } } price += shipping_price + payment_price; x5engine.imCart.email_data.total = x5engine.imCart._setCurrency(price); x5engine.imCart.email_data.clear_total = price; _jq("#imDivTotalPrice").html(x5engine.imCart._setCurrency(price)); x5engine.imCart.total_price = price; } });