From 1b1736cb2a1645a4fb2320a4d05e6492e72ad935 Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Mon, 30 Jul 2018 16:54:21 -0400 Subject: [PATCH] Update the filter for saving billing data. It now works for saving Contact or Company data as billing. --- classes/billingSupport.php | 113 ++++++++++++++++++++++++--- views/admin/billing/contact.html | 130 ++++++++++++++++++++++++++++++- 2 files changed, 230 insertions(+), 13 deletions(-) diff --git a/classes/billingSupport.php b/classes/billingSupport.php index 1b3ca56..6417bc5 100644 --- a/classes/billingSupport.php +++ b/classes/billingSupport.php @@ -1541,9 +1541,38 @@ class GlmBillingSupport ); } + /** + * getCityIdByName + * + * Find the name of the city with a given id. + * + * @param int $city_id The city id + * + * @return string Name of the city. + */ + public function getCityIdByName( $city_id ) + { + return $this->wpdb->get_var( + $this->wpdb->prepare( + "SELECT name + FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "cities + WHERE id = %d", + $city_id + ) + ); + } + + /** + * saveContactBillingData + * + * @param int $ref_dest Member Id. + * + * @return mixed Boolean or Array for an error. + */ public function saveContactBillingData( $ref_dest ) { $required_fields = $errors = array(); + $city_name = ''; $billingAccount = new GlmDataAccounts( $this->wpdb, $this->config ); $billingFields = $billingAccount->fields; if ( $billingFields ) { @@ -1553,18 +1582,70 @@ class GlmBillingSupport } } } - // 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 + // Check to see if using contact or business address for billing + $contact_use_billing = filter_var( $_REQUEST['contact_use_billing'], FILTER_VALIDATE_BOOLEAN ); + $business_use_billing = filter_var( $_REQUEST['business_use_billing'], FILTER_VALIDATE_BOOLEAN ); + if ( $contact_use_billing ) { + // Need to convert city to String + $city_id = filter_var( $_REQUEST['city'], FILTER_VALIDATE_INT ); + if ( $city_id ) { + $city_name = $this->getCityIdByName( $city_id ); + } + $billing_updated = array( + 'email' => filter_var( $_REQUEST['alt_email'] ), + 'billing_fname' => filter_var( $_REQUEST['fname'] ), + 'billing_lname' => filter_var( $_REQUEST['lname'] ), + 'billing_addr1' => filter_var( $_REQUEST['addr1'] ), + 'billing_addr2' => filter_var( $_REQUEST['addr2'] ), + 'billing_city' => $city_name, + 'billing_state' => filter_var( $_REQUEST['state'] ), + 'billing_country' => filter_var( $_REQUEST['country'] ), + 'billing_zip' => filter_var( $_REQUEST['zip'] ), + ); + $billing_updated_format = array( + '%s', // email + '%s', // fname + '%s', // lname + '%s', // addr1 + '%s', // addr2 + '%s', // city + '%s', // state + '%s', // country + '%s', // zip + ); + } else if ( $business_use_billing ) { + // Need to convert city to String + $city_id = filter_var( $_REQUEST['business_city'], FILTER_VALIDATE_INT ); + if ( $city_id ) { + $city_name = $this->getCityIdByName( $city_id ); + } + $billing_updated = array( + 'email' => filter_var( $_REQUEST['business_email'] ), + 'billing_company' => filter_var( $_REQUEST['org'] ), + 'billing_position' => filter_var( $_REQUEST['title'] ), + 'billing_fname' => filter_var( $_REQUEST['business_fname'] ), + 'billing_lname' => filter_var( $_REQUEST['business_lname'] ), + 'billing_addr1' => filter_var( $_REQUEST['business_addr1'] ), + 'billing_addr2' => filter_var( $_REQUEST['business_addr2'] ), + 'billing_city' => $city_name, + 'billing_state' => filter_var( $_REQUEST['business_state'] ), + 'billing_country' => filter_var( $_REQUEST['business_country'] ), + 'billing_zip' => filter_var( $_REQUEST['business_zip'] ), + ); + $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 + ); + } else if ( !$contact_use_billing && !$business_use_billing ) { $billing_updated = array( 'email' => filter_var( $_REQUEST['billing_email'] ), 'billing_company' => filter_var( $_REQUEST['billing_company'] ), @@ -1595,6 +1676,14 @@ class GlmBillingSupport '%s', // phone '%s', // fax ); + } + // Check the given $ref_dest + $member_id = filter_var( $ref_dest, FILTER_VALIDATE_INT ); + if ( $member_id && $billing_updated && $billing_updated_format ) { + // Get the members account + $account = $this->getAccountByRefDest( $member_id ); + + // New Billing Data If using Billing Fields // echo '
$billing_updated: ' . print_r( $billing_updated, true ) . '
'; // Check for required fields foreach ( $billing_updated as $field_name => $field_value ) { diff --git a/views/admin/billing/contact.html b/views/admin/billing/contact.html index 5f10978..0a914d5 100644 --- a/views/admin/billing/contact.html +++ b/views/admin/billing/contact.html @@ -1,4 +1,4 @@ - +
@@ -114,3 +114,131 @@
Billing Email
+ -- 2.17.1