diff --git a/classes/Admin.php b/classes/Admin.php
index e643423..2c7cf26 100644
--- a/classes/Admin.php
+++ b/classes/Admin.php
@@ -1,106 +1,114 @@
array(
+ 'name' => __( 'Enquiry Messages', 'catalogx' ),
+ 'subtab' => '',
+ ),
+ 'quote-requests' => array(
+ 'name' => __( 'Quotation Requests', 'catalogx' ),
+ 'subtab' => '',
+ ),
+ 'wholesale-users' => array(
+ 'name' => __( 'Wholesale Users', 'catalogx' ),
+ 'subtab' => '',
+ ),
+ 'rules' => array(
+ 'name' => __( 'Dynamic Pricing Rules', 'catalogx' ),
+ 'subtab' => '',
+ ),
+ 'settings' => array(
+ 'name' => __( 'Settings', 'catalogx' ),
+ 'subtab' => 'all-settings',
+ ),
+ 'modules' => array(
+ 'name' => __( 'Modules', 'catalogx' ),
+ 'subtab' => '',
+ ),
);
- add_submenu_page(
- 'catalogx',
- __('Dynamic Pricing Rules', 'catalogx'),
- __('Dynamic Pricing Rules', 'catalogx'),
- 'manage_woocommerce',
- 'catalogx#&tab=rules',
- '__return_null'
- );
+ foreach ( $submenus as $slug => $submenu ) {
+ // prepare subtab if subtab is exist.
+ $subtab = '';
- add_submenu_page(
- 'catalogx',
- __( 'Settings', 'catalogx' ),
- __( 'Settings', 'catalogx' ),
- 'manage_woocommerce',
- 'catalogx#&tab=settings&subtab=all-settings',
- '__return_null'
- );
+ if ( $submenu['subtab'] ) {
+ $subtab = '&subtab=' . $submenu['subtab'];
+ }
- add_submenu_page(
- 'catalogx',
- __( 'Modules', 'catalogx' ),
- __( 'Modules', 'catalogx' ),
- 'manage_woocommerce',
- 'catalogx#&tab=modules',
- '__return_null'
- );
+ add_submenu_page(
+ 'catalogx',
+ $submenu['name'],
+ $submenu['name'],
+ 'manage_woocommerce',
+ 'catalogx#&tab=' . $slug . $subtab,
+ '__return_null'
+ );
+ }
if ( ! Utill::is_khali_dabba() ) {
- $submenu[ 'catalogx' ][] = [
+ add_submenu_page(
+ 'catalogx',
+ __( 'Upgrade to Pro', 'catalogx' ),
'
-
@@ -90,6 +99,7 @@ function add_button_group() {
/**
* Display product price and description in single product page.
+ *
* @return void
*/
public function display_price_and_description() {
@@ -98,17 +108,16 @@ public function display_price_and_description() {
add_filter( 'woocommerce_show_variation_price', '__return_false' );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 );
- // for block support
+ // for block support.
add_filter( 'woocommerce_get_price_html', '__return_empty_string' );
}
-
+
$desc_hide_product_page = CatalogX()->setting->get_setting( 'hide_product_desc' );
if ( $desc_hide_product_page ) {
- remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 20);
- // for block support
- add_filter('woocommerce_short_description', '__return_empty_string');
- add_filter('render_block_core/post-excerpt', '__return_empty_string');
+ remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 20 );
+ // for block support.
+ add_filter( 'woocommerce_short_description', '__return_empty_string' );
+ add_filter( 'render_block_core/post-excerpt', '__return_empty_string' );
}
}
-
}
\ No newline at end of file
diff --git a/classes/FrontendScripts.php b/classes/FrontendScripts.php
index afd2425..3229b77 100644
--- a/classes/FrontendScripts.php
+++ b/classes/FrontendScripts.php
@@ -1,214 +1,603 @@
is_dev ) {
+ return 'release/assets/';
+ }
+ return 'assets/';
+ }
+
+ /**
+ * Enqueue external JavaScript files.
+ *
+ * @return void
+ */
+ public static function enqueue_external_scripts() {
+ $base_dir = plugin_dir_path( __FILE__ ) . '../' . self::get_build_path_name() . 'js/';
+ $base_url = CatalogX()->plugin_url . self::get_build_path_name() . 'js/';
+ self::enqueue_scripts_from_dir( $base_dir . 'externals/', $base_url . 'externals/' );
+ if ( CatalogX()->is_dev ) {
+ self::enqueue_scripts_from_dir(
+ $base_dir,
+ $base_url,
+ array( 'index.js', 'components.js' ),
+ '/min\.js$/i'
+ );
+ }
+ }
+
+ /**
+ * Enqueue JavaScript files from a directory, optionally excluding some by name or pattern.
+ *
+ * @param string $dir Full filesystem path to the JS directory.
+ * @param string $url Corresponding URL for the directory.
+ * @param string[] $exclude_files Array of filenames to exclude.
+ * @param string $exclude_pattern Optional regex pattern to exclude.
+ * @return void
+ */
+ private static function enqueue_scripts_from_dir( $dir, $url, $exclude_files = array(), $exclude_pattern = '' ) {
+ if ( ! is_dir( $dir ) ) {
+ return;
+ }
+ $js_files = glob( $dir . '*.js' );
+ foreach ( $js_files as $chunk_path ) {
+ $chunk_file = basename( $chunk_path );
+ // Exclude based on filename or regex.
+ if ( in_array( $chunk_file, $exclude_files, true ) ||
+ ( $exclude_pattern && preg_match( $exclude_pattern, $chunk_file ) )
+ ) {
+ continue;
+ }
+ $chunk_handle = 'catalogx-script-' . sanitize_title( $chunk_file );
+ $asset_file = str_replace( '.js', '.asset.php', $chunk_path );
+ $deps = array();
+ $version = filemtime( $chunk_path );
+ if ( file_exists( $asset_file ) ) {
+ $asset = include $asset_file;
+ $deps = $asset['dependencies'] ?? array();
+ $version = $asset['version'] ?? $version;
+ }
+ wp_enqueue_script(
+ $chunk_handle,
+ $url . $chunk_file,
+ $deps,
+ $version,
+ true
+ );
+ }
}
- public static function register_script( $handle, $path, $deps = [], $version="", $text_domain="" ) {
+ /**
+ * Register and store a script for later use.
+ *
+ * @param string $handle Name of the script.
+ * @param string $path URL to the script.
+ * @param array $deps Optional. An array of dependencies. Default empty array.
+ * @param string $version Optional. Script version. Default empty string.
+ */
+ public static function register_script( $handle, $path, $deps = array(), $version = '' ) {
self::$scripts[] = $handle;
wp_register_script( $handle, $path, $deps, $version, true );
- wp_set_script_translations( $handle, $text_domain );
+ wp_set_script_translations( $handle, 'catalogx' );
}
- public static function register_style( $handle, $path, $deps = [], $version="" ) {
+ /**
+ * Register and store a style for later use.
+ *
+ * @param string $handle Name of the script.
+ * @param string $path URL to the script.
+ * @param array $deps Optional. An array of dependencies. Default empty array.
+ * @param string $version Optional. Script version. Default empty string.
+ */
+ public static function register_style( $handle, $path, $deps = array(), $version = '' ) {
self::$styles[] = $handle;
wp_register_style( $handle, $path, $deps, $version );
}
+ /**
+ * Register frontend scripts using filters and enqueue required external scripts.
+ *
+ * @return void
+ */
public static function register_scripts() {
$version = CatalogX()->version;
+ self::enqueue_external_scripts();
- $register_scripts = apply_filters('catalogx_register_scripts', array(
- 'catalogx-enquiry-frontend-script' => [
- 'src' => CatalogX()->plugin_url . 'modules/Enquiry/assets/js/frontend.js',
- 'deps' => [ 'jquery', 'jquery-blockui' ],
- 'version' => $version,
- 'text_domain' => 'catalogx'
- ],
- 'catalogx-enquiry-form-script' => [
- 'src' => CatalogX()->plugin_url . 'build/blocks/enquiryForm/index.js',
- 'deps' => [ 'jquery', 'jquery-blockui', 'wp-element', 'wp-i18n', 'wp-blocks', 'wp-hooks' ],
- 'version' => $version,
- 'text_domain' => 'catalogx'
- ],
- 'catalogx-quote-cart-script' => [
- 'src' => CatalogX()->plugin_url . 'build/blocks/quote-cart/index.js',
- 'deps' => [ 'jquery', 'jquery-blockui', 'wp-element', 'wp-i18n', 'wp-blocks' ],
- 'version' => $version,
- 'text_domain' => 'catalogx'
- ],
- 'catalogx-add-to-quote-cart-script' => [
- 'src' => CatalogX()->plugin_url . 'modules/Quote/js/frontend.js',
- 'deps' => [ 'jquery' ],
- 'version' => $version,
- 'text_domain' => 'catalogx'
- ],
- ) );
+ $register_scripts = apply_filters(
+ 'catalogx_register_scripts',
+ array(
+ 'catalogx-enquiry-frontend-script' => array(
+ 'src' => CatalogX()->plugin_url . self::get_build_path_name() . 'modules/Enquiry/js/' . CATALOGX_PLUGIN_SLUG . '-frontend.min.js',
+ 'deps' => array( 'jquery', 'jquery-blockui' ),
+ 'version' => $version,
+ ),
+ 'catalogx-enquiry-form-script' => array(
+ 'src' => CatalogX()->plugin_url . self::get_build_path_name() . 'js/block/enquiryForm/index.js',
+ 'deps' => array( 'jquery', 'jquery-blockui', 'wp-element', 'wp-i18n', 'wp-blocks', 'wp-hooks' ),
+ 'version' => $version,
+ ),
+ 'catalogx-quote-cart-script' => array(
+ 'src' => CatalogX()->plugin_url . self::get_build_path_name() . 'js/block/quote-cart/index.js',
+ 'deps' => array( 'jquery', 'jquery-blockui', 'wp-element', 'wp-i18n', 'wp-blocks' ),
+ 'version' => $version,
+ ),
+ 'catalogx-add-to-quote-cart-script' => array(
+ 'src' => CatalogX()->plugin_url . self::get_build_path_name() . 'modules/Quote/js/' . CATALOGX_PLUGIN_SLUG . '-frontend.min.js',
+ 'deps' => array( 'jquery' ),
+ 'version' => $version,
+ ),
+ )
+ );
foreach ( $register_scripts as $name => $props ) {
- self::register_script( $name, $props['src'], $props['deps'], $props['version'], $props['text_domain'] );
+ self::register_script( $name, $props['src'], $props['deps'], $props['version'] );
}
}
+ /**
+ * Register frontend styles using filters.
+ *
+ * @return void
+ */
public static function register_styles() {
$version = CatalogX()->version;
- $register_styles = apply_filters('catalogx_register_styles', [
- 'catalogx-frontend-style' => [
- 'src' => CatalogX()->plugin_url . 'assets/css/frontend.css',
- 'deps' => array(),
- 'version' => $version,
- ],
- 'catalogx-enquiry-form-style' => [
- 'src' => CatalogX()->plugin_url . 'build/blocks/enquiryForm/index.css',
- 'deps' => array(),
- 'version' => $version,
- ],
- 'catalogx-quote-cart-style' => [
- 'src' => CatalogX()->plugin_url . 'build/blocks/quote-cart/index.css',
- 'deps' => array(),
- 'version' => $version,
- ],
- ] );
+ $register_styles = apply_filters(
+ 'catalogx_register_styles',
+ array(
+ 'catalogx-frontend-style' => array(
+ 'src' => CatalogX()->plugin_url . self::get_build_path_name() . 'styles/' . CATALOGX_PLUGIN_SLUG . '-frontend.min.css',
+ 'deps' => array(),
+ 'version' => $version,
+ ),
+ 'catalogx-enquiry-form-style' => array(
+ 'src' => CatalogX()->plugin_url . self::get_build_path_name() . 'styles/block/enquiryForm/index.css',
+ 'deps' => array(),
+ 'version' => $version,
+ ),
+ )
+ );
+ foreach ( $register_styles as $name => $props ) {
+ self::register_style( $name, $props['src'], $props['deps'], $props['version'] );
+ }
+ }
+
+ /**
+ * Register admin scripts using filters.
+ *
+ * Loads admin-specific JavaScript assets and chunked dependencies.
+ *
+ * @return void
+ */
+ public static function admin_register_scripts() {
+ $version = CatalogX()->version;
+ // Enqueue all chunk files (External dependencies).
+ self::enqueue_external_scripts();
+ $index_asset = include plugin_dir_path( __FILE__ ) . '../' . self::get_build_path_name() . 'js/index.asset.php';
+ $component_asset = include plugin_dir_path( __FILE__ ) . '../' . self::get_build_path_name() . 'js/components.asset.php';
+ $register_scripts = apply_filters(
+ 'admin_catalogx_register_scripts',
+ array(
+ 'catalogx-admin-script' => array(
+ 'src' => CatalogX()->plugin_url . self::get_build_path_name() . 'js/index.js',
+ 'deps' => $index_asset['dependencies'],
+ 'version' => $version,
+ ),
+ 'catalogx-components-script' => array(
+ 'src' => CatalogX()->plugin_url . self::get_build_path_name() . 'js/components.js',
+ 'deps' => $component_asset['dependencies'],
+ 'version' => $version,
+ ),
+ )
+ );
+ foreach ( $register_scripts as $name => $props ) {
+ self::register_script( $name, $props['src'], $props['deps'], $props['version'] );
+ }
+ }
+
+ /**
+ * Register admin styles using filters.
+ *
+ * @return void
+ */
+ public static function admin_register_styles() {
+ $version = CatalogX()->version;
+
+ $register_styles = apply_filters(
+ 'admin_catalogx_register_styles',
+ array(
+ 'catalogx-components-style' => array(
+ 'src' => CatalogX()->plugin_url . self::get_build_path_name() . 'styles/components.css',
+ 'deps' => array(),
+ 'version' => $version,
+ ),
+ )
+ );
+
foreach ( $register_styles as $name => $props ) {
self::register_style( $name, $props['src'], $props['deps'], $props['version'] );
}
}
/**
- * Register/queue frontend scripts.
+ * Register/queue frontend scripts and styles
*/
public static function load_scripts() {
self::register_scripts();
self::register_styles();
}
+ /**
+ * Register/queue admin scripts and styles
+ */
+ public static function admin_load_scripts() {
+ self::admin_register_scripts();
+ self::admin_register_styles();
+ }
+ /**
+ * Localize all scripts.
+ *
+ * @param string $handle Script handle in which the data will be attached to.
+ */
public static function localize_scripts( $handle ) {
- $current_user = wp_get_current_user();
-
- $localize_scripts = apply_filters('catalogx_localize_scripts', array(
- 'catalogx-enquiry-frontend-script' => [
- 'object_name' => 'enquiryFrontend',
- 'data' => [
- 'ajaxurl' => admin_url('admin-ajax.php'),
- ],
- ],
- 'catalogx-enquiry-form-script' => [
- 'object_name' => 'enquiryFormData',
- 'data' => [
- 'apiurl' => untrailingslashit(get_rest_url()),
- 'nonce' => wp_create_nonce( 'wp_rest' ),
- 'settings_free' => CatalogX()->modules->is_active('enquiry') ? EnquiryFrontend::catalogx_free_form_settings() : [],
- 'settings_pro' => CatalogX()->modules->is_active('enquiry') ? EnquiryFrontend::catalogx_pro_form_settings() : [],
- 'khali_dabba' => \CatalogX\Utill::is_khali_dabba(),
- 'product_data' => (\CatalogX\Utill::is_khali_dabba() && !empty(CatalogX_Pro()->cart->get_cart_data())) ? CatalogX_Pro()->cart->get_cart_data() : '',
- 'default_placeholder' => [
- 'name' => $current_user->display_name,
- 'email' => $current_user->user_email
- ],
- 'content_before_form' => apply_filters('catalogx_add_content_before_form', ''),
- 'content_after_form' => apply_filters('catalogx_add_content_after_form', ''),
- 'error_strings' => [
- 'required' => __("This field is required", "catalogx"),
- 'invalid' => __("Invalid email format", "catalogx"),
- ]
- ],
- ],
- 'catalogx-add-to-quote-cart-script' => [
- 'object_name' => 'addToQuoteCart',
- 'data' => [
- 'ajaxurl' => admin_url('admin-ajax.php'),
- 'loader' => admin_url('images/wpspin_light.gif'),
- 'no_more_product' => __('No more product in Quote list!', 'catalogx'),
- ],
- ],
- 'catalogx-enquiry-button-editor-script' => [
- 'object_name' => 'enquiryButton',
- 'data' => [
- 'apiUrl' => untrailingslashit(get_rest_url()),
- 'restUrl' => CatalogX()->rest_namespace,
- 'nonce' => wp_create_nonce( 'catalog-security-nonce' )
- ],
- ],
- 'catalogx-quote-button-editor-script' => [
- 'object_name' => 'quoteButton',
- 'data' => [
- 'apiUrl' => untrailingslashit(get_rest_url()),
- 'restUrl' => CatalogX()->rest_namespace,
- 'nonce' => wp_create_nonce( 'catalog-security-nonce' )
- ],
- ],
- 'catalogx-quote-cart-editor-script' => [
- 'object_name' => 'quoteCart',
- 'data' => [
- 'apiUrl' => untrailingslashit(get_rest_url()),
- 'restUrl' => CatalogX()->rest_namespace,
- 'nonce' => wp_create_nonce('wp_rest'),
- 'name' => $current_user->display_name,
- 'email' => $current_user->user_email,
- 'quote_my_account_url' => site_url('/my-account/all-quotes/'),
- 'khali_dabba' => Utill::is_khali_dabba(),
- ],
- ],
- 'catalogx-quote-button-script' => [
- 'object_name' => 'quoteButton',
- 'data' => [
- 'apiUrl' => untrailingslashit(get_rest_url()),
- 'restUrl' => CatalogX()->rest_namespace,
- 'nonce' => wp_create_nonce( 'catalog-security-nonce' )
- ],
- ],
- 'catalogx-quote-cart-script' => [
- 'object_name' => 'quoteCart',
- 'data' => [
- 'apiUrl' => untrailingslashit(get_rest_url()),
- 'restUrl' => CatalogX()->rest_namespace,
- 'nonce' => wp_create_nonce('wp_rest'),
- 'name' => $current_user->display_name,
- 'email' => $current_user->user_email,
- 'quote_my_account_url' => site_url('/my-account/all-quotes/'),
- 'khali_dabba' => Utill::is_khali_dabba(),
- ],
- ],
- 'catalogx-enquiry-button-script' => [
- 'object_name' => 'enquiryButton',
- 'data' => [
- 'apiUrl' => untrailingslashit(get_rest_url()),
- 'restUrl' => CatalogX()->rest_namespace,
- 'nonce' => wp_create_nonce( 'catalog-security-nonce' )
- ],
- ],
- ));
-
+
+ // Prepare data of all pages.
+ $pages = get_pages();
+ $all_pages = array();
+
+ if ( $pages ) {
+ foreach ( $pages as $page ) {
+ $all_pages[] = array(
+ 'value' => $page->ID,
+ 'label' => $page->post_title,
+ 'key' => $page->ID,
+ );
+ }
+ }
+
+ // Prepare data of all user roles.
+ $roles = wp_roles()->roles;
+ $all_roles = array();
+
+ if ( $roles ) {
+ foreach ( $roles as $key => $role ) {
+ $all_roles[] = array(
+ 'value' => $key,
+ 'label' => $role['name'],
+ 'key' => $key,
+ );
+ }
+ }
+
+ // Get all users id and name and prepare data.
+ $users = get_users( array( 'fields' => array( 'display_name', 'id' ) ) );
+ $all_users = array();
+
+ foreach ( $users as $user ) {
+ $all_users[] = array(
+ 'value' => $user->ID,
+ 'label' => $user->display_name,
+ 'key' => $user->ID,
+ );
+ }
+
+ // Prepare all products.
+ $products_ids = wc_get_products(
+ array(
+ 'limit' => -1,
+ 'return' => 'ids',
+ )
+ );
+ $all_products = array();
+
+ foreach ( $products_ids as $id ) {
+ $product_name = get_the_title( $id );
+
+ $all_products[] = array(
+ 'value' => $id,
+ 'label' => $product_name,
+ 'key' => $id,
+ );
+ }
+
+ // Prepare all product terms.
+ $terms = get_terms(
+ array(
+ 'taxonomy' => 'product_cat',
+ 'orderby' => 'name',
+ 'order' => 'ASC',
+ )
+ );
+ $product_cat = array();
+
+ if ( $terms && empty( $terms->errors ) ) {
+ foreach ( $terms as $term ) {
+ $product_cat[] = array(
+ 'value' => $term->term_id,
+ 'label' => $term->name,
+ 'key' => $term->term_id,
+ );
+ }
+ }
+
+ // Prepare all product tags.
+ $tags = get_terms(
+ array(
+ 'taxonomy' => 'product_tag',
+ 'hide_empty' => false,
+ )
+ );
+ $product_tags = array();
+ if ( $tags ) {
+ foreach ( $tags as $tag ) {
+ $product_tags[] = array(
+ 'value' => $tag->term_id,
+ 'label' => $tag->name,
+ 'key' => $tag->term_id,
+ );
+ }
+ }
+
+ // Prepare all product brands.
+ $brands = get_terms(
+ array(
+ 'taxonomy' => 'product_brand',
+ 'hide_empty' => false,
+ )
+ );
+ $all_product_brand = array();
+ if ( $brands ) {
+ foreach ( $brands as $brand ) {
+ $all_product_brand[] = array(
+ 'value' => $brand->term_id,
+ 'label' => $brand->name,
+ 'key' => $brand->term_id,
+ );
+ }
+ }
+
+ // Get current user role.
+ $current_user = wp_get_current_user();
+ $current_user_role = '';
+ if ( ! empty( $current_user->roles ) && is_array( $current_user->roles ) ) {
+ $current_user_role = reset( $current_user->roles );
+ }
+
+ // Get all tab setting's database value.
+ $settings_value = array();
+ $tabs_names = array( 'enquiry-catalog-customization', 'all-settings', 'enquiry-form-customization', 'enquiry-quote-exclusion', 'tools', 'enquiry-email-temp', 'wholesale', 'wholesale-registration', 'pages' );
+ foreach ( $tabs_names as $tab_name ) {
+ $settings_value[ $tab_name ] = CatalogX()->setting->get_option( str_replace( '-', '_', 'catalogx_' . $tab_name . '_settings' ) );
+ }
+
+ if ( 'administrator' === $current_user_role ) {
+ $quote_base_url = admin_url( 'admin.php?page=wc-orders&action=edit&id=' );
+ } elseif ( 'customer' === $current_user_role ) {
+ $quote_base_url = site_url( '/my-account/view-quote/' );
+ } else {
+ $quote_base_url = '/';
+ }
+
+ $localize_scripts = apply_filters(
+ 'catalogx_localize_scripts',
+ array(
+ 'catalogx-admin-script' => array(
+ 'object_name' => 'appLocalizer',
+ 'data' => array(
+ 'apiUrl' => untrailingslashit( get_rest_url() ),
+ 'nonce' => wp_create_nonce( 'wp_rest' ),
+ 'tab_name' => 'CatalogX',
+ 'restUrl' => CatalogX()->rest_namespace,
+ 'all_pages' => $all_pages,
+ 'role_array' => $all_roles,
+ 'all_users' => $all_users,
+ 'all_products' => $all_products,
+ 'all_product_cat' => $product_cat,
+ 'all_product_brand' => $all_product_brand,
+ 'all_product_tag' => $product_tags,
+ 'settings_databases_value' => $settings_value,
+ 'active_modules' => CatalogX()->modules->get_active_modules(),
+ 'user_role' => $current_user_role,
+ 'banner_img' => CatalogX()->plugin_url . 'assets/images/catalog-pro-add-admin-banner.jpg',
+ 'default_img' => CatalogX()->plugin_url . 'src/assets/images/default.png',
+ 'template1' => CatalogX()->plugin_url . 'assets/images/email/templates/catalogx-email-template-default.png',
+ 'template2' => CatalogX()->plugin_url . 'assets/images/email/templates/catalogx-email-template-1.png',
+ 'template3' => CatalogX()->plugin_url . 'assets/images/email/templates/catalogx-email-template-2.png',
+ 'template4' => CatalogX()->plugin_url . 'assets/images/email/templates/catalogx-email-template-3.png',
+ 'template5' => CatalogX()->plugin_url . 'assets/images/email/templates/catalogx-email-template-4.png',
+ 'template6' => CatalogX()->plugin_url . 'assets/images/email/templates/catalogx-email-template-5.png',
+ 'template7' => CatalogX()->plugin_url . 'assets/images/email/templates/catalogx-email-template-6.png',
+ 'khali_dabba' => Utill::is_khali_dabba(),
+ 'pro_url' => esc_url( CATALOGX_PRO_SHOP_URL ),
+ 'order_edit' => admin_url( 'admin.php?page=wc-orders&action=edit' ),
+ 'site_url' => admin_url( 'admin.php?page=catalogx#&tab=settings&subtab=all-settings' ),
+ 'module_page_url' => admin_url( 'admin.php?page=catalogx#&tab=modules' ),
+ 'settings_page_url' => admin_url( 'admin.php?page=catalogx#&tab=settings&subtab=all-settings' ),
+ 'enquiry_form_settings_url' => admin_url( 'admin.php?page=catalogx#&tab=settings&subtab=enquiry-form-customization' ),
+ 'customization_settings_url' => admin_url( 'admin.php?page=catalogx#&tab=settings&subtab=enquiry-catalog-customization' ),
+ 'wholesale_settings_url' => admin_url( 'admin.php?page=catalogx#&tab=settings&subtab=wholesale' ),
+ 'rule_url' => admin_url( 'admin.php?page=catalogx#&tab=rules' ),
+ 'currency' => get_woocommerce_currency(),
+ 'notifima_active' => Utill::is_active_plugin( 'notifima' ),
+ 'mvx_active' => Utill::is_active_plugin( 'multivendorx' ),
+ 'quote_module_active' => CatalogX()->modules->is_active( 'quote' ),
+ 'quote_base_url' => $quote_base_url,
+ ),
+ ),
+ 'catalogx-enquiry-frontend-script' => array(
+ 'object_name' => 'enquiryFrontend',
+ 'data' => array(
+ 'ajaxurl' => admin_url( 'admin-ajax.php' ),
+ ),
+ ),
+ 'catalogx-enquiry-form-script' => array(
+ 'object_name' => 'enquiryFormData',
+ 'data' => array(
+ 'apiUrl' => untrailingslashit( get_rest_url() ),
+ 'nonce' => wp_create_nonce( 'wp_rest' ),
+ 'settings_free' => CatalogX()->modules->is_active( 'enquiry' ) ? EnquiryFrontend::catalogx_free_form_settings() : array(),
+ 'settings_pro' => CatalogX()->modules->is_active( 'enquiry' ) ? EnquiryFrontend::catalogx_pro_form_settings() : array(),
+ 'khali_dabba' => \CatalogX\Utill::is_khali_dabba(),
+ 'product_data' => ( \CatalogX\Utill::is_khali_dabba() && ! empty( CatalogX_Pro()->cart->get_cart_data() ) ) ? CatalogX_Pro()->cart->get_cart_data() : '',
+ 'default_placeholder' => array(
+ 'name' => $current_user->display_name,
+ 'email' => $current_user->user_email,
+ ),
+ 'content_before_form' => apply_filters( 'catalogx_add_content_before_form', '' ),
+ 'content_after_form' => apply_filters( 'catalogx_add_content_after_form', '' ),
+ 'error_strings' => array(
+ 'required' => __( 'This field is required', 'catalogx' ),
+ 'invalid' => __( 'Invalid email format', 'catalogx' ),
+ ),
+ ),
+ ),
+ 'catalogx-add-to-quote-cart-script' => array(
+ 'object_name' => 'addToQuoteCart',
+ 'data' => array(
+ 'ajaxurl' => admin_url( 'admin-ajax.php' ),
+ 'loader' => admin_url( 'images/wpspin_light.gif' ),
+ 'no_more_product' => __( 'No more product in Quote list!', 'catalogx' ),
+ ),
+ ),
+ 'catalogx-enquiry-button-editor-script' => array(
+ 'object_name' => 'enquiryButton',
+ 'data' => array(
+ 'apiUrl' => untrailingslashit( get_rest_url() ),
+ 'restUrl' => CatalogX()->rest_namespace,
+ 'nonce' => wp_create_nonce( 'wp_rest' ),
+ ),
+ ),
+ 'catalogx-quote-button-editor-script' => array(
+ 'object_name' => 'quoteButton',
+ 'data' => array(
+ 'apiUrl' => untrailingslashit( get_rest_url() ),
+ 'restUrl' => CatalogX()->rest_namespace,
+ 'nonce' => wp_create_nonce( 'wp_rest' ),
+ ),
+ ),
+ 'catalogx-quote-cart-editor-script' => array(
+ 'object_name' => 'quoteCart',
+ 'data' => array(
+ 'apiUrl' => untrailingslashit( get_rest_url() ),
+ 'restUrl' => CatalogX()->rest_namespace,
+ 'nonce' => wp_create_nonce( 'wp_rest' ),
+ 'name' => $current_user->display_name,
+ 'email' => $current_user->user_email,
+ 'quote_my_account_url' => site_url( '/my-account/all-quotes/' ),
+ 'khali_dabba' => Utill::is_khali_dabba(),
+ ),
+ ),
+ 'catalogx-quote-button-script' => array(
+ 'object_name' => 'quoteButton',
+ 'data' => array(
+ 'apiUrl' => untrailingslashit( get_rest_url() ),
+ 'restUrl' => CatalogX()->rest_namespace,
+ 'nonce' => wp_create_nonce( 'wp_rest' ),
+ ),
+ ),
+ 'catalogx-quote-cart-script' => array(
+ 'object_name' => 'quoteCart',
+ 'data' => array(
+ 'apiUrl' => untrailingslashit( get_rest_url() ),
+ 'restUrl' => CatalogX()->rest_namespace,
+ 'nonce' => wp_create_nonce( 'wp_rest' ),
+ 'name' => $current_user->display_name,
+ 'email' => $current_user->user_email,
+ 'quote_my_account_url' => site_url( '/my-account/all-quotes/' ),
+ 'khali_dabba' => Utill::is_khali_dabba(),
+ ),
+ ),
+ 'catalogx-enquiry-button-script' => array(
+ 'object_name' => 'enquiryButton',
+ 'data' => array(
+ 'apiUrl' => untrailingslashit( get_rest_url() ),
+ 'restUrl' => CatalogX()->rest_namespace,
+ 'nonce' => wp_create_nonce( 'wp_rest' ),
+ ),
+ ),
+ )
+ );
+
if ( isset( $localize_scripts[ $handle ] ) ) {
$props = $localize_scripts[ $handle ];
self::localize_script( $handle, $props['object_name'], $props['data'] );
}
}
- public static function localize_script( $handle, $name, $data = [], ) {
+ /**
+ * Localizes a registered script with data for use in JavaScript.
+ *
+ * @param string $handle Script handle the data will be attached to.
+ * @param string $name JavaScript object name.
+ * @param array $data Data to be made available in JavaScript.
+ */
+ public static function localize_script( $handle, $name, $data = array(), ) {
wp_localize_script( $handle, $name, $data );
}
+ /**
+ * Enqueues a registered script.
+ *
+ * @param string $handle Handle of the registered script to enqueue.
+ */
public static function enqueue_script( $handle ) {
wp_enqueue_script( $handle );
}
+ /**
+ * Enqueues a registered style.
+ *
+ * @param string $handle Handle of the registered style to enqueue.
+ */
public static function enqueue_style( $handle ) {
wp_enqueue_style( $handle );
}
-
-}
\ No newline at end of file
+}
diff --git a/classes/Install.php b/classes/Install.php
index 972bbc2..e4c0a36 100644
--- a/classes/Install.php
+++ b/classes/Install.php
@@ -1,17 +1,25 @@
'name-label',
'email' => 'email-label',
'phone' => 'is-phone',
@@ -21,342 +29,373 @@ class Install {
'fileupload' => 'is-fileupload',
'filesize-limit' => 'filesize-limit',
'captcha' => 'is-captcha',
- ];
+ );
- const PRO_FORM_TYPE_MAP = [
+ const PRO_FORM_TYPE_MAP = array(
'p_title' => 'title',
'textbox' => 'text',
- ];
+ );
+ /**
+ * Previously stored plugin version.
+ *
+ * @var string
+ */
public static $previous_version = '';
- public static $current_version = '';
-
/**
* Install class constructor functions
*/
public function __construct() {
- // Get the previous version and current version
+ // Get the previous version and current version.
self::$previous_version = get_option( self::VERSION_KEY, '' );
- self::$current_version = CatalogX()->version;
-
- $this->create_database_tables();
- $this->set_default_modules();
- $this->set_default_settings();
-
- // this function should be deleted after 7.0.0
- if (!empty(get_option('mvx_catalog_general_tab_settings'))) {
+ // this function should be deleted after 7.0.0 .
+ if ( ! empty( get_option( 'mvx_catalog_general_tab_settings' ) ) ) {
+ $this->create_database_tables();
+ $this->set_default_modules();
+ $this->set_default_settings();
$this->migrate_catalog_enquiry_to_catalogx();
+ update_option( self::VERSION_KEY, '6.0.0' );
}
-
- $this->run_default_migration();
-
- // Update the version in database
- update_option( self::VERSION_KEY, self::$current_version );
+ if ( ! ( get_option( self::VERSION_KEY, false ) ) ) {
+ $this->create_database_tables();
+ $this->set_default_modules();
+ $this->set_default_settings();
+ } else {
+ $this->run_default_migration();
+ }
+ // Update the version in database.
+ update_option( self::VERSION_KEY, CatalogX()->version );
}
/**
* Create database table for plugin
+ *
* @return void
*/
private function create_database_tables() {
+ // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.DirectDatabaseQuery.SchemaChange, WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQL.InterpolatedNotPrepared
global $wpdb;
+ // Include upgrade functions if not loaded.
+ if ( ! function_exists( 'dbDelta' ) ) {
+ require_once ABSPATH . 'wp-admin/includes/upgrade.php';
+ }
+
$collate = '';
- if ($wpdb->has_cap('collation')) {
+ if ( $wpdb->has_cap( 'collation' ) ) {
$collate = $wpdb->get_charset_collate();
}
- if (!empty(get_option('mvx_catalog_general_tab_settings'))) {
- // table migration
- // Rename the table
+ if ( ! empty( get_option( 'mvx_catalog_general_tab_settings' ) ) ) {
+ // table migration.
+ // Rename the table.
$wpdb->query(
- "ALTER TABLE `{$wpdb->prefix}catelog_cust_vendor_answers` RENAME TO `{$wpdb->prefix}" . Utill::TABLES[ 'message' ] . "`"
+ "ALTER TABLE `{$wpdb->prefix}catelog_cust_vendor_answers` RENAME TO `{$wpdb->prefix}" . Utill::TABLES['message'] . '`'
);
- // Add column to table
+ // Add column to table.
$wpdb->query(
- "ALTER TABLE `{$wpdb->prefix}" . Utill::TABLES[ 'message' ] . "`
- ADD COLUMN attachment bigint(20);"
+ "ALTER TABLE `{$wpdb->prefix}" . Utill::TABLES['message'] . '`
+ ADD COLUMN attachment bigint(20);'
);
$wpdb->query(
- "ALTER TABLE `{$wpdb->prefix}" . Utill::TABLES[ 'message' ] . "`
- ADD COLUMN reaction varchar(20);"
+ "ALTER TABLE `{$wpdb->prefix}" . Utill::TABLES['message'] . '`
+ ADD COLUMN reaction varchar(20);'
);
$wpdb->query(
- "ALTER TABLE `{$wpdb->prefix}" . Utill::TABLES[ 'message' ] . "`
- ADD COLUMN star boolean;"
+ "ALTER TABLE `{$wpdb->prefix}" . Utill::TABLES['message'] . '`
+ ADD COLUMN star boolean;'
);
$wpdb->query(
- "ALTER TABLE `{$wpdb->prefix}" . Utill::TABLES[ 'message' ] . "`
- ADD COLUMN reply text DEFAULT NULL;"
+ "ALTER TABLE `{$wpdb->prefix}" . Utill::TABLES['message'] . '`
+ ADD COLUMN reply text DEFAULT NULL;'
);
-
} else {
- // Create message table
- $wpdb->query(
- "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}" . Utill::TABLES[ 'message' ] . "` (
- `chat_message_id` bigint(20) NOT NULL AUTO_INCREMENT,
- `to_user_id` bigint(20) NOT NULL,
- `from_user_id` bigint(20) NOT NULL,
- `chat_message` text NOT NULL,
- `product_id` text NOT NULL,
- `enquiry_id` bigint(20) NOT NULL,
- `status` varchar(20) NOT NULL,
- `date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
- `attachment` bigint(20),
- `reaction` varchar(20),
- `star` boolean,
- `reply` text DEFAULT NULL,
- PRIMARY KEY (`chat_message_id`)
- ) $collate;"
- );
- }
-
- // Create enquiry table
- $wpdb->query(
- "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}" . Utill::TABLES[ 'enquiry' ] . "` (
- `id` bigint(20) NOT NULL AUTO_INCREMENT,
- `product_info` text NOT NULL,
- `user_id` bigint(20) NOT NULL DEFAULT 0,
- `user_name` varchar(50) NOT NULL,
- `user_email` varchar(50) NOT NULL,
- `user_additional_fields` text NOT NULL,
- `pin_msg_id` bigint(20) DEFAULT NULL,
+ // Create message table.
+ $sql_message = "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}" . Utill::TABLES['message'] . "` (
+ `chat_message_id` bigint(20) NOT NULL AUTO_INCREMENT,
+ `to_user_id` bigint(20) NOT NULL,
+ `from_user_id` bigint(20) NOT NULL,
+ `chat_message` text NOT NULL,
+ `product_id` text NOT NULL,
+ `enquiry_id` bigint(20) NOT NULL,
+ `status` varchar(20) NOT NULL,
`date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
- PRIMARY KEY (`id`)
- ) $collate;"
- );
+ `attachment` bigint(20),
+ `reaction` varchar(20),
+ `star` boolean,
+ `reply` text DEFAULT NULL,
+ PRIMARY KEY (`chat_message_id`)
+ ) $collate;";
+
+ dbDelta( $sql_message );
+ }
- // Create rules table
- $wpdb->query(
- "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}" . Utill::TABLES[ 'rule' ] . "` (
- `id` bigint(20) NOT NULL AUTO_INCREMENT,
- `name` text,
- `user_id` bigint(20),
- `role_id` varchar(100),
- `product_id` bigint(20),
- `category_id` bigint(20),
- `brand_id` bigint(20),
- `quentity` bigint(20) NOT NULL,
- `type` varchar(20) NOT NULL,
- `amount` bigint(20) NOT NULL,
- `priority` bigint(20) NOT NULL,
- `active` boolean NOT NULL DEFAULT true,
- PRIMARY KEY ( `id` )
- ) $collate;"
- );
+ // Create enquiry table.
+ $sql_enquiry = "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}" . Utill::TABLES['enquiry'] . "` (
+ `id` bigint(20) NOT NULL AUTO_INCREMENT,
+ `product_info` text NOT NULL,
+ `user_id` bigint(20) NOT NULL DEFAULT 0,
+ `user_name` varchar(50) NOT NULL,
+ `user_email` varchar(50) NOT NULL,
+ `user_additional_fields` text NOT NULL,
+ `pin_msg_id` bigint(20) DEFAULT NULL,
+ `date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
+ PRIMARY KEY (`id`)
+ ) $collate;";
+
+ dbDelta( $sql_enquiry );
+
+ // Create rules table.
+ $sql_rule = "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}" . Utill::TABLES['rule'] . "` (
+ `id` bigint(20) NOT NULL AUTO_INCREMENT,
+ `name` text,
+ `user_id` bigint(20),
+ `role_id` varchar(100),
+ `product_id` bigint(20),
+ `category_id` bigint(20),
+ `brand_id` bigint(20),
+ `quentity` bigint(20) NOT NULL,
+ `type` varchar(20) NOT NULL,
+ `amount` bigint(20) NOT NULL,
+ `priority` bigint(20) NOT NULL,
+ `active` boolean NOT NULL DEFAULT true,
+ PRIMARY KEY ( `id` )
+ ) $collate;";
+
+ dbDelta( $sql_rule );
+ // phpcs:enable
}
/**
* Set default modules
+ *
* @return void
*/
- public static function set_default_modules() {
- // Enable catalog module by default
- $active_modules = get_option( Modules::ACTIVE_MODULES_DB_KEY, [] );
- update_option( Modules::ACTIVE_MODULES_DB_KEY, array_unique( array_merge( $active_modules, ['catalog'] ) ) );
+ public static function set_default_modules() {
+ // Enable catalog module by default.
+ $active_modules = get_option( Modules::ACTIVE_MODULES_DB_KEY, array() );
+ update_option( Modules::ACTIVE_MODULES_DB_KEY, array_unique( array_merge( $active_modules, array( 'catalog' ) ) ) );
}
/**
* Set default settings
+ *
* @return void
*/
public function set_default_settings() {
- // Update shopping gurnal
- $all_settings = [
- 'is_disable_popup' => 'popup',
- 'enable_cart_checkout' => [],
- 'set_expiry_time' => 'Never',
- 'is_enable_multiple_product_enquiry' => ['is_enable_multiple_product_enquiry'],
- ];
+ // Update shopping gurnal.
+ $all_settings = array(
+ 'is_disable_popup' => 'popup',
+ 'enable_cart_checkout' => array(),
+ 'set_expiry_time' => 'Never',
+ 'is_enable_multiple_product_enquiry' => array( 'is_enable_multiple_product_enquiry' ),
+ );
update_option( 'catalogx_all_settings_settings', $all_settings );
-
- $email_settings = [
- 'additional_alert_email' => CatalogX()->admin_email,
- ];
+
+ $email_settings = array(
+ 'additional_alert_email' => CatalogX()->admin_email,
+ );
update_option( 'catalogx_enquiry_email_temp_settings', $email_settings );
- // Update pages settings
- $page_settings = [
- 'set_enquiry_cart_page' => intval( get_option( 'catalogx_enquiry_cart_page' ) ),
- 'set_request_quote_page' => intval( get_option( 'catalogx_request_quote_page' ) ),
- 'set_wholesale_products_page' => intval( get_option( 'wholesale_products_page' ) )
- ];
+ // Update pages settings.
+ $page_settings = array(
+ 'set_enquiry_cart_page' => intval( get_option( 'catalogx_enquiry_cart_page' ) ),
+ 'set_request_quote_page' => intval( get_option( 'catalogx_request_quote_page' ) ),
+ 'set_wholesale_products_page' => intval( get_option( 'wholesale_products_page' ) ),
+ );
update_option( 'catalogx_pages_settings', $page_settings );
-
- // Update form settings
- $free_form = [
- [
- 'key' => 'name',
- 'label' => 'Enter your name',
- 'active' => true,
- ],
- [
- 'key' => 'email',
- 'label' => 'Enter your email',
- 'active' => true,
- ],
- [ "key" => "phone" ],
- [ "key" => "address" ],
- [ "key" => "subject" ],
- [ "key" => "comment" ],
- [ "key" => "fileupload" ],
- [ "key" => "filesize-limit" ],
- [ "key" => "captcha" ],
- ];
-
- $pro_form = [
- [
- 'id' => 1,
- 'type' => 'title',
- 'label' => 'Enquiry Form',
- ],
- [
+
+ // Update form settings.
+ $free_form = array(
+ array(
+ 'key' => 'name',
+ 'label' => 'Enter your name',
+ 'active' => true,
+ ),
+ array(
+ 'key' => 'email',
+ 'label' => 'Enter your email',
+ 'active' => true,
+ ),
+ array( 'key' => 'phone' ),
+ array( 'key' => 'address' ),
+ array( 'key' => 'subject' ),
+ array( 'key' => 'comment' ),
+ array( 'key' => 'fileupload' ),
+ array( 'key' => 'filesize-limit' ),
+ array( 'key' => 'captcha' ),
+ );
+
+ $pro_form = array(
+ array(
+ 'id' => 1,
+ 'type' => 'title',
+ 'label' => 'Enquiry Form',
+ ),
+ array(
'id' => 2,
'type' => 'text',
'label' => 'Enter your name',
'required' => true,
'placeholder' => 'I am default place holder',
'name' => 'name',
- 'not_editable' => true
- ],
- [
+ 'not_editable' => true,
+ ),
+ array(
'id' => 3,
'type' => 'email',
'label' => 'Enter your email',
'required' => true,
'placeholder' => 'I am default place holder',
'name' => 'email',
- 'not_editable' => true
- ],
- ];
+ 'not_editable' => true,
+ ),
+ );
- $form_settings = [
- 'formsettings' => [
+ $form_settings = array(
+ 'formsettings' => array(
'formfieldlist' => $pro_form,
- 'butttonsetting' => [],
- ],
- 'freefromsetting' => $free_form,
- ];
+ 'butttonsetting' => array(),
+ ),
+ 'freefromsetting' => $free_form,
+ );
update_option( 'catalogx_enquiry_form_customization_settings', $form_settings );
- $wholesale_form = [
- [
- 'id' => 1,
- 'type' => 'title',
- 'label' => 'Wholesale Form',
- ],
- [
+ $wholesale_form = array(
+ array(
+ 'id' => 1,
+ 'type' => 'title',
+ 'label' => 'Wholesale Form',
+ ),
+ array(
'id' => 2,
'type' => 'text',
'label' => 'Enter your name',
'required' => true,
'placeholder' => 'I am default place holder',
'name' => 'name',
- 'not_editable' => true
- ],
- [
+ 'not_editable' => true,
+ ),
+ array(
'id' => 3,
'type' => 'email',
'label' => 'Enter your email',
'required' => true,
'placeholder' => 'I am default place holder',
'name' => 'email',
- 'not_editable' => true
- ],
- ];
+ 'not_editable' => true,
+ ),
+ );
- $wholesale_from_settings = [
- 'wholesale_from_settings' => [
+ $wholesale_from_settings = array(
+ 'wholesale_from_settings' => array(
'formfieldlist' => $wholesale_form,
- 'butttonsetting' => [],
- ],
- ];
+ 'butttonsetting' => array(),
+ ),
+ );
update_option( 'catalogx_wholesale_registration_settings', $wholesale_from_settings );
}
- // this function is for default migration run
+ /**
+ * Run default migration tasks.
+ *
+ * @return void
+ */
public function run_default_migration() {
- // Migration by specific version controll
+ // Migration by specific version controll.
if ( version_compare( self::$previous_version, '6.0.7', '<' ) ) {
+ // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.SchemaChange
global $wpdb;
$column_exists = $wpdb->get_results(
$wpdb->prepare(
- "SHOW COLUMNS FROM `{$wpdb->prefix}" . Utill::TABLES[ 'rule' ] . "` LIKE %s",
+ "SHOW COLUMNS FROM `{$wpdb->prefix}" . Utill::TABLES['rule'] . '` LIKE %s',
'brand_id'
)
- );
- if (empty($column_exists)) {
+ );
+ if ( empty( $column_exists ) ) {
$wpdb->query(
- "ALTER TABLE `{$wpdb->prefix}" . Utill::TABLES[ 'rule' ] . "`
- ADD COLUMN brand_id bigint(20);"
+ "ALTER TABLE `{$wpdb->prefix}" . Utill::TABLES['rule'] . '`
+ ADD COLUMN brand_id bigint(20);'
);
}
+ // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.SchemaChange
- $previous_enquiry_catalog_customization_settings = get_option( 'catalogx_enquiry-catalog-customization_settings', [] );
- update_option( 'catalogx_enquiry_catalog_customization_settings', $previous_enquiry_catalog_customization_settings );
-
- $previous_all_settings_settings = get_option( 'catalogx_all-settings_settings', [] );
- update_option( 'catalogx_all_settings_settings', $previous_all_settings_settings );
-
- $previous_enquiry_quote_exclusion_settings = get_option( 'catalogx_enquiry-quote-exclusion_settings', [] );
- update_option( 'catalogx_enquiry_quote_exclusion_settings', $previous_enquiry_quote_exclusion_settings );
-
- $previous_enquiry_form_customization_settings = get_option( 'catalogx_enquiry-form-customization_settings', [] );
- update_option( 'catalogx_enquiry_form_customization_settings', $previous_enquiry_form_customization_settings );
-
- $previous_enquiry_email_temp_settings = get_option( 'catalogx_enquiry-email-temp_settings', [] );
- update_option( 'catalogx_enquiry_email_temp_settings', $previous_enquiry_email_temp_settings );
-
- $previous_wholesale_registration_settings = get_option( 'catalogx_wholesale-registration_settings', [] );
- update_option( 'catalogx_wholesale_registration_settings', $previous_wholesale_registration_settings );
-
-
- delete_option('catalogx_enquiry-catalog-customization_settings');
- delete_option('catalogx_all-settings_settings');
- delete_option('catalogx_enquiry-quote-exclusion_settings');
- delete_option('catalogx_enquiry-form-customization_settings');
- delete_option('catalogx_enquiry-email-temp_settings');
- delete_option('catalogx_wholesale-registration_settings');
+ $previous_enquiry_catalog_customization_settings = get_option( 'catalogx_enquiry-catalog-customization_settings', array() );
+ if ( ! empty( $previous_enquiry_catalog_customization_settings ) ) {
+ update_option( 'catalogx_enquiry_catalog_customization_settings', $previous_enquiry_catalog_customization_settings );
+ delete_option( 'catalogx_enquiry-catalog-customization_settings' );
+ }
+ $previous_all_settings_settings = get_option( 'catalogx_all-settings_settings', array() );
+ if ( ! empty( $previous_all_settings_settings ) ) {
+ update_option( 'catalogx_all_settings_settings', $previous_all_settings_settings );
+ delete_option( 'catalogx_all-settings_settings' );
+ }
+ $previous_enquiry_quote_exclusion_settings = get_option( 'catalogx_enquiry-quote-exclusion_settings', array() );
+ if ( ! empty( $previous_enquiry_quote_exclusion_settings ) ) {
+ update_option( 'catalogx_enquiry_quote_exclusion_settings', $previous_enquiry_quote_exclusion_settings );
+ delete_option( 'catalogx_enquiry-quote-exclusion_settings' );
+ }
+ $previous_enquiry_form_customization_settings = get_option( 'catalogx_enquiry-form-customization_settings', array() );
+ if ( ! empty( $previous_enquiry_form_customization_settings ) ) {
+ update_option( 'catalogx_enquiry_form_customization_settings', $previous_enquiry_form_customization_settings );
+ delete_option( 'catalogx_enquiry-form-customization_settings' );
+ }
+ $previous_enquiry_email_temp_settings = get_option( 'catalogx_enquiry-email-temp_settings', array() );
+ if ( ! empty( $previous_enquiry_email_temp_settings ) ) {
+ update_option( 'catalogx_enquiry_email_temp_settings', $previous_enquiry_email_temp_settings );
+ delete_option( 'catalogx_enquiry-email-temp_settings' );
+ }
+ $previous_wholesale_registration_settings = get_option( 'catalogx_wholesale-registration_settings', array() );
+ if ( ! empty( $previous_wholesale_registration_settings ) ) {
+ update_option( 'catalogx_wholesale_registration_settings', $previous_wholesale_registration_settings );
+ delete_option( 'catalogx_wholesale-registration_settings' );
+ }
}
}
+ /**
+ * Migrate old Catalog Enquiry data and settings to CatalogX.
+ *
+ * @return void
+ */
public function migrate_catalog_enquiry_to_catalogx() {
- // module migration
- $previous_settings = get_option( 'mvx_catalog_general_tab_settings', [] );
+ // module migration.
+ $previous_settings = get_option( 'mvx_catalog_general_tab_settings', array() );
- // Enable enquiry module based on previous setting
- if ( isset( $previous_settings[ 'is_enable_enquiry' ] ) && reset($previous_settings[ 'is_enable_enquiry' ]) === 'is_enable_enquiry' ) {
- $active_modules = get_option( Modules::ACTIVE_MODULES_DB_KEY, [] );
- update_option( Modules::ACTIVE_MODULES_DB_KEY, array_unique( array_merge( $active_modules, ['enquiry'] ) ) );
+ // Enable enquiry module based on previous setting.
+ if ( isset( $previous_settings['is_enable_enquiry'] ) && reset( $previous_settings['is_enable_enquiry'] ) === 'is_enable_enquiry' ) {
+ $active_modules = get_option( Modules::ACTIVE_MODULES_DB_KEY, array() );
+ update_option( Modules::ACTIVE_MODULES_DB_KEY, array_unique( array_merge( $active_modules, array( 'enquiry' ) ) ) );
}
- // migrate all enquiry and details from post table to enquiry table
+ // migrate all enquiry and details from post table to enquiry table.
$this->migrate_database_table();
- // migrate all vendor settings
+ // migrate all vendor settings.
$this->migrate_vendor_settings();
-
- // migrate setttings
- $this->migrate_old_settings();
+ // migrate setttings.
+ $this->migrate_old_settings();
}
-
+
/**
- * Migrate database
+ * Migrate database
+ *
* @return void
*/
public function migrate_database_table() {
global $wpdb;
try {
- // Get enquiry post and post meta
+ // Get enquiry post and post meta.
+ // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
$enquirys_datas = $wpdb->get_results(
"SELECT p.ID as id,
p.post_author as user_id,
@@ -374,24 +413,25 @@ public function migrate_database_table() {
);
foreach ( $enquirys_datas as $id => $enquiry ) {
- $product_ids = $enquiry[ 'product_ids' ];
- $product_quantitys = $enquiry[ 'product_quantitys' ];
+ $product_ids = $enquiry['product_ids'];
+ $product_quantitys = $enquiry['product_quantitys'];
+ // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
$wpdb->insert(
"{$wpdb->prefix}" . Utill::TABLES['enquiry'],
- [
- 'id' => $enquiry[ 'id' ],
- 'user_id' => $enquiry[ 'user_id' ],
- 'user_name' => $enquiry[ 'username' ],
- 'user_email' => $enquiry[ 'useremail' ],
- 'user_additional_fields' => $enquiry[ 'additional_fields' ],
- 'date' => $enquiry[ 'date' ],
- 'product_info' => serialize([ $product_ids => $product_quantitys ]),
- ]
+ array(
+ 'id' => $enquiry['id'],
+ 'user_id' => $enquiry['user_id'],
+ 'user_name' => $enquiry['username'],
+ 'user_email' => $enquiry['useremail'],
+ 'user_additional_fields' => $enquiry['additional_fields'],
+ 'date' => $enquiry['date'],
+ 'product_info' => wp_json_encode( array( $product_ids => $product_quantitys ) ),
+ )
);
- // Delete the posts
- wp_delete_post( $enquiry[ 'id' ], false );
+ // Delete the posts.
+ wp_delete_post( $enquiry['id'], false );
}
} catch ( \Exception $e ) {
Utill::log( $e->getMessage() );
@@ -399,347 +439,363 @@ public function migrate_database_table() {
}
/**
- * Migrate vendor settings
+ * Migrate vendor settings
+ *
* @return void
*/
public function migrate_vendor_settings() {
$vendors = get_users( array( 'role' => 'dc_vendor' ) );
foreach ( $vendors as $vendor ) {
- // Check if the vendor has the meta key '_mvx_vendor_catalog_settings'
+ // Check if the vendor has the meta key '_mvx_vendor_catalog_settings'.
$catalogx_vendor_settings = get_user_meta( $vendor->ID, '_mvx_vendor_catalog_settings', true );
if ( ! empty( $catalogx_vendor_settings['woocommerce_product_vendor_list'] ) && is_array( $catalogx_vendor_settings['woocommerce_product_vendor_list'] ) ) {
$new_product_list = array();
- $index = 0;
-
+ $index = 0;
+
foreach ( $catalogx_vendor_settings['woocommerce_product_vendor_list'] as $product_id ) {
- // Get the product title (assuming these are product IDs)
+ // Get the product title (assuming these are product IDs).
$product = wc_get_product( $product_id );
-
+
if ( $product ) {
- // Create the new format for each product
+ // Create the new format for each product.
$new_product_list[] = array(
'value' => $product_id,
- 'label' => $product->get_name(), // Fetch the product name
+ 'label' => $product->get_name(), // Fetch the product name.
'index' => $index,
);
- $index++;
+ ++$index;
}
}
}
if ( ! empty( $catalogx_vendor_settings['woocommerce_category_vendor_list'] ) && is_array( $catalogx_vendor_settings['woocommerce_category_vendor_list'] ) ) {
$new_category_list = array();
- $index = 0;
-
+ $index = 0;
+
foreach ( $catalogx_vendor_settings['woocommerce_category_vendor_list'] as $category_id ) {
- // Get the category name using the category ID
+ // Get the category name using the category ID.
$category = get_term( $category_id, 'product_cat' ); // 'product_cat' is the WooCommerce category taxonomy
-
+
if ( $category ) {
- // Create the new format for each category
+ // Create the new format for each category.
$new_category_list[] = array(
'value' => $category_id,
- 'label' => $category->name, // Fetch the category name
+ 'label' => $category->name, // Fetch the category name.
'index' => $index,
);
- $index++;
+ ++$index;
}
}
}
- // If the meta key does not exist or is empty, create it with default values
- if ( !empty( $catalogx_vendor_settings ) ) {
+ // If the meta key does not exist or is empty, create it with default values.
+ if ( ! empty( $catalogx_vendor_settings ) ) {
$new_catalogx_vendor_settings = array(
- 'selected_email_tpl' => $catalogx_vendor_settings['selected_email_tpl'] ? $catalogx_vendor_settings['selected_email_tpl'] : '',
- 'woocommerce_product_list' => $new_product_list,
+ 'selected_email_tpl' => $catalogx_vendor_settings['selected_email_tpl'] ? $catalogx_vendor_settings['selected_email_tpl'] : '',
+ 'woocommerce_product_list' => $new_product_list,
'woocommerce_category_list' => $new_category_list,
);
- // Update user meta with default catalog settings
+ // Update user meta with default catalog settings.
update_user_meta( $vendor->ID, 'vendor_enquiry_settings', $new_catalogx_vendor_settings );
}
}
}
/**
- * Migrate old catalog settings
+ * Migrate old catalog settings
+ *
* @return void
*/
- public function migrate_old_settings() {
- $previous_general_settings = get_option( 'mvx_catalog_general_tab_settings', [] );
- $previous_button_settings = get_option( 'mvx_catalog_button_appearance_tab_settings', [] );
-
- // Update product page builder
- $page_builder_setting = [
- 'hide_product_price' => !empty($previous_general_settings[ 'is_remove_price_free' ]) ? true : false,
- 'additional_input' => $previous_general_settings[ 'replace_text_in_price' ] ?? '',
- 'enquiry_button' => [
- 'button_text_color' => !empty($previous_button_settings['custom_text_color']) ? $previous_button_settings['custom_text_color'] : '',
- 'button_background_color_onhover' => !empty($previous_button_settings['custom_hover_background_color']) ? $previous_button_settings['custom_hover_background_color'] : '',
- 'button_text_color_onhover' => !empty($previous_button_settings['custom_hover_text_color']) ? $previous_button_settings['custom_hover_text_color'] : '',
- 'button_border_color' => !empty($previous_button_settings['custom_border_color']) ? $previous_button_settings['custom_border_color'] : '',
- 'button_border_size' => !empty($previous_button_settings['custom_border_size']) ? $previous_button_settings['custom_border_size'] : '',
- 'button_border_radious' => !empty($previous_button_settings['custom_border_radius']) ? $previous_button_settings['custom_border_radius'] : '',
- 'button_text' => !empty($previous_button_settings['enquiry_button_text']) ? $previous_button_settings['enquiry_button_text'] : '',
- 'button_font_size' => !empty($previous_button_settings['custom_font_size']) ? $previous_button_settings['custom_font_size'] : '',
- ]
- ];
+ public function migrate_old_settings() {
+ $previous_general_settings = get_option( 'mvx_catalog_general_tab_settings', array() );
+ $previous_button_settings = get_option( 'mvx_catalog_button_appearance_tab_settings', array() );
+
+ // Update product page builder.
+ $page_builder_setting = array(
+ 'hide_product_price' => ! empty( $previous_general_settings['is_remove_price_free'] ) ? true : false,
+ 'additional_input' => $previous_general_settings['replace_text_in_price'] ?? '',
+ 'enquiry_button' => array(
+ 'button_text_color' => ! empty( $previous_button_settings['custom_text_color'] ) ? $previous_button_settings['custom_text_color'] : '',
+ 'button_background_color_onhover' => ! empty( $previous_button_settings['custom_hover_background_color'] ) ? $previous_button_settings['custom_hover_background_color'] : '',
+ 'button_text_color_onhover' => ! empty( $previous_button_settings['custom_hover_text_color'] ) ? $previous_button_settings['custom_hover_text_color'] : '',
+ 'button_border_color' => ! empty( $previous_button_settings['custom_border_color'] ) ? $previous_button_settings['custom_border_color'] : '',
+ 'button_border_size' => ! empty( $previous_button_settings['custom_border_size'] ) ? $previous_button_settings['custom_border_size'] : '',
+ 'button_border_radious' => ! empty( $previous_button_settings['custom_border_radius'] ) ? $previous_button_settings['custom_border_radius'] : '',
+ 'button_text' => ! empty( $previous_button_settings['enquiry_button_text'] ) ? $previous_button_settings['enquiry_button_text'] : '',
+ 'button_font_size' => ! empty( $previous_button_settings['custom_font_size'] ) ? $previous_button_settings['custom_font_size'] : '',
+ ),
+ );
update_option( 'catalogx_enquiry-catalog-customization_settings', $page_builder_setting );
-
- // Update shopping gurnal
- $all_settings = [
- 'is_enable_out_of_stock' => $previous_general_settings[ 'is_enable_out_of_stock' ] ?? [],
- 'enquiry_user_permission' => is_array($previous_general_settings['for_user_type']) && $previous_general_settings[ 'for_user_type' ]['value'] == '1' ? ['enquiry_logged_out'] : [],
- 'is_page_redirect' => $previous_general_settings[ 'is_page_redirect' ] ?? [],
- 'redirect_page_id' => $previous_general_settings[ 'redirect_page_id' ] ? $previous_general_settings[ 'redirect_page_id' ]['value'] : '',
- 'is_disable_popup' => !empty($previous_general_settings[ 'is_disable_popup' ]) ? 'inline' : 'popup',
- 'enable_cart_checkout' => [],
- 'set_expiry_time' => 'Never',
- 'is_enable_multiple_product_enquiry' => $previous_general_settings[ 'is_enable_multiple_product_enquiry' ] ?? ['is_enable_multiple_product_enquiry'],
- ];
+ // Update shopping gurnal.
+ $all_settings = array(
+ 'is_enable_out_of_stock' => $previous_general_settings['is_enable_out_of_stock'] ?? array(),
+ 'enquiry_user_permission' => is_array( $previous_general_settings['for_user_type'] ) && '1' === $previous_general_settings['for_user_type']['value'] ? array( 'enquiry_logged_out' ) : array(),
+ 'is_page_redirect' => $previous_general_settings['is_page_redirect'] ?? array(),
+ 'redirect_page_id' => $previous_general_settings['redirect_page_id'] ? $previous_general_settings['redirect_page_id']['value'] : '',
+ 'is_disable_popup' => ! empty( $previous_general_settings['is_disable_popup'] ) ? 'inline' : 'popup',
+ 'enable_cart_checkout' => array(),
+ 'set_expiry_time' => 'Never',
+ 'is_enable_multiple_product_enquiry' => $previous_general_settings['is_enable_multiple_product_enquiry'] ?? array( 'is_enable_multiple_product_enquiry' ),
+ );
update_option( 'catalogx_all-settings_settings', $all_settings );
-
- $email_settings = [
- 'additional_alert_email' => !empty($previous_general_settings[ 'other_emails' ]) ? $previous_general_settings[ 'other_emails' ] : get_option( 'admin_email' ),
- ];
- if (!empty($previous_general_settings['is_other_admin_mail'])) {
+ $email_settings = array(
+ 'additional_alert_email' => ! empty( $previous_general_settings['other_emails'] ) ? $previous_general_settings['other_emails'] : get_option( 'admin_email' ),
+ );
+
+ if ( ! empty( $previous_general_settings['is_other_admin_mail'] ) ) {
$admin_email = CatalogX()->admin_email;
-
- // Convert the string into an array, remove the admin email, and convert back to a string
- $emails_array = array_map('trim', explode(',', $email_settings['additional_alert_email']));
- $emails_array = array_diff($emails_array, [$admin_email]);
- $email_settings['additional_alert_email'] = implode(', ', $emails_array);
+
+ // Convert the string into an array, remove the admin email, and convert back to a string.
+ $emails_array = array_map( 'trim', explode( ',', $email_settings['additional_alert_email'] ) );
+ $emails_array = array_diff( $emails_array, array( $admin_email ) );
+ $email_settings['additional_alert_email'] = implode( ', ', $emails_array );
}
update_option( 'catalogx_enquiry-email-temp_settings', $email_settings );
- // Update pages settings
- $page_settings = [
- 'set_enquiry_cart_page' => intval( get_option( 'catalogx_enquiry_cart_page' ) ),
- 'set_request_quote_page' => intval( get_option( 'catalogx_request_quote_page' ) ),
- 'set_wholesale_products_page' => intval( get_option( 'wholesale_products_page' ) )
- ];
+ // Update pages settings.
+ $page_settings = array(
+ 'set_enquiry_cart_page' => intval( get_option( 'catalogx_enquiry_cart_page' ) ),
+ 'set_request_quote_page' => intval( get_option( 'catalogx_request_quote_page' ) ),
+ 'set_wholesale_products_page' => intval( get_option( 'wholesale_products_page' ) ),
+ );
update_option( 'catalogx_pages_settings', $page_settings );
-
- $tool_settings = [
- 'custom_css_product_page' => !empty($previous_button_settings[ 'custom_css_product_page' ]) ? $previous_button_settings[ 'custom_css_product_page' ] : '',
- ];
+
+ $tool_settings = array(
+ 'custom_css_product_page' => ! empty( $previous_button_settings['custom_css_product_page'] ) ? $previous_button_settings['custom_css_product_page'] : '',
+ );
update_option( 'catalogx_tools_settings', $tool_settings );
-
- // Update form settings
-
- // Free form migration
- $previous_free_from_setting = get_option( 'mvx_catalog_enquiry_form_tab_settings', [] );
-
- $free_form = [
- [
- 'key' => 'name',
- 'label' => 'Enter your name',
- 'active' => true,
- ],
- [
- 'key' => 'email',
- 'label' => 'Enter your email',
- 'active' => true,
- ],
- [ "key" => "phone" ],
- [ "key" => "address" ],
- [ "key" => "subject" ],
- [ "key" => "comment" ],
- [ "key" => "fileupload" ],
- [ "key" => "filesize-limit" ],
- [ "key" => "captcha" ],
- ];
-
-
- $previous_free_from = $previous_free_from_setting[ 'enquiry_form_fileds' ];
+
+ // Update form settings.
+
+ // Free form migration.
+ $previous_free_from_setting = get_option( 'mvx_catalog_enquiry_form_tab_settings', array() );
+
+ $free_form = array(
+ array(
+ 'key' => 'name',
+ 'label' => 'Enter your name',
+ 'active' => true,
+ ),
+ array(
+ 'key' => 'email',
+ 'label' => 'Enter your email',
+ 'active' => true,
+ ),
+ array( 'key' => 'phone' ),
+ array( 'key' => 'address' ),
+ array( 'key' => 'subject' ),
+ array( 'key' => 'comment' ),
+ array( 'key' => 'fileupload' ),
+ array( 'key' => 'filesize-limit' ),
+ array( 'key' => 'captcha' ),
+ );
+
+ $previous_free_from = $previous_free_from_setting['enquiry_form_fileds'];
if ( is_array( $previous_free_from ) ) {
-
$previous_free_from_keys = array_column( $previous_free_from, 0 );
- $free_form = array_map( function ( $form ) use ( $previous_free_from, $previous_free_from_keys ) {
-
- // Get label key and active status key
- $label_key = self::FREE_FORM_MAP[ $form[ 'key' ] ];
- $active_key = "{$label_key}_checkbox";
+ $free_form = array_map(
+ function ( $form ) use ( $previous_free_from, $previous_free_from_keys ) {
- $label_index = array_search( $label_key, $previous_free_from_keys );
- $active_index = array_search( $active_key, $previous_free_from_keys );
+ // Get label key and active status key.
+ $label_key = self::FREE_FORM_MAP[ $form['key'] ];
+ $active_key = "{$label_key}_checkbox";
- $label = $form[ 'label' ] ?? '';
- $active = $form[ 'active' ] ?? false;
+ $label_index = array_search( $label_key, $previous_free_from_keys, true );
+ $active_index = array_search( $active_key, $previous_free_from_keys, true );
- $label = $label_index ? $previous_free_from[ $label_index ][ 1 ] : $label;
- $active = $active_index ? $previous_free_from[ $active_index ][ 1 ] : $active;
+ $label = $form['label'] ?? '';
+ $active = $form['active'] ?? false;
- return [
- 'key' => $form[ 'key' ],
- 'label' => $label,
- 'active' => $active,
- ];
+ $label = $label_index ? $previous_free_from[ $label_index ][1] : $label;
+ $active = $active_index ? $previous_free_from[ $active_index ][1] : $active;
- }, $free_form );
+ return array(
+ 'key' => $form['key'],
+ 'label' => $label,
+ 'active' => $active,
+ );
+ },
+ $free_form
+ );
}
- // Pro form migration
- $previous_pro_from_setting = get_option( 'mvx_catalog_pro_enquiry_form_data', [] );
-
- if ( !empty($previous_pro_from_setting) ) {
- $pro_form = array_map( function ( $form ) {
- return [
- ...$form,
- 'name' => $form[ 'name' ],
- 'type' => self::PRO_FORM_TYPE_MAP[ $form[ 'type' ] ] ?? $form[ 'type' ],
- ];
- }, $previous_pro_from_setting );
+ // Pro form migration.
+ $previous_pro_from_setting = get_option( 'mvx_catalog_pro_enquiry_form_data', array() );
+
+ if ( ! empty( $previous_pro_from_setting ) ) {
+ $pro_form = array_map(
+ function ( $form ) {
+ return array(
+ ...$form,
+ 'name' => $form['name'],
+ 'type' => self::PRO_FORM_TYPE_MAP[ $form['type'] ] ?? $form['type'],
+ );
+ },
+ $previous_pro_from_setting
+ );
} else {
- $pro_form = [
- [
- 'id' => 1,
- 'type' => 'title',
- 'label' => 'Enquiry Form',
- ],
- [
+ $pro_form = array(
+ array(
+ 'id' => 1,
+ 'type' => 'title',
+ 'label' => 'Enquiry Form',
+ ),
+ array(
'id' => 2,
'type' => 'text',
'label' => 'Enter your name',
'required' => true,
'placeholder' => 'I am default place holder',
'name' => 'name',
- 'not_editable' => true
- ],
- [
+ 'not_editable' => true,
+ ),
+ array(
'id' => 3,
'type' => 'email',
'label' => 'Enter your email',
'required' => true,
'placeholder' => 'I am default place holder',
'name' => 'email',
- 'not_editable' => true
- ],
- ];
+ 'not_editable' => true,
+ ),
+ );
}
- $form_settings = [
- 'formsettings' => [
+ $form_settings = array(
+ 'formsettings' => array(
'formfieldlist' => $pro_form,
- 'butttonsetting' => [],
- ],
- 'freefromsetting' => $free_form,
- ];
+ 'butttonsetting' => array(),
+ ),
+ 'freefromsetting' => $free_form,
+ );
update_option( 'catalogx_enquiry-form-customization_settings', $form_settings );
- $wholesale_form = [
- [
- 'id' => 1,
- 'type' => 'title',
- 'label' => 'Wholesale Form',
- ],
- [
+ $wholesale_form = array(
+ array(
+ 'id' => 1,
+ 'type' => 'title',
+ 'label' => 'Wholesale Form',
+ ),
+ array(
'id' => 2,
'type' => 'text',
'label' => 'Enter your name',
'required' => true,
'placeholder' => 'I am default place holder',
'name' => 'name',
- 'not_editable' => true
- ],
- [
+ 'not_editable' => true,
+ ),
+ array(
'id' => 3,
'type' => 'email',
'label' => 'Enter your email',
'required' => true,
'placeholder' => 'I am default place holder',
'name' => 'email',
- 'not_editable' => true
- ],
- ];
+ 'not_editable' => true,
+ ),
+ );
- $wholesale_from_settings = [
- 'wholesale_from_settings' => [
+ $wholesale_from_settings = array(
+ 'wholesale_from_settings' => array(
'formfieldlist' => $wholesale_form,
- 'butttonsetting' => [],
- ],
- ];
+ 'butttonsetting' => array(),
+ ),
+ );
update_option( 'catalogx_wholesale-registration_settings', $wholesale_from_settings );
- // Update exclusion settings
- $previous_exclusion_settings = get_option( 'mvx_catalog_exclusion_tab_settings', [] );
-
- // Prepare exclusion user list
- $exclusion_user_list = $previous_exclusion_settings[ 'woocommerce_user_list' ];
- $exclusion_user_list = is_array( $exclusion_user_list ) ? $exclusion_user_list : [];
-
- $exclusion_user_list = array_map(function ($user_list) {
- return [
- 'key' => $user_list[ 'value' ],
- 'label' => $user_list[ 'label' ],
- 'value' => $user_list[ 'value' ],
- ];
- }, $exclusion_user_list );
-
- // Prepare user role list
- $exclusion_userroles_list = $previous_exclusion_settings[ 'woocommerce_userroles_list' ];
- $exclusion_userroles_list = is_array( $exclusion_userroles_list ) ? $exclusion_userroles_list : [];
-
- $exclusion_userroles_list = array_map(function ($user_list) {
- return [
- 'key' => $user_list[ 'value' ],
- 'label' => $user_list[ 'label' ],
- 'value' => $user_list[ 'value' ],
- ];
- }, $exclusion_userroles_list );
-
- // Prepare product list
- $exclusion_product_list = $previous_exclusion_settings[ 'woocommerce_product_list' ];
- $exclusion_product_list = is_array( $exclusion_product_list ) ? $exclusion_product_list : [];
-
- $exclusion_product_list = array_map(function ($user_list) {
- return [
- 'key' => $user_list[ 'value' ],
- 'label' => $user_list[ 'label' ],
- 'value' => $user_list[ 'value' ],
- ];
- }, $exclusion_product_list );
-
- // Prepare category list
- $exclusion_category_list = $previous_exclusion_settings[ 'woocommerce_category_list' ];
- $exclusion_category_list = is_array( $exclusion_category_list ) ? $exclusion_category_list : [];
-
- $exclusion_category_list = array_map( function ( $user_list ) {
- return [
- 'key' => $user_list[ 'value' ],
- 'label' => $user_list[ 'label' ],
- 'value' => $user_list[ 'value' ],
- ];
- }, $exclusion_category_list );
-
- $exclusion_settings = [
- 'catalog_exclusion_user_list' => $exclusion_user_list,
- 'enquiry_exclusion_user_list' => $exclusion_user_list,
-
- 'catalog_exclusion_userroles_list' => $exclusion_userroles_list,
- 'enquiry_exclusion_userroles_list' => $exclusion_userroles_list,
-
- 'enquiry_exclusion_product_list' => $exclusion_product_list,
- 'catalog_exclusion_product_list' => $exclusion_product_list,
-
- 'catalog_exclusion_category_list' => $exclusion_category_list,
- 'enquiry_exclusion_category_list' => $exclusion_category_list,
- ];
+ // Update exclusion settings.
+ $previous_exclusion_settings = get_option( 'mvx_catalog_exclusion_tab_settings', array() );
+
+ // Prepare exclusion user list.
+ $exclusion_user_list = $previous_exclusion_settings['woocommerce_user_list'];
+ $exclusion_user_list = is_array( $exclusion_user_list ) ? $exclusion_user_list : array();
+
+ $exclusion_user_list = array_map(
+ function ( $user_list ) {
+ return array(
+ 'key' => $user_list['value'],
+ 'label' => $user_list['label'],
+ 'value' => $user_list['value'],
+ );
+ },
+ $exclusion_user_list
+ );
+
+ // Prepare user role list.
+ $exclusion_userroles_list = $previous_exclusion_settings['woocommerce_userroles_list'];
+ $exclusion_userroles_list = is_array( $exclusion_userroles_list ) ? $exclusion_userroles_list : array();
+
+ $exclusion_userroles_list = array_map(
+ function ( $user_list ) {
+ return array(
+ 'key' => $user_list['value'],
+ 'label' => $user_list['label'],
+ 'value' => $user_list['value'],
+ );
+ },
+ $exclusion_userroles_list
+ );
+
+ // Prepare product list.
+ $exclusion_product_list = $previous_exclusion_settings['woocommerce_product_list'];
+ $exclusion_product_list = is_array( $exclusion_product_list ) ? $exclusion_product_list : array();
+
+ $exclusion_product_list = array_map(
+ function ( $user_list ) {
+ return array(
+ 'key' => $user_list['value'],
+ 'label' => $user_list['label'],
+ 'value' => $user_list['value'],
+ );
+ },
+ $exclusion_product_list
+ );
+
+ // Prepare category list.
+ $exclusion_category_list = $previous_exclusion_settings['woocommerce_category_list'];
+ $exclusion_category_list = is_array( $exclusion_category_list ) ? $exclusion_category_list : array();
+
+ $exclusion_category_list = array_map(
+ function ( $user_list ) {
+ return array(
+ 'key' => $user_list['value'],
+ 'label' => $user_list['label'],
+ 'value' => $user_list['value'],
+ );
+ },
+ $exclusion_category_list
+ );
+
+ $exclusion_settings = array(
+ 'catalog_exclusion_user_list' => $exclusion_user_list,
+ 'enquiry_exclusion_user_list' => $exclusion_user_list,
+
+ 'catalog_exclusion_userroles_list' => $exclusion_userroles_list,
+ 'enquiry_exclusion_userroles_list' => $exclusion_userroles_list,
+
+ 'enquiry_exclusion_product_list' => $exclusion_product_list,
+ 'catalog_exclusion_product_list' => $exclusion_product_list,
+
+ 'catalog_exclusion_category_list' => $exclusion_category_list,
+ 'enquiry_exclusion_category_list' => $exclusion_category_list,
+ );
update_option( 'catalogx_enquiry-quote-exclusion_settings', $exclusion_settings );
- // delete previous option from database
+ // delete previous option from database.
delete_option( 'mvx_catalog_general_tab_settings' );
delete_option( 'mvx_catalog_enquiry_form_tab_settings' );
delete_option( 'mvx_catalog_exclusion_tab_settings' );
@@ -751,4 +807,4 @@ public function migrate_old_settings() {
delete_option( 'woocommerce_catalog_enquiry_exclusion_settings' );
delete_option( 'woocommerce_catalog_enquiry_button_appearence_settings' );
}
-}
\ No newline at end of file
+}
diff --git a/classes/Modules.php b/classes/Modules.php
index 7a4d86c..5557e33 100644
--- a/classes/Modules.php
+++ b/classes/Modules.php
@@ -1,73 +1,93 @@
modules ) {
-
- $this->modules = apply_filters( 'catalogx_modules', [
- 'catalog' => [
- 'id' => 'catalog',
- 'module_file' => CatalogX()->plugin_path . 'modules/Catalog/Module.php',
- 'module_class' => 'CatalogX\Catalog\Module',
- ],
- 'enquiry' => [
- 'id' => 'enquiry',
- 'module_file' => CatalogX()->plugin_path . 'modules/Enquiry/Module.php',
- 'module_class' => 'CatalogX\Enquiry\Module',
- ],
- 'quote' => [
- 'id' => 'quote',
- 'module_file' => CatalogX()->plugin_path . 'modules/Quote/Module.php',
- 'module_class' => 'CatalogX\Quote\Module',
- ],
- ]);
+ $this->modules = apply_filters(
+ 'catalogx_modules',
+ array(
+ 'catalog' => array(
+ 'id' => 'catalog',
+ 'module_file' => CatalogX()->plugin_path . 'modules/Catalog/Module.php',
+ 'module_class' => 'CatalogX\Catalog\Module',
+ ),
+ 'enquiry' => array(
+ 'id' => 'enquiry',
+ 'module_file' => CatalogX()->plugin_path . 'modules/Enquiry/Module.php',
+ 'module_class' => 'CatalogX\Enquiry\Module',
+ ),
+ 'quote' => array(
+ 'id' => 'quote',
+ 'module_file' => CatalogX()->plugin_path . 'modules/Quote/Module.php',
+ 'module_class' => 'CatalogX\Quote\Module',
+ ),
+ )
+ );
}
return $this->modules;
@@ -75,21 +95,23 @@ public function get_all_modules() {
/**
* Get all active modules
+ *
* @return array
*/
public function get_active_modules() {
- // If active modules are loaded return it
+ // If active modules are loaded return it.
if ( $this->active_modules ) {
return $this->active_modules;
}
- $this->active_modules = CatalogX()->setting->get_option( self::ACTIVE_MODULES_DB_KEY, [] );
+ $this->active_modules = CatalogX()->setting->get_option( self::ACTIVE_MODULES_DB_KEY, array() );
return $this->active_modules;
}
/**
* Load all active modules
+ *
* @return void
*/
public function load_active_modules() {
@@ -100,7 +122,7 @@ public function load_active_modules() {
$license_active = Utill::is_khali_dabba();
$active_modules = $this->get_active_modules();
$all_modules = $this->get_all_modules();
- $activated_modules = [];
+ $activated_modules = array();
foreach ( $active_modules as $modules_id ) {
if ( ! isset( $all_modules[ $modules_id ] ) ) {
@@ -109,34 +131,33 @@ public function load_active_modules() {
$module = $all_modules[ $modules_id ];
-
- // Check if the module is available
+ // Check if the module is available.
if ( ! $this->is_module_available( $module, $license_active ) ) {
continue;
}
- // Store the module as active module
+ // Store the module as active module.
if ( file_exists( $module['module_file'] ) ) {
$activated_modules[] = $modules_id;
}
- // Activate the module
- if ( file_exists( $module['module_file'] ) && ! in_array( $modules_id, $this->container ) ) {
+ // Activate the module.
+ if ( file_exists( $module['module_file'] ) && ! in_array( $modules_id, $this->container, true ) ) {
require_once $module['module_file'];
- $module_class = $module['module_class'];
+ $module_class = $module['module_class'];
$this->container[ $modules_id ] = new $module_class();
/**
* Module activation hook
- *
+ *
* @param object $name module object
*/
do_action( 'catalogx_activated_module_' . $modules_id, $this->container[ $modules_id ] );
}
}
- // store activated module as active module
+ // store activated module as active module.
if ( $activated_modules !== $active_modules ) {
update_option( self::ACTIVE_MODULES_DB_KEY, $activated_modules );
}
@@ -146,20 +167,21 @@ public function load_active_modules() {
/**
* Check a perticular module is available or not.
- * @param array $module
- * @param bool $license_active
+ *
+ * @param array $module The module configuration array.
+ * @param bool $license_active Whether the license for pro modules is active.
* @return bool
*/
private function is_module_available( $module, $license_active ) {
$is_pro_module = $module['pro_module'] ?? false;
- // if it is free module
+ // if it is free module.
if ( ! $is_pro_module ) {
return true;
}
- // if it is pro module
- if( $is_pro_module && $license_active ) {
+ // if it is pro module.
+ if ( $is_pro_module && $license_active ) {
return true;
}
@@ -168,6 +190,7 @@ private function is_module_available( $module, $license_active ) {
/**
* Get list of all module's id
+ *
* @return array
*/
public function get_all_modules_ids() {
@@ -177,15 +200,16 @@ public function get_all_modules_ids() {
/**
* Get all available modules.
+ *
* @return array
*/
public function get_available_modules() {
$modules = $this->get_all_modules();
$license_active = Utill::is_khali_dabba();
- $available_modules = [];
+ $available_modules = array();
foreach ( $modules as $module_id => $module ) {
- // Check if the module is available
+ // Check if the module is available.
if ( ! $this->is_module_available( $module, $license_active ) ) {
continue;
}
@@ -200,7 +224,8 @@ public function get_available_modules() {
/**
* Activate modules
- * @param array $modules
+ *
+ * @param array $modules The module name to activate.
* @return array|mixed
*/
public function activate_modules( $modules ) {
@@ -219,14 +244,15 @@ public function activate_modules( $modules ) {
/**
* Defactivate modules.
- * @param array $modules
- * @return void
+ *
+ * @param array $modules The module name to deactivate.
+ * @return array
*/
public function deactivate_modules( $modules ) {
$active_modules = $this->get_active_modules();
foreach ( $modules as $module_id ) {
- $active_modules = array_diff( $active_modules, [ $module_id ] );
+ $active_modules = array_diff( $active_modules, array( $module_id ) );
}
$active_modules = array_values( $active_modules );
@@ -236,24 +262,27 @@ public function deactivate_modules( $modules ) {
update_option( self::ACTIVE_MODULES_DB_KEY, $this->active_modules );
add_action(
- 'shutdown', function () use ( $modules ) {
+ 'shutdown',
+ function () use ( $modules ) {
foreach ( $modules as $module_id ) {
/**
* Module deactivation hook
+ *
* @param object $module deactivated module object
*/
- do_action( 'catalogx_deactivated_module_' . $module_id, $this->container[$module_id] );
+ do_action( 'catalogx_deactivated_module_' . $module_id, $this->container[ $module_id ] );
}
}
);
return $this->active_modules;
}
-
+
/**
* Get a module is available or not.
- * @param mixed $module_id
- * @return true
+ *
+ * @param mixed $module_id The id of the module to check.
+ * @return bool
*/
public function is_available( $module_id ) {
$available_modules = $this->get_available_modules();
@@ -263,7 +292,8 @@ public function is_available( $module_id ) {
/**
* Check a module is active or not
- * @param mixed $module_id
+ *
+ * @param mixed $module_id The id of the module to check.
* @return bool
*/
public function is_active( $module_id ) {
@@ -271,4 +301,4 @@ public function is_active( $module_id ) {
return in_array( $module_id, $active_modules, true );
}
-}
\ No newline at end of file
+}
diff --git a/classes/Rest.php b/classes/Rest.php
index d8cb510..b0bc4ad 100644
--- a/classes/Rest.php
+++ b/classes/Rest.php
@@ -1,15 +1,23 @@
rest_namespace, '/settings', [
- 'methods' => 'POST',
- 'callback' => [ $this, 'set_settings' ],
- 'permission_callback' => [ $this, 'catalogx_permission' ]
- ] );
-
- // enable/disable the module
- register_rest_route( CatalogX()->rest_namespace, '/modules', [
- 'methods' => 'POST',
- 'callback' => [ $this, 'set_modules' ],
- 'permission_callback' => [ $this, 'catalogx_permission' ]
- ] );
-
- register_rest_route( CatalogX()->rest_namespace, '/tour', [
- [
- 'methods' => 'GET',
- 'callback' => [ $this, 'get_tour' ],
- 'permission_callback' => [ $this, 'catalogx_permission' ],
- ],
- [
- 'methods' => 'POST',
- 'callback' => [ $this, 'set_tour' ],
- 'permission_callback' => [ $this, 'catalogx_permission' ],
- ]
- ] );
-
- register_rest_route( CatalogX()->rest_namespace, '/buttons', [
- 'methods' => 'GET',
- 'callback' => [ $this, 'get_buttons' ],
- 'permission_callback' => [ $this, 'catalogx_permission' ],
- ]);
-
+ public function register_rest_apis() {
+
+ register_rest_route(
+ CatalogX()->rest_namespace,
+ '/settings',
+ array(
+ 'methods' => 'POST',
+ 'callback' => array( $this, 'set_settings' ),
+ 'permission_callback' => array( $this, 'catalogx_permission' ),
+ )
+ );
+
+ // enable/disable the module.
+ register_rest_route(
+ CatalogX()->rest_namespace,
+ '/modules',
+ array(
+ array(
+ 'methods' => 'POST',
+ 'callback' => array( $this, 'set_modules' ),
+ 'permission_callback' => array( $this, 'catalogx_permission' ),
+ ),
+ array(
+ 'methods' => 'GET',
+ 'callback' => array( $this, 'get_modules' ),
+ 'permission_callback' => array( $this, 'catalogx_permission' ),
+ ),
+ )
+ );
+
+ register_rest_route(
+ CatalogX()->rest_namespace,
+ '/tour',
+ array(
+ array(
+ 'methods' => 'GET',
+ 'callback' => array( $this, 'get_tour' ),
+ 'permission_callback' => array( $this, 'catalogx_permission' ),
+ ),
+ array(
+ 'methods' => 'POST',
+ 'callback' => array( $this, 'set_tour' ),
+ 'permission_callback' => array( $this, 'catalogx_permission' ),
+ ),
+ )
+ );
+
+ register_rest_route(
+ CatalogX()->rest_namespace,
+ '/buttons',
+ array(
+ 'methods' => 'GET',
+ 'callback' => array( $this, 'get_buttons' ),
+ 'permission_callback' => array( $this, 'catalogx_permission' ),
+ )
+ );
}
/**
- * get tour status
+ * Get tour status
+ *
* @return \WP_Error|\WP_REST_Response
*/
public function get_tour() {
- $status = CatalogX()->setting->get_option('catalogx_tour_active', false);
- return ['active' => $status];
+ $status = CatalogX()->setting->get_option( 'catalogx_tour_active', false );
+ return array( 'active' => $status );
}
-
+
/**
- * set tour status
- * @param mixed $request
+ * Set tour status
+ *
+ * active boolean required
+ * catalogx tour active or not
+ *
+ * @param \WP_REST_Request $request The REST request object.
* @return \WP_Error|\WP_REST_Response
*/
- // active boolean required
- // catalogx tour active or not
- public function set_tour($request) {
- update_option('catalogx_tour_active', $request->get_param( 'active' ));
- return ['success' => true];
+ public function set_tour( $request ) {
+ update_option( 'catalogx_tour_active', $request->get_param( 'active' ) );
+ return array( 'success' => true );
}
/**
* Save global settings
- * @param mixed $request
+ *
+ * setting array required
+ * all the settings of a particular id
+ * settingName string required
+ * Give the setting id
+ *
+ * @param \WP_REST_Request $request The REST request object.
* @return \WP_Error|\WP_REST_Response
*/
- // setting array required
- // all the settings of a particular id
- // settingName string required
- // Give the setting id
public function set_settings( $request ) {
- $all_details = [];
- $get_settings_data = $request->get_param( 'setting' );
- $settingsname = $request->get_param( 'settingName' );
- $settingsname = str_replace( '-', '_', 'catalogx_' . $settingsname . '_settings' );
- // save the settings in database
+ $all_details = array();
+ $get_settings_data = $request->get_param( 'setting' );
+ $settingsname = $request->get_param( 'settingName' );
+ $settingsname = str_replace( '-', '_', 'catalogx_' . $settingsname . '_settings' );
+
+ // save the settings in database.
CatalogX()->setting->update_option( $settingsname, $get_settings_data );
do_action( 'catalogx_settings_after_save', $settingsname, $get_settings_data );
- $all_details[ 'error' ] = __( 'Settings Saved', 'catalogx' );
+ $all_details['error'] = __( 'Settings Saved', 'catalogx' );
- //setup wizard settings
- $action = $request->get_param('action');
+ // setup wizard settings.
+ $action = $request->get_param( 'action' );
- if ($action == 'enquiry') {
- $display_option = $request->get_param('displayOption');
- $restrict_user = $request->get_param('restrictUserEnquiry');
- CatalogX()->setting->update_setting('is_disable_popup', $display_option, 'catalogx_all_settings_settings');
- CatalogX()->setting->update_setting('enquiry_user_permission', $restrict_user, 'catalogx_all_settings_settings');
+ if ( 'enquiry' === $action ) {
+ $display_option = $request->get_param( 'displayOption' );
+ $restrict_user = $request->get_param( 'restrictUserEnquiry' );
+ CatalogX()->setting->update_setting( 'is_disable_popup', $display_option, 'catalogx_all_settings_settings' );
+ CatalogX()->setting->update_setting( 'enquiry_user_permission', $restrict_user, 'catalogx_all_settings_settings' );
}
-
- if ($action == 'quote') {
- $restrict_user = $request->get_param('restrictUserQuote');
- CatalogX()->setting->update_setting('quote_user_permission', $restrict_user, 'catalogx_all_settings_settings');
+
+ if ( 'quote' === $action ) {
+ $restrict_user = $request->get_param( 'restrictUserQuote' );
+ CatalogX()->setting->update_setting( 'quote_user_permission', $restrict_user, 'catalogx_all_settings_settings' );
}
- return rest_ensure_response($all_details);
+ return rest_ensure_response( $all_details );
}
/**
* Manage module setting. Active or Deactive modules.
- * @param mixed $request
+ *
+ * id string required
+ * Give the module id
+ * action string required
+ * Give the action that is activate or deactivate
+ *
+ * @param \WP_REST_Request $request The REST request object.
* @return void
*/
- // id string required
- // Give the module id
- // action string required
- // Give the action that is activate or deactivate
public function set_modules( $request ) {
- $moduleId = $request->get_param( 'id' );
- $action = $request->get_param( 'action' );
+ $module_id = $request->get_param( 'id' );
+ $action = $request->get_param( 'action' );
- // Setup wizard module
- $modules = $request->get_param('modules');
- foreach ($modules as $module_id) {
- CatalogX()->modules->activate_modules([$module_id]);
+ // Setup wizard module.
+ $modules = $request->get_param( 'modules' );
+ foreach ( $modules as $module ) {
+ CatalogX()->modules->activate_modules( array( $module ) );
}
- // Handle the actions
+ // Handle the actions.
switch ( $action ) {
case 'activate':
- CatalogX()->modules->activate_modules([$moduleId]);
+ CatalogX()->modules->activate_modules( array( $module_id ) );
break;
-
+
default:
- CatalogX()->modules->deactivate_modules([$moduleId]);
+ CatalogX()->modules->deactivate_modules( array( $module_id ) );
break;
}
}
- public function get_buttons($request) {
- $product_id = $request->get_param('product_id');
- $button_type = $request->get_param('button_type');
+ /**
+ * Get the list of active CatalogX modules.
+ *
+ * @return array
+ */
+ public function get_modules() {
+ $modules_instance = new Modules();
+ return $modules_instance->get_active_modules();
+ }
+
+ /**
+ * Get the enquiry or quote button markup.
+ *
+ * @param \WP_REST_Request $request The REST request object.
+ * @return \WP_REST_Response The HTML response.
+ */
+ public function get_buttons( $request ) {
+ $product_id = $request->get_param( 'product_id' );
+ $button_type = $request->get_param( 'button_type' );
- // Start output buffering
+ // Start output buffering.
ob_start();
- if ($button_type == 'enquiry') {
- EnquiryModule::init()->frontend->add_enquiry_button(intval($product_id));
+ if ( 'enquiry' === $button_type ) {
+ EnquiryModule::init()->frontend->add_enquiry_button( intval( $product_id ) );
}
- if ($button_type == 'quote') {
- QuoteModule::init()->frontend->add_button_for_quote(intval($product_id));
+ if ( 'quote' === $button_type ) {
+ QuoteModule::init()->frontend->add_button_for_quote( intval( $product_id ) );
}
- do_action('catalogx_get_buttons', $button_type, $product_id);
+ do_action( 'catalogx_get_buttons', $button_type, $product_id );
- // Return the output
- return rest_ensure_response(['html' => ob_get_clean()]);
+ // Return the output.
+ return rest_ensure_response( array( 'html' => ob_get_clean() ) );
}
/**
* Catalog rest api permission functions
+ *
* @return bool
*/
public function catalogx_permission() {
- return true;
+ return current_user_can( 'manage_options' );
}
-
-}
\ No newline at end of file
+}
diff --git a/classes/Setting.php b/classes/Setting.php
index fce1a19..1f1439c 100644
--- a/classes/Setting.php
+++ b/classes/Setting.php
@@ -1,177 +1,194 @@
load_settings();
}
/**
* Load all setting from option table
- * @param mixed $fource
+ *
+ * @param bool $force Whether to force reload the settings even if already loaded.
* @return void
*/
- private function load_settings( $fource = true ) {
+ private function load_settings( $force = true ) {
- // If settings are loaded previously and not force to load
- if ( ! $fource && $this->settings ) {
+ // If settings are loaded previously and not force to load.
+ if ( ! $force && $this->settings ) {
return;
}
$setting_keys = $this->get_settings_keys();
- // Get all setting from option table
- foreach( $setting_keys as $key) {
- $this->settings[ $key ] = get_option( $key, [] );
+ // Get all setting from option table.
+ foreach ( $setting_keys as $key ) {
+ $this->settings[ $key ] = get_option( $key, array() );
}
}
/**
* Get all register setting key
- * @return array
+ *
+ * @return array
*/
private function get_settings_keys() {
- // Settings key are available
+ // Settings key are available.
if ( $this->settings_keys ) {
return $this->settings_keys;
}
/**
* Filter for register settings key's
+ *
* @var array setting keys
*/
- $this->settings_keys = apply_filters( 'catalogx_register_settings_keys', [
- 'catalogx_extra_settings',
- 'catalogx_enquiry_catalog_customization_settings',
- 'catalogx_all_settings_settings',
- 'catalogx_tools_settings',
- 'catalogx_pages_settings',
- 'catalogx_enquiry_quote_exclusion_settings',
- 'catalogx_enquiry_form_customization_settings',
- 'catalogx_enquiry_email_temp_settings',
- 'catalogx_wholesale_settings',
- 'catalogx_wholesale_registration_settings'
- ]);
+ $this->settings_keys = apply_filters(
+ 'catalogx_register_settings_keys',
+ array(
+ 'catalogx_extra_settings',
+ 'catalogx_enquiry_catalog_customization_settings',
+ 'catalogx_all_settings_settings',
+ 'catalogx_tools_settings',
+ 'catalogx_pages_settings',
+ 'catalogx_enquiry_quote_exclusion_settings',
+ 'catalogx_enquiry_form_customization_settings',
+ 'catalogx_enquiry_email_temp_settings',
+ 'catalogx_wholesale_settings',
+ 'catalogx_wholesale_registration_settings',
+ )
+ );
return $this->settings_keys;
}
/**
* Get the setting that was previously added.
- * If setting is not present it return defalult value
- * @param string $key setting key
- * @param string $default setting value
- * @param mixed $option_key option table's key
+ * If setting is not present it return defalult value
+ *
+ * @param string $key setting key.
+ * @param string $default_value setting value.
+ * @param mixed $option_key option table's key.
* @return mixed
*/
- public function get_setting( $key, $default = '', $option_key = null ) {
+ public function get_setting( $key, $default_value = '', $option_key = null ) {
- // If option key is not provided
+ // If option key is not provided.
if ( ! $option_key ) {
$option_key = $this->get_option_key( $key );
}
- $setting = $this->settings[ $option_key ] ?? [];
+ $setting = $this->settings[ $option_key ] ?? array();
- return $setting[ $key ] ?? $default;
+ return $setting[ $key ] ?? $default_value;
}
/**
* Update the setting that was already added.
- * @param string $key setting key
- * @param string $value setting value
- * @param string $option_key option table's key
+ *
+ * @param string $key setting key.
+ * @param string $value setting value.
+ * @param string $option_key option table's key.
* @return void
*/
public function update_setting( $key, $value, $option_key = null ) {
- // If option key is not provided
+ // If option key is not provided.
if ( ! $option_key ) {
$option_key = $this->get_option_key( $key );
}
- // Get the setting array from setting settings container
- $setting = $this->settings[ $option_key ] ?? [];
+ // Get the setting array from setting settings container.
+ $setting = $this->settings[ $option_key ] ?? array();
- // Update setting in setting container
- $setting[ $key ] = $value;
+ // Update setting in setting container.
+ $setting[ $key ] = $value;
$this->settings[ $option_key ] = $setting;
- // Update the setting in database
- update_option( $option_key, $setting );
+ // Update the setting in database.
+ update_option( $option_key, $setting );
}
/**
- * Get the option
- * @param string $key
- * @param mixed $default
+ * Get the option
+ *
+ * @param string $key The key for the setting to retrieve.
* @return mixed value
*/
- public function get_option( $key, $default = [] ) {
+ public function get_option( $key ) {
- // Check key exist in register settings keys
- if ( in_array( $key, $this->get_settings_keys() ) ) {
+ // Check key exist in register settings keys.
+ if ( in_array( $key, $this->get_settings_keys(), true ) ) {
return $this->settings[ $key ];
}
- return get_option( $key, [] );
+ return get_option( $key, array() );
}
/**
* Update the value in option table.
- * If key does't exist it create it.
- * @param string $key
- * @param mixed $value
+ * If key doesn't exist it create it.
+ *
+ * @param string $key The option key to update.
+ * @param mixed $value The value to set for the given key.
* @return void
*/
public function update_option( $key, $value ) {
-
- // Check key exist in register settings keys
- if ( in_array( $key, $this->get_settings_keys() ) ) {
-
- // Update the container
+
+ // Check key exist in register settings keys.
+ if ( in_array( $key, $this->get_settings_keys(), true ) ) {
+
+ // Update the container.
$this->settings[ $key ] = $value;
}
- // Update the option
+ // Update the option.
update_option( $key, $value );
}
/**
* Find option key from setting container
- * @param mixed $key setting key
+ *
+ * @param mixed $key setting key.
* @return string
*/
private function get_option_key( $key ) {
- foreach ( $this->settings as $option_key => $setting ) {
+ foreach ( $this->settings as $option_key => $setting ) {
// Key exist in a particular setting.
if ( is_array( $setting ) && array_key_exists( $key, $setting ) ) {
return $option_key;
@@ -180,4 +197,4 @@ private function get_option_key( $key ) {
return 'catalogx_extra_settings';
}
-}
\ No newline at end of file
+}
diff --git a/classes/SetupWizard.php b/classes/SetupWizard.php
index f5d3e21..9f099b4 100644
--- a/classes/SetupWizard.php
+++ b/classes/SetupWizard.php
@@ -1,55 +1,76 @@
id === 'dashboard_page_catalogx-setup' ) {
- wp_enqueue_script('setup-wizard-script', CatalogX()->plugin_url . 'build/blocks/setupWizard/index.js', [ 'jquery', 'jquery-blockui', 'wp-element', 'wp-i18n', 'react-jsx-runtime' ], CatalogX()->version, true);
+ if ( 'dashboard_page_catalogx-setup' === $current_screen->id ) {
+ wp_enqueue_script( 'setup-wizard-script', CatalogX()->plugin_url . FrontendScripts::get_build_path_name() . 'js/block/setupWizard/index.js', array( 'jquery', 'jquery-blockui', 'wp-element', 'wp-i18n', 'react-jsx-runtime' ), CatalogX()->version, true );
wp_set_script_translations( 'setup-wizard-script', 'catalogx' );
- wp_enqueue_style('setup-wizard-style', CatalogX()->plugin_url . 'build/blocks/setupWizard/index.css');
+ wp_enqueue_style( 'setup-wizard-style', CatalogX()->plugin_url . FrontendScripts::get_build_path_name() . 'styles/block/setupWizard/index.css', array(), CatalogX()->version );
wp_localize_script(
- 'setup-wizard-script', 'appLocalizer', [
- 'apiurl' => untrailingslashit(get_rest_url()),
- 'nonce' => wp_create_nonce( 'wp_rest' ),
- 'restUrl' => CatalogX()->rest_namespace,
- 'redirect_url' => admin_url() . 'admin.php?page=catalogx#&tab=modules',
- ]);
+ 'setup-wizard-script',
+ 'appLocalizer',
+ array(
+ 'apiUrl' => untrailingslashit( get_rest_url() ),
+ 'nonce' => wp_create_nonce( 'wp_rest' ),
+ 'restUrl' => CatalogX()->rest_namespace,
+ 'redirect_url' => admin_url() . 'admin.php?page=catalogx#&tab=modules',
+ )
+ );
}
}
-
}
diff --git a/classes/Shortcode.php b/classes/Shortcode.php
index af2dfe7..ad7b612 100644
--- a/classes/Shortcode.php
+++ b/classes/Shortcode.php
@@ -1,32 +1,49 @@
modules->is_active('quote')) {
+ if ( CatalogX()->modules->is_active( 'quote' ) ) {
FrontendScripts::load_scripts();
- FrontendScripts::localize_scripts('catalogx-quote-cart-script');
- FrontendScripts::enqueue_script('catalogx-quote-cart-script' );
- FrontendScripts::enqueue_style('catalogx-quote-cart-style');
+ FrontendScripts::localize_scripts( 'catalogx-quote-cart-script' );
+ FrontendScripts::enqueue_script( 'catalogx-quote-cart-script' );
+ FrontendScripts::enqueue_style( 'catalogx-frontend-style' );
}
}
+ /**
+ * Display the request quote container and enqueue necessary frontend scripts.
+ *
+ * @return string HTML output for the request quote section.
+ */
public function display_request_quote() {
$this->frontend_scripts();
ob_start();
@@ -36,5 +53,4 @@ public function display_request_quote() {
'catalogx_enquiry',
'rule' => 'catalogx_rules',
'message' => 'catalogx_messages',
- ];
+ );
/**
* Function to console and debug errors.
+ *
+ * @param mixed $data The data to be logged (string, array, object, etc.).
+ * @return void
*/
- public static function log( $str ) {
- $file = apply_filters( 'catalogx_log_file_path', CatalogX()->plugin_path . 'log/catalogx.txt' );
+ public static function log( $data ) {
+ if ( ! defined( 'WP_DEBUG' ) || ! WP_DEBUG ) {
+ return;
+ }
+ require_once ABSPATH . 'wp-admin/includes/file.php';
+ WP_Filesystem();
- if ( file_exists( $file ) ) {
- // Open the file to get existing content
- $str = var_export( $str, true );
+ global $wp_filesystem;
- // Wp_remote_gate replacement required
- $current = file_get_contents( $file );
+ $log_file = CatalogX()->plugin_path . 'log/catalogx.log';
+ $message = wp_json_encode( $data, JSON_PRETTY_PRINT ) . "\n---------------------------\n";
- if ( $current ) {
- // Append a new content to the file
- $current .= "$str" . "\r\n";
- $current .= "-------------------------------------\r\n";
- } else {
- $current = "$str" . "\r\n";
- $current .= "-------------------------------------\r\n";
- }
-
- // Write the contents back to the file
- file_put_contents( $file, $current );
- }
+ $existing = $wp_filesystem->exists( $log_file ) ? $wp_filesystem->get_contents( $log_file ) : '';
+ $wp_filesystem->put_contents( $log_file, $existing . $message, FS_CHMOD_FILE );
}
/**
* Check is Catalog Pro is active or not.
+ *
* @return bool
*/
public static function is_khali_dabba() {
- if ( defined( 'CATALOGX_PRO_PLUGIN_TOKEN' ) ) {
- return CatalogX_Pro()->license->is_active();
- }
-
- return false;
+ return apply_filters( 'kothay_dabba', false );
}
/**
* Get other templates ( e.g. product attributes ) passing attributes and including the file.
*
* @access public
- * @param mixed $template_name
- * @param array $args ( default: array() )
+ * @param mixed $template_name The name of the template file to load.
+ * @param array $args ( default: array() ) .
* @return void
*/
- public static function get_template( $template_name, $args = [] ) {
-
- if ( $args && is_array( $args ) ) {
- extract( $args );
- }
-
- // Check if the template exists in the theme
+ public static function get_template( $template_name, $args = array() ) {
+
+ // Check if the template exists in the theme.
$theme_template = get_stylesheet_directory() . '/woocommerce-catalog-enquiry/' . $template_name;
-
- // Use the theme template if it exists, otherwise use the plugin template
+
+ // Use the theme template if it exists, otherwise use the plugin template.
$located = file_exists( $theme_template ) ? $theme_template : CatalogX()->plugin_path . 'templates/' . $template_name;
-
- // Load the template
+
+ // Load the template.
load_template( $located, false, $args );
}
-
+
/**
* Create atachment from array of fiels.
- * @param mixed $files_array
+ *
+ * @param mixed $files_array Array representing the uploaded file.
* @return int|\WP_Error
*/
- public static function create_attachment_from_files_array($files_array) {
- require_once(ABSPATH . 'wp-admin/includes/file.php');
- require_once(ABSPATH . 'wp-admin/includes/image.php');
- require_once(ABSPATH . 'wp-admin/includes/media.php');
-
- // Handle the file upload
- $upload = wp_handle_upload($files_array, array('test_form' => false));
-
-
- // Prepare the attachment
+ public static function create_attachment_from_files_array( $files_array ) {
+ require_once ABSPATH . 'wp-admin/includes/file.php';
+ require_once ABSPATH . 'wp-admin/includes/image.php';
+ require_once ABSPATH . 'wp-admin/includes/media.php';
+
+ // Handle the file upload.
+ $upload = wp_handle_upload( $files_array, array( 'test_form' => false ) );
+
+ // Prepare the attachment.
$file_path = $upload['file'];
- $file_name = basename($file_path);
- $file_type = wp_check_filetype($file_name, null);
+ $file_name = basename( $file_path );
+ $file_type = wp_check_filetype( $file_name, null );
- // Create attachment post
+ // Create attachment post.
$attachment = array(
- 'guid' => $upload['url'],
+ 'guid' => $upload['url'],
'post_mime_type' => $file_type['type'],
- 'post_title' => preg_replace('/\.[^.]+$/', '', $file_name),
- 'post_content' => '',
- 'post_status' => 'inherit'
+ 'post_title' => preg_replace( '/\.[^.]+$/', '', $file_name ),
+ 'post_content' => '',
+ 'post_status' => 'inherit',
);
- // Insert attachment into the media library
- $attachment_id = wp_insert_attachment($attachment, $file_path);
+ // Insert attachment into the media library.
+ $attachment_id = wp_insert_attachment( $attachment, $file_path );
- if (!is_wp_error($attachment_id)) {
- // Generate metadata for the attachment, and update the attachment
- $attachment_data = wp_generate_attachment_metadata($attachment_id, $file_path);
- wp_update_attachment_metadata($attachment_id, $attachment_data);
+ if ( ! is_wp_error( $attachment_id ) ) {
+ // Generate metadata for the attachment, and update the attachment.
+ $attachment_data = wp_generate_attachment_metadata( $attachment_id, $file_path );
+ wp_update_attachment_metadata( $attachment_id, $attachment_data );
- return $attachment_id; // Return the attachment ID
+ return $attachment_id; // Return the attachment ID.
}
return 0;
@@ -131,67 +125,90 @@ public static function create_attachment_from_files_array($files_array) {
/**
* Check the plugin is active or not
+ *
+ * @param string $name Optional. Plugin name to check. Supported: 'notifima', 'multivendorx'.
* @return bool
*/
- public static function is_active_plugin($name = '') {
+ public static function is_active_plugin( $name = '' ) {
require_once ABSPATH . 'wp-admin/includes/plugin.php';
- if ($name == 'notifima') {
- return is_plugin_active('woocommerce-product-stock-alert/product_stock_alert.php');
+ if ( 'notifima' === $name ) {
+ return is_plugin_active( 'woocommerce-product-stock-alert/product_stock_alert.php' );
}
-
- if ($name == 'multivendorx') {
- return is_plugin_active('dc-woocommerce-multi-vendor/dc_product_vendor.php');
+
+ if ( 'multivendorx' === $name ) {
+ return is_plugin_active( 'dc-woocommerce-multi-vendor/dc_product_vendor.php' );
}
-
+
return false;
}
/**
* WPML support for language translation
- * @param mixed $context
- * @param mixed $name
- * @param mixed $default
- * @return mixed
+ *
+ * @param string $context The translation context (used by WPML).
+ * @param string $name The name of the string to translate.
+ * @param string $default_value The default string to return if no translation is found.
+ * @return string The translated string.
*/
- public static function get_translated_string($context, $name, $default ) {
+ public static function get_translated_string( $context, $name, $default_value ) {
if ( function_exists( 'icl_t' ) ) {
- return icl_t( $context, $name, $default );
+ return icl_t( $context, $name, $default_value );
} else {
- return __( $default, $context );
+ return __( $default_value, $context );
}
}
- public static function get_button_styles($button_settings, $hover = false) {
- $button_css = "";
- $border_size = !empty($button_settings['button_border_size']) ? esc_html($button_settings['button_border_size']) . 'px' : '1px';
-
- if ($hover) {
- if ( isset( $button_settings[ 'button_background_color_onhover' ] ) )
- $button_css .= !empty( $button_settings[ 'button_background_color_onhover' ] ) ? 'background: ' . $button_settings[ 'button_background_color_onhover' ] . ' !important;' : '';
- if ( isset( $button_settings[ 'button_text_color_onhover' ] ) )
- $button_css .= !empty( $button_settings[ 'button_text_color_onhover' ] ) ? ' color: ' . $button_settings[ 'button_text_color_onhover' ] . ' !important;' : '';
- if ( isset( $button_settings[ 'button_border_color_onhover' ] ) )
- $button_css .= !empty( $button_settings[ 'button_border_color_onhover' ] ) ? 'border: ' . $border_size . ' solid' . $button_settings[ 'button_border_color_onhover' ] . ' !important;' : '';
+ /**
+ * Generate inline CSS styles for button.
+ *
+ * Applies styles based on provided settings and whether the button is in a hover state.
+ *
+ * @param array $button_settings An associative array of button styling options.
+ * @param bool $hover Optional. Whether to apply hover styles. Default false.
+ * @return string CSS string to apply inline on the button.
+ */
+ public static function get_button_styles( $button_settings, $hover = false ) {
+ $button_css = '';
+ $border_size = ! empty( $button_settings['button_border_size'] ) ? esc_html( $button_settings['button_border_size'] ) . 'px' : '1px';
+
+ if ( $hover ) {
+ if ( isset( $button_settings['button_background_color_onhover'] ) ) {
+ $button_css .= ! empty( $button_settings['button_background_color_onhover'] ) ? 'background: ' . $button_settings['button_background_color_onhover'] . ' !important;' : '';
+ }
+ if ( isset( $button_settings['button_text_color_onhover'] ) ) {
+ $button_css .= ! empty( $button_settings['button_text_color_onhover'] ) ? ' color: ' . $button_settings['button_text_color_onhover'] . ' !important;' : '';
+ }
+ if ( isset( $button_settings['button_border_color_onhover'] ) ) {
+ $button_css .= ! empty( $button_settings['button_border_color_onhover'] ) ? 'border: ' . $border_size . ' solid' . $button_settings['button_border_color_onhover'] . ' !important;' : '';
+ }
} else {
- if (!empty($button_settings['button_background_color']))
- $button_css .= "background: " . esc_html($button_settings['button_background_color']) . ";";
- if (!empty($button_settings['button_text_color']))
- $button_css .= "color: " . esc_html($button_settings['button_text_color']) . ";";
- if (!empty($button_settings['button_border_color']))
- $button_css .= "border: " . $border_size . " solid " . esc_html($button_settings['button_border_color']) . ";";
- if (!empty($button_settings['button_font_size']))
- $button_css .= "font-size: " . esc_html($button_settings['button_font_size']) . "px;";
- if (!empty($button_settings['button_border_radious']))
- $button_css .= "border-radius: " . esc_html($button_settings['button_border_radious']) . "px;";
- if (!empty($button_settings['button_font_width']))
- $button_css .= "font-weight: " . esc_html($button_settings['button_font_width']) . "px;";
- if (!empty($button_settings['button_padding']))
- $button_css .= "padding: " . esc_html($button_settings['button_padding']) . "px;";
- if (!empty($button_settings['button_margin']))
- $button_css .= "margin: " . esc_html($button_settings['button_margin']) . "px;";
+ if ( ! empty( $button_settings['button_background_color'] ) ) {
+ $button_css .= 'background: ' . esc_html( $button_settings['button_background_color'] ) . ';';
+ }
+ if ( ! empty( $button_settings['button_text_color'] ) ) {
+ $button_css .= 'color: ' . esc_html( $button_settings['button_text_color'] ) . ';';
+ }
+ if ( ! empty( $button_settings['button_border_color'] ) ) {
+ $button_css .= 'border: ' . $border_size . ' solid ' . esc_html( $button_settings['button_border_color'] ) . ';';
+ }
+ if ( ! empty( $button_settings['button_font_size'] ) ) {
+ $button_css .= 'font-size: ' . esc_html( $button_settings['button_font_size'] ) . 'px;';
+ }
+ if ( ! empty( $button_settings['button_border_radious'] ) ) {
+ $button_css .= 'border-radius: ' . esc_html( $button_settings['button_border_radious'] ) . 'px;';
+ }
+ if ( ! empty( $button_settings['button_font_width'] ) ) {
+ $button_css .= 'font-weight: ' . esc_html( $button_settings['button_font_width'] ) . 'px;';
+ }
+ if ( ! empty( $button_settings['button_padding'] ) ) {
+ $button_css .= 'padding: ' . esc_html( $button_settings['button_padding'] ) . 'px;';
+ }
+ if ( ! empty( $button_settings['button_margin'] ) ) {
+ $button_css .= 'margin: ' . esc_html( $button_settings['button_margin'] ) . 'px;';
+ }
}
return $button_css;
}
-}
\ No newline at end of file
+}
diff --git a/modules/Catalog/Admin.php b/modules/Catalog/Admin.php
index 6752f20..f0d3f33 100644
--- a/modules/Catalog/Admin.php
+++ b/modules/Catalog/Admin.php
@@ -1,68 +1,78 @@
- __( 'Catalog', 'catalogx' ),
'target' => 'catalog_per_product_desc',
- 'class' => [ 'show_if_simple', 'show_if_variable', 'show_if_grouped', 'show_if_external' ],
+ 'class' => array( 'show_if_simple', 'show_if_variable', 'show_if_grouped', 'show_if_external' ),
'priority' => 50,
- ];
+ );
return $tabs;
}
/**
* Content of custom field in product tab.
+ *
* @return void
*/
public function catalog_product_data_fields() {
global $post;
- // Retrieve existing value from the database
+ // Retrieve existing value from the database.
$catalog_product_desc = get_post_meta( $post->ID, 'catalog_per_product_desc', true );
?>
- 'catalog_per_product_desc',
- 'label' => __( 'Additional Product Details', 'catalogx' ),
- 'description' => __( 'Enter extra information about the product to display on the single product page. Useful for highlighting unique features, usage tips, or care instructions.', 'catalogx' ),
- 'desc_tip' => true,
- 'type' => 'text',
- 'value' => $catalog_product_desc ?? '',
- ] );
+ 'catalog_per_product_desc',
+ 'label' => __( 'Additional Product Details', 'catalogx' ),
+ 'description' => __( 'Enter extra information about the product to display on the single product page. Useful for highlighting unique features, usage tips, or care instructions.', 'catalogx' ),
+ 'desc_tip' => true,
+ 'type' => 'text',
+ 'value' => $catalog_product_desc ?? '',
+ )
+ );
?>
@@ -71,12 +81,13 @@ public function catalog_product_data_fields() {
/**
* Save custom product data for wholesale product.
- * @param mixed $post_id
+ *
+ * @param mixed $post_id The ID of the product being saved.
* @return void
*/
public function save_catalog_product_data_fields( $post_id ) {
- $catalog_product_desc = filter_input(INPUT_POST, 'catalog_per_product_desc', FILTER_SANITIZE_FULL_SPECIAL_CHARS) ?? '';
-
+ $catalog_product_desc = filter_input( INPUT_POST, 'catalog_per_product_desc', FILTER_SANITIZE_FULL_SPECIAL_CHARS ) ?? '';
+
update_post_meta( $post_id, 'catalog_per_product_desc', wc_clean( $catalog_product_desc ) );
}
}
\ No newline at end of file
diff --git a/modules/Catalog/Frontend.php b/modules/Catalog/Frontend.php
index ef03529..adefdbc 100644
--- a/modules/Catalog/Frontend.php
+++ b/modules/Catalog/Frontend.php
@@ -1,89 +1,100 @@
-register_description_box();
+ add_action( 'woocommerce_single_product_summary', array( $this, 'exclusion_for_single_product_page' ), 5 );
+ // register description box.
+ $this->register_description_box();
}
-
+
/**
* Redirect cart and checkout page to home page
+ *
* @return void
*/
public static function catalogx_redirect_page() {
- // For exclusion
+ // For exclusion.
foreach ( WC()->cart->get_cart() as $cart_item ) {
$product_id = $cart_item['product_id'];
- if ( ! Util::is_available_for_product( $product_id ) ) {
+ if ( ! Util::is_available_for_product( $product_id ) ) {
return;
}
}
-
- // Get setting for sales enabled
+
+ // Get setting for sales enabled.
$sales_enabled = CatalogX()->setting->get_setting( 'enable_cart_checkout' );
- // Check sales enabled setting is enable or not
- if ( !empty($sales_enabled) ) return;
+ // Check sales enabled setting is enable or not.
+ if ( ! empty( $sales_enabled ) ) {
+ return;
+ }
- // Get cart and checkout page id
- $cart_page_id = wc_get_page_id( 'cart' );
- $checkout_page_id = wc_get_page_id( 'checkout' );
+ // Get cart and checkout page id.
+ $cart_page_id = wc_get_page_id( 'cart' );
+ $checkout_page_id = wc_get_page_id( 'checkout' );
- // Redirect to redirect url if page is cart page or checkout page
+ // Redirect to redirect url if page is cart page or checkout page.
if ( is_page( $cart_page_id ) || is_page( $checkout_page_id ) ) {
- wp_redirect( home_url() );
+ wp_safe_redirect( home_url() );
exit;
}
}
/**
- * Display single product page descrioption box
+ * Display single product page descrioption box
+ *
* @return void
*/
public static function show_description_box() {
global $post;
- if ( ! Util::is_available_for_product( $post->ID ) ) {
+ if ( ! Util::is_available_for_product( $post->ID ) ) {
return;
}
?>
- ID, 'catalog_per_product_desc', true );
- $input_box = !empty($catalog_per_product_desc) ? $catalog_per_product_desc : CatalogX()->setting->get_setting( 'additional_input' );
- if ($input_box) { ?>
+ $input_box = ! empty( $catalog_per_product_desc ) ? $catalog_per_product_desc : CatalogX()->setting->get_setting( 'additional_input' );
+ if ( $input_box ) {
+ ?>
-
+
@@ -92,93 +103,99 @@ public static function show_description_box() {
/**
* Price exclusion for shop page
- * @return void
+ *
+ * @param string $price The original price HTML.
+ * @param \WC_Product $product The WooCommerce product object.
+ * @return string The modified (or original) price HTML.
*/
-
public function exclude_price_for_selected_product( $price, $product ) {
$price_hide_product_page = CatalogX()->setting->get_setting( 'hide_product_price' );
-
+
if ( Util::is_available_for_product( $product->get_id() ) && $price_hide_product_page && is_shop() ) {
return '';
}
-
+
return $price;
}
/**
* Shop page add to cart button exclusion for block
- * @return void
+ *
+ * @param string $button The HTML for the add to cart button.
+ * @param \WC_Product $product The WooCommerce product object.
+ * @return string The modified (or original) button HTML.
*/
public function exclude_add_to_cart_button( $button, $product ) {
if ( ! Util::is_available_for_product( $product->get_id() ) ) {
return $button;
}
-
+
return empty( CatalogX()->setting->get_setting( 'enable_cart_checkout' ) ) ? '' : $button;
-
}
/**
* Single product page add to cart button exclusion
+ *
* @return void
*/
- public function exclusion_for_single_product_page() {
+ public function exclusion_for_single_product_page() {
global $post;
if ( Util::is_available_for_product( $post->ID ) && is_product() ) {
- if ( empty(CatalogX()->setting->get_setting( 'enable_cart_checkout' )) ) {
- // remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
+ if ( empty( CatalogX()->setting->get_setting( 'enable_cart_checkout' ) ) ) {
remove_action( 'woocommerce_single_variation', 'woocommerce_single_variation_add_to_cart_button', 20 );
- // for block support
- remove_action('woocommerce_simple_add_to_cart', 'woocommerce_simple_add_to_cart', 30);
+ // for block support.
+ remove_action( 'woocommerce_simple_add_to_cart', 'woocommerce_simple_add_to_cart', 30 );
}
}
}
/**
* Register description box for display in shop page
+ *
* @return void
*/
public function register_description_box() {
-
- // Get shop page button settings
- $position_settings = CatalogX()->setting->get_setting( 'shop_page_possition_setting', [] );
- // Priority of colide position
+ // Get shop page button settings.
+ $position_settings = CatalogX()->setting->get_setting( 'shop_page_possition_setting', array() );
+
+ // Priority of colide position.
$possiton_priority = 1;
- // Possiotion after a particular section
- $possition_after = 'sku_category';
+ // Possiotion after a particular section.
+ $possition_after = 'sku_category';
- // If possition settings exists
+ // If possition settings exists.
if ( $position_settings ) {
- // Get the colide possition priority
- $possiton_priority = array_search( 'additional_input', array_keys( $position_settings ) ) + 1;
+ // Get the colide possition priority.
+ $possiton_priority = array_search( 'additional_input', array_keys( $position_settings ), true ) + 1;
- // Get the possition after
- $possition_after = $position_settings[ 'additional_input' ];
+ // Get the possition after.
+ $possition_after = $position_settings['additional_input'];
}
-
- // Display button group in a hooked based on possition setting
+
+ // Display button group in a hooked based on possition setting.
switch ( $possition_after ) {
case 'sku_category':
- add_action( 'woocommerce_product_meta_end', [ self::class, 'display_description_box' ], 99 + $possiton_priority );
+ add_action( 'woocommerce_product_meta_end', array( self::class, 'display_description_box' ), 99 + $possiton_priority );
break;
case 'add_to_cart':
case 'product_description':
- add_action( 'woocommerce_product_meta_start', [ self::class, 'display_description_box' ], 99 + $possiton_priority );
+ add_action( 'woocommerce_product_meta_start', array( self::class, 'display_description_box' ), 99 + $possiton_priority );
break;
case 'price_section':
- add_action( 'woocommerce_single_product_summary', [ self::class, 'display_description_box' ], 10 + $possiton_priority );
+ add_action( 'woocommerce_single_product_summary', array( self::class, 'display_description_box' ), 10 + $possiton_priority );
break;
default:
- add_action( 'woocommerce_single_product_summary', [ self::class, 'display_description_box' ], 6 + $possiton_priority );
+ add_action( 'woocommerce_single_product_summary', array( self::class, 'display_description_box' ), 6 + $possiton_priority );
break;
}
}
- /**
+ /**
* Display descriopton box
+ *
* @return void
*/
public static function display_description_box() {
diff --git a/modules/Catalog/Module.php b/modules/Catalog/Module.php
index 69fded2..66149e7 100644
--- a/modules/Catalog/Module.php
+++ b/modules/Catalog/Module.php
@@ -1,24 +1,31 @@
-init_classes();
do_action( 'load_premium_catalog_module' );
-
}
/**
* Init helper classes
+ *
* @return void
*/
public function init_classes() {
- $this->container[ 'util' ] = new Util();
- $this->container[ 'fontend' ] = new Frontend();
- $this->container[ 'admin' ] = new Admin();
+ $this->container['util'] = new Util();
+ $this->container['fontend'] = new Frontend();
+ $this->container['admin'] = new Admin();
}
/**
* Magic getter function to get the reference of class.
- * Accept class name, If valid return reference, else Wp_Error.
- * @param mixed $class
+ * Accept class name, If valid return reference, else Wp_Error.
+ *
+ * @param mixed $class Name of the class to retrieve from the container.
* @return object | \WP_Error
*/
- public function __get( $class ) {
+ public function __get( $class ) { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.classFound
if ( array_key_exists( $class, $this->container ) ) {
return $this->container[ $class ];
}
- return new \WP_Error( sprintf('Call to unknown class %s.', $class ) );
+ return new \WP_Error( sprintf( 'Call to unknown class %s.', $class ) );
}
/**
@@ -63,7 +71,7 @@ public function __get( $class ) {
* @param string $class The class name or key to store the instance.
* @param object $value The instance of the class to store.
*/
- public function __set( $class, $value ) {
+ public function __set( $class, $value ) { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.classFound
$this->container[ $class ] = $value;
}
@@ -71,11 +79,11 @@ public function __set( $class, $value ) {
* Initializes Catalog class.
* Checks for an existing instance
* And if it doesn't find one, create it.
- * @param mixed $file
+ *
* @return object | null
*/
public static function init() {
- if ( self::$instance === null ) {
+ if ( null === self::$instance ) {
self::$instance = new self();
}
diff --git a/modules/Catalog/Util.php b/modules/Catalog/Util.php
index 3a077b2..ff54d45 100644
--- a/modules/Catalog/Util.php
+++ b/modules/Catalog/Util.php
@@ -1,50 +1,62 @@
-setting->get_option( 'catalogx_enquiry_quote_exclusion_settings', [] );
+ // Get exclusion setting.
+ $catalog_exclusion_setting = CatalogX()->setting->get_option( 'catalogx_enquiry_quote_exclusion_settings', array() );
+
+ // Get userroll exclusion settings.
+ $userroles_exclusion_settings = isset( $catalog_exclusion_setting['catalog_exclusion_userroles_list'] ) ? $catalog_exclusion_setting['catalog_exclusion_userroles_list'] : array();
- // Get userroll exclusion settings
- $userroles_exclusion_settings = isset($catalog_exclusion_setting['catalog_exclusion_userroles_list']) ? $catalog_exclusion_setting[ 'catalog_exclusion_userroles_list' ] : [];
-
- // Get excluded user roles
- $exclude_user_roles = array_map( function( $userrole ) {
- return $userrole[ 'key' ];
- }, $userroles_exclusion_settings );
+ // Get excluded user roles.
+ $exclude_user_roles = array_map(
+ function ( $userrole ) {
+ return $userrole['key'];
+ },
+ $userroles_exclusion_settings
+ );
- // Check current user's role is in exclude user roles
+ // Check current user's role is in exclude user roles.
if ( array_intersect( $exclude_user_roles, $current_user->roles ) ) {
return false;
}
-
- // Get user exclusion settings
- $userlist_exclusion_settings = isset($catalog_exclusion_setting['catalog_exclusion_user_list']) ? $catalog_exclusion_setting[ 'catalog_exclusion_user_list' ] : [];
- // Get excluded user ids
- $exclude_user_ids = array_map( function( $userid ) {
- return $userid[ 'key' ];
- }, $userlist_exclusion_settings );
+ // Get user exclusion settings.
+ $userlist_exclusion_settings = isset( $catalog_exclusion_setting['catalog_exclusion_user_list'] ) ? $catalog_exclusion_setting['catalog_exclusion_user_list'] : array();
- // Check current user's id is in exclude user id
- if ( in_array( $current_user->ID, $exclude_user_ids ) ) {
+ // Get excluded user ids.
+ $exclude_user_ids = array_map(
+ function ( $userid ) {
+ return (int) $userid['key'];
+ },
+ $userlist_exclusion_settings
+ );
+
+ // Check current user's id is in exclude user id.
+ if ( in_array( $current_user->ID, $exclude_user_ids, true ) ) {
return false;
}
@@ -53,67 +65,86 @@ public static function is_available() {
/**
* Check catalog functionlity available for product
+ *
+ * @param int $product_id The ID of the product to check.
* @return bool
*/
- public static function is_available_for_product($product_id) {
- // Get exclusion setting
- $catalog_exclusion_setting = CatalogX()->setting->get_option( 'catalogx_enquiry_quote_exclusion_settings', [] );
-
- // Get product exclusion settings
- $product_exclusion_settings = isset($catalog_exclusion_setting['catalog_exclusion_product_list']) ? $catalog_exclusion_setting['catalog_exclusion_product_list'] : [];
-
- // Get excluded products
- $exclude_products = array_map( function( $product ) {
- return $product[ 'key' ];
- }, $product_exclusion_settings );
-
-
- // Check current product id is in exclude products
- if ( in_array( $product_id, $exclude_products ) ) {
+ public static function is_available_for_product( $product_id ) {
+ // Get exclusion setting.
+ $catalog_exclusion_setting = CatalogX()->setting->get_option( 'catalogx_enquiry_quote_exclusion_settings', array() );
+
+ // Get product exclusion settings.
+ $product_exclusion_settings = isset( $catalog_exclusion_setting['catalog_exclusion_product_list'] ) ? $catalog_exclusion_setting['catalog_exclusion_product_list'] : array();
+
+ // Get excluded products.
+ $exclude_products = array_map(
+ function ( $product ) {
+ return $product['key'];
+ },
+ $product_exclusion_settings
+ );
+
+ // Check current product id is in exclude products.
+ if ( in_array( $product_id, $exclude_products, true ) ) {
return false;
}
- // Get category exclusion settings
- $category_exclusion_settings = isset($catalog_exclusion_setting['catalog_exclusion_category_list']) ? $catalog_exclusion_setting['catalog_exclusion_category_list'] : [];
-
- // Get excluded category
- $exclude_categories = array_filter(array_map(function($category) use ($product_id) {
- $term_list = wp_get_post_terms($product_id, 'product_cat', ['fields' => 'ids']);
- return $category['key'] == $term_list[0] ? $product_id : null;
- }, $category_exclusion_settings));
-
- // Check current product id is in exclude categories
- if ( in_array( $product_id, $exclude_categories ) ) {
+ // Get category exclusion settings.
+ $category_exclusion_settings = isset( $catalog_exclusion_setting['catalog_exclusion_category_list'] ) ? $catalog_exclusion_setting['catalog_exclusion_category_list'] : array();
+
+ // Get excluded category.
+ $exclude_categories = array_filter(
+ array_map(
+ function ( $category ) use ( $product_id ) {
+ $term_list = wp_get_post_terms( $product_id, 'product_cat', array( 'fields' => 'ids' ) );
+ return $category['key'] === $term_list[0] ? $product_id : null;
+ },
+ $category_exclusion_settings
+ )
+ );
+
+ // Check current product id is in exclude categories.
+ if ( in_array( $product_id, $exclude_categories, true ) ) {
return false;
}
- // Get tag exclusion settings
- $tag_exclusion_settings = isset($catalog_exclusion_setting['catalog_exclusion_tag_list']) ? $catalog_exclusion_setting['catalog_exclusion_tag_list'] : [];
-
- // Get excluded tag
- $exclude_tags = array_filter(array_map( function( $tag ) use ($product_id) {
- $tag_term_list = wp_get_post_terms($product_id,'product_tag',['fields'=>'ids']);
- return $tag[ 'key' ] == (!empty($tag_term_list) && $tag_term_list[0]) ? $product_id : null;
- }, $tag_exclusion_settings ));
-
- // Check current product id is in exclude tags
- if ( in_array( $product_id, $exclude_tags ) ) {
+ // Get tag exclusion settings.
+ $tag_exclusion_settings = isset( $catalog_exclusion_setting['catalog_exclusion_tag_list'] ) ? $catalog_exclusion_setting['catalog_exclusion_tag_list'] : array();
+
+ // Get excluded tag.
+ $exclude_tags = array_filter(
+ array_map(
+ function ( $tag ) use ( $product_id ) {
+ $tag_term_list = wp_get_post_terms( $product_id, 'product_tag', array( 'fields' => 'ids' ) );
+ return ( ! empty( $tag_term_list ) && $tag_term_list[0] ) == $tag['key'] ? $product_id : null;
+ },
+ $tag_exclusion_settings
+ )
+ );
+
+ // Check current product id is in exclude tags.
+ if ( in_array( $product_id, $exclude_tags, true ) ) {
return false;
}
- // Get brand exclusion settings
- $brand_exclusion_settings = isset($catalog_exclusion_setting['catalog_exclusion_brand_list']) ? $catalog_exclusion_setting['catalog_exclusion_brand_list'] : [];
- // Get excluded brand
- $exclude_brands = array_filter(array_map( function( $tag ) use ($product_id) {
- $brand_term_list = wp_get_post_terms($product_id,'product_brand',['fields'=>'ids']);
- return (!empty($brand_term_list) && in_array($tag['key'], $brand_term_list)) ? $product_id : null;
- }, $brand_exclusion_settings ));
-
- // Check current product id is in exclude brands
- if ( in_array( $product_id, $exclude_brands ) ) {
+ // Get brand exclusion settings.
+ $brand_exclusion_settings = isset( $catalog_exclusion_setting['catalog_exclusion_brand_list'] ) ? $catalog_exclusion_setting['catalog_exclusion_brand_list'] : array();
+ // Get excluded brand.
+ $exclude_brands = array_filter(
+ array_map(
+ function ( $tag ) use ( $product_id ) {
+ $brand_term_list = wp_get_post_terms( $product_id, 'product_brand', array( 'fields' => 'ids' ) );
+ return ( ! empty( $brand_term_list ) && in_array( $tag['key'], $brand_term_list, true ) ) ? $product_id : null;
+ },
+ $brand_exclusion_settings
+ )
+ );
+
+ // Check current product id is in exclude brands.
+ if ( in_array( $product_id, $exclude_brands, true ) ) {
return false;
}
+
return true;
}
-
-}
\ No newline at end of file
+}
diff --git a/modules/Enquiry/Ajax.php b/modules/Enquiry/Ajax.php
index 3f2be67..ecddd4e 100644
--- a/modules/Enquiry/Ajax.php
+++ b/modules/Enquiry/Ajax.php
@@ -1,36 +1,45 @@
setting->get_setting( 'enquiry_user_permission', [] );
- if ( !empty($display_enquiry_button) && !is_user_logged_in()) {
+ $display_enquiry_button = CatalogX()->setting->get_setting( 'enquiry_user_permission', array() );
+ if ( ! empty( $display_enquiry_button ) && ! is_user_logged_in() ) {
return;
}
if ( empty( CatalogX()->setting->get_setting( 'enable_cart_checkout' ) ) ) {
- add_action( 'woocommerce_after_shop_loop_item', [$this, 'add_button_in_shop_page'] );
+ add_action( 'woocommerce_after_shop_loop_item', array( $this, 'add_button_in_shop_page' ) );
}
- add_action( 'display_shop_page_button', [ $this, 'catalogx_add_enquiry_button' ] );
+ add_action( 'display_shop_page_button', array( $this, 'catalogx_add_enquiry_button' ) );
- //Hook for exclusion
- add_action( 'woocommerce_single_product_summary', [ $this, 'enquiry_button_exclusion' ], 5);
+ // Hook for exclusion.
+ add_action( 'woocommerce_single_product_summary', array( $this, 'enquiry_button_exclusion' ), 5 );
- add_action( 'wp_enqueue_scripts', [ $this, 'frontend_scripts' ] );
+ add_action( 'wp_enqueue_scripts', array( $this, 'frontend_scripts' ) );
- // Enquiry button shortcode
- add_shortcode( 'catalogx_enquiry_button', [ $this, 'catalogx_enquiry_button_shortcode' ] );
+ // Enquiry button shortcode.
+ add_shortcode( 'catalogx_enquiry_button', array( $this, 'catalogx_enquiry_button_shortcode' ) );
}
+ /**
+ * Adds enquiry button on shop page via hook.
+ *
+ * @return void
+ */
public function catalogx_add_enquiry_button() {
global $product;
- if (empty(trim(CatalogX()->render_enquiry_btn_via))) {
+ if ( empty( trim( CatalogX()->render_enquiry_btn_via ) ) ) {
CatalogX()->render_enquiry_btn_via = 'hook';
- $this->add_enquiry_button($product->get_id());
+ $this->add_enquiry_button( $product->get_id() );
}
}
/**
- * Add enquiry button
+ * Add enquiry button in single product page and shop page
+ *
+ * @param int|\WC_Product|null $product_obj Product object or ID. Falls back to global $product if null.
* @return void
*/
- public function add_enquiry_button($productObj) {
+ public function add_enquiry_button( $product_obj ) {
global $product;
- $productObj = is_int($productObj) ? wc_get_product($productObj) : ($productObj ?: $product);
+ $product_obj = is_int( $product_obj ) ? wc_get_product( $product_obj ) : ( $product_obj ? $product_obj : $product );
- if ( empty( $productObj ) )
+ if ( empty( $product_obj ) ) {
return;
+ }
- if ( CatalogX()->setting->get_setting( 'is_enable_multiple_product_enquiry' ) && Utill::is_khali_dabba() ) {
+ if ( apply_filters( 'catalogx_enable_multiple_product_enquiry', false ) ) {
return;
}
- $button_settings = CatalogX()->setting->get_setting( 'enquiry_button', [] );
- $button_css = Utill::get_button_styles($button_settings);
- $button_hover_css = Utill::get_button_styles($button_settings, true);
-
+ $button_settings = CatalogX()->setting->get_setting( 'enquiry_button', array() );
+ $button_css = Utill::get_button_styles( $button_settings );
+ $button_hover_css = Utill::get_button_styles( $button_settings, true );
+
if ( $button_hover_css ) {
echo '';
}
$additional_css_settings = CatalogX()->setting->get_setting( 'custom_css_product_page' );
- if (isset($additional_css_settings) && !empty($additional_css_settings)) {
+ if ( isset( $additional_css_settings ) && ! empty( $additional_css_settings ) ) {
$button_css .= $additional_css_settings;
}
-
- $button_settings[ 'button_text' ] = !empty( $button_settings[ 'button_text' ] ) ? $button_settings[ 'button_text' ] : \CatalogX\Utill::get_translated_string( 'catalogx', 'send_an_enquiry', 'Send an enquiry' );
- $button_position_settings = CatalogX()->setting->get_setting( 'shop_page_button_position_setting', [] );
- $position = array_search('enquiry_button', $button_position_settings);
- $position = $position !== false ? $position : 0;
+
+ $button_settings['button_text'] = ! empty( $button_settings['button_text'] ) ? $button_settings['button_text'] : \CatalogX\Utill::get_translated_string( 'catalogx', 'send_an_enquiry', 'Send an enquiry' );
+ $button_position_settings = CatalogX()->setting->get_setting( 'shop_page_button_position_setting', array() );
+ $position = array_search( 'enquiry_button', $button_position_settings, true );
+ $position = false !== $position ? $position : 0;
?>
- setting->get_setting( 'is_enable_out_of_stock' ) ){
- if ( !$productObj->managing_stock() && !$productObj->is_in_stock()) { ?>
-
-
+ setting->get_setting( 'is_enable_out_of_stock' ) ) {
+ if ( ! $product_obj->managing_stock() && ! $product_obj->is_in_stock() ) {
+ ?>
+
+
-
-
+ }
+ } else {
+ ?>
+
+
-
-
-
-
-
+ }
+ ?>
+
+
+
+
+
-