Skip to content

Instantly share code, notes, and snippets.

@daksamedia
Created March 27, 2019 10:42
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 daksamedia/761f4ab66fce062f3613ea485cd3d2d1 to your computer and use it in GitHub Desktop.
Save daksamedia/761f4ab66fce062f3613ea485cd3d2d1 to your computer and use it in GitHub Desktop.
bljapikp_1
function getItemKp(itemdIds, callback, loadMoreOptions){
if(itemdIds.length > 0){
$.ajax({
type : "POST", url : baseUrl + "/kp/itemCache", data : "itemIds="+itemdIds , timeout: 5000, success : function(data) {
/** list Property
*
* data.id item Id
* data.title item name
* data.price item price
* data.saleprice item saleprice
* data.linkUrl item PDP link
* data.image item image uploaded by seller
* data.ribbon discount value
* data.quantity quantity produk
* data.qtyStatus status quantity produk (available = 1 / not-available = 0)
* data.discountEndTime discount end-time for item LTD
* data.countdown countdown for limit discount time (LTD)
* data.limitNum limit quantity for LTD
*/
var arrOffShelfItem = itemdIds.slice();
if(data){
var arrData = eval(data);
$.each(itemdIds, function(n, value) {
var checkResult = false;
$.each(arrData, function(index, content){
if(value == content.id && (value != undefined && content.id != undefined)){
$(".salePrice-"+value).html("Rp "+content.salePrice+" ");
$(".price-"+value+" del").html("Rp "+content.price+" ");
var price = Number(content.price.replace(/[^0-9\,]+/g,""));
var salePrice = Number(content.salePrice.replace(/[^0-9\,]+/g,""));
if(content.ribbon == undefined && (price != undefined && price > 0)){
content.ribbon = ((price - salePrice) / price) * 100;
content.ribbon = Math.round(content.ribbon);
}
$(".dis-"+value).html(""+content.ribbon+"% ");
if(content.ribbon == undefined && (price == undefined || price < 1)){
$(".dis-"+value).hide();
}
if(content.countdown != undefined && content.countdown > 0) {
arrCountdown[arrCountdownPrefix+""+value] = content.countdown;
setInterval("countdownFun("+value+")", 1000);
}else{
if($(".countdown-"+value))
$(".countdown-"+value).hide();
}
if(content.price == undefined || content.price < 1){
$(".price-"+value).css("opacity","0");
$(".price-"+value).css("height","23px");
}
var prodImg = $("div[itemId="+value+"]").find("img.swiper-lazy");
if(prodImg) {
if (content.image.indexOf("tokopedia") !== -1) {
prodImg.attr("data-src", ""+content.image);
prodImg.attr("src", ""+content.image);
}else{
prodImg.attr("data-src", ""+content.image+"?w=200");
prodImg.attr("src", ""+content.image+"?w=200");
}
}
var prodImg2 = $("div[itemId="+value+"]").find("img.lazy");
if(prodImg2) {
if (content.image.indexOf("tokopedia") !== -1) {
prodImg2.attr("data-original", ""+content.image);
prodImg2.attr("src", ""+content.image);
}else{
prodImg2.attr("data-original", ""+content.image+"?w=200");
prodImg2.attr("src", ""+content.image+"?w=200");
}
}
//var prodImg = $("div[itemId="+value+"]").find("#gambar");
//if(prodImg) {
//prodImg.css("background-image", "url("+content.image+"_348x348.jpg)");
//}
var prodTitle = $("div[itemId="+value+"]").find("h2");
if(prodTitle) {
prodTitle.html(content.title);
}
////item.blanja.com/item/jual-beli-eolins-5-sarung-bantal-sofa-daun-jsps044-rainbow-14586720?ref=[Onsite-20162104-17-3-CP000253-14586720]
//ref=[Onsite-dateCamp-week-category-CampId-ProductId]
//ref=[Onsite-20162104-17-3-CP000253-14586720]
// define your tracking here
//var tracking = "ref=[Onsite-20160612-49-1-CP000578-"+value+"]";
var linkPdp = content.linkUrl;
// var linkPdpWithTracking = linkPdp + "?" + tracking;
var pdpHref = $("div[itemId="+value+"]").find("a");
if(pdpHref) {
pdpHref.attr("href", linkPdp);
}
var i = arrOffShelfItem.indexOf(value);
arrOffShelfItem.splice(i, 1);
}
});
});
}
if(arrOffShelfItem != undefined && arrOffShelfItem.length > 0){
$.each(arrOffShelfItem, function(index, value){
$("div[itemid="+value+"]").hide();
$("div[itemid="+value+"]").attr("data-tag", "");
});
}
if(callback === "showItems") {
loadMoreOptions.reloadSuccess = true;
showItems(loadMoreOptions);
//window[callback](loadMoreOptions);
} else if (callback === "no-callback"){
$.each(itemdIds, function(n, value) {
$j(".box").find(".kpItemId[value="+this+"]").closest(".box").show();
});
//$(loadMoreOptions.items_selector).slice(0, loadMoreOptions.items_per_page).show();
}
//$.getScript('//cdnjs.cloudflare.com/ajax/libs/jquery.lazyload/1.9.1/jquery.lazyload.min.js',function(){$('.img-responsive').lazyload({}); });
}, error : function(xhr, status){
if(callback === "showItems") {
loadMoreOptions.reloadSuccess = false;
showItems(loadMoreOptions);
//window[callback](loadMoreOptions);
} else if (callback === "no-callback"){
//$(loadMoreOptions.items_selector).slice(0, loadMoreOptions.items_per_page).show();
}
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment