Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 2 additions & 92 deletions includes/crm-library/class-crmlib-clientify.php
Original file line number Diff line number Diff line change
Expand Up @@ -700,80 +700,6 @@ public function list_fields( $settings, $module = 'Contacts' ) {
return $fields;
}

/**
* Searches for an existing contact or company by a given field.
*
* @param string $module CRM module: 'contacts' or 'companies'.
* @param string $update_by Strategy key: 'email', 'phone', or 'tax_id'.
* @param string $value Value to search for.
* @param string $apikey API authentication token.
* @return int|false CRM record ID if found, false otherwise.
*/
private function search_contact( $module, $update_by, $value, $apikey ) {
if ( empty( $value ) ) {
return false;
}

$field_map = array(
'email' => 'email',
'phone' => 'phone',
'tax_id' => 'taxpayer_identification_number',
);

if ( ! isset( $field_map[ $update_by ] ) ) {
return false;
}

$result = $this->request(
$module . '/',
array(
$field_map[ $update_by ] => $value,
'fields' => 'id',
),
$apikey,
'GET'
);

if ( 'ok' !== $result['status'] ) {
return false;
}

$results = isset( $result['data']['results'] ) ? $result['data']['results'] : array();
if ( ! empty( $results[0]['id'] ) ) {
return (int) $results[0]['id'];
}

return false;
}

/**
* Extracts the search value from merge_vars for the given update-by strategy.
*
* @param array $merge_vars Array of mapped form field values.
* @param string $update_by Strategy key: 'email', 'phone', or 'tax_id'.
* @return string The value to search by, or empty string if not found.
*/
private function extract_update_by_value( $merge_vars, $update_by ) {
$field_map = array(
'email' => 'email',
'phone' => 'phone',
'tax_id' => 'taxpayer_identification_number',
);

if ( ! isset( $field_map[ $update_by ] ) ) {
return '';
}

$target = $field_map[ $update_by ];
foreach ( $merge_vars as $element ) {
if ( isset( $element['name'] ) && $target === $element['name'] && ! empty( $element['value'] ) ) {
return (string) $element['value'];
}
}

return '';
}

/**
* Creates an entry for given module of a CRM
*
Expand Down Expand Up @@ -887,25 +813,9 @@ public function create_entry( $settings, $merge_vars ) {
$contact['tags'] = array_values( array_filter( $contact_tags ) );
}

$update_by = isset( $settings['fc_crm_update_by'] ) ? $settings['fc_crm_update_by'] : 'none';
$http_method = 'POST';
$endpoint = $module . '/';
$found_id = false;

if ( 'none' !== $update_by ) {
$search_value = $this->extract_update_by_value( $merge_vars, $update_by );
if ( ! empty( $search_value ) ) {
$found_id = $this->search_contact( $module, $update_by, $search_value, $apikey );
if ( $found_id ) {
$http_method = 'PATCH';
$endpoint = $module . '/' . $found_id . '/';
}
}
}

$result = $this->request( $endpoint, $contact, $apikey, $http_method );
$result = $this->request( $module . '/', $contact, $apikey );
if ( 'ok' === $result['status'] ) {
$contact_id = isset( $result['data']['id'] ) ? $result['data']['id'] : ( $found_id ? $found_id : '' );
$contact_id = isset( $result['data']['id'] ) ? $result['data']['id'] : '';
$response_result = array(
'status' => 'ok',
'message' => 'success',
Expand Down
9 changes: 0 additions & 9 deletions includes/formscrm-library/class-contactform7.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,15 +164,6 @@ public function settings_add_crm( $args ) {
<?php esc_html_e( 'Saving...', 'formscrm' ); ?>
</span>
</p>
<p>
<label for="wpcf7-crm-fc_crm_update_by"><?php esc_html_e( 'Contact Update Strategy:', 'formscrm' ); ?></label><br />
<select name="wpcf7-crm[fc_crm_update_by]" id="wpcf7-crm-fc_crm_update_by" class="medium">
<?php foreach ( formscrm_get_update_by_choices() as $choice ) { ?>
<option value="<?php echo esc_attr( $choice['value'] ); ?>" <?php selected( isset( $cf7_crm['fc_crm_update_by'] ) ? $cf7_crm['fc_crm_update_by'] : 'none', $choice['value'] ); ?>><?php echo esc_html( $choice['label'] ); ?></option>
<?php } ?>
</select>
<span class="description"><?php esc_html_e( 'Search for an existing contact before creating. If found, it will be updated instead.', 'formscrm' ); ?></span>
</p>
<p>
<label for="wpcf7-crm-fc_crm_mode_expert"><?php esc_html_e( 'Expert Mode', 'formscrm' ); ?></label><br />
<input type="checkbox" id="wpcf7-crm-fc_crm_mode_expert" name="wpcf7-crm[fc_crm_mode_expert]" class="medium" value="on" <?php checked( $cf7_crm['fc_crm_mode_expert'], 'on' ); ?> /><?php esc_html_e( 'Enable this option to show all fields of the CRM.', 'formscrm' ); ?>
Expand Down
17 changes: 0 additions & 17 deletions includes/formscrm-library/class-elementor.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,23 +171,6 @@ public function register_settings_section( $widget ) {
)
);

// Contact Update Strategy.
$update_by_options = array();
foreach ( formscrm_get_update_by_choices() as $choice ) {
$update_by_options[ $choice['value'] ] = $choice['label'];
}
$widget->add_control(
'fc_crm_update_by',
array(
'label' => __( 'Contact Update Strategy', 'formscrm' ),
'type' => \Elementor\Controls_Manager::SELECT,
'label_block' => true,
'description' => __( 'Search for an existing contact before creating. If found, it will be updated instead.', 'formscrm' ),
'options' => $update_by_options,
'default' => 'none',
)
);

// Expert Mode.
$widget->add_control(
'fc_crm_mode_expert',
Expand Down
17 changes: 0 additions & 17 deletions includes/formscrm-library/class-gravityforms.php
Original file line number Diff line number Diff line change
Expand Up @@ -576,23 +576,6 @@ private function get_crm_feed_fields( $settings ) {
);
}

$update_by_choices = array();
foreach ( formscrm_get_update_by_choices() as $choice ) {
$update_by_choices[] = array(
'label' => $choice['label'],
'value' => $choice['value'],
);
}
$crm_feed_fields[] = array(
'name' => 'fc_crm_update_by',
'label' => __( 'Contact Update Strategy', 'formscrm' ),
'type' => 'select',
'class' => 'medium',
'dependency' => 'fc_crm_module',
'tooltip' => '<h6>' . __( 'Contact Update Strategy', 'formscrm' ) . '</h6>' . __( 'Choose whether to search for an existing contact before creating a new one. If a match is found, the record will be updated instead.', 'formscrm' ),
'choices' => $update_by_choices,
);

$crm_feed_fields[] = array(
'name' => 'listFields',
'label' => __( 'Map Fields', 'formscrm' ),
Expand Down
12 changes: 0 additions & 12 deletions includes/formscrm-library/class-woocommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,18 +189,6 @@ public function get_settings() {
);
}

$options_update_by = array();
foreach ( formscrm_get_update_by_choices() as $choice ) {
$options_update_by[ $choice['value'] ] = $choice['label'];
}
$settings_crm[] = array(
'name' => __( 'Contact Update Strategy', 'formscrm' ),
'type' => 'select',
'desc' => __( 'Search for an existing contact before creating. If found, it will be updated instead.', 'formscrm' ),
'options' => $options_update_by,
'id' => 'wc_formscrm[fc_crm_update_by]',
);

$settings_crm[] = array(
'type' => 'sectionend',
'id' => 'wc_settings_formscrm_section_end',
Expand Down
28 changes: 7 additions & 21 deletions includes/formscrm-library/class-wpforms.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,13 @@ public function process_entry( $fields, $entry, $form_data, $entry_id = 0 ) {

// Fire for each connection.
foreach ( $form_data['providers'][ $this->slug ] as $connection ) {
$account_id = $connection['account_id'];
$settings = $this->api_connect( $account_id );
$settings['fc_crm_module'] = $connection['list_id'];
$settings['fc_crm_update_by'] = isset( $connection['fc_crm_update_by'] ) ? $connection['fc_crm_update_by'] : 'none';
$merge_vars = array();
$entry_meta = wpforms()->get( 'entry_meta' );
$form_id = (int) $form_data['id'];
$title = '<strong>FormsCRM Log</strong><br/>';
$account_id = $connection['account_id'];
$settings = $this->api_connect( $account_id );
$settings['fc_crm_module'] = $connection['list_id'];
$merge_vars = array();
$entry_meta = wpforms()->get( 'entry_meta' );
$form_id = (int) $form_data['id'];
$title = '<strong>FormsCRM Log</strong><br/>';

// Check for credentials.
if ( empty( $settings['fc_crm_type'] ) ) {
Expand Down Expand Up @@ -545,19 +544,6 @@ public function output_options( $connection_id = '', $connection = array() ) {

$html .= '</div>';
$html .= '</div>';

// Contact Update Strategy select.
$saved_update_by = isset( $connection['fc_crm_update_by'] ) ? $connection['fc_crm_update_by'] : 'none';
$html .= '<div style="margin: 10px 0;">';
$html .= '<label for="wpforms-provider-formscrm-update-by-' . esc_attr( $connection_id ) . '" style="display:block; font-weight:600; margin-bottom:5px;">' . esc_html__( 'Contact Update Strategy', 'formscrm' ) . '</label>';
$html .= '<select id="wpforms-provider-formscrm-update-by-' . esc_attr( $connection_id ) . '" name="providers[' . esc_attr( $this->slug ) . '][' . esc_attr( $connection_id ) . '][fc_crm_update_by]">';
foreach ( formscrm_get_update_by_choices() as $choice ) {
$selected = selected( $saved_update_by, $choice['value'], false );
$html .= '<option value="' . esc_attr( $choice['value'] ) . '"' . $selected . '>' . esc_html( $choice['label'] ) . '</option>';
}
$html .= '</select>';
$html .= '<p style="margin: 5px 0 0; color: #666; font-size: 12px;">' . esc_html__( 'Search for an existing contact before creating. If found, it will be updated instead.', 'formscrm' ) . '</p>';
$html .= '</div>';
}
}

Expand Down
28 changes: 0 additions & 28 deletions includes/formscrm-library/helpers-library-crm.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,34 +170,6 @@ function formscrm_get_dependency_odoodb() {
}
}

if ( ! function_exists( 'formscrm_get_update_by_choices' ) ) {
/**
* Returns the choices for the update-by contact strategy setting.
*
* @return array
*/
function formscrm_get_update_by_choices() {
return array(
array(
'value' => 'none',
'label' => __( 'Always create new', 'formscrm' ),
),
array(
'value' => 'email',
'label' => __( 'Update by Email', 'formscrm' ),
),
array(
'value' => 'phone',
'label' => __( 'Update by Phone', 'formscrm' ),
),
array(
'value' => 'tax_id',
'label' => __( 'Update by Tax ID', 'formscrm' ),
),
);
}
}

// Visitor Key.
add_action( 'init', 'formscrm_visitorkey_session', 1 );
if ( ! function_exists( 'formscrm_visitorkey_session' ) ) {
Expand Down
Loading
Loading