Created by
Lucas Werth
| <script type="text/javascript">
'use strict';
var booldPriceUpdater=function(){
this.grundpreis=0.0;
this.endpreis=0.0;
};
booldPriceUpdater.prototype.init = function(){
this.grundpreis=this.toFloat("[{assign var="oxPrice" value=$oDetailsProduct->getPrice()}][{$oxPrice->getPrice()}]");
};
booldPriceUpdater.prototype.toFloat = function(aString){
return parseFloat(aString);
};
booldPriceUpdater.prototype.trackChange = function(element) {
MutationObserver = window.MutationObserver || window.WebKitMutationObserver;
var observer = new MutationObserver(function(mutations, observer) {
if(mutations[0].attributeName == "value") {
$(element).trigger("change");
}
});
observer.observe(element, {
attributes: true
});
};
document.addEventListener("DOMContentLoaded", function(event) {
var bpu = new booldPriceUpdater;
$('input[name^="sel"]').each(function(){
bpu.trackChange( this);
});
bpu.init();
$('input[name^="sel"]').on( "change",function(){
bpu.endpreis = bpu.grundpreis;
$('input[name^="sel"]').each(function(){
var id=$(this).val();
var aItem = $(this).parent().find('.dropdown-menu a[data-selection-id="'+id+'"]');
var modprice = aItem.data('modprice');
var modmode = aItem.data('modmode');
if(typeof modprice != "undefined" && typeof modmode != "undefined"){
if(modmode=='percent'){
bpu.endpreis += bpu.endpreis * parseFloat(modprice)/100;
}else{
bpu.endpreis = bpu.endpreis + parseFloat(modprice);
}
}
});
$('#productPrice .price').html((Math.round(bpu.endpreis *100) / 100).toFixed(2).replace(/\./,","));
}).triggerHandler('change');
});
</script>
|