Files
2024-12-17 13:43:22 +01:00

779 lines
30 KiB
Smarty

{*
* Module Name: Perimeter / Length / Surface (Area) / Volume / Weight Calculator for Prestashop
* Module URI: Please contact with info@megventure.com
* Description: A utility to calculate quantity in perimeter, length, area, volume or weight units
* Version: 5.5.0
* Author: MEG Venture
*
* Copyright 2013, MEG Venture (info@megventure.com)
*
* This program is not a free software: you can't redistribute it and/or modify
* it. All rights reserved.
*
*
* This copyright notice and licence should be retained in all modules based on this framework.
* This does not affect your rights to assert copyright over your own original work.
*}
{if $psversion == ''}
{assign var='psversion' value=Configuration::get('PS_VERSION_DB')}
{/if}
{if ($page_name == 'product') AND isset($admintab_display)}
{if ($admintab_type == "linear")}
<!-- Square Meter Calculation Module -->
{if ($decimaltype == 'comma')}
{assign var="format" value="#.##0,00##"}
{else}
{assign var="format" value="#,##0.00##"}
{/if}
<script type="text/javascript">
var product_total_price = Number({$admintab_startingprice|escape:'htmlall':'UTF-8'}) + 0;
var product_calc_quantity = 1;
var qty_prod2 = 0;
var qty_prod3 = 0;
check_waste();
$(document).ready(function () {
if (("{$admintab_dispprice|escape:'html':'UTF-8'}" == "nopricetotalprice") || ("{$admintab_dispprice|escape:'html':'UTF-8'}" == "nopricebutton"))
$('.product-prices').hide();
//detect if the quantity field or applet dimensions changed and See the Calculated Total price
var searchValue = "";
var searchValue5 = "";
var oldLocation = location.href;
var running = true;
document.getElementById("quantity_wanted").readOnly=true;
totalpriceinfospecific();
prod();
$(document).on('change', '.product-variants [data-product-attribute]', function (event) {
initial = setTimeout(function() {
TextboxChanged();
//checkHrefChanged();
clearTimeout(initial);
}, 1500);
});
$(document).on('click', '.ui-spinner', function (event) {
TextboxChanged();
});
$(document).on('change', 'input', function (event) {
initial = setTimeout(function() {
TextboxChanged();
clearTimeout(initial);
}, 1000);
});
$(document).on('click', '.input-group-btn-vertical', function (event) {
TextboxChanged();
});
$(document).on('keyup', 'input', function (event) {
check_waste();
TextboxChanged();
});
$("input[name='discretion']").change(function(){
check_discretion();
});
$("input[name='waste']").change(function(){
check_waste();
});
$(document).on('click', '.ui-spinner-button, .ui-icon, .value-button', function (event) {
check_waste();
TextboxChanged();
});
$(document).on('click', '#totalprice_product_button', function (event) {
document.getElementById('totalpriceinfo').style.display = 'block';
});
setInterval(function() {
isCartValidCheck();
}, 1000);
function isCartValidCheck() {
var available_quantity = JSON.parse($('#product-details').attr('data-product'))["quantity"];
var allow_oosp = JSON.parse($('#product-details').attr('data-product'))["allow_oosp"];
if ((product_total_price == 0) || ((qty_prod3 > available_quantity) && (allow_oosp == 0))) {
$('.add-to-cart').addClass('squaremeter_disablecart');
$('.add').addClass('squaremeter_disablecart_wrapper');
if (product_total_price == 0) {
$("#squaremeter_availability").html("<span style='color:#f39d72;' class='material-icons'>remove_shopping_cart</span> {l s='Total price cannot be zero.' mod='squaremeter'}");
}
if ((qty_prod3 > available_quantity) && (allow_oosp == 0)) {
$("#squaremeter_availability").html("<span style='color:#f39d72;' class='material-icons'>remove_shopping_cart</span> {l s='Not enough stock is available.' mod='squaremeter'}");
}
}
else {
if (($(".product-unavailable")[0]) && ($(".product-unavailable:visible").length > 0)){
} else {
$('.add-to-cart').removeClass('squaremeter_disablecart');
$('.add').removeClass('squaremeter_disablecart_wrapper');
$('#squaremeter_availability').html('');
}
}
}
function TextboxChanged() {
if (running == true) {
prod();
}
}
function check_discretion()
{
var check1 = $('input[name="discretion"]:checked').length; // We are checking whether the switch is checked or not. If it is checked, the applet is visible.
var check2 = $('#quantity_wanted').is('[readonly]'); // We are checking whether the standard quantity input is readonly or not.
{if $design_type == "design1"}
if (check1 > 0) {
$('#squaremeter, #totalprice').show();
$(".qty").hide();
$(".qty").prev("span").hide();
$('.close_calculator').show();
$('.open_calculator').hide();
} else {
$('#squaremeter, #totalprice').hide();
$(".qty").show();
$(".qty").prev("span").show();
$('.close_calculator').hide();
$('.open_calculator').show();
}
if (check1 > 0) {
running = true;
$('input[name="discretion"]').val('on');
} else {
document.getElementById("quantity_wanted").readOnly=false;
running = false;
$('input[name="discretion"]').val('off');
}
{/if}
{if $design_type == "design2"}
if (("{$admintab_dispquan|escape:'html':'UTF-8'}" == "onevisible") || ("{$admintab_dispquan|escape:'html':'UTF-8'}" == "onewithcalcvisible") || ("{$admintab_dispquan|escape:'html':'UTF-8'}" == "calcvisible") || ("{$admintab_dispquan|escape:'html':'UTF-8'}" == "decimalok")) { // We are checking whether the standard quantity field is visible or not at the page load.
if (check1 > 0) {
$('#squaremeter, #dimension, #totalprice').show();
$('.close_calculator').show();
$('.open_calculator').hide();
} else {
$('#squaremeter, #dimension, #totalprice').hide();
$('.close_calculator').hide();
$('.open_calculator').show();
}
$(".qty").show();
$(".qty").prev("span").show();
} else {
if (check1 > 0) {
$('#squaremeter, #dimension, #totalprice').show();
$(".qty").hide();
$(".qty").prev("span").hide();
$('.close_calculator').show();
$('.open_calculator').hide();
} else {
$('#squaremeter, #dimension, #totalprice').hide();
$(".qty").show();
$(".qty").prev("span").show();
$('.close_calculator').hide();
$('.open_calculator').show();
}
}
if (check1 > 0) {
running = true;
$('input[name="discretion"]').val('on');
} else {
document.getElementById("quantity_wanted").readOnly=false;
running = false;
$('input[name="discretion"]').val('off');
}
{/if}
}
});
function countDecimals (x){
if(Math.floor(x) === x) return 0;
return x.toString().split(".")[1].length || 0;
}
function check_waste()
{
{if ($admintab_waste_select|escape:'html':'UTF-8')}
var admintab_waste_select = {$admintab_waste_select|escape:'html':'UTF-8'};
{else}
var admintab_waste_select = '';
{/if}
{if $step_width > 0}
var step = {$step_width};
{else}
var step = {$step};
{/if}
if ((typeof waste_increase_percentage === 'undefined')) {
var step = 1;
}
var numofdecimal = countDecimals(step);
var waste_check = $('input[name="waste"]:checked').length;
if ((admintab_waste_select) && (waste_check > 0)) {
{if $admintab_directinput}
if ($('#wastevalue').val() > 0) {
waste_increase_percentage = 1;
} else {
waste_increase_percentage = 1 + Number({$admintab_waste|escape:'htmlall':'UTF-8'})/100;
$('#wastevalue').val(Number({$admintab_waste|escape:'htmlall':'UTF-8'}));
}
{else}
waste_increase_percentage = 1 + Number({$admintab_waste|escape:'htmlall':'UTF-8'})/100;
$('#wastevalue').val(Number({$admintab_waste|escape:'htmlall':'UTF-8'}));
{/if}
} else {
if ((typeof waste_increase_percentage !== 'undefined')) {
waste_increase_percentage = 1 + $('#wastevalue').val()/100;
{if $admintab_directinput}
{if $design_type == 'design1'}
var old_value = $('#directinput').val();
var rounded_old_value = (old_value/waste_increase_percentage).toFixed(numofdecimal);
$('#directinput').val(rounded_old_value);
{else}
var old_value = $('#quantity_wanted_alt').val();
var rounded_old_value = (old_value/waste_increase_percentage).toFixed(numofdecimal);
$('#quantity_wanted_alt').val(rounded_old_value);
{/if}
{else}
{if $design_type != 'design1'}
var old_value = $('#quantity_wanted_alt').val();
var rounded_old_value = (old_value/waste_increase_percentage).toFixed(numofdecimal);
$('#quantity_wanted_alt').val(rounded_old_value);
{/if}
{/if}
}
$('#wastevalue').val(0);
waste_increase_percentage = 1;
}
}
function check_directinput()
{
var qty_el_alt = document.getElementById('directinput');
var qty_alt = Number(qty_el_alt.value);
{if $design_type == 'design1'}
if (qty_alt < {$admintab_minwidth|escape:'html':'UTF-8'})
{
qty_el_alt.value = {$admintab_minwidth|escape:'html':'UTF-8'};
}
else if (isNaN( qty_alt ))
{
qty_el_alt.value = {$admintab_minwidth|escape:'html':'UTF-8'};
}
{else}
if (qty_alt<{$admintab_minwidth|escape:'html':'UTF-8'})
{
qty_el_alt.value = Number({$admintab_minwidth|escape:'html':'UTF-8'});
}
else if (qty_alt>{$admintab_maxwidth|escape:'htmlall':'UTF-8'})
{
qty_el_alt.value = Number({$admintab_maxwidth|escape:'htmlall':'UTF-8'});
}
else if (isNaN( qty_alt ))
{
qty_el_alt.value = Number({$admintab_minwidth|escape:'html':'UTF-8'});
}
{/if}
prod();
return false;
}
function check_width()
{
var qty_el_alt = document.getElementById('quantity_wanted_alt');
var qty_alt = Number(qty_el_alt.value);
if (qty_alt<{$admintab_minwidth|escape:'html':'UTF-8'})
{
qty_el_alt.value = Number({$admintab_minwidth|escape:'html':'UTF-8'});
}
else if (qty_alt>{$admintab_maxwidth|escape:'htmlall':'UTF-8'})
{
qty_el_alt.value = Number({$admintab_maxwidth|escape:'htmlall':'UTF-8'});
}
else if (isNaN( qty_alt ))
{
qty_el_alt.value = Number({$admintab_minwidth|escape:'html':'UTF-8'});
}
prod();
return false;
}
function check_quantity()
{
var quantity = document.getElementById('quantity');
var quantity_value = Number(quantity.value);
if (quantity_value<1)
quantity.value = 1;
else if (isNaN( quantity_value ))
quantity.value = 1;
prod();
return false;
}
function prod()
{
{if $admintab_directinput && ($design_type == 'design1')}
{if $admintab_conversion_unit}
{$admintab_maxwidth_unit = $admintab_conversion_unit}
{else if ($admintab_attribute_unit)}
{$admintab_maxwidth_unit = $admintab_attribute_unit}
{/if}
{/if}
{if $unittype == 'metric'}
//Quantity in m
if ("{$admintab_conversion_unit|escape:'html':'UTF-8'}" == "m" || "{$admintab_attribute_unit|escape:'htmlall':'UTF-8'}" == "m")
{
if ("{$admintab_maxwidth_unit|escape:'html':'UTF-8'}" == "mm")
{
var qty_el_alt = document.getElementById('quantity_wanted_alt');
var qty_alt = (Number(qty_el_alt.value))/1000;
}
else if ("{$admintab_maxwidth_unit|escape:'html':'UTF-8'}" == "cm")
{
var qty_el_alt = document.getElementById('quantity_wanted_alt');
var qty_alt = (Number(qty_el_alt.value))/100;
}
else if ("{$admintab_maxwidth_unit|escape:'html':'UTF-8'}" == "dm")
{
var qty_el_alt = document.getElementById('quantity_wanted_alt');
var qty_alt = (Number(qty_el_alt.value))/10;
}
else if ("{$admintab_maxwidth_unit|escape:'html':'UTF-8'}" == "m")
{
var qty_el_alt = document.getElementById('quantity_wanted_alt');
var qty_alt = Number(qty_el_alt.value);
}
}
//Quantity in dm
if ("{$admintab_conversion_unit|escape:'html':'UTF-8'}" == "dm" || "{$admintab_attribute_unit|escape:'htmlall':'UTF-8'}" == "dm")
{
if ("{$admintab_maxwidth_unit|escape:'html':'UTF-8'}" == "mm")
{
var qty_el_alt = document.getElementById('quantity_wanted_alt');
var qty_alt = Number(qty_el_alt.value)/100;
}
else if ("{$admintab_maxwidth_unit|escape:'html':'UTF-8'}" == "cm")
{
var qty_el_alt = document.getElementById('quantity_wanted_alt');
var qty_alt = Number(qty_el_alt.value)/10;
}
else if ("{$admintab_maxwidth_unit|escape:'html':'UTF-8'}" == "dm")
{
var qty_el_alt = document.getElementById('quantity_wanted_alt');
var qty_alt = Number(qty_el_alt.value);
}
else
{
var qty_el_alt = document.getElementById('quantity_wanted_alt');
var qty_alt = Number(qty_el_alt.value)*10;
}
}
//Quantity in cm
if ("{$admintab_conversion_unit|escape:'html':'UTF-8'}" == "cm"|| "{$admintab_attribute_unit|escape:'htmlall':'UTF-8'}" == "cm")
{
if ("{$admintab_maxwidth_unit|escape:'html':'UTF-8'}" == "mm")
{
var qty_el_alt = document.getElementById('quantity_wanted_alt');
var qty_alt = Number(qty_el_alt.value)/10;
}
else if ("{$admintab_maxwidth_unit|escape:'html':'UTF-8'}" == "cm")
{
var qty_el_alt = document.getElementById('quantity_wanted_alt');
var qty_alt = Number(qty_el_alt.value);
}
else if ("{$admintab_maxwidth_unit|escape:'html':'UTF-8'}" == "dm")
{
var qty_el_alt = document.getElementById('quantity_wanted_alt');
var qty_alt = Number(qty_el_alt.value)*10;
}
else
{
var qty_el_alt = document.getElementById('quantity_wanted_alt');
var qty_alt = Number(qty_el_alt.value)*100;
}
}
//Quanitity in mm
if ("{$admintab_conversion_unit|escape:'html':'UTF-8'}" == "mm" || "{$admintab_attribute_unit|escape:'htmlall':'UTF-8'}" == "mm")
{
if ("{$admintab_maxwidth_unit|escape:'html':'UTF-8'}" == "mm")
{
var qty_el_alt = document.getElementById('quantity_wanted_alt');
var qty_alt = Number(qty_el_alt.value);
}
else if ("{$admintab_maxwidth_unit|escape:'html':'UTF-8'}" == "cm")
{
var qty_el_alt = document.getElementById('quantity_wanted_alt');
var qty_alt = Number(qty_el_alt.value)*10;
}
else if ("{$admintab_maxwidth_unit|escape:'html':'UTF-8'}" == "dm")
{
var qty_el_alt = document.getElementById('quantity_wanted_alt');
var qty_alt = Number(qty_el_alt.value)*100;
}
else
{
var qty_el_alt = document.getElementById('quantity_wanted_alt');
var qty_alt = Number(qty_el_alt.value)*1000;
}
}
{else}
//Quantity in yd
if ("{$admintab_conversion_unit|escape:'html':'UTF-8'}" == "yd" || "{$admintab_attribute_unit|escape:'htmlall':'UTF-8'}" == "yd")
{
if ("{$admintab_maxwidth_unit|escape:'html':'UTF-8'}" == "in")
{
var qty_el_alt = document.getElementById('quantity_wanted_alt');
var qty_alt = (Number(qty_el_alt.value))/36;
}
else if ("{$admintab_maxwidth_unit|escape:'html':'UTF-8'}" == "ft")
{
var qty_el_alt = document.getElementById('quantity_wanted_alt');
var qty_alt = (Number(qty_el_alt.value))/3;
}
else if ("{$admintab_maxwidth_unit|escape:'html':'UTF-8'}" == "yd")
{
var qty_el_alt = document.getElementById('quantity_wanted_alt');
var qty_alt = (Number(qty_el_alt.value));
}
}
//Quantity in ft
if ("{$admintab_conversion_unit|escape:'html':'UTF-8'}" == "ft" || "{$admintab_attribute_unit|escape:'htmlall':'UTF-8'}" == "ft")
{
if ("{$admintab_maxwidth_unit|escape:'html':'UTF-8'}" == "in")
{
var qty_el_alt = document.getElementById('quantity_wanted_alt');
var qty_alt = Number(qty_el_alt.value)/12;
}
else if ("{$admintab_maxwidth_unit|escape:'html':'UTF-8'}" == "ft")
{
var qty_el_alt = document.getElementById('quantity_wanted_alt');
var qty_alt = Number(qty_el_alt.value);
}
else if ("{$admintab_maxwidth_unit|escape:'html':'UTF-8'}" == "yd")
{
var qty_el_alt = document.getElementById('quantity_wanted_alt');
var qty_alt = Number(qty_el_alt.value)*3;
}
}
//Quanitity in in
if ("{$admintab_conversion_unit|escape:'html':'UTF-8'}" == "in" || "{$admintab_attribute_unit|escape:'htmlall':'UTF-8'}" == "in")
{
if ("{$admintab_maxwidth_unit|escape:'html':'UTF-8'}" == "in")
{
var qty_el_alt = document.getElementById('quantity_wanted_alt');
var qty_alt = Number(qty_el_alt.value);
}
else if ("{$admintab_maxwidth_unit|escape:'html':'UTF-8'}" == "ft")
{
var qty_el_alt = document.getElementById('quantity_wanted_alt');
var qty_alt = Number(qty_el_alt.value)*12;
}
else if ("{$admintab_maxwidth_unit|escape:'html':'UTF-8'}" == "yd")
{
var qty_el_alt = document.getElementById('quantity_wanted_alt');
var qty_alt = Number(qty_el_alt.value)*36;
}
}
{/if}
{if $admintab_directinput}
{if $design_type == 'design1'}
var qty_el_directinput = document.getElementById('directinput');
var qty_directinput = Number(qty_el_directinput.value);
var multiplication = qty_directinput * waste_increase_percentage;
{else}
var qty_el_alt = document.getElementById('quantity_wanted_alt');
var qty_alt = Number(qty_el_alt.value);
var multiplication = qty_alt * waste_increase_percentage;
{/if}
{else}
var multiplication = qty_alt * waste_increase_percentage;
{/if}
var qty_prod = document.getElementById('quantity_wanted');
var qty_production = Number(qty_prod.value);
{if $admintab_attselect}
var e = document.getElementById("group_" + {$admintab_attribute|escape:'htmlall':'UTF-8'});
if (e.tagName == "SELECT")
{
var selectedlength = e.options[e.selectedIndex].text;
} else {
var selectedlength = $( "input[name='group[{$admintab_attribute|escape:'htmlall':'UTF-8'}]']:checked" ).siblings("span").text()
}
selectedlength = selectedlength.replace(/[^0-9\.]/g, '');
{else}
var selectedlength = {$admintab_conversion|escape:'htmlall':'UTF-8'};
{/if}
{if $admintab_secconversionselect}
selectedlength = selectedlength*{$admintab_secconversion|escape:'htmlall':'UTF-8'};
{/if}
if ("{$admintab_addquan|escape:'htmlall':'UTF-8'}" == "1")
{
var req = document.getElementById('quantity');
var req_value = Number(req.value);
if (("{$admintab_dispquan|escape:'html':'UTF-8'}" == "onevisible") || ("{$admintab_dispquan|escape:'html':'UTF-8'}" == "oneinvisible") || ("{$admintab_dispquan|escape:'html':'UTF-8'}" == "onewithcalcvisible") || ("{$admintab_dispquan|escape:'html':'UTF-8'}" == "onewithcalcinvisible") || ("{$admintab_dispquan|escape:'html':'UTF-8'}" == "decimalok"))
{
qty_prod.value = 1;
qty_prod2 = Math.ceil((multiplication/selectedlength) * req_value);
qty_prod3 = parseFloat(Math.round((multiplication/selectedlength) * req_value * 100) / 100).toFixed(2);
{if ($admintab_dispquan != "decimalok")}
if (qty_prod3 < 1)
qty_prod3 = 1;
{/if}
fulllength = multiplication * req_value;
extra = Math.ceil(multiplication * req_value / selectedlength) * selectedlength - fulllength;
}
else
qty_prod.value = Math.ceil((multiplication/selectedlength) * req_value);
if (qty_prod.value == 0)
qty_prod.value = 1;
if ("{$admintab_dispquan|escape:'html':'UTF-8'}" == "decimalok")
product_calc_quantity = parseFloat(Math.round((multiplication/selectedlength) * req_value * 100) / 100).toFixed(2);
else
product_calc_quantity = Math.ceil((multiplication/selectedlength) * req_value);
var dimen=document.getElementById("dimension");
var unit={if $admintab_attselect}"{$admintab_attribute_unit|escape:'htmlall':'UTF-8'}"{else}"{$admintab_conversion_unit|escape:'html':'UTF-8'}"{/if};
if ("{$admintab_dispquan|escape:'html':'UTF-8'}" == "decimalok")
dimen.innerHTML="{l s='Length' mod='squaremeter'}&nbsp;" + qty_el_alt.value + "&nbsp;{$admintab_maxwidth_unit|escape:'html':'UTF-8'},&nbsp;" + qty_prod3 + "&nbsp;{l s='ea' mod='squaremeter'}"{if ($dimensiondisplaytype == 'on')}+"<br>({l s='Calculated Total' mod='squaremeter'}&nbsp;" + format( "{$format|escape:'htmlall':'UTF-8'}", qty_alt*req_value) + "&nbsp;" + unit + ")"{else}+""{/if};
else
dimen.innerHTML="{l s='Length' mod='squaremeter'}&nbsp;" + qty_el_alt.value + "&nbsp;{$admintab_maxwidth_unit|escape:'html':'UTF-8'}&nbsp;" + req_value + "&nbsp;{l s='ea' mod='squaremeter'}"{if ($dimensiondisplaytype == 'on')}+"&nbsp;<br>({l s='Total' mod='squaremeter'}&nbsp;" + format("{$format|escape:'htmlall':'UTF-8'}", qty_alt*req_value) + "&nbsp;" + unit + ")({l s='Extra' mod='squaremeter'}&nbsp;" + format("{$format|escape:'htmlall':'UTF-8'}", extra) + "&nbsp;" + unit + ")"{else}+""{/if};
}
else
{
fulllength = multiplication;
extra = Math.ceil(multiplication / selectedlength) * selectedlength - fulllength;
if (("{$admintab_dispquan|escape:'html':'UTF-8'}" == "onevisible") || ("{$admintab_dispquan|escape:'html':'UTF-8'}" == "oneinvisible") || ("{$admintab_dispquan|escape:'html':'UTF-8'}" == "onewithcalcvisible") || ("{$admintab_dispquan|escape:'html':'UTF-8'}" == "onewithcalcinvisible") || ("{$admintab_dispquan|escape:'html':'UTF-8'}" == "decimalok"))
{
qty_prod.value = 1;
qty_prod2 = Math.ceil(multiplication/selectedlength);
qty_prod3 = parseFloat(Math.round((multiplication/selectedlength) * 100) / 100).toFixed(2);
{if ($admintab_dispquan != "decimalok")}
if (qty_prod3 < 1)
qty_prod3 = 1;
{/if}
}
else
qty_prod.value = Math.ceil(multiplication/selectedlength);
if (qty_prod.value == 0)
qty_prod.value = 1;
if ("{$admintab_dispquan|escape:'html':'UTF-8'}" == "decimalok")
product_calc_quantity = parseFloat(Math.round((multiplication/selectedlength) * 100) / 100).toFixed(2);
else
product_calc_quantity = Math.ceil(multiplication/selectedlength);
var dimen=document.getElementById("dimension");
var unit={if $admintab_attselect}"{$admintab_attribute_unit|escape:'htmlall':'UTF-8'}"{else}"{$admintab_conversion_unit|escape:'html':'UTF-8'}"{/if};
if ("{$admintab_dispquan|escape:'html':'UTF-8'}" == "decimalok")
dimen.innerHTML="{l s='Length' mod='squaremeter'}&nbsp;" + parseFloat(multiplication).toFixed(2) + "&nbsp;{$admintab_maxwidth_unit|escape:'html':'UTF-8'},&nbsp;" + qty_prod3 + "&nbsp;{l s='ea' mod='squaremeter'}"{if ($dimensiondisplaytype == 'on')}+"<br>({l s='Calculated Total' mod='squaremeter'}&nbsp;" + format( "{$format|escape:'htmlall':'UTF-8'}", qty_alt) + "&nbsp;" + unit + ")"{else}+""{/if};
else
dimen.innerHTML="{l s='Length' mod='squaremeter'}&nbsp;" + parseFloat(multiplication).toFixed(2) + "&nbsp;{$admintab_maxwidth_unit|escape:'html':'UTF-8'}&nbsp;"{if ($dimensiondisplaytype == 'on')}+"<br>({l s='Total' mod='squaremeter'}&nbsp;" + format( "{$format|escape:'htmlall':'UTF-8'}", qty_alt) + "&nbsp;" + unit + ")({l s='Extra' mod='squaremeter'}&nbsp;" + format( "{$format|escape:'htmlall':'UTF-8'}", extra) + "&nbsp;" + unit + ")"{else}+""{/if};
}
if (typeof fulllength !== 'undefined') {
$('#calculated_total').val((fulllength).toFixed(2));
if ((typeof extra !== 'undefined') && ("{$admintab_dispquan|escape:'html':'UTF-8'}" != "decimalok")) {
$('#grand_calculated_total').val((fulllength).toFixed(2) + extra);
}
}
totalpriceinfospecific();
if(("{$admintab_dispquan|escape:'html':'UTF-8'}" == "onewithcalcinvisible") || ("{$admintab_dispquan|escape:'html':'UTF-8'}" == "onewithcalcvisible"))
{
var pricecurrencyval = $('meta[property="product:price:currency"]').attr('content');
var totalpriceinfo = document.getElementById("totalpriceinfo");
totalpriceinfo.innerHTML = "{l s='Total Price' mod='squaremeter'} : <span>" + pricecurrencyval + " " + format( "{$format|escape:'htmlall':'UTF-8'}", product_total_price) + "</span>";
}
var dimx = dimen.innerHTML;
dimx=dimx.replace(/&nbsp;/gi," ");
dimx=dimx.replace(/&amp;/gi,"&");
dimx=dimx.replace(/&quot;/gi,'"');
dimx=dimx.replace(/<br>/gi,', ');
dimx=dimx.replace(/&lt;/gi,'<');
dimx=dimx.replace(/&gt;/gi,'>');
document.getElementById("dim").value = dimx;
return false;
}
function calc_pos()
{
$('#squaremeter').insertBefore('.product-add-to-cart');
{if $design_type == 'design2'}
$('#dimension').insertBefore('.product-add-to-cart');
{/if}
if ("{$admintab_dispprice|escape:'html':'UTF-8'}"!="pricenototalprice")
$('#totalprice').insertBefore('.product-add-to-cart');
$('#switchx').insertBefore('.product-add-to-cart');
$('<span id="squaremeter_availability"></span>').insertBefore('.product-add-to-cart');
}
//totalpriceinfospecific function is the same for all dimension types
function totalpriceinfospecific()
{
if (("{$admintab_dispprice|escape:'html':'UTF-8'}"=="pricetotalprice") || ("{$admintab_dispprice|escape:'html':'UTF-8'}"=="nopricetotalprice"))
document.getElementById('totalpriceinfo').style.display = 'block';
var qty_prod = document.getElementById('quantity_wanted');
if(("{$admintab_dispquan|escape:'html':'UTF-8'}" == "onewithcalcinvisible") || ("{$admintab_dispquan|escape:'html':'UTF-8'}" == "onewithcalcvisible"))
var qty_production = qty_prod2;
else if ("{$admintab_dispquan|escape:'html':'UTF-8'}" == "decimalok")
var qty_production = qty_prod3;
else
var qty_production = Number(qty_prod.value);
$('#converted_ea').val(qty_production);
var pricecurrencyval = $('meta[property="product:price:currency"]').attr('content');
if ($("#product-details").length) {
window.pricenumberval = $("#product-details").data("product").price_amount;
} else {
window.pricenumberval = $('meta[property="product:price:amount"]').attr('content');
}
//if quantity discounts are available
// if ($("#product-details").length) {
// var qty_discount = $("#product-details").data("product").quantity_discounts;
// if(qty_discount.length > 0 && parseFloat(qty_discount[0].from_quantity) <= parseFloat(qty_production))
// {
// for(var i =0; i<qty_discount.length ; i++){
// if(parseFloat(qty_production) >= parseFloat(qty_discount[i].from_quantity)){
// var type_of_discount = qty_discount[i].discount.includes("%", 0);
// if (type_of_discount == true) {
// discount_amount = qty_discount[i].discount.replace('%','');
// pricenumberval = pricenumberval * (100 - discount_amount) /100;
// } else {
// pricenumberval = qty_discount[i].discount.replace(/[^0-9.,]/g, "").replace(/[,]/g, ".");
// }
//var iskonto = qty_discount[i].discount.replace(/[^0-9.,]/g, "").replace(/[,]/g, ".");
//pricenumberval = pricenumberval - iskonto;
//break;
// }
// }
// }
// }
$("#quantity_wanted").change();
var totalprice = Number({$admintab_startingprice|escape:'htmlall':'UTF-8'}) + qty_production * pricenumberval;
totalprice = Math.round((totalprice + Number.EPSILON) * 100) / 100; //We convert the price to 2 decimals
var totalpriceinfo = document.getElementById("totalpriceinfo");
$('#product_total_price_calc').val(totalprice);
var pricenumberval = $("#product-details").data("product").price_amount;
if ("{$admintab_dispquan|escape:'html':'UTF-8'}" == "decimalok")
product_total_price = Number({$admintab_startingprice|escape:'htmlall':'UTF-8'}) + parseFloat(product_calc_quantity) * pricenumberval;
else
product_total_price = Number({$admintab_startingprice|escape:'htmlall':'UTF-8'}) + parseInt(product_calc_quantity,10) * pricenumberval;
{if ($admintab_extrafee_select|escape:'html':'UTF-8')}
var admintab_extrafee_select = {$admintab_extrafee_select|escape:'html':'UTF-8'};
{else}
var admintab_extrafee_select = '';
{/if}
var fee_check = $('input[name="extrafee"]:checked').length;
if ((admintab_extrafee_select) && (fee_check > 0)) {
product_total_price = product_total_price + Number({$admintab_extrafee|escape:'htmlall':'UTF-8'});
$('#extrafeevalue').val(Number({$admintab_extrafee|escape:'htmlall':'UTF-8'}));
} else {
$('#extrafeevalue').val(0);
}
var cart_button_initial_status = $('.add-to-cart').attr("disabled");
if (cart_button_initial_status != "disabled") {
var available_quantity = JSON.parse($('#product-details').attr('data-product'))["quantity"];
var allow_oosp = JSON.parse($('#product-details').attr('data-product'))["allow_oosp"];
if ((product_total_price == 0) || ((qty_prod3 > available_quantity) && (allow_oosp == 0))) {
$('.add-to-cart').addClass('squaremeter_disablecart');
$('.add').addClass('squaremeter_disablecart_wrapper');
if ((qty_prod3 > available_quantity) && (allow_oosp == 0)) {
$("#squaremeter_availability").html("<span style='color:#f39d72;' class='material-icons'>remove_shopping_cart</span> {l s='Not enough stock is available.' mod='squaremeter'}");
}
} else {
if (($(".product-unavailable")[0]) && ($(".product-unavailable:visible").length > 0)){
} else {
$('.add-to-cart').removeClass('squaremeter_disablecart');
$('.add').removeClass('squaremeter_disablecart_wrapper');
$('#squaremeter_availability').html('');
}
}
}
if ("{$admintab_dispquan|escape:'html':'UTF-8'}" == "onevisible" || "{$admintab_dispquan|escape:'html':'UTF-8'}" == "oneinvisible") {
product_total_price = pricenumberval;
}
{if $admintab_unit_baseprice}
if(pricenumberval > product_total_price)
product_total_price = pricenumberval;
{/if}
{if $admintab_reserve}
if(Number("{$admintab_reserve|escape:'htmlall':'UTF-8'}")>product_total_price)
product_total_price = Number({$admintab_reserve|escape:'htmlall':'UTF-8'});
{/if}
product_total_price = Math.round((product_total_price + Number.EPSILON) * 100) / 100; //We convert the price to 2 decimals
if(!$("#product_total_price_calc").size())
$('<input type="hidden" name="product_total_price_calc" id="product_total_price_calc" value='+product_total_price+' />').appendTo('form#add-to-cart-or-refresh');
else
$("#product_total_price_calc").val(product_total_price);
if(("{$admintab_dispquan|escape:'html':'UTF-8'}" == "onewithcalcvisible") || ("{$admintab_dispquan|escape:'html':'UTF-8'}" == "onewithcalcinvisible") || ("{$admintab_dispquan|escape:'html':'UTF-8'}" == "decimalok"))
totalprice = $('#product_total_price_calc').val();
totalpriceinfo.innerHTML = "{l s='Total Price' mod='squaremeter'} : <span>" + pricecurrencyval + " " + format( "{$format|escape:'htmlall':'UTF-8'}", $('#product_total_price_calc').val()) + "</span>";
{if $design_type == 'design1'}
if (waste_increase_percentage != 1) {
if((product_calc_quantity % 1 < 1) && (product_calc_quantity % 1 != 0))
document.getElementById('directinput').value = parseFloat(product_calc_quantity).toFixed(2);
else
document.getElementById('directinput').value = parseFloat(product_calc_quantity);
}
check_waste();
{if !$admintab_directinput}
var qty_el_alt = document.getElementById('quantity_wanted_alt');
var qty_alt = Number(qty_el_alt.value);
if((qty_alt % 1 < 1) && (qty_alt % 1 != 0))
document.getElementById('quantity_wanted_alt').value = parseFloat(qty_alt).toFixed(2);
else
document.getElementById('quantity_wanted_alt').value = parseFloat(qty_alt);
if((product_calc_quantity % 1 < 1) && (product_calc_quantity % 1 != 0))
document.getElementById('directinput').value = parseFloat(product_calc_quantity).toFixed(2);
else
document.getElementById('directinput').value = parseFloat(product_calc_quantity);
{/if}
{else}
if((product_calc_quantity % 1 < 1) && (product_calc_quantity % 1 != 0))
document.getElementById('quantity_wanted_alt').value = parseFloat(product_calc_quantity).toFixed(2);
else
document.getElementById('quantity_wanted_alt').value = parseFloat(product_calc_quantity);
{/if}
}
</script>
{/if}
{/if}
<!-- Square Meter Calculation Module -->