| 1 |
<?php |
| 2 |
/** |
| 3 |
* WPPIZZA_MARKUP_MINICART Class |
| 4 |
* |
| 5 |
* @package WPPIZZA |
| 6 |
* @subpackage WPPizza Minicart |
| 7 |
* @copyright Copyright (c) 2015, Oliver Bach |
| 8 |
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License |
| 9 |
* @since 3.0 |
| 10 |
* |
| 11 |
*/ |
| 12 |
if ( ! defined( 'ABSPATH' ) ) exit;/*Exit if accessed directly*/ |
| 13 |
|
| 14 |
/* ================================================================================================================================= * |
| 15 |
* |
| 16 |
* |
| 17 |
* |
| 18 |
* CLASS - WPPIZZA_MARKUP_MINICART |
| 19 |
* |
| 20 |
* |
| 21 |
* |
| 22 |
* ================================================================================================================================= */ |
| 23 |
|
| 24 |
class WPPIZZA_MARKUP_MINICART{ |
| 25 |
|
| 26 |
/****************************************************************************** |
| 27 |
* |
| 28 |
* |
| 29 |
* [construct] |
| 30 |
* |
| 31 |
* |
| 32 |
*******************************************************************************/ |
| 33 |
function __construct() { |
| 34 |
/** set localized js vars **/ |
| 35 |
add_filter('wppizza_filter_js_localize', array( $this, 'js_localize')); |
| 36 |
} |
| 37 |
|
| 38 |
/****************************************************************************** |
| 39 |
* |
| 40 |
* |
| 41 |
* [methods] |
| 42 |
* |
| 43 |
* |
| 44 |
*******************************************************************************/ |
| 45 |
/*************************************** |
| 46 |
[apply attributes] |
| 47 |
***************************************/ |
| 48 |
function attributes($atts=null){ |
| 49 |
static $markup = null; |
| 50 |
|
| 51 |
/** no minicart on orderpage as it's pointless there**/ |
| 52 |
if(wppizza_is_orderpage()){ |
| 53 |
return; |
| 54 |
} |
| 55 |
/** do only once **/ |
| 56 |
if($markup == null){ |
| 57 |
/**set flag**/ |
| 58 |
$markup = true; |
| 59 |
/** add to footer **/ |
| 60 |
add_action('wp_footer', array( $this, 'get_markup'), 99); |
| 61 |
} |
| 62 |
return; |
| 63 |
} |
| 64 |
|
| 65 |
/******************************************************* |
| 66 |
* localize js vars adding to [crt] key |
| 67 |
*******************************************************/ |
| 68 |
function js_localize($js_vars){ |
| 69 |
|
| 70 |
/** no minicart on orderpage as it's pointless there**/ |
| 71 |
if(wppizza_is_orderpage()){ |
| 72 |
return $js_vars; |
| 73 |
} |
| 74 |
|
| 75 |
global $wppizza_options; |
| 76 |
|
| 77 |
/**minicart max width**/ |
| 78 |
if(!empty($wppizza_options['layout']['minicart_max_width_active'])){ |
| 79 |
$js_vars['crt']['mMaxWidth'] = $wppizza_options['layout']['minicart_max_width_active']; |
| 80 |
} |
| 81 |
/**minicart body padding top**/ |
| 82 |
if(!empty($wppizza_options['layout']['minicart_elm_padding_top'])){ |
| 83 |
$js_vars['crt']['mPadTop'] = $wppizza_options['layout']['minicart_elm_padding_top']; |
| 84 |
/**minicart padding to distinct element**/ |
| 85 |
if(!empty($wppizza_options['layout']['minicart_elm_padding_selector'])){ |
| 86 |
$js_vars['crt']['mPadElm'] = $wppizza_options['layout']['minicart_elm_padding_selector']; |
| 87 |
} |
| 88 |
} |
| 89 |
/**minicart add to element**/ |
| 90 |
if(!empty($wppizza_options['layout']['minicart_add_to_element'])){ |
| 91 |
$js_vars['crt']['mElm'] = $wppizza_options['layout']['minicart_add_to_element']; |
| 92 |
} |
| 93 |
/**minicart always displayed**/ |
| 94 |
if(!empty($wppizza_options['layout']['minicart_always_shown'])){ |
| 95 |
$js_vars['crt']['mStatic'] = 1; |
| 96 |
} |
| 97 |
|
| 98 |
return $js_vars; |
| 99 |
} |
| 100 |
|
| 101 |
|
| 102 |
/*************************************** |
| 103 |
[markup] |
| 104 |
uses the same classes as totals shortcode |
| 105 |
to do the ajax call only once |
| 106 |
even whan both shortcodes are used |
| 107 |
***************************************/ |
| 108 |
function get_markup($atts = null){ |
| 109 |
global $wppizza_options; |
| 110 |
|
| 111 |
|
| 112 |
/********************* |
| 113 |
set unique id |
| 114 |
*********************/ |
| 115 |
$id = WPPIZZA_PREFIX.'-minicart'; |
| 116 |
|
| 117 |
/********************* |
| 118 |
set container classes |
| 119 |
*********************/ |
| 120 |
$class= array(); |
| 121 |
$class[] = WPPIZZA_PREFIX.'-totals-container' ; |
| 122 |
|
| 123 |
/* add empty/full class ident if nothing/something in cart when loading - will also getadded/removed by js*/ |
| 124 |
$class[] = (wppizza_cart_is_empty()) ? WPPIZZA_PREFIX.'-totals-no-items' : WPPIZZA_PREFIX.'-totals-has-items' ; |
| 125 |
/**fixed to top or relative to element set **/ |
| 126 |
$class[]=empty($wppizza_options['layout']['minicart_add_to_element']) ? ''.WPPIZZA_PREFIX.'-minicart-fixed' : ''.WPPIZZA_PREFIX.'-minicart-relative'; |
| 127 |
/**always visible or not**/ |
| 128 |
$class[]=!empty($wppizza_options['layout']['minicart_always_shown']) ? ''.WPPIZZA_PREFIX.'-minicart-static' : '' ; |
| 129 |
/**position**/ |
| 130 |
$class[]=($wppizza_options['layout']['minicart_position'] == 'bottom') ? ''.WPPIZZA_PREFIX.'-minicart-bottom' : '' ; |
| 131 |
|
| 132 |
if(!empty($atts['class'])){ |
| 133 |
$class[] = esc_html($atts['class']); |
| 134 |
} |
| 135 |
/* implode */ |
| 136 |
$class = trim(implode(' ', $class)); |
| 137 |
|
| 138 |
/********************* |
| 139 |
set opacity classes |
| 140 |
*********************/ |
| 141 |
$opacity_class= array(); |
| 142 |
$opacity_class[] = WPPIZZA_PREFIX.'-totals-opacity' ; |
| 143 |
/* implode */ |
| 144 |
$opacity_class = trim(implode(' ', $opacity_class)); |
| 145 |
|
| 146 |
|
| 147 |
/********************* |
| 148 |
set markup components |
| 149 |
*********************/ |
| 150 |
/**get links to order page*/ |
| 151 |
$orderpage = wppizza_page_links('orderpage'); |
| 152 |
/** checkout button **/ |
| 153 |
if(!empty($wppizza_options['layout']['minicart_checkout']) && !empty($orderpage)){ |
| 154 |
$checkoutbutton = true; |
| 155 |
$checkoutbutton_class=''.WPPIZZA_PREFIX.'-totals-checkout-button'; |
| 156 |
$checkoutbutton_title=''.$wppizza_options['localization']['place_your_order'].''; |
| 157 |
} |
| 158 |
|
| 159 |
/*item count enabled/position**/ |
| 160 |
if(!empty($wppizza_options['layout']['minicart_itemcount'])){ |
| 161 |
if($wppizza_options['layout']['minicart_itemcount']=='left'){ |
| 162 |
$count_left = true; |
| 163 |
$count_left_class=''.WPPIZZA_PREFIX.'-totals-itemcount'; |
| 164 |
} |
| 165 |
if($wppizza_options['layout']['minicart_itemcount']=='right'){ |
| 166 |
$count_right = true; |
| 167 |
$count_right_class=''.WPPIZZA_PREFIX.'-totals-itemcount'; |
| 168 |
} |
| 169 |
} |
| 170 |
/** |
| 171 |
value full order |
| 172 |
**/ |
| 173 |
$total = true; |
| 174 |
$total_class = WPPIZZA_PREFIX.'-totals-order' ; |
| 175 |
|
| 176 |
/** |
| 177 |
allow for view cart button to show cart contents |
| 178 |
**/ |
| 179 |
if(!empty($wppizza_options['layout']['minicart_viewcart'])){ |
| 180 |
/*create view cart button */ |
| 181 |
$viewcart=true; |
| 182 |
$viewcart_class=''.WPPIZZA_PREFIX.'-totals-viewcart-button'; |
| 183 |
$viewcart_title=$wppizza_options['localization']['view_cart']; |
| 184 |
|
| 185 |
/*create hidden cart span adding classes always using full cart*/ |
| 186 |
$cart_class = array(); |
| 187 |
$cart_class[] = ''.WPPIZZA_PREFIX.'-totals-cart'; |
| 188 |
$cart_class[] = ''.WPPIZZA_PREFIX.'-totals-cart-items'; |
| 189 |
$cart_class[] = ''.WPPIZZA_PREFIX.'-totals-cart-summary'; |
| 190 |
|
| 191 |
$cart= true; |
| 192 |
$cart_class = implode(' ',$cart_class); |
| 193 |
} |
| 194 |
|
| 195 |
/** |
| 196 |
allow for empty cart button |
| 197 |
**/ |
| 198 |
if(!empty($wppizza_options['layout']['minicart_emptycart'])){ |
| 199 |
/*create empty cart button */ |
| 200 |
$emptycart=true; |
| 201 |
$emptycart_class=''.WPPIZZA_PREFIX.'-totals-emptycart-button'; |
| 202 |
$emptycart_title=$wppizza_options['localization']['empty_cart']; |
| 203 |
} |
| 204 |
|
| 205 |
/********************* |
| 206 |
ini markup array |
| 207 |
*********************/ |
| 208 |
$markup = array(); |
| 209 |
|
| 210 |
/********************* |
| 211 |
get markup |
| 212 |
*********************/ |
| 213 |
if(file_exists( WPPIZZA_TEMPLATE_DIR . '/markup/cart/minicart.php')){ |
| 214 |
require(WPPIZZA_TEMPLATE_DIR.'/markup/cart/minicart.php'); |
| 215 |
}else{ |
| 216 |
require(WPPIZZA_PATH.'templates/markup/cart/minicart.php'); |
| 217 |
} |
| 218 |
|
| 219 |
/********************* |
| 220 |
apply filter if required and implode for output |
| 221 |
*********************/ |
| 222 |
$markup = apply_filters('wppizza_filter_minicart_widget_markup', $markup, $atts); |
| 223 |
$markup = trim(implode('', $markup)); |
| 224 |
/* echo in wp_footer */ |
| 225 |
echo $markup; |
| 226 |
} |
| 227 |
} |
| 228 |
?> |