Software: Apache/2.4.41 (Ubuntu). PHP/8.0.30 uname -a: Linux apirnd 5.4.0-204-generic #224-Ubuntu SMP Thu Dec 5 13:38:28 UTC 2024 x86_64 uid=33(www-data) gid=33(www-data) groups=33(www-data) Safe-mode: OFF (not secure) /var/www/html/checkout/js/ drwxr-xr-x | |
| Viewing file: Select action/file-type:
$(".shopping-cart-footer").on('click','a#checkout_a', function(e) {
var c=0;
for (let i = 0; i < cart_products.length; i++) {
if (cart_products[i].quantity!==0) {
c+=cart_products[i].quantity;
}
}
if (cart_products.length==0 || c==0) {
swal("","Shopping cart is empty. Please add item and visit the page again", "info");
}else{
$('#th2').click();
}
});
// increments quantity
$('#tdata').on('click','a.qty-plus', function(e) {
e.preventDefault();
// var cart_id= $(this).parent().parent().parent().find("#cart_id").text();
// var cart_quan=cart_products.filter(function(item){
// return item.cart_id == cart_id;
// });
var $this = $(this);
var $input = $this.closest('div').find('#quantity');
var value = parseInt($input.val());
var cart_id= $(this).parent().parent().parent().find("#cart_id").text();
var check=checkInventory(cart_id,value+1);
if (check=="true") {
var unit_price=$(this).parent().parent().parent().find('#product_info').find('#unit_price');
var product_total=$(this).parent().parent().parent().find("#action").find("#p_total");
var total_info=$(this).parent().parent().parent().find("#action").find("#total_info");
var remove_cart=$(this).parent().parent().parent().find("#action").find("#remove_cart");
unit_value=parseInt(unit_price.text());
temp_total=total-parseInt(product_total.text());
if (value < 100) {
value = value + 1;
} else {
value =100;
}
total_info.show();
remove_cart.hide();
$input.val(value);
cart_products.filter(function(item){
if (item.cart_id == cart_id) {
item.quantity=value;
}
});
product_total.text(value*unit_value);
total=temp_total+value*unit_value;
$("#total_without_shipping").text("৳"+total);
}
});
// decrement quantity
$('#tdata').on('click','a.qty-minus', function(e) {
e.preventDefault();
var $this = $(this);
var $input = $this.closest('div').find('#quantity');
var value = parseInt($input.val());
var unit_price=$(this).parent().parent().parent().find('#product_info').find('#unit_price');
var product_total=$(this).parent().parent().parent().find("#action").find("#p_total");
var total_info=$(this).parent().parent().parent().find("#action").find("#total_info");
var remove_cart=$(this).parent().parent().parent().find("#action").find("#remove_cart");
unit_value=parseInt(unit_price.text());
temp_total=total-parseInt(product_total.text());
total_info.show();
remove_cart.hide();
if (value > 1) {
value = value - 1;
} else {
value = 0;
total_info.hide();
remove_cart.css("margin-top", "10px");
remove_cart.show();
}
$input.val(value);
var cart_id= $(this).parent().parent().parent().find("#cart_id").text();
cart_products.filter(function(item){
if (item.cart_id == cart_id) {
item.quantity=value;
}
});
product_total.text(value*unit_value);
total=temp_total+value*unit_value;
$("#total_without_shipping").text("৳"+total);
});
// edit quantity
$("#tdata").on("keyup",".quantity",function(e){
e.preventDefault();
var cart_id= $(this).parent().parent().parent().find("#cart_id").text();
var $this = $(this);
var $input = $this.closest('div').find('#quantity');
var ln=$input.val().length;
var value = parseInt($input.val());
var check=checkInventory(cart_id,value);
if (check=="true") {
var total_info=$(this).parent().parent().parent().find("#action").find("#total_info");
var remove_cart=$(this).parent().parent().parent().find("#action").find("#remove_cart");
total_info.show();
remove_cart.hide();
if (ln== 0 || value<1) {
value=0;
total_info.hide();
remove_cart.css("margin-top", "10px");
remove_cart.show();
$input.val(value);
}
if (value>100) {
value=100;
$input.val(value);
}
cart_products.filter(function(item){
if (item.cart_id == cart_id) {
// console.log("match");
item.quantity=value;
}
});
var unit_price=$(this).parent().parent().parent().find('#product_info').find('#unit_price');
var product_total=$(this).parent().parent().parent().find("#action").find("#p_total");
temp_total=total-parseInt(product_total.text());
unit_value=parseInt(unit_price.text());
product_total.text(value*unit_value);
total=temp_total+value*unit_value;
$("#total_without_shipping").text("৳"+total);
}
});
// check inventory
function checkInventory(cart_id,value) {
var status;
cart_products.filter(function(item){
// console.log(item);
if (item.cart_id == cart_id) {
if (item.inventory<value && item.inventory_check==1) {
status="false";
// item.quantity=data[i].inventory;
// total=total+data[i].inventory*data[i].price;
// alert("We are sorry but the product stock is lower then the ordered quantity.");
swal("","We are sorry, the product stock is lower then the ordered quantity", "error", {
buttons: false,
timer: 2000,
});
$("#tr_"+cart_id +" #quantity").val(item.inventory);
// $("#tr_"+cart_id).append("<div><p>not available</p></div>")
// $("#"+id +" #p_total").text(data[i].inventory*data[i].price);
}else{
status="true";
}
// item.quantity=value;
}
});
return status;
}
// remove product from cart
$("#tdata").on("click","#remove_cart",function(e){
// event.preventDefault();
var parent=$( this ).parent().parent();
var cart_id= $(this).parent().parent().find("#cart_id").text();
$.ajax({
type: 'post',
url: 'http://159.203.91.178:9009/delete_carts/'+cart_id,
headers:auth,
success: function (data, status, xhr) {
removeById(cart_products, cart_id);
swal("","Product remove from cart successfully", "success");
parent.hide( 400 );
}
});
});
// remove item form cart products
const removeById = (cart_products, cart_id) => {
const requiredIndex = cart_products.findIndex(el => {
return el.cart_id === String(cart_id);
});
if(requiredIndex === -1){
return false;
};
return !!cart_products.splice(requiredIndex, 1);
};
// move product to wish list
$("#tdata").on("click","#add_wishList", function() {
var cart_id= $(this).parent().find("#cart_id").text();
var cart_quan=cart_items.filter(function(item){
return item._id == cart_id;
});
var wishData={
page_id:cart_quan[0].page_id,
psid:cart_quan[0].psid,
variant_id:cart_quan[0].variant_id
}
var product_total=$(this).parent().find("#total_info").find("#p_total");
event.preventDefault();
var parent=$( this ).parent().parent().find("#qty").find("#quantity");
var total_info=$(this).parent().parent().find("#action").find("#total_info");
var remove_cart=$(this).parent().parent().find("#action").find("#remove_cart");
$(this).prop('disabled', true);
$.ajax({
type: 'post',
url: 'http://159.203.91.178:9009/cart_to_wish',
data: wishData,
headers:auth,
success: function (data, status, xhr) {
swal("","Product Successfully added to your WishList.", "success");
cart_products.filter(function(item){
if (item.cart_id == cart_id) {
item.quantity=0;
}
});
// parent.hide( 400 );
var abc= $(this).closest("div");
total=total-parseInt(product_total.text());
product_total.text(0);
parent.val(0);
total_info.hide();
remove_cart.css("margin-top", "10px");
remove_cart.show();
$("#total_without_shipping").text("৳"+total);
}
});
})
var variants=Array();
var cart_items= {};
var cart_products=[];
$(document).ready(function(){
// console.log(payment );
if (payment==2) {
swal("Payment Failure!","Your order could not be completed due to a payment failure.Please try again.", "error");
cartInfo();
}else if(payment==1) {
swal("Order Confirmed!","Thank you for your purchase. Your order has been placed successfully!.", "success");
}else{
cartInfo();
}
});
function cartInfo() {
$.ajax({
type: 'GET',
url: 'http://159.203.91.178:9009/carts?page_id='+page_id+'&psid='+psid,
headers:auth,
// url: 'https://api.businesscloud.xyz/carts?page_id='+id.split("_")[0]+'&psid='+id.split("_")[1],
success: function (data, status, xhr) {
cart_items=data;
if (data.length>0) {
for (let i = 0; i < data.length; i++) {
variants.push(data[i].variant_id);
}
product_info(variants);
}else{
$('#th2').css('pointer-events','none');
// $("#th2").prop("disabled",true);
// $("#checkout_a").prop("disabled",true);
swal("","Shopping cart is empty. Please add item and visit the page again", "info");
}
},
error: function (data) {
swal("","Something is wrong, please try again", "error");
}
});
}
// get cart products info
function product_info(variants) {
$.ajax({
type: 'GET',
url: 'http://159.203.91.178:9009/cart_products?variants='+variants,
headers:auth,
success: function (data, status, xhr) {
if (data.length<1) {
$('#th2').css('pointer-events','none');
$("#th2").attr('title', 'Shopping cart is empty. Please add item and visit the page again');
// $("#th2").prop("disabled",true);
// $("#checkout_a").prop("disabled",true);
swal("","Shopping cart is empty. Please add item and visit the page again", "info");
}else{
for (let i = 0; i < data.length; i++) {
for (let j = 0; j < cart_items.length; j++) {
if (data[i]._id==cart_items[j].variant_id) {
var image;
if (data[i].images === undefined || data[i].images == 0) {
image="empty";
}else{
image=data[i].images[0];
}
var item={
cart_id:cart_items[j]._id,
product_code:data[i].product[0].product_code,
product_id:data[i].product[0].id,
product_name:data[i].product[0].title,
quantity: cart_items[j].quantity,
price: data[i].price,
variant_id:data[i].id,
variant_name: data[i].name,
images:image,
image_folder:data[i].product[0].folder,
inventory:data[i].inventory,
inventory_check:data[i].inventory_check
}
cart_products.push(item);
}
}
}
setView(cart_products);
}
}
});
}
// set html view
function setView(data) {
for (let i = 0; i < data.length; i++) {
console.log(data[i].images[0]);
if (data[i].images=="empty") {
var image="https://media.istockphoto.com/id/1055079680/vector/black-linear-photo-camera-like-no-image-available.webp?s=612x612&w=is&k=20&c=OB0AoxouENQqDd14Te9WpfNy2aPOXoJF8AAi3zcd7Pk=";
}else{
var image="https://jiffc.s3.ap-southeast-1.amazonaws.com/"+data[i].image_folder+"/"+data[i].images;
// var image="https://media.istockphoto.com/id/1055079680/vector/black-linear-photo-camera-like-no-image-available.webp?s=612x612&w=is&k=20&c=OB0AoxouENQqDd14Te9WpfNy2aPOXoJF8AAi3zcd7Pk=";
}
$("#tdata").append('<tr id="tr_'+data[i].cart_id+'">\
<td id="product_info">\
<div class="product-item">\
<a class="product-thumb"><img src="'+image+'" alt="No Image"></a>\
<div class="product-info">\
<h4 class="product-title"><a ><b>'+data[i].product_name+" "+data[i].variant_name+'</b></a></h4><span class="taka_sign">৳</span><span id="unit_price" class="unit_price">'+data[i].price+'</span>\
</div>\
</div>\
</td>\
<td class="text-center" id="qty">\
<div class="count-input">\
<a href="#" class="qty qty-plus"><i class="fa fa-plus"></i></a>\
<input type="number" class="quantity" id="quantity" value="'+data[i].quantity+'" />\
<a href="#" class="qty qty-minus"><i class="fa fa-minus"></i></a>\
</div>\
</td>\
<td class="text-center" id="action">\
<span id="cart_id" style="display: none;">'+data[i].cart_id+'</span>\
<a class="remove-from-cart" id="add_wishList" href="#" data-toggle="tooltip" title="Move to wish list" data-original-title="Move to wish list"><span>WishList </span></i></a><br>\
<div id="total_info"><span>Total</span><br><span class="taka_sign"style="font-size:16px;">৳</span><span class="p_total" id="p_total">'+data[i].quantity*data[i].price+'</span></div>\
<a class="remove-from-cart remove_cart" id="remove_cart" style="display: none;" href="#" data-toggle="tooltip" title="Remove from cart" data-original-title="Remopve from cart"><span>Remove </span></a></td>\
</tr>');
}
checkStock(data);
$("#total_without_shipping").text("৳"+total);
}
// check default stock
function checkStock(data) {
var id;
for (let i = 0; i < data.length; i++) {
id="tr_"+data[i].cart_id;
if (data[i].inventory_check==1) {
if (data[i].inventory<1 ) {
// console.log(data[i]);
// console.log(data[i].cart_id);
$("#"+id +" #qty").empty();
$("#"+id +" #qty").append("<span style='color: red; font-weight: 600;'>Out of Stock</span>");
$("#"+id +" #total_info").hide();
$("#"+id +" #remove_cart").css("margin-top", "10px");
$("#"+id +" #remove_cart").show();
cart_products.filter(function(item){
if (item.cart_id == data[i].cart_id) {
// console.log("match");
item.quantity=0;
}
});
}else{
cart_products.filter(function(item){
if (item.cart_id == data[i].cart_id) {
if (data[i].inventory<item.quantity) {
item.quantity=data[i].inventory;
total=total+data[i].inventory*data[i].price;
$("#"+id +" #quantity").val(data[i].inventory);
$("#"+id +" #p_total").text(data[i].inventory*data[i].price);
// console.log("hello "+abc);
}else{
total=total+data[i].quantity*data[i].price;
}
// console.log("match");
}
});
}
}else{
total=total+data[i].quantity*data[i].price;
}
}
} |
:: Command execute :: | |
--[ c99shell v. 2.5 [PHP 8 Update] [24.05.2025] | Generation time: 0.0056 ]-- |