function retrieveProductsInUserCart(userEmail){
        var products_keys = [];
        var products_values = [];
        var k = 0;
        var price;
        user_cart_ref = firebase.firestore().collection("Cart").doc(userEmail);
        user_cart_ref.get().then(function(doc){
            if(doc.exists){
                products_keys = Object.keys(doc.data());
                products_values = Object.values(doc.data());
                var product_ref = firebase.firestore().collection('Products');
                product_ref.get().then(function(querySnapshot){
                    querySnapshot.forEach(function(doc) {
                        var key = doc.id;
                        for (var i = 0; i < products_keys.length; i++){
                            if (key == products_keys[i]){
                                var product_info = doc.data();
                                for(var j = 0; j < products_values[i].length; j++){
                                    createHTMLElements(key, product_info.type, products_values[i][j].id);
                                    advance_notice_list.push(product_info.advanceNotice);
                                    product_names = $('.item-name h5');
                                    quantity_indicator = $('.quantity-number');
                                    products_prices = $('.price');
                                    products_sizes = $('.size-number');
                                    other_notes = $('.other-notes');

                                    product_names.eq(k).html(product_info.name);
                                    if(product_info.type == "b"){
                                        if(products_values[i][j]["size"] === "7 inch"){
                                            price = product_info.price[0];
                                        }
                                        else if(products_values[i][j]["size"] === "9 inch"){
                                            price = product_info.price[1];
                                        }
                                    }
                                    else{
                                        price = product_info.price;
                                    }
                                    var dollar_amount = price.slice(0, -2);
                                    var cents_amount = price.slice(-2);
                                    products_prices.eq(k).html("$" + dollar_amount + cents_amount.sup() +  "<span class='currency'> CAD</span>");
                                    quantity_indicator.eq(k).html(products_values[i][j]["quantity"]);
                                    products_sizes.eq(k).html(products_values[i][j]["size"]);
                                    
                                    if(product_info.type == "b"){
                                        if(products_values[i][j]["decorationSelected"]){
                                            other_notes.eq(k).append("<strong>Text Piping - </strong> " + products_values[i][j]["decorationText"] + "</br>");
                                        }
                                    }
                                    if(product_info.type == "m"){
                                        var separator = "";
                                        other_notes.eq(k).append("<strong>Flavors - </strong>");
                                        $.each(products_values[i][j]["macaronFlavors"], function(key, value) {
                                            other_notes.eq(k).append(separator + key);
                                            separator = ", ";
                                        });
                                        other_notes.eq(k).append("</br>");
                                    }
                                    if(products_values[i][j]["numberCandleIsSelected"]){
                                        other_notes.eq(k).append("<strong>Number Candle - </strong> #" + products_values[i][j]["numberCandleNumber"] + "</br>");
                                    }
                                    if(products_values[i][j]["standardCandleIsSelected"]){
                                        other_notes.eq(k).append("<strong>Standard Candle Pack</strong>" + "</br>");
                                    }
                                    if(products_values[i][j]["wishCardIsSelected"]){
                                        other_notes.eq(k).append("<strong>Wish Card - </strong>" + products_values[i][j]["wishCardText"] + "</br>");
                                    }

                                    k++;

                                    if(products_values[i][j]["decorationSelected"]){
                                        piping_cost += piping_price;
                                    }
                                    if(products_values[i][j]["standardCandleIsSelected"]){
                                        standard_candle_cost += standard_candle_price;
                                    }
                                    if(products_values[i][j]["numberCandleIsSelected"]){
                                        number_candle_cost += number_candle_price;
                                    }
                                    if(products_values[i][j]["wishCardIsSelected"]){
                                        wish_card_cost += wish_card_price;
                                    }
                                    subtotal += (parseInt(price) * parseInt(products_values[i][j]["quantity"]))  / 100 ;
                                    delivery_cost = calculateDeliveryCost(subtotal);
                                    tax = calculateTax(tax_rate, subtotal);
                                    total = calculateTotal(subtotal, tax, delivery_cost, piping_cost, standard_candle_cost, number_candle_cost, wish_card_cost);
                                }
                                break;
                            }
                        }
                    });
                    buildOrderSummaryTable(subtotal, delivery_cost, tax, coupon_amount, total, piping_cost, standard_candle_cost, number_candle_cost, wish_card_cost);
                })
            }
            
            else{
                $('.items_container').remove();
            }
        })
    }
// retrieves the number of products in the user's cart
retrieves the number of products in the user's cart
retrieves the number of products in the user ' s cart
function retrieveProductsInUserCart(userEmail){
        var products_keys = [];
        var products_values = [];
        var k = 0;
        var price;
        user_cart_ref = firebase.firestore().collection("Cart").doc(userEmail);
        user_cart_ref.get().then(function(doc){
            if(doc.exists){
                products_keys = Object.keys(doc.data());
                products_values = Object.values(doc.data());
                var product_ref = firebase.firestore().collection('Products');
                product_ref.get().then(function(querySnapshot){
                    querySnapshot.forEach(function(doc) {
                        var key = doc.id;
                        for (var i = 0; i < products_keys.length; i++){
                            if (key == products_keys[i]){
                                var product_info = doc.data();
                                for(var j = 0; j < products_values[i].length; j++){
                                    createHTMLElements(key, product_info.type, products_values[i][j].id);
                                    advance_notice_list.push(product_info.advanceNotice);
                                    product_names = $('.item-name h5');
                                    quantity_indicator = $('.quantity-number');
                                    products_prices = $('.price');
                                    products_sizes = $('.size-number');
                                    other_notes = $('.other-notes');
                                    product_names.eq(k).html(product_info.name);
                                    if(product_info.type == "b"){
                                        if(products_values[i][j]["size"] === "7 inch"){
                                            price = product_info.price[0];
                                        }
                                        else if(products_values[i][j]["size"] === "9 inch"){
                                            price = product_info.price[1];
                                        }
                                    }
                                    else{
                                        price = product_info.price;
                                    }
                                    var dollar_amount = price.slice(0, -2);
                                    var cents_amount = price.slice(-2);
                                    products_prices.eq(k).html("$" + dollar_amount + cents_amount.sup() +  "<span class='currency'> CAD</span>");
                                    quantity_indicator.eq(k).html(products_values[i][j]["quantity"]);
                                    products_sizes.eq(k).html(products_values[i][j]["size"]);
                                    if(product_info.type == "b"){
                                        if(products_values[i][j]["decorationSelected"]){
                                            other_notes.eq(k).append("<strong>Text Piping - </strong> " + products_values[i][j]["decorationText"] + "</br>");
                                        }
                                    }
                                    if(product_info.type == "m"){
                                        var separator = "";
                                        other_notes.eq(k).append("<strong>Flavors - </strong>");
                                        $.each(products_values[i][j]["macaronFlavors"], function(key, value) {
                                            other_notes.eq(k).append(separator + key);
                                            separator = ", ";
                                        });
                                        other_notes.eq(k).append("</br>");
                                    }
                                    if(products_values[i][j]["numberCandleIsSelected"]){
                                        other_notes.eq(k).append("<strong>Number Candle - </strong> #" + products_values[i][j]["numberCandleNumber"] + "</br>");
                                    }
                                    if(products_values[i][j]["standardCandleIsSelected"]){
                                        other_notes.eq(k).append("<strong>Standard Candle Pack</strong>" + "</br>");
                                    }
                                    if(products_values[i][j]["wishCardIsSelected"]){
                                        other_notes.eq(k).append("<strong>Wish Card - </strong>" + products_values[i][j]["wishCardText"] + "</br>");
                                    }
                                    k++;
                                    if(products_values[i][j]["decorationSelected"]){
                                        piping_cost += piping_price;
                                    }
                                    if(products_values[i][j]["standardCandleIsSelected"]){
                                        standard_candle_cost += standard_candle_price;
                                    }
                                    if(products_values[i][j]["numberCandleIsSelected"]){
                                        number_candle_cost += number_candle_price;
                                    }
                                    if(products_values[i][j]["wishCardIsSelected"]){
                                        wish_card_cost += wish_card_price;
                                    }
                                    subtotal += (parseInt(price) * parseInt(products_values[i][j]["quantity"]))  / 100 ;
                                    delivery_cost = calculateDeliveryCost(subtotal);
                                    tax = calculateTax(tax_rate, subtotal);
                                    total = calculateTotal(subtotal, tax, delivery_cost, piping_cost, standard_candle_cost, number_candle_cost, wish_card_cost);
                                }
                                break;
                            }
                        }
                    });
                    buildOrderSummaryTable(subtotal, delivery_cost, tax, coupon_amount, total, piping_cost, standard_candle_cost, number_candle_cost, wish_card_cost);
                })
            }
            else{
                $('.items_container').remove();
            }
        })
    }
function retrieveProductsInUserCart ( userEmail ) { var products_keys = [ ] ; var products_values = [ ] ; var k = 0 ; var price ; user_cart_ref = firebase . firestore ( ) . collection ( "Cart" ) . doc ( userEmail ) ; user_cart_ref . get ( ) . then ( function ( doc ) { if ( doc . exists ) { products_keys = Object . keys ( doc . data ( ) ) ; products_values = Object . values ( doc . data ( ) ) ; var product_ref = firebase . firestore ( ) . collection ( 'Products' ) ; product_ref . get ( ) . then ( function ( querySnapshot ) { querySnapshot . forEach ( function ( doc ) { var key = doc . id ; for ( var i = 0 ; i < products_keys . length ; i ++ ) { if ( key == products_keys [ i ] ) { var product_info = doc . data ( ) ; for ( var j = 0 ; j < products_values [ i ] . length ; j ++ ) { createHTMLElements ( key , product_info . type , products_values [ i ] [ j ] . id ) ; advance_notice_list . push ( product_info . advanceNotice ) ; product_names = $ ( '.item-name h5' ) ; quantity_indicator = $ ( '.quantity-number' ) ; products_prices = $ ( '.price' ) ; products_sizes = $ ( '.size-number' ) ; other_notes = $ ( '.other-notes' ) ; product_names . eq ( k ) . html ( product_info . name ) ; if ( product_info . type == "b" ) { if ( products_values [ i ] [ j ] [ "size" ] === "7 inch" ) { price = product_info . price [ 0 ] ; } else if ( products_values [ i ] [ j ] [ "size" ] === "9 inch" ) { price = product_info . price [ 1 ] ; } } else { price = product_info . price ; } var dollar_amount = price . slice ( 0 , - 2 ) ; var cents_amount = price . slice ( - 2 ) ; products_prices . eq ( k ) . html ( "$" + dollar_amount + cents_amount . sup ( ) + "<span class='currency'> CAD</span>" ) ; quantity_indicator . eq ( k ) . html ( products_values [ i ] [ j ] [ "quantity" ] ) ; products_sizes . eq ( k ) . html ( products_values [ i ] [ j ] [ "size" ] ) ; if ( product_info . type == "b" ) { if ( products_values [ i ] [ j ] [ "decorationSelected" ] ) { other_notes . eq ( k ) . append ( "<strong>Text Piping - </strong> " + products_values [ i ] [ j ] [ "decorationText" ] + "</br>" ) ; } } if ( product_info . type == "m" ) { var separator = "" ; other_notes . eq ( k ) . append ( "<strong>Flavors - </strong>" ) ; $ . each ( products_values [ i ] [ j ] [ "macaronFlavors" ] , function ( key , value ) { other_notes . eq ( k ) . append ( separator + key ) ; separator = ", " ; } ) ; other_notes . eq ( k ) . append ( "</br>" ) ; } if ( products_values [ i ] [ j ] [ "numberCandleIsSelected" ] ) { other_notes . eq ( k ) . append ( "<strong>Number Candle - </strong> #" + products_values [ i ] [ j ] [ "numberCandleNumber" ] + "</br>" ) ; } if ( products_values [ i ] [ j ] [ "standardCandleIsSelected" ] ) { other_notes . eq ( k ) . append ( "<strong>Standard Candle Pack</strong>" + "</br>" ) ; } if ( products_values [ i ] [ j ] [ "wishCardIsSelected" ] ) { other_notes . eq ( k ) . append ( "<strong>Wish Card - </strong>" + products_values [ i ] [ j ] [ "wishCardText" ] + "</br>" ) ; } k ++ ; if ( products_values [ i ] [ j ] [ "decorationSelected" ] ) { piping_cost += piping_price ; } if ( products_values [ i ] [ j ] [ "standardCandleIsSelected" ] ) { standard_candle_cost += standard_candle_price ; } if ( products_values [ i ] [ j ] [ "numberCandleIsSelected" ] ) { number_candle_cost += number_candle_price ; } if ( products_values [ i ] [ j ] [ "wishCardIsSelected" ] ) { wish_card_cost += wish_card_price ; } subtotal += ( parseInt ( price ) * parseInt ( products_values [ i ] [ j ] [ "quantity" ] ) ) / 100 ; delivery_cost = calculateDeliveryCost ( subtotal ) ; tax = calculateTax ( tax_rate , subtotal ) ; total = calculateTotal ( subtotal , tax , delivery_cost , piping_cost , standard_candle_cost , number_candle_cost , wish_card_cost ) ; } break ; } } } ) ; buildOrderSummaryTable ( subtotal , delivery_cost , tax , coupon_amount , total , piping_cost , standard_candle_cost , number_candle_cost , wish_card_cost ) ; } ) } else { $ ( '.items_container' ) . remove ( ) ; } } ) }
retrieves the number of products in the user's cart
retrieves the number of products in the user ' s cart