function vtwpr_wholesale_pricing_msgs_advanced($atts)
{
    global $vtwpr_rules_set, $vtwpr_setup_options;
    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...
    vtwpr_set_selected_timezone();
    $vtwpr_rules_set = get_option('vtwpr_rules_set');
    $output = '<div class="vtwpr-advanced-deal-msg-area">';
    $msg_counter = 0;
    //echo 'incoming attributes= ' .$atts. '<br>'; //mwnt
    $sizeof_rules_set = sizeof($vtwpr_rules_set);
    for ($i = 0; $i < $sizeof_rules_set; $i++) {
        if ($vtwpr_rules_set[$i]->rule_status != 'publish') {
            continue;
        }
        $rule_is_date_valid = vtwpr_rule_date_validity_test($i);
        if (!$rule_is_date_valid) {
            continue;
        }
        if (defined('VTWPR_PRO_DIRNAME') && $vtwpr_setup_options['use_lifetime_max_limits'] == 'yes') {
            //IP is immediately available, check against Lifetime limits
            $rule_has_reached_lifetime_limit = vtwpr_rule_lifetime_validity_test($i, 'shortcode');
            if ($rule_has_reached_lifetime_limit) {
                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 ($vtwpr_rules_set[$i]->rule_execution_type == 'display') {
                    $status['group1_type'] = 'failed';
                } else {
                    $status['group1_type'] = 'success';
                }
                break;
            case 'catalog':
                if ($vtwpr_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 ($vtwpr_rules_set[$i]->inPop == 'wholeStore' || $vtwpr_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 = vtwpr_get_current_user_role();
            $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($vtwpr_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($vtwpr_rules_set[$i]->prodcat_in_checked, $group3_product_category_array) || array_intersect($vtwpr_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($vtwpr_rules_set[$i]->rulecat_in_checked, $group3_plugin_category_array) || array_intersect($vtwpr_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="vtwpr-advanced-deal-msg" id="vtwpr-advanced-deal-msg-' . $vtwpr_rules_set[$i]->post_id . '">';
            $output .= stripslashes($vtwpr_rules_set[$i]->discount_product_full_msg);
            $output .= '</span>';
            $output .= '<span class="vtwpr-line-skip-with-display-block"></span>';
        }
    }
    //end 'for' loop
    if ($msg_counter == 0) {
        return;
    }
    //close owning div
    $output .= '</div>';
    //  vtwpr_enqueue_front_end_css();
    return $output;
}
Exemplo n.º 2
0
 public function vtwpr_manage_shared_rule_tests($i)
 {
     global $vtwpr_cart, $vtwpr_rules_set, $vtwpr_rule, $vtwpr_info, $vtwpr_setup_options;
     $rule_is_date_valid = vtwpr_rule_date_validity_test($i);
     if (!$rule_is_date_valid) {
         $vtwpr_rules_set[$i]->rule_status = 'dateInvalid';
         //temp chg of rule_status for this execution only
         $vtwpr_rules_set[$i]->rule_processing_status = 'Cart Transaction does not fall within date boundaries set for the rule.';
     }
     //IP is immediately available, check against Lifetime limits
     //  check against all rules
     //EDITED * + * +  * + * +  * + * +  * + * +
     //don't run if 'no'
     if ($vtwpr_rules_set[$i]->cumulativeCouponPricing == 'no' && $vtwpr_rules_set[0]->coupons_amount_without_rule_discounts > 0) {
         $vtwpr_rules_set[$i]->rule_status = 'cumulativeCouponPricingNo';
         //temp chg of rule_status for this execution only
         $vtwpr_rules_set[$i]->rule_processing_status = 'Coupon presented, rule switch says do not run.';
     }
 }