You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
112 lines
3.0 KiB
112 lines
3.0 KiB
Object.size = function(obj) {
|
|
var size = 0, key;
|
|
for (key in obj) {
|
|
if (obj.hasOwnProperty(key)) size++;
|
|
}
|
|
return size;
|
|
};
|
|
|
|
function addtocart(quant, produktid, korbid) {
|
|
$.post(
|
|
"/cart/add",
|
|
{'quant': quant, 'produktid': produktid, 'korbid': korbid},
|
|
function (data) {
|
|
console.log("add: ", data);
|
|
if (data) {
|
|
//do something
|
|
}
|
|
}
|
|
);
|
|
}
|
|
|
|
function getcart(korbid) {
|
|
$.post("/cart/getcart",
|
|
{'korbid': korbid},
|
|
function(data){
|
|
var size = Object.size(data);
|
|
for(var i = 0; i < size; i++) {
|
|
if (data[i][0]>0){
|
|
getprodukt(data[i][1], data[i][0]);
|
|
}
|
|
}
|
|
});
|
|
setTimeout(function(){
|
|
$.getScript("https://test.alc.gmbh/static/js/warenkorb.js", function() {
|
|
console.log("warenkorb.js loaded");
|
|
});
|
|
}, 1500);
|
|
}
|
|
|
|
function removefromcart(produktid, korbid) {
|
|
$.post(
|
|
"/cart/remove",
|
|
{'korbid': korbid, 'produktid': produktid},
|
|
function (data) {
|
|
console.log("remove: ", data);
|
|
if (data) {
|
|
//do something
|
|
}
|
|
}
|
|
);
|
|
}
|
|
|
|
function changequant(quant, produktid, korbid) {
|
|
$.post(
|
|
"/cart/changequant",
|
|
{'quant': quant, 'produktid': produktid, 'korbid': korbid},
|
|
function (data) {
|
|
console.log("changequant: ", data);
|
|
if (data) {
|
|
//do something
|
|
}
|
|
}
|
|
);
|
|
}
|
|
|
|
function getprodukt(produktid, quant) {
|
|
$.post(
|
|
"/cart/getprodukt",
|
|
{'produktid': produktid},
|
|
function (data) {
|
|
fullprice = parseFloat(quant) * parseFloat(data.preis);
|
|
$("#cart").prepend('<article class="product"><header><a class="remove" data-aaa="'+ data.id +'"> \
|
|
<img src="'+ data.bildlink +'" alt=""> \
|
|
<h3>Produkt entfernen</h3> \
|
|
</a>\
|
|
</header>\
|
|
<div class="content">\
|
|
<h1>'+ data.titel +'</h1>\
|
|
'+ data.kurzbeschreibung +'\
|
|
</div>\
|
|
<footer class="content" data-aaa="'+ data.id +'">\
|
|
<span class="qt-minus">-</span>\
|
|
<span class="qt">'+ quant +'</span>\
|
|
<span class="qt-plus">+</span>\
|
|
<h2 class="full-price">\
|
|
'+ fullprice +'€\
|
|
</h2>\
|
|
<h2 class="price">\
|
|
'+ data.preis +'€\
|
|
</h2>\
|
|
</footer>\
|
|
</article>');
|
|
return data;
|
|
}
|
|
);
|
|
}
|
|
|
|
$(document).ready(function(){
|
|
|
|
$(".cart-btn").click(function(){
|
|
|
|
var el = $(this);
|
|
cartid = document.getElementById("gcartid").innerHTML;
|
|
//console.log(cartid);
|
|
//console.log( $(this).data('produkt'));
|
|
addtocart("1", $(this).data('produkt'), cartid)
|
|
$("#modal1").modal();
|
|
console.log("modal open");
|
|
|
|
});
|
|
|
|
});
|