| @@ -1,590 +1,809 @@ | ||
| 1 | -<?php | |
| 2 | -//***************************************************************************** | |
| 3 | -//cart.class.php | |
| 4 | -//***************************************************************************** | |
| 5 | -class usces_cart { | |
| 6 | - | |
| 7 | - var $serial; | |
| 8 | - | |
| 9 | - function usces_cart() { | |
| 10 | - | |
| 11 | - if ( !isset($_SESSION['usces_cart']) ) { | |
| 12 | - $_SESSION['usces_cart'] = array(); | |
| 13 | - $_SESSION['usces_entry'] = array(); | |
| 14 | - } | |
| 15 | - | |
| 16 | - } | |
| 17 | - // into Cart *************************************************************** | |
| 18 | - function inCart() { | |
| 19 | - global $usces; | |
| 20 | - $_POST = $usces->stripslashes_deep_post($_POST); | |
| 21 | - | |
| 22 | - if( $_SERVER['HTTP_REFERER'] ){ | |
| 23 | - $_SESSION['usces_previous_url'] = $_SERVER['HTTP_REFERER']; | |
| 24 | - }else{ | |
| 25 | - $_SESSION['usces_previous_url'] = str_replace('https://', 'http://', get_home_url()).'/'; | |
| 26 | - } | |
| 27 | - | |
| 28 | - $ids = array_keys($_POST['inCart']); | |
| 29 | - $post_id = $ids[0]; | |
| 30 | - | |
| 31 | - $skus = array_keys($_POST['inCart'][$post_id]); | |
| 32 | - $sku = $skus[0]; | |
| 33 | - | |
| 34 | - $this->in_serialize($post_id, $sku); | |
| 35 | - if( !isset($_SESSION['usces_cart'][$this->serial]['quant']) ){ | |
| 36 | - $_SESSION['usces_cart'][$this->serial]['quant'] = 0; | |
| 37 | - } | |
| 38 | - | |
| 39 | - if ( isset($_POST['quant'][$post_id][$sku]) && !WCUtils::is_blank($_POST['quant'][$post_id][$sku]) ) { | |
| 40 | - | |
| 41 | - $post_quant = (int)$_POST['quant'][$post_id][$sku]; | |
| 42 | - $_SESSION['usces_cart'][$this->serial]['quant'] = apply_filters('usces_filter_post_quant', $post_quant, $_SESSION['usces_cart'][$this->serial]['quant']); | |
| 43 | - | |
| 44 | - } else { | |
| 45 | - | |
| 46 | - if ( isset($_SESSION['usces_cart'][$this->serial]) ) | |
| 47 | - $_SESSION['usces_cart'][$this->serial]['quant'] = apply_filters('usces_filter_post_quant', 1, $_SESSION['usces_cart'][$this->serial]['quant']); | |
| 48 | - else | |
| 49 | - $_SESSION['usces_cart'][$this->serial]['quant'] = 1; | |
| 50 | - | |
| 51 | - $_SESSION['usces_cart'][$this->serial]['quant'] = apply_filters('usces_filter_inCart_quant', $_SESSION['usces_cart'][$this->serial]['quant']); | |
| 52 | - | |
| 53 | - } | |
| 54 | - | |
| 55 | - | |
| 56 | - if ( isset($_POST['skuPrice']) && !WCUtils::is_blank($_POST['skuPrice'][$post_id][$sku]) ) { | |
| 57 | - $price = $this->get_realprice($post_id, $sku, $_SESSION['usces_cart'][$this->serial]['quant']); | |
| 58 | - $price = apply_filters('usces_filter_inCart_price', $price, $this->serial); | |
| 59 | - $_SESSION['usces_cart'][$this->serial]['price'] = $price; | |
| 60 | - } | |
| 61 | - | |
| 62 | - if ( isset($_POST['advance']) ) { | |
| 63 | - $_SESSION['usces_cart'][$this->serial]['advance'] = $this->wc_serialize($_POST['advance']); | |
| 64 | - } | |
| 65 | - | |
| 66 | - do_action('usces_action_after_inCart', $this->serial); | |
| 67 | - } | |
| 68 | - | |
| 69 | - // update Cart *************************************************************** | |
| 70 | - function upCart() { | |
| 71 | - | |
| 72 | - if(!isset($_POST['quant'])) return false; | |
| 73 | - | |
| 74 | - global $usces; | |
| 75 | - $_POST = $usces->stripslashes_deep_post($_POST); | |
| 76 | - | |
| 77 | - foreach($_POST['quant'] as $index => $vs){ | |
| 78 | - | |
| 79 | - $ids = array_keys($vs); | |
| 80 | - $post_id = $ids[0]; | |
| 81 | - | |
| 82 | - $skus = array_keys($vs[$post_id]); | |
| 83 | - $sku = $skus[0]; | |
| 84 | - | |
| 85 | - $this->up_serialize($index, $post_id, $sku); | |
| 86 | - | |
| 87 | - if ( !WCUtils::is_blank($_POST['quant'][$index][$post_id][$sku]) ) { | |
| 88 | - | |
| 89 | - $_SESSION['usces_cart'][$this->serial]['quant'] = (int)$_POST['quant'][$index][$post_id][$sku]; | |
| 90 | - $_SESSION['usces_cart'][$this->serial]['advance'] = isset($_POST['advance'][$index][$post_id][$sku]) ? $this->wc_unserialize($_POST['advance'][$index][$post_id][$sku]) : array(); | |
| 91 | - if( isset($_POST['order_action']) ){ | |
| 92 | - $price = (int)$_POST['skuPrice'][$index][$post_id][$sku]; | |
| 93 | - }else{ | |
| 94 | - $price = $this->get_realprice($post_id, $sku, $_SESSION['usces_cart'][$this->serial]['quant']); | |
| 95 | - $price = apply_filters('usces_filter_upCart_price', $price, $this->serial, $index); | |
| 96 | - } | |
| 97 | - $_SESSION['usces_cart'][$this->serial]['price'] = $price; | |
| 98 | - | |
| 99 | - } | |
| 100 | - } | |
| 101 | - | |
| 102 | - unset( $_SESSION['usces_entry']['order']['usedpoint'] ); | |
| 103 | - do_action('usces_action_after_upCart'); | |
| 104 | - } | |
| 105 | - | |
| 106 | - // inCart_advance **************************************************************** | |
| 107 | - function inCart_advance( $serial, $name, $key, $value ){ | |
| 108 | - $_SESSION['usces_cart'][$serial]['advance'][$name][$key] = $value; | |
| 109 | - } | |
| 110 | - | |
| 111 | - // serialize **************************************************************** | |
| 112 | - function wc_serialize( $value ){ | |
| 113 | - $out = NULL; | |
| 114 | - if( !empty($value) ) | |
| 115 | -// $out = urlencode(serialize($value)); | |
| 116 | - $out = serialize($value); | |
| 117 | - return $out; | |
| 118 | - } | |
| 119 | - | |
| 120 | - function wc_unserialize( $str ){ | |
| 121 | - $out = array(); | |
| 122 | - if( !empty($str) ) | |
| 123 | -// $out = unserialize(urldecode($str)); | |
| 124 | - $out = unserialize($str); | |
| 125 | - return $out; | |
| 126 | - } | |
| 127 | - | |
| 128 | - // get data by index **************************************************************** | |
| 129 | -// function get_row($index) { | |
| 130 | -// | |
| 131 | -// if ( !isset($_SESSION['usces_cart']['post_id'][$index]) ) { | |
| 132 | -// return false; | |
| 133 | -// | |
| 134 | -// } else { | |
| 135 | -// $post_id = $_SESSION['usces_cart']['post_id'][$index]; | |
| 136 | -// $item_quantity = $_SESSION['usces_cart']['item_quantity'][$index]; | |
| 137 | -// | |
| 138 | -// $rows = compact('post_id', 'item_quantity'); | |
| 139 | -// return $rows; | |
| 140 | -// } | |
| 141 | -// } | |
| 142 | - | |
| 143 | - // delete data by index *************************************************************** | |
| 144 | - function del_row() { | |
| 145 | - | |
| 146 | - $indexs = array_keys($_POST['delButton']); | |
| 147 | - $index = $indexs[0]; | |
| 148 | - $ids = array_keys($_POST['delButton'][$index]); | |
| 149 | - $post_id = $ids[0]; | |
| 150 | - $skus = array_keys($_POST['delButton'][$index][$post_id]); | |
| 151 | - $sku = $skus[0]; | |
| 152 | - | |
| 153 | - $this->up_serialize($index, $post_id, $sku); | |
| 154 | - do_action('usces_cart_del_row', $index); | |
| 155 | - | |
| 156 | - if(isset($_SESSION['usces_cart'][$this->serial])) | |
| 157 | - unset($_SESSION['usces_cart'][$this->serial]); | |
| 158 | - | |
| 159 | - unset( $_SESSION['usces_entry']['order']['usedpoint'] ); | |
| 160 | - do_action('usces_action_after_cart_del_row', $index); | |
| 161 | - } | |
| 162 | - | |
| 163 | - // number of data in cart *********************************************************** | |
| 164 | - function num_row() { | |
| 165 | - if( !isset($_SESSION['usces_cart']) ) | |
| 166 | - return false; | |
| 167 | - | |
| 168 | - $num = count($_SESSION['usces_cart']); | |
| 169 | - | |
| 170 | - if( $num > 0 ) { | |
| 171 | - return $num; | |
| 172 | - } else { | |
| 173 | - return false; | |
| 174 | - } | |
| 175 | - } | |
| 176 | - | |
| 177 | - // clear cart **************************************************************** | |
| 178 | - function crear_cart() { | |
| 179 | - $_SESSION['usces_cart'] = array(); | |
| 180 | - $_SESSION['usces_entry'] = array(); | |
| 181 | - } | |
| 182 | - | |
| 183 | - // cart associative array *********************************************************** | |
| 184 | - function get_cart() { | |
| 185 | - | |
| 186 | - if(!isset($_SESSION['usces_cart'])) return false; | |
| 187 | - | |
| 188 | - $rows = array(); | |
| 189 | - | |
| 190 | - $i = 0; | |
| 191 | - foreach($_SESSION['usces_cart'] as $serial => $qua) { | |
| 192 | - $array = $this->key_unserialize($serial); | |
| 193 | - | |
| 194 | - $rows[$i] = $array; | |
| 195 | - | |
| 196 | - $i++; | |
| 197 | - } | |
| 198 | - | |
| 199 | - return $rows; | |
| 200 | - } | |
| 201 | - | |
| 202 | - // insert serialize ************************************************************** | |
| 203 | - function in_serialize($id, $sku){ | |
| 204 | - | |
| 205 | - global $usces; | |
| 206 | - $_POST = $usces->stripslashes_deep_post($_POST); | |
| 207 | - | |
| 208 | - if(isset($_POST['itemOption'])){ | |
| 209 | - foreach( $_POST['itemOption'][$id][$sku] as $key => $value ){ | |
| 210 | -//20110629ysk start 0000190 | |
| 211 | - //$pots[$key] = urlencode($value); | |
| 212 | - if( is_array($value) ) { | |
| 213 | - foreach( $value as $k => $v ) { | |
| 214 | - $pots[$key][urlencode(trim($v))] = urlencode(trim($v)); | |
| 215 | - } | |
| 216 | - } else { | |
| 217 | - $pots[$key] = urlencode($value); | |
| 218 | - } | |
| 219 | -//20110629ysk end | |
| 220 | - } | |
| 221 | - $sels[$id][$sku] = $pots; | |
| 222 | - }else{ | |
| 223 | - $sels[$id][$sku] = 0; | |
| 224 | - } | |
| 225 | - $sels = apply_filters('usces_filter_in_serialize', $sels, $id, $sku); | |
| 226 | - $this->serial = serialize($sels); | |
| 227 | - } | |
| 228 | - | |
| 229 | - // update serialize ************************************************************** | |
| 230 | - function up_serialize($index, $id, $sku){ | |
| 231 | - | |
| 232 | - global $usces; | |
| 233 | - $_POST = $usces->stripslashes_deep_post($_POST); | |
| 234 | - | |
| 235 | - if(isset($_POST['itemOption'][$index])){ | |
| 236 | - foreach( $_POST['itemOption'][$index][$id][$sku] as $key => $value ){ | |
| 237 | -//20110629ysk start 0000190 | |
| 238 | - //$pots[$key] = $value; | |
| 239 | - if( is_array($value) ) { | |
| 240 | - foreach( $value as $k => $v ) { | |
| 241 | - $pots[$key][$v] = $v; | |
| 242 | - } | |
| 243 | - } else { | |
| 244 | - $pots[$key] = $value; | |
| 245 | - } | |
| 246 | -//20110629ysk end | |
| 247 | - } | |
| 248 | - $sels[$id][$sku] = $pots; | |
| 249 | - }else{ | |
| 250 | - $sels[$id][$sku] = 0; | |
| 251 | - } | |
| 252 | - $sels = apply_filters('usces_filter_up_serialize', $sels, $index, $id, $sku); | |
| 253 | - $this->serial = serialize($sels); | |
| 254 | - } | |
| 255 | - | |
| 256 | - // key unserialize ************************************************************** | |
| 257 | - function key_unserialize($serial){ | |
| 258 | - | |
| 259 | - $array = unserialize($serial); | |
| 260 | - $ids = array_keys($array); | |
| 261 | - $skus = array_keys($array[$ids[0]]); | |
| 262 | - | |
| 263 | - $row['serial'] = $serial; | |
| 264 | - $row['post_id'] = $ids[0]; | |
| 265 | - $row['sku'] = $skus[0]; | |
| 266 | - $row['options'] = apply_filters('usces_filter_key_unserialize_options', $array[$ids[0]][$skus[0]], $ids[0], $skus[0]); | |
| 267 | - $row['price'] = isset($_SESSION['usces_cart'][$serial]['price']) ? $_SESSION['usces_cart'][$serial]['price'] : 0; | |
| 268 | - $row['quantity'] = $_SESSION['usces_cart'][$serial]['quant']; | |
| 269 | - $row['advance'] = isset($_SESSION['usces_cart'][$serial]['advance']) ? $_SESSION['usces_cart'][$serial]['advance'] : array(); | |
| 270 | - | |
| 271 | - return $row; | |
| 272 | - } | |
| 273 | - | |
| 274 | - // is order condition *************************************************************** | |
| 275 | - function is_order_condition() { | |
| 276 | - if ( isset($_SESSION['usces_entry']['condition']) ) | |
| 277 | - return true; | |
| 278 | - else | |
| 279 | - return false; | |
| 280 | - } | |
| 281 | - | |
| 282 | - // set order condition *************************************************************** | |
| 283 | - function set_order_condition( $conditions ) { | |
| 284 | - foreach( $conditions as $key => $value ) | |
| 285 | - $_SESSION['usces_entry']['condition'][$key] = $value; | |
| 286 | - } | |
| 287 | - | |
| 288 | - // get order condition *************************************************************** | |
| 289 | - function get_order_condition() { | |
| 290 | - if(isset($_SESSION['usces_entry']['condition'])) | |
| 291 | - return $_SESSION['usces_entry']['condition']; | |
| 292 | - else | |
| 293 | - return NULL; | |
| 294 | - } | |
| 295 | - | |
| 296 | - // entry information *************************************************************** | |
| 297 | - function set_order_entry( $array ) { | |
| 298 | - foreach ( $array as $key => $value ) | |
| 299 | - $_SESSION['usces_entry']['order'][$key] = $value; | |
| 300 | - } | |
| 301 | -//20110203ysk start | |
| 302 | - // get entry information *************************************************************** | |
| 303 | - function get_order_entry( $key ) { | |
| 304 | - return $_SESSION['usces_entry']['order'][$key]; | |
| 305 | - } | |
| 306 | -//20110203ysk end | |
| 307 | - // entry information *************************************************************** | |
| 308 | - function entry() { | |
| 309 | - global $usces; | |
| 310 | - $_POST = $usces->stripslashes_deep_post($_POST); | |
| 311 | - | |
| 312 | - if(isset($_SESSION['usces_member']['ID']) && !empty($_SESSION['usces_member']['ID'])) { | |
| 313 | -//20110126ysk start | |
| 314 | - if($usces->page !== 'confirm') { | |
| 315 | - foreach( $_SESSION['usces_member'] as $key => $value ){ | |
| 316 | -//20100818ysk start | |
| 317 | - if($key === 'custom_member') { | |
| 318 | -//20101008ysk start | |
| 319 | - unset($_SESSION['usces_entry']['custom_member']); | |
| 320 | -//20101008ysk end | |
| 321 | - foreach( $_SESSION['usces_member']['custom_member'] as $mbkey => $mbvalue ) { | |
| 322 | - if(empty($_SESSION['usces_entry']['custom_customer'][$mbkey])) { | |
| 323 | - if( is_array($mbvalue) ) { | |
| 324 | - foreach( $mbvalue as $k => $v ) { | |
| 325 | - $_SESSION['usces_entry']['custom_customer'][$mbkey][$v] = $v; | |
| 326 | - } | |
| 327 | - } else { | |
| 328 | - $_SESSION['usces_entry']['custom_customer'][$mbkey] = $mbvalue; | |
| 329 | - } | |
| 330 | - } | |
| 331 | - } | |
| 332 | - } else { | |
| 333 | - //if(empty($_SESSION['usces_entry']['customer'][$key])) { | |
| 334 | - if( 'country' == $key && empty($value) ){ | |
| 335 | - $_SESSION['usces_entry']['customer'][$key] = usces_get_base_country();//20110513ysk | |
| 336 | - }else{ | |
| 337 | - $_SESSION['usces_entry']['customer'][$key] = trim($value); | |
| 338 | - } | |
| 339 | - //} | |
| 340 | - } | |
| 341 | -//20100818ysk end | |
| 342 | - } | |
| 343 | - } | |
| 344 | - } | |
| 345 | - //} else if(isset($_POST['customer'])) { | |
| 346 | - if(isset($_POST['customer'])) { | |
| 347 | - foreach( $_POST['customer'] as $key => $value ){ | |
| 348 | - if( 'country' == $key && empty($value) ){ | |
| 349 | - $_SESSION['usces_entry']['customer'][$key] = usces_get_base_country();//20110513ysk | |
| 350 | - }else{ | |
| 351 | - $_SESSION['usces_entry']['customer'][$key] = trim($value); | |
| 352 | - } | |
| 353 | - } | |
| 354 | - } | |
| 355 | -//20110126ysk end | |
| 356 | - | |
| 357 | - if(isset($_POST['delivery'])) { | |
| 358 | - foreach( $_POST['delivery'] as $key => $value ) | |
| 359 | - if( 'country' == $key && empty($value) ){ | |
| 360 | - $_SESSION['usces_entry']['delivery'][$key] = usces_get_base_country();//20110513ysk | |
| 361 | - }else{ | |
| 362 | - $_SESSION['usces_entry']['delivery'][$key] = trim($value); | |
| 363 | - } | |
| 364 | - } | |
| 365 | - | |
| 366 | - if(isset($_POST['delivery']['delivery_flag']) && $_POST['delivery']['delivery_flag'] == 0) { | |
| 367 | - foreach( $_SESSION['usces_entry']['customer'] as $key => $value ) | |
| 368 | - if( 'country' == $key && empty($value) ){ | |
| 369 | - $_SESSION['usces_entry']['delivery'][$key] = usces_get_base_country();//20110513ysk | |
| 370 | - }else{ | |
| 371 | - $_SESSION['usces_entry']['delivery'][$key] = trim($value); | |
| 372 | - } | |
| 373 | - } | |
| 374 | - | |
| 375 | - if(isset($_POST['offer'])) { | |
| 376 | - foreach( $_POST['offer'] as $key => $value ) | |
| 377 | - $_SESSION['usces_entry']['order'][$key] = trim($value); | |
| 378 | - } | |
| 379 | - | |
| 380 | - if(isset($_POST['reserve'])) { | |
| 381 | - foreach( $_POST['reserve'] as $key => $value ) | |
| 382 | - $_SESSION['usces_entry']['reserve'][$key] = trim($value); | |
| 383 | - } | |
| 384 | -//20100809ysk start | |
| 385 | - if(isset($_POST['custom_order'])) { | |
| 386 | -//20101008ysk start | |
| 387 | - unset($_SESSION['usces_entry']['custom_order']); | |
| 388 | -//20101008ysk end | |
| 389 | - foreach( $_POST['custom_order'] as $key => $value ) | |
| 390 | - if ( is_array($value) ) { | |
| 391 | - foreach( $value as $k => $v ) { | |
| 392 | - $_SESSION['usces_entry']['custom_order'][$key][trim($v)] = trim($v); | |
| 393 | - } | |
| 394 | - } else { | |
| 395 | - $_SESSION['usces_entry']['custom_order'][$key] = trim($value); | |
| 396 | - } | |
| 397 | - } | |
| 398 | -//20100809ysk end | |
| 399 | -//20110106ysk start | |
| 400 | - $this->set_custom_customer_delivery(); | |
| 401 | -//20110106ysk end | |
| 402 | -//20100818ysk start | |
| 403 | - if(isset($_POST['custom_customer'])) { | |
| 404 | -//20101008ysk start | |
| 405 | - unset($_SESSION['usces_entry']['custom_customer']); | |
| 406 | -//20101008ysk end | |
| 407 | - foreach( $_POST['custom_customer'] as $key => $value ) | |
| 408 | - if ( is_array($value) ) { | |
| 409 | - foreach( $value as $k => $v ) { | |
| 410 | - $_SESSION['usces_entry']['custom_customer'][$key][trim($v)] = trim($v); | |
| 411 | - } | |
| 412 | - } else { | |
| 413 | - $_SESSION['usces_entry']['custom_customer'][$key] = trim($value); | |
| 414 | - } | |
| 415 | - } | |
| 416 | - if(isset($_POST['custom_delivery'])) { | |
| 417 | -//20101008ysk start | |
| 418 | - unset($_SESSION['usces_entry']['custom_delivery']); | |
| 419 | -//20101008ysk end | |
| 420 | - foreach( $_POST['custom_delivery'] as $key => $value ) | |
| 421 | - if ( is_array($value) ) { | |
| 422 | - foreach( $value as $k => $v ) { | |
| 423 | - $_SESSION['usces_entry']['custom_delivery'][$key][trim($v)] = trim($v); | |
| 424 | - } | |
| 425 | - } else { | |
| 426 | - $_SESSION['usces_entry']['custom_delivery'][$key] = trim($value); | |
| 427 | - } | |
| 428 | - } | |
| 429 | -//20110106ysk start | |
| 430 | - if(isset($_POST['delivery']['delivery_flag']) && $_POST['delivery']['delivery_flag'] == 0) { | |
| 431 | - $this->set_custom_customer_delivery(); | |
| 432 | - } | |
| 433 | -//20110106ysk end | |
| 434 | - } | |
| 435 | - | |
| 436 | - // get entry information *************************************************************** | |
| 437 | - function get_entry() { | |
| 438 | - | |
| 439 | - $res['customer'] = array( | |
| 440 | - 'mailaddress1' => '', | |
| 441 | - 'mailaddress2' => '', | |
| 442 | - 'password1' => '', | |
| 443 | - 'password2' => '', | |
| 444 | - 'name1' => '', | |
| 445 | - 'name2' => '', | |
| 446 | - 'name3' => '', | |
| 447 | - 'name4' => '', | |
| 448 | - 'zipcode' => '', | |
| 449 | - 'address1' => '', | |
| 450 | - 'address2' => '', | |
| 451 | - 'address3' => '', | |
| 452 | - 'tel' => '', | |
| 453 | - 'fax' => '', | |
| 454 | - 'country' => '', | |
| 455 | - 'pref' => '' | |
| 456 | - ); | |
| 457 | - if(isset($_SESSION['usces_entry']['customer'])){ | |
| 458 | - foreach((array)$_SESSION['usces_entry']['customer'] as $key => $val){ | |
| 459 | - $res['customer'][$key] = $val; | |
| 460 | - } | |
| 461 | - } | |
| 462 | - | |
| 463 | - $res['delivery'] = array( | |
| 464 | - 'name1' => '', | |
| 465 | - 'name2' => '', | |
| 466 | - 'name3' => '', | |
| 467 | - 'name4' => '', | |
| 468 | - 'zipcode' => '', | |
| 469 | - 'address1' => '', | |
| 470 | - 'address2' => '', | |
| 471 | - 'address3' => '', | |
| 472 | - 'tel' => '', | |
| 473 | - 'fax' => '', | |
| 474 | - 'country' => '', | |
| 475 | - 'pref' => '', | |
| 476 | - 'delivery_flag' => '' | |
| 477 | - ); | |
| 478 | - if(isset($_SESSION['usces_entry']['delivery'])){ | |
| 479 | - foreach((array)$_SESSION['usces_entry']['delivery'] as $key => $val){ | |
| 480 | - $res['delivery'][$key] = $val; | |
| 481 | - } | |
| 482 | - } | |
| 483 | - | |
| 484 | - $res['order'] = array( | |
| 485 | - 'usedpoint' => '', | |
| 486 | - 'total_items_price' => '', | |
| 487 | - 'discount' => '', | |
| 488 | - 'shipping_charge' => '', | |
| 489 | - 'cod_fee' => '', | |
| 490 | - 'shipping_charge' => '', | |
| 491 | - 'payment_name' => '', | |
| 492 | - 'delivery_method' => '', | |
| 493 | - 'delivery_date' => '', | |
| 494 | - 'delivery_time' => '', | |
| 495 | - 'total_full_price' => '', | |
| 496 | - 'note' => '', | |
| 497 | - 'tax' => '', | |
| 498 | - 'payment_name' => '', | |
| 499 | - 'delidue_date' => '' | |
| 500 | - ); | |
| 501 | - if(isset($_SESSION['usces_entry']['order'])){ | |
| 502 | - foreach((array)$_SESSION['usces_entry']['order'] as $key => $val){ | |
| 503 | - $res['order'][$key] = $val; | |
| 504 | - } | |
| 505 | - } | |
| 506 | - | |
| 507 | - if(isset($_SESSION['usces_entry']['reserve'])) | |
| 508 | - $res['reserve'] = $_SESSION['usces_entry']['reserve']; | |
| 509 | - else | |
| 510 | - $res['reserve'] = NULL; | |
| 511 | - | |
| 512 | - if(isset($_SESSION['usces_entry']['condition'])) | |
| 513 | - $res['condition'] = $_SESSION['usces_entry']['condition']; | |
| 514 | - else | |
| 515 | - $res['condition'] = NULL; | |
| 516 | - | |
| 517 | -//20100809ysk start | |
| 518 | - if(isset($_SESSION['usces_entry']['custom_order'])) | |
| 519 | - $res['custom_order'] = $_SESSION['usces_entry']['custom_order']; | |
| 520 | - else | |
| 521 | - $res['custom_order'] = NULL; | |
| 522 | -//20100809ysk end | |
| 523 | -//20100818ysk start | |
| 524 | - if(isset($_SESSION['usces_entry']['custom_customer'])) | |
| 525 | - $res['custom_customer'] = $_SESSION['usces_entry']['custom_customer']; | |
| 526 | - else | |
| 527 | - $res['custom_customer'] = NULL; | |
| 528 | - if(isset($_SESSION['usces_entry']['custom_delivery'])) | |
| 529 | - $res['custom_delivery'] = $_SESSION['usces_entry']['custom_delivery']; | |
| 530 | - else | |
| 531 | - $res['custom_delivery'] = NULL; | |
| 532 | -//20100818ysk end | |
| 533 | - return $res; | |
| 534 | - | |
| 535 | - } | |
| 536 | - // get realprice *************************************************************** | |
| 537 | - function get_realprice($post_id, $sku, $quant, $price = NULL) { | |
| 538 | - global $usces; | |
| 539 | - $sku = urldecode($sku); | |
| 540 | - $skus = $usces->get_skus( $post_id, 'code' ); | |
| 541 | - | |
| 542 | - if($price === NULL) { | |
| 543 | - $p = $skus[$sku]['price']; | |
| 544 | - } else { | |
| 545 | - $p = $price; | |
| 546 | - } | |
| 547 | -//20110905ysk start 0000251 | |
| 548 | - $p = apply_filters('usces_filter_realprice', $p, $this->serial); | |
| 549 | -//20110905ysk end | |
| 550 | - if( !$skus[$sku]['gp'] ) return $p; | |
| 551 | - | |
| 552 | - $realprice = usces_get_gp_price($post_id, $p, $quant); | |
| 553 | - | |
| 554 | - return $realprice; | |
| 555 | - } | |
| 556 | - | |
| 557 | - function set_pre_order_id($id){ | |
| 558 | - $_SESSION['usces_entry']['reserve']['pre_order_id'] = $id; | |
| 559 | - } | |
| 560 | - | |
| 561 | -//20110106ysk start | |
| 562 | - function set_custom_customer_delivery() { | |
| 563 | - if(isset($_SESSION['usces_entry']['custom_customer'])) { | |
| 564 | - $delivery = array(); | |
| 565 | - $csde_meta = usces_has_custom_field_meta('delivery'); | |
| 566 | - if(!empty($csde_meta) and is_array($csde_meta)) { | |
| 567 | - foreach($csde_meta as $key => $entry) { | |
| 568 | - $delivery[$key] = $key; | |
| 569 | - } | |
| 570 | - } | |
| 571 | - foreach( $_SESSION['usces_entry']['custom_customer'] as $mbkey => $mbvalue ) { | |
| 572 | - if(array_key_exists($mbkey, $delivery)) { | |
| 573 | -//20110126ysk start | |
| 574 | - if(empty($_SESSION['usces_entry']['custom_delivery'][$mbkey])) { | |
| 575 | - if( is_array($mbvalue) ) { | |
| 576 | - foreach( $mbvalue as $k => $v ) { | |
| 577 | - $_SESSION['usces_entry']['custom_delivery'][$mbkey][$v] = $v; | |
| 578 | - } | |
| 579 | - } else { | |
| 580 | - $_SESSION['usces_entry']['custom_delivery'][$mbkey] = $mbvalue; | |
| 581 | - } | |
| 582 | - } | |
| 583 | -//20110126ysk end | |
| 584 | - } | |
| 585 | - } | |
| 586 | - } | |
| 587 | - } | |
| 588 | -//20110106ysk end | |
| 589 | -} | |
| 590 | -?> | |
| 1 | +<?php | |
| 2 | +/** | |
| 3 | + * Cart class | |
| 4 | + */ | |
| 5 | +class usces_cart { | |
| 6 | + | |
| 7 | + /** | |
| 8 | + * Serial key | |
| 9 | + * | |
| 10 | + * @var string | |
| 11 | + */ | |
| 12 | + var $serial; | |
| 13 | + | |
| 14 | + /** | |
| 15 | + * Constructor | |
| 16 | + */ | |
| 17 | + public function __construct() { | |
| 18 | + | |
| 19 | + if ( ! isset( $_SESSION['usces_cart'] ) ) { | |
| 20 | + $_SESSION['usces_cart'] = array(); | |
| 21 | + $_SESSION['usces_entry'] = array(); | |
| 22 | + } | |
| 23 | + } | |
| 24 | + | |
| 25 | + /** | |
| 26 | + * Create instance | |
| 27 | + * | |
| 28 | + * @param string $serial Serial key. | |
| 29 | + * @return object | |
| 30 | + */ | |
| 31 | + public static function create( $serial ) { | |
| 32 | + $instance = new self(); | |
| 33 | + $instance->serial = $serial; | |
| 34 | + | |
| 35 | + return $instance; | |
| 36 | + } | |
| 37 | + | |
| 38 | + /** | |
| 39 | + * Add to Cart | |
| 40 | + */ | |
| 41 | + public function inCart() { | |
| 42 | + global $usces; | |
| 43 | + | |
| 44 | + $_POST = $usces->stripslashes_deep_post( $_POST ); | |
| 45 | + if ( $_SERVER['HTTP_REFERER'] ) { | |
| 46 | + $_SESSION['usces_previous_url'] = esc_url( $_SERVER['HTTP_REFERER'] ); | |
| 47 | + } else { | |
| 48 | + $_SESSION['usces_previous_url'] = str_replace( 'https://', 'http://', get_home_url() ) . '/'; | |
| 49 | + } | |
| 50 | + | |
| 51 | + $ids = array_keys( $_POST['inCart'] ); | |
| 52 | + $post_id = (int) $ids[0]; | |
| 53 | + | |
| 54 | + $skus = array_keys( $_POST['inCart'][ $post_id ] ); | |
| 55 | + $sku = $skus[0]; | |
| 56 | + | |
| 57 | + $zaiko_id = $usces->getItemZaikoStatusId( $post_id, urldecode( $sku ) ); | |
| 58 | + if ( false === $zaiko_id ) { | |
| 59 | + header( 'HTTP/1.0 400 Bad request' ); | |
| 60 | + die(); | |
| 61 | + } | |
| 62 | + | |
| 63 | + $this->in_serialize( $post_id, $sku ); | |
| 64 | + if ( ! isset( $_SESSION['usces_cart'][ $this->serial ]['quant'] ) ) { | |
| 65 | + $_SESSION['usces_cart'][ $this->serial ]['quant'] = 0; | |
| 66 | + } | |
| 67 | + | |
| 68 | + if ( isset( $_POST['quant'][ $post_id ][ $sku ] ) && ! WCUtils::is_blank( $_POST['quant'][ $post_id ][ $sku ] ) ) { | |
| 69 | + | |
| 70 | + $post_quant = (int) $_POST['quant'][ $post_id ][ $sku ]; | |
| 71 | + $_SESSION['usces_cart'][ $this->serial ]['quant'] = apply_filters( 'usces_filter_post_quant', $post_quant, $_SESSION['usces_cart'][ $this->serial ]['quant'] ); | |
| 72 | + | |
| 73 | + } else { | |
| 74 | + | |
| 75 | + if ( isset( $_SESSION['usces_cart'][ $this->serial ] ) ) { | |
| 76 | + $_SESSION['usces_cart'][ $this->serial ]['quant'] = apply_filters( 'usces_filter_post_quant', 1, $_SESSION['usces_cart'][ $this->serial ]['quant'] ); | |
| 77 | + } else { | |
| 78 | + $_SESSION['usces_cart'][ $this->serial ]['quant'] = 1; | |
| 79 | + } | |
| 80 | + $_SESSION['usces_cart'][ $this->serial ]['quant'] = apply_filters( 'usces_filter_inCart_quant', $_SESSION['usces_cart'][ $this->serial ]['quant'] ); | |
| 81 | + | |
| 82 | + } | |
| 83 | + | |
| 84 | + $price = $this->get_realprice( $post_id, $sku, $_SESSION['usces_cart'][ $this->serial ]['quant'], null, $unit_price ); | |
| 85 | + $price = apply_filters( 'usces_filter_inCart_price', $price, $this->serial ); | |
| 86 | + | |
| 87 | + $_SESSION['usces_cart'][ $this->serial ]['price'] = $price; | |
| 88 | + $_SESSION['usces_cart'][ $this->serial ]['unit_price'] = $unit_price; | |
| 89 | + | |
| 90 | + if ( isset( $_POST['advance'] ) ) { | |
| 91 | + $_SESSION['usces_cart'][ $this->serial ]['advance'] = $this->wc_serialize( $_POST['advance'] ); | |
| 92 | + } | |
| 93 | + | |
| 94 | + unset( $_SESSION['usces_entry']['order']['usedpoint'] ); | |
| 95 | + do_action( 'usces_action_after_inCart', $this->serial ); | |
| 96 | + } | |
| 97 | + | |
| 98 | + /** | |
| 99 | + * Update Cart | |
| 100 | + */ | |
| 101 | + public function upCart() { | |
| 102 | + | |
| 103 | + if ( ! isset( $_POST['quant'] ) ) { | |
| 104 | + return false; | |
| 105 | + } | |
| 106 | + | |
| 107 | + global $usces; | |
| 108 | + $_POST = $usces->stripslashes_deep_post( $_POST ); | |
| 109 | + $keys = array_keys( $_SESSION['usces_cart'] ); | |
| 110 | + | |
| 111 | + $serial_option = apply_filters( 'usces_filter_upcart_serial_option', false ); | |
| 112 | + | |
| 113 | + $index = 0; | |
| 114 | + foreach ( $_POST['quant'] as $vs ) { | |
| 115 | + | |
| 116 | + if ( ! is_array( $vs ) ) { | |
| 117 | + break; | |
| 118 | + } | |
| 119 | + | |
| 120 | + if ( ! isset( $_POST['quant'][ $index ] ) ) { | |
| 121 | + continue; | |
| 122 | + } | |
| 123 | + | |
| 124 | + $res = apply_filters( 'usces_filter_upCart_check', '', $index, $vs ); | |
| 125 | + if ( '' !== $res ) { | |
| 126 | + return $res; | |
| 127 | + } | |
| 128 | + | |
| 129 | + $ids = array_keys( $vs ); | |
| 130 | + $post_id = $ids[0]; | |
| 131 | + | |
| 132 | + $skus = array_keys( $vs[ $post_id ] ); | |
| 133 | + $sku = $skus[0]; | |
| 134 | + | |
| 135 | + $sku_decode = urldecode( $sku ); | |
| 136 | + | |
| 137 | + $skus = $usces->get_skus( $post_id, 'code' ); | |
| 138 | + | |
| 139 | + if ( ! $skus || ! isset( $skus[ $sku_decode ] ) ) { | |
| 140 | + continue; | |
| 141 | + } | |
| 142 | + | |
| 143 | + if ( $serial_option ) { | |
| 144 | + $this->up_serialize( $index, $post_id, $sku ); | |
| 145 | + } else { | |
| 146 | + if ( ! isset( $keys[ $index ] ) ) { | |
| 147 | + /* | |
| 148 | + * The cart in the session has fewer rows than the posted data | |
| 149 | + * ( session GC, deletion in another tab, etc. ). | |
| 150 | + * Skip it, because a null key is converted to "" and would | |
| 151 | + * write a broken row into the session. | |
| 152 | + */ | |
| 153 | + $index++; | |
| 154 | + continue; | |
| 155 | + } | |
| 156 | + $this->serial = $keys[ $index ]; | |
| 157 | + } | |
| 158 | + | |
| 159 | + if ( ! WCUtils::is_blank( $_POST['quant'][ $index ][ $post_id ][ $sku ] ) ) { | |
| 160 | + | |
| 161 | + $_SESSION['usces_cart'][ $this->serial ]['quant'] = (int) $_POST['quant'][ $index ][ $post_id ][ $sku ]; | |
| 162 | + $_SESSION['usces_cart'][ $this->serial ]['advance'] = isset( $_POST['advance'][ $index ][ $post_id ][ $sku ] ) ? $_POST['advance'][ $index ][ $post_id ][ $sku ] : array(); | |
| 163 | + | |
| 164 | + // if ( isset( $_POST['order_action'] ) ) { | |
| 165 | + // $price = (int) $_POST['skuPrice'][ $index ][ $post_id ][ $sku ]; | |
| 166 | + // } else { | |
| 167 | + $price = $this->get_realprice( $post_id, $sku, $_SESSION['usces_cart'][ $this->serial ]['quant'] ); | |
| 168 | + $price = apply_filters( 'usces_filter_upCart_price', $price, $this->serial, $index ); | |
| 169 | + // } | |
| 170 | + $_SESSION['usces_cart'][ $this->serial ]['price'] = $price; | |
| 171 | + | |
| 172 | + } | |
| 173 | + | |
| 174 | + $index++; | |
| 175 | + } | |
| 176 | + | |
| 177 | + unset( $_SESSION['usces_entry']['order']['usedpoint'] ); | |
| 178 | + do_action( 'usces_action_after_upCart' ); | |
| 179 | + | |
| 180 | + return false; | |
| 181 | + } | |
| 182 | + | |
| 183 | + /** | |
| 184 | + * Add to Cart additional information | |
| 185 | + * | |
| 186 | + * @param string $serial Serial key. | |
| 187 | + * @param string $name Advance name. | |
| 188 | + * @param string $key Advance key. | |
| 189 | + * @param mixed $value Advance value. | |
| 190 | + */ | |
| 191 | + public function inCart_advance( $serial, $name, $key, $value ) { | |
| 192 | + $_SESSION['usces_cart'][ $serial ]['advance'][ $name ][ $key ] = $value; | |
| 193 | + } | |
| 194 | + | |
| 195 | + /** | |
| 196 | + * Serialize value | |
| 197 | + * | |
| 198 | + * @param array $value Value. | |
| 199 | + * @return string | |
| 200 | + */ | |
| 201 | + public function wc_serialize( $value ) { | |
| 202 | + $out = null; | |
| 203 | + if ( ! empty( $value ) ) { | |
| 204 | + $out = urlencode( json_encode( $value ) ); | |
| 205 | + } | |
| 206 | + return $out; | |
| 207 | + } | |
| 208 | + | |
| 209 | + /** | |
| 210 | + * Unserialize value | |
| 211 | + * | |
| 212 | + * @param string $str Value. | |
| 213 | + * @return array | |
| 214 | + */ | |
| 215 | + public function wc_unserialize( $str ) { | |
| 216 | + $out = array(); | |
| 217 | + if ( ! empty( $str ) ) { | |
| 218 | + $out = json_decode( urldecode( $str ), true ); | |
| 219 | + } | |
| 220 | + return $out; | |
| 221 | + } | |
| 222 | + | |
| 223 | + /** | |
| 224 | + * Remove Cart | |
| 225 | + */ | |
| 226 | + public function del_row() { | |
| 227 | + $indexs = array_keys( $_POST['delButton'] ); | |
| 228 | + $index = $indexs[0]; | |
| 229 | + $ids = array_keys( $_POST['delButton'][ $index ] ); | |
| 230 | + $post_id = $ids[0]; | |
| 231 | + $skus = array_keys( $_POST['delButton'][ $index ][ $post_id ] ); | |
| 232 | + $sku = $skus[0]; | |
| 233 | + | |
| 234 | + $this->up_serialize( $index, $post_id, $sku ); | |
| 235 | + do_action( 'usces_cart_del_row', $index ); | |
| 236 | + | |
| 237 | + if ( isset( $_SESSION['usces_cart'][ $this->serial ] ) ) { | |
| 238 | + unset( $_SESSION['usces_cart'][ $this->serial ] ); | |
| 239 | + } | |
| 240 | + unset( $_SESSION['usces_entry']['order']['usedpoint'] ); | |
| 241 | + do_action( 'usces_action_after_cart_del_row', $index ); | |
| 242 | + } | |
| 243 | + | |
| 244 | + /** | |
| 245 | + * Number of rows in cart | |
| 246 | + * | |
| 247 | + * @return int|bool | |
| 248 | + */ | |
| 249 | + public function num_row() { | |
| 250 | + if ( ! isset( $_SESSION['usces_cart'] ) ) { | |
| 251 | + return false; | |
| 252 | + } | |
| 253 | + | |
| 254 | + $num = ( is_array( $_SESSION['usces_cart'] ) ) ? count( $_SESSION['usces_cart'] ) : 0; | |
| 255 | + | |
| 256 | + if ( $num > 0 ) { | |
| 257 | + return $num; | |
| 258 | + } else { | |
| 259 | + return false; | |
| 260 | + } | |
| 261 | + } | |
| 262 | + | |
| 263 | + /** | |
| 264 | + * Clear Cart | |
| 265 | + * alias crear_cart() | |
| 266 | + */ | |
| 267 | + public function clear_cart() { | |
| 268 | + $this->crear_cart(); | |
| 269 | + } | |
| 270 | + /** | |
| 271 | + * Clear Cart | |
| 272 | + */ | |
| 273 | + public function crear_cart() { | |
| 274 | + $_SESSION['usces_cart'] = array(); | |
| 275 | + $_SESSION['usces_entry'] = array(); | |
| 276 | + do_action( 'usces_action_after_clear_cart' ); | |
| 277 | + } | |
| 278 | + | |
| 279 | + /** | |
| 280 | + * Get Cart | |
| 281 | + * | |
| 282 | + * @return array | |
| 283 | + */ | |
| 284 | + public function get_cart() { | |
| 285 | + if ( ! isset( $_SESSION['usces_cart'] ) ) { | |
| 286 | + return array(); | |
| 287 | + } | |
| 288 | + | |
| 289 | + $rows = array(); | |
| 290 | + | |
| 291 | + $i = 0; | |
| 292 | + foreach ( (array) $_SESSION['usces_cart'] as $serial => $qua ) { | |
| 293 | + $row = $this->key_unserialize( $serial ); | |
| 294 | + if ( false === $row ) { | |
| 295 | + /* A row that cannot be restored is unusable for display and ordering, so remove it from the session. */ | |
| 296 | + unset( $_SESSION['usces_cart'][ $serial ] ); | |
| 297 | + continue; | |
| 298 | + } | |
| 299 | + $rows[ $i ] = $row; | |
| 300 | + $i++; | |
| 301 | + } | |
| 302 | + | |
| 303 | + return $rows; | |
| 304 | + } | |
| 305 | + | |
| 306 | + /** | |
| 307 | + * Serial key creation | |
| 308 | + * | |
| 309 | + * @param int $id Post ID. | |
| 310 | + * @param string $sku SKU code. | |
| 311 | + */ | |
| 312 | + public function in_serialize( $id, $sku ) { | |
| 313 | + global $usces; | |
| 314 | + | |
| 315 | + $_POST = $usces->stripslashes_deep_post( $_POST ); | |
| 316 | + $pots = array(); | |
| 317 | + $option_field = usces_get_opts( $id, 'name' ); | |
| 318 | + | |
| 319 | + foreach ( $option_field as $opkey => $opval ) { | |
| 320 | + if ( ! isset( $_POST['itemOption'][ $id ][ $sku ][ urlencode( $opkey ) ] ) ) { | |
| 321 | + if ( 3 === (int) $opval['means'] || 4 === (int) $opval['means'] ) { | |
| 322 | + $pots[ urlencode( $opkey ) ] = ''; | |
| 323 | + } | |
| 324 | + } | |
| 325 | + } | |
| 326 | + | |
| 327 | + if ( isset( $_POST['itemOption'][ $id ][ $sku ] ) ) { | |
| 328 | + foreach ( $_POST['itemOption'][ $id ][ $sku ] as $key => $value ) { | |
| 329 | + if ( ! isset( $option_field[ urldecode( $key ) ] ) ) { | |
| 330 | + continue; | |
| 331 | + } | |
| 332 | + | |
| 333 | + $option = $option_field[ urldecode( $key ) ]; | |
| 334 | + if ( 3 === (int) $option['means'] || 4 === (int) $option['means'] ) { | |
| 335 | + if ( is_array( $value ) ) { | |
| 336 | + foreach ( $value as $k => $v ) { | |
| 337 | + $v = trim( wel_safe_text_serialize( $v ) ); | |
| 338 | + $pots[ $key ][ $v ] = $v; | |
| 339 | + } | |
| 340 | + } else { | |
| 341 | + $pots[ $key ] = wel_safe_text_serialize( $value ); | |
| 342 | + } | |
| 343 | + } else { | |
| 344 | + if ( is_array( $value ) ) { | |
| 345 | + foreach ( $value as $k => $v ) { | |
| 346 | + $pots[ $key ][ urlencode( trim( $v ) ) ] = urlencode( trim( $v ) ); | |
| 347 | + } | |
| 348 | + } else { | |
| 349 | + $pots[ $key ] = urlencode( $value ); | |
| 350 | + } | |
| 351 | + } | |
| 352 | + } | |
| 353 | + ksort( $pots ); | |
| 354 | + $sels[ $id ][ $sku ] = $pots; | |
| 355 | + } else { | |
| 356 | + if ( empty( $pots ) ) { | |
| 357 | + $sels[ $id ][ $sku ] = 0; | |
| 358 | + } else { | |
| 359 | + $sels[ $id ][ $sku ] = $pots; | |
| 360 | + } | |
| 361 | + } | |
| 362 | + $sels = apply_filters( 'usces_filter_in_serialize', $sels, $id, $sku ); | |
| 363 | + $this->serial = serialize( $sels ); | |
| 364 | + } | |
| 365 | + | |
| 366 | + /** | |
| 367 | + * Serial key recreation | |
| 368 | + * | |
| 369 | + * @param int $index Cart index. | |
| 370 | + * @param int $id Post ID. | |
| 371 | + * @param string $sku SKU code. | |
| 372 | + */ | |
| 373 | + public function up_serialize( $index, $id, $sku ) { | |
| 374 | + global $usces; | |
| 375 | + | |
| 376 | + $_POST = $usces->stripslashes_deep_post( $_POST ); | |
| 377 | + $pots = array(); | |
| 378 | + $option_field = usces_get_opts( $id, 'name' ); | |
| 379 | + | |
| 380 | + if ( isset( $_POST['itemOption'][ $index ][ $id ][ $sku ] ) && is_array( $_POST['itemOption'][ $index ][ $id ][ $sku ] ) ) { | |
| 381 | + foreach ( $_POST['itemOption'][ $index ][ $id ][ $sku ] as $key => $value ) { | |
| 382 | + if ( is_array( $value ) ) { | |
| 383 | + foreach ( $value as $k => $v ) { | |
| 384 | + $v = wel_safe_text_serialize( $v ); | |
| 385 | + $pots[ $key ][ $v ] = $v; | |
| 386 | + } | |
| 387 | + } else { | |
| 388 | + $pots[ $key ] = wel_safe_text_serialize( $value ); | |
| 389 | + } | |
| 390 | + } | |
| 391 | + ksort( $pots ); | |
| 392 | + $sels[ $id ][ $sku ] = $pots; | |
| 393 | + } else { | |
| 394 | + $sels[ $id ][ $sku ] = 0; | |
| 395 | + } | |
| 396 | + $sels = apply_filters( 'usces_filter_up_serialize', $sels, $index, $id, $sku ); | |
| 397 | + $this->serial = serialize( $sels ); | |
| 398 | + } | |
| 399 | + | |
| 400 | + /** | |
| 401 | + * Serial key decompression | |
| 402 | + * | |
| 403 | + * @param string $serial Serial key. | |
| 404 | + * @return array|false False if the serial key cannot be restored ( unserialize failure or invalid format ). | |
| 405 | + */ | |
| 406 | + public function key_unserialize( $serial ) { | |
| 407 | + $array = wel_safe_unserialize( $serial ); | |
| 408 | + if ( ! is_array( $array ) || empty( $array ) ) { | |
| 409 | + return false; | |
| 410 | + } | |
| 411 | + $ids = array_keys( $array ); | |
| 412 | + if ( ! is_array( $array[ $ids[0] ] ) || empty( $array[ $ids[0] ] ) ) { | |
| 413 | + return false; | |
| 414 | + } | |
| 415 | + $skus = array_keys( $array[ $ids[0] ] ); | |
| 416 | + | |
| 417 | + $row['serial'] = $serial; | |
| 418 | + $row['post_id'] = $ids[0]; | |
| 419 | + $row['sku'] = $skus[0]; | |
| 420 | + $options = $array[ $ids[0] ][ $skus[0] ]; | |
| 421 | + $opt_fields = usces_get_opts( $row['post_id'], 'sort' ); | |
| 422 | + $new_opt = array(); | |
| 423 | + foreach ( $opt_fields as $key => $field ) { | |
| 424 | + $name = urlencode( $field['name'] ); | |
| 425 | + $new_opt[ $name ] = isset( $options[ $name ] ) ? $options[ $name ] : ''; | |
| 426 | + } | |
| 427 | + $row['options'] = apply_filters( 'usces_filter_key_unserialize_options', $new_opt, $ids[0], $skus[0], $serial ); | |
| 428 | + $row['price'] = isset( $_SESSION['usces_cart'][ $serial ]['price'] ) ? $_SESSION['usces_cart'][ $serial ]['price'] : 0; | |
| 429 | + $row['unit_price'] = isset( $_SESSION['usces_cart'][ $serial ]['unit_price'] ) ? $_SESSION['usces_cart'][ $serial ]['unit_price'] : 0; | |
| 430 | + $row['quantity'] = isset( $_SESSION['usces_cart'][ $serial ]['quant'] ) ? $_SESSION['usces_cart'][ $serial ]['quant'] : 0; | |
| 431 | + $row['advance'] = isset( $_SESSION['usces_cart'][ $serial ]['advance'] ) ? $_SESSION['usces_cart'][ $serial ]['advance'] : ''; | |
| 432 | + | |
| 433 | + return $row; | |
| 434 | + } | |
| 435 | + | |
| 436 | + /** | |
| 437 | + * Is condition | |
| 438 | + * | |
| 439 | + * @return bool | |
| 440 | + */ | |
| 441 | + public function is_order_condition() { | |
| 442 | + if ( isset( $_SESSION['usces_entry']['condition'] ) ) { | |
| 443 | + return true; | |
| 444 | + } else { | |
| 445 | + return false; | |
| 446 | + } | |
| 447 | + } | |
| 448 | + | |
| 449 | + /** | |
| 450 | + * Set condition | |
| 451 | + * | |
| 452 | + * @param array $conditions Condition. | |
| 453 | + */ | |
| 454 | + public function set_order_condition( $conditions ) { | |
| 455 | + foreach ( $conditions as $key => $value ) { | |
| 456 | + $_SESSION['usces_entry']['condition'][ $key ] = $value; | |
| 457 | + } | |
| 458 | + } | |
| 459 | + | |
| 460 | + /** | |
| 461 | + * Get condition | |
| 462 | + * | |
| 463 | + * @return mixed | |
| 464 | + */ | |
| 465 | + public function get_order_condition() { | |
| 466 | + if ( isset( $_SESSION['usces_entry']['condition'] ) ) { | |
| 467 | + return $_SESSION['usces_entry']['condition']; | |
| 468 | + } else { | |
| 469 | + return null; | |
| 470 | + } | |
| 471 | + } | |
| 472 | + | |
| 473 | + /** | |
| 474 | + * Set entry information | |
| 475 | + * | |
| 476 | + * @param array $array Entry data. | |
| 477 | + */ | |
| 478 | + public function set_order_entry( $array ) { | |
| 479 | + foreach ( $array as $key => $value ) { | |
| 480 | + $_SESSION['usces_entry']['order'][ $key ] = $value; | |
| 481 | + } | |
| 482 | + } | |
| 483 | + | |
| 484 | + /** | |
| 485 | + * Get entry information | |
| 486 | + * | |
| 487 | + * @param string $key Key. | |
| 488 | + * @return mixed | |
| 489 | + */ | |
| 490 | + public function get_order_entry( $key ) { | |
| 491 | + if ( isset( $_SESSION['usces_entry']['order'][ $key ] ) ) { | |
| 492 | + return $_SESSION['usces_entry']['order'][ $key ]; | |
| 493 | + } else { | |
| 494 | + return null; | |
| 495 | + } | |
| 496 | + } | |
| 497 | + | |
| 498 | + /** | |
| 499 | + * Set entry data | |
| 500 | + */ | |
| 501 | + public function entry() { | |
| 502 | + global $usces; | |
| 503 | + $_POST = $usces->stripslashes_deep_post( $_POST ); | |
| 504 | + | |
| 505 | + if ( isset( $_SESSION['usces_member']['ID'] ) && ! empty( $_SESSION['usces_member']['ID'] ) ) { | |
| 506 | + | |
| 507 | + $usces->set_member_session_data( $_SESSION['usces_member']['ID'] ); | |
| 508 | + | |
| 509 | + if ( 'confirm' !== $usces->page ) { | |
| 510 | + foreach ( $_SESSION['usces_member'] as $key => $value ) { | |
| 511 | + if ( 'custom_member' === $key ) { | |
| 512 | + unset( $_SESSION['usces_entry']['custom_member'] ); | |
| 513 | + foreach ( $_SESSION['usces_member']['custom_member'] as $mbkey => $mbvalue ) { | |
| 514 | + if ( empty( $_SESSION['usces_entry']['custom_customer'][ $mbkey] ) ) { | |
| 515 | + if ( is_array( $mbvalue ) ) { | |
| 516 | + foreach ( $mbvalue as $k => $v ) { | |
| 517 | + $_SESSION['usces_entry']['custom_customer'][ $mbkey ][ $v ] = $v; | |
| 518 | + } | |
| 519 | + } else { | |
| 520 | + $_SESSION['usces_entry']['custom_customer'][ $mbkey ] = $mbvalue; | |
| 521 | + } | |
| 522 | + } | |
| 523 | + } | |
| 524 | + } else { | |
| 525 | + if ( 'country' === $key && empty( $value ) ) { | |
| 526 | + $_SESSION['usces_entry']['customer'][ $key ] = usces_get_base_country(); | |
| 527 | + } else { | |
| 528 | + $_SESSION['usces_entry']['customer'][ $key ] = trim( $value ); | |
| 529 | + } | |
| 530 | + } | |
| 531 | + } | |
| 532 | + } | |
| 533 | + } | |
| 534 | + if ( isset( $_POST['customer'] ) ) { | |
| 535 | + foreach ( $_POST['customer'] as $key => $value ) { | |
| 536 | + if ( 'country' === $key && empty( $value ) ) { | |
| 537 | + $_SESSION['usces_entry']['customer'][ $key ] = usces_get_base_country(); | |
| 538 | + } else { | |
| 539 | + $_SESSION['usces_entry']['customer'][ $key ] = trim( $value ); | |
| 540 | + } | |
| 541 | + } | |
| 542 | + } | |
| 543 | + | |
| 544 | + if ( isset( $_POST['delivery'] ) ) { | |
| 545 | + foreach ( $_POST['delivery'] as $key => $value ) { | |
| 546 | + if ( 'country' === $key && empty( $value ) ) { | |
| 547 | + $_SESSION['usces_entry']['delivery'][ $key ] = usces_get_base_country(); | |
| 548 | + } else { | |
| 549 | + $_SESSION['usces_entry']['delivery'][ $key ] = trim( $value ); | |
| 550 | + } | |
| 551 | + } | |
| 552 | + } | |
| 553 | + if ( isset( $_POST['delivery']['delivery_flag'] ) && 0 === (int) $_POST['delivery']['delivery_flag'] ) { | |
| 554 | + foreach ( $_SESSION['usces_entry']['customer'] as $key => $value ) { | |
| 555 | + if ( 'country' === $key && empty( $value ) ) { | |
| 556 | + $_SESSION['usces_entry']['delivery'][ $key ] = usces_get_base_country(); | |
| 557 | + } else { | |
| 558 | + $_SESSION['usces_entry']['delivery'][ $key ] = trim( $value ); | |
| 559 | + } | |
| 560 | + } | |
| 561 | + } | |
| 562 | + | |
| 563 | + if ( isset( $_POST['offer'] ) ) { | |
| 564 | + foreach ( $_POST['offer'] as $key => $value ) { | |
| 565 | + $_SESSION['usces_entry']['order'][ $key ] = trim( $value ); | |
| 566 | + } | |
| 567 | + } | |
| 568 | + | |
| 569 | + if ( isset( $_POST['reserve'] ) ) { | |
| 570 | + foreach ( $_POST['reserve'] as $key => $value ) { | |
| 571 | + $_SESSION['usces_entry']['reserve'][ $key ] = trim( wel_safe_text_serialize( $value ) ); | |
| 572 | + } | |
| 573 | + } | |
| 574 | + if ( isset( $_POST['custom_order'] ) ) { | |
| 575 | + unset( $_SESSION['usces_entry']['custom_order'] ); | |
| 576 | + $csod_meta = usces_has_custom_field_meta( 'order' ); | |
| 577 | + foreach ( $_POST['custom_order'] as $key => $value ) { | |
| 578 | + if ( ! is_array( $csod_meta ) || ! isset( $csod_meta[ $key ] ) ) { | |
| 579 | + continue; | |
| 580 | + } | |
| 581 | + $value = wel_safe_text_serialize( $value ); | |
| 582 | + if ( is_array( $value ) ) { | |
| 583 | + foreach ( $value as $k => $v ) { | |
| 584 | + $_SESSION['usces_entry']['custom_order'][ $key ][ trim( $v ) ] = trim( $v ); | |
| 585 | + } | |
| 586 | + } else { | |
| 587 | + $_SESSION['usces_entry']['custom_order'][ $key ] = trim( $value ); | |
| 588 | + } | |
| 589 | + } | |
| 590 | + } | |
| 591 | + if ( isset( $_SESSION['usces_entry']['delivery']['delivery_flag'] ) && 0 === (int) $_SESSION['usces_entry']['delivery']['delivery_flag'] ) { | |
| 592 | + $this->set_custom_customer_delivery(); | |
| 593 | + } | |
| 594 | + if ( isset( $_POST['custom_customer'] ) ) { | |
| 595 | + unset( $_SESSION['usces_entry']['custom_customer'] ); | |
| 596 | + foreach ( $_POST['custom_customer'] as $key => $value ) { | |
| 597 | + $value = wel_safe_text_serialize( $value ); | |
| 598 | + if ( is_array( $value ) ) { | |
| 599 | + foreach ( $value as $k => $v ) { | |
| 600 | + $_SESSION['usces_entry']['custom_customer'][ $key ][ trim( $v ) ] = trim( $v ); | |
| 601 | + } | |
| 602 | + } else { | |
| 603 | + $_SESSION['usces_entry']['custom_customer'][ $key ] = trim( $value ); | |
| 604 | + } | |
| 605 | + } | |
| 606 | + } | |
| 607 | + if ( isset( $_POST['custom_delivery'] ) ) { | |
| 608 | + unset( $_SESSION['usces_entry']['custom_delivery'] ); | |
| 609 | + foreach ( $_POST['custom_delivery'] as $key => $value ) { | |
| 610 | + $value = wel_safe_text_serialize( $value ); | |
| 611 | + if ( is_array( $value ) ) { | |
| 612 | + foreach ( $value as $k => $v ) { | |
| 613 | + $_SESSION['usces_entry']['custom_delivery'][ $key ][ trim( $v ) ] = trim( $v ); | |
| 614 | + } | |
| 615 | + } else { | |
| 616 | + $_SESSION['usces_entry']['custom_delivery'][ $key ] = trim( $value ); | |
| 617 | + } | |
| 618 | + } | |
| 619 | + } | |
| 620 | + if ( isset( $_POST['delivery']['delivery_flag'] ) && 0 === (int) $_POST['delivery']['delivery_flag'] ) { | |
| 621 | + $this->set_custom_customer_delivery(); | |
| 622 | + } | |
| 623 | + } | |
| 624 | + | |
| 625 | + /** | |
| 626 | + * Get entry data | |
| 627 | + * | |
| 628 | + * @return array | |
| 629 | + */ | |
| 630 | + public function get_entry() { | |
| 631 | + $res['customer'] = array( | |
| 632 | + 'mailaddress1' => '', | |
| 633 | + 'mailaddress2' => '', | |
| 634 | + 'password1' => '', | |
| 635 | + 'password2' => '', | |
| 636 | + 'name1' => '', | |
| 637 | + 'name2' => '', | |
| 638 | + 'name3' => '', | |
| 639 | + 'name4' => '', | |
| 640 | + 'zipcode' => '', | |
| 641 | + 'address1' => '', | |
| 642 | + 'address2' => '', | |
| 643 | + 'address3' => '', | |
| 644 | + 'tel' => '', | |
| 645 | + 'fax' => '', | |
| 646 | + 'country' => '', | |
| 647 | + 'pref' => '', | |
| 648 | + ); | |
| 649 | + if ( isset( $_SESSION['usces_entry']['customer'] ) ) { | |
| 650 | + foreach ( (array) $_SESSION['usces_entry']['customer'] as $key => $val ) { | |
| 651 | + $res['customer'][ $key ] = $val; | |
| 652 | + } | |
| 653 | + } | |
| 654 | + | |
| 655 | + $res['delivery'] = array( | |
| 656 | + 'name1' => '', | |
| 657 | + 'name2' => '', | |
| 658 | + 'name3' => '', | |
| 659 | + 'name4' => '', | |
| 660 | + 'zipcode' => '', | |
| 661 | + 'address1' => '', | |
| 662 | + 'address2' => '', | |
| 663 | + 'address3' => '', | |
| 664 | + 'tel' => '', | |
| 665 | + 'fax' => '', | |
| 666 | + 'country' => '', | |
| 667 | + 'pref' => '', | |
| 668 | + 'delivery_flag' => '0', | |
| 669 | + ); | |
| 670 | + if ( isset( $_SESSION['usces_entry']['delivery'] ) ) { | |
| 671 | + foreach ( (array) $_SESSION['usces_entry']['delivery'] as $key => $val ) { | |
| 672 | + $res['delivery'][ $key ] = $val; | |
| 673 | + } | |
| 674 | + } | |
| 675 | + | |
| 676 | + $res['order'] = array( | |
| 677 | + 'usedpoint' => '', | |
| 678 | + 'total_items_price' => '', | |
| 679 | + 'discount' => '', | |
| 680 | + 'shipping_charge' => '', | |
| 681 | + 'cod_fee' => '', | |
| 682 | + 'shipping_charge' => '', | |
| 683 | + 'payment_name' => '', | |
| 684 | + 'delivery_method' => '', | |
| 685 | + 'delivery_date' => '', | |
| 686 | + 'delivery_time' => '', | |
| 687 | + 'total_full_price' => '', | |
| 688 | + 'note' => '', | |
| 689 | + 'tax' => '', | |
| 690 | + 'payment_name' => '', | |
| 691 | + 'delidue_date' => '', | |
| 692 | + ); | |
| 693 | + if ( isset( $_SESSION['usces_entry']['order'] ) ) { | |
| 694 | + foreach ( (array) $_SESSION['usces_entry']['order'] as $key => $val ) { | |
| 695 | + $res['order'][ $key ] = $val; | |
| 696 | + } | |
| 697 | + } | |
| 698 | + if ( isset( $_SESSION['usces_entry']['reserve'] ) ) { | |
| 699 | + $res['reserve'] = $_SESSION['usces_entry']['reserve']; | |
| 700 | + } else { | |
| 701 | + $res['reserve'] = null; | |
| 702 | + } | |
| 703 | + if ( isset( $_SESSION['usces_entry']['condition'] ) ) { | |
| 704 | + $res['condition'] = $_SESSION['usces_entry']['condition']; | |
| 705 | + } else { | |
| 706 | + $res['condition'] = null; | |
| 707 | + } | |
| 708 | + if ( isset( $_SESSION['usces_entry']['custom_order'] ) ) { | |
| 709 | + $res['custom_order'] = $_SESSION['usces_entry']['custom_order']; | |
| 710 | + } else { | |
| 711 | + $res['custom_order'] = null; | |
| 712 | + } | |
| 713 | + if ( isset( $_SESSION['usces_entry']['custom_customer'] ) ) { | |
| 714 | + $res['custom_customer'] = $_SESSION['usces_entry']['custom_customer']; | |
| 715 | + } else { | |
| 716 | + $res['custom_customer'] = null; | |
| 717 | + } | |
| 718 | + if ( isset( $_SESSION['usces_entry']['custom_delivery'] ) ) { | |
| 719 | + $res['custom_delivery'] = $_SESSION['usces_entry']['custom_delivery']; | |
| 720 | + } else { | |
| 721 | + $res['custom_delivery'] = null; | |
| 722 | + } | |
| 723 | + return $res; | |
| 724 | + } | |
| 725 | + | |
| 726 | + /** | |
| 727 | + * Get sales price | |
| 728 | + * | |
| 729 | + * @param int $post_id Post ID. | |
| 730 | + * @param string $sku SKU code. | |
| 731 | + * @param int $quant Quantity. | |
| 732 | + * @param float $price Sales price. | |
| 733 | + * @param float $unit_price Unit price. | |
| 734 | + * @return float | |
| 735 | + */ | |
| 736 | + public function get_realprice( $post_id, $sku, $quant, $price = null, &$unit_price = null ) { | |
| 737 | + global $usces; | |
| 738 | + | |
| 739 | + $sku = urldecode( $sku ); | |
| 740 | + $skus = $usces->get_skus( $post_id, 'code' ); | |
| 741 | + | |
| 742 | + if ( null === $price ) { | |
| 743 | + $p = isset( $skus[ $sku ]['price'] ) ? $skus[ $sku ]['price'] : ''; | |
| 744 | + } else { | |
| 745 | + $p = $price; | |
| 746 | + } | |
| 747 | + $p = apply_filters( 'usces_filter_realprice', $p, $this->serial ); | |
| 748 | + $unit_price = $p; | |
| 749 | + if ( isset( $skus[ $sku ]['price'] ) && ! $skus[ $sku ]['gp'] ) { | |
| 750 | + return $p; | |
| 751 | + } | |
| 752 | + | |
| 753 | + $realprice = usces_get_gp_price( $post_id, $p, $quant ); | |
| 754 | + | |
| 755 | + return $realprice; | |
| 756 | + } | |
| 757 | + | |
| 758 | + /** | |
| 759 | + * Set Pre-Order ID | |
| 760 | + * | |
| 761 | + * @param string $id Pre-Order ID. | |
| 762 | + * @return void | |
| 763 | + */ | |
| 764 | + public function set_pre_order_id( $id ) { | |
| 765 | + $_SESSION['usces_entry']['reserve']['pre_order_id'] = $id; | |
| 766 | + } | |
| 767 | + | |
| 768 | + /** | |
| 769 | + * Transcribe membership information to shipping address information | |
| 770 | + * | |
| 771 | + * @return void | |
| 772 | + */ | |
| 773 | + public function set_custom_customer_delivery() { | |
| 774 | + if ( isset( $_SESSION['usces_entry']['custom_customer'] ) ) { | |
| 775 | + $delivery = array(); | |
| 776 | + $csde_meta = usces_has_custom_field_meta( 'delivery' ); | |
| 777 | + if ( ! empty( $csde_meta ) && is_array( $csde_meta ) ) { | |
| 778 | + foreach ( $csde_meta as $key => $entry ) { | |
| 779 | + $delivery[ $key ] = $key; | |
| 780 | + } | |
| 781 | + } | |
| 782 | + foreach ( $_SESSION['usces_entry']['custom_customer'] as $mbkey => $mbvalue ) { | |
| 783 | + if ( array_key_exists( $mbkey, $delivery ) ) { | |
| 784 | + if ( is_array( $mbvalue ) ) { | |
| 785 | + foreach ( $mbvalue as $k => $v ) { | |
| 786 | + $_SESSION['usces_entry']['custom_delivery'][ $mbkey ][ $v ] = $v; | |
| 787 | + } | |
| 788 | + } else { | |
| 789 | + $_SESSION['usces_entry']['custom_delivery'][ $mbkey ] = $mbvalue; | |
| 790 | + } | |
| 791 | + } | |
| 792 | + } | |
| 793 | + } | |
| 794 | + if ( ! empty( $_SESSION['usces_entry']['custom_delivery'] ) ) { | |
| 795 | + foreach ( $_SESSION['usces_entry']['custom_delivery'] as $key => $value ) { | |
| 796 | + if ( ! isset( $_SESSION['usces_entry']['custom_customer'] ) || ! array_key_exists( $key, $_SESSION['usces_entry']['custom_customer'] ) ) { | |
| 797 | + // Set item empty. | |
| 798 | + if ( is_array( $value ) ) { | |
| 799 | + foreach ( $value as $k => $v ) { | |
| 800 | + $_SESSION['usces_entry']['custom_delivery'][ $key ][ $v ] = ''; | |
| 801 | + } | |
| 802 | + } else { | |
| 803 | + $_SESSION['usces_entry']['custom_delivery'][ $key ] = ''; | |
| 804 | + } | |
| 805 | + } | |
| 806 | + } | |
| 807 | + } | |
| 808 | + } | |
| 809 | +} | |