VTMIN_Rule_update

The VarkTech Minimum Purchase for WooCommerce VTMIN Rule update class.

Defined (1)

The class is defined in the following location(s).

/admin/vtmin-rules-update.php  
  1. class VTMIN_Rule_update { 
  2.  
  3.  
  4. public function __construct() {  
  5. $this->vtmin_update_rule(); 
  6.  
  7. public function vtmin_update_rule () { 
  8. global $post, $vtmin_rule;  
  9. $post_id = $post->ID;  
  10. $vtmin_rule_new = new VTMIN_Rule(); // always start with fresh copy 
  11. $selected = 's'; 
  12.  
  13. $vtmin_rule = $vtmin_rule_new; //otherwise vtmin_rule is not addressable! 
  14.  
  15. //***************************************** 
  16. // FILL / upd VTMIN_RULE... 
  17. //***************************************** 
  18. // Candidate Population 
  19.  
  20. $vtmin_rule->post_id = $post_id; 
  21.  
  22. if ( ($_REQUEST['post_title'] > ' ' ) ) { 
  23. //do nothing 
  24. else {  
  25. $vtmin_rule->rule_error_message[] = __('The Rule needs to have a title, but title is empty.', 'vtmin'); 
  26.  
  27. $vtmin_rule->inpop_selection = $_REQUEST['popChoice']; 
  28. switch( $vtmin_rule->inpop_selection ) { 
  29. case 'groups': 
  30. $vtmin_rule->inpop[1]['user_input'] = $selected; 
  31. // $vtmin_checkbox_classes = new VTMIN_Checkbox_classes; 
  32. //get all checked taxonomies/roles as arrays 
  33.  
  34. if(!empty($_REQUEST['tax-input-role-in'])) { 
  35. $vtmin_rule->role_in_checked = $_REQUEST['tax-input-role-in']; 
  36. if ((!$vtmin_rule->prodcat_in_checked) && (!$vtmin_rule->rulecat_in_checked) && (!$vtmin_rule->role_in_checked)) { 
  37. $vtmin_rule->rule_error_message[] = __('In Cart Search Criteria Selection Metabox, "Use Selection Groups" was chosen, but no Categories or Roles checked', 'vtmin'); 
  38. }  
  39. // And/Or switch for category/role relationship  
  40. $vtmin_rule->role_and_or_in_selection = $_REQUEST['andorChoice'];  
  41. $this->vtmin_set_default_or_values();  
  42. break; 
  43.  
  44.  
  45.  
  46.  
  47.  
  48. // Population Handling Specifics  
  49. $vtmin_rule->specChoice_in_selection = $_REQUEST['specChoice']; 
  50.  
  51. switch( $vtmin_rule->specChoice_in_selection ) { 
  52. case 'all': 
  53. $vtmin_rule->specChoice_in[0]['user_input'] = $selected; 
  54. break; 
  55. case 'each': 
  56. $vtmin_rule->specChoice_in[1]['user_input'] = $selected; 
  57. break; 
  58. case 'any': 
  59. $vtmin_rule->specChoice_in[2]['user_input'] = $selected; 
  60. if (empty($_REQUEST['anyChoice-max'])) { 
  61. $vtmin_rule->rule_error_message[] = __('In Select Rule Application cs Metabox, "*Any* in the Population" was chosen, but Maximum products count not filled in', 'vtmin'); 
  62. } else {  
  63. $vtmin_rule->anyChoice_max['value'] = $_REQUEST['anyChoice-max']; 
  64. if ($vtmin_rule->anyChoice_max['value'] == ' ') { 
  65. $vtmin_rule->rule_error_message[] = __('In Select Rule Application Metabox, "*Any* in the Population" was chosen, but Maximum products count not filled in', 'vtmin'); 
  66. }  
  67. if ( is_numeric($vtmin_rule->anyChoice_max['value']) === false ) { 
  68. $vtmin_rule->rule_error_message[] = __('In Select Rule Application Metabox, "*Any* in the Population" was chosen, but Maximum products count not numeric', 'vtmin');  
  69. }  
  70. break; 
  71.  
  72.  
  73. // Minimum Amount for this role 
  74. $vtmin_rule->amtSelected_selection = $_REQUEST['amtSelected'];  
  75.  
  76. switch( $vtmin_rule->amtSelected_selection ) { 
  77. case 'quantity': 
  78. $vtmin_rule->amtSelected[0]['user_input'] = $selected; 
  79. break; 
  80. case 'currency': 
  81. $vtmin_rule->amtSelected[1]['user_input'] = $selected; 
  82. break; 
  83. }  
  84. if (empty($_REQUEST['amtChoice-count'])) { 
  85. $vtmin_rule->rule_error_message[] = __('In Minimum Amount for this role Metabox, Minimum Amount not filled in', 'vtmin'); 
  86. } else {  
  87. $vtmin_rule->minimum_amt['value'] = $_REQUEST['amtChoice-count']; 
  88. if ($vtmin_rule->minimum_amt['value'] == ' ') { 
  89. $vtmin_rule->rule_error_message[] = __('In Minimum Amount for this role Metabox, Minimum Amount not filled in', 'vtmin'); 
  90. }  
  91. if ( is_numeric($vtmin_rule->minimum_amt['value']) === false ) { 
  92. $vtmin_rule->rule_error_message[] = __('In Minimum Amount for this role Metabox, Minimum Amount not numeric', 'vtmin');  
  93.  
  94. //v1.09.6 begin 
  95. $vtmin_rule->repeatingGroups = $_REQUEST['repeating-groups']; 
  96. if ( ( $vtmin_rule->repeatingGroups == '') || 
  97. ( $vtmin_rule->repeatingGroups == ' ') ) { 
  98. $vtmin_rule->repeatingGroups = ''; //re-initialize if default msg still there... 
  99. } else { 
  100. if ( is_numeric($vtmin_rule->repeatingGroups) === false ) { 
  101. $vtmin_rule->rule_error_message[] = __('If Repeating Groups is chosen, this must be a number greater than 0.', 'vtmin');  
  102. }  
  103. //v1.09.6 end 
  104.  
  105. //v1.08 begin 
  106. $vtmin_rule->custMsg_text = $_REQUEST['cust-msg-text']; 
  107. global $vtmin_info;  
  108. if ( $vtmin_rule->custMsg_text == $vtmin_info['default_full_msg']) { 
  109. $vtmin_rule->custMsg_text = ''; //re-initialize if default msg still there... 
  110. }  
  111. //v1.08 end 
  112.  
  113. //***************************************** 
  114. // If errors were found, the error message array will be displayed by the UI on next screen send. 
  115. //***************************************** 
  116. if ( sizeof($vtmin_rule->rule_error_message) > 0 ) { 
  117. $vtmin_rule->rule_status = 'pending'; 
  118. } else { 
  119. $vtmin_rule->rule_status = 'publish'; 
  120.  
  121. $rules_set_found = false; 
  122. $vtmin_rules_set = get_option( 'vtmin_rules_set' );  
  123. if ($vtmin_rules_set) { 
  124. $rules_set_found = true; 
  125.  
  126. if ($rules_set_found) { 
  127. $rule_found = false; 
  128. $sizeof_rules_set = sizeof($vtmin_rules_set); 
  129. for($i=0; $i < $sizeof_rules_set; $i++) {  
  130. if ($vtmin_rules_set[$i]->post_id == $post_id) { 
  131. $vtmin_rules_set[$i] = $vtmin_rule; 
  132. $i = $sizeof_rules_set; 
  133. $rule_found = true;  
  134. if (!$rule_found) { 
  135. $vtmin_rules_set[] = $vtmin_rule; 
  136. }  
  137. } else { 
  138. $vtmin_rules_set = array (); 
  139. $vtmin_rules_set[] = $vtmin_rule; 
  140.  
  141. if ($rules_set_found) { 
  142. update_option( 'vtmin_rules_set', $vtmin_rules_set ); 
  143. } else { 
  144. add_option( 'vtmin_rules_set', $vtmin_rules_set ); 
  145.  
  146. } //end function 
  147.  
  148. //default to 'OR', as the default value goes away and may be needed if the user switches back to 'groups'... 
  149. public function vtmin_set_default_or_values () { 
  150. global $vtmin_rule;  
  151. $vtmin_rule->role_and_or_in[1]['user_input'] = 's'; //'s' = 'selected' 
  152. $vtmin_rule->role_and_or_in_selection = 'or';  
  153. }  
  154.  
  155.  
  156. } //end class