1function Basket() { 2 3 var Items = [], 4 TotalAmount = 0, 5 SubTotal = 0, 6 DeliveryFee = 0, 7 DeliveryFeeFix = 0, 8 DeliveryFeeDiff = 0, 9 DeliveryFeeThreshold = 0, 10 MinimumOrderValueHold = 0, 11 MinimumOrderValue = 0, 12 ItemsCount = 0, 13 BasketComment = "", 14 Gift = [], 15 Takeout = false, 16 Discount = 0, 17 DiscountValue = 0, 18 CouponCode = "", 19 CouponId = 0, 20 CouponValue = 0, 21 CouponDiscount = 0, 22 CouponType = 0, 23 FreeOrderCount = 0, 24 FreeOrderValue = 0, 25 RemainingOrderValue = 0, 26 DiscountTakeoutActive = 0; 27 28 this.addItemToBasket = function($Item) { 29 30 var item, 31 sameItem = false, 32 qty = 0, 33 price = 0, 34 sameExtras = true; 35 36 if (Items.length > 0) { 37 for (item in Items) { 38 if (Items[item].id == $Item.id) { 39 if (Items[item].comment == $Item.comment) { 40 if (Items[item].extrasdata.length == $Item.extrasdata.length) { 41 sameExtras = true; 42 43 for (var i = 0; i < Items[item].extrasdata.length; i++) { 44 45 if (Items[item].extrasdata[i].id != $Item.extrasdata[i].id || Items[item].extrasdata[i].modus != $Item.extrasdata[i].modus) { 46 47 sameExtras = false; 48 break; 49 50 } 51 } 52 53 } else if ($Item.extrasdata.length != Items[item].extrasdata.length) { 54 sameExtras = false; 55 } 56 if (sameExtras) { 57 Items[item].quantity++; 58 qty = Items[item].quantity; 59 60 sameItem = true; 61 } 62 } 63 } 64 } 65 if (!sameItem) { 66 Items.push($Item); 67 } 68 69 } else { 70 Items.push($Item); 71 } 72 } 73 74 this.countUpItemInBasket = function($prodID, $position) { 75 var item, 76 qty = 0, 77 status = false, 78 price = 0; 79 for (item in Items) { 80 81 if (Items[item].id == $prodID && Items[item].position == $position) { 82 Items[item].quantity++; 83 qty = Items[item].quantity; 84 if (Items[item].extrasdata.length > 0) { 85 for (var i = 0; i < Items[item].extrasdata.length; i++) { 86 Items[item].extrasdata[i].quantity = qty; 87 } 88 } 89 status = true; 90 } 91 } 92 if (status) { 93 return qty; 94 } else { 95 return 0; 96 } 97 } 98 99 this.returnItemsFromBasket = function() { 100 var pos = 0; 101 for (var item in Items) { 102 Items[item].position = pos; 103 pos++; 104 } 105 pos = 0; 106 return Items; 107 } 108 109 this.getTotalValue = function() { 110 SubTotal = 0; 111 TotalAmount = 0; 112 RemainingOrderValue = 0; 113 FreeOrderCount = MainData.getFreeOrderCount(); 114 FreeOrderValue = MainData.getFreeOrderValue(); 115 var deliveryfeeThresholdStatus = getDeliveryfeeThresholdStatus(); 116 for (var item in Items) { 117 SubTotal += Items[item].quantity * Items[item].price; 118 if (Items[item].extrasdata.length > 0) { 119 for (var i = 0; i < Items[item].extrasdata.length; i++) { 120 if (Items[item].extrasdata[i].modus == "1") { 121 SubTotal += parseFloat(Items[item].extrasdata[i].price.replace(",", ".")*Items[item].quantity); 122 } 123 } 124 } 125 } 126 127 if(Discount > 0) { 128 DiscountValue = parseFloat(SubTotal * (1 - (1 * ((100 - Discount)/100)))); 129 TotalAmount -= DiscountValue; 130 RemainingOrderValue += DiscountValue; 131 } 132 133 if(!Takeout) { 134 if(SubTotal >= MinimumOrderValue){ 135 if (DeliveryFeeThreshold >= 0 && deliveryfeeThresholdStatus == 0) { 136 if(DeliveryFeeFix == 1) { 137 DeliveryFeeDiff = parseFloat(DeliveryFee); 138 } else { 139 DeliveryFeeDiff = 0; 140 } 141 } else { 142 if (SubTotal < DeliveryFeeThreshold || DeliveryFeeThreshold == 0) { 143 DeliveryFeeDiff = parseFloat(DeliveryFee); 144 } else { 145 DeliveryFeeDiff = 0; 146 } 147 } 148 149 TotalAmount += parseFloat(SubTotal); 150 TotalAmount += DeliveryFeeDiff; 151 }else{ 152 if(MinimumOrderValue > 0){ 153 TotalAmount += parseFloat(SubTotal); 154 if (DeliveryFeeThreshold >= 0 && deliveryfeeThresholdStatus == 0) { 155 156 if(MinimumOrderValueHold == 1) { 157 DeliveryFeeDiff = parseFloat(MinimumOrderValue - SubTotal + DeliveryFee); 158 159 if(DeliveryFeeFix == 0) { 160 if (MinimumOrderValue < SubTotal) { 161 TotalAmount -= parseFloat(DeliveryFee); 162 } 163 } 164 165 TotalAmount += parseFloat(DeliveryFeeDiff); 166 } else { 167 TotalAmount += parseFloat(DeliveryFee); 168 DeliveryFeeDiff = parseFloat(DeliveryFee); 169 } 170 } else { 171 if (SubTotal < MinimumOrderValue) { 172 DeliveryFeeDiff = parseFloat(MinimumOrderValue - SubTotal); 173 } else { 174 DeliveryFeeDiff = 0; 175 } 176 177 if (SubTotal < DeliveryFeeThreshold || DeliveryFeeThreshold == 0) { 178 DeliveryFeeDiff += parseFloat(DeliveryFee); 179 } 180 TotalAmount += DeliveryFeeDiff; 181 } 182 } 183 } 184 } else { 185 TotalAmount += parseFloat(SubTotal); 186 } 187 188 if (TotalAmount < MinimumOrderValue && MinimumOrderValueHold == 1) { 189 TotalAmount += DiscountValue; 190 DiscountValue = 0; 191 } 192 193 if(CouponType == 0) { 194 CouponDiscount = parseFloat(CouponValue); 195 } else { 196 CouponDiscount = parseFloat(TotalAmount * (CouponValue/100)); 197 } 198 199 if (parseFloat(CouponDiscount) > TotalAmount) { 200 TotalAmount = 0; 201 } else { 202 TotalAmount -= parseFloat(CouponDiscount); 203 } 204 RemainingOrderValue += parseFloat(CouponDiscount); 205 // if(FreeOrderCount > 0) { 206 // TotalAmount -= FreeOrderValue; 207 // RemainingOrderValue += FreeOrderValue; 208 // } 209 210 return parseFloat(TotalAmount); 211 } 212 213 214 this.setTakeout = function($val) { 215 Takeout = $val; 216 } 217 218 this.getTakeout = function() { 219 return Takeout; 220 } 221 222 this.setMinimumOrderValue = function($val){ 223 MinimumOrderValue = $val; 224 } 225 226 this.getMinimumOrderValue = function(){ 227 return MinimumOrderValue; 228 } 229 230 this.setDeliveryFeeValue = function($val){ 231 DeliveryFee = $val; 232 } 233 234 this.getDeliveryFeeValue = function(){ 235 return DeliveryFee; 236 } 237 238 this.setDeliveryFeeThreshold = function($val){ 239 DeliveryFeeThreshold = $val; 240 } 241 242 this.getDeliveryFeeThreshold = function(){ 243 return DeliveryFeeThreshold; 244 } 245 246 this.setDeliveryFeeFix = function($val){ 247 DeliveryFeeFix = $val; 248 } 249 250 this.getDeliveryFeeFix = function(){ 251 return DeliveryFeeFix; 252 } 253 254 this.getDeliveryFeeDiff = function(){ 255 return parseFloat(DeliveryFeeDiff); 256 } 257 258 this.setMinimumOrderValueHold = function($val){ 259 MinimumOrderValueHold = $val; 260 } 261 262 this.getMinimumOrderValueHold = function(){ 263 return MinimumOrderValueHold; 264 } 265
266 this.getSubtotalValue = function(){ 267 return SubTotal; 268 } 269 270 this.setDiscount = function($val) { 271 Discount = $val; 272 } 273 this.getDiscount = function() { 274 return Discount; 275 } 276 this.setDiscountValue = function($val) { 277 DiscountValue = $val; 278 } 279 this.getDiscountValue = function() { 280 return DiscountValue; 281 } 282 this.setDiscountTakeout = function($val) { 283 DiscountTakeoutActive = $val; 284 } 285 this.getDiscountTakeout = function() { 286 return DiscountTakeoutActive; 287 } 288 this.setCouponType = function($val) { 289 CouponType = $val; 290 } 291 this.getCouponType = function() { 292 return CouponType; 293 } 294 this.setCouponValue = function($val) { 295 CouponValue = $val; 296 } 297 this.getCouponValue = function() { 298 return CouponValue; 299 } 300 this.setCouponId = function($val) { 301 CouponId = $val; 302 } 303 this.getCouponId = function() { 304 return CouponId; 305 } 306 this.setCouponCode = function($val) { 307 CouponCode = $val; 308 } 309 this.getCouponCode = function() { 310 return CouponCode; 311 } 312 this.getCouponDiscount = function() { 313 return CouponDiscount; 314 } 315 this.getRemainingOrderValue = function() { 316 return RemainingOrderValue; 317 } 318 319 this.removeItemFromBasket = function($ItemID, $position = null, $clicked) { 320 var item, 321 delItem = false, 322 index, 323 qty = 0; 324 325 if ($clicked == "sub" || !$position) { 326 for (var item in Items) { 327 if (Items[item].id == $ItemID) { 328 if ($position) { 329 if (Items[item].position == $position) { 330 if (Items[item].quantity > 1) { 331 Items[item].quantity--; 332 qty = Items[item].quantity; 333 if (Items[item].extrasdata.length > 0) { 334 for (var i = 0; i < Items[item].extrasdata.length; i++) { 335 Items[item].extrasdata[i].quantity = qty; 336 } 337 } 338 } else { 339 delItem = true; 340 index = Items[item].position; 341 qty = 0; 342 } 343 } 344 } else { 345 delItem = true; 346 index = Items[item].position; 347 348 qty = 0; 349 } 350 } 351 } 352 353 if (delItem) { 354 Items.splice(index, 1); 355 } 356 return qty; 357 } 358 if ($clicked == "delete-basket-item") { 359 Items.splice($position, 1); 360 } 361 } 362 363 this.updateItemFromBasket = function ($Item, $position) { 364 Items.splice($position,1,$Item); 365 } 366 367 this.removeAllItems = function() { 368 //global Items und co löschen 369 Items = []; 370 ItemsCount = 0; 371 SubTotal = '0.00'; 372 TotalAmount = 0; 373 CouponCode = ""; 374 CouponId = 0; 375 CouponValue = 0; 376 CouponType = 0; 377 CouponDiscount = 0; 378 CouponValue = 0; 379 $("#subtotal-amount").text(SubTotal); 380 $("#coupon-wrap").addClass("hidden"); 381 return true; 382 } 383 384 this.getBasketCount = function() { 385 ItemsCount = Items.length; 386 return ItemsCount; 387 } 388 389 this.hasItemExtras = function($Item) { 390 var item = $Item; 391 if (item['extrasdata'].length > 0) { 392 return item['extrasdata']; 393 } else { 394 return null; 395 } 396 } 397 398 this.getExtrasFromBasketItem = function($pos) { 399 for (var item in Items) { 400 if (Items[item].position == $pos) { 401 if (Items[item].extrasdata.length > 0) { 402 console.log(JSON.stringify(Items[item].extrasdata)); 403 return Items[item].extrasdata; 404 } else { 405 return null; 406 } 407 } 408 409 } 410 411 } 412 413 this.setBasketComment = function($comment) { 414 BasketComment = $comment; 415 } 416 417 this.resetBasketComment = function() { 418 BasketComment = ""; 419 } 420 421 this.setItemComment = function($ItemID, $comment) { 422 Items[$ItemID].comment = ""; 423 Items[$ItemID].comment = $comment; 424 } 425 //Geschenkartikel-Funktionen 426 this.addGiftToBasket = function($GiftItem) { 427 if (Gift.length < 1) { 428 Gift.push($GiftItem); 429 } 430 431 } 432 433 this.removeGiftFromBasket = function() { 434 Gift = []; 435 } 436 437 this.basketSessionTask = function(){ 438 439 var basket = JSON.stringify(Items); 440 return basket; 441 } 442 443 444 this.priceChanged = function(id, oldVal, newVal) { 445 $('.fill-div#'+id).find('span.article-price').attr('data-price-id', newVal).html('⬠' + parseFloating(newVal)); 446 447 if (oldVal != newVal) { 448 alert('Der Preis für dieses Produkt hat sich geändert! Preis: ' + oldVal + ' -> ' + newVal); 449 } 450 } 451 452 this.getBasket = function() { 453 return (Items); 454 } 455} 456 457// basket relevant code
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.