/* globals jQuery, Modernizr, enquire, smg */ /*! * @file digital-river.js * @class SMG Object Namespacing * @author Jason Han * @Modified by Xi for Mini-Cart enhancement & EPP improvement * @comment Only Page specific functions will be added here * @copyright (c) Samsung SDS America Inc. */ var tryCount = 0; var showCartError = false; var cartErrorMessage='', prdMdlCdDr=''; var tmpWTBPrice = ''; smg.global.digitalRiver = (function(window, document, $, undefined) { "use strict"; var dRCount = 0; var defaults = { container : ".product-module[data-eppMdlCd]", holidayPage: false, defaultCallback : true, successCallback : function(priceList) { },done :function(){ } }, cookie_options = { path : '/', domain : 'samsung.com' }, dr_store_domain = '//shop.us.samsung.com'; function getAllEcom(data){ var modelCodes = _.map(data.cart.lineItems.lineItem, function(item) { return item.product.externalReferenceId; }); return $.ajax({ url : '/us/price/samsungB2CEcomPrice.json', data : modelCodes.toString(), type : 'POST', dataType : 'json', error : function() { // console.log(err); return data; }, success : function(priceList) { // console.log(priceList); if (data.cart.totalItemsInCart > 0) { var items = data.cart.lineItems.lineItem; var itemsCount = items.length; for (var j = 0; j < itemsCount; j++){ var priceRefer = _.find(priceList, function(o) { var id = items[j].product.externalReferenceId; return o.prdMdlCd == id; }); if (priceRefer && priceRefer.prdPriceInf != '') { if (data.cart.lineItems.lineItem[j].quantity > 1) { var price = Number(priceRefer.prdPriceInf.replace(/[$,]+/g, '')) * data.cart.lineItems.lineItem[j].quantity; priceRefer.prdPriceInf = '$' + price.toLocaleString('en'); } data.cart.lineItems.lineItem[j].pricing.formattedListPriceWithQuantity = priceRefer.prdPriceInf; } } } return data; } }).then(function(res) { return data; }); } function loadCart() { } function loadPrice(opts) { if(window.location.href.indexOf("/us/shop/black-friday") > -1 || window.location.href.indexOf("/us/shop/home-appliance-holiday-offers") > -1){ }else{ var options = $.extend({}, defaults, opts); var planId = $.cookie("tppid"); if (typeof (planId) != 'undefined' && planId != null && planId != "") { var modelCodes = new Array(); $(options.container).each(function() { modelCodes[modelCodes.length] = $(this).attr("data-eppMdlCd"); }); if($(options.container).length == 0 && $('#gen-supportsite').length >0 && location.href.indexOf('home-appliances') != -1 && location.href.indexOf('-buy') != -1){ modelCodes = $('#gen-supportsite').data('prdmdlcd'); }else if($(options.container).length == 0 && location.href.indexOf('home-appliances') == -1 && location.href.indexOf('-buy') != -1){ modelCodes = $('.ps-widget').attr('ps-sku'); } var requestData = { referralUrl : document.referrer, planId : planId, modelCodes : modelCodes.toString(), accessToken: $.cookie('DR_SESSION_TOKEN'), holidayPage : options.holidayPage }; $.ajax({ url : '/us/shop/price.us', data : requestData, type : 'POST', dataType : "json", error : function() { if(options.done && typeof options.done === "function"){ options.done(); } }, success : function(priceList) { if(options.defaultCallback) { for ( var i = 0; i < priceList.length; i++) { $(".product-module[data-eppMdlCd = '" + priceList[i].prdMdlCd + "'] .price-module").html( _.template($("#priceTemplate").html(), { price : priceList[i] })); tmpWTBPrice = priceList[i].prdPromoPriceInf; if(location.href.indexOf('home-appliances') != -1 && location.href.indexOf('-buy') != -1 && tmpWTBPrice) { $('.marketplace-page .ps-widget').attr('data-samsung-price', tmpWTBPrice.replace(/\$/g,'').replace(/\,/g,'')); }else if(location.href.indexOf('home-appliances') == -1 && location.href.indexOf('-buy') != -1 && tmpWTBPrice) { $('.marketplace-page .ps-widget').attr('data-samsung-price', tmpWTBPrice.replace(/\$/g,'').replace(/\,/g,'')); }} } if(options.successCallback && typeof options.successCallback === "function"){ options.successCallback(priceList); } if(options.done && typeof options.done === "function"){ options.done(); } } }); }else{ var modelCodes = new Array(); $(options.container).each(function() { if("Y" == $(this).data("ecom") || $(this).data("ecom")){ modelCodes[modelCodes.length] = $(this).attr("data-eppMdlCd"); } }); if(modelCodes.length>0){ getPriceForEcomProducts(modelCodes,options); } if(options.done && typeof options.done === "function"){ options.done(); } } } } function isIE() { var ua = window.navigator.userAgent; var msie = ua.indexOf("MSIE "); if (msie > 0 || !!navigator.userAgent.match(/Trident.*rv\:11\./)) { return true; } else { return false; } } function isEppUser() { var planId = $.cookie("tppid"); if(!!planId) { return true; } else { return false; } } function showEmpty(){ $('.purchase-options').css('display', 'none'); $('.purchase-save').css('display', 'none'); if($(".item-container").length>0){ if($(".item-container").children().length==0){ $(".item-container").prepend('
Your shopping cart is empty.
'); } }else{ $('.cart-container').prepend('Your shopping cart is empty.