Last active
October 20, 2017 22:48
-
-
Save steveosoule/29af1f421cbbb942b3ed9d1115315b1b to your computer and use it in GitHub Desktop.
Miva - PROD Attribute Machine - Generate Discount with Savings Percent
This file contains 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
<script> | |
AttributeMachine.prototype.Generate_Discount = function( discount ) | |
{ | |
var discount_div; | |
var msrp = Number(document.getElementById('price-value-additional').innerHTML.replace(/[\$,]/, '')), | |
savings_percent = Math.round(discount.discount / msrp * 100), | |
savings_percent_formatted = savings_percent + '%'; | |
// console.log('Generate_Discount', discount, msrp, savings_percent, savings_percent_formatted ); | |
discount_div = document.createElement( 'div' ); | |
discount_div.innerHTML = 'You Save: ' + savings_percent_formatted + '<br>' + discount.descrip + ': ' + discount.formatted_discount; | |
return discount_div; | |
} | |
AttributeMachine.prototype.Generate_Swatch = function( product_code, attribute, option ) | |
{ | |
var swatch = document.createElement( 'li' ); | |
var span = document.createElement( 'span' ); // to vertically center the swatch images | |
var img = document.createElement( 'img' ); | |
img.src = option.image; | |
swatch.appendChild( span ); | |
swatch.appendChild( img ); | |
return swatch; | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment