Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
checkout.js SSL fail
var checkout_data = {
product : "",
variation:0,
flavour_set :true,
selected_flavour:"",
specific_flavours:[]
};
function navigate_step(step){
$(".one_button .step").removeClass("active");
$("#step"+step).addClass("active");
$(".step-data").hide();
$(".step-data.step-data-"+step).show();
$(window).scrollTop($(".main_sub").offset().top);
}
$(document).ready(function(e) {
$(".step").click(function(e) {
navigate_step($(this).data().step);
return false;
});
$(".select-product").click(function(e) {
checkout_data.product = $(this).data().id;
navigate_step(2);
return false;
});
$(".select_variation").click(function(e) {
var amount = $(this).data().variation, height = 0;
switch(amount){
case 0: height = 0; break;
case 6: height = 42; break;
case 12: height = 84; break;
case 18: height = 126; break;
case 24: height = 168; break;
}
checkout_data.variation = amount;
$(".select_variation").removeClass("change");
$(this).addClass("change");
$("#nicotin_indicator").css("display", amount==0?"none":"block");
$("#nicotin_indicator").height(height)
$("#nicotin_strength_text").html(amount+"mg");
return false;
});
$(".select_variation").hover(function(e) {
var amount = $(this).data().variation, height = 0;
switch(amount){
case 0: height = 0; break;
case 6: height = 42; break;
case 12: height = 84; break;
case 18: height = 126; break;
case 24: height = 168; break;
}
checkout_data.variation = amount;
/* $(".select_variation").removeClass("change");
$(this).addClass("change");*/
$("#nicotin_indicator").css("display", amount==0?"none":"block");
$("#nicotin_indicator").height(height)
$("#nicotin_strength_text").html(amount+"mg");
return false;
});
$("#nicotine_next").click(function(e) {
navigate_step(3);
return false;
});
$(".single-choice").click(function(e) {
$(".single-choice").removeClass("active");
$(".single-choice").parent().removeClass("active");
$(this).addClass("active");
$(this).parent().addClass("active");
checkout_data.flavour_set = true;
checkout_data.selected_flavour = $(this).data().flavor;
$(".multi-choose").removeClass("active");
$(".multi-choose").parent().removeClass("active");
checkout_data.specific_flavours = [];
return false;
});
$(".multi-choose").click(function(e) {
if($(this).is(".active")){
$(this).removeClass("active");
$(this).parent().removeClass("active");
}else{
$(this).addClass("active");
$(this).parent().addClass("active");
}
$(".single-choice").removeClass("active");
$(".single-choice").parent().removeClass("active");
checkout_data.flavour_set = false;
checkout_data.selected_flavour = "";
var select_flavors = new Array();
$(".multi-choose.active").each(function() {
select_flavors.push($(this).data().flavor);
});
checkout_data.specific_flavours = select_flavors;
return false;
});
$("#show_more_flavor").click(function(e) {
$("#more_flavors").slideDown();
$(this).hide();
$('#hide_more_flavor').show();
return false;
});
$("#hide_more_flavor").click(function(e) {
$("#more_flavors").slideUp();
$(this).hide();
$('#show_more_flavor').css("display","inline-block");
return false;
});
$("#finish_selection").click(function(e) {
var _data = checkout_data;
if(_data.product==""){
alert("Please select a product.");
navigate_step(1);
}else if((_data.flavour_set==true && _data.selected_flavour=="") || (_data.flavour_set==false && _data.specific_flavours.length==0)){
alert("Please select flavour.");
navigate_step(3);
}else{
$(this).hide();
$("#submitting_survey").show();
var post_data = {
"mf:cart.details.Nicotine Strength.string" : _data.variation+"mg",
"redirect_url":"/subscribe/"
};
if(_data.flavour_set==true){
post_data["mf:cart.details.Flavour.string"] = _data.selected_flavour;
}else{
var flavor_list = "";
for(var i=0; i<_data.specific_flavours.length; i++){
flavor_list += (flavor_list==""?"":", ")+_data.specific_flavours[i];
}
post_data["mf:cart.details.Flavour.string"] = flavor_list;
}
$.ajax({
url:"/cart/survey",
data:post_data,
type:"post",
success:function(){
window.location = "/subscribe/"+_data.product;
}
});
}
return false;
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment