Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save steveosoule/29af1f421cbbb942b3ed9d1115315b1b to your computer and use it in GitHub Desktop.
Save steveosoule/29af1f421cbbb942b3ed9d1115315b1b to your computer and use it in GitHub Desktop.
Miva - PROD Attribute Machine - Generate Discount with Savings Percent
<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