Merged in feature/from-pantheon (pull request #16)

code from pantheon

* code from pantheon
This commit is contained in:
Tony Volpe
2024-01-10 17:03:02 +00:00
parent 054b4fffc9
commit 4eb982d7a8
16492 changed files with 3475854 additions and 0 deletions

View File

@@ -0,0 +1,665 @@
var woo = {};
(function($) {
//Keys required for accessing the woocommerce api calls (Referenced in woo.getRatePlan, woo.getCoreProduct, and woo.displayProtectionPlan)
var consumer_key = "ck_63c6c0c6c1a22a78c0cbfdc9f344f74ba6c42f3b";
var consumer_secret = "cs_71499bc1c4a6429ff1c6aca680a97b0cc74b2d95";
var _self = this;
_self.productInfo = undefined; //Stores product information retrieved from API call
_self.productVariations = undefined;//Stores product variation information from API call in woo.getRatePlan
_self.cart = undefined; //Stores the cart object created in woo.displayFallDetection
_self.productName = undefined; //Stores that name of the product given in woo.getRatePlan
//Function to parse together the html for the product cards based on the product JSON object sent
woo.createRateButtons = function(product) {
//regularPrice = parseFloat(product.regular_price).toFixed(2);
var card = '';
var ratePromotions = '';
var displayPrice;
salePrice = parseFloat(product.sale_price).toFixed(2);
ratePromotions = product.attributes[6].option.split(",");
specialOffer = product.attributes[7].option.split(",");
dPrice = parseFloat(product.price).toFixed(2);
ratePlan = product.attributes[1].option;
product_id = product.id;
noidea = product.attributes[1].option;
card +=
'<a class="et_pb_button et_pb_button_0 mobblk et_pb_bg_layout_dark" data-toggle="modal" title=' + product.attributes[1].option +'" data-product="' + product.id + '" onclick="woo.displayFallDetection(' + "'" + product.id+ "','" + product.price + "','" + product.attributes[1].option + "','" + product.attributes[3].option + "','" + product.sku + "','" + product.attributes[2].option + "','" + product.attributes[5].option + "'" + ')"> Order Now </a>';
//"<a onclick=" + "woo.displayFallDetection(" + "'" + product.id + "','" + product.price + "','" + product.attributes[1].option + "','" + product.attributes[3].option + "','" + product.sku + "','" + product.attributes[2].option + "','" + product.attributes[5].option + "'" + ') "data-toggle="modal" title="' + product.attributes[1].option +'" class="btn btn-orange btn-block iperModalProduct" data-product="' + product.id + '">Select</a>';
return card;
};
//Function to parse together the html for the rate plan cards based on the product JSON object sent
woo.createRateCard = function(product) {
//regularPrice = parseFloat(product.regular_price).toFixed(2);
var card = '';
var ratePromotions = '';
var displayPrice;
salePrice = parseFloat(product.sale_price).toFixed(2);
ratePromotions = product.attributes[6].option.split(",");
specialOffer = product.attributes[7].option.split(",");
dPrice = parseFloat(product.price).toFixed(2);
ratePlan = product.attributes[1].option;
card +=
'<div class="prtrow">' +
'<div class="prtcolumn30"><label for="'+ratePlan+'" class="radiolbl">'+ratePlan+'</label></div>' +
'<div class="prtcolumn30 prtcolumn65mob paddtop0smob">' +
'<p class="prodcost">$'+dPrice+'/mo. <span class="small-red-txt">'+specialOffer+' </span></p>' +
'<p class="showmob prodoffer2"><strong>'+ratePromotions+'</p>' +
'</div>' +
'<div class="nsmob prtcolumn35">' +
'<p class="prodoffer2"><strong>'+ratePromotions+'</p>' +
'</div>' +
'<div class="prtcolumn25 paddtop12">' +
'<a class="btn btn-red-learnmore qr-buy-btn red-btn et_pb_bg_layout_light" onmouseover="" style="cursor: pointer;" data-toggle="modal" title=' + ratePlan +'" data-product="' + product.id + '" onclick="woo.displayFallDetection(' + "'" + product.id+ "','" + product.price + "','" + ratePlan + "','" + product.attributes[3].option + "','" + product.sku + "','" + product.attributes[2].option + "','" + product.attributes[5].option + "'" + ' ) "> Select </a>'+
'</div>' +
'</div>';
return card;
};
//Function that does an ajax call returning on all the variations for a specific product.
woo.getRatePlan = function(callback, productId, productName) {
_self.productName = productName;
$.ajax({
async: false,
method: "GET",
url:
"/wp-json/wc/v3/products/" +
productId +
"/variations?per_page=100&order=asc&consumer_key=" +
consumer_key +
"&consumer_secret=" +
consumer_secret,
success: function(data) {
_self.productVariations = data;
callback(data);
}
});
};
//Function that initiates the display and creation of the modal for the upsell fall detection pendents, also creates and does initial insert into cart object.
woo.displayFallDetection = function(id, price, rate_plan, rateplan_sfid, product_sfid, price_mulitplier, promotion) {
//Initial add to cart
_self.cart = new woo.cartPackage();
_self.cart.product_sid = product_sfid;
_self.cart.rateplan_sid = rateplan_sfid;
_self.cart.rateplan_multiplier = price_mulitplier;
_self.cart.product_price = price;
_self.cart.product_rate_price = (parseFloat(price)*parseFloat(price_mulitplier)).toFixed(2);
_self.cart.ratePlan = rate_plan;
if(promotion !== "none"){
_self.cart.promotionId = promotion;
}else{
_self.cart.promotionId = undefined;
}
_self.cart.productName = _self.productName;
//Modal creation
var modal = document.getElementById("modalProduct");
var modalContent = woo.createFallDetectionCard(rate_plan);
$("#modalProduct").html(modalContent);
$("body").append('<div id="modalBackDrop" class="modal-backdrop fade in"></div>');
modal.classList.add("in");
modal.style.display = "block";
};
//Function that generates the html for the Modal Fall Detection Buttons
woo.createFallDetectionCard = function(rate_plan) {
var product = _self.productVariations;
var fd_info;
for (var i = 0; i < product.length; i++) {
if (
product[i].attributes[0].option === "fall" &&
product[i].attributes[1].option === rate_plan
) {
fd_info = product[i];
break;
}
}
fdPrice = parseFloat(fd_info.attributes[4].option).toFixed(2);
var modalContent =
'<div class="modal-dialog modal-lg" role="document">' +
'<div class="modal-content">' +
'<div class="modal-body">' +
'<button class="close" data-dismiss="modal" aria-label="Close" onclick="woo.closeModal()"><span aria-hidden="true">×</span></button>' +
'<div class="row">' +
'<div class="col-md-6 mod-text text-left">' +
'<div class="detail-plan">' +
'<div class="text-plan">' +
"<h2>Add Fall Detection</h2>" +
"<p>With this popular feature your Medical Alert pendant senses a fall and contacts an operator immediately—even if you cant press your button.*</p>" +
"</div>" +
// "<h1>Fall Detection </h1>" +
'<span class="upsell_price">$' +
fdPrice +
"/mo.</span>" +
'<div id="modal-btns" class="modal-btns">' +
'<a onclick="woo.displayProtectionPlan(' +"'" +1 + "','" + rate_plan + "','" + fd_info.attributes[3].option + "','" + fd_info.attributes[4].option + "','" + fd_info.attributes[6].option +
"'" +
')" class="btn et_pb_button et_pb_button_1 btn-red-learnmore et_pb_bg_layout_light modbtn-add iperModalUpsell" id="modalupsell" data-toggle="modal" data-target="#modalProduct69" data-promotion-id="" data-block="" data-upsell="2175,10" data-product-id="10" data-upsell-id="68" data-dismiss="modal">Add to Cart</a>' +
'<a onclick="woo.displayProtectionPlan(' +
"'" +
0 +
"','" +
rate_plan +
"'" +
')" class="blue-btn et_pb_button et_pb_button_1 btn-blue-learnmore et_pb_bg_layout_light modbtn-thanks" id="modalupsell" data-toggle="modal" data-target="#modalProduct69" data-upsell-id="68" data-dismiss="modal">No Thanks</a> ' +
"</div>" +
"</div>" +
"</div>" +
'<div class="col-md-6 upsell_img fd-upsell"></div>' +
"</div>" +
"</div>" +
"</div>" +
"</div>";
return modalContent;
};
//Function that initiates the display and creation of the modal for the upsell protection plan, also adds fall detection data to cart if add to cart is selected.
//Also performs that AJAX call to get the shipping information(Might be better placed somewhere else in the flow but is here for now)
woo.displayProtectionPlan = function(choice, rate_plan, sfID, price, promoID) {
//If Add to Cart is selected on fall detection pendent modal add FDP info to cart
if (choice == 1){
_self.cart.upsells.push([
sfID,
price,
"Fall Detection Button",
parseFloat(_self.cart.rateplan_multiplier) * parseFloat(price),
promoID
]);
}
//AJAX call to get the shipping variations from woocommerce then parse them into the cart object(Maybe better served at different location)
$.ajax({
async: false,
method: "GET",
url:
"/wp-json/wc/v3/products/" +
localStorage.getItem('ShippingInfo') +
"/variations?consumer_key=" +
consumer_key +
"&consumer_secret=" +
consumer_secret,
success: function(data) {
woo.parseShipping(data);
}
});
//creates and displays modal for the Protection Plan
var modal = document.getElementById("modalProduct");
var modalContent = woo.createProtectionPlanCard(rate_plan);
$("#modalProduct").html(modalContent);
modal.classList.add("in");
modal.style.display = "block";
};
//Function that generate the html for the Modal Protection Plan
woo.createProtectionPlanCard = function(rate_plan) {
var product = _self.productVariations;
var pp_info;
for (var i = 0; i < product.length; i++) {
if (
product[i].attributes[0].option === "protection" &&
product[i].attributes[1].option === rate_plan
) {
pp_info = product[i];
break;
}
}
var modalContent =
'<div class="modal-dialog modal-lg" role="document">' +
'<div class="modal-content">' +
'<div class="modal-body">' +
'<button class="close" data-dismiss="modal" aria-label="Close" onclick="woo.closeModal()"><span aria-hidden="true">×</span></button>' +
'<div class="row">' +
'<div class="col-md-6 mod-text protection-text-plan text-left">' +
'<div class="detail-plan">' +
'<div class="text-plan">' +
"<h2>Add a Protection Plan</h2>" +
"<p>Prevent out of pocket expenses up to $350 in case your system is lost, stolen, or damaged with a Protection Plan.</p>" +
"</div>" +
// "<h1>Protection Plan </h1>" +
'<span class="upsell_price">$' +
pp_info.attributes[4].option +
"/mo.</span>" +
'<div id="modal-btns" class="modal-btns">' +
'<a onclick="woo.navShipping(' +
"'1" +
"','" +
pp_info.attributes[3].option +
"','" +
pp_info.attributes[4].option +
"','" +
pp_info.attributes[6].option +
"'" +
')" class="btn et_pb_button et_pb_button_1 btn-red-learnmore et_pb_bg_layout_light modbtn-add iperModalUpsell" id="modalupsell" data-toggle="modal" data-target="#modalProduct69" data-promotion-id="" data-block="" data-upsell="2175,10" data-product-id="10" data-upsell-id="68" data-dismiss="modal">Add to Cart</a>' +
'<a onclick="woo.navShipping(' +
"'0'" +
')" class="blue-btn et_pb_button et_pb_button_1 btn-blue-learnmore et_pb_bg_layout_light modbtn-thanks" id="modalupsell" data-toggle="modal" data-target="#modalProduct69" data-upsell-id="68" data-dismiss="modal">No Thanks</a> ' +
"</div>" +
"</div>" +
"</div>" +
'<div class="col-md-6 upsell_img protection-upsell"></div>' +
"</div>" +
"</div>" +
"</div>" +
"</div>";
return modalContent;
};
//Function that initiates the display and creation of the modal for the upsell protection plan, also adds fall detection data to cart if add to cart is selected.
//Also performs that AJAX call to get the shipping information(Might be better placed somewhere else in the flow but is here for now)
woo.displayProtectionPlanSale = function(choice, rate_plan, sfID, price, promoID) {
//If Add to Cart is selected on fall detection pendent modal add FDP info to cart
if (choice == 1){
_self.cart.upsells.push([
sfID,
price,
"Fall Detection Sale Button",
parseFloat(_self.cart.rateplan_multiplier) * parseFloat(price),
promoID
]);
}
//AJAX call to get the shipping variations from woocommerce then parse them into the cart object(Maybe better served at different location)
$.ajax({
async: false,
method: "GET",
url:
"/wp-json/wc/v3/products/" +
localStorage.getItem('ShippingInfo') +
"/variations?consumer_key=" +
consumer_key +
"&consumer_secret=" +
consumer_secret,
success: function(data) {
woo.parseShipping(data);
}
});
//creates and displays modal for the Protection Plan
var modal = document.getElementById("modalProduct");
var modalContent = woo.createProtectionPlanSaleCard(rate_plan);
$("#modalProduct").html(modalContent);
modal.classList.add("in");
modal.style.display = "block";
};
//Function that generate the html for the Modal Protection Plan
woo.createProtectionPlanSaleCard = function(rate_plan) {
var product = _self.productVariations;
var ppsale_info;
for (var i = 0; i < product.length; i++) {
if (
product[i].attributes[0].option === "protection_sale" &&
product[i].attributes[1].option === rate_plan
) {
ppsale_info = product[i];
break;
}
}
var modalContent =
'<div class="modal-dialog modal-lg" role="document">' +
'<div class="modal-content">' +
'<div class="modal-body">' +
'<button class="close" data-dismiss="modal" aria-label="Close" onclick="woo.closeModal()"><span aria-hidden="true">×</span></button>' +
'<div class="row">' +
'<div class="col-md-6 mod-text protection-text-plan text-left">' +
'<div class="detail-plan">' +
'<div class="text-plan">' +
"<h2>Free Protection Plan</h2>" +
"<p>Prevent out of pocket expenses up to $350 in case your system is lost, stolen, or damaged with a Protection Plan.</p>" +
"</div>" +
"<h1>Protection Plan </h1>" +
'<span class="upsell_price">$' +
ppsale_info.attributes[4].option +
"/mo.</span>" +
'<div id="modal-btns" class="modal-btns">' +
'<a onclick="woo.navShipping(' +
"'1" +
"','" +
ppsale_info.attributes[3].option +
"','" +
ppsale_info.attributes[4].option +
"','" +
ppsale_info.attributes[6].option +
"'" +
')" class="btn et_pb_button et_pb_button_1 btn-red-learnmore et_pb_bg_layout_light modbtn-add iperModalUpsell" id="modalupsell" data-toggle="modal" data-target="#modalProduct69" data-promotion-id="" data-block="" data-upsell="2175,10" data-product-id="10" data-upsell-id="68" data-dismiss="modal">Continue</a>' +
"</div>" +
"</div>" +
"</div>" +
'<div class="col-md-6 upsell_img" style="background: url(/wp-content/uploads/2020/11/Protection-Plan.jpg) no-repeat center / cover; height: 600px; position:absolute; right:0;"></div>' +
"</div>" +
"</div>" +
"</div>" +
"</div>";
return modalContent;
};
//Shows cart when Product is added
woo.getCart = function(){
cartCard = woo.createCart();
$('#preview-order-payment').html(cartCard);
}
woo.getCartItemCount = function(){
var cart = JSON.parse(sessionStorage.getItem('cart'));
return cart.upsells.length + cart.accessories.length + ((cart.product_sid != undefined && cart.product_sid !== '') ? 1 : 0);
}
function resize(){
var cartCheck = sessionStorage.getItem('cart');
var width = jQuery(window).width();
if (cartCheck) {
if (width >= 768) {
jQuery('#carticon').css('display', 'inline');
jQuery('.mobcart').css('display', 'none');
} else {
jQuery('.mobcart').css('display', 'inline-block');
}
}else {
jQuery('.menu-item-29619').css('display','none');
jQuery('.mobcart').css('display','none');
}
}
$(document).ready(function(){
resize();
$(window).resize(resize);
});
//Function that generates the html for the cart to be viewed in the Order Summary Column on the Shipping Page
woo.createCart = function() {
var cartInfo = JSON.parse(sessionStorage.getItem('cart'));
//console.log(cartInfo.ratePlan);
if (cartInfo.ratePlan == "Annually") {
cartInfo.rateplan_multiplier = "12";
//console.log(cartInfo.rateplan_multiplier);
}
var cart =
//console.log(cartInfo.accessories);
'<div class="title">Order Summary</div>' +
'<div id="iperCartDetail" class="order-detail">' +
'<div data-product="12" class="containerIperProduct">' +
'<img src="' + cartInfo.accessories[0][3]+ '" style="float: right;" width="30%">' +
"<!-- PRODOTTO -->" +
'<div class="product">' +
'<span class="name"><strong>'+cartInfo.productName+'</strong></span>' +
"</div>" +
'<div class="clearfix"></div>';
//Builds the rateplan portion of cart
cart+=
"<!-- RATEPLAN -->" +
'<div class="row payment-type">' +
'<div class="col-6 col-md-6">' + cartInfo.ratePlan + "</div>" +
'<div class="col-6 col-md-6 priceff"> <span> $'+cartInfo.product_rate_price+'<strong>/'+cartInfo.rateplan_multiplier+' mo</strong></span></div>' +
"</div>";
//Builds the Upsells portion of cart
if (isNaN(cartInfo.upsells)) {
cart+="<!-- UPSELLS -->" +
'<div class="row upsells">';
for(var i = 0; i<cartInfo.upsells.length; i++){
cart +=
'<div class="col-6 col-md-6">' +
cartInfo.upsells[i][2] +
"</div>" +
'<div class="col-6 col-md-6 price_up"><span class="priceff">$' +
cartInfo.upsells[i][3] +
"<strong>/" +
cartInfo.rateplan_multiplier +
" mo</strong></span></div>";
}
}
cart+="</div>" +
'<div class="clearfix"></div>';
//Builds Accessories portion of cart
cart+="<!-- ACCESSORIES -->" +
'<div class="row">';
for(var i = 0; i<cartInfo.accessories.length; i++){
cart +=
'<div class="col-6 col-md-6">' +
cartInfo.accessories[i][1] +
"</div>" +
'<div class="col-6 col-md-6 price_up"><span class="priceff">$' +
cartInfo.accessories[i][2] +
"</span></div>";
}
cart+=
'<div class="col-12 col-md-12 shipping-label"></div>' +
'<div class="col-6 col-md-6 shipping-type-label"></div>' +
'<div class="col-6 col-md-6 shipping-price"></div>' +
'</div>' +
"<hr>";
//Builds the Total portion of cart
cart+="<!-- TOTAL -->" +
'<div class="row total">' +
'<div class="col-6 col-md-6 total">' +
'<div class="total1"><strong>Total</strong>' +
"</div>" +
"</div>" +
'<div class="col-6 col-md-6 price_up"><span class="price">$'+cartInfo.totalPrice+'</span></div>' +
'<div class="clearfix"></div>' +
"</div>" +
"<!--Session variable to display text on cart page -->" +
'<span id="taxdisclaimer" style="display:none">Plus applicable tax</span>';
var cookies = document.cookie;
var arrayCookies = cookies.split(';');
var sessPromo = '';
var promoLabel = '';
//console.log(cookies);
//console.log(arrayCookies);
for(k in arrayCookies){
//console.log(arrayCookies[k]);
if(arrayCookies[k].includes("SESSpromotion")){
//console.log("Promo found");
var arraySessPromo = arrayCookies[k].split('=');
sessPromo = arraySessPromo[1];
//str.replace(/%20/g, " ");
sessPromo = sessPromo.replace(/%20/g, " ");;
sessPromo = sessPromo.replace(/%24/g, "$");;
promoLabel = "Promotion";
break;
}
}
cart+=
"<!-- PROMOTION -->" +
'<hr>' +
'<div class="row total">' +
'<div class="col-12 col-md-12 total">' +
'<div class="total1"><strong>'+promoLabel+'</strong>' +
"</div>" +
"</div>" +
"</div>" +
'<div class="row total">' +
'<div class="col-12 col-md-12">'+sessPromo+'</div>' +
'<div class="clearfix"></div>' +
"</div>" +
"</div>";
return cart;
};
//Function that gets the object cart out of session storage
woo.packageObject = function() {
var payLoad = sessionStorage.getItem('cart');
return payLoad;
};
//Function that sends the all the information in cart to the dataPassing.php file to be parsed and pushed into Session variables in the server.
woo.postProductInformation = function() {
// $.ajax({
// data: "Package=" + woo.packageObject(),
// //url: "/wp-content/plugins/iper-medical/templates/dataPassing.php",
// url: "/wp-content/plugins/iper-medical/templates/template-product.php",
// async: false,
// method: "POST", // or GET
// success: function() {
// console.log("This was sent with a 200 code");
// alert('success');
// },
// error: function(x, msg, ex) {
// alert('fail');
// console.log(msg);
// }
// });
$('[name="Package"]').val(woo.packageObject);
$('#dataPassing').submit();
};
//Function that performs the AJAX GET call to the woocommerce API for all products
woo.getCoreProducts = function(callback, $) {
$.ajax({
async: false,
method: "GET",
url:
"/wp-json/wc/v3/products?order=asc&consumer_key=" +
consumer_key +
"&consumer_secret=" +
consumer_secret,
success: function(data) {
_self.productInfo = data;
callback(data);
}
});
};
//Function that does the final add to cart for Accessories and Protection Plan choice before sending information over to Server, then navigating page to the
// shipping page.
woo.navShipping = function(choice, sfid, price,promoID, displayFeatimage) {
//If add to cart was chosen for protection plan push information into cart
var product = _self.productVariations;
var ratePlan = _self.cart.ratePlan;
var accessories = _self.cart.accessories;
for(var i = 0; i<product.length; i++){
console.log(product[i].image.src);
let displayFeatimage = product[i].image.src;
};
//Add all Accessories related to product into the cart
for(var i = 0; i<product.length; i++){
if (product[i].attributes[0].option === "accessory") {
if (product[i].attributes[1].option === "all") {
accessories.push([
product[i].attributes[2].option, //Salesforce ID
product[i].attributes[3].option, //Acessory Name
product[i].attributes[4].option, //Programming Fee
product[i].image.src
]);
//alert(product[i].attributes[4].option);
} else if ( product[i].attributes[1].option === ratePlan)
{
accessories.push([
product[i].attributes[2].option, //Salesforce ID
product[i].attributes[3].option, //Acessory Name
product[i].attributes[4].option //Programming Fee
]);
}
}
}
if (ratePlan === 'Annually'){
var pp_total = parseFloat(12) * parseFloat(price);
console.log(ratePlan);
} else {
var pp_total = parseFloat(_self.cart.rateplan_multiplier) * parseFloat(price);
console.log(ratePlan);
}
if(choice == 1){
_self.cart.upsells.push([
sfid,
price,
"Protection Plan",
pp_total,
promoID
]);
}
//Add the total price of order (Upsells + Core) to cart
console.log(productName);
_self.cart.totalPrice = parseFloat(_self.cart.product_price) * parseFloat(_self.cart.rateplan_multiplier) + 79.00;
for(var i = 0; i<_self.cart.upsells.length; i++){
//Takes the initial value for total price and adds to it the unrounded price from the upsell
_self.cart.totalPrice += _self.cart.upsells[i][3];
//Rounds the price for the upsell to 2 decimal places for display purposes
_self.cart.upsells[i][3] = (_self.cart.upsells[i][3]).toFixed(2);
}
//Rounds the final total price to 2 decimal places.
_self.cart.totalPrice = (_self.cart.totalPrice).toFixed(2);
//Sends the cart object to the sessionStorage object to be referenced on shipping page.
sessionStorage.setItem('cart', JSON.stringify(_self.cart));
//Sends the cart object to the Server
woo.postProductInformation();
//Navigates user to next page
//window.location.href = "/medical-shipping.html";
};
//Cart object used to pass information to the Server
woo.cartPackage = function() {
this.images;
this.productName;
this.product_sid;
this.product_price;
this.product_rate_price;
this.ratePlan;
this.rateplan_sid;
this.rateplan_multiplier;
this.upsells = [];
this.accessories = [];
this.totalPrice;
this.promotionId;
this.shippingMethods = [];
};
//Parses the response from the AJAX call to get all shipping prices, pushing into the cart
woo.parseShipping = function(data) {
for(var i = 0; i<data.length; i++){
_self.cart.shippingMethods.push([data[i].attributes[0].option, data[i].attributes[1].option, data[i].attributes[2].option]);
}
};
//Function used to remove the html/css rules that show the modal.
woo.closeModal=function(){
$("#modalProduct").html('');
$("#modalProduct").removeClass('in');
$("#modalProduct").removeAttr("style");
$("#modalBackDrop").remove();
}
})(jQuery);