Skip to content

Commit df317c9

Browse files
refactor: add fields group count to survey
1 parent 6d76386 commit df317c9

File tree

3 files changed

+26
-6
lines changed

3 files changed

+26
-6
lines changed

classes/plugin.class.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,20 @@ function get_product_meta_all() {
623623
return $res;
624624
}
625625

626+
/**
627+
* Get the count of all the created PPOM Group fields.
628+
*
629+
* @return int - The number of group fields in the database.
630+
*/
631+
public static function get_product_meta_count() {
632+
global $wpdb;
633+
634+
$qry = 'SELECT COUNT(*) FROM ' . $wpdb->prefix . PPOM_TABLE_META;
635+
$count = $wpdb->get_var($qry);
636+
637+
return intval($count);
638+
}
639+
626640
function get_product_meta( $meta_id ) {
627641

628642
if ( ! $meta_id ) {

classes/survey.class.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,20 +49,25 @@ public function get_survey_metadata( $data, $page_slug ) {
4949
return $data;
5050
}
5151

52-
$license_status = apply_filters( 'product_ppom_license_status', 'invalid' );
53-
$license_plan = intval( apply_filters( 'product_ppom_license_plan', -1 ) );
54-
$license_key = apply_filters( 'product_ppom_license_key', '' );
52+
$license_status = apply_filters( 'product_ppom_license_status', 'invalid' );
53+
$license_plan = intval( apply_filters( 'product_ppom_license_plan', -1 ) );
54+
$license_key = apply_filters( 'product_ppom_license_key', '' );
55+
$group_fields_count = get_transient( PPOM_GROUPS_COUNT_CACHE_KEY );
5556

56-
$license_data = get_option( 'ppom_pro_license_data', array() );
57+
if ( false === $group_fields_count ) {
58+
$group_fields_count = min( 100, NM_PersonalizedProduct::get_product_meta_count() );
59+
set_transient( PPOM_GROUPS_COUNT_CACHE_KEY, $group_fields_count, 100 <= $group_fields_count ? WEEK_IN_SECONDS : 12 * HOUR_IN_SECONDS );
60+
}
5761

58-
$install_days_number = round( ( time() - get_option( 'woocommerce_product_addon_install', time() ) ) / DAY_IN_SECONDS );
62+
$install_days_number = intval( ( time() - get_option( 'woocommerce_product_addon_install', time() ) ) / DAY_IN_SECONDS );
5963

6064
$data = array(
6165
'environmentId' => 'clza3s4zm000h10km1699nlli',
6266
'attributes' => array(
6367
'install_days_number' => $install_days_number,
6468
'free_version' => PPOM_VERSION,
6569
'license_status' => $license_status,
70+
'field_groups_count' => intval( $group_fields_count )
6671
)
6772
);
6873

@@ -71,7 +76,7 @@ public function get_survey_metadata( $data, $page_slug ) {
7176
}
7277

7378
if ( ! empty( $license_key ) ) {
74-
$data['attributes']['license_key'] = apply_filters( 'themeisle_sdk_secret_masking', $license_data->key );
79+
$data['attributes']['license_key'] = apply_filters( 'themeisle_sdk_secret_masking', $license_key );
7580
}
7681

7782
if ( defined( 'PPOM_PRO_VERSION' ) ) {

woocommerce-product-addon.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
define( 'PPOM_PRODUCT_META_KEY', '_product_meta_id' );
3434
define( 'PPOM_TABLE_META', 'nm_personalized' );
3535
define( 'PPOM_UPLOAD_DIR_NAME', 'ppom_files' );
36+
define( 'PPOM_GROUPS_COUNT_CACHE_KEY', 'ppom_groups_count_cache' );
3637
define( 'PPOM_COMPATIBILITY_FEATURES', [
3738
'pro_cond_field_repeat' => true, // Compatibility for Conditional Field Repeater feature
3839
'pgfbdfm_wp_filter_param_fix' => true // Fix for the wrong params of the ppom_get_field_by_dataname__field_meta WP filter .

0 commit comments

Comments
 (0)