Warning: unlink(/home/uslutekn/storagesilmeyiniz/cache/cache.catalog.language.1785039065): No such file or directory in /home/uslutekn/public_html/system/library/cache/file.php on line 68Warning: Cannot modify header information - headers already sent by (output started at /home/uslutekn/public_html/system/framework.php:42) in /home/uslutekn/public_html/vqmod/vqcache/vq2-catalog_controller_startup_startup.php on line 103Warning: Cannot modify header information - headers already sent by (output started at /home/uslutekn/public_html/system/framework.php:42) in /home/uslutekn/public_html/vqmod/vqcache/vq2-catalog_controller_startup_startup.php on line 161(function($) {
'use strict';
var cvLiveOption = {
updateUrl: 'index.php?route=extension/module/codervia_live_option_price/update&product_id=234',
optionsUrl: 'index.php?route=extension/module/codervia_live_option_price/options&product_id=234',
updateOptionLabels: 1,
productTotal: 1,
debug: 0,
timer: null,
lastData: ''
};
function cvLog() {
if (cvLiveOption.debug && window.console) {
console.log.apply(console, arguments);
}
}
function cvGetProductBox() {
return $('#product');
}
function cvSerializeProduct() {
var selector = [
'#product input[type="text"]',
'#product input[type="number"]',
'#product input[type="hidden"]',
'#product input[type="radio"]:checked',
'#product input[type="checkbox"]:checked',
'#product select',
'#product textarea'
].join(',');
return $(selector).serialize();
}
function cvHtml(text) {
return $('').text(text || '').html();
}
function cvSetHtml(selector, value) {
if (typeof value === 'undefined' || value === null) {
return;
}
var els = $(selector);
if (!els.length) {
return;
}
els.each(function() {
if ($(this).html() !== value) {
$(this).html(value);
}
});
}
function cvEnsureNormalPrice() {
var priceBox = $('.ocp-price-box .ocp-price-main').first();
if (!priceBox.length) {
return;
}
if (!$('.ocp-price-box .ocp-price-normal').length) {
priceBox.find('.ocp-price-old, .ocp-price-new').remove();
priceBox.prepend('');
}
}
function cvApplyProductPrice(product) {
if (!product) {
return;
}
var hasSpecial = product.special && product.special !== '0' && product.special !== '0,00₺';
var priceBox = $('.ocp-price-box .ocp-price-main').first();
if (priceBox.length) {
if (hasSpecial) {
if (!priceBox.find('.ocp-price-old').length) {
priceBox.find('.ocp-price-normal').remove();
priceBox.prepend(' ');
}
cvSetHtml('.ocp-price-box .ocp-price-old', product.price);
cvSetHtml('.ocp-price-box .ocp-price-new', product.special);
} else {
cvEnsureNormalPrice();
cvSetHtml('.ocp-price-box .ocp-price-normal', product.price);
}
}
if ($('.ocp-mobile-price').length) {
if (hasSpecial) {
$('.ocp-mobile-price').html(product.special + '' + product.price + '');
} else {
$('.ocp-mobile-price').html(product.price);
}
}
if (product.tax) {
$('.ocp-price-meta').find('[data-cv-live-tax]').html(product.tax);
}
if (product.points) {
$('.ocp-price-meta').find('[data-cv-live-points]').html(product.points);
}
}
function cvApplyOptionLabels(options) {
if (!cvLiveOption.updateOptionLabels || !options || !options.length) {
return;
}
$.each(options, function(i, opt) {
var valueId = String(opt.product_option_value_id);
var priceText = opt.price_text || '';
var labelText = opt.price_prefix && priceText ? opt.price_prefix + priceText : '';
var radioCheckbox = $('#product input[type="radio"][value="' + valueId + '"], #product input[type="checkbox"][value="' + valueId + '"]');
radioCheckbox.each(function() {
var wrap = $(this).closest('label, .radio, .checkbox, .ocp-choice');
var target = wrap.find('.ocp-choice-price').first();
if (target.length) {
target.html(labelText ? cvHtml(labelText) : '');
}
});
var selectOption = $('#product select option[value="' + valueId + '"]');
selectOption.each(function() {
var name = opt.name || $.trim($(this).text()).replace(/\s*\([^)]*\)\s*$/, '');
$(this).text(labelText ? name + ' (' + labelText + ')' : name);
});
});
}
function cvUpdateNow(force) {
var productBox = cvGetProductBox();
if (!productBox.length) {
return;
}
var data = cvSerializeProduct();
if (!force && data === cvLiveOption.lastData) {
return;
}
cvLiveOption.lastData = data;
$.ajax({
url: cvLiveOption.updateUrl,
type: 'post',
data: data,
dataType: 'json',
success: function(json) {
cvLog('Codervia Live Option Price:', json);
if (!json || !json.success) {
return;
}
cvApplyProductPrice(json.product);
cvApplyOptionLabels(json.options);
},
error: function(xhr) {
cvLog('Codervia Live Option Price error:', xhr.responseText || xhr.statusText);
}
});
}
function cvUpdate(delay) {
clearTimeout(cvLiveOption.timer);
cvLiveOption.timer = setTimeout(function() {
cvUpdateNow(false);
}, delay || 80);
}
$(document).on('change input keyup', '#product input, #product select, #product textarea', function() {
cvUpdate(80);
});
$(document).on('click', '#product label, #product .ocp-choice, .ocp-qty-minus, .ocp-qty-plus', function() {
cvUpdate(140);
});
$(document).ready(function() {
if (!$('.ocp-price-meta [data-cv-live-tax]').length) {
$('.ocp-price-meta li').each(function() {
if ($(this).text().toLowerCase().indexOf('vergi') !== -1 || $(this).text().toLowerCase().indexOf('tax') !== -1) {
$(this).wrapInner('');
}
});
}
cvUpdateNow(true);
});
})(jQuery);