Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like EED_Single_Page_Checkout often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use EED_Single_Page_Checkout, and based on these observations, apply Extract Interface, too.
| 1 | <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {exit('No direct script access allowed');} |
||
| 10 | class EED_Single_Page_Checkout extends EED_Module { |
||
| 11 | |||
| 12 | |||
| 13 | /** |
||
| 14 | * $_initialized - has the SPCO controller already been initialized ? |
||
| 15 | * @access private |
||
| 16 | * @var bool $_initialized |
||
| 17 | */ |
||
| 18 | private static $_initialized = false; |
||
| 19 | |||
| 20 | |||
| 21 | /** |
||
| 22 | * $_checkout_verified - is the EE_Checkout verified as correct for this request ? |
||
| 23 | * |
||
| 24 | * @access private |
||
| 25 | * @var bool $_valid_checkout |
||
| 26 | */ |
||
| 27 | private static $_checkout_verified = true; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * $_reg_steps_array - holds initial array of reg steps |
||
| 31 | * @access private |
||
| 32 | * @var array $_reg_steps_array |
||
| 33 | */ |
||
| 34 | private static $_reg_steps_array = array(); |
||
| 35 | |||
| 36 | /** |
||
| 37 | * $checkout - EE_Checkout object for handling the properties of the current checkout process |
||
| 38 | * @access public |
||
| 39 | * @var EE_Checkout $checkout |
||
| 40 | */ |
||
| 41 | public $checkout; |
||
| 42 | |||
| 43 | |||
| 44 | |||
| 45 | |||
| 46 | /** |
||
| 47 | * @return EED_Single_Page_Checkout |
||
| 48 | */ |
||
| 49 | public static function instance() { |
||
| 53 | |||
| 54 | |||
| 55 | |||
| 56 | /** |
||
| 57 | * @return EE_CART |
||
| 58 | */ |
||
| 59 | public function cart() { |
||
| 62 | |||
| 63 | |||
| 64 | |||
| 65 | /** |
||
| 66 | * @return EE_Transaction |
||
| 67 | */ |
||
| 68 | public function transaction() { |
||
| 71 | |||
| 72 | |||
| 73 | |||
| 74 | /** |
||
| 75 | * set_hooks - for hooking into EE Core, other modules, etc |
||
| 76 | * |
||
| 77 | * @access public |
||
| 78 | * @return void |
||
| 79 | * @throws \EE_Error |
||
| 80 | */ |
||
| 81 | public static function set_hooks() { |
||
| 84 | |||
| 85 | |||
| 86 | |||
| 87 | /** |
||
| 88 | * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
||
| 89 | * |
||
| 90 | * @access public |
||
| 91 | * @return void |
||
| 92 | * @throws \EE_Error |
||
| 93 | */ |
||
| 94 | public static function set_hooks_admin() { |
||
| 113 | |||
| 114 | |||
| 115 | |||
| 116 | /** |
||
| 117 | * process ajax request |
||
| 118 | * |
||
| 119 | * @param string $ajax_action |
||
| 120 | * @throws \EE_Error |
||
| 121 | */ |
||
| 122 | public static function process_ajax_request( $ajax_action ) { |
||
| 126 | |||
| 127 | |||
| 128 | |||
| 129 | /** |
||
| 130 | * ajax display registration step |
||
| 131 | * |
||
| 132 | * @throws \EE_Error |
||
| 133 | */ |
||
| 134 | public static function display_reg_step() { |
||
| 137 | |||
| 138 | |||
| 139 | |||
| 140 | /** |
||
| 141 | * ajax process registration step |
||
| 142 | * |
||
| 143 | * @throws \EE_Error |
||
| 144 | */ |
||
| 145 | public static function process_reg_step() { |
||
| 148 | |||
| 149 | |||
| 150 | |||
| 151 | /** |
||
| 152 | * ajax process registration step |
||
| 153 | * |
||
| 154 | * @throws \EE_Error |
||
| 155 | */ |
||
| 156 | public static function update_reg_step() { |
||
| 159 | |||
| 160 | |||
| 161 | |||
| 162 | /** |
||
| 163 | * update_checkout |
||
| 164 | * |
||
| 165 | * @access public |
||
| 166 | * @return void |
||
| 167 | * @throws \EE_Error |
||
| 168 | */ |
||
| 169 | public static function update_checkout() { |
||
| 172 | |||
| 173 | |||
| 174 | |||
| 175 | /** |
||
| 176 | * load_request_handler |
||
| 177 | * |
||
| 178 | * @access public |
||
| 179 | * @return void |
||
| 180 | */ |
||
| 181 | public static function load_request_handler() { |
||
| 187 | |||
| 188 | |||
| 189 | |||
| 190 | /** |
||
| 191 | * set_definitions |
||
| 192 | * |
||
| 193 | * @access public |
||
| 194 | * @return void |
||
| 195 | * @throws \EE_Error |
||
| 196 | */ |
||
| 197 | public static function set_definitions() { |
||
| 207 | |||
| 208 | |||
| 209 | |||
| 210 | /** |
||
| 211 | * load_reg_steps |
||
| 212 | * loads and instantiates each reg step based on the EE_Registry::instance()->CFG->registration->reg_steps array |
||
| 213 | * |
||
| 214 | * @access private |
||
| 215 | * @throws EE_Error |
||
| 216 | * @return array |
||
| 217 | */ |
||
| 218 | public static function load_reg_steps() { |
||
| 254 | |||
| 255 | |||
| 256 | |||
| 257 | /** |
||
| 258 | * get_reg_steps |
||
| 259 | * |
||
| 260 | * @access public |
||
| 261 | * @return array |
||
| 262 | */ |
||
| 263 | public static function get_reg_steps() { |
||
| 295 | |||
| 296 | |||
| 297 | |||
| 298 | /** |
||
| 299 | * registration_checkout_for_admin |
||
| 300 | * |
||
| 301 | * @access public |
||
| 302 | * @return string |
||
| 303 | * @throws \EE_Error |
||
| 304 | */ |
||
| 305 | public static function registration_checkout_for_admin() { |
||
| 314 | |||
| 315 | |||
| 316 | |||
| 317 | /** |
||
| 318 | * process_registration_from_admin |
||
| 319 | * |
||
| 320 | * @access public |
||
| 321 | * @return int |
||
| 322 | * @throws \EE_Error |
||
| 323 | */ |
||
| 324 | public static function process_registration_from_admin() { |
||
| 343 | |||
| 344 | |||
| 345 | |||
| 346 | /** |
||
| 347 | * run |
||
| 348 | * |
||
| 349 | * @access public |
||
| 350 | * @param WP_Query $WP_Query |
||
| 351 | * @return void |
||
| 352 | * @throws \EE_Error |
||
| 353 | */ |
||
| 354 | public function run( $WP_Query ) { |
||
| 363 | |||
| 364 | |||
| 365 | |||
| 366 | /** |
||
| 367 | * run |
||
| 368 | * |
||
| 369 | * @access public |
||
| 370 | * @param WP_Query $WP_Query |
||
| 371 | * @return void |
||
| 372 | * @throws \EE_Error |
||
| 373 | */ |
||
| 374 | public static function init( $WP_Query ) { |
||
| 377 | |||
| 378 | |||
| 379 | |||
| 380 | /** |
||
| 381 | * _initialize - initial module setup |
||
| 382 | * |
||
| 383 | * @access private |
||
| 384 | * @throws EE_Error |
||
| 385 | * @return void |
||
| 386 | */ |
||
| 387 | private function _initialize() { |
||
| 388 | // ensure SPCO doesn't run twice |
||
| 389 | if ( EED_Single_Page_Checkout::$_initialized ) { |
||
| 390 | return; |
||
| 391 | } |
||
| 392 | try { |
||
| 393 | // setup the EE_Checkout object |
||
| 394 | $this->checkout = $this->_initialize_checkout(); |
||
| 395 | // filter checkout |
||
| 396 | $this->checkout = apply_filters( 'FHEE__EED_Single_Page_Checkout___initialize__checkout', $this->checkout ); |
||
| 397 | // get the $_GET |
||
| 398 | $this->_get_request_vars(); |
||
| 399 | // filter continue_reg |
||
| 400 | $this->checkout->continue_reg = apply_filters( 'FHEE__EED_Single_Page_Checkout__init___continue_reg', TRUE, $this->checkout ); |
||
| 401 | // load the reg steps array |
||
| 402 | if ( ! $this->_load_and_instantiate_reg_steps() ) { |
||
| 403 | EED_Single_Page_Checkout::$_initialized = true; |
||
| 404 | return; |
||
| 405 | } |
||
| 406 | // set the current step |
||
| 407 | $this->checkout->set_current_step( $this->checkout->step ); |
||
| 408 | // and the next step |
||
| 409 | $this->checkout->set_next_step(); |
||
| 410 | // was there already a valid transaction in the checkout from the session ? |
||
| 411 | if ( ! $this->checkout->transaction instanceof EE_Transaction ) { |
||
| 412 | // get transaction from db or session |
||
| 413 | $this->checkout->transaction = $this->checkout->reg_url_link && ! is_admin() |
||
| 414 | ? $this->_get_transaction_and_cart_for_previous_visit() |
||
| 415 | : $this->_get_cart_for_current_session_and_setup_new_transaction(); |
||
| 416 | if ( ! $this->checkout->transaction instanceof EE_Transaction ) { |
||
| 417 | // add some style and make it dance |
||
| 418 | $this->checkout->transaction = EE_Transaction::new_instance(); |
||
| 419 | $this->add_styles_and_scripts(); |
||
| 420 | EED_Single_Page_Checkout::$_initialized = true; |
||
| 421 | return; |
||
| 422 | } |
||
| 423 | // and the registrations for the transaction |
||
| 424 | $this->_get_registrations( $this->checkout->transaction ); |
||
| 425 | } |
||
| 426 | // verify that everything has been setup correctly |
||
| 427 | if ( ! $this->_final_verifications() ) { |
||
| 428 | EED_Single_Page_Checkout::$_initialized = true; |
||
| 429 | return; |
||
| 430 | } |
||
| 431 | // lock the transaction |
||
| 432 | $this->checkout->transaction->lock(); |
||
| 433 | // make sure all of our cached objects are added to their respective model entity mappers |
||
| 434 | $this->checkout->refresh_all_entities(); |
||
| 435 | // set amount owing |
||
| 436 | $this->checkout->amount_owing = $this->checkout->transaction->remaining(); |
||
| 437 | // initialize each reg step, which gives them the chance to potentially alter the process |
||
| 438 | $this->_initialize_reg_steps(); |
||
| 439 | // DEBUG LOG |
||
| 440 | //$this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ ); |
||
| 441 | // get reg form |
||
| 442 | $this->_check_form_submission(); |
||
| 443 | // checkout the action!!! |
||
| 444 | $this->_process_form_action(); |
||
| 445 | // add some style and make it dance |
||
| 446 | $this->add_styles_and_scripts(); |
||
| 447 | // kk... SPCO has successfully run |
||
| 448 | EED_Single_Page_Checkout::$_initialized = TRUE; |
||
| 449 | // set no cache headers and constants |
||
| 450 | EE_System::do_not_cache(); |
||
| 451 | // add anchor |
||
| 452 | add_action( 'loop_start', array( $this, 'set_checkout_anchor' ), 1 ); |
||
| 453 | } catch ( Exception $e ) { |
||
| 454 | EE_Error::add_error( $e->getMessage(), __FILE__, __FUNCTION__, __LINE__ ); |
||
| 455 | } |
||
| 456 | } |
||
| 457 | |||
| 458 | |||
| 459 | |||
| 460 | /** |
||
| 461 | * _initialize_checkout |
||
| 462 | * loads and instantiates EE_Checkout |
||
| 463 | * |
||
| 464 | * @access private |
||
| 465 | * @throws EE_Error |
||
| 466 | * @return EE_Checkout |
||
| 467 | */ |
||
| 468 | private function _initialize_checkout() { |
||
| 491 | |||
| 492 | |||
| 493 | |||
| 494 | /** |
||
| 495 | * _get_request_vars |
||
| 496 | * |
||
| 497 | * @access private |
||
| 498 | * @return void |
||
| 499 | * @throws \EE_Error |
||
| 500 | */ |
||
| 501 | private function _get_request_vars() { |
||
| 525 | |||
| 526 | |||
| 527 | |||
| 528 | /** |
||
| 529 | * _display_request_vars |
||
| 530 | * |
||
| 531 | * @access protected |
||
| 532 | * @return void |
||
| 533 | */ |
||
| 534 | protected function _display_request_vars() { |
||
| 547 | |||
| 548 | |||
| 549 | |||
| 550 | /** |
||
| 551 | * _get_first_step |
||
| 552 | * gets slug for first step in $_reg_steps_array |
||
| 553 | * |
||
| 554 | * @access private |
||
| 555 | * @throws EE_Error |
||
| 556 | * @return array |
||
| 557 | */ |
||
| 558 | private function _get_first_step() { |
||
| 562 | |||
| 563 | |||
| 564 | |||
| 565 | /** |
||
| 566 | * _load_and_instantiate_reg_steps |
||
| 567 | * instantiates each reg step based on the loaded reg_steps array |
||
| 568 | * |
||
| 569 | * @access private |
||
| 570 | * @throws EE_Error |
||
| 571 | * @return bool |
||
| 572 | */ |
||
| 573 | private function _load_and_instantiate_reg_steps() { |
||
| 619 | |||
| 620 | |||
| 621 | |||
| 622 | /** |
||
| 623 | * _load_and_instantiate_reg_step |
||
| 624 | * |
||
| 625 | * @access private |
||
| 626 | * @param array $reg_step |
||
| 627 | * @param int $order |
||
| 628 | * @return bool |
||
| 629 | */ |
||
| 630 | private function _load_and_instantiate_reg_step( $reg_step = array(), $order = 0 ) { |
||
| 683 | |||
| 684 | |||
| 685 | |||
| 686 | /** |
||
| 687 | * _get_transaction_and_cart_for_previous_visit |
||
| 688 | * |
||
| 689 | * @access private |
||
| 690 | * @return mixed EE_Transaction|NULL |
||
| 691 | */ |
||
| 692 | private function _get_transaction_and_cart_for_previous_visit() { |
||
| 707 | |||
| 708 | |||
| 709 | |||
| 710 | /** |
||
| 711 | * _get_cart_for_transaction |
||
| 712 | * |
||
| 713 | * @access private |
||
| 714 | * @param EE_Transaction $transaction |
||
| 715 | * @return EE_Cart |
||
| 716 | */ |
||
| 717 | private function _get_cart_for_transaction( $transaction ) { |
||
| 720 | |||
| 721 | |||
| 722 | |||
| 723 | /** |
||
| 724 | * get_cart_for_transaction |
||
| 725 | * |
||
| 726 | * @access public |
||
| 727 | * @param EE_Transaction $transaction |
||
| 728 | * @return EE_Cart |
||
| 729 | */ |
||
| 730 | public function get_cart_for_transaction( EE_Transaction $transaction ) { |
||
| 733 | |||
| 734 | |||
| 735 | |||
| 736 | /** |
||
| 737 | * _get_transaction_and_cart_for_current_session |
||
| 738 | * generates a new EE_Transaction object and adds it to the $_transaction property. |
||
| 739 | * |
||
| 740 | * @access private |
||
| 741 | * @return EE_Transaction |
||
| 742 | * @throws \EE_Error |
||
| 743 | */ |
||
| 744 | private function _get_cart_for_current_session_and_setup_new_transaction() { |
||
| 761 | |||
| 762 | |||
| 763 | |||
| 764 | /** |
||
| 765 | * generates a new EE_Transaction object and adds it to the $_transaction property. |
||
| 766 | * |
||
| 767 | * @access private |
||
| 768 | * @return mixed EE_Transaction|NULL |
||
| 769 | */ |
||
| 770 | private function _initialize_transaction() { |
||
| 789 | |||
| 790 | |||
| 791 | |||
| 792 | /** |
||
| 793 | * _get_registrations |
||
| 794 | * |
||
| 795 | * @access private |
||
| 796 | * @param EE_Transaction $transaction |
||
| 797 | * @return EE_Cart |
||
| 798 | * @throws \EE_Error |
||
| 799 | */ |
||
| 800 | private function _get_registrations( EE_Transaction $transaction ) { |
||
| 835 | |||
| 836 | |||
| 837 | |||
| 838 | /** |
||
| 839 | * adds related EE_Registration objects for each ticket in the cart to the current EE_Transaction object |
||
| 840 | * |
||
| 841 | * @access private |
||
| 842 | * @param EE_Transaction $transaction |
||
| 843 | * @return array |
||
| 844 | * @throws \EE_Error |
||
| 845 | */ |
||
| 846 | private function _initialize_registrations( EE_Transaction $transaction ) { |
||
| 873 | |||
| 874 | |||
| 875 | |||
| 876 | /** |
||
| 877 | * sorts registrations by REG_count |
||
| 878 | * |
||
| 879 | * @access public |
||
| 880 | * @param EE_Registration $reg_A |
||
| 881 | * @param EE_Registration $reg_B |
||
| 882 | * @return array() |
||
| 883 | */ |
||
| 884 | public static function sort_registrations_by_REG_count( EE_Registration $reg_A, EE_Registration $reg_B ) { |
||
| 891 | |||
| 892 | |||
| 893 | |||
| 894 | /** |
||
| 895 | * _final_verifications |
||
| 896 | * just makes sure that everything is set up correctly before proceeding |
||
| 897 | * |
||
| 898 | * @access private |
||
| 899 | * @return bool |
||
| 900 | * @throws \EE_Error |
||
| 901 | */ |
||
| 902 | private function _final_verifications() { |
||
| 903 | // filter checkout |
||
| 904 | $this->checkout = apply_filters( 'FHEE__EED_Single_Page_Checkout___final_verifications__checkout', $this->checkout ); |
||
| 905 | //verify that current step is still set correctly |
||
| 906 | if ( ! $this->checkout->current_step instanceof EE_SPCO_Reg_Step ) { |
||
| 907 | EE_Error::add_error( __( 'We\'re sorry but the registration process can not proceed because one or more registration steps were not setup correctly. Please refresh the page and try again or contact support.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ ); |
||
| 908 | return false; |
||
| 909 | } |
||
| 910 | // if returning to SPCO, then verify that primary registrant is set |
||
| 911 | if ( ! empty( $this->checkout->reg_url_link )) { |
||
| 912 | $valid_registrant = $this->checkout->transaction->primary_registration(); |
||
| 913 | if ( ! $valid_registrant instanceof EE_Registration ) { |
||
| 914 | EE_Error::add_error( __( 'We\'re sorry but there appears to be an error with the "reg_url_link" or the primary registrant for this transaction. Please refresh the page and try again or contact support.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ ); |
||
| 915 | return false; |
||
| 916 | } |
||
| 917 | $valid_registrant = null; |
||
| 918 | foreach ( $this->checkout->transaction->registrations( $this->checkout->reg_cache_where_params ) as $registration ) { |
||
| 919 | if ( |
||
| 920 | $registration instanceof EE_Registration |
||
| 921 | && $registration->reg_url_link() === $this->checkout->reg_url_link |
||
| 922 | ) { |
||
| 923 | $valid_registrant = $registration; |
||
| 924 | } |
||
| 925 | } |
||
| 926 | if ( ! $valid_registrant instanceof EE_Registration ) { |
||
| 927 | // hmmm... maybe we have the wrong session because the user is opening multiple tabs ? |
||
| 928 | if ( EED_Single_Page_Checkout::$_checkout_verified ) { |
||
| 929 | // clear the session, mark the checkout as unverified, and try again |
||
| 930 | EE_Registry::instance()->SSN->clear_session(); |
||
| 931 | EED_Single_Page_Checkout::$_initialized = false; |
||
| 932 | EED_Single_Page_Checkout::$_checkout_verified = false; |
||
| 933 | $this->_initialize(); |
||
| 934 | EE_Error::reset_notices(); |
||
| 935 | return false; |
||
| 936 | } |
||
| 937 | EE_Error::add_error( __( 'We\'re sorry but there appears to be an error with the "reg_url_link" or the transaction itself. Please refresh the page and try again or contact support.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ ); |
||
| 938 | return false; |
||
| 939 | } |
||
| 940 | } |
||
| 941 | // now that things have been kinda sufficiently verified, |
||
| 942 | // let's add the checkout to the session so that's available other systems |
||
| 943 | EE_Registry::instance()->SSN->set_checkout( $this->checkout ); |
||
| 944 | return true; |
||
| 945 | } |
||
| 946 | |||
| 947 | |||
| 948 | |||
| 949 | /** |
||
| 950 | * _initialize_reg_steps |
||
| 951 | * first makes sure that EE_Transaction_Processor::set_reg_step_initiated() is called as required |
||
| 952 | * then loops thru all of the active reg steps and calls the initialize_reg_step() method |
||
| 953 | * |
||
| 954 | * @access private |
||
| 955 | * @param bool $reinitializing |
||
| 956 | * @throws \EE_Error |
||
| 957 | */ |
||
| 958 | private function _initialize_reg_steps( $reinitializing = false ) { |
||
| 959 | $this->checkout->set_reg_step_initiated( $this->checkout->current_step ); |
||
| 960 | // loop thru all steps to call their individual "initialize" methods and set i18n strings for JS |
||
| 961 | foreach ( $this->checkout->reg_steps as $reg_step ) { |
||
| 962 | if ( ! $reg_step->initialize_reg_step() ) { |
||
| 963 | // if not initialized then maybe this step is being removed... |
||
| 964 | if ( ! $reinitializing && $reg_step->is_current_step() ) { |
||
| 965 | // if it was the current step, then we need to start over here |
||
| 966 | $this->_initialize_reg_steps( true ); |
||
| 967 | return; |
||
| 968 | } |
||
| 969 | continue; |
||
| 970 | } |
||
| 971 | // add css and JS for current step |
||
| 972 | $reg_step->enqueue_styles_and_scripts(); |
||
| 973 | // i18n |
||
| 974 | $reg_step->translate_js_strings(); |
||
| 975 | if ( $reg_step->is_current_step() ) { |
||
| 976 | // the text that appears on the reg step form submit button |
||
| 977 | $reg_step->set_submit_button_text(); |
||
| 978 | } |
||
| 979 | } |
||
| 980 | // dynamically creates hook point like: AHEE__Single_Page_Checkout___initialize_reg_step__attendee_information |
||
| 981 | do_action( "AHEE__Single_Page_Checkout___initialize_reg_step__{$this->checkout->current_step->slug()}", $this->checkout->current_step ); |
||
| 982 | } |
||
| 983 | |||
| 984 | |||
| 985 | |||
| 986 | /** |
||
| 987 | * _check_form_submission |
||
| 988 | * |
||
| 989 | * @access private |
||
| 990 | * @return void |
||
| 991 | */ |
||
| 992 | private function _check_form_submission() { |
||
| 993 | //does this request require the reg form to be generated ? |
||
| 994 | if ( $this->checkout->generate_reg_form ) { |
||
| 995 | // ever heard that song by Blue Rodeo ? |
||
| 996 | try { |
||
| 997 | $this->checkout->current_step->reg_form = $this->checkout->current_step->generate_reg_form(); |
||
| 998 | // if not displaying a form, then check for form submission |
||
| 999 | if ( $this->checkout->process_form_submission && $this->checkout->current_step->reg_form->was_submitted() ) { |
||
| 1000 | // clear out any old data in case this step is being run again |
||
| 1001 | $this->checkout->current_step->set_valid_data( array() ); |
||
| 1002 | // capture submitted form data |
||
| 1003 | $this->checkout->current_step->reg_form->receive_form_submission( |
||
| 1004 | apply_filters( 'FHEE__Single_Page_Checkout___check_form_submission__request_params', EE_Registry::instance()->REQ->params(), $this->checkout ) |
||
| 1005 | ); |
||
| 1006 | // validate submitted form data |
||
| 1007 | if ( ! $this->checkout->continue_reg && ! $this->checkout->current_step->reg_form->is_valid() ) { |
||
| 1008 | // thou shall not pass !!! |
||
| 1009 | $this->checkout->continue_reg = FALSE; |
||
| 1010 | // any form validation errors? |
||
| 1011 | if ( $this->checkout->current_step->reg_form->submission_error_message() !== '' ) { |
||
| 1012 | $submission_error_messages = array(); |
||
| 1013 | // bad, bad, bad registrant |
||
| 1014 | foreach( $this->checkout->current_step->reg_form->get_validation_errors_accumulated() as $validation_error ){ |
||
| 1015 | View Code Duplication | if ( $validation_error instanceof EE_Validation_Error ) { |
|
| 1016 | $submission_error_messages[] = sprintf( |
||
| 1017 | __( '%s : %s', 'event_espresso' ), |
||
| 1018 | $validation_error->get_form_section()->html_label_text(), |
||
| 1019 | $validation_error->getMessage() |
||
| 1020 | ); |
||
| 1021 | } |
||
| 1022 | } |
||
| 1023 | EE_Error::add_error( implode( '<br />', $submission_error_messages ), __FILE__, __FUNCTION__, __LINE__ ); |
||
| 1024 | } |
||
| 1025 | // well not really... what will happen is we'll just get redirected back to redo the current step |
||
| 1026 | $this->go_to_next_step(); |
||
| 1027 | return; |
||
| 1028 | } |
||
| 1029 | } |
||
| 1030 | } catch( EE_Error $e ) { |
||
| 1031 | $e->get_error(); |
||
| 1032 | } |
||
| 1033 | } |
||
| 1034 | } |
||
| 1035 | |||
| 1036 | |||
| 1037 | |||
| 1038 | /** |
||
| 1039 | * _process_action |
||
| 1040 | * |
||
| 1041 | * @access private |
||
| 1042 | * @return void |
||
| 1043 | * @throws \EE_Error |
||
| 1044 | */ |
||
| 1045 | private function _process_form_action() { |
||
| 1046 | // what cha wanna do? |
||
| 1047 | switch( $this->checkout->action ) { |
||
| 1048 | // AJAX next step reg form |
||
| 1049 | case 'display_spco_reg_step' : |
||
| 1050 | $this->checkout->redirect = FALSE; |
||
| 1051 | if ( EE_Registry::instance()->REQ->ajax ) { |
||
| 1052 | $this->checkout->json_response->set_reg_step_html( $this->checkout->current_step->display_reg_form() ); |
||
| 1053 | } |
||
| 1054 | break; |
||
| 1055 | |||
| 1056 | default : |
||
| 1057 | // meh... do one of those other steps first |
||
| 1058 | if ( ! empty( $this->checkout->action ) && is_callable( array( $this->checkout->current_step, $this->checkout->action ))) { |
||
| 1059 | // dynamically creates hook point like: AHEE__Single_Page_Checkout__before_attendee_information__process_reg_step |
||
| 1060 | do_action( "AHEE__Single_Page_Checkout__before_{$this->checkout->current_step->slug()}__{$this->checkout->action}", $this->checkout->current_step ); |
||
| 1061 | // call action on current step |
||
| 1062 | if ( call_user_func( array( $this->checkout->current_step, $this->checkout->action )) ) { |
||
| 1063 | // good registrant, you get to proceed |
||
| 1064 | if ( |
||
| 1065 | $this->checkout->current_step->success_message() !== '' |
||
| 1066 | && apply_filters( |
||
| 1067 | 'FHEE__Single_Page_Checkout___process_form_action__display_success', |
||
| 1068 | false |
||
| 1069 | ) |
||
| 1070 | ) { |
||
| 1071 | EE_Error::add_success( |
||
| 1072 | $this->checkout->current_step->success_message() |
||
| 1073 | . '<br />' . $this->checkout->next_step->_instructions() |
||
| 1074 | ); |
||
| 1075 | |||
| 1076 | } |
||
| 1077 | // pack it up, pack it in... |
||
| 1078 | $this->_setup_redirect(); |
||
| 1079 | } |
||
| 1080 | // dynamically creates hook point like: AHEE__Single_Page_Checkout__after_payment_options__process_reg_step |
||
| 1081 | do_action( "AHEE__Single_Page_Checkout__after_{$this->checkout->current_step->slug()}__{$this->checkout->action}", $this->checkout->current_step ); |
||
| 1082 | |||
| 1083 | } else { |
||
| 1084 | EE_Error::add_error( |
||
| 1085 | sprintf( |
||
| 1086 | __( 'The requested form action "%s" does not exist for the current "%s" registration step.', 'event_espresso' ), |
||
| 1087 | $this->checkout->action, |
||
| 1088 | $this->checkout->current_step->name() |
||
| 1089 | ), |
||
| 1090 | __FILE__, __FUNCTION__, __LINE__ |
||
| 1091 | ); |
||
| 1092 | } |
||
| 1093 | // end default |
||
| 1094 | } |
||
| 1095 | // store our progress so far |
||
| 1096 | $this->checkout->stash_transaction_and_checkout(); |
||
| 1097 | // advance to the next step! If you pass GO, collect $200 |
||
| 1098 | $this->go_to_next_step(); |
||
| 1099 | } |
||
| 1100 | |||
| 1101 | |||
| 1102 | |||
| 1103 | /** |
||
| 1104 | * add_styles_and_scripts |
||
| 1105 | * |
||
| 1106 | * @access public |
||
| 1107 | * @return void |
||
| 1108 | */ |
||
| 1109 | public function add_styles_and_scripts() { |
||
| 1110 | // i18n |
||
| 1111 | $this->translate_js_strings(); |
||
| 1112 | if ( $this->checkout->admin_request ) { |
||
| 1113 | add_action('admin_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10 ); |
||
| 1114 | } else { |
||
| 1115 | add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_styles_and_scripts' ), 10 ); |
||
| 1116 | } |
||
| 1117 | } |
||
| 1118 | |||
| 1119 | |||
| 1120 | |||
| 1121 | /** |
||
| 1122 | * translate_js_strings |
||
| 1123 | * |
||
| 1124 | * @access public |
||
| 1125 | * @return void |
||
| 1126 | */ |
||
| 1127 | public function translate_js_strings() { |
||
| 1128 | EE_Registry::$i18n_js_strings['revisit'] = $this->checkout->revisit; |
||
| 1129 | EE_Registry::$i18n_js_strings['e_reg_url_link'] = $this->checkout->reg_url_link; |
||
| 1130 | EE_Registry::$i18n_js_strings['server_error'] = __('An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.', 'event_espresso'); |
||
| 1131 | EE_Registry::$i18n_js_strings['invalid_json_response'] = __( 'An invalid response was returned from the server while attempting to process your request. Please refresh the page and try again or contact support.', 'event_espresso' ); |
||
| 1132 | EE_Registry::$i18n_js_strings['validation_error'] = __( 'There appears to be a problem with the form validation configuration! Please check the admin settings or contact support.', 'event_espresso' ); |
||
| 1133 | EE_Registry::$i18n_js_strings['invalid_payment_method'] = __( 'There appears to be a problem with the payment method configuration! Please refresh the page and try again or contact support.', 'event_espresso' ); |
||
| 1134 | EE_Registry::$i18n_js_strings['reg_step_error'] = __('This registration step could not be completed. Please refresh the page and try again.', 'event_espresso'); |
||
| 1135 | EE_Registry::$i18n_js_strings['invalid_coupon'] = __('We\'re sorry but that coupon code does not appear to be valid. If this is incorrect, please contact the site administrator.', 'event_espresso'); |
||
| 1136 | EE_Registry::$i18n_js_strings['process_registration'] = sprintf( __( 'Please wait while we process your registration.%sDo not refresh the page or navigate away while this is happening.%sThank you for your patience.', 'event_espresso' ), '<br/>', '<br/>' ); |
||
| 1137 | EE_Registry::$i18n_js_strings['language'] = get_bloginfo( 'language' ); |
||
| 1138 | EE_Registry::$i18n_js_strings['EESID'] = EE_Registry::instance()->SSN->id(); |
||
| 1139 | EE_Registry::$i18n_js_strings['currency'] = EE_Registry::instance()->CFG->currency; |
||
| 1140 | EE_Registry::$i18n_js_strings['datepicker_yearRange'] = '-150:+20'; |
||
| 1141 | EE_Registry::$i18n_js_strings['timer_years'] = __( 'years', 'event_espresso' ); |
||
| 1142 | EE_Registry::$i18n_js_strings['timer_months'] = __( 'months', 'event_espresso' ); |
||
| 1143 | EE_Registry::$i18n_js_strings['timer_weeks'] = __( 'weeks', 'event_espresso' ); |
||
| 1144 | EE_Registry::$i18n_js_strings['timer_days'] = __( 'days', 'event_espresso' ); |
||
| 1145 | EE_Registry::$i18n_js_strings['timer_hours'] = __( 'hours', 'event_espresso' ); |
||
| 1146 | EE_Registry::$i18n_js_strings['timer_minutes'] = __( 'minutes', 'event_espresso' ); |
||
| 1147 | EE_Registry::$i18n_js_strings['timer_seconds'] = __( 'seconds', 'event_espresso' ); |
||
| 1148 | EE_Registry::$i18n_js_strings['timer_year'] = __( 'year', 'event_espresso' ); |
||
| 1149 | EE_Registry::$i18n_js_strings['timer_month'] = __( 'month', 'event_espresso' ); |
||
| 1150 | EE_Registry::$i18n_js_strings['timer_week'] = __( 'week', 'event_espresso' ); |
||
| 1151 | EE_Registry::$i18n_js_strings['timer_day'] = __( 'day', 'event_espresso' ); |
||
| 1152 | EE_Registry::$i18n_js_strings['timer_hour'] = __( 'hour', 'event_espresso' ); |
||
| 1153 | EE_Registry::$i18n_js_strings['timer_minute'] = __( 'minute', 'event_espresso' ); |
||
| 1154 | EE_Registry::$i18n_js_strings['timer_second'] = __( 'second', 'event_espresso' ); |
||
| 1155 | EE_Registry::$i18n_js_strings['registration_expiration_notice'] = sprintf( |
||
| 1156 | __( '%1$sWe\'re sorry, but your registration time has expired.%2$s%3$s%4$sIf you still wish to complete your registration, please return to the %5$sEvent List%6$sEvent List%7$s and reselect your tickets if available. Please except our apologies for any inconvenience this may have caused.%8$s', 'event_espresso' ), |
||
| 1157 | '<h4 class="important-notice">', |
||
| 1158 | '</h4>', |
||
| 1159 | '<br />', |
||
| 1160 | '<p>', |
||
| 1161 | '<a href="'. get_post_type_archive_link( 'espresso_events' ) . '" title="', |
||
| 1162 | '">', |
||
| 1163 | '</a>', |
||
| 1164 | '</p>' |
||
| 1165 | ); |
||
| 1166 | EE_Registry::$i18n_js_strings[ 'ajax_submit' ] = apply_filters( 'FHEE__Single_Page_Checkout__translate_js_strings__ajax_submit', true ); |
||
| 1167 | } |
||
| 1168 | |||
| 1169 | |||
| 1170 | |||
| 1171 | /** |
||
| 1172 | * enqueue_styles_and_scripts |
||
| 1173 | * |
||
| 1174 | * @access public |
||
| 1175 | * @return void |
||
| 1176 | */ |
||
| 1177 | public function enqueue_styles_and_scripts() { |
||
| 1178 | // load css |
||
| 1179 | wp_register_style( 'single_page_checkout', SPCO_CSS_URL . 'single_page_checkout.css', array(), EVENT_ESPRESSO_VERSION ); |
||
| 1180 | wp_enqueue_style( 'single_page_checkout' ); |
||
| 1181 | // load JS |
||
| 1182 | wp_register_script( 'jquery_plugin', EE_THIRD_PARTY_URL . 'jquery .plugin.min.js', array( 'jquery' ), '1.0.1', TRUE ); |
||
| 1183 | wp_register_script( 'jquery_countdown', EE_THIRD_PARTY_URL . 'jquery .countdown.min.js', array( 'jquery_plugin' ), '2.0.2', TRUE ); |
||
| 1184 | wp_register_script( 'single_page_checkout', SPCO_JS_URL . 'single_page_checkout.js', array( 'espresso_core', 'underscore', 'ee_form_section_validation', 'jquery_countdown' ), EVENT_ESPRESSO_VERSION, TRUE ); |
||
| 1185 | wp_enqueue_script( 'single_page_checkout' ); |
||
| 1186 | |||
| 1187 | /** |
||
| 1188 | * global action hook for enqueueing styles and scripts with |
||
| 1189 | * spco calls. |
||
| 1190 | */ |
||
| 1191 | do_action( 'AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts', $this ); |
||
| 1192 | |||
| 1193 | /** |
||
| 1194 | * dynamic action hook for enqueueing styles and scripts with spco calls. |
||
| 1195 | * The hook will end up being something like AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__attendee_information |
||
| 1196 | */ |
||
| 1197 | do_action( 'AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__' . $this->checkout->current_step->slug(), $this ); |
||
| 1198 | |||
| 1199 | } |
||
| 1200 | |||
| 1201 | |||
| 1202 | |||
| 1203 | /** |
||
| 1204 | * display the Registration Single Page Checkout Form |
||
| 1205 | * |
||
| 1206 | * @access private |
||
| 1207 | * @return void |
||
| 1208 | * @throws \EE_Error |
||
| 1209 | */ |
||
| 1210 | private function _display_spco_reg_form() { |
||
| 1272 | |||
| 1273 | |||
| 1274 | |||
| 1275 | /** |
||
| 1276 | * add_extra_finalize_registration_inputs |
||
| 1277 | * |
||
| 1278 | * @access public |
||
| 1279 | * @param $next_step |
||
| 1280 | * @internal param string $label |
||
| 1281 | * @return string |
||
| 1282 | */ |
||
| 1283 | public function add_extra_finalize_registration_inputs( $next_step ) { |
||
| 1288 | |||
| 1289 | |||
| 1290 | |||
| 1291 | /** |
||
| 1292 | * display_registration_footer |
||
| 1293 | * |
||
| 1294 | * @access public |
||
| 1295 | * @return string |
||
| 1296 | */ |
||
| 1297 | public static function display_registration_footer() { |
||
| 1316 | |||
| 1317 | |||
| 1318 | |||
| 1319 | /** |
||
| 1320 | * unlock_transaction |
||
| 1321 | * |
||
| 1322 | * @access public |
||
| 1323 | * @return void |
||
| 1324 | * @throws \EE_Error |
||
| 1325 | */ |
||
| 1326 | public function unlock_transaction() { |
||
| 1329 | |||
| 1330 | |||
| 1331 | |||
| 1332 | |||
| 1333 | /** |
||
| 1334 | * _setup_redirect |
||
| 1335 | * |
||
| 1336 | * @access private |
||
| 1337 | * @return array |
||
| 1338 | */ |
||
| 1339 | private function _setup_redirect() { |
||
| 1348 | |||
| 1349 | |||
| 1350 | |||
| 1351 | /** |
||
| 1352 | * handle ajax message responses and redirects |
||
| 1353 | * |
||
| 1354 | * @access public |
||
| 1355 | * @return void |
||
| 1356 | * @throws \EE_Error |
||
| 1357 | */ |
||
| 1358 | public function go_to_next_step() { |
||
| 1379 | |||
| 1380 | |||
| 1381 | |||
| 1382 | /** |
||
| 1383 | * _handle_json_response |
||
| 1384 | * |
||
| 1385 | * @access protected |
||
| 1386 | * @return void |
||
| 1387 | */ |
||
| 1388 | protected function _handle_json_response() { |
||
| 1413 | |||
| 1414 | |||
| 1415 | |||
| 1416 | /** |
||
| 1417 | * _handle_redirects |
||
| 1418 | * |
||
| 1419 | * @access protected |
||
| 1420 | * @return void |
||
| 1421 | */ |
||
| 1422 | protected function _handle_html_redirects() { |
||
| 1440 | |||
| 1441 | |||
| 1442 | |||
| 1443 | /** |
||
| 1444 | * set_checkout_anchor |
||
| 1445 | * |
||
| 1446 | * @access public |
||
| 1447 | * @return string |
||
| 1448 | */ |
||
| 1449 | public function set_checkout_anchor() { |
||
| 1452 | |||
| 1453 | |||
| 1454 | |||
| 1455 | } |
||
| 1456 | // End of file EED_Single_Page_Checkout.module.php |
||
| 1457 | // Location: /modules/single_page_checkout/EED_Single_Page_Checkout.module.php |
||
| 1458 |
This check looks for a call to a parent method whose name is different than the method from which it is called.
Consider the following code:
The
getFirstName()method in theSoncalls the wrong method in the parent class.