Skip to content

Instantly share code, notes, and snippets.

@Javiani
Last active November 26, 2015 19:32
Show Gist options
  • Save Javiani/b04d933ee7150fc57f44 to your computer and use it in GitHub Desktop.
Save Javiani/b04d933ee7150fc57f44 to your computer and use it in GitHub Desktop.
product-list-replace
;(function(){
var
lists = $('.product-list'),
services = '/services/get-complete-product-vo.jsp',
n = 2;
lists.each( eachList );
function eachList(idx, ul){
if(idx < n)
$(ul).find('.product-list-item').each( eachProduct );
}
function eachProduct(idx, product){
var link = $( product ).find('a');
params = getParams( link );
$.getJSON( services, params )
.then(function( resultVO ){ return resultVO.value; })
.done(function( vo ){
if(!vo) return;
addBadge( link, vo );
addOldPrice( link, vo);
});
}
function getParams(link){
var sku = link.attr('href').split(/\//).pop();
sku = sku.split(/\-/);
return{
_org : 'home',
productId :sku.slice(0, 2).join('-'),
skuId :sku.join('-')
};
}
function addBadge(product, vo){
if(vo && vo.badge){
var tpl = '<span class="base-badge badge-sport-friday" style="background-color:#fbd330;">'+vo.badge.value+'</span>';
product.find('.aligner').after( tpl );
}
}
function addOldPrice(product, vo){
if(vo && vo.price){
var tpl = '<del class="old-price">'+vo.price.original_price+'</del>';
product.find('.new-price').after( tpl );
}
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment