public function vtprd_ajax_edit_product($product_ID, $inOrOut) { global $wpdb, $post, $vtprd_rule, $vtprd_setup_options; //edits copied from vtprd-rules-update.php if ($product_ID == ' ') { $vtprd_rule->rule_error_message[] = __('No Product ID was supplied.', 'vtprd'); return; } if (is_numeric($product_ID) === false) { $vtprd_rule->rule_error_message[0] = __('<br><br>Product ID in error = <span id="varProdID-error-ID">', 'vtprd') . $product_ID . __('</span>', 'vtprd'); if ($vtprd_setup_options['debugging_mode_on'] == 'yes') { $vtprd_rule->rule_error_message[0] = __('<br><br>Product ID in error = <span id="varProdID-error-ID">', 'vtprd') . $product_ID . __('</span>', 'vtprd'); } return; } $test_post = get_post($product_ID); if (!$test_post) { $vtprd_rule->rule_error_message[] = __('Product ID was not found. >', 'vtprd'); if ($vtprd_setup_options['debugging_mode_on'] == 'yes') { $vtprd_rule->rule_error_message[0] = __('<br><br>Product ID in error = <span id="varProdID-error-ID">', 'vtprd') . $product_ID . __('</span>', 'vtprd'); } return; } if ($inOrOut == 'in') { $vtprd_rule->inPop_varProdID_name = $test_post->post_title; } else { $vtprd_rule->actionPop_varProdID_name = $test_post->post_title; } $product_has_variations = vtprd_test_for_variations($product_ID); if ($product_has_variations == 'no') { $vtprd_rule->rule_error_message[] = __('Product has no Variations. Product Name = ', 'vtprd') . $test_post->post_title . __('<br><br> Please use "Single Product Only" option, above.', 'vtprd'); if ($vtprd_setup_options['debugging_mode_on'] == 'yes') { $vtprd_rule->rule_error_message[0] = __('<br><br>Product ID in error = <span id="varProdID-error-ID">', 'vtprd') . $product_ID . __('</span>', 'vtprd'); } return; } $product_variation_IDs = vtprd_get_variations_list($product_ID); if (sizeof($product_variation_IDs) == 0) { //v1.0.5 // if ($product_variation_IDs <= ' ') { //v1.0.5 $vtprd_rule->rule_error_message[] = __('Product has no Variations. Product Name = ', 'vtprd') . $test_post->post_title . __('<br><br> Please use "Single Product Only" option, above.', 'vtprd'); if ($vtprd_setup_options['debugging_mode_on'] == 'yes') { $vtprd_rule->rule_error_message[0] = __('<br><br>Product ID in error = <span id="varProdID-error-ID">', 'vtprd') . $product_ID . __('</span>', 'vtprd'); } return; } return $product_variation_IDs; }
public function vtprd_edit_rule() { global $post, $wpdb, $vtprd_rule, $vtprd_info, $vtprd_rules_set, $vtprd_rule_template_framework, $vtprd_deal_edits_framework, $vtprd_deal_structure_framework; $vtprd_rule_new = new VTPRD_Rule(); // always start with fresh copy $selected = 's'; $vtprd_rule = $vtprd_rule_new; //otherwise vtprd_rule is not addressable! // NOT NEEDED now that the edits are going through successfully //for new rule, put in 1st iteration of deal info //$vtprd_rule->rule_deal_info[] = $vtprd_deal_structure_framework; mwnt //***************************************** // FILL / upd VTPRD_RULE... //***************************************** // Candidate Population $vtprd_rule->post_id = $post->ID; if ($_REQUEST['post_title'] > ' ') { //do nothing } else { $vtprd_rule->rule_error_message[] = array('insert_error_before_selector' => '#vtprd-deal-selection', 'error_msg' => __('The Rule needs to have a Title, but Title is empty.', 'vtprd')); } /* //specialty edits list: **FOR THE PRICE OF** =>for the price of within the group: buy condition must be an amt buy amt count must be > 1 buy amt must be = to discount amount count action group condition must be 'applies to entire' action group must be same as buy pool group only discount applies to must be = 'all' => for the price of next buy condition can be anything action amt condition must be an amt action amt count must be > 1 action amt must be = to discount amount count **CHEAPEST/MOST EXPENSIVE** *=> in buy group buy condition must be an amt buy amt count must be > 1 *=> in action group buy condition can be anything action amt condition can be an amt or $$ */ //Upper Selects $vtprd_rule->cart_or_catalog_select = $_REQUEST['cart-or-catalog-select']; $vtprd_rule->pricing_type_select = $_REQUEST['pricing-type-select']; $vtprd_rule->minimum_purchase_select = $_REQUEST['minimum-purchase-select']; $vtprd_rule->buy_group_filter_select = $_REQUEST['buy-group-filter-select']; $vtprd_rule->get_group_filter_select = $_REQUEST['get-group-filter-select']; $vtprd_rule->rule_on_off_sw_select = $_REQUEST['rule-on-off-sw-select']; $vtprd_rule->rule_type_select = $_REQUEST['rule-type-select']; $vtprd_rule->wizard_on_off_sw_select = $_REQUEST['wizard-on-off-sw-select']; $upperSelectsDoneSw = $_REQUEST['upperSelectsDoneSw']; if ($upperSelectsDoneSw != 'yes') { $vtprd_rule->rule_error_message[] = array('insert_error_before_selector' => '.top-box', 'error_msg' => __('Blueprint choices not yet completed', 'vtprd')); //mwn20140414 $vtprd_rule->rule_error_red_fields[] = '#blue-area-title'; //mwn20140414 } //mwn20140414 begin ==> added these IDs to rules_ui.php ... if ($vtprd_rule->cart_or_catalog_select == 'choose' || $vtprd_rule->cart_or_catalog_select <= ' ') { $vtprd_rule->rule_error_message[] = array('insert_error_before_selector' => '.top-box', 'error_msg' => __('Cart or Catalog choice not yet made', 'vtprd')); //mwn20140414 $vtprd_rule->rule_error_red_fields[] = '#cart-or-catalog-select-label'; } if ($vtprd_rule->pricing_type_select == 'choose' || $vtprd_rule->pricing_type_select <= ' ') { $vtprd_rule->rule_error_message[] = array('insert_error_before_selector' => '.top-box', 'error_msg' => __('Deal Type choice not yet made', 'vtprd')); //mwn20140414 $vtprd_rule->rule_error_red_fields[] = '#pricing-type-select-label'; } if ($vtprd_rule->minimum_purchase_select == 'choose' || $vtprd_rule->minimum_purchase_select <= ' ') { $vtprd_rule->rule_error_message[] = array('insert_error_before_selector' => '.top-box', 'error_msg' => __('Deal Action choice not yet made', 'vtprd')); //mwn20140414 $vtprd_rule->rule_error_red_fields[] = '#minimum-purchase-select-label'; } //mwn20140414 end //#RULEtEMPLATE IS NOW A HIDDEN FIELD which carries the rule template SET WITHIN THE JS // in response to the inital dropdowns being selected. $vtprd_rule->rule_template = $_REQUEST['rule_template_framework']; if ($vtprd_rule->rule_template <= '0') { //mwn20140414 /* mwn20140414 $vtprd_rule->rule_error_message[] = array( 'insert_error_before_selector' => '.template-area', 'error_msg' => __('Pricing Deal Template choice is required.', 'vtprd') ); $vtprd_rule->rule_error_red_fields[] = '#deal-type-title' ; */ $this->vtprd_dump_deal_lines_to_rule(); // $this->vtprd_update_rules_info(); mwn20140414 return; //fatal exit.... } else { for ($i = 0; $i < sizeof($vtprd_rule_template_framework['option']); $i++) { //get template title to make that name available on the Rule if ($vtprd_rule_template_framework['option'][$i]['value'] == $vtprd_rule->rule_template) { $vtprd_rule->rule_template_name = $vtprd_rule_template_framework['option'][$i]['title']; $i = sizeof($vtprd_rule_template_framework['option']); } } } //DISCOUNT TEMPLATE $display_or_cart = substr($vtprd_rule->rule_template, 0, 1); if ($display_or_cart == 'D') { $vtprd_rule->rule_execution_type = 'display'; } else { $vtprd_rule->rule_execution_type = 'cart'; } //using the selected Template, build the $vtprd_deal_edits_framework, used for all DEAL edits following $this->vtprd_build_deal_edits_framework(); //******************************************************************************** //EDIT DEAL LINES //***LOOP*** through all of the deal line iterations, edit lines //******************************************************************************** $deal_iterations_done = 'no'; //initialize variable $active_line_count = 0; //initialize variable $active_field_count = 0; for ($k = 0; $deal_iterations_done == 'no'; $k++) { if (isset($_REQUEST['buy_repeat_condition_' . $k]) && !empty($_REQUEST['buy_repeat_condition_' . $k])) { //is a deal line there? always 1 at least... foreach ($vtprd_deal_structure_framework as $key => $value) { //spin through all of the screen fields=> $key = field name, so has multiple uses... //load up the deal structure with incoming fields $vtprd_deal_structure_framework[$key] = $_REQUEST[$key . '_' . $k]; } //Edit deal line $this->vtprd_edit_deal_info_line($active_field_count, $active_line_count, $k); //add deal line to rule $vtprd_rule->rule_deal_info[] = $vtprd_deal_structure_framework; //add each line to rule, regardless if empty } else { $deal_iterations_done = 'yes'; } } //if max_amt_type is active, may have a max_amt_msg $vtprd_rule->discount_rule_max_amt_msg = $_REQUEST['discount_rule_max_amt_msg']; //if max_lifetime_amt_type is active, may have a max_amt_msg $vtprd_rule->discount_lifetime_max_amt_msg = $_REQUEST['discount_lifetime_max_amt_msg']; //if max_cum_amt_type is active, may have a max_amt_msg $vtprd_rule->discount_rule_cum_max_amt_msg = $_REQUEST['discount_rule_cum_max_amt_msg']; $vtprd_rule->discount_product_short_msg = $_REQUEST['discount_product_short_msg']; if ($vtprd_rule->discount_product_short_msg <= ' ' || $vtprd_rule->discount_product_short_msg == $_REQUEST['shortMsg']) { $vtprd_rule->rule_error_message[] = array('insert_error_before_selector' => '#messages-box', 'error_msg' => __('Checkout Short Message is required.', 'vtprd')); $vtprd_rule->rule_error_red_fields[] = '#discount_product_short_msg_label'; $vtprd_rule->rule_error_box_fields[] = '#discount_product_short_msg'; } else { $vtprd_rule->discount_product_short_msg = stripslashes($vtprd_rule->discount_product_short_msg); //v1.0.9.0 } $vtprd_rule->discount_product_full_msg = $_REQUEST['discount_product_full_msg']; //if default msg, get rid of it!!!!!!!!!!!!!! //v1.1.0.8 reworked the IF $vtprd_rule->discount_product_full_msg = stripslashes($vtprd_rule->discount_product_full_msg); //v1.0.9.0 if ($vtprd_rule->discount_product_full_msg == $vtprd_info['default_full_msg']) { $vtprd_rule->discount_product_full_msg = ' '; } /* full msg now OPTIONAL if ( ($vtprd_rule->discount_product_full_msg <= ' ') || ($vtprd_rule->discount_product_full_msg == $_REQUEST['fullMsg'] )){ $vtprd_rule->rule_error_message[] = array( 'insert_error_before_selector' => '#messages-box', 'error_msg' => __('Theme Full Message is required.', 'vtprd') ); $vtprd_rule->rule_error_red_fields[] = '#discount_product_full_msg_label' ; } */ $vtprd_rule->cumulativeRulePricing = $_REQUEST['cumulativeRulePricing']; if ($vtprd_rule->cumulativeRulePricing == 'yes') { if ($vtprd_rule->cumulativeRulePricingAllowed == 'yes') { $vtprd_rule->ruleApplicationPriority_num = $_REQUEST['ruleApplicationPriority_num']; $vtprd_rule->ruleApplicationPriority_num = preg_replace('/[^0-9.]+/', '', $vtprd_rule->ruleApplicationPriority_num); //remove leading/trailing spaces, percent sign, dollar sign if (is_numeric($vtprd_rule->ruleApplicationPriority_num) === false) { $vtprd_rule->ruleApplicationPriority_num = '10'; //init variable /* $vtprd_rule->rule_error_message[] = array( 'insert_error_before_selector' => '#cumulativePricing_box', 'error_msg' => __('"Apply this Rule Discount in Addition to Other Rule Discounts" = Yes. Rule Priority Sort Number is required, and must be numeric. "10" inserted if blank.', 'vtprd') ); $vtprd_rule->rule_error_red_fields[] = '#ruleApplicationPriority_num_label' ; */ } } else { $vtprd_rule->rule_error_message[] = array('insert_error_before_selector' => '#cumulativePricing_box', 'error_msg' => __('With this Rule Template chosen, "Apply this Rule Discount in Addition to Other Rule Discounts" must = "No".', 'vtprd')); $vtprd_rule->rule_error_red_fields[] = '#ruleApplicationPriority_num_label'; $vtprd_rule->rule_error_box_fields[] = '#ruleApplicationPriority_num'; $vtprd_rule->ruleApplicationPriority_num = '10'; //init variable } } else { //v1.0.5.3 begin // $vtprd_rule->ruleApplicationPriority_num = '10'; //init variable $vtprd_rule->ruleApplicationPriority_num = $_REQUEST['ruleApplicationPriority_num']; $vtprd_rule->ruleApplicationPriority_num = preg_replace('/[^0-9.]+/', '', $vtprd_rule->ruleApplicationPriority_num); //remove leading/trailing spaces, percent sign, dollar sign if (is_numeric($vtprd_rule->ruleApplicationPriority_num) === false) { $vtprd_rule->ruleApplicationPriority_num = '10'; //init variable } //v1.0.5.3 end } $vtprd_rule->cumulativeSalePricing = $_REQUEST['cumulativeSalePricing']; if ($vtprd_rule->cumulativeSalePricing != 'no' && $vtprd_rule->cumulativeSalePricingAllowed == 'no') { $vtprd_rule->rule_error_message[] = array('insert_error_before_selector' => '#cumulativePricing_box', 'error_msg' => __('With this Rule Template chosen, "Rule Discount in addition to Product Sale Pricing" must = "Does not apply when Product Sale Priced".', 'vtprd')); $vtprd_rule->rule_error_red_fields[] = '#cumulativePricing_box'; $vtprd_rule->rule_error_box_fields[] = '#cumulativePricing'; } $vtprd_rule->cumulativeCouponPricing = $_REQUEST['cumulativeCouponPricing']; if ($vtprd_rule->cumulativeCouponPricing == 'yes' && $vtprd_rule->cumulativeCouponPricingAllowed == 'no') { $vtprd_rule->rule_error_message[] = array('insert_error_before_selector' => '#cumulativePricing_box', 'error_msg' => __('With this Rule Template chosen, " Apply Rule Discount in addition to Coupon Discount?" must = "No".', 'vtprd')); $vtprd_rule->rule_error_red_fields[] = '#cumulativePricing_box'; $vtprd_rule->rule_error_box_fields[] = '#cumulativePricing'; } //inPop $vtprd_rule->role_and_or_in = 'or'; //initialize so it's always there. overwritten by logic as needed. $vtprd_rule->inPop = $_REQUEST['popChoiceIn']; switch ($vtprd_rule->inPop) { case 'wholeStore': break; case 'groups': //get all checked taxonomies/roles as arrays if (!empty($_REQUEST['tax-input-prodcat-in'])) { $vtprd_rule->prodcat_in_checked = $_REQUEST['tax-input-prodcat-in']; // $vtprd_rule->prodcat_in_checked_min_requirement = $_REQUEST["prodcat-list-in-min-requirement"]; foreach ($vtprd_rule->prodcat_in_checked as $term_id) { if (!empty($_REQUEST["prodcat-list-in-value-' . {$term_id} . '"])) { $vtprd_rule->prodcat_in_checked_info[$term_id]->value = $_REQUEST["prodcat-list-in-value-' . {$term_id} . '"]; $vtprd_rule->prodcat_in_checked_info[$term_id]->value_selector = $_REQUEST["prodcat-list-in-value-selector-' . {$term_id} . '"]; } } } if (!empty($_REQUEST['tax-input-rulecat-in'])) { $vtprd_rule->rulecat_in_checked = $_REQUEST['tax-input-rulecat-in']; // $vtprd_rule->rulecat_in_checked_min_requirement = $_REQUEST["rulecat-list-in-min-requirement"]; foreach ($vtprd_rule->rulecat_in_checked as $term_id) { if (!empty($_REQUEST["rulecat-list-in-value-' . {$term_id} . '"])) { $vtprd_rule->rulecat_in_checked_info[$term_id]->value = $_REQUEST["rulecat-list-in-value-' . {$term_id} . '"]; $vtprd_rule->rulecat_in_checked_info[$term_id]->value_selector = $_REQUEST["rulecat-list-in-value-selector-' . {$term_id} . '"]; } } } if (!empty($_REQUEST['tax-input-role-in'])) { $vtprd_rule->role_in_checked = $_REQUEST['tax-input-role-in']; } if (!$vtprd_rule->prodcat_in_checked && !$vtprd_rule->rulecat_in_checked && !$vtprd_rule->role_in_checked) { $vtprd_rule->rule_error_message[] = array('insert_error_before_selector' => '#buy_group_box_0', 'error_msg' => __('In Cart Search Criteria Selection Metabox, "Category / Logged-in Role / Custom Category" was chosen, but no Categories or Roles checked', 'vtprd')); $vtprd_rule->rule_error_red_fields[] = '#inPopChoiceIn_label'; $vtprd_rule->rule_error_red_fields[] = '#prodcat-in-label'; $vtprd_rule->rule_error_red_fields[] = '#rulecat-in-label'; $vtprd_rule->rule_error_red_fields[] = '#role-in-label'; } // And/Or switch for category/role relationship $vtprd_rule->role_and_or_in = $_REQUEST['andorChoiceIn']; switch ($vtprd_rule->role_and_or_in) { case 'and': // $vtprd_rule->role_and_or_in[0]['user_input'] = $selected; if (!$vtprd_rule->prodcat_in_checked && !$vtprd_rule->rulecat_in_checked && !$vtprd_rule->role_in_checked) { $vtprd_rule->rule_error_message[] = array('insert_error_before_selector' => '#buy_group_box_0', 'error_msg' => __('In "Buy" Group Selection, "Category / Logged-in Role / Custom Category" and "And" was chosen, but no Categories or Roles are checked', 'vtprd')); $vtprd_rule->rule_error_red_fields[] = '#inPopChoiceIn_label'; $vtprd_rule->rule_error_red_fields[] = '#prodcat-in-label'; $vtprd_rule->rule_error_red_fields[] = '#rulecat-in-label'; $vtprd_rule->rule_error_red_fields[] = '#role-in-label'; } else { if (!$vtprd_rule->prodcat_in_checked && !$vtprd_rule->rulecat_in_checked) { $vtprd_rule->rule_error_message[] = array('insert_error_before_selector' => '#buy_group_box_0', 'error_msg' => __('In "Buy" Group Selection, "Category / Logged-in Role / Custom Category" and "And" was chosen, but no Categories are checked. <br><br><br><br><em>If Roles alone are desired, please select "OR".</em>', 'vtprd')); $vtprd_rule->rule_error_red_fields[] = '#inPopChoiceIn_label'; $vtprd_rule->rule_error_red_fields[] = '#prodcat-in-label'; $vtprd_rule->rule_error_red_fields[] = '#rulecat-in-label'; } else { if (!$vtprd_rule->role_in_checked) { $vtprd_rule->rule_error_message[] = array('insert_error_before_selector' => '#buy_group_box_0', 'error_msg' => __('In "Buy" Group Selection, "Category / Logged-in Role / Custom Category" and "And" was chosen, but no Roles are checked. <br><br><br><br><em>If Categories alone are desired, please select "OR".</em>', 'vtprd')); $vtprd_rule->rule_error_red_fields[] = '#inPopChoiceIn_label'; $vtprd_rule->rule_error_red_fields[] = '#role-in-label'; } } } break; case 'or': // $vtprd_rule->role_and_or_in[1]['user_input'] = $selected; break; default: $vtprd_rule->role_and_or_in = 'or'; //v1.0.5.5 //initialize so it's always there. overwritten by logic as needed. break; } break; case 'vargroup': // $vtprd_rule->inPop[2]['user_input'] = $selected; $vtprd_rule->inPop_varProdID = $_REQUEST['inVarProdID']; //blank or spaces... if ($vtprd_rule->inPop_varProdID == '' || $vtprd_rule->inPop_varProdID == ' ') { $vtprd_rule->rule_error_message[] = array('insert_error_before_selector' => '#vtprd-buy-action-groups', 'error_msg' => __('In "Buy" Group Selection, "*Single Product with variations* was chosen, but Product ID was not supplied.', 'vtprd')); $vtprd_rule->rule_error_red_fields[] = '#inPopChoiceIn_label'; $vtprd_rule->rule_error_red_fields[] = '#varProdID-in-label'; } $vtprd_rule->inPop_varProdID = preg_replace('/[^0-9.]+/', '', $vtprd_rule->inPop_varProdID); //remove leading/trailing spaces, percent sign, dollar sign if (is_numeric($vtprd_rule->inPop_varProdID) === false) { $vtprd_rule->rule_error_message[] = array('insert_error_before_selector' => '#inPop-varProdID-cntl', 'error_msg' => __('In "Buy" Group Selection, "*Single Product with variations* was chosen, but Product ID was not numeric.', 'vtprd')); $vtprd_rule->rule_error_red_fields[] = '#inPopChoiceIn_label'; $vtprd_rule->rule_error_red_fields[] = '#varProdID-in-label'; } else { $test_post = get_post($vtprd_rule->inPop_varProdID); if (!$test_post) { $vtprd_rule->rule_error_message[] = array('insert_error_before_selector' => '#inPop-varProdID-cntl', 'error_msg' => __('In "Buy" Group Selection, "*Single Product with variations* was chosen, but Product ID was not found.', 'vtprd')); $vtprd_rule->rule_error_red_fields[] = '#inPopChoiceIn_label'; $vtprd_rule->rule_error_red_fields[] = '#varProdID-in-label'; } else { $vtprd_rule->inPop_varProdID_name = sanitize_title($test_post->post_title) . ' (Variations)'; $product_has_variations = vtprd_test_for_variations($vtprd_rule->inPop_varProdID); if ($product_has_variations == 'yes') { if (!empty($_REQUEST['tax-input-var-in'])) { $vtprd_rule->var_in_checked = $_REQUEST['tax-input-var-in']; // $vtprd_rule->var_in_checked_min_requirement = $_REQUEST["var-list-in-min-requirement"]; $checked_count = 0; foreach ($vtprd_rule->var_in_checked as $varID) { $checked_count++; if (!empty($_REQUEST["var-list-in-value-' . {$varID} . '"])) { $vtprd_rule->var_in_checked_info[$varID]->value = $_REQUEST["var-list-in-value-' . {$varID} . '"]; $vtprd_rule->var_in_checked_info[$varID]->value_selector = $_REQUEST["var-list-in-value-selector-' . {$varID} . '"]; } } //used in the DISPLAY type 'yousave' message only, about how many variations are on sale $checkbox_count = $_REQUEST['checkbox_count-var-in']; //checkbox_count-var-in hidden field from ajax... switch (true) { case $checkbox_count == $checked_count: $vtprd_rule->inPop_varProdID_parentLit = 'all'; break; case $checked_count > 1: $vtprd_rule->inPop_varProdID_parentLit = 'some'; break; case $checked_count == 1: $vtprd_rule->inPop_varProdID_parentLit = 'one'; break; } // $vtprd_rule->inPop_varProdID_parentLit = '$checked_count=' .$checked_count . ' $checkbox_count=' .$checkbox_count; //mwntest } //mwnt echo 'var_in_checked <pre>'.print_r($vtprd_rule->var_in_checked, true).'</pre>' ; if (sizeof($vtprd_rule->var_in_checked) <= 0) { //if (!$vtprd_rule->var_in_checked) { $vtprd_rule->rule_error_message[] = array('insert_error_before_selector' => '#inPop-varProdID-cntl', 'error_msg' => __('In "Buy" Group Selection, "Single Product with variations" was chosen, but no Variations checked', 'vtprd')); $vtprd_rule->rule_error_red_fields[] = '#inPopChoiceIn_label'; $vtprd_rule->rule_error_red_fields[] = '#varProdID-in-label'; } } else { $vtprd_rule->rule_error_message[] = array('insert_error_before_selector' => '#inPop-varProdID-cntl', 'error_msg' => __('In "Buy" Group Selection, "Single Product with variations" was chosen, but no Product has no Variations. Please use "Single Product Only" option.', 'vtprd')); $vtprd_rule->rule_error_red_fields[] = '#inPopChoiceIn_label'; $vtprd_rule->rule_error_red_fields[] = '#varProdID-in-label'; } } //v1.1 begin if (!empty($_REQUEST['tax-input-role-in'])) { $vtprd_rule->role_in_checked = $_REQUEST['tax-input-role-in']; } //v1.1 end } // $this->vtprd_set_default_or_values_in(); break; case 'single': // edit for single product ID $vtprd_rule->inPop_singleProdID = $_REQUEST['singleProdID_in']; if ($vtprd_rule->inPop_singleProdID == ' ') { $vtprd_rule->rule_error_message[] = array('insert_error_before_selector' => '#buy_group_box_0', 'error_msg' => __('In "Buy" Group Selection, "*Single Product Only* was chosen, but Product ID was not supplied.', 'vtprd')); $vtprd_rule->rule_error_red_fields[] = '#inPopChoiceIn_label'; $vtprd_rule->rule_error_red_fields[] = '#singleProdID-in-label'; } $vtprd_rule->inPop_singleProdID = preg_replace('/[^0-9.]+/', '', $vtprd_rule->inPop_singleProdID); //remove leading/trailing spaces, percent sign, dollar sign if (is_numeric($vtprd_rule->inPop_singleProdID) === false) { $vtprd_rule->rule_error_message[] = array('insert_error_before_selector' => '#buy_group_box_0', 'error_msg' => __('In "Buy" Group Selection, "*Single Product Only* was chosen, but Product ID was not numeric.', 'vtprd')); $vtprd_rule->rule_error_red_fields[] = '#inPopChoiceIn_label'; $vtprd_rule->rule_error_red_fields[] = '#singleProdID-in-label'; } else { $test_post = get_post($vtprd_rule->inPop_singleProdID); if (!$test_post) { $vtprd_rule->rule_error_message[] = array('insert_error_before_selector' => '#buy_group_box_0', 'error_msg' => __('In "Buy" Group Selection, "*Single Product Only* was chosen, but Product ID was not found.', 'vtprd')); $vtprd_rule->rule_error_red_fields[] = '#inPopChoiceIn_label'; $vtprd_rule->rule_error_red_fields[] = '#singleProdID-in-label'; } else { $vtprd_rule->inPop_singleProdID_name = $test_post->post_title; $product_has_variations = vtprd_test_for_variations($vtprd_rule->inPop_singleProdID); if ($product_has_variations == 'yes') { $vtprd_rule->rule_error_message[] = array('insert_error_before_selector' => '#buy_group_box_0', 'error_msg' => __('In "Buy" Group Selection, "Single Product Only" was chosen, but ** Product has Variations **. Please use "Single Product with variations" option.', 'vtprd')); $vtprd_rule->rule_error_red_fields[] = '#inPopChoiceIn_label'; $vtprd_rule->rule_error_red_fields[] = '#singleProdID-in-label'; } } //v1.1 begin if (!empty($_REQUEST['tax-input-role-in'])) { $vtprd_rule->role_in_checked = $_REQUEST['tax-input-role-in']; } //v1.1 end } // $this->vtprd_set_default_or_values_in(); break; } //******************************************************************************************************************** //The WPSC Realtime Catalog repricing action does not pass variation-level info, so these options are disallowed //******************************************************************************************************************** if ($vtprd_rule->rule_execution_type == 'display' && VTPRD_PARENT_PLUGIN_NAME == 'WP E-Commerce') { if ($vtprd_rule->inPop == 'vargroup') { $vtprd_rule->rule_error_message[] = array('insert_error_before_selector' => '#inPop-varProdID-cntl', 'error_msg' => __('"Buy" Group Selection - Single with Variations may not be chosen when "Apply Price Reduction to Products in the Catalog" Pricing Deal Type is chosen.', 'vtprd')); $vtprd_rule->rule_error_red_fields[] = '#inPopChoiceIn_label'; } if ($vtprd_rule->cumulativeSalePricingAllowed == 'no') { $vtprd_rule->rule_error_message[] = array('insert_error_before_selector' => '#cumulativePricing_box', 'error_msg' => __('"Apply this Rule Discount in addition to Product Sale Pricing" must not be "No" when "Apply Price Reduction to Products in the Catalog" Pricing Deal Type is chosen.', 'vtprd')); $vtprd_rule->rule_error_red_fields[] = '#cumulativeSalePricing_label'; $vtprd_rule->rule_error_box_fields[] = '#cumulativeSalePricing'; } } //******************************************************************************************************************** // ruleApplicationPriority_num must ALWAYS be numeric, to allow for sorting //******************************************************************************************************************** /* $vtprd_rule->ruleApplicationPriority_num = preg_replace('/[^0-9.]+/', '', $vtprd_rule->ruleApplicationPriority_num); //remove leading/trailing spaces, percent sign, dollar sign if ( is_numeric($vtprd_rule->ruleApplicationPriority_num) === false ) { $vtprd_rule->ruleApplicationPriority_num = '10'; } */ /* not necessary any more! if ($vtprd_rule->rule_execution_type == 'display') { //display rules must ALWAYS sort first, so we reset it here $vtprd_rule->ruleApplicationPriority_num = '0'; } */ //actionPop $vtprd_rule->role_and_or_out = 'or'; //initialize so it's always there. overwritten by logic as needed. $vtprd_rule->actionPop = $_REQUEST['popChoiceOut']; switch ($vtprd_rule->actionPop) { case 'sameAsInPop': case 'wholeStore': // $vtprd_rule->actionPop[0]['user_input'] = $selected; // $this->vtprd_set_default_or_values_out(); break; case 'groups': //get all checked taxonomies/roles as arrays if (!empty($_REQUEST['tax-input-prodcat-out'])) { $vtprd_rule->prodcat_out_checked = $_REQUEST['tax-input-prodcat-out']; // $vtprd_rule->prodcat_out_checked_min_requirement = $_REQUEST["prodcat-list-out-min-requirement"]; foreach ($vtprd_rule->prodcat_out_checked as $term_id) { if (!empty($_REQUEST["prodcat-list-out-value-' . {$term_id} . '"])) { $vtprd_rule->prodcat_out_checked_info[$term_id]->value = $_REQUEST["prodcat-list-out-value-' . {$term_id} . '"]; $vtprd_rule->prodcat_out_checked_info[$term_id]->value_selector = $_REQUEST["prodcat-list-out-value-selector-' . {$term_id} . '"]; } } } if (!empty($_REQUEST['tax-input-rulecat-out'])) { $vtprd_rule->rulecat_out_checked = $_REQUEST['tax-input-rulecat-out']; // $vtprd_rule->rulecat_out_checked_min_requirement = $_REQUEST["rulecat-list-out-min-requirement"]; foreach ($vtprd_rule->rulecat_out_checked as $term_id) { if (!empty($_REQUEST["rulecat-list-out-value-' . {$term_id} . '"])) { $vtprd_rule->rulecat_out_checked_info[$term_id]->value = $_REQUEST["rulecat-list-out-value-' . {$term_id} . '"]; $vtprd_rule->rulecat_out_checked_info[$term_id]->value_selector = $_REQUEST["rulecat-list-out-value-selector-' . {$term_id} . '"]; } } } if (!empty($_REQUEST['tax-input-role-out'])) { $vtprd_rule->role_out_checked = $_REQUEST['tax-input-role-out']; } if (!$vtprd_rule->prodcat_out_checked && !$vtprd_rule->rulecat_out_checked && !$vtprd_rule->role_out_checked) { $vtprd_rule->rule_error_message[] = array('insert_error_before_selector' => '#action_group_box_0', 'error_msg' => __('In Cart Search Criteria Selection Metabox, "Category / Logged-in Role / Custom Category" was chosen, but no Categories or Roles checked', 'vtprd')); $vtprd_rule->rule_error_red_fields[] = '#actionPopChoiceOut_label'; $vtprd_rule->rule_error_red_fields[] = '#prodcat-out-label'; $vtprd_rule->rule_error_red_fields[] = '#rulecat-out-label'; $vtprd_rule->rule_error_red_fields[] = '#role-out-label'; } // And/Or switch for category/role relationship $vtprd_rule->role_and_or_out = $_REQUEST['andorChoiceOut']; switch ($vtprd_rule->role_and_or_out) { case 'and': // $vtprd_rule->role_and_or_out[0]['user_input'] = $selected; if (!$vtprd_rule->prodcat_out_checked && !$vtprd_rule->rulecat_out_checked && !$vtprd_rule->role_out_checked) { $vtprd_rule->rule_error_message[] = array('insert_error_before_selector' => '#action_group_box_0', 'error_msg' => __('In "Action" Group Selection, "Category / Logged-in Role / Custom Category" and "And" was chosen, but no Categories or Roles are checked', 'vtprd')); $vtprd_rule->rule_error_red_fields[] = '#actionPopChoiceOut_label'; $vtprd_rule->rule_error_red_fields[] = '#prodcat-out-label'; $vtprd_rule->rule_error_red_fields[] = '#rulecat-out-label'; $vtprd_rule->rule_error_red_fields[] = '#role-out-label'; } else { if (!$vtprd_rule->prodcat_out_checked && !$vtprd_rule->rulecat_out_checked) { $vtprd_rule->rule_error_message[] = array('insert_error_before_selector' => '#action_group_box_0', 'error_msg' => __('In "Action" Group Selection, "Category / Logged-in Role / Custom Category" and "And" was chosen, but no Categories are checked. <br><br><br><br><em>If Roles alone are desired, please select "OR".</em>', 'vtprd')); $vtprd_rule->rule_error_red_fields[] = '#actionPopChoiceOut_label'; $vtprd_rule->rule_error_red_fields[] = '#prodcat-out-label'; $vtprd_rule->rule_error_red_fields[] = '#rulecat-out-label'; } else { if (!$vtprd_rule->role_out_checked) { $vtprd_rule->rule_error_message[] = array('insert_error_before_selector' => '#action_group_box_0', 'error_msg' => __('In "Action" Group Selection, "Category / Logged-in Role / Custom Category" and "And" was chosen, but no Roles are checked. <br><br><br><br><em>If Categories alone are desired, please select "OR".</em>', 'vtprd')); $vtprd_rule->rule_error_red_fields[] = '#actionPopChoiceOut_label'; $vtprd_rule->rule_error_red_fields[] = '#role-out-label'; } } } break; case 'or': // $vtprd_rule->role_and_or_out[1]['user_input'] = $selected; break; default: $vtprd_rule->role_and_or_out = 'or'; //v1.0.5.5 //initialize so it's always there. overwritten by logic as needed. break; } break; case 'vargroup': $vtprd_rule->actionPop_varProdID = $_REQUEST['outVarProdID']; //blank or spaces... if ($vtprd_rule->actionPop_varProdID == '' || $vtprd_rule->actionPop_varProdID == ' ') { $vtprd_rule->rule_error_message[] = array('insert_error_before_selector' => '#actionPop-varProdID-cntl', 'error_msg' => __('In "Action" Group Selection, "*Single Product with variations* was chosen, but Product ID was not supplied.', 'vtprd')); $vtprd_rule->rule_error_red_fields[] = '#actionPopChoiceOut_label'; $vtprd_rule->rule_error_red_fields[] = '#varProdID-out-label'; } $vtprd_rule->actionPop_varProdID = preg_replace('/[^0-9.]+/', '', $vtprd_rule->actionPop_varProdID); //remove leading/trailing spaces, percent sign, dollar sign if (is_numeric($vtprd_rule->actionPop_varProdID) === false) { $vtprd_rule->rule_error_message[] = array('insert_error_before_selector' => '#actionPop-varProdID-cntl', 'error_msg' => __('In "Action" Group Selection, "*Single Product with variations* was chosen, but Product ID was not numeric.', 'vtprd')); $vtprd_rule->rule_error_red_fields[] = '#actionPopChoiceOut_label'; $vtprd_rule->rule_error_red_fields[] = '#varProdID-out-label'; } else { $test_post = get_post($vtprd_rule->actionPop_varProdID); if (!$test_post) { $vtprd_rule->rule_error_message[] = array('insert_error_before_selector' => '#actionPop-varProdID-cntl', 'error_msg' => __('In "Action" Group Selection, "*Single Product with variations* was chosen, but Product ID was not found.', 'vtprd')); $vtprd_rule->rule_error_red_fields[] = '#actionPopChoiceOut_label'; $vtprd_rule->rule_error_red_fields[] = '#varProdID-out-label'; } else { $vtprd_rule->actionPop_varProdID_name = sanitize_title($test_post->post_title) . ' (Variations)'; $product_has_variations = vtprd_test_for_variations($vtprd_rule->actionPop_varProdID); if ($product_has_variations == 'yes') { if (!empty($_REQUEST['tax-input-var-out'])) { $vtprd_rule->var_out_checked = $_REQUEST['tax-input-var-out']; // $vtprd_rule->var_out_checked_min_requirement = $_REQUEST["var-list-out-min-requirement"]; foreach ($vtprd_rule->var_out_checked as $varID) { if (!empty($_REQUEST["var-list-out-value-' . {$varID} . '"])) { $vtprd_rule->var_out_checked_info[$varID]->value = $_REQUEST["var-list-out-value-' . {$varID} . '"]; $vtprd_rule->var_out_checked_info[$varID]->value_selector = $_REQUEST["var-list-out-value-selector-' . {$varID} . '"]; } } } if (sizeof($vtprd_rule->var_out_checked) <= 0) { //if (!$vtprd_rule->var_out_checked) { $vtprd_rule->rule_error_message[] = array('insert_error_before_selector' => '#actionPop-varProdID-cntl', 'error_msg' => __('In "Action" Group Selection, "Single Product with variations" was chosen, but no Variations checked', 'vtprd')); $vtprd_rule->rule_error_red_fields[] = '#actionPopChoiceOut_label'; $vtprd_rule->rule_error_red_fields[] = '#varProdID-out-label'; } } else { $vtprd_rule->rule_error_message[] = array('insert_error_before_selector' => '#actionPop-varProdID-cntl', 'error_msg' => __('In "Action" Group Selection, "Single Product with variations" was chosen, but no Product has no Variations. Please use "Single Product Only" option.', 'vtprd')); $vtprd_rule->rule_error_red_fields[] = '#actionPopChoiceOut_label'; $vtprd_rule->rule_error_red_fields[] = '#varProdID-out-label'; } } } // $this->vtprd_set_default_or_values_out(); break; case 'single': // $vtprd_rule->actionPop[3]['user_input'] = $selected; // edit for single product ID $vtprd_rule->actionPop_singleProdID = $_REQUEST['singleProdID_out']; if ($vtprd_rule->actionPop_singleProdID == ' ') { $vtprd_rule->rule_error_message[] = array('insert_error_before_selector' => '#action_group_box_0', 'error_msg' => __('In "Action" Group Selection, "*Single Product Only* was chosen, but Product ID was not supplied.', 'vtprd')); $vtprd_rule->rule_error_red_fields[] = '#actionPopChoiceOut_label'; $vtprd_rule->rule_error_red_fields[] = '#singleProdID-out-label'; } $vtprd_rule->actionPop_singleProdID = preg_replace('/[^0-9.]+/', '', $vtprd_rule->actionPop_singleProdID); //remove leading/trailing spaces, percent sign, dollar sign if (is_numeric($vtprd_rule->actionPop_singleProdID) === false) { $vtprd_rule->rule_error_message[] = array('insert_error_before_selector' => '#action_group_box_0', 'error_msg' => __('In "Action" Group Selection, "*Single Product Only* was chosen, but Product ID was not numeric.', 'vtprd')); $vtprd_rule->rule_error_red_fields[] = '#actionPopChoiceOut_label'; $vtprd_rule->rule_error_red_fields[] = '#singleProdID-out-label'; } else { $test_post = get_post($vtprd_rule->actionPop_singleProdID); if (!$test_post) { $vtprd_rule->rule_error_message[] = array('insert_error_before_selector' => '#action_group_box_0', 'error_msg' => __('In "Action" Group Selection, "*Single Product Only* was chosen, but Product ID was not found.', 'vtprd')); $vtprd_rule->rule_error_red_fields[] = '#actionPopChoiceOut_label'; $vtprd_rule->rule_error_red_fields[] = '#singleProdID-out-label'; } else { $vtprd_rule->actionPop_singleProdID_name = $test_post->post_title; $product_has_variations = vtprd_test_for_variations($vtprd_rule->actionPop_singleProdID); if ($product_has_variations == 'yes') { $vtprd_rule->rule_error_message[] = array('insert_error_before_selector' => '#action_group_box_0', 'error_msg' => __('In "Action" Group Selection, "Single Product Only" was chosen, but ** Product has Variations **. Please use "Single Product with variations" option.', 'vtprd')); $vtprd_rule->rule_error_red_fields[] = '#actionPopChoiceOut_label'; $vtprd_rule->rule_error_red_fields[] = '#singleProdID-out-label'; } } } // $this->vtprd_set_default_or_values_out(); break; } //******************************************************************************************************************** //Specialty Complex edits... //******************************************************************************************************************** //FOR THE PRICE OF requirements... if ($vtprd_rule->rule_deal_info[0]['discount_amt_type'] == 'forThePriceOf_Units') { switch ($vtprd_rule->rule_template) { case 'C-forThePriceOf-inCart': //buy-x-action-forThePriceOf-same-group-discount if ($vtprd_rule->rule_deal_info[0]['buy_amt_type'] != 'quantity') { $vtprd_rule->rule_error_message[] = array('insert_error_before_selector' => '#buy_amt_box_0', 'error_msg' => __('"Buy Unit Quantity" required for Discount Type "For the Price of (Units) Discount"', 'vtprd')); $vtprd_rule->rule_error_red_fields[] = '#buy_amt_type_label_0'; $vtprd_rule->rule_error_red_fields[] = '#discount_amt_type_label_0'; } elseif (is_numeric($vtprd_rule->rule_deal_info[0]['buy_amt_count']) && $vtprd_rule->rule_deal_info[0]['buy_amt_count'] < '2') { $vtprd_rule->rule_error_message[] = array('insert_error_before_selector' => '#buy_amt_box_0', 'error_msg' => __('"Buy Unit Quantity" must be > 1 for Discount Type "For the Price of (Units) Discount".', 'vtprd')); $vtprd_rule->rule_error_red_fields[] = '#discount_amt_type_label_0'; $vtprd_rule->rule_error_box_fields[] = '#buy_amt_count_0'; } elseif (is_numeric($vtprd_rule->rule_deal_info[0]['buy_amt_count']) && $vtprd_rule->rule_deal_info[0]['buy_amt_count'] <= $vtprd_rule->rule_deal_info[0]['discount_amt_count']) { $vtprd_rule->rule_error_message[] = array('insert_error_before_selector' => '#buy_amt_box_0', 'error_msg' => __('"Buy Unit Quantity" must be greater than Discount Type "Discount For the Price of Units", when "For the Price of (Units) Discount" chosen.', 'vtprd')); $vtprd_rule->rule_error_red_fields[] = '#discount_amt_count_literal_forThePriceOf_0'; $vtprd_rule->rule_error_box_fields[] = '#buy_amt_count_0'; } break; case 'C-forThePriceOf-Next': //buy-x-action-forThePriceOf-other-group-discount if ($vtprd_rule->rule_deal_info[0]['action_amt_type'] != 'quantity') { $vtprd_rule->rule_error_message[] = array('insert_error_before_selector' => '#action_amt_box_0', 'error_msg' => __('"Get Unit Quantity" required for Discount Type "For the Price of (Units) Discount"', 'vtprd')); $vtprd_rule->rule_error_red_fields[] = '#discount_amt_type_label_0'; $vtprd_rule->rule_error_box_fields[] = '#action_amt_count_0'; } elseif (is_numeric($vtprd_rule->rule_deal_info[0]['action_amt_count']) && $vtprd_rule->rule_deal_info[0]['action_amt_count'] < '2') { $vtprd_rule->rule_error_message[] = array('insert_error_before_selector' => '#action_amt_box_0', 'error_msg' => __('"Get Unit Quantity" must be > 1 for Discount Type "For the Price of (Units) Discount".', 'vtprd')); $vtprd_rule->rule_error_red_fields[] = '#discount_amt_type_label_0'; $vtprd_rule->rule_error_box_fields[] = '#action_amt_count_0'; } elseif (is_numeric($vtprd_rule->rule_deal_info[0]['action_amt_count']) && $vtprd_rule->rule_deal_info[0]['action_amt_count'] <= $vtprd_rule->rule_deal_info[0]['discount_amt_count']) { $vtprd_rule->rule_error_message[] = array('insert_error_before_selector' => '#action_amt_box_0', 'error_msg' => __('"Get Unit Quantity" must be greater than Discount Type "Discount For the Price of Units", when "For the Price of (Units) Discount" chosen.', 'vtprd')); $vtprd_rule->rule_error_red_fields[] = '#discount_amt_count_literal_forThePriceOf_0'; $vtprd_rule->rule_error_box_fields[] = '#action_amt_count_0'; } break; default: $vtprd_rule->rule_error_message[] = array('insert_error_before_selector' => '#discount_amt_box_0', 'error_msg' => __('To use Discount Type "For the Price of (Units) Discount", choose a "For the Price Of" template type.', 'vtprd')); $vtprd_rule->rule_error_red_fields[] = '#discount_amt_type_label_0'; $vtprd_rule->rule_error_red_fields[] = '#deal-type-title'; break; } //end switch } //end if forThePriceOf_Units if ($vtprd_rule->rule_deal_info[0]['discount_amt_type'] == 'forThePriceOf_Currency') { switch ($vtprd_rule->rule_template) { case 'C-forThePriceOf-inCart': //buy-x-action-forThePriceOf-same-group-discount if ($vtprd_rule->rule_deal_info[0]['buy_amt_type'] != 'quantity') { $vtprd_rule->rule_error_message[] = array('insert_error_before_selector' => '#buy_amt_box_0', 'error_msg' => __('"Buy Unit Quantity" required for Discount Type "For the Price of (Currency) Discount"', 'vtprd')); $vtprd_rule->rule_error_red_fields[] = '#buy_amt_type_label_0'; $vtprd_rule->rule_error_red_fields[] = '#discount_amt_type_label_0'; } elseif ($vtprd_rule->rule_deal_info[0]['buy_amt_count'] < '2') { $vtprd_rule->rule_error_message[] = array('insert_error_before_selector' => '#buy_amt_box_0', 'error_msg' => __('"Buy Unit Quantity" must be > 1 for Discount Type "For the Price of (Currency) Discount".', 'vtprd')); $vtprd_rule->rule_error_red_fields[] = '#discount_amt_type_label_0'; $vtprd_rule->rule_error_box_fields[] = '#buy_amt_count_0'; } break; case 'C-forThePriceOf-Next': //buy-x-action-forThePriceOf-other-group-discount if ($vtprd_rule->rule_deal_info[0]['action_amt_type'] != 'quantity') { $vtprd_rule->rule_error_message[] = array('insert_error_before_selector' => '#action_amt_box_0', 'error_msg' => __('"Get Unit Quantity" required for Discount Type "For the Price of (Currency) Discount"', 'vtprd')); $vtprd_rule->rule_error_red_fields[] = '#action_amt_type_label_0'; $vtprd_rule->rule_error_red_fields[] = '#discount_amt_type_label_0'; } elseif ($vtprd_rule->rule_deal_info[0]['action_amt_count'] < '2') { $vtprd_rule->rule_error_message[] = array('insert_error_before_selector' => '#action_amt_box_0', 'error_msg' => __('"Get Unit Quantity" must be > 1 for Discount Type "For the Price of (Currency) Discount".', 'vtprd')); $vtprd_rule->rule_error_red_fields[] = '#discount_amt_type_label_0'; $vtprd_rule->rule_error_box_fields[] = '#action_amt_count_0'; } break; default: $vtprd_rule->rule_error_message[] = array('insert_error_before_selector' => '#discount_amt_box_0', 'error_msg' => __('To use Discount Type "For the Price of (Currency) Discount", choose a "For the Price Of" template type.', 'vtprd')); $vtprd_rule->rule_error_red_fields[] = '#discount_amt_type_label_0'; $vtprd_rule->rule_error_red_fields[] = '#deal-type-title'; break; } //end switch } //end if forThePriceOf_Currency //DISCOUNT APPLIES TO requirements... if ($vtprd_rule->rule_deal_info[0]['discount_applies_to'] == 'cheapest' || $vtprd_rule->rule_deal_info[0]['discount_applies_to'] == 'most_expensive') { switch ($vtprd_rule->rule_template) { case 'C-cheapest-inCart': //buy-x-action-most-expensive-same-group-discount if ($vtprd_rule->rule_deal_info[0]['buy_amt_type'] != 'quantity' && $vtprd_rule->rule_deal_info[0]['buy_amt_type'] != 'currency') { $vtprd_rule->rule_error_message[] = array('insert_error_before_selector' => '#buy_amt_box_0', 'error_msg' => __('Buy Amount type must be Quantity or Currency, when Discount "Applies To Cheapest/Most Expensive" chosen.', 'vtprd')); $vtprd_rule->rule_error_red_fields[] = '#buy_amt_type_label_0'; $vtprd_rule->rule_error_red_fields[] = '#discount_applies_to_label_0'; } elseif (is_numeric($vtprd_rule->rule_deal_info[0]['buy_amt_count']) && $vtprd_rule->rule_deal_info[0]['buy_amt_count'] < '2') { $vtprd_rule->rule_error_message[] = array('insert_error_before_selector' => '#buy_amt_box_0', 'error_msg' => __('Buy Amount Count must be greater than 1, when Discount "Applies To Cheapest/Most Expensive" chosen.', 'vtprd')); $vtprd_rule->rule_error_red_fields[] = '#buy_amt_type_label_0'; $vtprd_rule->rule_error_red_fields[] = '#discount_applies_to_label_0'; } break; case 'C-cheapest-Next': //buy-x-action-most-expensive-other-group-discount if ($vtprd_rule->rule_deal_info[0]['action_amt_type'] != 'quantity' && $vtprd_rule->rule_deal_info[0]['action_amt_type'] != 'currency') { $vtprd_rule->rule_error_message[] = array('insert_error_before_selector' => '#action_amt_box_0', 'error_msg' => __('Get Amount type must be Quantity or Currency, when Discount "Applies To Cheapest/Most Expensive" chosen.', 'vtprd')); $vtprd_rule->rule_error_red_fields[] = '#action_amt_type_label_0'; $vtprd_rule->rule_error_red_fields[] = '#discount_applies_to_label_0'; } elseif (is_numeric($vtprd_rule->rule_deal_info[0]['action_amt_count']) && $vtprd_rule->rule_deal_info[0]['action_amt_count'] < '2') { $vtprd_rule->rule_error_message[] = array('insert_error_before_selector' => '#action_amt_box_0', 'error_msg' => __('Get Amount Count must be greater than 1, when Discount "Applies To Cheapest/Most Expensive" chosen.', 'vtprd')); $vtprd_rule->rule_error_red_fields[] = '#action_amt_type_label_0'; $vtprd_rule->rule_error_red_fields[] = '#discount_applies_to_label_0'; } break; default: $vtprd_rule->rule_error_message[] = array('insert_error_before_selector' => '#discount_applies_to_box_0', 'error_msg' => __('Please choose a "Cheapest/Most Expensive" template type, when Discount "Applies To Cheapest/Most Expensive" chosen.', 'vtprd')); $vtprd_rule->rule_error_red_fields[] = '#discount_applies_to_label_0'; $vtprd_rule->rule_error_red_fields[] = '#deal-type-title'; break; } //end switch } //end if discountAppliesTo //v1.1.0.8 begin //only_for_this_coupon_name $vtprd_rule->only_for_this_coupon_name = $_REQUEST['only_for_this_coupon_name']; if ($vtprd_rule->only_for_this_coupon_name == $vtprd_info['default_coupon_msg']) { $vtprd_rule->only_for_this_coupon_name = ' '; } if ($vtprd_rule->only_for_this_coupon_name > ' ') { vtprd_woo_ensure_coupons_are_allowed(); if ($vtprd_rule->cart_or_catalog_select == 'catalog') { $vtprd_rule->rule_error_message[] = array('insert_error_before_selector' => '#only_for_this_coupon_box_0', 'error_msg' => __('Discount Coupon Code option not valid for Catalog rule type - please remove coupon code.', 'vtprd')); $vtprd_rule->rule_error_red_fields[] = '#only_for_this_coupon_anchor'; } else { $coupon = $vtprd_rule->only_for_this_coupon_name; //from woocommerce/includes/admin/mtea-boxes/views/html-order-items.php $post_id = $wpdb->get_var($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_title = %s AND post_type = 'shop_coupon' AND post_status = 'publish' LIMIT 1;", $coupon)); if (!$post_id) { $vtprd_rule->rule_error_message[] = array('insert_error_before_selector' => '#only_for_this_coupon_box_0', 'error_msg' => __('Discount Coupon Code not found - must be a valid coupon code or blank.', 'vtprd')); $vtprd_rule->rule_error_red_fields[] = '#only_for_this_coupon_anchor'; } } //v1.1.0.9 begin - disallow activation by coupon, when auto-add free in use ==>> because of the recursive aspect of re-checking the cart to pick up the coupon add/remove if ($vtprd_rule->rule_deal_info[0]['discount_auto_add_free_product'] == 'yes') { $vtprd_rule->rule_error_message[] = array('insert_error_before_selector' => '#only_for_this_coupon_box_0', 'error_msg' => __('Discount Coupon Code not allowed when Auto Add for Free function selected', 'vtprd')); $vtprd_rule->rule_error_red_fields[] = '#only_for_this_coupon_anchor'; $vtprd_rule->rule_error_red_fields[] = '#discount_auto_add_free_product_label_0'; } //v1.1.0.9 end } //v1.1.0.8 end //******************************************************************************************************************** //The WPSC Realtime Catalog repricing action does not pass variation-level info, so these options are disallowed //******************************************************************************************************************** if ($vtprd_rule->rule_execution_type == 'display' && VTPRD_PARENT_PLUGIN_NAME == 'WP E-Commerce') { if ($vtprd_rule->actionPop == 'vargroup') { $vtprd_rule->rule_error_message[] = array('insert_error_before_selector' => '#actionPop-varProdID-cntl', 'error_msg' => __('"Action" Group Selection - Single with Variations may not be chosen when "Apply Price Reduction to Products in the Catalog" Pricing Deal Type is chosen, due to a WPEC limitation.', 'vtprd')); $vtprd_rule->rule_error_red_fields[] = '#actionPopChoiceOut_label'; } if ($vtprd_rule->cumulativeSalePricingAllowed == 'no') { $vtprd_rule->rule_error_message[] = array('insert_error_before_selector' => '#cumulativeSalePricing_areaID', 'error_msg' => __('"Apply this Rule Discount in addition to Product Sale Pricing" must not be "No" when "Apply Price Reduction to Products in the Catalog" Pricing Deal Type is chosen, due to a WPEC limitation.', 'vtprd')); $vtprd_rule->rule_error_red_fields[] = '#cumulativeSalePricing_label'; } } //******************************************************************************************************************** //******************************************************************************************************************** //************************* //AUTO ADD switching (+ sort field switching as well) //************************* $vtprd_rule->rule_contains_auto_add_free_product = 'no'; $vtprd_rule->rule_contains_free_product = 'no'; //used for sort in apply-rules.php $vtprd_rule->var_out_product_variations_parameter = array(); $sizeof_rule_deal_info = sizeof($vtprd_rule->rule_deal_info); for ($d = 0; $d < $sizeof_rule_deal_info; $d++) { if ($vtprd_rule->rule_deal_info[$d]['discount_auto_add_free_product'] == 'yes') { $vtprd_rule->rule_contains_auto_add_free_product = 'yes'; $vtprd_rule->rule_contains_free_product = 'yes'; if ($vtprd_rule->actionPop == 'sameAsInPop') { if ($vtprd_rule->inPop == 'vargroup' && sizeof($vtprd_rule->var_in_checked) == 1) { $vtprd_rule->auto_add_free_trigger_rule_type = 'same_product'; $vtprd_rule->var_out_product_variations_parameter = $this->vtprd_get_variations_parameter('inPop'); break; } if ($vtprd_rule->inPop == 'single') { $vtprd_rule->auto_add_free_trigger_rule_type = 'same_product'; break; } //if we get this far, it's an ERROR $vtprd_rule->rule_error_message[] = array('insert_error_before_selector' => '#buy_group_box_0', 'error_msg' => __('"Buy Group Filter" must be either a single product, or a single product variation, When "Discount Group Same as Buy Group" and "Automatically Add Free Product to Cart" is Selected.', 'vtprd')); $vtprd_rule->rule_error_red_fields[] = '#buy_group_title'; $vtprd_rule->rule_error_red_fields[] = '#discount_auto_add_free_product_label_' . $d; } if ($vtprd_rule->actionPop == 'vargroup' && sizeof($vtprd_rule->var_out_checked) == 1) { $vtprd_rule->var_out_product_variations_parameter = $this->vtprd_get_variations_parameter('actionPop'); } //find $auto_add_free_trigger_rule_type if ($vtprd_rule->inPop == 'vargroup' && $vtprd_rule->actionPop == 'vargroup') { if ($vtprd_rule->inPop_varProdID == $vtprd_rule->actionPop_varProdID && $vtprd_rule->var_in_checked == $vtprd_rule->var_out_checked) { $vtprd_rule->auto_add_free_trigger_rule_type = 'same_product'; } else { $vtprd_rule->auto_add_free_trigger_rule_type = 'external'; } break; } if ($vtprd_rule->inPop == 'single' && $vtprd_rule->actionPop == 'single') { if ($vtprd_rule->inPop_singleProdID == $vtprd_rule->actionPop_singleProdID) { $vtprd_rule->auto_add_free_trigger_rule_type = 'same_product'; } else { $vtprd_rule->auto_add_free_trigger_rule_type = 'external'; } break; } } if ($vtprd_rule->rule_deal_info[$d]['discount_amt_type'] == 'free') { $vtprd_rule->rule_contains_free_product = 'yes'; } } //************************* //Pop Filter Agreement Check (switch used in apply...) //************************* $this->vtprd_maybe_pop_filter_agreement(); //************************* //check against all other rules acting on the free product //************************* if ($vtprd_rule->rule_contains_auto_add_free_product == 'yes') { $vtprd_rules_set = get_option('vtprd_rules_set'); $sizeof_rules_set = sizeof($vtprd_rules_set); for ($i = 0; $i < $sizeof_rules_set; $i++) { if ($vtprd_rules_set[$i]->rule_status != 'publish' || $vtprd_rules_set[$i]->rule_on_off_sw_select == 'off') { continue; } if ($vtprd_rules_set[$i]->post_id == $vtprd_rule->post_id) { continue; } //if another rule has the exact same FREE product, that's an ERROR if ($vtprd_rules_set[$i]->rule_contains_auto_add_free_product == 'yes') { //v1.1.1.2 begin ADDED ==>> can't do auto adds when activated by coupon //v1.1.0.9 begin - // If CURRENT rule activated by coupon, ***no AUTO ADD rules may exist*** ==>> the switches which handle add/remove for coupons go nuts. if ($vtprd_rule->only_for_this_coupon_name > ' ') { $conflictPost = get_post($vtprd_rules_set[$i]->post_id); $vtprd_rule->rule_error_message[] = array('insert_error_before_selector' => '#only_for_this_coupon_box_0', 'error_msg' => __('Discount Coupon Code not allowed when *any rule* has Auto Add for Free function selected. CONFLICTING RULE NAME is: ', 'vtprd') . $conflictPost->post_title); $vtprd_rule->rule_error_red_fields[] = '#only_for_this_coupon_anchor'; } //v1.1.0.9 end //v1.1.1.2 end //v1.1.1.2 REMOVED - multiples now allowed /* //v1.1.1 begin - disallow multiple auto adds in ruleset $conflictPost = get_post($vtprd_rules_set[$i]->post_id); $vtprd_rule->rule_error_message[] = array( 'insert_error_before_selector' => '#discount_amt_box_0', 'error_msg' => __('When "Automatically Add Free Product to Cart" is Selected, no other Auto Add Rule may exist. CONFLICTING RULE NAME is: ', 'vtprd') .$conflictPost->post_title ); $vtprd_rule->rule_error_red_fields[] = '#discount_auto_add_free_product_label_0'; break; //v1.1.1 end */ //v1.1.1.2 end switch (true) { // compare to vtprd_rule actionpop vargroup case $vtprd_rule->actionPop == 'vargroup': //current rule vs other rule actionPop vs actionPop if ($vtprd_rules_set[$i]->actionPop == 'vargroup' && $vtprd_rules_set[$i]->actionPop_varProdID == $vtprd_rule->actionPop_varProdID && $vtprd_rules_set[$i]->var_out_checked[0] == $vtprd_rule->var_out_checked[0]) { $conflictPost = get_post($vtprd_rules_set[$i]->post_id); $vtprd_rule->rule_error_message[] = array('insert_error_before_selector' => '#discount_amt_box_0', 'error_msg' => __('When "Automatically Add Free Product to Cart" is Selected, no other Auto Add Rule may have the same product as the Discount Group. CONFLICTING RULE NAME is: ', 'vtprd') . $conflictPost->post_title); $vtprd_rule->rule_error_red_fields[] = '#discount_auto_add_free_product_label_0'; break 2; } //current rule actionPop vs other rule inPop if ($vtprd_rules_set[$i]->actionPop == 'sameAsInPop') { if ($vtprd_rules_set[$i]->inPop == 'vargroup' && $vtprd_rules_set[$i]->inPop_varProdID == $vtprd_rule->actionPop_varProdID && $vtprd_rules_set[$i]->var_in_checked[0] == $vtprd_rule->var_out_checked[0]) { $conflictPost = get_post($vtprd_rules_set[$i]->post_id); $vtprd_rule->rule_error_message[] = array('insert_error_before_selector' => '#discount_amt_box_0', 'error_msg' => __('When "Automatically Add Free Product to Cart" is Selected, no other Auto Add Rule may have the same product as the Discount Group. CONFLICTING RULE NAME is: ', 'vtprd') . $conflictPost->post_title); $vtprd_rule->rule_error_red_fields[] = '#discount_auto_add_free_product_label_0'; break 2; } } break; // compare to vtprd_rule actionpop single // compare to vtprd_rule actionpop single case $vtprd_rule->actionPop == 'single': if ($vtprd_rules_set[$i]->actionPop == 'single' && $vtprd_rules_set[$i]->actionPop_singleProdID == $vtprd_rule->actionPop_singleProdID) { $conflictPost = get_post($vtprd_rules_set[$i]->post_id); $vtprd_rule->rule_error_message[] = array('insert_error_before_selector' => '#discount_amt_box_0', 'error_msg' => __('When "Automatically Add Free Product to Cart" is Selected, no other Auto Add Rule may have the same product as the Discount Group. CONFLICTING RULE NAME is: ', 'vtprd') . $conflictPost->post_title); $vtprd_rule->rule_error_red_fields[] = '#discount_auto_add_free_product_label_0'; break 2; } //current rule actionPop vs other rule inPop if ($vtprd_rules_set[$i]->actionPop == 'sameAsInPop') { if ($vtprd_rules_set[$i]->inPop == 'single' && $vtprd_rules_set[$i]->inPop_singleProdID == $vtprd_rule->actionPop_singleProdID) { $conflictPost = get_post($vtprd_rules_set[$i]->post_id); $vtprd_rule->rule_error_message[] = array('insert_error_before_selector' => '#discount_amt_box_0', 'error_msg' => __('When "Automatically Add Free Product to Cart" is Selected, no other Auto Add Rule may have the same product as the Discount Group. CONFLICTING RULE NAME is: ', 'vtprd') . $conflictPost->post_title); $vtprd_rule->rule_error_red_fields[] = '#discount_auto_add_free_product_label_0'; break 2; } } break; // compare to vtprd_rule inpop vargroup // compare to vtprd_rule inpop vargroup case $vtprd_rule->actionPop == 'sameAsInPop' && $vtprd_rule->inPop == 'vargroup': //current rule vs other rule actionPop vs actionPop if ($vtprd_rules_set[$i]->actionPop == 'vargroup' && $vtprd_rules_set[$i]->actionPop_varProdID == $vtprd_rule->inPop_varProdID && $vtprd_rules_set[$i]->var_out_checked[0] == $vtprd_rule->var_in_checked[0]) { $conflictPost = get_post($vtprd_rules_set[$i]->post_id); $vtprd_rule->rule_error_message[] = array('insert_error_before_selector' => '#discount_amt_box_0', 'error_msg' => __('When "Automatically Add Free Product to Cart" is Selected, no other Auto Add Rule may have the same product as the Discount Group. CONFLICTING RULE NAME is: ', 'vtprd') . $conflictPost->post_title); $vtprd_rule->rule_error_red_fields[] = '#discount_auto_add_free_product_label_0'; break 2; } //current rule actionPop vs other rule inPop if ($vtprd_rules_set[$i]->actionPop == 'sameAsInPop') { if ($vtprd_rules_set[$i]->inPop == 'vargroup' && $vtprd_rules_set[$i]->inPop_varProdID == $vtprd_rule->inPop_varProdID && $vtprd_rules_set[$i]->var_in_checked[0] == $vtprd_rule->var_in_checked[0]) { $conflictPost = get_post($vtprd_rules_set[$i]->post_id); $vtprd_rule->rule_error_message[] = array('insert_error_before_selector' => '#discount_amt_box_0', 'error_msg' => __('When "Automatically Add Free Product to Cart" is Selected, no other Auto Add Rule may have the same product as the Discount Group. CONFLICTING RULE NAME is: ', 'vtprd') . $conflictPost->post_title); $vtprd_rule->rule_error_red_fields[] = '#discount_auto_add_free_product_label_0'; break 2; } } break; // compare to vtprd_rule inpop single // compare to vtprd_rule inpop single case $vtprd_rule->actionPop == 'sameAsInPop' && $vtprd_rule->inPop == 'single': if ($vtprd_rules_set[$i]->actionPop == 'single' && $vtprd_rules_set[$i]->actionPop_singleProdID == $vtprd_rule->inPop_singleProdID) { $conflictPost = get_post($vtprd_rules_set[$i]->post_id); $vtprd_rule->rule_error_message[] = array('insert_error_before_selector' => '#discount_amt_box_0', 'error_msg' => __('When "Automatically Add Free Product to Cart" is Selected, no other Auto Add Rule may have the same product as the Discount Group. CONFLICTING RULE NAME is: ', 'vtprd') . $conflictPost->post_title); $vtprd_rule->rule_error_red_fields[] = '#discount_auto_add_free_product_label_0'; break 2; } //current rule actionPop vs other rule inPop if ($vtprd_rules_set[$i]->actionPop == 'sameAsInPop') { if ($vtprd_rules_set[$i]->inPop == 'single' && $vtprd_rules_set[$i]->inPop_singleProdID == $vtprd_rule->inPop_singleProdID) { $conflictPost = get_post($vtprd_rules_set[$i]->post_id); $vtprd_rule->rule_error_message[] = array('insert_error_before_selector' => '#discount_amt_box_0', 'error_msg' => __('When "Automatically Add Free Product to Cart" is Selected, no other Auto Add Rule may have the same product as the Discount Group. CONFLICTING RULE NAME is: ', 'vtprd') . $conflictPost->post_title); $vtprd_rule->rule_error_red_fields[] = '#discount_auto_add_free_product_label_0'; break 2; } } break; } //end switch } //end if } //end 'for' loop } //end if auto product //************************* //v1.0.7.9a begin //additional lifetime custom edit global $vtprd_setup_options; if (($vtprd_rule->rule_deal_info[0]['discount_lifetime_max_amt_type'] == 'quantity' || $vtprd_rule->rule_deal_info[0]['discount_lifetime_max_amt_type'] == 'currency') && $vtprd_setup_options['use_lifetime_max_limits'] != 'yes') { $vtprd_rule->rule_error_message[] = array('insert_error_before_selector' => '#discount_lifetime_max_dropdown', 'error_msg' => __('In order to use a Customer Rule Limit, please <b>FIRST</b> go to the <b>Pricing Deals Settings Page</b> and turn on the "Use Customer Rule Limits" switch', 'vtprd')); $vtprd_rule->rule_error_red_fields[] = '#discount_lifetime_max_title_anchor'; } //v1.0.7.9a end }