$(function () { $('.checkout-button').click(function (event) { event.preventDefault(); // $('#place_order').mouseover(function() {
let kurczakWeight = 4; let perliczkaWeight = 3; let gesWeight = 6; let kaczkaWeight = 3; let packageWeight = 20; let sleepTime = 1;
let currentQuantity = parseInt($('tr.woocommerce-cart-form__cart-item.cart_item > td.product-quantity > div > div > input').val()) let courierDpdFood = $('#shipping_method_0_flexible_shipping_single7').val(); //flexible_shipping_single:7 let courierDpdClassic = $('#shipping_method_0_flexible_shipping_single9').val(); //flexible_shipping_single:9
var nameProduct = $('.product-name').text();
if (nameProduct.includes("kurczaka")) { setTimeout(function () { showAlert(currentQuantity, countBirdPackageQuantity(packageWeight, kurczakWeight)) }, sleepTime) } else if (nameProduct.includes("gęsi")) { setTimeout(function () { showAlert(currentQuantity, countBirdPackageQuantity(packageWeight, gesWeight)) }, sleepTime) } else if (nameProduct.includes("perliczki")) { setTimeout(function () { showAlert(currentQuantity, countBirdPackageQuantity(packageWeight, perliczkaWeight)) }, sleepTime) } else if (nameProduct.includes("kaczki")) { setTimeout(function () { showAlert(currentQuantity, countBirdPackageQuantity(packageWeight, kaczkaWeight)) }, sleepTime) } else { setTimeout(function () { if (courierDpdFood) { var rest = Math.abs((currentQuantity % 4) - 4); if (rest != 4) { fireSweet(rest); } } else if (courierDpdClassic) { var rest = Math.abs((currentQuantity % 3) - 3); if (rest != 3) {
fireSweet(rest); } } }, sleepTime) } } ) } )
function showAlert(currentQuantity, packageQuantity) { let localPickup = $('#shipping_method_0_local_pickup5'); if(!localPickup.is(':checked')){ let rest = Math.abs((currentQuantity % packageQuantity) - packageQuantity); if (rest !== packageQuantity) { fireSweet(rest); } else{ window.location.href = "/zamowienie"; } } }
function countBirdPackageQuantity(packageWeight, birdWeight){ return Math.abs(Math.floor(packageWeight / birdWeight)); }
function fireSweet(rest) {
Swal.fire({ icon: 'info', title: 'Jeszcze jedno...', text: "Chcielibyśmy Cię poinformować, że możesz dodać do koszyka jeszcze " + rest + " " + polishPlural("tuszkę", "tuszki", "tuszek", rest) + " i wciąż zachować tą samą kwotę dostawy. Jeżeli nie masz możliwości zamrożenia podaruj " + polishPlural("ją", "je", "je", rest) + " swoim znajomym. Oni też zasługują na to żeby się zdrowo odżywiać.", confirmButtonText: "Chcę zapłacić", showCancelButton: true, cancelButtonText: "Chcę dodać więcej",
}) .then((result) => { if (result.value) { window.location.href = `/zamowienie` } })
}
function polishPlural(singularNominativ, pluralNominativ, pluralGenitive, value) { if (value === 1) { return singularNominativ; } else if (value % 10 >= 2 && value % 10 <= 4 && (value % 100 < 10 || value % 100 >= 20)) { return pluralNominativ; } else { return pluralGenitive; } }