From: Steve Sutton Date: Fri, 27 Jul 2018 19:13:18 +0000 (-0400) Subject: Setting up billing filters for contact billing edits. X-Git-Tag: v1.0.10^2~34 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=4dbb67b678b661a282f8f05283ecf1611e7b8bef;p=WP-Plugins%2Fglm-member-db-billing.git Setting up billing filters for contact billing edits. Billing data is saved with contact edit billing form. --- diff --git a/classes/billingSupport.php b/classes/billingSupport.php index beb2483..1b3ca56 100644 --- a/classes/billingSupport.php +++ b/classes/billingSupport.php @@ -1541,5 +1541,86 @@ class GlmBillingSupport ); } + public function saveContactBillingData( $ref_dest ) + { + $required_fields = $errors = array(); + $billingAccount = new GlmDataAccounts( $this->wpdb, $this->config ); + $billingFields = $billingAccount->fields; + if ( $billingFields ) { + foreach( $billingFields as $field_name => $field ) { + if ( $field['required'] ) { + $required_fields[] = $field_name; + } + } + } + // echo '
$billingFields: ' . print_r( $billingFields, true ) . '
'; + // echo '
$required_fields: ' . print_r( $required_fields, true ) . '
'; + // echo '
$ref_dest: ' . print_r( $ref_dest, true ) . '
'; + // echo '
$_REQUEST: ' . print_r( $_REQUEST, true ) . '
'; + // Check the given $ref_dest + $member_id = filter_var( $ref_dest, FILTER_VALIDATE_INT ); + if ( $member_id ) { + // Get the members account + $account = $this->getAccountByRefDest( $member_id ); + // echo '
$account: ' . print_r( $account, true ) . '
'; + + // New Billing Data If using Billing Fields + $billing_updated = array( + 'email' => filter_var( $_REQUEST['billing_email'] ), + 'billing_company' => filter_var( $_REQUEST['billing_company'] ), + 'billing_position' => filter_var( $_REQUEST['billing_position'] ), + 'billing_fname' => filter_var( $_REQUEST['billing_fname'] ), + 'billing_lname' => filter_var( $_REQUEST['billing_lname'] ), + 'billing_addr1' => filter_var( $_REQUEST['billing_addr1'] ), + 'billing_addr2' => filter_var( $_REQUEST['billing_addr2'] ), + 'billing_city' => filter_var( $_REQUEST['billing_city'] ), + 'billing_state' => filter_var( $_REQUEST['billing_state'] ), + 'billing_country' => filter_var( $_REQUEST['billing_country'] ), + 'billing_zip' => filter_var( $_REQUEST['billing_zip'] ), + 'billing_phone' => filter_var( $_REQUEST['billing_phone'] ), + 'billing_fax' => filter_var( $_REQUEST['billing_fax'] ), + ); + $billing_updated_format = array( + '%s', // email + '%s', // company + '%s', // position + '%s', // fname + '%s', // lname + '%s', // addr1 + '%s', // addr2 + '%s', // city + '%s', // state + '%s', // country + '%s', // zip + '%s', // phone + '%s', // fax + ); + // echo '
$billing_updated: ' . print_r( $billing_updated, true ) . '
'; + // Check for required fields + foreach ( $billing_updated as $field_name => $field_value ) { + $key = array_search( $field_name, $required_fields ); + if ( $key !== false && !trim( $field_value ) ) { + $errors[$field_name] = true; + } + } + // If the $errors array is empty then we can store the billing data + if ( empty( $errors ) ) { + if ( $account ) { + $this->wpdb->update( + GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . 'accounts', + $billing_updated, + array( 'id' => $account['id'] ), + $billing_updated_format, + array( '%d' ) + ); + } + } else { + return $errors; + } + } + // echo '
$errors: ' . print_r( $errors, true ) . '
'; + return true; + } + } diff --git a/models/admin/billing/contact.php b/models/admin/billing/contact.php new file mode 100644 index 0000000..9eaf5cf --- /dev/null +++ b/models/admin/billing/contact.php @@ -0,0 +1,144 @@ + + * @license http://www.gaslightmedia.com Gaslightmedia + * @release index.php,v 1.0 2014/10/31 19:31:47 cscott Exp $ + * @link http://dev.gaslightmedia.com/ + */ + +// Load Contacts data class +require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH . '/data/dataAccounts.php'; +require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH . '/billingSupport.php'; + +class GlmMembersAdmin_billing_contact extends GlmDataAccounts +{ + + /** + * WordPress Database Object + * + * @var $wpdb + * @access public + */ + public $wpdb; + /** + * Plugin Configuration Data + * + * @var $config + * @access public + */ + public $config; + /** + * Transactions ID + * + * @var $account_id + * @access public + */ + public $account_id = false; + + /** + * Constructor + * + * This constructor performs the work for this model. This model returns + * an array containing the following. + * + * 'status' + * + * True if successful and false if there was a fatal failure. + * + * 'view' + * + * A suggested view name that the controller should use instead of the + * default view for this model or false to indicate that the default view + * should be used. + * + * 'data' + * + * Data that the model is returning for use in merging with the view to + * produce output. + * + * @wpdb object WordPress database object + * + * @return array Array containing status, suggested view, and any data + */ + public function __construct ( $wpdb, $config ) + { + + // Save WordPress Database object + $this->wpdb = $wpdb; + + // Save plugin configuration object + $this->config = $config; + + /* + * Run constructor for the Contacts data class + * + * Note, the third parameter is a flag that indicates to the Contacts + * data class that it should flag a group of fields as 'view_only'. + */ + parent::__construct( false, false, true ); + + } + + public function modelAction($actionData = false) + { + + $option = 'list'; + $this->account_id = false; + $ref_dest = false; + + // Get any provided option + if ( isset( $_REQUEST['option'] ) ) { + $option = $_REQUEST['option']; + } + + // Get any provided Id + if ( isset( $actionData['id'] ) ) { + $ref_dest = filter_var( $actionData['id'], FILTER_VALIDATE_INT ); + } + + if ( $ref_dest ) { + $BillingSupport = new GlmBillingSupport( $this->wpdb, $this->config ); + $billing_account = $BillingSupport->getAccountByRefDest( $ref_dest ); + $this->account_id = $billing_account['id']; + } + + switch ($option) { + + default: + + + break; + + } + + if ( $this->account_id ) { + // Get the billing data for the form + $account = $this->editEntry( $this->account_id ); + } else { + $account = $this->newEntry(); + } + + $templateData = array( + 'option' => $option, + 'account_id' => $this->account_id, + 'account' => $account, + ); + + // Return status, any suggested view, and any data to controller + return array( + 'status' => true, + 'modelRedirect' => false, + 'view' => "admin/billing/contact.html", + 'data' => $templateData + ); + + } + +} diff --git a/setup/adminHooks.php b/setup/adminHooks.php index 470c0d4..066ac8f 100644 --- a/setup/adminHooks.php +++ b/setup/adminHooks.php @@ -96,3 +96,36 @@ add_filter( return array_merge( $cron_task, $new_cron ); } ); + +/** + * Filter returning the html for the billing field form (contact) + */ +add_filter( + 'glm-members-billing-contact-form', + function( $content, $id ){ + unset( $_REQUEST['glm_action'] ); + $content .= $this->controller( 'billing', 'contact', array( 'id' => $id ) ); + return $content; +}, 10, 2); + +/** + * Returns true if plugin is enabled + */ +add_filter( + 'glm-members-billing-enabled', + function( $content ){ + return true; +}); + +/** + * Save the data for the billing info + * Returns Boolean or Array For Error + */ +add_filter( + 'glm-members-billing-contact-save-data', + function( $ref_dest ){ + require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH . '/billingSupport.php'; + $BillingSupport = new GlmBillingSupport( $this->wpdb, $this->config ); + return $BillingSupport->saveContactBillingData( $ref_dest ); + }, 10, 1 +); diff --git a/setup/validActions.php b/setup/validActions.php index e0b1806..0e761bc 100644 --- a/setup/validActions.php +++ b/setup/validActions.php @@ -85,6 +85,7 @@ $glmMembersBillingAddOnValidActions = array( 'payments' => GLM_MEMBERS_BILLING_PLUGIN_SLUG, 'accounts' => GLM_MEMBERS_BILLING_PLUGIN_SLUG, 'logs' => GLM_MEMBERS_BILLING_PLUGIN_SLUG, + 'contact' => GLM_MEMBERS_BILLING_PLUGIN_SLUG, ), 'member' => array( 'billing' => GLM_MEMBERS_BILLING_PLUGIN_SLUG, diff --git a/views/admin/billing/contact.html b/views/admin/billing/contact.html new file mode 100644 index 0000000..5f10978 --- /dev/null +++ b/views/admin/billing/contact.html @@ -0,0 +1,116 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Billing Email + + {if $account.fieldFail.email}

{$account.fieldFail.email}

{/if}
+
Billing Company + + {if $account.fieldFail.billing_company}

{$account.fieldFail.billing_company}

{/if}
+
Billing Position + + {if $account.fieldFail.billing_position}

{$account.fieldFail.billing_position}

{/if}
+
Billing First Name + + {if $account.fieldFail.billing_fname}

{$account.fieldFail.billing_fname}

{/if}
+
Billing Last Name + + {if $account.fieldFail.billing_lname}

{$account.fieldFail.billing_lname}

{/if}
+
Billing Address 1 + + {if $account.fieldFail.billing_addr1}

{$account.fieldFail.billing_addr1}

{/if}
+
Billing Address 2 + + {if $account.fieldFail.billing_addr2}

{$account.fieldFail.billing_addr2}

{/if}
+
Billing City + + {if $account.fieldFail.billing_city}

{$account.fieldFail.billing_city}

{/if}
+
Billing State + + {if $account.fieldFail.billing_state}

{$account.fieldFail.billing_state}

{/if}
+
Billing Zip + + {if $account.fieldFail.billing_zip}

{$account.fieldFail.billing_zip}

{/if}
+
Billing Country + + {if $account.fieldFail.billing_country}

{$account.fieldFail.billing_country}

{/if}
+
Billing Phone + + {if $account.fieldFail.billing_phone}

{$account.fieldFail.billing_phone}

{/if}
+
Billing Fax + + {if $account.fieldFail.billing_fax}

{$account.fieldFail.billing_fax}

{/if}
+
+