1338 lines
49 KiB
JavaScript
1338 lines
49 KiB
JavaScript
/*
|
|
* Custom code goes here.
|
|
* A template should always ship with an empty custom.js
|
|
*/
|
|
|
|
$( document ).ready(function() {
|
|
if ( sessionStorage.getItem("wcagColor") ){
|
|
jQuery("body").addClass("wcag");
|
|
jQuery(".switchColor").toggleClass('customInput')
|
|
}
|
|
});
|
|
|
|
var size = 1;
|
|
var sizeMin = 1;
|
|
var sizeMax = 5;
|
|
|
|
if ( sessionStorage.getItem("wcagSize") ){
|
|
size = sessionStorage.getItem("wcagSize");
|
|
WcagSetSize();
|
|
}
|
|
|
|
|
|
jQuery(".button-wcag-size-up").click(function(){
|
|
WcagSizeUp();
|
|
});
|
|
|
|
jQuery(".button-wcag-size-down").click(function(){
|
|
WcagSizeDown();
|
|
});
|
|
|
|
|
|
jQuery("#button-wcag").click(function(){
|
|
jQuery(".switchColor").toggleClass('customInput')
|
|
jQuery("body").toggleClass("wcag");
|
|
|
|
if ( jQuery("body").hasClass("wcag") ){
|
|
sessionStorage.setItem("wcagColor", "true");
|
|
contrastModeBackgroundWhite()
|
|
|
|
}
|
|
else{
|
|
sessionStorage.removeItem("wcagColor");
|
|
removecontrastModeBackgroundWhite()
|
|
}
|
|
});
|
|
|
|
$(document).on("click", ".toggle-listing-filters", function(){
|
|
jQuery("main").toggleClass("filtersHidden");
|
|
});
|
|
|
|
|
|
function WcagSizeUp(){
|
|
size = size + 1;
|
|
if (size > sizeMax) size = sizeMax;
|
|
WcagSetSize();
|
|
}
|
|
|
|
function WcagSizeDown(){
|
|
size = size - 1;
|
|
if (size < sizeMin) size = sizeMin;
|
|
WcagSetSize();
|
|
}
|
|
|
|
function WcagSetSize(){
|
|
WcagResetSize();
|
|
|
|
if (size != 1){
|
|
jQuery("body").addClass("size-"+size);
|
|
sessionStorage.setItem("wcagSize", size);
|
|
}
|
|
}
|
|
|
|
function WcagResetSize(){
|
|
jQuery("body").removeClass("size-2");
|
|
jQuery("body").removeClass("size-3");
|
|
jQuery("body").removeClass("size-4");
|
|
jQuery("body").removeClass("size-5");
|
|
|
|
sessionStorage.removeItem("wcagSize");
|
|
}
|
|
|
|
function dragElement(elmnt) {
|
|
var pos1 = 0, pos2 = 0, pos3 = 0, pos4 = 0;
|
|
if (document.getElementById(elmnt.id )) {
|
|
document.getElementById(elmnt.id ).onmousedown = dragMouseDown;
|
|
} else {
|
|
elmnt.onmousedown = dragMouseDown;
|
|
}
|
|
|
|
function dragMouseDown(e) {
|
|
e = e || window.event;
|
|
e.preventDefault();
|
|
// get the mouse cursor position at startup:
|
|
pos3 = e.clientX;
|
|
pos4 = e.clientY;
|
|
|
|
document.onmouseup = closeDragElement;
|
|
// call a function whenever the cursor moves:
|
|
document.onmousemove = elementDrag;
|
|
}
|
|
|
|
function elementDrag(e) {
|
|
e = e || window.event;
|
|
e.preventDefault();
|
|
// calculate the new cursor position:
|
|
pos1 = pos3 - e.clientX;
|
|
pos2 = pos4 - e.clientY;
|
|
pos3 = e.clientX;
|
|
pos4 = e.clientY;
|
|
|
|
var fixedTop = (elmnt.offsetTop - pos2);
|
|
var fixedLeft = (elmnt.offsetLeft - pos1);
|
|
|
|
if (fixedTop < 0) fixedTop = 0;
|
|
if (fixedLeft < 0) fixedLeft = 0;
|
|
|
|
// 2 to border
|
|
if (fixedLeft + jQuery(elmnt).width() + 2 > jQuery(elmnt).parent().width() ) fixedLeft = jQuery(elmnt).parent().width() - jQuery(elmnt).width() - 2;
|
|
if (fixedTop + jQuery(elmnt).height() + 2 > jQuery(elmnt).parent().height() ) fixedTop = jQuery(elmnt).parent().height() - jQuery(elmnt).height() - 2;
|
|
|
|
elmnt.style.top = fixedTop + "px";
|
|
elmnt.style.left = fixedLeft + "px";
|
|
|
|
$('.piece-left-positon').html(fixedLeft);
|
|
$('.piece-top-positon').html(fixedTop);
|
|
prod();
|
|
MovePieceBackground(fixedLeft, fixedTop);
|
|
}
|
|
|
|
function closeDragElement() {
|
|
document.onmouseup = null;
|
|
document.onmousemove = null;
|
|
}
|
|
}
|
|
|
|
|
|
function CheckPieceBorders(){
|
|
var elmnt = document.getElementById("piece");
|
|
|
|
var fixedTop = parseFloat(elmnt.style.top);
|
|
var fixedLeft = parseFloat(elmnt.style.left);
|
|
|
|
if (fixedTop < 0) fixedTop = 0;
|
|
if (fixedLeft < 0) fixedLeft = 0;
|
|
|
|
// 2 to border
|
|
if (fixedLeft + jQuery(elmnt).width() + 2 > jQuery(elmnt).parent().width() ) fixedLeft = jQuery(elmnt).parent().width() - jQuery(elmnt).width() - 2;
|
|
if (fixedTop + jQuery(elmnt).height() + 2 > jQuery(elmnt).parent().height() ) fixedTop = jQuery(elmnt).parent().height() - jQuery(elmnt).height() - 2;
|
|
|
|
elmnt.style.top = fixedTop + "px";
|
|
elmnt.style.left = fixedLeft + "px";
|
|
|
|
MovePieceBackground(fixedLeft, fixedTop);
|
|
}
|
|
|
|
var pieceEverEnabled = false;
|
|
|
|
var checkedHandler = (value) => {
|
|
if (value.is(":checked")){
|
|
jQuery(".piece-size-values").fadeTo("slow",1);
|
|
jQuery("#piece").fadeIn();
|
|
jQuery("#custom-wallpaper-price").fadeTo("slow",1);
|
|
jQuery("#custom-wallpaper-price-label").fadeTo("slow",1);
|
|
jQuery("#piece-width").attr('readonly', false);
|
|
jQuery("#piece-height").attr('readonly', false);
|
|
|
|
|
|
jQuery(".images-container .product-images li.thumb-container .thumb").addClass("dark");
|
|
|
|
|
|
|
|
var elmnt = document.getElementById("piece");
|
|
|
|
var leftSpacing = jQuery(elmnt).parent().width() / 2 - jQuery(elmnt).width() / 2 - 2;
|
|
var topSpacing = jQuery(elmnt).parent().height() / 2 - jQuery(elmnt).height() / 2 - 2;;
|
|
|
|
if ( $("#product_is_crop").val() == 0 ){ jQuery("#piece").css("top", topSpacing);
|
|
jQuery("#piece").css("left",leftSpacing);}
|
|
|
|
MovePieceBackground(leftSpacing, topSpacing);
|
|
|
|
dragElement(document.getElementById("piece"));
|
|
jQuery("#piece-width").trigger("change");
|
|
jQuery("#piece-height").trigger("change");
|
|
|
|
jQuery("#product_is_crop").val(1);
|
|
|
|
$('#piece-size-view').html($("#piece-width").val()+'x'+$("#piece-height").val());
|
|
|
|
}else{
|
|
jQuery(".piece-size-values").fadeTo("slow",0.23);
|
|
jQuery("#piece").fadeOut();
|
|
jQuery("#custom-wallpaper-price").fadeTo("slow",0.23);
|
|
jQuery("#custom-wallpaper-price-label").fadeTo("slow",0.23);
|
|
jQuery("#piece-width").attr('readonly', true);
|
|
jQuery("#piece-height").attr('readonly', true);
|
|
|
|
jQuery(".images-container .product-images li.thumb-container .thumb").removeClass("dark");
|
|
|
|
jQuery("#product_is_crop").val(0);
|
|
$('#piece-size-view').html('Wybierz rozmiar');
|
|
|
|
}
|
|
|
|
};
|
|
jQuery("#checkbox-piece").change(function(){
|
|
checkedHandler(jQuery("#checkbox-piece"))
|
|
});
|
|
jQuery(document).ready(function() {
|
|
jQuery('#checkbox-piece').prop('checked', false);
|
|
$('#piece-height').val(50);
|
|
$('#piece-width').val(50);
|
|
checkedHandler(jQuery("#checkbox-piece"))
|
|
});
|
|
jQuery("#group_5").click(function() {
|
|
jQuery('#checkbox-piece').prop('checked', true);
|
|
setTimeout(function() {$('#checkbox-piece').trigger('change');
|
|
$("#piece").css('top', parseInt($('.piece-top-positon').html())+"px");
|
|
jQuery("#piece").css('left', parseInt($('.piece-left-positon').html())+"px");
|
|
jQuery("#piece").css("background-position", parseInt('-'+$('.piece-left-positon').html())+"px "+parseInt('-'+$('.piece-top-positon').html())+"px");
|
|
}, 2000);
|
|
});
|
|
|
|
|
|
jQuery(".wariant_kolorystyczny").click(function() {
|
|
jQuery('#checkbox-piece').prop('checked', true);
|
|
setTimeout(function() {
|
|
checkedHandler(jQuery("#checkbox-piece"));
|
|
|
|
if ($("#product_is_reflection").val() == '1'){
|
|
$("#piece").addClass("mirrored");
|
|
$(".product-images img.thumb").addClass("mirrored");
|
|
}
|
|
else {
|
|
$("#piece").removeClass("mirrored");
|
|
$(".product-images img.thumb").removeClass("mirrored");
|
|
}
|
|
|
|
|
|
$('#checkbox-piece').trigger('change');
|
|
$("#piece").css('top', parseInt($('.piece-top-positon').html())+"px");
|
|
jQuery("#piece").css('left', parseInt($('.piece-left-positon').html())+"px");
|
|
|
|
if ($("#product_is_reflection").val() == '1'){
|
|
jQuery("#piece").css("background-position", parseInt($('.piece-left-positon').html()) + $("#piece").width() +"px "+parseInt('-'+$('.piece-top-positon').html())+"px");
|
|
|
|
}
|
|
else {
|
|
jQuery("#piece").css("background-position", parseInt('-'+$('.piece-left-positon').html())+"px "+parseInt('-'+$('.piece-top-positon').html())+"px");
|
|
}
|
|
|
|
}, 2000);
|
|
});
|
|
|
|
function MovePieceBackground(left, top){
|
|
|
|
top = -top - 1;
|
|
left = -left - 1;
|
|
|
|
//if (jQuery("#piece").hasClass("mirrored")){
|
|
if ($("#product_is_reflection").val() == '1'){
|
|
left = -left + jQuery("#piece").width();
|
|
}
|
|
|
|
jQuery("#piece").css("background-size", jQuery("#piece").parent().width());
|
|
jQuery("#piece").css("background-position", left+"px "+top+"px");
|
|
jQuery("#piece_bg_left").val(left);
|
|
jQuery("#piece_bg_top").val(top);
|
|
//1000 500
|
|
jQuery("#product_crop_pos_x").val( Math.ceil(( 501 * Math.ceil(parseFloat(jQuery("#piece").css('left')) )) / jQuery("#piece").parent().width() ));
|
|
jQuery("#product_crop_pos_y").val( Math.ceil(( 301 * Math.ceil(parseFloat(jQuery("#piece").css('top')) )) / jQuery("#piece").parent().height() ));
|
|
|
|
}
|
|
|
|
jQuery("#piece-width").change(function() {
|
|
if (jQuery(this).val() > 500) jQuery(this).val(500);
|
|
if (jQuery(this).val() < 50) jQuery(this).val(50);
|
|
jQuery("#piece").width(this.value * 0.2 + "%");
|
|
$('.piece-width-px').html($('#piece-width').val());
|
|
$('#quantity_wanted_alt').val($('#piece-width').val()/100);
|
|
totalpriceinfospecific();
|
|
|
|
jQuery("#product_crop_width").val(jQuery("#piece-width").val());
|
|
|
|
CheckPieceBorders();
|
|
});
|
|
|
|
jQuery("#piece-height").change(function() {
|
|
if (jQuery(this).val() > 300) jQuery(this).val(300);
|
|
if (jQuery(this).val() < 50) jQuery(this).val(50);
|
|
jQuery("#piece").height(this.value * 0.3333 + "%");
|
|
$('.piece-height-px').html($('#piece-height').val());
|
|
$('#quantity_wanted_alth').val($('#piece-height').val()/100);
|
|
totalpriceinfospecific();
|
|
jQuery("#product_crop_height").val(jQuery("#piece-height").val());
|
|
|
|
CheckPieceBorders();
|
|
});
|
|
|
|
|
|
|
|
|
|
var basePrice = jQuery("#product_base_price").val();
|
|
|
|
|
|
function WallpaperMirrorReflection(){
|
|
jQuery(".product-images img.thumb").toggleClass("mirrored");
|
|
|
|
if (jQuery(".product-images img.thumb").hasClass("mirrored")){
|
|
jQuery("#piece").addClass("mirrored");
|
|
jQuery("#product_is_reflection").val(1);
|
|
}
|
|
else{
|
|
jQuery("#piece").removeClass("mirrored");
|
|
jQuery("#product_is_reflection").val(0);
|
|
}
|
|
|
|
CheckPieceBorders();
|
|
}
|
|
|
|
jQuery("#button-mirror-reflection").click(function() {
|
|
WallpaperMirrorReflection();
|
|
});
|
|
|
|
|
|
jQuery(document).ready(function(){
|
|
$('#add-to-cart-or-refresh button').on('click', function(e){
|
|
if (!$("#checkbox-piece").is(":checked")) {
|
|
e.stopPropagation();
|
|
e.preventDefault();
|
|
$.fancybox({
|
|
minWidth: 800,
|
|
maxWidth: 1000,
|
|
padding: 30,
|
|
height: 100,
|
|
content: 'Proszę wybrać rozmiar i wycinek tapety przed dodaniem jej do koszyka.'
|
|
});
|
|
}
|
|
});
|
|
});
|
|
|
|
|
|
jQuery(document).ready(function(){
|
|
if ( jQuery("body").hasClass("wcag") ){
|
|
contrastModeBackgroundWhite()
|
|
} else {
|
|
removecontrastModeBackgroundWhite()
|
|
}
|
|
|
|
jQuery("#textSearch").change(function(){
|
|
|
|
if (jQuery("#textSearch").val().length >= 1){
|
|
jQuery("#clearTextSearch").fadeIn();
|
|
}else{
|
|
ExcludeTextSearch();
|
|
}
|
|
if (jQuery("#textSearch").val().length >= 1){
|
|
|
|
var fullUrl = window.location.href;
|
|
|
|
if (fullUrl.indexOf("?") >= 0){
|
|
fullUrl = fullUrl + "&";
|
|
}else{
|
|
fullUrl = fullUrl + "?";
|
|
}
|
|
|
|
fullUrl = fullUrl + "text="+jQuery("#textSearch").val();
|
|
|
|
prestashop.emit("updateFacets",fullUrl);
|
|
|
|
}
|
|
});
|
|
|
|
jQuery("#clearTextSearch").click(function(){
|
|
|
|
ExcludeTextSearch();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
function ExcludeTextSearch(){
|
|
|
|
jQuery("#textSearch").val("");
|
|
|
|
var fullUrl = window.location.href;
|
|
|
|
if (fullUrl.indexOf("?") >= 0){
|
|
fullUrl = fullUrl + "&";
|
|
}else{
|
|
fullUrl = fullUrl + "?";
|
|
}
|
|
|
|
fullUrl = fullUrl + "text=";
|
|
|
|
prestashop.emit("updateFacets",fullUrl);
|
|
|
|
jQuery("#clearTextSearch").fadeOut();
|
|
|
|
}
|
|
function contrastModeBackgroundWhite(){
|
|
$(".contrastModeBackground").children().attr('style', 'background-color: transparent !important');
|
|
$(".contrastModeBackground").attr('style', 'background-color: transparent !important')
|
|
}
|
|
function removecontrastModeBackgroundWhite(){
|
|
$(".contrastModeBackground").children().removeAttr('style');
|
|
$(".contrastModeBackground").removeAttr('style')
|
|
}
|
|
// JP
|
|
$(document).on('click', '.fancybox-material-controls', function() {
|
|
$('html').animate({scrollTop: $('.pp_stick_parent').offset().top - 150});
|
|
priceDisplay = parseFloat($('.current-price').text().replace(/[^0-9\,.]/g, '')).toFixed(2);
|
|
$.fancybox({
|
|
minWidth: 800,
|
|
maxWidth: 1000,
|
|
padding: 0,
|
|
content: `
|
|
<div class="fancybox-material-box">
|
|
<h3 style="text-align: center; padding:10px; margin: 10px 0 20px 0;">Wybierz materiał</h3>
|
|
|
|
<div class="col-xs-12 material-canvas" style="padding:20px;">
|
|
<div class="row">
|
|
<div class="col-xs-12">
|
|
<span>Tapeta winylowa na fizelinie Canvas</span>
|
|
<button id="fancy-material-btn" class="btn" data-value="9">
|
|
Wybierz (${priceDisplay} PLN/m2) <i class="material-icons">chevron_right</i>
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="col-xs-12 material-canvas" style="padding:20px;">
|
|
<div class="row">
|
|
<div class="col-xs-12">
|
|
<span>Tapeta winylowa na fizelinie Concre</span>
|
|
<button id="fancy-material-btn" class="btn" data-value="19">
|
|
Wybierz (${priceDisplay} PLN/m2) <i class="material-icons">chevron_right</i>
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="col-xs-12 material-canvas" style="padding:20px;">
|
|
<div class="row">
|
|
<div class="col-xs-12">
|
|
<span>Tapeta winylowa na fizelinie Craft</span>
|
|
<button id="fancy-material-btn" class="btn" data-value="20">
|
|
Wybierz (${priceDisplay} PLN/m2) <i class="material-icons">chevron_right</i>
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="col-xs-12 material-canvas" style="padding:20px;">
|
|
<div class="row">
|
|
<div class="col-xs-12">
|
|
<span>Tapeta winylowa na fizelinie Extra Fine</span>
|
|
<button id="fancy-material-btn" class="btn" data-value="16">
|
|
Wybierz (${priceDisplay} PLN/m2) <i class="material-icons">chevron_right</i>
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="col-xs-12 material-canvas" style="padding:20px;">
|
|
<div class="row">
|
|
<div class="col-xs-12">
|
|
<span>Tapeta winylowa na fizelinie Fibro</span>
|
|
<button id="fancy-material-btn" class="btn" data-value="21">
|
|
Wybierz (${priceDisplay} PLN/m2) <i class="material-icons">chevron_right</i>
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="col-xs-12 material-canvas" style="padding:20px;">
|
|
<div class="row">
|
|
<div class="col-xs-12">
|
|
<span>Tapeta winylowa na fizelinie Linen</span>
|
|
<button id="fancy-material-btn" class="btn" data-value="22">
|
|
Wybierz (${priceDisplay} PLN/m2) <i class="material-icons">chevron_right</i>
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="col-xs-12 material-canvas" style="padding:20px;">
|
|
<div class="row">
|
|
<div class="col-xs-12">
|
|
<span>Tapeta winylowa na fizelinie Novella</span>
|
|
<button id="fancy-material-btn" class="btn" data-value="23">
|
|
Wybierz (${priceDisplay} PLN/m2) <i class="material-icons">chevron_right</i>
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="col-xs-12 material-canvas" style="padding:20px;">
|
|
<div class="row">
|
|
<div class="col-xs-12">
|
|
<span>Tapeta winylowa na fizelinie Ruta</span>
|
|
<button id="fancy-material-btn" class="btn" data-value="24">
|
|
Wybierz (${priceDisplay} PLN/m2) <i class="material-icons">chevron_right</i>
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="col-xs-12 material-canvas" style="padding:20px;">
|
|
<div class="row">
|
|
<div class="col-xs-12">
|
|
<span>Tapeta winylowa na fizelinie Trapan</span>
|
|
<button id="fancy-material-btn" class="btn" data-value="25">
|
|
Wybierz (${priceDisplay} PLN/m2) <i class="material-icons">chevron_right</i>
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="col-xs-12 material-canvas" style="padding:20px;">
|
|
<div class="row">
|
|
<div class="col-xs-12">
|
|
<span>Tapeta winylowa na fizelinie Zebra</span>
|
|
<button id="fancy-material-btn" class="btn" data-value="26">
|
|
Wybierz (${priceDisplay} PLN/m2) <i class="material-icons">chevron_right</i>
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
`
|
|
});
|
|
});
|
|
|
|
$(document).on('click', '.fancybox-size-controls', function() {
|
|
console.log('t');
|
|
$('#checkbox-piece').prop('checked', true);
|
|
$('#checkbox-piece').trigger('change');
|
|
|
|
// Phase 02 Plan 02-01: defensive offset check — .pp_stick_parent istnieje tylko w starym layoucie.
|
|
// Bez tego guard'a .offset() zwraca undefined w nowym layoucie i handler aborts przed $.fancybox().
|
|
var $ppStick = $('.pp_stick_parent');
|
|
if ($ppStick.length) {
|
|
$('html').animate({scrollTop: $ppStick.offset().top - 100});
|
|
}
|
|
$.fancybox({
|
|
maxWidth: 600,
|
|
minHeight: 420,
|
|
padding: 0,
|
|
content: '<h3 style="text-align: center; padding:10px; margin: 10px 0 20px 0;">Wymiary tapety</h3><div class="fancy-piece-size-values" style="padding:10px; text-align: center;"><label for="fancy-piece-width">Szerokość</label><input type="number" min="50" max="500" value="'+$('#piece-width').val()+'" id="fancy-piece-width" style="padding: 5px; text-align: center; margin: 0 10px;"><span class="fancy-piece-divider">X</span><input type="number" min="50" max="300" value="'+$('#piece-height').val()+'" id="fancy-piece-height" style="padding: 5px; text-align: center; margin: 0 10px;"><label for="piece-height">Wysokość</label><p style="margin-bottom:0px"><small> </small><small class="valid-width-alert" style="display:none">Proszę o podanie szerokości z przedziału od 50 do 500.</small><small class="valid-height-alert" style="display:none">Proszę o podanie wysokości z przedziału od 50 do 300.</small><small class="valid-alert" style="display:none">Proszę o podanie wysokości i szerokości oba pola są wymagane</small></p></div><div style="background: #dfdfdf; padding: 10px;margin: 10px 0 20px 0; text-align: center; font-size:11px;"><strong>Dodaj 3-6 cm na dodatkowy margines</stronsag><br/>Ponieważ ściany i sufit często nie są całkowicie równe, najlepiej dodać od trzech do sześciu centymetrów do zmierzonej szerokości i wysokości. Będą one stanowić dodatkowy margines przydatny podczas montażu tapety.</div><div class="button-content" style="text-align: center; width:100%; margin: 20px 0 20px 0;"><button id="fancy-piece-btn" class="btn">Pokaż tapetę i cenę <i class="material-icons">chevron_right</i></button></div>'
|
|
});
|
|
});
|
|
|
|
$(document).on('change', '#fancy-piece-width', function() {
|
|
if (jQuery('#fancy-piece-width').val() === '') {$('.valid-alert').show(); $('.valid-width-alert').hide();}
|
|
else if (jQuery('#fancy-piece-width').val() > 500 || jQuery('#fancy-piece-width').val() < 50) {$('.valid-alert').hide(); $('.valid-width-alert').show();}
|
|
else {
|
|
$('.valid-alert').hide();
|
|
$('.valid-width-alert').hide();
|
|
$('#piece-width').val($('#fancy-piece-width').val());
|
|
$('#piece-width').trigger('change');
|
|
$('#piece-size-view').html($("#piece-width").val()+'x'+$("#piece-height").val());
|
|
}
|
|
});
|
|
|
|
$(document).on('change', '#fancy-piece-height', function() {
|
|
if (jQuery('#fancy-piece-height').val() === '') {$('.valid-alert').show(); $('.valid-height-alert').hide();}
|
|
else if (jQuery('#fancy-piece-height').val() > 300 || jQuery('#fancy-piece-height').val() < 50) {$('.valid-alert').hide(); $('.valid-height-alert').show();}
|
|
else {
|
|
$('.valid-alert').hide();
|
|
$('.valid-height-alert').hide();
|
|
$('#piece-height').val($('#fancy-piece-height').val());
|
|
$('#piece-height').trigger('change');
|
|
$('#piece-size-view').html($("#piece-width").val()+'x'+$("#piece-height").val());
|
|
}
|
|
});
|
|
|
|
$(document).on('click', '#fancy-material-btn', function(){
|
|
|
|
$("#group_5").val($(this).data('value')).change();
|
|
$.fancybox.close();
|
|
$('.fancybox-material-controls strong').text($('#group_5').find('option:selected').text());
|
|
setTimeout(function() {$('#checkbox-piece').trigger('change');
|
|
$("#piece").css('top', parseInt($('.piece-top-positon').html())+"px");
|
|
jQuery("#piece").css('left', parseInt($('.piece-left-positon').html())+"px");
|
|
jQuery("#piece").css("background-position", parseInt('-'+$('.piece-left-positon').html())+"px "+parseInt('-'+$('.piece-top-positon').html())+"px");
|
|
}, 2000);
|
|
});
|
|
|
|
$(document).on('click', '#fancy-piece-btn', function(){
|
|
if(jQuery('#fancy-piece-width').val() > 500 || jQuery('#fancy-piece-width').val() < 50 || jQuery('#fancy-piece-height').val() > 300 || jQuery('#fancy-piece-height').val() < 50)
|
|
{$('#fancy-piece-weight').trigger('change'); $('#fancy-piece-height').trigger('change');}
|
|
else
|
|
$.fancybox.close();
|
|
});
|
|
|
|
$('#cart').ready(function() {
|
|
$('.customization-modal').each(function(index, element){
|
|
valArray = $.trim($(this).find('.value').html()).split(" ");
|
|
valDif = $(this);
|
|
console.log(valArray);
|
|
$.each(valArray, function(dd, element){
|
|
console.log();
|
|
if (dd == 1)
|
|
$(valDif).find('.power').css('width', parseFloat(element.replace(/[^0-9\.]/g, ''))*100+'px');
|
|
if (dd == 4)
|
|
$(valDif).find('.power').css('height', parseFloat(element.replace(/[^0-9\.]/g, ''))*100+'px');
|
|
if (dd == 14)
|
|
$(valDif).find('.power').css('background-position-x', element+'px');
|
|
if (dd == 15)
|
|
$(valDif).find('.power').css('background-position-y', element+'px');
|
|
if (dd == 17 && element == "1")
|
|
$(valDif).find('.power').css('transform', 'scaleX(-1)');
|
|
});
|
|
});
|
|
|
|
});
|
|
|
|
|
|
$(document).on('click', '#button-color-variants', function(){
|
|
$("#box-color-variants").fadeIn()
|
|
})
|
|
|
|
$(document).on('click', '#box-color-variants .wariant_kolorystyczny', function(){
|
|
$("#box-color-variants").fadeOut()
|
|
})
|
|
|
|
/* NEW layout — klik w kafelek wariantu zmienia wariant (delegowany, przeżywa refresh AJAX) */
|
|
$(document).on('click', '.product-variants-data--new .wariant_kolorystyczny label', function (e) {
|
|
var $label = $(this);
|
|
var $radio = $label.find('input.input-color');
|
|
if (!$radio.length) return;
|
|
if ($radio.is(':checked')) return;
|
|
$radio.prop('checked', true).trigger('change');
|
|
});
|
|
|
|
/* NEW layout — refresh wariantu produktu bez przeładowania strony.
|
|
PS core handler updateProduct_ szuka formy przez $('.product-actions').find('form:first'),
|
|
ale w nowym layoucie .product-actions nie istnieje tam, gdzie jest forma wariantów.
|
|
Robimy więc ręczny refresh (POST na bieżący URL produktu, action=refresh zwraca JSON
|
|
z HTML-fragmentami wariantu) i aktualizujemy kluczowe elementy in-place. */
|
|
$(document).on('change', '.product-variants-data--new input[name^="group["]', function () {
|
|
var $form = $('.product-variants-data--new #add-to-cart-or-refresh');
|
|
if (!$form.length) return;
|
|
var data = {};
|
|
$form.serializeArray().forEach(function (f) { data[f.name] = f.value; });
|
|
data.ajax = 1;
|
|
data.action = 'refresh';
|
|
data.quantity_wanted = 1;
|
|
var productUrl = window.location.href.split('?')[0].split('#')[0];
|
|
$.ajax({
|
|
url: productUrl,
|
|
type: 'POST',
|
|
data: data,
|
|
dataType: 'json',
|
|
headers: { 'Accept': 'application/json' },
|
|
success: function (resp) {
|
|
if (!resp) { window.location.reload(); return; }
|
|
try {
|
|
if (resp.product_url) {
|
|
history.pushState({}, '', resp.product_url);
|
|
}
|
|
if (resp.product_prices) {
|
|
var $p = $('.product-prices-data .product-prices');
|
|
if ($p.length) $p.replaceWith(resp.product_prices);
|
|
}
|
|
if (resp.product_cover_thumbnails) {
|
|
$('.product_image_wrapper').html(resp.product_cover_thumbnails);
|
|
}
|
|
if (window.prestashop && typeof prestashop.emit === 'function') {
|
|
prestashop.emit('updatedProduct', resp);
|
|
}
|
|
} catch (e) {
|
|
window.location.href = resp.product_url || window.location.href;
|
|
}
|
|
},
|
|
error: function () { window.location.reload(); }
|
|
});
|
|
});
|
|
|
|
// Phase 02 Plan 02-01: piece re-sync po variant AJAX refresh.
|
|
// #piece jest sibling-em .product_image_wrapper (nie dzieckiem) wiec przezywa .html() replace.
|
|
// Po zmianie wariantu re-triggerujemy change na width/height zeby odswiezyc background-position
|
|
// (rozmiar kontenera moze sie zmienic miedzy wariantami).
|
|
if (window.prestashop && typeof prestashop.on === 'function') {
|
|
prestashop.on('updatedProduct', function () {
|
|
// #piece jest re-renderowany przez product-cover-thumbnails.tpl (rendered inside resp.product_cover_thumbnails).
|
|
// Po replace .product_image_wrapper.html(...) dragElement trzeba zapiac ponownie na nowy node.
|
|
if ($('#product_is_crop').val() === '1' && document.getElementById('piece') && typeof dragElement === 'function') {
|
|
dragElement(document.getElementById('piece'));
|
|
$('#piece-width').trigger('change');
|
|
$('#piece-height').trigger('change');
|
|
}
|
|
});
|
|
}
|
|
|
|
// Phase 02 Plan 02-01: setup defensywny dla piece/crop w nowym layoucie.
|
|
// Piece pojawia sie DOPIERO po kliknieciu .fancybox-size-controls (user feedback).
|
|
// Dlatego NIE wywolujemy checkedHandler automatycznie — tylko przygotowujemy srodowisko,
|
|
// aby pozniejsze kliknieciem popup'a nie crashowalo:
|
|
// 1) override totalpriceinfospecific/prod (crash na brakujacym #product-details/totalpriceinfo w nowym layoucie)
|
|
// 2) wstrzyknij stuby DOM (elementy wymagane przez module-hook inline scripts)
|
|
setTimeout(function () {
|
|
if (!$('.product-variants-data--new').length) return;
|
|
|
|
// totalpriceinfospecific() jest wywolywana przez #piece-width change handler (custom.js:281)
|
|
// oraz przez kilka innych flow. Ma wiele DOM dependencies ktore nie istnieja w nowym layoucie.
|
|
// Nadpisujemy no-op — cena w nowym layoucie jest przekalkulowywana gdzie indziej.
|
|
if (typeof window.totalpriceinfospecific === 'function') {
|
|
window.totalpriceinfospecific = function () { /* no-op in new layout */ };
|
|
}
|
|
if (typeof window.prod === 'function') {
|
|
var _origProd = window.prod;
|
|
window.prod = function () { try { return _origProd.apply(this, arguments); } catch (e) { /* swallow */ } };
|
|
}
|
|
|
|
// Stub elementy dla pozostalych inline-script hooks.
|
|
['totalpriceinfo', 'custom-wallpaper-price', 'custom-wallpaper-price-label'].forEach(function (id) {
|
|
if (!document.getElementById(id)) {
|
|
var el = document.createElement('div');
|
|
el.id = id;
|
|
el.style.display = 'none';
|
|
document.body.appendChild(el);
|
|
}
|
|
});
|
|
['quantity_wanted', 'quantity_wanted_alt', 'quantity_wanted_alth'].forEach(function (id) {
|
|
if (!document.getElementById(id)) {
|
|
var el = document.createElement('input');
|
|
el.type = 'hidden';
|
|
el.id = id;
|
|
el.value = '1';
|
|
document.body.appendChild(el);
|
|
}
|
|
});
|
|
}, 600);
|
|
|
|
$(document).on('click', '#custom-order-btn', function(e){
|
|
e.preventDefault();
|
|
$('#custom-order-modal').modal('show');
|
|
})
|
|
$(document).on('click', '#custom-order-box-close', function(){
|
|
$('#custom-order-modal').modal('hide');
|
|
$('#custom-order-form .form-info').empty()
|
|
})
|
|
|
|
$(document).on('click', '#custom-pattern-btn', function(e){
|
|
e.preventDefault();
|
|
$('#custom-email-pattern-modal').modal('show');
|
|
})
|
|
$(document).on('click', '#custom-order-box-close', function(){
|
|
$('#custom-email-pattern-modal').modal('hide');
|
|
$('#custom-email-pattern-modal .form-info').empty()
|
|
})
|
|
|
|
$(document).ready(function(){
|
|
$(document).on('click', '#custom-order-form button.send-form', function(e){
|
|
e.preventDefault();
|
|
|
|
var form_name = $('#custom-order-form input[name="name"]').val();
|
|
var form_surname = $('#custom-order-form input[name="surname"]').val();
|
|
var form_email = $('#custom-order-form input[name="email"]').val();
|
|
var form_contact_type = $('#custom-order-form input[name="contact_type"]:checked').val();
|
|
var form_message = $('#custom-order-form textarea[name="text"]').val();
|
|
var fileInput = $('#custom-order-form input[name="file"]')[0];
|
|
|
|
if (form_name !== '' && form_surname !== '' && form_email !== '' && form_contact_type !== '') {
|
|
var formData = new FormData();
|
|
formData.append('name', form_name);
|
|
formData.append('surname', form_surname);
|
|
formData.append('email', form_email);
|
|
formData.append('contact_type', form_contact_type);
|
|
formData.append('text', form_message);
|
|
formData.append('file', fileInput.files[0]);
|
|
|
|
$.ajax({
|
|
type: 'POST',
|
|
cache: false,
|
|
url: '/special-order.php',
|
|
data: formData,
|
|
processData: false,
|
|
contentType: false,
|
|
|
|
beforeSend: function() {
|
|
$('#custom-order-form .form-info').empty()
|
|
$('#custom-order-form .loader').show();
|
|
$('#custom-order-form button.send-form').prop('disabled', true);
|
|
$('#custom-order-form button.send-form').hide();
|
|
},
|
|
|
|
success: function( data ) {
|
|
response = jQuery.parseJSON( data );
|
|
$('#custom-order-form button.send-form').prop('disabled', false);
|
|
$('#custom-order-form .loader').hide();
|
|
$('#custom-order-form button.send-form').show();
|
|
$('#custom-order-form .form-info').html(`<p class="${response.status}">${response.message}</p>`)
|
|
dataLayer.push({
|
|
event: "send_form_send_custom_order",
|
|
form_user_name: form_name,
|
|
form_user_surname: form_surname,
|
|
form_user_email: form_email
|
|
});
|
|
},
|
|
})
|
|
} else {
|
|
$('#custom-order-form .form-info').html(`<p class="error">Proszę wypełnić wszystkie wymagane pola w formularzu</p>`)
|
|
}
|
|
})
|
|
|
|
|
|
$(document).on('change', '#file-upload', function(){
|
|
var fileName = $(this).prop('files')[0].name;
|
|
console.log(fileName);
|
|
$('#file-selected').text('Plik: ' + fileName);
|
|
|
|
})
|
|
})
|
|
|
|
$(document).ready(function(){
|
|
$(document).on('click', '#custom-email-pattern-modal button.send-form', function(e){
|
|
e.preventDefault();
|
|
|
|
var form_name = $('#custom-email-pattern-modal input[name="name"]').val();
|
|
var form_surname = $('#custom-email-pattern-modal input[name="surname"]').val();
|
|
var form_email = $('#custom-email-pattern-modal input[name="email"]').val();
|
|
var form_contact_type = $('#custom-email-pattern-modal input[name="contact_type"]:checked').val();
|
|
var form_image = $('#custom-email-pattern-modal input[name="image"]').val();
|
|
|
|
if (form_name !== '' && form_surname !== '' && form_email !== '' && form_contact_type !== '') {
|
|
var formData = new FormData();
|
|
formData.append('name', form_name);
|
|
formData.append('surname', form_surname);
|
|
formData.append('email', form_email);
|
|
formData.append('contact_type', form_contact_type);
|
|
formData.append('image', form_image);
|
|
|
|
$.ajax({
|
|
type: 'POST',
|
|
cache: false,
|
|
url: '/email-pattern.php',
|
|
data: formData,
|
|
processData: false,
|
|
contentType: false,
|
|
|
|
beforeSend: function() {
|
|
$('#custom-email-pattern-modal .form-info').empty()
|
|
$('#custom-email-pattern-modal .loader').show();
|
|
$('#custom-email-pattern-modal button.send-form').prop('disabled', true);
|
|
$('#custom-email-pattern-modal button.send-form').hide();
|
|
},
|
|
|
|
success: function( data ) {
|
|
response = jQuery.parseJSON( data );
|
|
$('#custom-email-pattern-modal button.send-form').prop('disabled', false);
|
|
$('#custom-email-pattern-modal .loader').hide();
|
|
$('#custom-email-pattern-modal button.send-form').show();
|
|
$('#custom-email-pattern-modal .form-info').html(`<p class="${response.status}">${response.message}</p>`)
|
|
dataLayer.push({
|
|
event: "send_form_send_pattern",
|
|
form_user_name: form_name,
|
|
form_user_surname: form_surname,
|
|
form_user_email: form_email,
|
|
form_contact_type: form_contact_type
|
|
});
|
|
},
|
|
})
|
|
} else {
|
|
$('#custom-email-pattern-modal .form-info').html(`<p class="error">Proszę wypełnić wszystkie wymagane pola w formularzu</p>`)
|
|
}
|
|
})
|
|
})
|
|
|
|
$(document).on('click', '#custom-sample-btn', function(e){
|
|
e.preventDefault();
|
|
|
|
$([document.documentElement, document.body]).animate({
|
|
scrollTop: $(".product-images.js-qv-product-images").offset().top - $('#header').height() - 50
|
|
}, 1000);
|
|
|
|
$('#checkbox-piece').prop('checked', true);
|
|
$('#checkbox-piece').trigger('change');
|
|
|
|
$('#piece-height').val(50);
|
|
$('#piece-width').val(50);
|
|
|
|
jQuery('#fancy-piece-width').val(50);
|
|
jQuery('#fancy-piece-height').val(50);
|
|
|
|
$('#fancy-piece-weight').trigger('change');
|
|
$('#fancy-piece-height').trigger('change');
|
|
})
|
|
|
|
$('body').on('click', '#wpcfu-f1-o1 .ets_cfu-submit', function() {
|
|
var startTime = new Date().getTime();
|
|
var interval = setInterval(function() {
|
|
var responseDiv = $('.wpcfu-response-output');
|
|
if (responseDiv.length && responseDiv.text().includes('Dziękuję za Twoją wiadomość.')) {
|
|
// Formularz został poprawnie wysłany
|
|
dataLayer.push({
|
|
'event': 'submit_form_contact',
|
|
'form_subject': $( 'input[name="text-905"]' ).val(),
|
|
'form_email': $( 'input[name="email-668"]' ).val(),
|
|
});
|
|
clearInterval(interval);
|
|
} else if (new Date().getTime() - startTime > 20000) {
|
|
// Minęło 20 sekund, przerywamy sprawdzanie
|
|
clearInterval(interval);
|
|
}
|
|
}, 500); // Sprawdzaj co 500ms
|
|
});
|
|
|
|
$(document).ready(function() {
|
|
var url = new URL(window.location.href);
|
|
if (url.pathname === '/pl/koszyk' && url.searchParams.get('action') === 'show') {
|
|
// Twoja akcja tutaj
|
|
// Na przykład:
|
|
dataLayer.push({
|
|
'event': 'cart_show',
|
|
});
|
|
}
|
|
|
|
$('body').on('click', '.cart-detailed-actions .btn', function() {
|
|
// Wywołanie zdarzenia begin_checkout
|
|
dataLayer.push({'event': 'begin_checkout'});
|
|
});
|
|
|
|
$( 'body' ).on( 'click', '#checkout-personal-information-step .btn-primary', function() {
|
|
// Wywołanie zdarzenia add_payment_info
|
|
dataLayer.push({'event': 'address_form_show'});
|
|
});
|
|
|
|
$( 'body' ).on( 'click', '#checkout-addresses-step .btn-primary', function() {
|
|
// Wywołanie zdarzenia add_payment_info
|
|
dataLayer.push({'event': 'shipping_method_show'});
|
|
});
|
|
|
|
var eventFired = false;
|
|
$('body').on('click', '#checkout-delivery-step .btn-primary', function() {
|
|
if (!eventFired) {
|
|
// Wywołanie zdarzenia add_payment_info
|
|
dataLayer.push({'event': 'payment_method_show'});
|
|
eventFired = true; // Ustawiamy flagę, aby nie wywołać ponownie
|
|
}
|
|
});
|
|
|
|
$( 'body' ).on( 'click', '#checkout-payment-step .btn-primary', function() {
|
|
// Wywołanie zdarzenia add_payment_info
|
|
if ( $( this ).attr( 'disabled' ) != 'disabled' ) {
|
|
dataLayer.push({'event': 'purchase'});
|
|
}
|
|
});
|
|
});
|
|
|
|
// Custom
|
|
|
|
$(document).ready(function() {
|
|
// Slidert
|
|
if ($('._partners-slider').length > 0) {
|
|
var swiper = new Swiper("._partners-slider", {
|
|
spaceBetween: 64,
|
|
slidesPerView: 4,
|
|
loop: true,
|
|
speed: 2000,
|
|
autoplay: {
|
|
delay: 4000,
|
|
disableOnInteraction: false,
|
|
},
|
|
});
|
|
}
|
|
});
|
|
|
|
$(document).ready(function() {
|
|
// Slidert
|
|
if ($('.structure-slider.swiper').length > 0) {
|
|
var swiperStructure = new Swiper(".structure-slider.swiper", {
|
|
spaceBetween: 20,
|
|
slidesPerView: 1,
|
|
loop: true,
|
|
effect: "fade",
|
|
navigation: {
|
|
nextEl: ".box-structure-slider .swiper-button-next",
|
|
prevEl: ".box-structure-slider .swiper-button-prev",
|
|
},
|
|
});
|
|
}
|
|
});
|
|
|
|
|
|
$(document).ready(function() {
|
|
$('body').on('click', '.page-cms-15 ._box-2 ._tiles ._tile', function() {
|
|
$(this).toggleClass('active').siblings().removeClass('active');
|
|
})
|
|
});
|
|
|
|
|
|
// ============================================================================
|
|
// Phase 02 Plan 02-02: add-to-cart w nowym layoucie (wlasny AJAX submit).
|
|
// ============================================================================
|
|
// Powod: w nowym layoucie (.product-variants-data--new) button
|
|
// [data-button-action=add-to-cart] oraz input #quantity_wanted znajduja sie POZA
|
|
// forma #add-to-cart-or-refresh (forma zamyka sie w sidebar .col-md-6, a button
|
|
// i qty sa w szerokim .product-bar). PS core delegowany handler uzywa
|
|
// $(btn).closest('form') -> length 0 -> nie znajduje formy; rownoczesnie PS
|
|
// core ma dodatkowe handler'y ktore moga POST'owac pusty payload, dublujac
|
|
// zgloszenie z naszym.
|
|
//
|
|
// Rozwiazanie: handler na CAPTURE phase przez natywny addEventListener
|
|
// (jQuery .on() nie wspiera capture). Capture odpala sie PRZED delegowanymi
|
|
// PS core handlerami na bubble phase -> stopImmediatePropagation blokuje je
|
|
// calkowicie. Nastepnie manualny AJAX POST z form.serialize() + qty + action.
|
|
//
|
|
// Dodatkowe problemy adresowane tu zamiast w innych planach:
|
|
// 1) Fancybox-blocker (custom.js:327) NIE odpala sie w nowym layoucie bo
|
|
// selector $('#add-to-cart-or-refresh button') matches 0 elementow
|
|
// (button poza forma). Port logiki tutaj.
|
|
// 2) Sync is_crop/crop_width/crop_height: checkedHandler (custom.js:183)
|
|
// aborts na crash'u totalpriceinfospecific przed jQuery('#product_is_crop').val(1).
|
|
// Tu wymuszamy synchronizacje jesli checkbox checked ale is_crop=0.
|
|
// 3) Blockcart widget (header cart counter) nie auto-refreshuje sie po
|
|
// updatedCart event w nowym layoucie. Fetchujemy blockcart module ajax
|
|
// i manualnie podmieniamy zawartosc .blockcart.
|
|
//
|
|
// Idempotency: `window.__p02p02Bound` flag chroni przed double-register gdy
|
|
// ten sam kod jest tez inline'owany w product.tpl (cache-buster dla browser
|
|
// ktorego <script src=custom.js> moze byc stale cached).
|
|
// ============================================================================
|
|
if (!window.__p02p02Bound) {
|
|
window.__p02p02Bound = true;
|
|
document.addEventListener('click', function(e) {
|
|
var btn = e.target.closest ? e.target.closest('[data-button-action=add-to-cart]') : null;
|
|
if (!btn) return;
|
|
if (!document.querySelector('.product-variants-data--new')) return; // stary layout: PS core handle
|
|
|
|
var $form = $('#add-to-cart-or-refresh');
|
|
if (!$form.length) return;
|
|
|
|
// CAPTURE phase: blokuje PS core delegated handlers (bubble) zanim odpala.
|
|
e.preventDefault();
|
|
e.stopImmediatePropagation();
|
|
e.stopPropagation();
|
|
|
|
// Re-entrancy guard: zapobiega podwojnemu POST gdy custom.js I inline mirror
|
|
// oba zarejestrowaly handler (np. race w idempotency guard).
|
|
if (window.__p02p02InFlight) return;
|
|
window.__p02p02InFlight = true;
|
|
|
|
// Walidacja: piece musi byc skonfigurowany.
|
|
if (!$('#checkbox-piece').is(':checked')) {
|
|
window.__p02p02InFlight = false;
|
|
$.fancybox({
|
|
minWidth: 800,
|
|
maxWidth: 1000,
|
|
padding: 30,
|
|
height: 100,
|
|
content: 'Proszę wybrać rozmiar i wycinek tapety przed dodaniem jej do koszyka.'
|
|
});
|
|
return;
|
|
}
|
|
|
|
// Wymus sync hidden inputs z piece state (obejscie crash'u checkedHandler).
|
|
// Idempotentne — bezpieczne gdy override z 02-01 zadziala w przyszlosci.
|
|
if ($('#product_is_crop').val() === '0' || !$('#product_crop_width').val() || $('#product_crop_width').val() === '0') {
|
|
$('#product_is_crop').val('1');
|
|
var pw = parseInt($('#piece-width').val(), 10) || 100;
|
|
var ph = parseInt($('#piece-height').val(), 10) || 100;
|
|
$('#product_crop_width').val(pw);
|
|
$('#product_crop_height').val(ph);
|
|
}
|
|
|
|
var $btn = $(btn);
|
|
$btn.prop('disabled', true).addClass('loading');
|
|
|
|
var qty = parseInt($('#quantity_wanted').val(), 10) || 1;
|
|
|
|
// Phase 02 Plan 02-03 Task 2: inject squaremeter fields for customization save.
|
|
// Tlo: Plan 02-01 override totalpriceinfospecific na no-op wylaczyl squaremeter JS
|
|
// -> hidden inputs (discretion, dim, calculated_total, product_total_price_calc,
|
|
// qty_alt, qty_alth) pozostaja zerowe. Hook hookActionObjectCartUpdateBefore
|
|
// gate'owany jest `discretion=on` + wymaga wartosci numerycznych >0 zeby zapisac
|
|
// customization. Populujemy pola z piece-width/piece-height (user input w cm,
|
|
// konwertujemy na m dla kompatybilnosci z OLD flow). dim uzywa formatu VERBOSE
|
|
// jaki produkuje squaremeter JS (widoczny pozniej w "Szczegoly" koszyka).
|
|
var pwRaw = parseInt($('#piece-width').val(), 10) || 100;
|
|
var phRaw = parseInt($('#piece-height').val(), 10) || 100;
|
|
var wM = (pwRaw / 100).toFixed(1);
|
|
var hM = (phRaw / 100).toFixed(1);
|
|
var areaM2 = (parseFloat(wM) * parseFloat(hM)).toFixed(4);
|
|
var basePrice = parseFloat($('#product_base_price').val())
|
|
|| parseFloat($('#product_fixed_price').val())
|
|
|| parseFloat($('meta[property="product:price:amount"]').attr('content'))
|
|
|| parseFloat(($('.product-prices .current-price, .current-price').first().text() || '').replace(/[^\d.,]/g, '').replace(',', '.'))
|
|
|| 0;
|
|
var totalPriceCalc = Math.round(basePrice * parseFloat(areaM2));
|
|
|
|
$('#discretion').prop('checked', true);
|
|
if ($('#product_total_price_calc').length) $('#product_total_price_calc').val(totalPriceCalc);
|
|
if ($('#calculated_total').length) $('#calculated_total').val(areaM2);
|
|
if ($('#converted_ea').length) $('#converted_ea').val(areaM2);
|
|
if ($('#grand_calculated_total').length) $('#grand_calculated_total').val('');
|
|
if ($('#extrafeevalue').length) $('#extrafeevalue').val('0');
|
|
if ($('#wastevalue').length) $('#wastevalue').val('0');
|
|
if ($('#quantity_wanted_alt').length) $('#quantity_wanted_alt').val(wM);
|
|
if ($('#quantity_wanted_alth').length) $('#quantity_wanted_alth').val(hM);
|
|
|
|
var isRefl = parseInt($('#product_is_reflection').val(), 10) || 0;
|
|
var cropPosX = parseInt($('#product_crop_pos_x').val(), 10) || 0;
|
|
var cropPosY = parseInt($('#product_crop_pos_y').val(), 10) || 0;
|
|
var bgTop = $('#piece_bg_top').val() || 0;
|
|
var bgLeft = $('#piece_bg_left').val() || 0;
|
|
var dimStr = 'Szerokość ' + wM + ' m, Wysokość ' + hM + ' m, ' +
|
|
parseFloat(areaM2).toFixed(2) + ' m2, Pozycja ' + cropPosX + ' ' + cropPosY +
|
|
' <span> ,Pozycja tła ' + bgTop + ' ' + bgLeft + ' ,Odbicie ' + isRefl + ' </span>';
|
|
if ($('#dim').length) $('#dim').val(dimStr);
|
|
|
|
// Explicit sqFields appended po form.serialize() -> PHP $_POST last-wins
|
|
// defense-in-depth gdyby form nie mial tych inputow (shared partial variability).
|
|
var sqFields = 'discretion=on' +
|
|
'&dim=' + encodeURIComponent(dimStr) +
|
|
'&converted_ea=' + encodeURIComponent(areaM2) +
|
|
'&calculated_total=' + encodeURIComponent(areaM2) +
|
|
'&grand_calculated_total=' +
|
|
'&extrafeevalue=0' +
|
|
'&wastevalue=0' +
|
|
'&product_total_price_calc=' + encodeURIComponent(totalPriceCalc) +
|
|
'&qty_alt=' + encodeURIComponent(wM) +
|
|
'&qty_alth=' + encodeURIComponent(hM);
|
|
|
|
// Plan 02-05: PS attribute group inputy mogą byc POZA forma #add-to-cart-or-refresh
|
|
// (np. #group_5 "Tekstura materiału" w .product-bar-box). $form.serialize() ich nie
|
|
// łapie → PS zapisuje wrong attribute combination. Enumeruj i dołącz do payload.
|
|
var externalGroups = '';
|
|
$('[name^="group["]').each(function() {
|
|
var $el = $(this);
|
|
if ($el.closest('#add-to-cart-or-refresh').length) return; // juz w $form.serialize()
|
|
var t = ($el.attr('type') || '').toLowerCase();
|
|
if ((t === 'radio' || t === 'checkbox') && !$el.prop('checked')) return;
|
|
var n = $el.attr('name');
|
|
var v = $el.val();
|
|
if (v === undefined || v === null || v === '') return;
|
|
externalGroups += '&' + encodeURIComponent(n) + '=' + encodeURIComponent(v);
|
|
});
|
|
var payload = $form.serialize() + '&qty=' + encodeURIComponent(qty) + externalGroups + '&' + sqFields + '&add=1&action=update';
|
|
var actionUrl = $form.attr('action') || window.location.href;
|
|
|
|
$.ajax({
|
|
url: actionUrl,
|
|
type: 'POST',
|
|
data: payload,
|
|
dataType: 'json',
|
|
headers: { 'Accept': 'application/json' },
|
|
success: function(resp) {
|
|
var hasError = !resp || resp.hasError === true || resp.success === false ||
|
|
(resp.errors && (Array.isArray(resp.errors) ? resp.errors.length : Object.keys(resp.errors).length));
|
|
if (hasError) {
|
|
var errs = resp && resp.errors;
|
|
var msg = '';
|
|
if (Array.isArray(errs)) msg = errs.join('<br>');
|
|
else if (errs && typeof errs === 'object') msg = Object.values(errs).join('<br>');
|
|
else msg = 'Nie udało się dodać produktu do koszyka. Spróbuj ponownie.';
|
|
$.fancybox({
|
|
minWidth: 400,
|
|
maxWidth: 800,
|
|
padding: 30,
|
|
height: 100,
|
|
content: msg
|
|
});
|
|
return;
|
|
}
|
|
|
|
// Success: emit updatedCart (PS core hook bus).
|
|
if (window.prestashop && typeof prestashop.emit === 'function') {
|
|
prestashop.emit('updatedCart', { resp: resp, reason: { linkAction: 'add-to-cart' } });
|
|
}
|
|
$(document).trigger('updatedCart', [resp]);
|
|
|
|
// Phase 02 Plan 02-03 Task 3: fetch success modal + blockcart preview
|
|
// w jednym POST do /module/ps_shoppingcart/ajax (endpoint zwraca
|
|
// {preview, modal}). Zastepuje stary $.get do urls.pages.cart (ktory
|
|
// czasem nie renderowal modalu w NEW layout).
|
|
$.ajax({
|
|
url: '/module/ps_shoppingcart/ajax',
|
|
type: 'POST',
|
|
data: {
|
|
action: 'add-to-cart',
|
|
id_product: resp.id_product || '',
|
|
id_product_attribute: resp.id_product_attribute || '',
|
|
id_customization: resp.id_customization || 0
|
|
},
|
|
dataType: 'json'
|
|
}).done(function(mr) {
|
|
if (mr && mr.preview) {
|
|
$('.blockcart').replaceWith(mr.preview);
|
|
}
|
|
if (mr && mr.modal) {
|
|
$('#blockcart-modal').remove();
|
|
$('.modal-backdrop').remove();
|
|
$('body').append(mr.modal);
|
|
var $modal = $('#blockcart-modal');
|
|
if (typeof $modal.modal === 'function') {
|
|
$modal.modal('show');
|
|
} else {
|
|
// Fallback dla brakujacego Bootstrap modal plugin.
|
|
$modal.addClass('show in').css('display', 'block').attr('aria-hidden', 'false');
|
|
$('body').addClass('modal-open').append('<div class="modal-backdrop fade in show"></div>');
|
|
$modal.on('click.blockcartClose', '[data-dismiss=modal], .close', function() {
|
|
$modal.removeClass('show in').css('display', 'none').remove();
|
|
$('body').removeClass('modal-open');
|
|
$('.modal-backdrop').remove();
|
|
});
|
|
}
|
|
}
|
|
}).fail(function() {
|
|
// Fallback minimal counter update gdy modal endpoint fail.
|
|
if (resp.cart) {
|
|
$('.cart-products-count').text((resp.cart.products_count) || '');
|
|
}
|
|
});
|
|
|
|
// Success feedback: subtelne pulsowanie przycisku (fallback gdy modal nie renderuje).
|
|
$btn.addClass('added-flash');
|
|
setTimeout(function () { $btn.removeClass('added-flash'); }, 1200);
|
|
},
|
|
error: function(xhr) {
|
|
$.fancybox({
|
|
minWidth: 400,
|
|
maxWidth: 800,
|
|
padding: 30,
|
|
height: 100,
|
|
content: 'Błąd połączenia z serwerem. Spróbuj ponownie za chwilę.'
|
|
});
|
|
},
|
|
complete: function() {
|
|
$btn.prop('disabled', false).removeClass('loading');
|
|
window.__p02p02InFlight = false;
|
|
}
|
|
});
|
|
}, true); // useCapture=true — kluczowe, odpala przed bubble-phase PS core handlers.
|
|
}
|
|
|
|
// ============================================================================
|
|
// Phase 02 Plan 02-04: live cena per-sqm w UI.
|
|
// ============================================================================
|
|
// Zmiana #piece-width / #piece-height -> natychmiastowe przeliczenie
|
|
// .product-prices .current-price (pure JS, zero HTTP). Formula identyczna
|
|
// z Plan 02-03 add-to-cart handler: basePrice x area_m^2. basePrice czytane
|
|
// z meta[property="product:price:amount"] (fallback: .current-price text).
|
|
// Guard `window.__p02p04Bound` niezalezny od __p02p02Bound — stale-cache
|
|
// custom.js nie blokuje inline mirror rejestracji w product.tpl.
|
|
// ============================================================================
|
|
if (!window.__p02p04Bound) {
|
|
window.__p02p04Bound = true;
|
|
|
|
// Zapewnia istnienie labelki obok przycisku "Dodaj do koszyka".
|
|
// Górna cena .current-price ("Od XXX zł / m²") pozostaje STATYCZNA.
|
|
window.__p02p04EnsureLabel = function() {
|
|
var $label = $('.p02p04-total-price');
|
|
if ($label.length) return $label;
|
|
// Wstaw PRZED .add (kontener buttona) wewnatrz .product-quantity
|
|
var $add = $('.product-quantity .add').first();
|
|
if (!$add.length) return $();
|
|
$label = $('<span class="p02p04-total-price" aria-live="polite" style="display:inline-block;margin-right:16px;font-weight:700;font-size:1.25rem;vertical-align:middle;"></span>');
|
|
$add.before($label);
|
|
return $label;
|
|
};
|
|
|
|
window.__p02p04RecalcPrice = function() {
|
|
if (!document.querySelector('.product-variants-data--new')) return;
|
|
|
|
var pwRaw = parseInt(($('#piece-width').val() || 0), 10) || 0;
|
|
var phRaw = parseInt(($('#piece-height').val() || 0), 10) || 0;
|
|
|
|
var $label = window.__p02p04EnsureLabel();
|
|
|
|
if (pwRaw <= 0 || phRaw <= 0) {
|
|
if ($label.length) $label.text('');
|
|
return;
|
|
}
|
|
|
|
var areaM2 = (pwRaw / 100) * (phRaw / 100);
|
|
|
|
var basePrice = parseFloat($('meta[property="product:price:amount"]').attr('content'))
|
|
|| parseFloat(($('.product-prices .current-price, .current-price').first()
|
|
.text() || '').replace(/[^\d.,]/g, '').replace(',', '.'))
|
|
|| 0;
|
|
if (basePrice <= 0) return;
|
|
|
|
var total = basePrice * areaM2;
|
|
var formatted = total.toFixed(2).replace('.', ',') + ' zł';
|
|
|
|
if ($label.length) $label.text(formatted);
|
|
};
|
|
|
|
$(document).on('input change keyup', '#piece-width, #piece-height', function() {
|
|
clearTimeout(window.__p02p04RecalcT);
|
|
window.__p02p04RecalcT = setTimeout(window.__p02p04RecalcPrice, 100);
|
|
});
|
|
|
|
// Initial render — interval re-apply przez 5s:
|
|
// (a) #piece-width/#piece-height stubs moga byc wstrzykiwane late (Plan 02-01),
|
|
// (b) squaremeter init overwrituje .current-price PO naszym pierwszym recalc.
|
|
// Prosty interval ktory reaplikuje recalc co 500ms przez 5s zapewnia stabilny
|
|
// final state. Po 5s user i tak ma pelna reaktywnosc na zmiany dimensions.
|
|
window.__p02p04TryInitial = function() {
|
|
var attempts = 0;
|
|
var iv = setInterval(function() {
|
|
attempts++;
|
|
window.__p02p04RecalcPrice();
|
|
if (attempts >= 10) clearInterval(iv);
|
|
}, 500);
|
|
};
|
|
// Uruchom synchronicznie — jQuery ready w kontekscie inline Smarty block
|
|
// nie firuje konsekwentnie; recalc early-returnuje jesli inputy jeszcze nie
|
|
// sa w DOM, wiec interval-based retry bezpiecznie pokrywa ready state.
|
|
window.__p02p04TryInitial();
|
|
|
|
// prestashop.on() uses $(prestashop).on — wymaga ze window.prestashop istnieje.
|
|
// W inline mirror kontekst Smarty, prestashop bundle laduje sie later. Poll az pojawi sie.
|
|
(function bindUpdatedProduct() {
|
|
if (window.prestashop && typeof prestashop.on === 'function') {
|
|
prestashop.on('updatedProduct', function() {
|
|
setTimeout(window.__p02p04RecalcPrice, 50);
|
|
});
|
|
} else {
|
|
setTimeout(bindUpdatedProduct, 200);
|
|
}
|
|
})();
|
|
$(document).on('updatedProduct', function() {
|
|
setTimeout(window.__p02p04RecalcPrice, 50);
|
|
});
|
|
}
|
|
|
|
|
|
// product custom accordion for variants
|
|
$(function() {
|
|
$('body').on('click', '.product-box.product-box-acc .product-box--head', function() {
|
|
$(this).parent().toggleClass('active');
|
|
$(this).parent().find('.product-box--data').slideToggle();
|
|
});
|
|
}) |