Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
2.0 kB
6
Indexable
Never
function fetchCustomerData() {
		var custFill = false;
		if (sessionStorage.getItem("woaCust")) {
			var data = JSON.parse(sessionStorage.getItem("woaCust"));
			if (data.phone == "<?= $phone ?>") {
				$("#checkoutPhone").val(data.phone);
				$("#checkoutName").val(data.name);
				$("#checkoutAddress").text(data.address);
				custFill = true;
			} else {
				sessionStorage.removeItem("woaCust");
			}
		}

		if (!custFill) {
			var sid = "<?= $store->id ?>";
			$.post(_apiUrl + '/v1/customer/data', {
				lang: _langCode,
				sid: sid,
				phone: "<?= $phone ?>"
			}, function(response) {
				if (response.success == 1) {
					var data = response.data;
					$("#checkoutPhone").val(data.phone);
					$("#checkoutName").val(data.name);
					$("#checkoutAddress").text(data.address);
				} else {
					$("#message").html(response.message);
				}
			}, "json");
		}

		_subTotal = sessionStorage.getItem("woaCartTotalAmount");
		_voucher = sessionStorage.getItem("woaCartTotalVoucher");
		_totalWeight = sessionStorage.getItem("woaCartTotalWeight");
		var dataCart = [];

		if (_subTotal == 0) {
			$("#tab-2, #tab-3").find(".payment-list").addClass("hidden");
		}
		// for(i=0;i<woaCart.length;i++){
		// 	row = woaCart[i];
		// 	var item = {pid:row.pid,qty:row.qty,note:row.note};
		// 	dataCart.push(item);
		// 	_subTotal += row.qty * row.price;
		// 	_totalWeight = _totalWeight + (row.weight * parseFloat(row.qty));
		// }
		$(".checkoutCart").text(JSON.stringify(dataCart));
		$(".checkoutLang").val(_langCode);
		$(".checkoutTotal").html(currency(_subTotal));
		$(".checkoutWeight").val(_totalWeight);

		var grandTotal = parseInt(_subTotal); // - parseInt(_voucher);
		// var totalVoucher = parseInt(_voucher);
		// if(grandTotal < 0){
		// 	grandTotal = 0;
		// 	totalVoucher = parseInt(_subTotal);
		// }

		// $(".voucher .value").html(currency(""+totalVoucher));
		$(".checkoutGrandTotal .value").html(currency("" + grandTotal));
	}