function vtprd_pricing_deal_msgs_advanced($atts)
{
    global $vtprd_rules_set, $vtprd_setup_options, $vtprd_info;
    extract(shortcode_atts(array('group1_type' => 'cart', 'group1_and_or_wholestore_msgs_only' => 'and', 'group1_wholestore_msgs_only' => 'no', 'and_or_group1_to_group2' => 'and', 'group2_rules' => '', 'group2_and_or_roles' => 'and', 'group2_roles' => '', 'and_or_group2_to_group3' => 'and', 'group3_product_category' => '', 'group3_and_or_plugin_category' => 'or', 'group3_plugin_category' => ''), $atts));
    //override default value with supplied parameters...
    vtprd_set_selected_timezone();
    $vtprd_rules_set = get_option('vtprd_rules_set');
    $output = '<div class="vtprd-advanced-deal-msg-area">';
    $msg_counter = 0;
    //echo 'incoming attributes= ' .$atts. '<br>'; //mwnt
    $sizeof_rules_set = sizeof($vtprd_rules_set);
    for ($i = 0; $i < $sizeof_rules_set; $i++) {
        if ($vtprd_rules_set[$i]->rule_status != 'publish') {
            continue;
        }
        $rule_is_date_valid = vtprd_rule_date_validity_test($i);
        if (!$rule_is_date_valid) {
            continue;
        }
        if (defined('VTPRD_PRO_DIRNAME') && $vtprd_setup_options['use_lifetime_max_limits'] == 'yes') {
            //IP is immediately available, check against Lifetime limits
            $rule_has_reached_lifetime_limit = vtprd_rule_lifetime_validity_test($i, 'shortcode');
            if ($rule_has_reached_lifetime_limit) {
                continue;
            }
        }
        //v1.0.9.3 new skipt test
        if ($vtprd_rules_set[$i]->discount_product_full_msg == $vtprd_info['default_full_msg']) {
            //v1.1.0.5
            continue;
        }
        $status = array('group1_type' => '', 'group1_wholestore_msgs_only' => '', 'group2_rules' => '', 'group2_roles' => '', 'group3_product_category' => '', 'group3_plugin_category' => '', 'group1' => '', 'group2' => '', 'group3' => '', 'total' => '');
        //SET Status success/failed for each parameter
        switch ($group1_type) {
            case 'cart':
                if ($vtprd_rules_set[$i]->rule_execution_type == 'display') {
                    $status['group1_type'] = 'failed';
                } else {
                    $status['group1_type'] = 'success';
                }
                break;
            case 'catalog':
                if ($vtprd_rules_set[$i]->rule_execution_type == 'cart') {
                    $status['group1_type'] = 'failed';
                } else {
                    $status['group1_type'] = 'success';
                }
                break;
            case 'all':
                $status['group1_type'] = 'success';
                break;
            default:
                $status['group1_type'] = 'failed';
                break;
        }
        if ($group1_wholestore_msgs_only == 'yes') {
            if ($vtprd_rules_set[$i]->inPop == 'wholeStore' || $vtprd_rules_set[$i]->actionPop == 'wholeStore') {
                $status['group1_wholestore_msgs_only'] = 'success';
            } else {
                $status['group1_wholestore_msgs_only'] = 'failed';
            }
        } else {
            $status['group1_wholestore_msgs_only'] = 'success';
        }
        if ($group2_roles > ' ') {
            $userRole = vtprd_get_current_user_role();
            //mwn04142014
            if ($userRole = 'notLoggedIn') {
                $userRole_name = 'Not logged in (just visiting)';
            } else {
                $userRole_name = translate_user_role($userRole);
            }
            $group2_roles_array = explode(",", $group2_roles);
            //remove comma separator, make list an array
            if (in_array($userRole_name, $group2_roles_array)) {
                $status['group2_roles'] = 'success';
            } else {
                $status['group2_roles'] = 'failed';
            }
        } else {
            $status['group2_roles'] = 'success';
        }
        if ($group2_rules > ' ') {
            $group2_rules_array = explode(",", $group2_rules);
            //remove comma separator, make list an array
            if (in_array($vtprd_rules_set[$i]->post_id, $group2_rules_array)) {
                $status['group2_rules'] = 'success';
            } else {
                $status['group2_rules'] = 'failed';
            }
        } else {
            $status['group2_rules'] = 'success';
        }
        if ($group3_product_category > ' ') {
            $group3_product_category_array = explode(",", $group3_product_category);
            //remove comma separator, make list an array
            if (array_intersect($vtprd_rules_set[$i]->prodcat_in_checked, $group3_product_category_array) || array_intersect($vtprd_rules_set[$i]->prodcat_out_checked, $group3_product_category_array)) {
                $status['group3_product_category'] = 'success';
            } else {
                $status['group3_product_category'] = 'failed';
            }
        } else {
            $status['group3_product_category'] = 'success';
        }
        if ($group3_plugin_category > ' ') {
            $group3_plugin_category_array = explode(",", $group3_plugin_category);
            //remove comma separator, make list an array
            if (array_intersect($vtprd_rules_set[$i]->rulecat_in_checked, $group3_plugin_category_array) || array_intersect($vtprd_rules_set[$i]->rulecat_out_checked, $group3_plugin_category_array)) {
                $status['group3_plugin_category'] = 'success';
            } else {
                $status['group3_plugin_category'] = 'failed';
            }
        } else {
            $status['group3_plugin_category'] = 'success';
        }
        //Evaluate status settings
        //evaluate group1
        switch ($group1_and_or_wholestore_msgs_only) {
            case 'and':
                if ($status['group1_type'] == 'success' && $status['group1_wholestore_msgs_only'] == 'success') {
                    $status['group1'] = 'success';
                } else {
                    $status['group1'] = 'failed';
                }
                break;
            case 'or':
                if ($status['group1_type'] == 'success' || $status['group1_wholestore_msgs_only'] == 'success') {
                    $status['group1'] = 'success';
                } else {
                    $status['group1'] = 'failed';
                }
                break;
            default:
                $status['group1'] = 'failed';
                break;
        }
        //evaluate group2
        switch ($group2_and_or_roles) {
            case 'and':
                if ($status['group2_rules'] == 'success' && $status['group2_roles'] == 'success') {
                    $status['group2'] = 'success';
                } else {
                    $status['group2'] = 'failed';
                }
                break;
            case 'or':
                if ($status['group2_rules'] == 'success' || $status['group2_roles'] == 'success') {
                    $status['group2'] = 'success';
                } else {
                    $status['group2'] = 'failed';
                }
                break;
            default:
                $status['group2'] = 'failed';
                break;
        }
        //evaluate group3
        switch ($group3_and_or_plugin_category) {
            case 'and':
                if ($status['group3_product_category'] == 'success' && $status['group3_plugin_category'] == 'success') {
                    $status['group3'] = 'success';
                } else {
                    $status['group3'] = 'failed';
                }
                break;
            case 'or':
                if ($status['group3_product_category'] == 'success' || $status['group3_plugin_category'] == 'success') {
                    $status['group3'] = 'success';
                } else {
                    $status['group3'] = 'failed';
                }
                break;
            default:
                $status['group3'] = 'failed';
                break;
        }
        //evaluate all 3 groups together
        switch (true) {
            case $and_or_group1_to_group2 == 'and' && $and_or_group2_to_group3 == 'and':
                if ($status['group1'] == 'success' && $status['group2'] == 'success' && $status['group3'] == 'success') {
                    $status['total'] = 'success';
                } else {
                    $status['total'] = 'failed';
                }
                break;
            case $and_or_group1_to_group2 == 'and' && $and_or_group2_to_group3 == 'or':
                if ($status['group1'] == 'success' && $status['group2'] == 'success' || $status['group3'] == 'success') {
                    $status['total'] = 'success';
                } else {
                    $status['total'] = 'failed';
                }
                break;
            case $and_or_group1_to_group2 == 'or' && $and_or_group2_to_group3 == 'and':
                if (($status['group1'] == 'success' || $status['group2'] == 'success') && $status['group3'] == 'success') {
                    $status['total'] = 'success';
                } else {
                    $status['total'] = 'failed';
                }
                break;
            case $and_or_group1_to_group2 == 'or' && $and_or_group2_to_group3 == 'or':
                if ($status['group1'] == 'success' || $status['group2'] == 'success' || $status['group3'] == 'success') {
                    $status['total'] = 'success';
                } else {
                    $status['total'] = 'failed';
                }
                break;
        }
        if ($status['total'] == 'success') {
            $msg_counter++;
            $output .= '<span class="vtprd-advanced-deal-msg" id="vtprd-advanced-deal-msg-' . $vtprd_rules_set[$i]->post_id . '">';
            $output .= stripslashes($vtprd_rules_set[$i]->discount_product_full_msg);
            $output .= '</span>';
            $output .= '<span class="vtprd-line-skip-with-display-block"></span>';
        }
    }
    //end 'for' loop
    if ($msg_counter == 0) {
        return;
    }
    //close owning div
    $output .= '</div>';
    //  vtprd_enqueue_front_end_css();
    return $output;
}
예제 #2
0
 public function vtprd_process_discount()
 {
     //and print discount info...
     //error_log( print_r(  'Function begin - vtprd_process_discount', true ) );
     global $woocommerce, $vtprd_cart, $vtprd_cart_item, $vtprd_info, $vtprd_rules_set, $vtprd_rule, $wpsc_coupons, $vtprd_setup_options;
     //v1.0.9.0
     /*
     //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
     //In order to prevent recursive executions, test for a TIMESTAMP    
     if (isset($_SESSION['process_discount_timestamp'])) {
       $previous_process_discount_timestamp = $_SESSION['process_discount_timestamp'];
       $current_process_discount_timestamp  = time();
       if ( ($current_time_in_seconds - $previous_process_discount_timestamp) > '1' ) { //session data older than 1 second
         $_SESSION['process_discount_timestamp'] = time();
       } else {
         return;
       }
     } else {
       $_SESSION['process_discount_timestamp'] = time();
     }
     //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++    
     */
     //calc discounts
     $vtprd_info['current_processing_request'] = 'cart';
     $vtprd_apply_rules = new VTPRD_Apply_Rules();
     //v1.0.9.0  begin
     //load the vtprd cart html fields, for later use - IF we are showing the discount in-line in unit price
     if ($vtprd_setup_options['discount_taken_where'] == 'discountUnitPrice') {
         $catalog_or_inline = 'inline';
     } else {
         $catalog_or_inline = null;
     }
     vtprd_get_cart_html_prices('process discount', $catalog_or_inline);
     //v1.1.1
     //v1.0.9.0  end
     /*  *************************************************
          Load this info into session variables, to begin the 
          DATA CHAIN - global to session back to global
          global to session - in vtprd_process_discount
          session to global - in vtprd_woo_validate_order
          access global     - in vtprd_post_purchase_maybe_save_log_info   
         *************************************************   */
     if (!isset($_SESSION)) {
         session_start();
         header("Cache-Control: no-cache");
         header("Pragma: no-cache");
     }
     //v1.1.0.9 begin  need to clear this out
     if (isset($_SESSION['data_chain'])) {
         $contents = $_SESSION['data_chain'];
         unset($_SESSION['data_chain'], $contents);
     }
     ///v1.1.0.9 end
     $contents_total = $woocommerce->cart->cart_contents_total;
     $applied_coupons = $woocommerce->cart->applied_coupons;
     $data_chain = array();
     $data_chain[] = $vtprd_rules_set;
     $data_chain[] = $vtprd_cart;
     $data_chain[] = vtprd_get_current_user_role();
     //v1.0.7.2
     $data_chain[] = $contents_total;
     $data_chain[] = $applied_coupons;
     $_SESSION['data_chain'] = serialize($data_chain);
     return;
 }
예제 #3
0
 public function vtprd_is_role_in_actionPop_list_check($i, $k)
 {
     global $vtprd_cart, $vtprd_rules_set, $vtprd_rule, $vtprd_info, $vtprd_setup_options;
     //error_log( print_r(  'vtprd_is_role_in_actionPop_list_check ', true ) );
     if (sizeof($vtprd_rules_set[$i]->role_out_checked) > 0) {
         if (in_array(vtprd_get_current_user_role(), $vtprd_rules_set[$i]->role_out_checked)) {
             //if role is in previously checked_list
             if ($vtprd_setup_options['debugging_mode_on'] == 'yes') {
                 error_log(print_r('In:: vtprd_is_role_in_actionPop_list_check($i,$k)', true));
                 error_log(print_r('current user role= ' . $userRole, true));
                 error_log(print_r('rule id= ' . $vtprd_rules_set[$i]->post_id, true));
                 error_log(print_r('$i= ' . $i, true));
                 error_log(print_r('$k= ' . $k, true));
                 error_log(print_r('role_out_checked', true));
                 error_log(var_export($vtprd_rules_set[$i]->role_out_checked, true));
             }
             $vtprd_cart->cart_items[$k]->cartAuditTrail[$vtprd_rules_set[$i]->post_id]['actionPop_role_found'] = 'yes';
             return true;
         }
     }
     $vtprd_cart->cart_items[$k]->cartAuditTrail[$vtprd_rules_set[$i]->post_id]['actionPop_role_found'] = 'no';
     return false;
 }
예제 #4
0
function vtprd_maybe_get_price_single_product($product_id, $price = null)
{
    global $post, $vtprd_info;
    //store product-specific session info
    if (!isset($_SESSION)) {
        session_start();
        header("Cache-Control: no-cache");
        header("Pragma: no-cache");
    }
    //if already in the session variable... => this routine can be called multiple times in displaying a single catalog price.  check first if already done.
    //      echo 'IN THE ROUTINE, $product_id= ' .$product_id.'<br>' ;
    //            echo 'SESSION data <pre>'.print_r($_SESSION, true).'</pre>' ;
    if (isset($_SESSION['vtprd_product_session_info_' . $product_id])) {
        $vtprd_info['product_session_info'] = $_SESSION['vtprd_product_session_info_' . $product_id];
        //will be a problem in Ajax...
        $current_time_in_seconds = time();
        $user_role = vtprd_get_current_user_role();
        //*****************************
        //v1.0.8.4 timestamp  begin
        $vtprd_ruleset_timestamp = get_option('vtprd_ruleset_timestamp');
        if (!$vtprd_ruleset_timestamp) {
            $vtprd_ruleset_timestamp = 0;
        }
        //v1.0.8.4 timestamp  end
        //*****************************
        if ($current_time_in_seconds - $vtprd_info['product_session_info']['session_timestamp_in_seconds'] > '3600' || $user_role != $vtprd_info['product_session_info']['user_role'] || $vtprd_ruleset_timestamp > $vtprd_info['product_session_info']['session_timestamp_in_seconds']) {
            //v1.0.8.4 timestamp - GET *more recent* ADMIN updates to ruleset NOW
            vtprd_apply_rules_to_single_product($product_id, $price);
            //reset stored role to current
            $vtprd_info['product_session_info']['user_role'] = $user_role;
        }
    } else {
        //First time obtaining the info, also moves the data to $vtprd_info
        vtprd_apply_rules_to_single_product($product_id, $price);
        // vtprd_apply_rules_to_vargroup_or_single($product_id, $price);
    }
    //$vtprd_info['product_session_info'] is loaded by this time...
    return;
}
 public function vtprd_is_user_in_role_list($checked_list)
 {
     if (!is_user_logged_in()) {
         return false;
     }
     if (strpos($checked_list, vtprd_get_current_user_role())) {
         //if role is in previously checked_list
         return true;
     } else {
         return false;
     }
 }