Created
November 23, 2016 08:05
-
-
Save vgrish/4ff79b235052bb805f74830ac8a4dba7 to your computer and use it in GitHub Desktop.
msAddLinked
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Created by mvoevodskiy on 20.07.16. | |
*/ | |
$(document).on('ready', function() { | |
msal.orig_price = 0; | |
msal.additional_price = 0; | |
if (msal.price_target === undefined) { | |
msal.price_target = '#price'; | |
} | |
if (msal.price_orig_target === undefined) { | |
msal.price_orig_target = '#msal_price_original'; | |
} | |
msal.calculatePrice = function (event) { | |
if ($(msal.price_orig_target).val() === undefined) { | |
return; | |
} | |
msal.orig_price = parseInt($(msal.price_orig_target).val().replace(' ', '')); | |
msal.additional_price = 0; | |
msal.discount = 0; | |
$('.msal_input').each(function() { | |
add_price = parseInt($(this).data('price')); | |
add_discount = parseInt($(this).data('discount')); | |
if (isNaN(add_discount)) { | |
add_discount = 0; | |
} | |
if ($(this).attr('type') === 'checkbox') { | |
if ($(this).is(':checked')) { | |
msal.additional_price = msal.additional_price + add_price; | |
msal.discount = add_discount; | |
} | |
} else { | |
if ($(this).attr('type') === 'radio') { | |
if ($(this).is(':checked')) { | |
count = 1; | |
} else { | |
count = 0; | |
} | |
} else { | |
count = parseInt($(this).val()); | |
} | |
if (!isNaN(count)) { | |
msal.additional_price = msal.additional_price + add_price * count; | |
msal.discount = add_discount * count; | |
} | |
} | |
}); | |
new_price = miniShop2.Utils.formatPrice(msal.orig_price + msal.additional_price - msal.discount); | |
full_price = miniShop2.Utils.formatPrice(msal.orig_price + msal.additional_price); | |
$(msal.price_target).html(new_price); | |
$(msal.price_full_target).html(full_price); | |
}; | |
$(document).on('change', '.msal_input', msal.calculatePrice); | |
msal.calculatePrice(); | |
$(document).on('msoptionsprice_product_action', function (e, action, form, r) { | |
if (action == 'modification/get' && r.success && r.data) { | |
$(msal.price_target).hide(); | |
$(msal.price_orig_target).val(r.data.modification['cost']); | |
setTimeout(function(){ | |
msal.calculatePrice(); | |
$(msal.price_target).show(); | |
},100); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment