Files
redline.com.pl/modules/dualpricedisplaypro/views/js/ps16/global.js
2024-11-11 18:46:54 +01:00

323 lines
14 KiB
JavaScript

/*
* 2018 Singleton software
*
* @author Singleton software <info@singleton-software.com>
* @copyright 2018 Singleton software
*/
//v detaile produktu - pri nacitani produktu, pri zmene atributu produktu alebo pocte produktov
var selectedCombination = 0;
if (typeof updatePrice !== 'undefined') {
var updatePriceOrig = updatePrice;
updatePrice = function () {
updatePriceOrig();
if (parseInt(dualPriceConfigData.show_in_product_detail) == 1 && (selectedCombination != parseInt($('#idCombination').val()))) {
selectedCombination = parseInt($('#idCombination').val());
quantity = parseInt($(getCorrectPathFromConfiguration('detail_quantity_path')).val());
if (parseInt(quantity) == 0 || isNaN(quantity) || typeof quantity === 'undefined') {
quantity = 1;
}
moveFreshPrices(productID, false);
getProductCombinationPrices(productID, selectedCombination, quantity, false);
}
};
}
//zabezpeci aby po prepnuti na listove zobrazenie katalogu, bola volba kombinacii pod cenou na pravo
if (typeof window.display !== 'undefined') {
var displayOrig = window.display;
window.display = function(view) {
displayOrig(view);
moveFreshPricesInCatalog();
}
}
//pretazenie funkcie updateProductUrl() ktora sa vola po manipulovani s filtrom
//vnutry sa zavola original funkcia updateProductUrl() a za nou sa vykona vykreslenie cien
if (typeof updateProductUrl !== 'undefined') {
var origUpdateProductUrl = updateProductUrl;
updateProductUrl = function(str) {
origUpdateProductUrl(str);
moveFreshPricesInCatalog();
}
}
//pretazenie funkcie ajaxCart.updateLayer() ktora sa vola po vyskoceni popupu po pridani produktu do kosika
//po jej zbehnuti sa zavolaju moje funkcie na vykrelesnie cien
if (typeof ajaxCart !== 'undefined' && ajaxCart.updateLayer !== 'undefined') {
var updateLayerOrig = ajaxCart.updateLayer;
ajaxCart.updateLayer = function(product) {
updateLayerOrig(product);
if (parseInt(dualPriceConfigData.show_in_add_to_cart_popup) == 1) {
var counter = 20;
var checkIfElementExistRepeatedly = setInterval(function() {
counter--;
if (counter === 0 || $(getCorrectPathFromConfiguration('summary_popup_parent_path')).length > 0) {
getProductCombinationPrices(product.id, product.idCombination, product.quantity, true);
clearInterval(checkIfElementExistRepeatedly);
}
}, 200);
}
}
}
$(document).ready(function() {
moveFreshPricesInCatalog();
moveFreshPricesInMinithumbs();
showAllPrices();
if (parseInt(dualPriceConfigData.show_in_product_detail) == 1) {
$(document).on('change', getCorrectPathFromConfiguration('detail_quantity_path'), function() {
quantity = parseInt($(this).val());
if (parseInt(quantity) != 0 && !isNaN(quantity) && typeof quantity !== 'undefined') {
getProductCombinationPrices(productID, parseInt($('#idCombination').val()), quantity, false);
}
});
$(document).on('click', '.product_quantity_down, .product_quantity_up', function() {
quantity = parseInt($(getCorrectPathFromConfiguration('detail_quantity_path')).val());
if (parseInt(quantity) != 0 && !isNaN(quantity) && typeof quantity !== 'undefined') {
getProductCombinationPrices(productID, parseInt($('#idCombination').val()), quantity, false);
}
});
}
});
function moveFreshPricesInCatalog() {
$('.productCatalogDualPriceModel.catalog').each(function() {
freshPricesModel = $(this);
$(this).parents(getCorrectPathFromConfiguration('miniature_root_path') + ':eq(0)').find(getCorrectPathFromConfiguration('catalog_price_path')).each(function() {
$(this).empty();
freshPricesModelForProduct = freshPricesModel.clone();
freshPricesModelForProduct.removeClass('productCatalogDualPriceModel');
freshPricesModelForProduct.addClass('moved');
freshPricesModelForProduct.clone().appendTo($(this));
$(this).css('visibility', 'visible');
});
});
setPriceSizeRatio('Catalog');
}
function moveFreshPricesInMinithumbs() {
findSomeAccessories = false;
$('.productCatalogDualPriceModel.minithumbs').each(function() {
freshPricesModel = $(this);
findPathInSideProducts = false;
findPathInAccessories = false;
findPathInCompare = false;
if (freshPricesModel.parents(getCorrectPathFromConfiguration('side_product_miniature_parent_path') + ':eq(0)').find(getCorrectPathFromConfiguration('side_product_miniature_price_path')).length > 0) {
findPathInSideProducts = true;
parentElement = freshPricesModel.parents(getCorrectPathFromConfiguration('side_product_miniature_parent_path') + ':eq(0)').find(getCorrectPathFromConfiguration('side_product_miniature_price_path')).parents(getCorrectPathFromConfiguration('side_product_miniature_parent_path') + ':eq(0)');
priceElement = parentElement.find(getCorrectPathFromConfiguration('side_product_miniature_price_path'));
} else if ($(this).parents(getCorrectPathFromConfiguration('accessories_miniature_parent_path') + ':eq(0)').find(getCorrectPathFromConfiguration('accessories_miniature_price_path')).length > 0) {
findPathInAccessories = true;
findSomeAccessories = true;
parentElement = freshPricesModel.parents(getCorrectPathFromConfiguration('accessories_miniature_parent_path') + ':eq(0)').find(getCorrectPathFromConfiguration('accessories_miniature_price_path')).parents(getCorrectPathFromConfiguration('accessories_miniature_parent_path') + ':eq(0)');
priceElement = parentElement.find(getCorrectPathFromConfiguration('accessories_miniature_price_path'));
} else if ($(this).parents(getCorrectPathFromConfiguration('compared_product_miniature_parent_path') + ':eq(0)').find(getCorrectPathFromConfiguration('compared_product_miniature_price_path')).length > 0) {
findPathInCompare = true;
parentElement = freshPricesModel.parents(getCorrectPathFromConfiguration('compared_product_miniature_parent_path') + ':eq(0)').find(getCorrectPathFromConfiguration('compared_product_miniature_price_path')).parents(getCorrectPathFromConfiguration('compared_product_miniature_parent_path') + ':eq(0)');
priceElement = parentElement.find(getCorrectPathFromConfiguration('compared_product_miniature_price_path'));
}
if (findPathInAccessories || findPathInSideProducts || findPathInCompare) {
freshPrices = freshPricesModel.clone();
freshPrices.appendTo(parentElement);
priceElement.empty();
freshPrices.appendTo(priceElement);
parentElement.find('.dualDisplayPro').removeClass('productCatalogDualPriceModel');
if (!findPathInCompare) {
parentElement.find('.dualDisplayPro').removeClass('product-price');
parentElement.find('.dualDisplayPro').removeClass('price');
}
priceElement.show();
}
});
if (findSomeAccessories) {
// pri accessories je po pridani cien schovany add to cart. Preto treba trosku zvacsit height.
if ($('.bx-viewport').length > 0) {
$('.bx-viewport').height(function (index, height) {
return (height + 100);
});
}
}
setPriceSizeRatio('Catalog');
}
function showAllPrices() {
$(dualPriceConfigData.miniature_root_path + ' ' + dualPriceConfigData.catalog_price_path).css('visibility', 'visible');
$(dualPriceConfigData.side_product_miniature_parent_path + ' ' + dualPriceConfigData.side_product_miniature_price_path).show();
$(dualPriceConfigData.accessories_miniature_parent_path + ' ' + dualPriceConfigData.accessories_miniature_price_path).show();
$(dualPriceConfigData.compared_product_miniature_parent_path + ' ' + dualPriceConfigData.compared_product_miniature_price_path).show();
}
function setPriceSizeRatio(type) {
$('.dualDisplayPro.product' + type).each(function() {
fontSizeOfFirstPrice = parseInt($(this).find('.priceDisplay').children('span:eq(0)').css('font-size'));
if ($(this).find('.priceDisplay').children('span:eq(1)').length > 0) {
$(this).find('.priceDisplay').children('span:eq(1)').css('font-size', (fontSizeOfFirstPrice/getSizeRatioFromConfig('standard')) + 'px');
}
if ($(this).find('.originalPriceDisplay').length > 0) {
$(this).find('.originalPriceDisplay').css('font-size', (fontSizeOfFirstPrice/getSizeRatioFromConfig('old')) + 'px');
}
});
}
function getSizeRatioFromConfig(priceType) {
if (priceType == 'standard') {
configSizeRation = dualPriceConfigData.size_ratio_between_prices;
} else {
configSizeRation = dualPriceConfigData.size_ratio_old_prices;
}
sizeRatio = 1.5;
if (parseInt(configSizeRation) == 1) {
sizeRatio = 1;
} else if (parseInt(configSizeRation) == 2) {
sizeRatio = 1.5;
} else if (parseInt(configSizeRation) == 3) {
sizeRatio = 1.666;
} else {
sizeRatio = 1.75;
}
return sizeRatio;
}
function getProductCombinationPrices(productID, productAttributeID, quantity, isAddToCartPopup) {
$.ajax({
type: "POST",
url: productCombinationsControllerLink,
async: false,
data : {
ajax: true,
action: 'getProductCombinationPrice',
productID : productID,
productAttributeID : productAttributeID,
quantity: quantity
},
dataType: 'json',
beforeSend: function() {
if (!isAddToCartPopup) {
displayProgresWheel(true, productID);
} else {
displayProgresWheelInAddToCartModal(true);
}
},
success: function(res) {
if (!isAddToCartPopup) {
displayProductDetailPrice(res.productID, res.productPriceInDetail);
} else {
displayProductPriceInAddToCartModal(res.productID, res.productPriceInDetail);
}
}
})
.always(function (dataOrjqXHR, textStatus, jqXHRorErrorThrown) {
if (!isAddToCartPopup) {
displayProgresWheel(false, productID);
} else {
displayProgresWheelInAddToCartModal(false);
}
});
}
function displayProductDetailPrice(productID, combinationPrices) {
$('.productDetailDualDisplayProWrapper[data-id="' + productID + '"].moved').each(function() {
freshPrices = $(this).html();
productPricesElement = $(this).parents(getCorrectPathFromConfiguration('detail_parent_path') + ':eq(0)').find(getCorrectPathFromConfiguration('detail_price_path'));
productPricesElement.empty();
productPricesElement.append(freshPrices);
if (combinationPrices != null) {
if (typeof combinationPrices.taxInclPrice !== 'undefined') {
productPricesElement.find('.dualDisplayPro .priceWithTax .priceWrapper').html(combinationPrices.taxInclPrice);
}
if (typeof combinationPrices.taxExclPrice !== 'undefined') {
productPricesElement.find('.dualDisplayPro .priceWithoutTax .priceWrapper').html(combinationPrices.taxExclPrice);
}
if (combinationPrices.hasDiscount) {
if (typeof combinationPrices.originalTaxInclPrice !== 'undefined') {
productPricesElement.find('.dualDisplayPro .originalPriceWithTax .priceWrapper').html(combinationPrices.originalTaxInclPrice);
}
if (typeof combinationPrices.originalTaxExclPrice !== 'undefined') {
productPricesElement.find('.dualDisplayPro .originalPriceWithoutTax .priceWrapper').html(combinationPrices.originalTaxExclPrice);
}
}
}
productPricesElement.show();
setPriceSizeRatio('Detail');
});
}
function displayProductPriceInAddToCartModal(productID, combinationPrices) {
freshPricesModelElement = $('#dualDisplayProWrapperModel');
productPricesElement = freshPricesModelElement.find('.dualDisplayPro').clone();
productPricesElement.addClass('addToCartModal');
productPricesElement.find('.originalPriceDisplay').remove();
appentToElement = $(getCorrectPathFromConfiguration('summary_popup_product_path'));
appentToElement.empty();
productPricesElement.appendTo(appentToElement);
if (combinationPrices != null) {
if (typeof combinationPrices.taxInclPrice !== 'undefined') {
productPricesElement.find('.priceWithTax .priceWrapper').html(combinationPrices.taxInclPrice);
}
if (typeof combinationPrices.taxExclPrice !== 'undefined') {
productPricesElement.find('.priceWithoutTax .priceWrapper').html(combinationPrices.taxExclPrice);
}
}
setPriceSizeRatio('InModal');
}
function moveFreshPrices(productID, isModal) {
if (isModal) {
$('.productDetailDualDisplayProWrapper[data-id="' + productID + '"][data-type="modal"].moved').remove();
}
originalPriceWrapper = $('.productDetailDualDisplayProWrapper[data-id="' + productID + '"][data-type="' + (isModal ? 'modal' : 'classic') + '"]:not(.moved)');
appendToElement = $('.productDetailDualDisplayProWrapper[data-id="' + productID + '"][data-type="' + (isModal ? 'modal' : 'classic') + '"]:not(.moved)').parents(getCorrectPathFromConfiguration('detail_parent_path') + ':eq(0)');
clonedElement = originalPriceWrapper.clone();
clonedElement.appendTo(appendToElement);
clonedElement.addClass('moved');
originalPriceWrapper.remove();
}
function displayProgresWheel(display, productID) {
$('.productDetailDualDisplayProWrapper[data-id="' + productID + '"].moved').each(function() {
productPricesElement = $(this).parents(getCorrectPathFromConfiguration('detail_parent_path') + ':eq(0)').find(getCorrectPathFromConfiguration('detail_price_path'));
if (display) {
productPricesElement.after(getLoadingSpinnerElement());
productPricesElement.siblings('.loadingSpinner').css({
'text-align': 'center',
'padding' : '10px'
});
productPricesElement.hide();
} else {
productPricesElement.show();
productPricesElement.siblings('.loadingSpinner').remove();
}
});
}
function displayProgresWheelInAddToCartModal(display) {
appentToElement = $(getCorrectPathFromConfiguration('summary_popup_product_path'));
if (display) {
appentToElement.empty();
appentToElement.append(getLoadingSpinnerElement());
appentToElement.show();
} else {
appentToElement.find('.loadingSpinner').remove();
}
}
function getCorrectPathFromConfiguration(name) {
correctValue = '.product-miniature';
if (dualPriceConfigData[name].length > 0) {
correctValue = dualPriceConfigData[name];
} else {
$(domElementPaths).each(function(key, value){
if (value['name'] == name) {
correctValue = value['init_value'];
}
});
}
return correctValue;
}
function getLoadingSpinnerElement() {
return "<div class='loadingSpinner'><img src='" + baseDir + "modules/dualpricedisplaypro/views/img/spinner.gif' alt='loading spinner' style='height: 40px;' /></div>";
}