javascript must be enabled for this site

Yosef Sahler – Web Developer

Javascript, AJAX, and Salesforce Marketing Cloud Developer at your service. Tell me what you need...

Submit

Thank You

Salesforce Marketing Cloud Salesforce Marketing Cloud
jQuery jQuery
php MySQL php MySQL
AJAX AJAX
Turning this: Beringer Cart Before
Into this: Beringer Cart After
                
//Last modified: 2018-12-11
$(document).ready( function() {
    // Change to cart summary
    if (docURL.indexOf("storecart.showcart") > -1 || docURL.indexOf("/cart") > -1 || docURL.indexOf("method=storecart%2eshowcart") > -1){
        // Change shipping options drop down to radio buttons
        $("#shippingOptionsForm .heading h4").html("Select your shipping option:");
        $(".cart-wrapper select.form-control").each( function(ind) {
            var shippingList = "<div class='shipping-options'>";
            $(this).find("option").each( function() {
                shippingList += "<input type='radio' name='";
                shippingList += $(this).closest("select").attr("name");
                shippingList += "' ";
                shippingList += "value='" + $(this).attr("value") + "' ";
                if ($(this).closest("select").val() == $(this).val()) {
                    shippingList += "checked ";
                    localStorage.setItem("shippingLevel" + ind, $(this).html()); //this is for validation on shipping page
                }
                shippingList += "> ";
                //shippingList += $(this).html().replace(/((.*))(\s\(\$(.*)$)/,"$2");
                shippingList += $(this).html();
                shippingList += "<br>";
            });
            shippingList += "</div>";
            $(this).after(shippingList + "<br><br>");
            $(this).remove();
        });
        //Add a discounts row in cart totals
        var totalDiscount = 0;
        $(".coupon-list .coupon .baseprice").each( function() {
            totalDiscount += $(this).html().replace(/\D/gi,"")/100;
        });
        if (totalDiscount > 0) {
            $(".cart-totals .table-striped").after("<div style='text-align:center;padding-bottom:20px;font-weight:bold;'>You Save: $" + totalDiscount.toFixed(2)+ "</div>");
        }
        // rearrange shopping cart elements
        $(".desktop-summary").after("<div id='afterTable' class='hidden-xs'></div>");
        $("#afterTable").html("<div class='col-xs-8' id='leftCol'></div><div class='col-xs-4' id='rightCol'></div>");
        $("#leftCol").html($(".desktop-summary").clone());
        $("#afterTable th[colspan='2'], #afterTable td[colspan='2']").attr("colspan","");
        $("#leftCol .thead-title").css("width","40%");
        $("#leftCol .thead-price, #leftCol .thead-total, #leftCol .cart-price, #leftCol .cart-total").css("text-align","left");
        $("#leftCol .btn-sm.remove").css("margin-top","0px");
        $("#rightCol").html("<div class='row'><div class='col-xs-12'>" + $(".cart-totals").html() + "</div></div>");
        $("#rightCol .row").addClass("cart-totals");
        $("#rightCol .cart-totals").after("<div class='row' id='shippingOptRow'>" + $(".shipping-row:eq(1)").html() + "</div>");
        $("#rightCol .col-sm-offset-8").removeClass("col-sm-offset-8 col-sm-4");
        $("#rightCol #shippingOptRow").after($(".offerCode").closest("form").parent().html());
        $("#rightCol .form-heading.special-offers").html("<div class='row'><div class='col-xs-12'>" + $("#rightCol .offerCode").html() + "</div></div><div class='row'><div class='col-xs-12'>" + $("#rightCol .appliedDiscounts").html() + "</div></div>");
        $("#rightCol #divCoupon, label[for='coupon-codes'], .desktop-summary:eq(0)").remove();
        $(".cart-wrapper .totals-row, .cart-wrapper .shipping-row").addClass("visible-xs");
        $("#rightCol").css("border","1px solid #ccc").css("border-radius","3px").css("padding-bottom","20px").css("background-color","#ddddddcc");
        $(".panel-shipping").find("h2").after("<div class='col-sm-3' style='text-align:right'>" + $(".btn.btn-primary.checkout.continue.next").parent().html() + "</div>");
        $(".btn.btn-primary.checkout.continue.next:eq(0)").hide();
        $(".btn.btn-primary.checkout.continue.next").attr("type","button").attr("onclick","document.location.href='/index.cfm?method=storecheckout.personalinformation&type=shipping'");
        // add input change function 
        $(".shipping-options input[type='radio']").each( function() {
            $(this).on("change", function() {
                $(this).closest("#shippingOptionsForm")[0].submit();
            });
        });
        $("input[name='Quantity']").attr("onkeydown","");
        $("#cart-summary tbody .cart-qty button[type='submit']").each( function() {
            $(this).attr("type","button")
            .on("click", function (c,p,q) {
                $.post ("/index.cfm?method=storecart.updateProductQuantity", 
                    {
                        cartitemid: $(this).closest("tr").prev().prev().val(),
                        productid: $(this).closest("tr").prev().val(),				
                        Quantity: $(this).siblings("input[name='Quantity']").val(),
                        updateDonation: "0",
                        donationIsPercentage: "0",
                        sessionKey: $("input[name='sessionKey']:eq(1)").val()
                    }, function() { document.location.reload(); });
            });
        });
        // hide ship to radio button on shipping state selector modal
        $("#ShipOptionsState[type='radio']").hide();
        //Add holiday deadline modal
        if (new Date(2018,11,22).valueOf() > new Date().valueOf()) {
            $(".top-buttons").append('<a data-toggle="modal" href="#holidayModal" class="btn btn-default" style="margin-right:5px;">Holiday Shipping Dates</a>');
            $("footer").before(holidayModal);
            $("#holidayModal h3").css("margin-top","0px");
            $("#holidayModal .modal-body").css("padding-bottom","0px");
            
            $("#holidayStateSelect").on("change", function() {
              $("#holidayStateSelect option[value='State']").remove();
              if ($("#holidayStateSelect").val() == "CA") {
                $("#holidayModal .modal-body:eq(1) .text-left:eq(1)").html(
                  "Ground Shipping: Order by Thursday, December 13"
                );
                $("#holidayModal .modal-body:eq(2) .text-left:eq(1)").html(
                  "Ground Shipping: Order by Wednesday, December 19"
                );
                $("#holidayZipcode")
                  .css("display", "inherit")
                  .on("blur keypress keyup", function() {
                    if (/\d{5}/.test($(this).val())) {
                      $(
                        "#holidayModal .modal-body:eq(1),#holidayModal .modal-body:eq(2)"
                      ).removeClass("hidden");
                      if (BayAreaZips.includes(parseInt($(this).val()))) {
                        $(
                          "#holidayModal .modal-body:eq(1) .text-left:eq(3),#holidayModal .modal-body:eq(2) .text-left:eq(3)"
                        ).removeClass("hidden");
                      } else {
                        $(
                          "#holidayModal .modal-body:eq(1) .text-left:eq(3),#holidayModal .modal-body:eq(2) .text-left:eq(3)"
                        ).addClass("hidden");
                      }
                    }
                  });
              } else {
                $("#holidayZipcode").css("display", "none");
                $(
                  "#holidayModal .modal-body:eq(1) .text-left:eq(3),#holidayModal .modal-body:eq(2) .text-left:eq(3)"
                ).addClass("hidden");
                $(
                  "#holidayModal .modal-body:eq(1),#holidayModal .modal-body:eq(2)"
                ).removeClass("hidden");
                $("#holidayModal .modal-body:eq(1) .text-left:eq(1)").html(
                  "Ground Shipping: Order by Thursday, December 11"
                );
                $("#holidayModal .modal-body:eq(2) .text-left:eq(1)").html(
                  "Ground Shipping: Order by Friday, December 17"
                );
              }
            });
            
            if (document.cookie.split("SHIPPINGSTATE").length > 1) {
                $("#holidayStateSelect option[selected='selected'").removeAttr("selected");
                $("#holidayStateSelect").val(document.cookie.split("SHIPPINGSTATE=")[1].split(";")[0]);
                $("#holidayStateSelect option[value='" + document.cookie.split("SHIPPINGSTATE=")[1].split(";")[0] + "']").attr("selected","selected");
                $("#holidayStateSelect").change();
            }
        }
    }
    // prop 65 quick fix
    if (docURL.indexOf("storecheckout.showpaymentinformation") > -1){
        var cookieObj2 = splitify(document.cookie.split(";"),"=",1);
        if (cookieObj2.SHIPPINGSTATE === "CA") {
            var propWarning = "<div class='row'><div class='col-xs-12' style='border: 2px solid #000;padding: 10px;'><span style='font-weight:bold;'>WARNING</span>: Drinking distilled spirits, beer, coolers, wine and other alcoholic beverages may increase cancer risk, and, during pregnancy, can cause birth defects.  For more information go to www.P65Warnings.ca.gov/alcohol.</div></div>";
            $(".content-area.container-fluid").append(propWarning);
            //fix for st clement classname
            if (docURL.indexOf("stclement") > -1) {
                $(".contentarea").append(propWarning);
            }
        }
    }
    // START BRAND SPECIFIC FIXES
    
    //beringer
    if (docURL.indexOf("beringer") > -1) {
        moveGiftMessage(docURL);
    }
    
    //cellar 360
    if (docURL.indexOf("cellar360") > -1) {
        $(".col-sm-5ths h4").css("text-align","center").css("font-size","1.2em");
        moveGiftMessage(docURL);
    }
    // penfolds
    if (docURL.indexOf("penfolds") > -1) {
        moveGiftMessage(docURL);
        if ($(".col-sm-5ths:contains('Club Membership')").length === 1) {
            $("div .content-area.container-fluid").css("padding-top","20px");
        }
        $(".modal-dialog").css("margin-top",$(".layout-header").outerHeight() + $(".layout-header").position().top + 30 + "px");
    }
    // acacia
    if (docURL.indexOf("acaciavineyard") > -1) {
        moveGiftMessage(docURL);
        $(".col-sm-5ths h4").css("margin-top","15px");
        $(".preferences.mb-2").hide();
    }
    // BV
    if (docURL.indexOf("bvwines") > -1) {
        moveGiftMessage(docURL);
        $(".col-sm-5ths h4").hover(function(){$(this).css("font-weight","bold");}, function(){$(this).css("font-weight","normal");});
        $(".preferences.mb-2").hide();
        //fix number shipments drop down on CM details page
        $("[name='TotalNumberOfShipments']").css("min-width","140px");
        //fix po-box color
        $(".po-box").css("color","#c59646");
    }
    // provenancevineyards
    if (docURL.indexOf("provenancevineyards") > -1) {
        moveGiftMessage(docURL);
        if (urlParams.method != "members.showlogin") {
            $(".subnavarea").hide();
            $(".header-container a:contains('My Account')").attr("href","/logout").html("Logout");
        }
    }
    // sterlingvineyards
    if (docURL.indexOf("sterlingvineyards") > -1) {
        moveGiftMessage(docURL);
        $(".preferences.mb-2").hide();
    }
});
                
            
HTML HTML
CSS CSS
JavaScript JavaScript
Bootstrap Bootstrap