Ejemplo n.º 1
0
        $res['itemcount'] += $item['count'];
    }
    $res['viewcart'] = '<input class="btn btn-primary" type="button" value="' . $options['localization']['view_cart']['lbl'] . '">';
    print "" . json_encode($res) . "";
    exit;
}
/****************************************************************************************************************************************
*
*
*	[checkif shop is still open when submitting order]
*
*
****************************************************************************************************************************************/
if (isset($_POST['vars']['type']) && $_POST['vars']['type'] == 'checkifopen') {
    $res = array();
    $isOpen = wpizza_are_we_open($options['opening_times_standard'], $options['opening_times_custom'], $options['times_closed_standard']);
    $isOpen = apply_filters('wppizza_filter_is_open', $isOpen);
    /*let others override*/
    if ($isOpen == 0) {
        //closed -> alert
        $res['isclosed'] = '' . $options['localization']['alert_closed']['lbl'] . '';
    }
    print "" . json_encode($res) . "";
    exit;
}
/************************************************************************************************
*
*
*	[in case one wants to do/add more things in functions.php]
*
*
function wppizza_order_summary($session, $options, $module = null, $ajax = null)
{
    global $blog_id;
    /**allow filtering of options and session**/
    $session = apply_filters('wppizza_filter_order_summary_session', $session);
    $options = apply_filters('wppizza_filter_order_summary_options', $options);
    /***************************************************
    		[in i some vars if undefined]
    	***************************************************/
    if (!isset($session['total_price_calc_delivery'])) {
        $session['total_price_calc_delivery'] = 0;
    }
    /****************************************************
    		[set the original free delivery min_total value as a var
    		to be able to compare against further down and deisplay appropriate
    		text if min order value has also been set
    	******************************************************/
    $orderMinTotalSet = $options['order']['delivery']['minimum_total']['min_total'];
    /****************************************************
    		[get currency]
    	****************************************************/
    $summary['currency'] = '' . $options['order']['currency_symbol'] . '';
    /*do not add any spans or anything else to this as it gets stored in the db */
    $summary['currencyiso'] = '' . wppizza_validate_letters_only($options['order']['currency'], 3) . '';
    //strip any -alt identifiers (serbian currency for example has 2 display options but the same ISO code)
    /****************************************************
    		[set currency positions]
    	****************************************************/
    $summary['currency_left'] = $summary['currency'] . ' ';
    $summary['currency_right'] = '';
    if ($options['layout']['currency_symbol_position'] == 'right') {
        /*right aligned*/
        $summary['currency_left'] = '';
        $summary['currency_right'] = ' ' . $summary['currency'];
    }
    /****************************************************
    		[hide decimals?]
    	****************************************************/
    $optionsDecimals = $options['layout']['hide_decimals'];
    /****************************************************
    		[get cart items as grouped array]
    	****************************************************/
    $cartItems = array();
    //ini array
    $cartItemsCount = 0;
    //count all items
    $groupedItems = array();
    //ini array
    $summary['items'] = array();
    //ini array
    /**lets group items by id and sizes***/
    foreach ($session['items'] as $groupid => $groupitems) {
        foreach ($groupitems as $v) {
            $excludeFromCount = false;
            /**allow items to be excluded from count when calculating delivery prices per item**/
            $excludeFromCount = apply_filters('wppizza_filter_order_summary_exclude_item_from_count', $excludeFromCount, $v);
            if (!$excludeFromCount) {
                $cartItemsCount++;
                //advance counter if not excluded (in case we want to not charge per item on this )
            }
            /**really only for legacy reasons, future versions will only have extend key**/
            if (!isset($v['additionalinfo'])) {
                $v['additionalinfo'] = array();
            }
            if (!isset($v['extend'])) {
                $v['extend'] = array();
            }
            if (!isset($v['extenddata'])) {
                $v['extenddata'] = array();
            }
            /*if not set , add current*/
            if (!isset($v['blogid'])) {
                $v['blogid'] = $blog_id;
            }
            $cartItems['' . $groupid . ''][] = array('sortname' => $v['sortname'], 'size' => $v['size'], 'sizename' => $v['sizename'], 'printname' => $v['printname'], 'price' => $v['price'], 'additionalinfo' => $v['additionalinfo'], 'extend' => $v['extend'], 'extenddata' => $v['extenddata'], 'postId' => $v['id'], 'blogid' => $v['blogid']);
            /**conditional just used to not break other extensions/plugins that have not been updated yet to add selected category id.*/
            if (isset($v['catIdSelected'])) {
                $catIdSelected['' . $groupid . ''] = $v['catIdSelected'];
            } else {
                $catIdSelected['' . $groupid . ''] = '';
            }
        }
    }
    foreach ($cartItems as $k => $v) {
        $groupedItems[$k] = array('sortname' => $cartItems[$k][0]['sortname'], 'size' => $cartItems[$k][0]['size'], 'sizename' => $cartItems[$k][0]['sizename'], 'printname' => $cartItems[$k][0]['printname'], 'price' => $cartItems[$k][0]['price'], 'count' => count($cartItems[$k]), 'total' => count($cartItems[$k]) * $cartItems[$k][0]['price'], 'additionalinfo' => $cartItems[$k][0]['additionalinfo'], 'extend' => $cartItems[$k][0]['extend'], 'extenddata' => $cartItems[$k][0]['extenddata'], 'postId' => $cartItems[$k][0]['postId'], 'catIdSelected' => $catIdSelected[$k], 'blogid' => $cartItems[$k][0]['blogid']);
    }
    asort($groupedItems);
    /**output items sorted by name and size**/
    foreach ($groupedItems as $k => $v) {
        /*in a multisite setup we need to sitch to the right blog if necessary**/
        if (is_multisite() && $v['blogid'] != $blog_id) {
            switch_to_blog($v['blogid']);
        }
        /*get categories**/
        $catObj = get_the_terms($v['postId'], WPPIZZA_TAXONOMY);
        /*restore blog if needed*/
        if (is_multisite() && $v['blogid'] != $blog_id) {
            restore_current_blog();
        }
        /*get categories**/
        $catObj = get_the_terms($v['postId'], WPPIZZA_TAXONOMY);
        $catArray = json_decode(json_encode($catObj), true);
        /*get meta value**/
        $objMeta = get_post_meta($v['postId'], WPPIZZA_SLUG);
        $taxRate = $options['order']['item_tax'];
        // check if we are using alt tax value
        if (!empty($objMeta[0]['item_tax_alt'])) {
            $taxRate = $options['order']['item_tax_alt'];
        }
        /*******************************************************************************************
        			if other extensions have yet to add selcatid, just add the first one
        			the item is categorised in.
        			90% of the time there will only be one anyway, so this would be correct.
        			worst case scenario, an unexpected (although not wrong) category will be displayed
        			all of this is only relevant anyway if "show category for emails etc" is enabled in layout
        		*******************************************************************************************/
        if ($v['catIdSelected'] == '') {
            /*make sure a category was also actually assigned*/
            if (is_array($catArray)) {
                $firstCat = reset($catArray);
                $v['catIdSelected'] = $firstCat['term_id'];
            } else {
                $v['catIdSelected'] = '';
            }
        }
        $summary['items'][$k] = array('name' => $v['printname'], 'count' => $v['count'], 'size' => $v['sizename'], 'price' => wppizza_output_format_price($v['price'], $optionsDecimals), 'pricetotal' => wppizza_output_format_price($v['total'], $optionsDecimals), 'categories' => $catArray, 'taxrate' => $taxRate, 'additionalinfo' => $v['additionalinfo'], 'extend' => $v['extend'], 'extenddata' => $v['extenddata'], 'postId' => $v['postId'], 'catIdSelected' => $v['catIdSelected'], 'blogid' => $v['blogid']);
    }
    /****************************************************
    		[if ajax request get items from template to keep formatting consistent]
    	****************************************************/
    if ($ajax) {
        $summary['itemsajax'] = do_shortcode('[wppizza type="cart" request="ajax"]');
    }
    /**********************************
    		[discounts]
    	**********************************/
    /** no discount**/
    $discountLabel = '';
    $discountValue = '';
    $discountValuePrint = '';
    if ($options['order']['discount_selected'] == 'none') {
        $discountApply = 0;
    }
    /*loose php notice**/
    $session['total_price_calc_discount'] = isset($session['total_price_calc_discount']) ? $session['total_price_calc_discount'] : $session['total_price_items'];
    /** percentage discount**/
    if ($options['order']['discount_selected'] == 'percentage') {
        /**sort highest to lowest and check if it aplies, if it does, apply and stop loop (only want to appply one!**/
        $discountApply = 0;
        /**get most relevant discount to apply to price***/
        rsort($options['order']['discounts']['percentage']['discounts']);
        foreach ($options['order']['discounts']['percentage']['discounts'] as $k => $v) {
            if ($session['total_price_calc_discount'] >= $v['min_total']) {
                $discountApply = round($session['total_price_calc_discount'] / 100 * $v['discount'], 2);
                break;
            }
        }
        /**get all available discounts to display***/
        sort($options['order']['discounts']['percentage']['discounts']);
        foreach ($options['order']['discounts']['percentage']['discounts'] as $k => $v) {
            if ($v['discount'] > 0) {
                // && $v['min_total']>0
                $summary['pricing_discounts'][] = "" . $options['localization']['spend']['lbl'] . " <span>" . $summary['currency_left'] . "" . wppizza_output_format_price($v['min_total'], $optionsDecimals) . "" . $summary['currency_right'] . "</span> " . $options['localization']['save']['lbl'] . " <span>" . $v['discount'] . "%</span>";
            }
        }
    }
    /** value discount**/
    if ($options['order']['discount_selected'] == 'standard') {
        /**sort highest to lowest and check if it aplies, if it does, apply and stop loop (only want to appply one!**/
        $discountApply = 0;
        /**get most relevant discount to apply to price***/
        rsort($options['order']['discounts']['standard']['discounts']);
        foreach ($options['order']['discounts']['standard']['discounts'] as $k => $v) {
            if ($session['total_price_calc_discount'] >= $v['min_total']) {
                $discountApply = $v['discount'];
                break;
            }
        }
        /**get all available discounts to display***/
        sort($options['order']['discounts']['standard']['discounts']);
        foreach ($options['order']['discounts']['standard']['discounts'] as $k => $v) {
            if ($v['discount'] > 0) {
                //&& $v['min_total']>0
                $summary['pricing_discounts'][] = "" . $options['localization']['spend']['lbl'] . " <span>" . $summary['currency_left'] . " " . wppizza_output_format_price($v['min_total'], $optionsDecimals) . "" . $summary['currency_right'] . "</span> " . $options['localization']['save']['lbl'] . " <span>" . $summary['currency_left'] . "" . wppizza_output_format_float($v['discount']) . "" . $summary['currency_right'] . "</span>";
            }
        }
    }
    /***self pickup discount added to other discounts (if any)**/
    if ($options['order']['order_pickup_discount'] > 0 && isset($session['selfPickup'])) {
        $discountApply = $discountApply + $session['total_price_calc_discount'] / 100 * $options['order']['order_pickup_discount'];
    }
    /**allow filtering of discounts**/
    $discountApply = apply_filters('wppizza_filter_discount', $discountApply, $session, $module);
    if (isset($discountApply) && $discountApply > 0) {
        $discountLabel = $options['localization']['discount']['lbl'];
        $discountValue = wppizza_output_format_float($discountApply);
        $discountValuePrint = wppizza_output_format_price($discountValue, $optionsDecimals);
    }
    /**********************************
    				[delivery]
    			**********************************/
    $deliveryLabel = $options['localization']['free_delivery']['lbl'];
    //initialize var
    $deliveryCharges = '';
    if ($options['order']['delivery_selected'] == 'no_delivery') {
        /*delivery disabled*/
        $deliveryCharges = '';
        /*set to empty to hide*/
        $deliveryLabel = '';
        /*set to empty to hide*/
        /*set flag for 'no delivery'*/
        $summary['no_delivery'] = 1;
        $summary['self_pickup_enabled'] = 1;
        $summary['selfPickup'] = 2;
        /**set to >1 to not display self pickup note/text in emails and order page*/
        /**disable self pickup checkboxes*/
        $options['order']['order_pickup'] = false;
    }
    if ($options['order']['delivery_selected'] == 'standard') {
        //standard (i.e. fixed delivery charges)
        /**delivery settings to display with discount options somewhere*/
        if ($options['order']['delivery']['standard']['delivery_charge'] > 0) {
            $deliveryLabel = $options['localization']['delivery_charges']['lbl'];
            $deliveryCharges = wppizza_output_format_float($options['order']['delivery']['standard']['delivery_charge']);
        }
    }
    if ($options['order']['delivery_selected'] == 'minimum_total') {
        //minimum total
        if ($options['order']['delivery']['minimum_total']['deliver_below_total']) {
            if ($session['total_price_calc_delivery'] < $options['order']['delivery']['minimum_total']['min_total']) {
                $deliveryLabel = $options['localization']['delivery_charges']['lbl'];
                $deliveryCharges = wppizza_output_format_float($options['order']['delivery']['minimum_total']['min_total'] - $session['total_price_calc_delivery']);
            }
        }
        /**fixed price set if below free delivery: overrides "deliver_below_total" **/
        if ($options['order']['delivery']['minimum_total']['deliverycharges_below_total'] > 0) {
            if ($session['total_price_calc_delivery'] < $options['order']['delivery']['minimum_total']['min_total']) {
                $deliveryLabel = $options['localization']['delivery_charges']['lbl'];
                $deliveryCharges = wppizza_output_format_float($options['order']['delivery']['minimum_total']['deliverycharges_below_total']);
            }
        }
        /**if we are hiding decimals recalc/round delivery charges or we might get rounding errors**/
        if ($deliveryCharges > 0 && $optionsDecimals) {
            $recalc = wppizza_output_format_float($deliveryCharges, 'hidedecimals');
            if ($recalc <= 0) {
                $deliveryLabel = $options['localization']['free_delivery']['lbl'];
                $deliveryCharges = '';
            } else {
                $deliveryCharges = $recalc;
            }
        }
        /**delivery settings to display with discount options somewhere*/
        if ($options['order']['delivery']['minimum_total']['min_total'] > 0) {
            $summary['pricing_delivery'] = "" . $options['localization']['free_delivery_for_orders_of']['lbl'] . " <span>" . $summary['currency_left'] . "" . wppizza_output_format_price($options['order']['delivery']['minimum_total']['min_total'], $optionsDecimals) . "" . $summary['currency_right'] . "</span>";
        } else {
            $summary['pricing_delivery'] = "" . $options['localization']['free_delivery']['lbl'] . "";
        }
    }
    if ($options['order']['delivery_selected'] == 'per_item') {
        /*delivery charges on a per item basis*/
        /**free delivery isset>0**/
        if ($options['order']['delivery']['per_item']['delivery_per_item_free'] > 0) {
            /*value not reached for free delivery*/
            if ($session['total_price_calc_delivery'] < $options['order']['delivery']['per_item']['delivery_per_item_free']) {
                /*number of items*deliverycharges per item*/
                if ($cartItemsCount > 0 && $options['order']['delivery']['per_item']['delivery_charge_per_item'] > 0) {
                    $deliveryCharges = wppizza_output_format_float($cartItemsCount * $options['order']['delivery']['per_item']['delivery_charge_per_item']);
                }
            }
        } else {
            /*no free delivery set (i.e set to 0)*/
            /*number of items*deliverycharges per item*/
            if ($cartItemsCount > 0) {
                $deliveryCharges = wppizza_output_format_float($cartItemsCount * $options['order']['delivery']['per_item']['delivery_charge_per_item']);
            }
        }
        /*label next to delivery charges if>0 otherwise default above->free*/
        if ($deliveryCharges > 0) {
            $deliveryLabel = $options['localization']['delivery_charges']['lbl'];
        }
        /**delivery settings to display with discount options somewhere*/
        if ($options['order']['delivery']['per_item']['delivery_per_item_free'] > 0) {
            $summary['pricing_delivery'] = "" . $options['localization']['delivery_charges_per_item']['lbl'] . " <span>" . $summary['currency_left'] . "" . wppizza_output_format_price($options['order']['delivery']['per_item']['delivery_charge_per_item'], $optionsDecimals) . "" . $summary['currency_right'] . "</span>";
            $summary['pricing_delivery_per_item_free'] = "" . $options['localization']['free_delivery_for_orders_of']['lbl'] . " <span>" . $summary['currency_left'] . "" . wppizza_output_format_price($options['order']['delivery']['per_item']['delivery_per_item_free'], $optionsDecimals) . "" . $summary['currency_right'] . "</span>";
        } else {
            $summary['pricing_delivery'] = "" . $options['localization']['delivery_charges_per_item']['lbl'] . " <span>" . $summary['currency_left'] . "" . wppizza_output_format_price($options['order']['delivery']['per_item']['delivery_charge_per_item'], $optionsDecimals) . "" . $summary['currency_right'] . "</span>";
        }
    }
    /*******************************************
     *	admin enabled self pickup on the frontend
     ******************************************/
    if ($options['order']['order_pickup']) {
        $summary['self_pickup_enabled'] = 1;
        $summary['order_self_pickup'] = $options['localization']['order_self_pickup']['lbl'];
        $summary['order_self_pickup_cart'] = $options['localization']['order_self_pickup_cart']['lbl'];
        $summary['order_page_self_pickup'] = $options['localization']['order_page_self_pickup']['lbl'];
        /*check where we want to display self pickup checkbox*/
        if ($options['order']['order_pickup_display_location'] == 1 || $options['order']['order_pickup_display_location'] == 3) {
            $summary['self_pickup_cart'] = 1;
        }
        if ($options['order']['order_pickup_display_location'] == 2 || $options['order']['order_pickup_display_location'] == 3) {
            $summary['self_pickup_order_page'] = 1;
        }
        $summary['selfPickup'] = 0;
        /*default off*/
        /*customer chose self pickup. set appropriate values in cart*/
        if (isset($session['selfPickup'])) {
            $summary['selfPickup'] = 1;
            /*indicate that self pcikup chosen*/
            $deliveryCharges = 0;
            /*set delivery charges to 0*/
        }
        /**set id for checkbox to see if we have enabled js alerts**/
        if ($options['order']['order_pickup_alert']) {
            $summary['selfPickupId'] = 'wppizza-order-pickup-js';
        } else {
            $summary['selfPickupId'] = 'wppizza-order-pickup-sel';
        }
    }
    /**allow filtering of delivery charges**/
    $deliveryCharges = apply_filters('wppizza_filter_delivery_charges', $deliveryCharges, $session, $options, $module);
    /*******************************************
     *	set min order values (delivery/pickup)
     ******************************************/
    /**minimum order value set but not reached -> on delivery - as long as its not set to $options['order']['delivery_selected']==no_delivery***/
    if (!isset($session['selfPickup']) && $options['order']['delivery_selected'] != 'no_delivery') {
        if ($options['order']['order_min_for_delivery'] > 0 && $options['order']['order_min_for_delivery'] > $session['total_price_calc_delivery']) {
            /*disable place order button**/
            $placeOrderDisabled = true;
            /**set min_total value to be min order for delivery**/
            $options['order']['delivery']['minimum_total']['min_total'] = $options['order']['order_min_for_delivery'];
            /**set min order info txt**/
            $options['localization']['minimum_order']['lbl'] = $options['localization']['minimum_order_delivery']['lbl'];
        }
    }
    /**minimum order value set but not reached -> on pickup or if set to pickup only***/
    if (isset($session['selfPickup']) || $options['order']['delivery_selected'] == 'no_delivery') {
        /**minimum order value set but not reached -> self pickup***/
        if ($options['order']['order_min_for_pickup'] > 0 && $options['order']['order_min_for_pickup'] > 0 && $options['order']['order_min_for_pickup'] > $session['total_price_calc_delivery']) {
            /*disable place order button**/
            $placeOrderDisabled = true;
            /**set min_total value to be min order for pickup**/
            $options['order']['delivery']['minimum_total']['min_total'] = $options['order']['order_min_for_pickup'];
            /**set min order info txt**/
            $options['localization']['minimum_order']['lbl'] = $options['localization']['minimum_order']['lbl'];
        }
    }
    /*************************************************************************
     *
     *
     *	[Taxes]
     *
     *
     *************************************************************************/
    /****************************************************
    				[tax on sum of all items BEFORE discounts. currently not in use]
    			****************************************************/
    $itemTax = 0;
    /**ini as 0**/
    $taxesIncluded = 0;
    /**ini as 0**/
    $summary['taxrate'] = $options['order']['item_tax'];
    /*capture/set taxrate**/
    $summary['taxrate_alt'] = $options['order']['item_tax_alt'];
    /*capture/set alternative taxrate**/
    /**********************************************************
     *
     *	[tax NOT included in set prices]
     *
     **********************************************************/
    if (!$options['order']['taxes_included']) {
        /***********************************************************
         *	as we may have different taxrates on different items
         *	and need to make sure that dicounts - as they are before tax -
         *	are applied correctly, we must calculate the resulting taxrate
         ***********************************************************/
        $calcTaxSum = 0;
        $calcItemsSum = 0;
        foreach ($groupedItems as $giKey => $item) {
            /*
            	taxrate from summary as it does not exist in grouped items yet
            */
            $itemTaxRate = $summary['items'][$giKey]['taxrate'];
            $calcTaxSum += $item['total'] / 100 * $itemTaxRate;
            $calcItemsSum += $item['total'];
        }
        /***if cart is empty, use defaults to avoid division by zero notice***/
        if ($calcItemsSum <= 0) {
            $avgTaxRate = 0;
        } else {
            $avgTaxRate = $calcTaxSum / ($calcItemsSum / 100);
        }
        $summary['taxrate_avg'] = $avgTaxRate;
        /*capture/set average taxrate**/
        /****************************************************
        				[set var for ident later if necessary]
        			****************************************************/
        $summary['tax_applied'] = 'items_only';
        /****************************************************
        				[item tax AFTER discounts]
        			****************************************************/
        if ($options['order']['item_tax'] > 0 || $options['order']['item_tax_alt'] > 0) {
            $summary['tax_enabled'] = 1;
            $totalSales = $session['total_price_items'] - (double) $discountValue;
            /*round up decimals**/
            $itemTax = wppizza_round_up($totalSales / 100 * $avgTaxRate, 2);
            /****************************************************
            				[add tax to shipping too]
            			****************************************************/
            if ($options['order']['shipping_tax']) {
                $summary['tax_applied'] = 'items_and_shipping';
                /*set location*/
            }
            if ($options['order']['shipping_tax'] && $deliveryCharges != '' && (int) $deliveryCharges > 0) {
                // ???????????? check
                $itemTax = wppizza_round_up($totalSales / 100 * $avgTaxRate + $deliveryCharges / 100 * $options['order']['shipping_tax_rate'], 2);
            }
        }
    }
    /**********************************************************
     *
     *	[tax IS included in prices !!!]
     *
     **********************************************************/
    if ($options['order']['taxes_included']) {
        /***********************************************************
         *	as we may have different taxrates on different items
         *	and need to make sure that dicounts - as they are before tax -
         *	are applied correctly, we must calculate the resulting taxrate
         *	
         *	as $summary['items'] might already by formatted to have prices 
         *	with commas, use the prices from grouped items
         ***********************************************************/
        $calcTaxSum = 0;
        $calcItemsSumBeforeTax = 0;
        foreach ($groupedItems as $giKey => $item) {
            /*
            	taxrate from summary as it does not exist in grouped items yet
            */
            $itemTaxRate = $summary['items'][$giKey]['taxrate'];
            $calcTaxItem = $item['total'] / (100 + $itemTaxRate) * $itemTaxRate;
            /*tax on this item**/
            $calcTaxSum += $calcTaxItem;
            $calcItemsSumBeforeTax += $item['total'] - $calcTaxItem;
        }
        /***if cart is empty, use defaults to avoid division by zero notice***/
        if ($calcItemsSumBeforeTax <= 0) {
            $avgTaxRate = 0;
        } else {
            $avgTaxRate = $calcTaxSum / ($calcItemsSumBeforeTax / 100);
        }
        /**we need to recalculate the tax included if we are also applying a discount to the total (alrady taxed) items***/
        if ((double) $discountValue > 0) {
            $calcTaxSum -= $discountValue / (100 + $avgTaxRate) * $avgTaxRate;
            //take the average tax and use it to get the included tax on the discount to substract
        }
        /****************************************************
        				[set var for ident later if necessary]
        			****************************************************/
        $summary['tax_applied'] = 'taxes_included';
        /****************************************************
        				[add tax to items only]
        			****************************************************/
        if ($options['order']['item_tax'] > 0 || $options['order']['item_tax_alt'] > 0) {
            $summary['tax_enabled'] = 1;
            $totalSales = $session['total_price_items'] - (double) $discountValue;
            $taxesIncluded = wppizza_round_up($calcTaxSum, 2);
        }
        /****************************************************
        				[add tax to shipping too]
        			****************************************************/
        if ($options['order']['shipping_tax'] && $deliveryCharges != '' && (int) $deliveryCharges > 0) {
            if ($options['order']['shipping_tax_rate'] > 0) {
                /***avoid division by zero notice***/
                $deliveryChargesTax = $deliveryCharges / (100 + $options['order']['shipping_tax_rate']) * $options['order']['shipping_tax_rate'];
            } else {
                $deliveryChargesTax = 0;
            }
            $taxesIncluded = wppizza_round_up($calcTaxSum + $deliveryChargesTax, 2);
        }
    }
    /*********************************************************************
     *
     *
     *	[surcharges handling charges]
     *
     *
     **********************************************************************/
    /****************************************************
    				[total order before tips]
    			****************************************************/
    $totalOrderBeforeTips = $session['total_price_items'] - (double) $discountValue + (double) $deliveryCharges + (double) $itemTax;
    /****************************************************
    				[surcharges]
    			****************************************************/
    $surcharges = 0;
    $surchargePcVal = $session['gateway-selected']['surchargePc'];
    $surchargeFixedVal = $session['gateway-selected']['surchargeFixed'];
    /*charges percent*/
    if ($surchargePcVal > 0) {
        $surcharges += $totalOrderBeforeTips / 100 * abs($surchargePcVal);
    }
    /*charges fixed*/
    if ($surchargeFixedVal > 0) {
        $surcharges += $surchargeFixedVal;
    }
    /**round*/
    if ($surcharges > 0) {
        $surcharges = wppizza_round_up($surcharges, 2);
    }
    /*********************************************************************
     *
     *
     *	[gratuities]
     *
     *
     **********************************************************************/
    $gratuities = 0;
    if (isset($session['tips']) && $session['tips'] > 0) {
        $gratuities = wppizza_output_format_price($session['tips'], $optionsDecimals);
        $summary['tips'] = array('lbl' => $options['localization']['tips']['lbl'], 'val' => $gratuities);
    }
    /****************************************************
    		[get total order value]
    	****************************************************/
    $totalOrder = $session['total_price_items'] - (double) $discountValue + (double) $deliveryCharges + (double) $itemTax + (double) $gratuities;
    /**if customer chose self pickup, display only label that states self pickup . no need for value**/
    $deliveryValue = wppizza_output_format_price($deliveryCharges, $optionsDecimals);
    $summary['order_value'] = array('item_tax' => array('lbl' => $options['localization']['item_tax_total']['lbl'], 'val' => wppizza_output_format_price($itemTax, $optionsDecimals)), 'taxes_included' => array('lbl' => sprintf('' . $options['localization']['taxes_included']['lbl'] . '', $options['order']['item_tax']), 'val' => wppizza_output_format_price($taxesIncluded, $optionsDecimals)), 'total_price_items' => array('lbl' => $options['localization']['order_items']['lbl'], 'val' => wppizza_output_format_price(wppizza_output_format_float($session['total_price_items']), $optionsDecimals)), 'delivery_charges' => array('lbl' => $deliveryLabel, 'val' => $deliveryValue), 'discount' => array('lbl' => $discountLabel, 'val' => $discountValuePrint), 'total' => array('lbl' => $options['localization']['order_total']['lbl'], 'val' => wppizza_output_format_price(wppizza_output_format_float($totalOrder), $optionsDecimals)));
    /*******************************************************
    		[gateways must handle surcharges themselves and
    		update the db accordingly. However, to display
    		surcharges on gateway change in the orderpage
    		we overwrite the total here for display before
    		actually processing and without adding them to the db]
    	*******************************************************/
    if ($surcharges > 0 && ($module == 'orderpage' || $module == 'confirmationpage')) {
        $summary['order_value']['total'] = array('lbl' => $options['localization']['order_total']['lbl'], 'val' => wppizza_output_format_price(wppizza_output_format_float($totalOrder + $surcharges), $optionsDecimals));
        $summary['order_value']['handling_charge'] = array('lbl' => $options['localization']['order_page_handling']['lbl'], 'val' => wppizza_output_format_price(wppizza_output_format_float($surcharges), $optionsDecimals));
    }
    if ($session['gateway-selected']['surchargeAtCheckout'] && ($module == 'orderpage' || $module == 'confirmationpage')) {
        $summary['order_value']['handling_charge'] = array('lbl' => $options['localization']['order_page_handling']['lbl'], 'str' => $options['localization']['order_page_handling_oncheckout']['lbl']);
    }
    /****************************************************
    		[check if we are open]
    	****************************************************/
    if (!isset($options['opening_times_custom'])) {
        $options['opening_times_custom'] = array();
    }
    /*get rid of some php notices*/
    if (!isset($options['times_closed_standard'])) {
        $options['times_closed_standard'] = array();
    }
    /*get rid of some php notices*/
    $isOpen = wpizza_are_we_open($options['opening_times_standard'], $options['opening_times_custom'], $options['times_closed_standard']);
    /***allow filtering of is_open**/
    $options = apply_filters('wppizza_filter_order_summary_options_open', $options, $isOpen);
    $session = apply_filters('wppizza_filter_order_summary_session_open', $session, $isOpen);
    $isOpen = apply_filters('wppizza_filter_is_open', $isOpen);
    $summary['shopopen'] = $isOpen;
    $summary['button'] = '';
    $summary['nocheckout'] = '';
    if ($isOpen == 0) {
        //closed -> display closed in cart element
        $summary['innercartinfo'] = $options['localization']['closed']['lbl'];
    }
    if ($isOpen == 1) {
        //open
        if (count($summary['items']) <= 0) {
            //open but nothing in cart -> display 'cart is empty' in cart element
            $summary['innercartinfo'] = $options['localization']['cart_is_empty']['lbl'];
        }
        if (count($summary['items']) > 0) {
            //open and stuff in cart -> check min value reached in do/dont display button and info
            if (($options['order']['delivery_selected'] == 'minimum_total' && ($options['order']['delivery']['minimum_total']['deliver_below_total'] || !$options['order']['delivery']['minimum_total']['deliver_below_total'] && $session['total_price_calc_delivery'] >= $options['order']['delivery']['minimum_total']['min_total']) || $options['order']['delivery_selected'] == 'standard' || $options['order']['delivery_selected'] == 'no_delivery' || $options['order']['delivery_selected'] == 'per_item') && !isset($placeOrderDisabled)) {
                if ($options['order']['orderpage']) {
                    //go to order page
                    /**wpml select of order page**/
                    if (function_exists('icl_object_id')) {
                        $options['order']['orderpage'] = icl_object_id($options['order']['orderpage'], 'page');
                        /*confirmation page -> amend order link**/
                        if ($options['confirmation_form_amend_order_link'] > 0) {
                            $options['confirmation_form_amend_order_link'] = icl_object_id($options['confirmation_form_amend_order_link'], 'page');
                        }
                    }
                    $summary['orderpagelink'] = get_page_link($options['order']['orderpage']);
                    /*confirmation page -> amend order link**/
                    if ($options['confirmation_form_amend_order_link'] > 0) {
                        $summary['amendorderlink'] = get_page_link($options['confirmation_form_amend_order_link']);
                    } else {
                        $summary['amendorderlink'] = '';
                    }
                    $summary['button'] = '<a href="' . $summary['orderpagelink'] . '">';
                    $summary['button'] .= '<input class="btn btn-primary" type="button" value="' . $options['localization']['place_your_order']['lbl'] . '" />';
                    $summary['button'] .= '</a>';
                }
            } else {
                /**free delivery and charges > min order value*/
                if ($options['order']['delivery_selected'] == 'minimum_total' && $orderMinTotalSet == $options['order']['delivery']['minimum_total']['min_total']) {
                    //&& $orderMinTotalSet>=$options['order']['delivery']['minimum_total']['min_total']
                    $summary['nocheckout'] = '' . $options['localization']['minimum_order_delivery']['lbl'] . ' ';
                } else {
                    $summary['nocheckout'] = '' . $options['localization']['minimum_order']['lbl'] . ' ';
                }
                $summary['nocheckout'] .= '' . $summary['currency_left'] . '' . wppizza_output_format_price($options['order']['delivery']['minimum_total']['min_total'], $optionsDecimals) . '' . $summary['currency_right'] . '';
            }
        }
        /****************************************************
        			[empty cart button, show/hide depending if enabled or no of items]
        		*****************************************************/
        if (!empty($options['layout']['empty_cart_button']) && count($summary['items']) > 0) {
            $summary['button'] .= '<input class="wppizza-empty-cart-button btn btn-primary" type="button" value="' . $options['localization']['empty_cart']['lbl'] . '" />';
        }
    }
    /**enable increase/decrease in cart**/
    if ($options['layout']['cart_increase']) {
        $summary['increase_decrease'] = 1;
    }
    $summary = apply_filters('wppizza_filter_summary', $summary);
    return $summary;
}
Ejemplo n.º 3
0
 		orderinfo=1				(optional[bool]: anything. if its defined it gets displayed)
 		stickycart=1			(optional[bool]: anything. if its defined it scrolls)
 		minicart=1				(optional[bool]: anything. if its defined it gets displayed)
 		width='200px' 			(optional[str]: value in px or % ) (although under 150px is probably bad)
 		height='200' 			(optional[str]: value in px )
	example: 		[wppizza type='cart']
**********************************************/
if ($type == 'cart') {
    /*disable shoppingcart when disable_online_order is set */
    if (isset($this->pluginOptions['layout']['disable_online_order']) && $this->pluginOptions['layout']['disable_online_order'] == 1) {
        $markup = '';
        return $markup;
    } else {
        /**caching plugin enabled->insert empty div to be filled with cart by ajax request**/
        if ($this->pluginOptions['plugin_data']['using_cache_plugin'] && !isset($atts['request'])) {
            $isOpen = wpizza_are_we_open($this->pluginOptions['opening_times_standard'], $this->pluginOptions['opening_times_custom'], $this->pluginOptions['times_closed_standard']);
            $markup = "<div class='wppizza-cart-nocache'><div class='wppizza-cart-nocacheinner'>";
            $markup .= "<div id='wppizza-loading'></div>";
            /**we need to pass on the attributes too*/
            $markup .= "<input type='hidden' id='wppizza-cart-nocache-attributes' name='wppizza-cart-nocache-attributes' value='" . json_encode($atts) . "' />";
            if ($isOpen == 1) {
                /*we need this to not break other wppizza extensions**/
                $markup .= "<input type='hidden' class='wppizza-open' name='wppizza-open' />";
            }
            $markup .= "</div></div>";
        } else {
            ob_start();
            $this->wppizza_include_shortcode_template($type, $atts);
            $markup = ob_get_clean();
        }
        $markup = apply_filters('wppizza_after_cart_markup', $markup);