@@ -1,22 +1,22 @@ discard block |
||
1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
1 | +<?php if (!defined('ABSPATH')) exit; |
|
2 | 2 | ?> |
3 | 3 | <div class="wps-gridwrapper3-padded"> |
4 | 4 | <div> |
5 | 5 | <div class="wps-form-group"> |
6 | - <label><?php _e( 'Selected part element background', 'wpshop'); ?> :</label> |
|
6 | + <label><?php _e('Selected part element background', 'wpshop'); ?> :</label> |
|
7 | 7 | <div class="wps-form"> |
8 | - <input type="text" name="wpshop_customize_display_option[account][activ_element_background]" class="wps-color-picker-field" value="<?php echo ( !empty($wpshop_customize_display_option) && !empty($wpshop_customize_display_option['account']) && !empty($wpshop_customize_display_option['account']['activ_element_background']) ) ? $wpshop_customize_display_option['account']['activ_element_background'] : ''; ?>" /> |
|
9 | - <span style="display : inline-block; width : 20px; height : 20px; background : <?php echo ( !empty($wpshop_customize_display_option) && !empty($wpshop_customize_display_option['account']) && !empty($wpshop_customize_display_option['account']['activ_element_background']) ) ? $wpshop_customize_display_option['account']['activ_element_background'] : ''; ?>"></span> |
|
8 | + <input type="text" name="wpshop_customize_display_option[account][activ_element_background]" class="wps-color-picker-field" value="<?php echo (!empty($wpshop_customize_display_option) && !empty($wpshop_customize_display_option['account']) && !empty($wpshop_customize_display_option['account']['activ_element_background'])) ? $wpshop_customize_display_option['account']['activ_element_background'] : ''; ?>" /> |
|
9 | + <span style="display : inline-block; width : 20px; height : 20px; background : <?php echo (!empty($wpshop_customize_display_option) && !empty($wpshop_customize_display_option['account']) && !empty($wpshop_customize_display_option['account']['activ_element_background'])) ? $wpshop_customize_display_option['account']['activ_element_background'] : ''; ?>"></span> |
|
10 | 10 | </div> |
11 | 11 | </div> |
12 | 12 | </div> |
13 | 13 | |
14 | 14 | <div> |
15 | 15 | <div class="wps-form-group"> |
16 | - <label><?php _e( 'Information box background color', 'wpshop'); ?> :</label> |
|
16 | + <label><?php _e('Information box background color', 'wpshop'); ?> :</label> |
|
17 | 17 | <div class="wps-form"> |
18 | - <input type="text" name="wpshop_customize_display_option[account][information_box_background]" class="wps-color-picker-field" value="<?php echo ( !empty($wpshop_customize_display_option) && !empty($wpshop_customize_display_option['account']) && !empty($wpshop_customize_display_option['account']['information_box_background']) ) ? $wpshop_customize_display_option['account']['information_box_background'] : ''; ?>" /> |
|
19 | - <span style="display : inline-block; width : 20px; height : 20px; background : <?php echo ( !empty($wpshop_customize_display_option) && !empty($wpshop_customize_display_option['account']) && !empty($wpshop_customize_display_option['account']['information_box_background']) ) ? $wpshop_customize_display_option['account']['information_box_background'] : ''; ?>"></span> |
|
18 | + <input type="text" name="wpshop_customize_display_option[account][information_box_background]" class="wps-color-picker-field" value="<?php echo (!empty($wpshop_customize_display_option) && !empty($wpshop_customize_display_option['account']) && !empty($wpshop_customize_display_option['account']['information_box_background'])) ? $wpshop_customize_display_option['account']['information_box_background'] : ''; ?>" /> |
|
19 | + <span style="display : inline-block; width : 20px; height : 20px; background : <?php echo (!empty($wpshop_customize_display_option) && !empty($wpshop_customize_display_option['account']) && !empty($wpshop_customize_display_option['account']['information_box_background'])) ? $wpshop_customize_display_option['account']['information_box_background'] : ''; ?>"></span> |
|
20 | 20 | |
21 | 21 | </div> |
22 | 22 | </div> |
@@ -24,10 +24,10 @@ discard block |
||
24 | 24 | |
25 | 25 | <div> |
26 | 26 | <div class="wps-form-group"> |
27 | - <label><?php _e( 'Unselected part element background', 'wpshop'); ?> :</label> |
|
27 | + <label><?php _e('Unselected part element background', 'wpshop'); ?> :</label> |
|
28 | 28 | <div class="wps-form"> |
29 | - <input type="text" name="wpshop_customize_display_option[account][part_background]" class="wps-color-picker-field" value="<?php echo ( !empty($wpshop_customize_display_option) && !empty($wpshop_customize_display_option['account']) && !empty($wpshop_customize_display_option['account']['part_background']) ) ? $wpshop_customize_display_option['account']['part_background'] : ''; ?>"/> |
|
30 | - <span style="display : inline-block; width : 20px; height : 20px; background : <?php echo ( !empty($wpshop_customize_display_option) && !empty($wpshop_customize_display_option['account']) && !empty($wpshop_customize_display_option['account']['part_background']) ) ? $wpshop_customize_display_option['account']['part_background'] : ''; ?>"></span> |
|
29 | + <input type="text" name="wpshop_customize_display_option[account][part_background]" class="wps-color-picker-field" value="<?php echo (!empty($wpshop_customize_display_option) && !empty($wpshop_customize_display_option['account']) && !empty($wpshop_customize_display_option['account']['part_background'])) ? $wpshop_customize_display_option['account']['part_background'] : ''; ?>"/> |
|
30 | + <span style="display : inline-block; width : 20px; height : 20px; background : <?php echo (!empty($wpshop_customize_display_option) && !empty($wpshop_customize_display_option['account']) && !empty($wpshop_customize_display_option['account']['part_background'])) ? $wpshop_customize_display_option['account']['part_background'] : ''; ?>"></span> |
|
31 | 31 | |
32 | 32 | </div> |
33 | 33 | </div> |
@@ -1,4 +1,6 @@ |
||
1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
1 | +<?php if ( !defined( 'ABSPATH' ) ) { |
|
2 | + exit; |
|
3 | +} |
|
2 | 4 | ?> |
3 | 5 | <div class="wps-gridwrapper3-padded"> |
4 | 6 | <div> |
@@ -1,4 +1,4 @@ discard block |
||
1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
1 | +<?php if (!defined('ABSPATH')) exit; |
|
2 | 2 | |
3 | 3 | /** |
4 | 4 | * Bootstrap file |
@@ -7,10 +7,10 @@ discard block |
||
7 | 7 | */ |
8 | 8 | |
9 | 9 | DEFINE('WPS_COUPON_DIR', basename(dirname(__FILE__))); |
10 | -DEFINE('WPS_COUPON_PATH', str_replace( "\\", "/", str_replace( WPS_COUPON_DIR, "", dirname( __FILE__ ) ) ) ); |
|
11 | -DEFINE('WPS_COUPON_URL', str_replace( str_replace( "\\", "/", ABSPATH), site_url() . '/', WPS_COUPON_PATH ) ); |
|
10 | +DEFINE('WPS_COUPON_PATH', str_replace("\\", "/", str_replace(WPS_COUPON_DIR, "", dirname(__FILE__)))); |
|
11 | +DEFINE('WPS_COUPON_URL', str_replace(str_replace("\\", "/", ABSPATH), site_url() . '/', WPS_COUPON_PATH)); |
|
12 | 12 | |
13 | 13 | |
14 | -include( plugin_dir_path( __FILE__ ).'/controller/wps_coupon_ctr.php' ); |
|
15 | -include( plugin_dir_path( __FILE__ ).'/model/wps_coupon_model.php' ); |
|
14 | +include(plugin_dir_path(__FILE__) . '/controller/wps_coupon_ctr.php'); |
|
15 | +include(plugin_dir_path(__FILE__) . '/model/wps_coupon_model.php'); |
|
16 | 16 | $wps_coupon = new wps_coupon_ctr(); |
@@ -1,4 +1,6 @@ |
||
1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
1 | +<?php if ( !defined( 'ABSPATH' ) ) { |
|
2 | + exit; |
|
3 | +} |
|
2 | 4 | |
3 | 5 | /** |
4 | 6 | * Bootstrap file |
@@ -1,4 +1,6 @@ |
||
1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
1 | +<?php if ( !defined( 'ABSPATH' ) ) { |
|
2 | + exit; |
|
3 | +} |
|
2 | 4 | if( !$is_from_admin ) : ?> |
3 | 5 | <span class="wps-h5"><?php _e( 'My coupons', 'wpshop'); ?></span> |
4 | 6 | <?php endif; ?> |
@@ -1,14 +1,14 @@ |
||
1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
2 | - if( !$is_from_admin ) : ?> |
|
3 | -<span class="wps-h5"><?php _e( 'My coupons', 'wpshop'); ?></span> |
|
4 | -<?php endif; ?> |
|
1 | +<?php if (!defined('ABSPATH')) exit; |
|
2 | + if (!$is_from_admin) : ?> |
|
3 | +<span class="wps-h5"><?php _e('My coupons', 'wpshop'); ?></span> |
|
4 | +<?php endif; ?> |
|
5 | 5 | |
6 | 6 | <div class="wps-table"> |
7 | 7 | <div class="wps-table-header wps-table-row"> |
8 | - <div class="wps-table-cell"><?php _e( 'Coupon value', 'wpshop'); ?></div> |
|
8 | + <div class="wps-table-cell"><?php _e('Coupon value', 'wpshop'); ?></div> |
|
9 | 9 | <!-- TODO Display elements only when is !empty --> |
10 | - <!--<div class="wps-table-cell"><?php _e( 'Validity date', 'wpshop'); ?></div>--> |
|
11 | - <div class="wps-table-cell"><?php _e( 'Coupon code', 'wpshop'); ?></div> |
|
10 | + <!--<div class="wps-table-cell"><?php _e('Validity date', 'wpshop'); ?></div>--> |
|
11 | + <div class="wps-table-cell"><?php _e('Coupon code', 'wpshop'); ?></div> |
|
12 | 12 | </div> |
13 | 13 | <?php echo $coupons_rows; ?> |
14 | 14 | </div> |
@@ -1,4 +1,4 @@ |
||
1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
1 | +<?php if (!defined('ABSPATH')) exit; |
|
2 | 2 | ?> |
3 | 3 | <div class="wps-table-content wps-table-row"> |
4 | 4 | <div class="wps-table-cell"><?php echo $coupon_value; ?></div> |
@@ -1,4 +1,6 @@ |
||
1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
1 | +<?php if ( !defined( 'ABSPATH' ) ) { |
|
2 | + exit; |
|
3 | +} |
|
2 | 4 | ?> |
3 | 5 | <div class="wps-table-content wps-table-row"> |
4 | 6 | <div class="wps-table-cell"><?php echo $coupon_value; ?></div> |
@@ -1,4 +1,6 @@ |
||
1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
1 | +<?php if ( !defined( 'ABSPATH' ) ) { |
|
2 | + exit; |
|
3 | +} |
|
2 | 4 | ?> |
3 | 5 | <table class="wpshop_coupon_definition_table" > |
4 | 6 | <tr class="wpshop_coupon_definition_table_code_coupon_line" > |
@@ -1,16 +1,16 @@ discard block |
||
1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
1 | +<?php if (!defined('ABSPATH')) exit; |
|
2 | 2 | ?> |
3 | 3 | <table class="wpshop_coupon_definition_table" > |
4 | 4 | <tr class="wpshop_coupon_definition_table_code_coupon_line" > |
5 | - <td class="wpshop_coupon_definition_table_label wpshop_coupon_definition_code_coupon_input_label" ><label for="coupon_code" ><?php _e('Coupon code','wpshop'); ?></label></td> |
|
5 | + <td class="wpshop_coupon_definition_table_label wpshop_coupon_definition_code_coupon_input_label" ><label for="coupon_code" ><?php _e('Coupon code', 'wpshop'); ?></label></td> |
|
6 | 6 | <td class="wpshop_coupon_definition_table_input wpshop_coupon_definition_code_coupon_input" ><input type="text" name="coupon_code" id="coupon_code" value="<?php echo $coupon_code; ?>" /></td> |
7 | 7 | </tr> |
8 | 8 | <tr class="wpshop_coupon_definition_table_code_type_line" > |
9 | - <td class="wpshop_coupon_definition_table_label wpshop_coupon_definition_coupon_type_amount_label" ><input type="radio" name="coupon_type" class="wpshop_coupon_type" id="coupon_type_amount" value="amount" <?php echo ( ($wpshop_coupon_discount_type=='amount') || empty($wpshop_coupon_discount_type) ? 'checked="checked"' : null ); ?> /><label for="coupon_type_amount" ><?php _e('Coupon discount amount','wpshop'); ?></label></td> |
|
10 | - <td class="wpshop_coupon_definition_table_input wpshop_coupon_definition_coupon_type_input" rowspan="2" ><input type="text" name="coupon_discount_amount" value="<?php echo $coupon_discount_amount; ?>" /><span class="wpshop_coupon_type_unit wpshop_coupon_type_unit_amount" > <?php echo ( ( (!empty($wpshop_coupon_discount_type) && $wpshop_coupon_discount_type == 'percent' ) ) ? '%' : wpshop_tools::wpshop_get_currency().' '.__('ATI', 'wpshop')); ?></span><span class="wpshopHide wpshop_coupon_type_unit wpshop_coupon_type_unit_percent" > % </span></td> |
|
9 | + <td class="wpshop_coupon_definition_table_label wpshop_coupon_definition_coupon_type_amount_label" ><input type="radio" name="coupon_type" class="wpshop_coupon_type" id="coupon_type_amount" value="amount" <?php echo (($wpshop_coupon_discount_type == 'amount') || empty($wpshop_coupon_discount_type) ? 'checked="checked"' : null); ?> /><label for="coupon_type_amount" ><?php _e('Coupon discount amount', 'wpshop'); ?></label></td> |
|
10 | + <td class="wpshop_coupon_definition_table_input wpshop_coupon_definition_coupon_type_input" rowspan="2" ><input type="text" name="coupon_discount_amount" value="<?php echo $coupon_discount_amount; ?>" /><span class="wpshop_coupon_type_unit wpshop_coupon_type_unit_amount" > <?php echo (((!empty($wpshop_coupon_discount_type) && $wpshop_coupon_discount_type == 'percent')) ? '%' : wpshop_tools::wpshop_get_currency() . ' ' . __('ATI', 'wpshop')); ?></span><span class="wpshopHide wpshop_coupon_type_unit wpshop_coupon_type_unit_percent" > % </span></td> |
|
11 | 11 | </tr> |
12 | 12 | <tr class="wpshop_coupon_definition_table_code_type_line" > |
13 | - <td class="wpshop_coupon_definition_table_label wpshop_coupon_definition_coupon_type_percent_label" ><input type="radio" name="coupon_type" id="coupon_type_percent" class="wpshop_coupon_type" value="percent" <?php echo ($wpshop_coupon_discount_type=='percent'?'checked="checked"':null); ?> /><label for="coupon_type_percent" ><?php _e('Coupon discount percent','wpshop'); ?></label></td> |
|
13 | + <td class="wpshop_coupon_definition_table_label wpshop_coupon_definition_coupon_type_percent_label" ><input type="radio" name="coupon_type" id="coupon_type_percent" class="wpshop_coupon_type" value="percent" <?php echo ($wpshop_coupon_discount_type == 'percent' ? 'checked="checked"' : null); ?> /><label for="coupon_type_percent" ><?php _e('Coupon discount percent', 'wpshop'); ?></label></td> |
|
14 | 14 | </tr> |
15 | 15 | <tr> |
16 | 16 | <td> |
@@ -24,14 +24,14 @@ discard block |
||
24 | 24 | 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS, |
25 | 25 | 'post_status' => 'draft', |
26 | 26 | ); |
27 | - $customers = get_posts( $args ); |
|
28 | - if ( !empty($customers) ) : |
|
29 | - foreach( $customers as $customer ) : |
|
30 | - $name = strtoupper( get_user_meta( $customer->post_author, 'last_name', true ) ).' '.get_user_meta( $customer->post_author, 'first_name', true ); |
|
27 | + $customers = get_posts($args); |
|
28 | + if (!empty($customers)) : |
|
29 | + foreach ($customers as $customer) : |
|
30 | + $name = strtoupper(get_user_meta($customer->post_author, 'last_name', true)) . ' ' . get_user_meta($customer->post_author, 'first_name', true); |
|
31 | 31 | $user = get_userdata($customer->post_author); |
32 | - if ( !empty( $user ) ) : |
|
32 | + if (!empty($user)) : |
|
33 | 33 | ?> |
34 | - <option value="<?php echo $customer->post_author; ?>" <?php echo ( (!empty( $coupon_receiver) && is_array($coupon_receiver) && in_array($customer->post_author, $coupon_receiver)) ? 'selected="selected"' : '' ); ?>><?php echo $name; ?> ( <?php echo $user->user_email; ?> )</option> |
|
34 | + <option value="<?php echo $customer->post_author; ?>" <?php echo ((!empty($coupon_receiver) && is_array($coupon_receiver) && in_array($customer->post_author, $coupon_receiver)) ? 'selected="selected"' : ''); ?>><?php echo $name; ?> ( <?php echo $user->user_email; ?> )</option> |
|
35 | 35 | <?php |
36 | 36 | endif; |
37 | 37 | endforeach; |
@@ -56,10 +56,10 @@ discard block |
||
56 | 56 | <label for="wpshop_coupon_mini_amount"><?php _e('Minimum order amount to use this coupon', 'wpshop'); ?></label> : |
57 | 57 | </td> |
58 | 58 | <td> |
59 | - <input type="text" name="wpshop_coupon_mini_amount" value="<?php echo ( (!empty($wpshop_coupon_minimum_amount) && !empty($wpshop_coupon_minimum_amount['amount']) ) ? $wpshop_coupon_minimum_amount['amount'] : ''); ?>" id="wpshop_coupon_mini_amount" /> <?php echo $default_currency; ?> |
|
59 | + <input type="text" name="wpshop_coupon_mini_amount" value="<?php echo ((!empty($wpshop_coupon_minimum_amount) && !empty($wpshop_coupon_minimum_amount['amount'])) ? $wpshop_coupon_minimum_amount['amount'] : ''); ?>" id="wpshop_coupon_mini_amount" /> <?php echo $default_currency; ?> |
|
60 | 60 | <select name="wpshop_coupon_min_mount_shipping_rule"> |
61 | - <option value="no_shipping_cost" <?php echo ( (!empty($wpshop_coupon_minimum_amount) && !empty($wpshop_coupon_minimum_amount['shipping_rule']) && $wpshop_coupon_minimum_amount['shipping_rule'] == 'no_shipping_cost') ? 'selected="selected"' : ''); ?>><?php _e('Without shipping cost', 'wpshop'); ?></option> |
|
62 | - <option value="shipping_cost" <?php echo ( (!empty($wpshop_coupon_minimum_amount) && !empty($wpshop_coupon_minimum_amount['shipping_rule']) && $wpshop_coupon_minimum_amount['shipping_rule'] == 'shipping_cost') ? 'selected="selected"' : ''); ?>><?php _e('With shipping cost', 'wpshop'); ?></option> |
|
61 | + <option value="no_shipping_cost" <?php echo ((!empty($wpshop_coupon_minimum_amount) && !empty($wpshop_coupon_minimum_amount['shipping_rule']) && $wpshop_coupon_minimum_amount['shipping_rule'] == 'no_shipping_cost') ? 'selected="selected"' : ''); ?>><?php _e('Without shipping cost', 'wpshop'); ?></option> |
|
62 | + <option value="shipping_cost" <?php echo ((!empty($wpshop_coupon_minimum_amount) && !empty($wpshop_coupon_minimum_amount['shipping_rule']) && $wpshop_coupon_minimum_amount['shipping_rule'] == 'shipping_cost') ? 'selected="selected"' : ''); ?>><?php _e('With shipping cost', 'wpshop'); ?></option> |
|
63 | 63 | </select> |
64 | 64 | <br/><?php _e('Leave empty if you want no limitation', 'wpshop'); ?> |
65 | 65 | </td> |
@@ -1,4 +1,6 @@ discard block |
||
1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
1 | +<?php if ( !defined( 'ABSPATH' ) ) { |
|
2 | + exit; |
|
3 | +} |
|
2 | 4 | class wps_coupon_model { |
3 | 5 | function __construct() { |
4 | 6 | |
@@ -65,8 +67,7 @@ discard block |
||
65 | 67 | |
66 | 68 | if ( !empty($coupon_use[$user_id]) ) { |
67 | 69 | $coupon_use[$user_id] = $coupon_use[$user_id] + 1; |
68 | - } |
|
69 | - else { |
|
70 | + } else { |
|
70 | 71 | $coupon_use[$user_id] = 1; |
71 | 72 | } |
72 | 73 | update_post_meta( $coupon_id, '_wpshop_coupon_usage', $coupon_use); |
@@ -1,4 +1,4 @@ discard block |
||
1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
1 | +<?php if (!defined('ABSPATH')) exit; |
|
2 | 2 | class wps_coupon_model { |
3 | 3 | function __construct() { |
4 | 4 | |
@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | * @return array |
10 | 10 | */ |
11 | 11 | function get_coupons() { |
12 | - $coupons = get_posts( array( 'post_per_page' => -1, 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_COUPON, 'post_status' => 'publish' ) ); |
|
12 | + $coupons = get_posts(array('post_per_page' => -1, 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_COUPON, 'post_status' => 'publish')); |
|
13 | 13 | return $coupons; |
14 | 14 | } |
15 | 15 | |
@@ -17,16 +17,16 @@ discard block |
||
17 | 17 | * Save coupon custom datas on asave post action |
18 | 18 | * @param array $data |
19 | 19 | */ |
20 | - function save_coupons_informations( $data ) { |
|
21 | - if( !empty($data) ) { |
|
22 | - $amount_min_limit = array( 'amount' => ( ( !empty($data['wpshop_coupon_mini_amount']) ) ? $data['wpshop_coupon_mini_amount'] : null ), 'shipping_rule' => ( ( !empty($data['wpshop_coupon_min_mount_shipping_rule']) ) ? $data['wpshop_coupon_min_mount_shipping_rule'] : null ) ); |
|
20 | + function save_coupons_informations($data) { |
|
21 | + if (!empty($data)) { |
|
22 | + $amount_min_limit = array('amount' => ((!empty($data['wpshop_coupon_mini_amount'])) ? $data['wpshop_coupon_mini_amount'] : null), 'shipping_rule' => ((!empty($data['wpshop_coupon_min_mount_shipping_rule'])) ? $data['wpshop_coupon_min_mount_shipping_rule'] : null)); |
|
23 | 23 | update_post_meta($data['post_ID'], 'wpshop_coupon_code', $data['coupon_code']); |
24 | - update_post_meta($data['post_ID'], 'wpshop_coupon_discount_value', floatval( str_replace(',', '.',$data['coupon_discount_amount']) ) ); |
|
24 | + update_post_meta($data['post_ID'], 'wpshop_coupon_discount_value', floatval(str_replace(',', '.', $data['coupon_discount_amount']))); |
|
25 | 25 | update_post_meta($data['post_ID'], 'wpshop_coupon_discount_type', $data['wpshop_coupon_discount_type']); |
26 | - update_post_meta($data['post_ID'], 'wpshop_coupon_individual_use', $data['coupon_receiver'] ); |
|
26 | + update_post_meta($data['post_ID'], 'wpshop_coupon_individual_use', $data['coupon_receiver']); |
|
27 | 27 | update_post_meta($data['post_ID'], 'wpshop_coupon_product_ids', ''); |
28 | 28 | update_post_meta($data['post_ID'], 'wpshop_coupon_exclude_product_ids', ''); |
29 | - update_post_meta($data['post_ID'], 'wpshop_coupon_usage_limit', $data['coupon_usage_limit'] ); |
|
29 | + update_post_meta($data['post_ID'], 'wpshop_coupon_usage_limit', $data['coupon_usage_limit']); |
|
30 | 30 | update_post_meta($data['post_ID'], 'wpshop_coupon_start_date', ''); |
31 | 31 | update_post_meta($data['post_ID'], 'wpshop_coupon_expiry_date', ''); |
32 | 32 | update_post_meta($data['post_ID'], 'wpshop_coupon_apply_before_tax', ''); |
@@ -42,15 +42,15 @@ discard block |
||
42 | 42 | * @param integer $coupon_id |
43 | 43 | * @return array |
44 | 44 | */ |
45 | - function get_coupon_data( $coupon_id ) { |
|
45 | + function get_coupon_data($coupon_id) { |
|
46 | 46 | global $wpdb; |
47 | - $coupon_id = ( !empty($coupon_id) ) ? $coupon_id : ( !empty($_SESSION['cart']['coupon_id']) ) ? $_SESSION['cart']['coupon_id'] : null ; |
|
48 | - if( !empty($coupon_id) ) { |
|
49 | - $query = $wpdb->prepare('SELECT meta_key, meta_value FROM ' . $wpdb->postmeta . ' WHERE post_id = %d', $coupon_id ); |
|
47 | + $coupon_id = (!empty($coupon_id)) ? $coupon_id : (!empty($_SESSION['cart']['coupon_id'])) ? $_SESSION['cart']['coupon_id'] : null; |
|
48 | + if (!empty($coupon_id)) { |
|
49 | + $query = $wpdb->prepare('SELECT meta_key, meta_value FROM ' . $wpdb->postmeta . ' WHERE post_id = %d', $coupon_id); |
|
50 | 50 | $coupons = $wpdb->get_results($query, ARRAY_A); |
51 | 51 | $coupon = array(); |
52 | 52 | $coupon['coupon_id'] = $coupon_id; |
53 | - foreach($coupons as $coupon_info){ |
|
53 | + foreach ($coupons as $coupon_info) { |
|
54 | 54 | $coupon[$coupon_info['meta_key']] = $coupon_info['meta_value']; |
55 | 55 | } |
56 | 56 | return $coupon; |
@@ -59,16 +59,16 @@ discard block |
||
59 | 59 | } |
60 | 60 | |
61 | 61 | /** Save an historic of coupon usage */ |
62 | - function save_coupon_use( $coupon_id ) { |
|
63 | - $coupon_use = get_post_meta( $coupon_id, '_wpshop_coupon_usage', true); |
|
62 | + function save_coupon_use($coupon_id) { |
|
63 | + $coupon_use = get_post_meta($coupon_id, '_wpshop_coupon_usage', true); |
|
64 | 64 | $user_id = get_current_user_id(); |
65 | 65 | |
66 | - if ( !empty($coupon_use[$user_id]) ) { |
|
66 | + if (!empty($coupon_use[$user_id])) { |
|
67 | 67 | $coupon_use[$user_id] = $coupon_use[$user_id] + 1; |
68 | 68 | } |
69 | 69 | else { |
70 | 70 | $coupon_use[$user_id] = 1; |
71 | 71 | } |
72 | - update_post_meta( $coupon_id, '_wpshop_coupon_usage', $coupon_use); |
|
72 | + update_post_meta($coupon_id, '_wpshop_coupon_usage', $coupon_use); |
|
73 | 73 | } |
74 | 74 | } |
75 | 75 | \ No newline at end of file |
@@ -1,4 +1,6 @@ |
||
1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
1 | +<?php if ( !defined( 'ABSPATH' ) ) { |
|
2 | + exit; |
|
3 | +} |
|
2 | 4 | class wpshop_customer_search { |
3 | 5 | |
4 | 6 | function __construct() { |
@@ -1,24 +1,24 @@ discard block |
||
1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
1 | +<?php if (!defined('ABSPATH')) exit; |
|
2 | 2 | class wpshop_customer_search { |
3 | 3 | |
4 | 4 | function __construct() { |
5 | - if ( is_admin() ) { |
|
6 | - add_filter( 'posts_where', array(&$this, 'wpshop_search_where_in_customer') ); |
|
5 | + if (is_admin()) { |
|
6 | + add_filter('posts_where', array(&$this, 'wpshop_search_where_in_customer')); |
|
7 | 7 | } |
8 | 8 | } |
9 | 9 | |
10 | - public function wpshop_search_where_in_customer( $where ) { |
|
11 | - $post_type = !empty( $_GET['post_type'] ) ? sanitize_text_field( $_GET['post_type'] ) : ''; |
|
12 | - $s = !empty( $_GET['s'] ) ? sanitize_text_field( $_GET['s'] ) : ''; |
|
13 | - $entity_filter = !empty( $_GET['filter'] ) ? sanitize_text_field( $_GET['filter'] ) : ''; |
|
10 | + public function wpshop_search_where_in_customer($where) { |
|
11 | + $post_type = !empty($_GET['post_type']) ? sanitize_text_field($_GET['post_type']) : ''; |
|
12 | + $s = !empty($_GET['s']) ? sanitize_text_field($_GET['s']) : ''; |
|
13 | + $entity_filter = !empty($_GET['filter']) ? sanitize_text_field($_GET['filter']) : ''; |
|
14 | 14 | |
15 | - if( is_admin() && ( !empty($post_type) && ( $post_type == WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS ) ) && ( !empty( $s ) || !empty( $entity_filter ) ) ) { |
|
15 | + if (is_admin() && (!empty($post_type) && ($post_type == WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS)) && (!empty($s) || !empty($entity_filter))) { |
|
16 | 16 | global $wpdb; |
17 | 17 | |
18 | 18 | $where = " AND {$wpdb->posts}.post_type = '" . WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS . "'"; |
19 | 19 | |
20 | - if( !empty( $entity_filter ) ) { |
|
21 | - switch ( $entity_filter ) { |
|
20 | + if (!empty($entity_filter)) { |
|
21 | + switch ($entity_filter) { |
|
22 | 22 | case 'orders': |
23 | 23 | $operator = 'IN'; |
24 | 24 | break; |
@@ -35,9 +35,9 @@ discard block |
||
35 | 35 | )"; |
36 | 36 | } |
37 | 37 | |
38 | - if( !empty( $s ) ) { |
|
39 | - $s_soundex = soundex( $s ); |
|
40 | - $s = strtoupper( $s ); |
|
38 | + if (!empty($s)) { |
|
39 | + $s_soundex = soundex($s); |
|
40 | + $s = strtoupper($s); |
|
41 | 41 | $where .= " AND ( {$wpdb->posts}.ID = '{$s}' |
42 | 42 | OR UPPER( {$wpdb->posts}.post_title ) LIKE '%{$s}%' |
43 | 43 | OR SOUNDEX( {$wpdb->posts}.post_title ) = '{$s_soundex}' |
@@ -93,6 +93,6 @@ discard block |
||
93 | 93 | |
94 | 94 | } |
95 | 95 | |
96 | -if ( class_exists("wpshop_customer_search") ) { |
|
96 | +if (class_exists("wpshop_customer_search")) { |
|
97 | 97 | $wpshop_customer_search = new wpshop_customer_search(); |
98 | 98 | } |
@@ -1,4 +1,6 @@ |
||
1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
1 | +<?php if ( !defined( 'ABSPATH' ) ) { |
|
2 | + exit; |
|
3 | +} |
|
2 | 4 | |
3 | 5 | /** Check if the plugin version is defined. If not defined script will be stopped here */ |
4 | 6 | if ( !defined( 'WPSHOP_VERSION' ) ) { |
@@ -1,11 +1,11 @@ discard block |
||
1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
1 | +<?php if (!defined('ABSPATH')) exit; |
|
2 | 2 | |
3 | 3 | /** Check if the plugin version is defined. If not defined script will be stopped here */ |
4 | -if ( !defined( 'WPSHOP_VERSION' ) ) { |
|
5 | - die( __("You are not allowed to use this service.", 'wpshop') ); |
|
4 | +if (!defined('WPSHOP_VERSION')) { |
|
5 | + die(__("You are not allowed to use this service.", 'wpshop')); |
|
6 | 6 | } |
7 | 7 | |
8 | -if ( !class_exists("wpshop_entity_filter") ) { |
|
8 | +if (!class_exists("wpshop_entity_filter")) { |
|
9 | 9 | class wpshop_entity_filter { |
10 | 10 | function __construct() { |
11 | 11 | add_action('restrict_manage_posts', array(&$this, 'wpshop_entity_filter')); |
@@ -13,8 +13,8 @@ discard block |
||
13 | 13 | } |
14 | 14 | |
15 | 15 | function wpshop_entity_filter() { |
16 | - $post_type = !empty( $_GET['post_type'] ) ? sanitize_text_field( $_GET['post_type'] ) : ''; |
|
17 | - $entity_filter = !empty( $_GET['entity_filter'] ) ? sanitize_text_field( $_GET['entity_filter'] ) : ''; |
|
16 | + $post_type = !empty($_GET['post_type']) ? sanitize_text_field($_GET['post_type']) : ''; |
|
17 | + $entity_filter = !empty($_GET['entity_filter']) ? sanitize_text_field($_GET['entity_filter']) : ''; |
|
18 | 18 | |
19 | 19 | if (isset($post_type)) { |
20 | 20 | if (post_type_exists($post_type) && ($post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT)) { |
@@ -33,13 +33,13 @@ discard block |
||
33 | 33 | function wpshop_entity_filter_parse_query($query) { |
34 | 34 | global $pagenow, $wpdb; |
35 | 35 | |
36 | - $post_type = !empty( $_GET['post_type'] ) ? sanitize_text_field( $_GET['post_type'] ) : ''; |
|
37 | - $entity_filter = !empty( $_GET['entity_filter'] ) ? sanitize_text_field( $_GET['entity_filter'] ) : ''; |
|
36 | + $post_type = !empty($_GET['post_type']) ? sanitize_text_field($_GET['post_type']) : ''; |
|
37 | + $entity_filter = !empty($_GET['entity_filter']) ? sanitize_text_field($_GET['entity_filter']) : ''; |
|
38 | 38 | |
39 | - if ( is_admin() && ($pagenow == 'edit.php') && !empty( $post_type ) && ( $post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT ) && !empty( $entity_filter ) ) { |
|
39 | + if (is_admin() && ($pagenow == 'edit.php') && !empty($post_type) && ($post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT) && !empty($entity_filter)) { |
|
40 | 40 | |
41 | 41 | $check = null; |
42 | - switch ( $entity_filter ) { |
|
42 | + switch ($entity_filter) { |
|
43 | 43 | case 'no_picture': |
44 | 44 | $sql_query = $wpdb->prepare("SELECT post_id FROM {$wpdb->postmeta} pm WHERE meta_key = %s ", '_thumbnail_id'); |
45 | 45 | $check = 'post__not_in'; |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | // $price_attribute = wpshop_attributes::getElement( WPSHOP_PRODUCT_PRICE_TTC, "'valid'", 'code'); |
50 | 50 | // $sql_query = $wpdb->prepare("SELECT DISTINCT ID as post_id FROM {$wpdb->posts} WHERE post_type = %s AND ID NOT IN (SELECT entity_id FROM {$table_attribute_decimal} WHERE value > 0 AND attribute_id = %d)", WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, $price_attribute->id); |
51 | 51 | // $check = 'post__in'; |
52 | - $query->set( 'meta_query' , array( |
|
52 | + $query->set('meta_query', array( |
|
53 | 53 | array( |
54 | 54 | 'key' => '_displayed_price', |
55 | 55 | 'value' => '', |
@@ -89,20 +89,20 @@ discard block |
||
89 | 89 | WHERE meta_key = %s |
90 | 90 | ) AND post_type = %s" |
91 | 91 | , "_barcode", WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, "_barcode", WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, "_barcode", WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION ); |
92 | - $options_product_without_barcode = $wpdb->get_results( $the_query ); |
|
93 | - if ( !empty( $options_product_without_barcode ) ) { |
|
94 | - foreach ( $options_product_without_barcode as $post ) { |
|
92 | + $options_product_without_barcode = $wpdb->get_results($the_query); |
|
93 | + if (!empty($options_product_without_barcode)) { |
|
94 | + foreach ($options_product_without_barcode as $post) { |
|
95 | 95 | $post_to_get[] = $post->post_parent; |
96 | 96 | } |
97 | 97 | } |
98 | 98 | /** If there are post that have variations without barcode => add them to the post list to get */ |
99 | - if ( !empty( $post_to_get ) ) { |
|
100 | - $query->query_vars[ 'post__in' ] = $post_to_get; |
|
99 | + if (!empty($post_to_get)) { |
|
100 | + $query->query_vars['post__in'] = $post_to_get; |
|
101 | 101 | } |
102 | 102 | break; |
103 | 103 | case 'no_barcode_products': |
104 | 104 | /** Check all product that don't have a barcode or having a barcode containing PDCT */ |
105 | - $query->set( 'meta_query' , array( |
|
105 | + $query->set('meta_query', array( |
|
106 | 106 | 'relation' => 'OR', |
107 | 107 | array( |
108 | 108 | 'key' => '_barcode', |
@@ -118,10 +118,10 @@ discard block |
||
118 | 118 | break; |
119 | 119 | } |
120 | 120 | |
121 | - if ( !empty( $check ) ) { |
|
121 | + if (!empty($check)) { |
|
122 | 122 | $results = $wpdb->get_results($sql_query); |
123 | 123 | $post_id_list = array(); |
124 | - foreach($results as $item){ |
|
124 | + foreach ($results as $item) { |
|
125 | 125 | $post_id_list[] = $item->post_id; |
126 | 126 | } |
127 | 127 | $query->query_vars[$check] = $post_id_list; |
@@ -2,8 +2,8 @@ |
||
2 | 2 | class wps_filter_search { |
3 | 3 | |
4 | 4 | /** Define the main directory containing the template for the current plugin |
5 | - * @var string |
|
6 | - */ |
|
5 | + * @var string |
|
6 | + */ |
|
7 | 7 | private $template_dir; |
8 | 8 | /** |
9 | 9 | * Define the directory name for the module in order to check into frontend |
@@ -1,4 +1,4 @@ discard block |
||
1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
1 | +<?php if (!defined('ABSPATH')) exit; |
|
2 | 2 | class wps_filter_search { |
3 | 3 | |
4 | 4 | /** Define the main directory containing the template for the current plugin |
@@ -16,24 +16,24 @@ discard block |
||
16 | 16 | // Template Load |
17 | 17 | $this->template_dir = WPS_SEARCH_PATH . WPS_SEARCH_DIR . "/templates/"; |
18 | 18 | // Display Filter search |
19 | - add_shortcode('wpshop_filter_search', array( $this, 'display_filter_search')); |
|
19 | + add_shortcode('wpshop_filter_search', array($this, 'display_filter_search')); |
|
20 | 20 | |
21 | 21 | // WP General actions |
22 | 22 | add_action('save_post', 'wps_filter_search::save_displayed_price_meta'); |
23 | 23 | add_action('save_post', array(&$this, 'stock_values_for_attribute')); |
24 | 24 | |
25 | 25 | // Add scripts |
26 | - add_action( 'wp_enqueue_scripts', array( &$this, 'add_frontend_scripts' ) ); |
|
26 | + add_action('wp_enqueue_scripts', array(&$this, 'add_frontend_scripts')); |
|
27 | 27 | |
28 | 28 | // Ajax Actions |
29 | - add_action('wp_ajax_filter_search_action',array(&$this, 'wpshop_ajax_filter_search_action')); |
|
30 | - add_action('wp_ajax_nopriv_filter_search_action',array(&$this, 'wpshop_ajax_filter_search_action')); |
|
29 | + add_action('wp_ajax_filter_search_action', array(&$this, 'wpshop_ajax_filter_search_action')); |
|
30 | + add_action('wp_ajax_nopriv_filter_search_action', array(&$this, 'wpshop_ajax_filter_search_action')); |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | |
34 | 34 | function add_frontend_scripts() { |
35 | - wp_enqueue_script( 'wpshop_filter_search_chosen', WPSHOP_JS_URL.'jquery-libs/chosen.jquery.min.js' ); |
|
36 | - wp_enqueue_script( 'wpshop_filter_search_js', WPS_SEARCH_URL.WPS_SEARCH_DIR.'/assets/filter_search/js/wpshop_filter_search.js' ); |
|
35 | + wp_enqueue_script('wpshop_filter_search_chosen', WPSHOP_JS_URL . 'jquery-libs/chosen.jquery.min.js'); |
|
36 | + wp_enqueue_script('wpshop_filter_search_js', WPS_SEARCH_URL . WPS_SEARCH_DIR . '/assets/filter_search/js/wpshop_filter_search.js'); |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | |
@@ -41,14 +41,14 @@ discard block |
||
41 | 41 | * Display Filter search interface |
42 | 42 | * @return string |
43 | 43 | */ |
44 | - function display_filter_search () { |
|
44 | + function display_filter_search() { |
|
45 | 45 | global $wp_query; |
46 | 46 | $output = ''; |
47 | - if ( !empty($wp_query) && !empty($wp_query->queried_object_id) ) { |
|
47 | + if (!empty($wp_query) && !empty($wp_query->queried_object_id)) { |
|
48 | 48 | $category_id = $wp_query->queried_object_id; |
49 | - $category_option = get_option('wpshop_product_category_'.$category_id); |
|
50 | - if ( !empty($category_option) && !empty($category_option['wpshop_category_filterable_attributes']) ) { |
|
51 | - $output = $this->construct_wpshop_filter_search_interface( $category_id ); |
|
49 | + $category_option = get_option('wpshop_product_category_' . $category_id); |
|
50 | + if (!empty($category_option) && !empty($category_option['wpshop_category_filterable_attributes'])) { |
|
51 | + $output = $this->construct_wpshop_filter_search_interface($category_id); |
|
52 | 52 | } |
53 | 53 | } |
54 | 54 | return $output; |
@@ -59,19 +59,19 @@ discard block |
||
59 | 59 | * @param integer $category_id |
60 | 60 | * @return string |
61 | 61 | */ |
62 | - function construct_wpshop_filter_search_interface ( $category_id ) { |
|
62 | + function construct_wpshop_filter_search_interface($category_id) { |
|
63 | 63 | global $wpdb; |
64 | 64 | $filter_elements = ''; |
65 | - if ( !empty($category_id) ) { |
|
66 | - $category_option = get_option('wpshop_product_category_'.$category_id); |
|
67 | - if ( !empty($category_option) && !empty($category_option['wpshop_category_filterable_attributes']) && is_array($category_option['wpshop_category_filterable_attributes']) ) { |
|
68 | - foreach ( $category_option['wpshop_category_filterable_attributes'] as $k => $attribute ) { |
|
65 | + if (!empty($category_id)) { |
|
66 | + $category_option = get_option('wpshop_product_category_' . $category_id); |
|
67 | + if (!empty($category_option) && !empty($category_option['wpshop_category_filterable_attributes']) && is_array($category_option['wpshop_category_filterable_attributes'])) { |
|
68 | + foreach ($category_option['wpshop_category_filterable_attributes'] as $k => $attribute) { |
|
69 | 69 | $attribute_def = wpshop_attributes::getElement($k); |
70 | - $filter_elements .= $this->construct_element( $attribute_def, $category_id ); |
|
70 | + $filter_elements .= $this->construct_element($attribute_def, $category_id); |
|
71 | 71 | $unity = ''; |
72 | - if ( !empty($attribute_def->_default_unit) ) { |
|
73 | - $query = $wpdb->prepare('SELECT unit FROM ' .WPSHOP_DBT_ATTRIBUTE_UNIT. ' WHERE id= %d', $attribute_def->_default_unit); |
|
74 | - $unity = $wpdb->get_var( $query ); |
|
72 | + if (!empty($attribute_def->_default_unit)) { |
|
73 | + $query = $wpdb->prepare('SELECT unit FROM ' . WPSHOP_DBT_ATTRIBUTE_UNIT . ' WHERE id= %d', $attribute_def->_default_unit); |
|
74 | + $unity = $wpdb->get_var($query); |
|
75 | 75 | } |
76 | 76 | |
77 | 77 | //$tpl_component['DEFAULT_UNITY'.'_'.$attribute_def->code] = $unity; |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | } |
80 | 80 | } |
81 | 81 | ob_start(); |
82 | - require( wpshop_tools::get_template_part( WPS_SEARCH_DIR, $this->template_dir, "frontend", "filter_search/filter_search_interface") ); |
|
82 | + require(wpshop_tools::get_template_part(WPS_SEARCH_DIR, $this->template_dir, "frontend", "filter_search/filter_search_interface")); |
|
83 | 83 | $filter_search_interface = ob_get_contents(); |
84 | 84 | ob_end_clean(); |
85 | 85 | return $filter_search_interface; |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | * @param integer $category_id |
92 | 92 | * @return string |
93 | 93 | */ |
94 | - function construct_element ( $attribute_def, $category_id ) { |
|
94 | + function construct_element($attribute_def, $category_id) { |
|
95 | 95 | global $wpdb; |
96 | 96 | $current_category_children = array(); |
97 | 97 | $args = array( |
@@ -101,27 +101,27 @@ discard block |
||
101 | 101 | ); |
102 | 102 | $current_category_children = get_categories($args); |
103 | 103 | |
104 | - if ( !empty( $attribute_def ) ) { |
|
105 | - switch ( $attribute_def->frontend_input ) { |
|
104 | + if (!empty($attribute_def)) { |
|
105 | + switch ($attribute_def->frontend_input) { |
|
106 | 106 | case 'text' : |
107 | - if ( $attribute_def->data_type == 'decimal' || $attribute_def->data_type == 'integer') { |
|
108 | - return $this->get_filter_element_for_integer_data( $attribute_def, $category_id, $current_category_children ); |
|
107 | + if ($attribute_def->data_type == 'decimal' || $attribute_def->data_type == 'integer') { |
|
108 | + return $this->get_filter_element_for_integer_data($attribute_def, $category_id, $current_category_children); |
|
109 | 109 | } |
110 | 110 | else { |
111 | - return $this->get_filter_element_for_text_data( $attribute_def, $category_id, $current_category_children ); |
|
111 | + return $this->get_filter_element_for_text_data($attribute_def, $category_id, $current_category_children); |
|
112 | 112 | } |
113 | 113 | break; |
114 | 114 | |
115 | 115 | case 'select' : case 'multiple-select' : |
116 | - return $this->get_filter_element_for_list_data ( $attribute_def, $category_id, $current_category_children, $attribute_def->frontend_input, 'select'); |
|
116 | + return $this->get_filter_element_for_list_data($attribute_def, $category_id, $current_category_children, $attribute_def->frontend_input, 'select'); |
|
117 | 117 | break; |
118 | 118 | |
119 | 119 | case 'checkbox' : |
120 | - return $this->get_filter_element_for_list_data ( $attribute_def, $category_id, $current_category_children, $attribute_def->frontend_input, 'checkbox'); |
|
120 | + return $this->get_filter_element_for_list_data($attribute_def, $category_id, $current_category_children, $attribute_def->frontend_input, 'checkbox'); |
|
121 | 121 | break; |
122 | 122 | |
123 | 123 | case 'radio' : |
124 | - return $this->get_filter_element_for_list_data ( $attribute_def, $category_id, $current_category_children, $attribute_def->frontend_input, 'radio' ); |
|
124 | + return $this->get_filter_element_for_list_data($attribute_def, $category_id, $current_category_children, $attribute_def->frontend_input, 'radio'); |
|
125 | 125 | break; |
126 | 126 | |
127 | 127 | } |
@@ -133,20 +133,20 @@ discard block |
||
133 | 133 | * @param StdObject $attribute_def |
134 | 134 | * @return string |
135 | 135 | */ |
136 | - function get_filter_element_for_text_data( $attribute_def, $category_id, $current_category_child ) { |
|
136 | + function get_filter_element_for_text_data($attribute_def, $category_id, $current_category_child) { |
|
137 | 137 | global $wpdb; |
138 | 138 | $output = ''; |
139 | - $category_option = get_option('wpshop_product_category_'.$category_id); |
|
139 | + $category_option = get_option('wpshop_product_category_' . $category_id); |
|
140 | 140 | $list_values = ''; |
141 | 141 | |
142 | - if ( !empty($category_option) && !empty($category_option['wpshop_category_filterable_attributes']) && !empty($category_option['wpshop_category_filterable_attributes'][$attribute_def->id]) && is_array($category_option['wpshop_category_filterable_attributes'][$attribute_def->id]) ) { |
|
143 | - foreach( $category_option['wpshop_category_filterable_attributes'][$attribute_def->id] as $attribute_value ) { |
|
144 | - $list_values .= '<option value="' .$attribute_value. '">' .$attribute_value. '</option>'; |
|
142 | + if (!empty($category_option) && !empty($category_option['wpshop_category_filterable_attributes']) && !empty($category_option['wpshop_category_filterable_attributes'][$attribute_def->id]) && is_array($category_option['wpshop_category_filterable_attributes'][$attribute_def->id])) { |
|
143 | + foreach ($category_option['wpshop_category_filterable_attributes'][$attribute_def->id] as $attribute_value) { |
|
144 | + $list_values .= '<option value="' . $attribute_value . '">' . $attribute_value . '</option>'; |
|
145 | 145 | } |
146 | 146 | |
147 | 147 | } |
148 | 148 | ob_start(); |
149 | - require( wpshop_tools::get_template_part( WPS_SEARCH_DIR, $this->template_dir, "frontend", "filter_search/filter_elements/element_combobox") ); |
|
149 | + require(wpshop_tools::get_template_part(WPS_SEARCH_DIR, $this->template_dir, "frontend", "filter_search/filter_elements/element_combobox")); |
|
150 | 150 | $output = ob_get_contents(); |
151 | 151 | ob_end_clean(); |
152 | 152 | return $output; |
@@ -157,77 +157,77 @@ discard block |
||
157 | 157 | * @param StdObject $attribute_def |
158 | 158 | * @return string |
159 | 159 | */ |
160 | - function get_filter_element_for_list_data ( $attribute_def, $category_id, $current_category_child, $field_type, $type = 'select') { |
|
160 | + function get_filter_element_for_list_data($attribute_def, $category_id, $current_category_child, $field_type, $type = 'select') { |
|
161 | 161 | global $wpdb; |
162 | 162 | $output = $list_values = ''; |
163 | - $category_option = get_option('wpshop_product_category_'.$category_id); |
|
164 | - if ( !empty( $attribute_def) ){ |
|
163 | + $category_option = get_option('wpshop_product_category_' . $category_id); |
|
164 | + if (!empty($attribute_def)) { |
|
165 | 165 | // Recovery values |
166 | - if ( !empty($category_option) && !empty($category_option['wpshop_category_filterable_attributes']) && isset($category_option['wpshop_category_filterable_attributes'][$attribute_def->id]) ) { |
|
166 | + if (!empty($category_option) && !empty($category_option['wpshop_category_filterable_attributes']) && isset($category_option['wpshop_category_filterable_attributes'][$attribute_def->id])) { |
|
167 | 167 | $available_attribute_values = $category_option['wpshop_category_filterable_attributes'][$attribute_def->id]; |
168 | 168 | } |
169 | 169 | |
170 | 170 | // Store options for attribute |
171 | 171 | $stored_available_attribute_values = array(); |
172 | - $query = $wpdb->prepare( 'SELECT * FROM ' .WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS .' WHERE attribute_id = %d ORDER BY position ASC', $attribute_def->id); |
|
173 | - $attributes_options = $wpdb->get_results( $query ); |
|
174 | - if ( $attribute_def->data_type_to_use == 'internal') { |
|
175 | - if ( !empty( $attribute_def->default_value ) ) { |
|
172 | + $query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE attribute_id = %d ORDER BY position ASC', $attribute_def->id); |
|
173 | + $attributes_options = $wpdb->get_results($query); |
|
174 | + if ($attribute_def->data_type_to_use == 'internal') { |
|
175 | + if (!empty($attribute_def->default_value)) { |
|
176 | 176 | $attribute_default_value = $attribute_def->default_value; |
177 | 177 | $attribute_default_value = unserialize($attribute_default_value); |
178 | 178 | |
179 | - $query = $wpdb->prepare( 'SELECT * FROM ' .$wpdb->posts. ' WHERE post_type = %s ORDER BY menu_order ASC', $attribute_default_value['default_value']); |
|
180 | - $elements = $wpdb->get_results( $query ); |
|
179 | + $query = $wpdb->prepare('SELECT * FROM ' . $wpdb->posts . ' WHERE post_type = %s ORDER BY menu_order ASC', $attribute_default_value['default_value']); |
|
180 | + $elements = $wpdb->get_results($query); |
|
181 | 181 | |
182 | - if ( !empty( $elements) ) { |
|
183 | - foreach ( $elements as $element ) { |
|
184 | - if ( array_key_exists($element->ID,$available_attribute_values ) ) { |
|
185 | - $stored_available_attribute_values[] = array( 'option_id' => $element->ID, 'option_label' => $element->post_title ); |
|
182 | + if (!empty($elements)) { |
|
183 | + foreach ($elements as $element) { |
|
184 | + if (array_key_exists($element->ID, $available_attribute_values)) { |
|
185 | + $stored_available_attribute_values[] = array('option_id' => $element->ID, 'option_label' => $element->post_title); |
|
186 | 186 | } |
187 | 187 | } |
188 | 188 | } |
189 | 189 | } |
190 | 190 | } |
191 | 191 | else { |
192 | - foreach ( $attributes_options as $attributes_option ) { |
|
193 | - if ( in_array($attributes_option->label, $available_attribute_values) ) { |
|
194 | - $key_value = array_search( $attributes_option->label, $available_attribute_values); |
|
195 | - $stored_available_attribute_values[] = array('option_id' => $key_value, 'option_label' => $attributes_option->label ); |
|
192 | + foreach ($attributes_options as $attributes_option) { |
|
193 | + if (in_array($attributes_option->label, $available_attribute_values)) { |
|
194 | + $key_value = array_search($attributes_option->label, $available_attribute_values); |
|
195 | + $stored_available_attribute_values[] = array('option_id' => $key_value, 'option_label' => $attributes_option->label); |
|
196 | 196 | } |
197 | 197 | } |
198 | 198 | } |
199 | 199 | // Sort Stored values |
200 | - ksort( $stored_available_attribute_values); |
|
201 | - if ( !empty($stored_available_attribute_values) && is_array($stored_available_attribute_values) ) { |
|
200 | + ksort($stored_available_attribute_values); |
|
201 | + if (!empty($stored_available_attribute_values) && is_array($stored_available_attribute_values)) { |
|
202 | 202 | // Construct List values |
203 | - foreach( $stored_available_attribute_values as $stored_available_attribute_value ) { |
|
204 | - $list_values .= '<option value="' .$stored_available_attribute_value['option_id']. '">' .$stored_available_attribute_value['option_label']. '</option>'; |
|
203 | + foreach ($stored_available_attribute_values as $stored_available_attribute_value) { |
|
204 | + $list_values .= '<option value="' . $stored_available_attribute_value['option_id'] . '">' . $stored_available_attribute_value['option_label'] . '</option>'; |
|
205 | 205 | } |
206 | 206 | |
207 | 207 | // Display the good template file |
208 | - switch( $type ) { |
|
208 | + switch ($type) { |
|
209 | 209 | case 'radio' : |
210 | 210 | ob_start(); |
211 | - require( wpshop_tools::get_template_part( WPS_SEARCH_DIR, $this->template_dir, "frontend", "filter_search/filter_elements/element_radiobox") ); |
|
211 | + require(wpshop_tools::get_template_part(WPS_SEARCH_DIR, $this->template_dir, "frontend", "filter_search/filter_elements/element_radiobox")); |
|
212 | 212 | $output = ob_get_contents(); |
213 | 213 | ob_end_clean(); |
214 | 214 | break; |
215 | 215 | case 'checkbox' : |
216 | 216 | ob_start(); |
217 | - require( wpshop_tools::get_template_part( WPS_SEARCH_DIR, $this->template_dir, "frontend", "filter_search/filter_elements/element_checkbox") ); |
|
217 | + require(wpshop_tools::get_template_part(WPS_SEARCH_DIR, $this->template_dir, "frontend", "filter_search/filter_elements/element_checkbox")); |
|
218 | 218 | $output = ob_get_contents(); |
219 | 219 | ob_end_clean(); |
220 | 220 | break; |
221 | 221 | default : |
222 | - if ( $field_type == 'multiple-select' ) { |
|
222 | + if ($field_type == 'multiple-select') { |
|
223 | 223 | ob_start(); |
224 | - require( wpshop_tools::get_template_part( WPS_SEARCH_DIR, $this->template_dir, "frontend", "filter_search/filter_elements/element_multiple_select") ); |
|
224 | + require(wpshop_tools::get_template_part(WPS_SEARCH_DIR, $this->template_dir, "frontend", "filter_search/filter_elements/element_multiple_select")); |
|
225 | 225 | $output = ob_get_contents(); |
226 | 226 | ob_end_clean(); |
227 | 227 | } |
228 | 228 | else { |
229 | 229 | ob_start(); |
230 | - require( wpshop_tools::get_template_part( WPS_SEARCH_DIR, $this->template_dir, "frontend", "filter_search/filter_elements/element_combobox") ); |
|
230 | + require(wpshop_tools::get_template_part(WPS_SEARCH_DIR, $this->template_dir, "frontend", "filter_search/filter_elements/element_combobox")); |
|
231 | 231 | $output = ob_get_contents(); |
232 | 232 | ob_end_clean(); |
233 | 233 | } |
@@ -243,20 +243,20 @@ discard block |
||
243 | 243 | * @param StdObject $attribute_def |
244 | 244 | * @return string |
245 | 245 | */ |
246 | - function get_filter_element_for_integer_data ( $attribute_def, $category_id, $current_category_children ) { |
|
246 | + function get_filter_element_for_integer_data($attribute_def, $category_id, $current_category_children) { |
|
247 | 247 | $min_value = $max_value = 0; |
248 | 248 | $sub_tpl_component = array(); |
249 | 249 | $output = ''; |
250 | 250 | $first = true; |
251 | 251 | /** Get allproducts of category **/ |
252 | - $category_product_ids = wpshop_categories::get_product_of_category( $category_id ); |
|
253 | - $category_option = get_option('wpshop_product_category_'.$category_id ); |
|
254 | - $amount_min = ( !empty($category_option['wpshop_category_filterable_attributes'][$attribute_def->id]['min']) ) ? number_format($category_option['wpshop_category_filterable_attributes'][$attribute_def->id]['min'],2, '.', '') : 0; |
|
255 | - $amount_max = ( !empty($category_option['wpshop_category_filterable_attributes'][$attribute_def->id]['max']) ) ? number_format($category_option['wpshop_category_filterable_attributes'][$attribute_def->id]['max'],2, '.', '') : 0; |
|
252 | + $category_product_ids = wpshop_categories::get_product_of_category($category_id); |
|
253 | + $category_option = get_option('wpshop_product_category_' . $category_id); |
|
254 | + $amount_min = (!empty($category_option['wpshop_category_filterable_attributes'][$attribute_def->id]['min'])) ? number_format($category_option['wpshop_category_filterable_attributes'][$attribute_def->id]['min'], 2, '.', '') : 0; |
|
255 | + $amount_max = (!empty($category_option['wpshop_category_filterable_attributes'][$attribute_def->id]['max'])) ? number_format($category_option['wpshop_category_filterable_attributes'][$attribute_def->id]['max'], 2, '.', '') : 0; |
|
256 | 256 | |
257 | - if ( !empty($category_option) && !empty($category_option['wpshop_category_filterable_attributes']) && !empty($category_option['wpshop_category_filterable_attributes'][$attribute_def->id]) ) { |
|
257 | + if (!empty($category_option) && !empty($category_option['wpshop_category_filterable_attributes']) && !empty($category_option['wpshop_category_filterable_attributes'][$attribute_def->id])) { |
|
258 | 258 | ob_start(); |
259 | - require( wpshop_tools::get_template_part( WPS_SEARCH_DIR, $this->template_dir, "frontend", "filter_search/filter_elements/element_slider") ); |
|
259 | + require(wpshop_tools::get_template_part(WPS_SEARCH_DIR, $this->template_dir, "frontend", "filter_search/filter_elements/element_slider")); |
|
260 | 260 | $output = ob_get_contents(); |
261 | 261 | ob_end_clean(); |
262 | 262 | |
@@ -270,17 +270,17 @@ discard block |
||
270 | 270 | * @param std_object $attribute_def |
271 | 271 | * @param array $current_category_child |
272 | 272 | */ |
273 | - function save_values_for_list_filterable_attribute( $category_id, $attribute_def, $current_category_children ) { |
|
273 | + function save_values_for_list_filterable_attribute($category_id, $attribute_def, $current_category_children) { |
|
274 | 274 | global $wpdb; |
275 | - $category_option = get_option('wpshop_product_category_'.$category_id); |
|
276 | - $products = wpshop_categories::get_product_of_category( $category_id ); |
|
275 | + $category_option = get_option('wpshop_product_category_' . $category_id); |
|
276 | + $products = wpshop_categories::get_product_of_category($category_id); |
|
277 | 277 | /** If there are sub-categories take all products of sub-categories **/ |
278 | - if ( !empty($current_category_children) ) { |
|
279 | - foreach ( $current_category_children as $current_category_child ) { |
|
280 | - $sub_categories_product_ids = wpshop_categories::get_product_of_category( $current_category_child->term_taxonomy_id ); |
|
281 | - if ( !empty($sub_categories_product_ids) ) { |
|
282 | - foreach ( $sub_categories_product_ids as $sub_categories_product_id ) { |
|
283 | - if ( !in_array($sub_categories_product_id, $products) ) { |
|
278 | + if (!empty($current_category_children)) { |
|
279 | + foreach ($current_category_children as $current_category_child) { |
|
280 | + $sub_categories_product_ids = wpshop_categories::get_product_of_category($current_category_child->term_taxonomy_id); |
|
281 | + if (!empty($sub_categories_product_ids)) { |
|
282 | + foreach ($sub_categories_product_ids as $sub_categories_product_id) { |
|
283 | + if (!in_array($sub_categories_product_id, $products)) { |
|
284 | 284 | $products[] = $sub_categories_product_id; |
285 | 285 | } |
286 | 286 | } |
@@ -289,33 +289,33 @@ discard block |
||
289 | 289 | } |
290 | 290 | |
291 | 291 | |
292 | - if ( !empty($category_option) && !empty($category_option['wpshop_category_filterable_attributes']) && !empty($category_option['wpshop_category_filterable_attributes'][$attribute_def->id]) ) { |
|
292 | + if (!empty($category_option) && !empty($category_option['wpshop_category_filterable_attributes']) && !empty($category_option['wpshop_category_filterable_attributes'][$attribute_def->id])) { |
|
293 | 293 | $category_option['wpshop_category_filterable_attributes'][$attribute_def->id] = array(); |
294 | 294 | } |
295 | 295 | |
296 | 296 | |
297 | - if ( !empty( $attribute_def) ){ |
|
297 | + if (!empty($attribute_def)) { |
|
298 | 298 | $available_attribute_values = array(); |
299 | 299 | $test = array(); |
300 | - foreach ( $products as $product ) { |
|
301 | - $available_attribute_values = array_merge( $available_attribute_values, wpshop_attributes::get_affected_value_for_list( $attribute_def->code, $product, $attribute_def->data_type_to_use) ) ; |
|
300 | + foreach ($products as $product) { |
|
301 | + $available_attribute_values = array_merge($available_attribute_values, wpshop_attributes::get_affected_value_for_list($attribute_def->code, $product, $attribute_def->data_type_to_use)); |
|
302 | 302 | } |
303 | 303 | |
304 | 304 | $available_attribute_values = array_flip($available_attribute_values); |
305 | 305 | $data_to_save = array(); |
306 | - if ( !empty($available_attribute_values) ) { |
|
306 | + if (!empty($available_attribute_values)) { |
|
307 | 307 | $data_to_save = array(); |
308 | - foreach( $available_attribute_values as $k => $available_attribute_value ) { |
|
309 | - if ( $attribute_def->data_type_to_use == 'internal' ) { |
|
310 | - $attribute_name = get_the_title( $k ); |
|
308 | + foreach ($available_attribute_values as $k => $available_attribute_value) { |
|
309 | + if ($attribute_def->data_type_to_use == 'internal') { |
|
310 | + $attribute_name = get_the_title($k); |
|
311 | 311 | } |
312 | 312 | else { |
313 | - $query = $wpdb->prepare( 'SELECT label FROM ' .WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS. ' WHERE attribute_id = %d AND id = %d', $attribute_def->id, $k); |
|
313 | + $query = $wpdb->prepare('SELECT label FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE attribute_id = %d AND id = %d', $attribute_def->id, $k); |
|
314 | 314 | |
315 | - $attribute_name = $wpdb->get_var( $query ); |
|
315 | + $attribute_name = $wpdb->get_var($query); |
|
316 | 316 | } |
317 | - if (!empty($attribute_name) && !empty($k) ) { |
|
318 | - if ( !empty($category_option) && !empty($category_option['wpshop_category_filterable_attributes']) && isset($category_option['wpshop_category_filterable_attributes'][$attribute_def->id]) ) { |
|
317 | + if (!empty($attribute_name) && !empty($k)) { |
|
318 | + if (!empty($category_option) && !empty($category_option['wpshop_category_filterable_attributes']) && isset($category_option['wpshop_category_filterable_attributes'][$attribute_def->id])) { |
|
319 | 319 | $data_to_save[$k] = $attribute_name; |
320 | 320 | $category_option['wpshop_category_filterable_attributes'][$attribute_def->id] = $data_to_save; |
321 | 321 | } |
@@ -323,7 +323,7 @@ discard block |
||
323 | 323 | } |
324 | 324 | } |
325 | 325 | } |
326 | - update_option('wpshop_product_category_'.$category_id, $category_option); |
|
326 | + update_option('wpshop_product_category_' . $category_id, $category_option); |
|
327 | 327 | } |
328 | 328 | |
329 | 329 | /** |
@@ -332,18 +332,18 @@ discard block |
||
332 | 332 | * @param std_object $attribute_def |
333 | 333 | * @param array $current_category_child |
334 | 334 | */ |
335 | - function save_values_for_integer_filterable_attribute ( $category_id, $attribute_def, $current_category_child ) { |
|
335 | + function save_values_for_integer_filterable_attribute($category_id, $attribute_def, $current_category_child) { |
|
336 | 336 | $first = true; |
337 | - $category_option = get_option('wpshop_product_category_'.$category_id); |
|
338 | - $category_product_ids = wpshop_categories::get_product_of_category( $category_id ); |
|
337 | + $category_option = get_option('wpshop_product_category_' . $category_id); |
|
338 | + $category_product_ids = wpshop_categories::get_product_of_category($category_id); |
|
339 | 339 | $min_value = $max_value = 0; |
340 | 340 | /** If there are sub-categories take all products of sub-categories **/ |
341 | - if ( !empty($current_category_children) ) { |
|
342 | - foreach ( $current_category_children as $current_category_child ) { |
|
343 | - $sub_categories_product_ids = wpshop_categories::get_product_of_category( $current_category_child->term_taxonomy_id ); |
|
344 | - if ( !empty($sub_categories_product_ids) ) { |
|
345 | - foreach ( $sub_categories_product_ids as $sub_categories_product_id ) { |
|
346 | - if ( !in_array($sub_categories_product_id, $category_product_ids) ) { |
|
341 | + if (!empty($current_category_children)) { |
|
342 | + foreach ($current_category_children as $current_category_child) { |
|
343 | + $sub_categories_product_ids = wpshop_categories::get_product_of_category($current_category_child->term_taxonomy_id); |
|
344 | + if (!empty($sub_categories_product_ids)) { |
|
345 | + foreach ($sub_categories_product_ids as $sub_categories_product_id) { |
|
346 | + if (!in_array($sub_categories_product_id, $category_product_ids)) { |
|
347 | 347 | $category_product_ids[] = $sub_categories_product_id; |
348 | 348 | } |
349 | 349 | } |
@@ -352,45 +352,45 @@ discard block |
||
352 | 352 | } |
353 | 353 | |
354 | 354 | /** For each product of category check the value **/ |
355 | - if ( !empty( $category_product_ids ) ) { |
|
355 | + if (!empty($category_product_ids)) { |
|
356 | 356 | $price_piloting_option = get_option('wpshop_shop_price_piloting'); |
357 | 357 | foreach ($category_product_ids as $category_product_id) { |
358 | 358 | |
359 | - if ( $attribute_def->code == WPSHOP_PRODUCT_PRICE_TTC || $attribute_def->code == WPSHOP_PRODUCT_PRICE_HT ) { |
|
359 | + if ($attribute_def->code == WPSHOP_PRODUCT_PRICE_TTC || $attribute_def->code == WPSHOP_PRODUCT_PRICE_HT) { |
|
360 | 360 | |
361 | 361 | $product_infos = wpshop_products::get_product_data($category_product_id); |
362 | 362 | $product_price_infos = wpshop_prices::check_product_price($product_infos); |
363 | - if (!empty($product_price_infos) && !empty($product_price_infos['fork_price']) && !empty($product_price_infos['fork_price']['have_fork_price']) && $product_price_infos['fork_price']['have_fork_price'] ) { |
|
363 | + if (!empty($product_price_infos) && !empty($product_price_infos['fork_price']) && !empty($product_price_infos['fork_price']['have_fork_price']) && $product_price_infos['fork_price']['have_fork_price']) { |
|
364 | 364 | |
365 | 365 | |
366 | - $max_value = ( !empty($product_price_infos['fork_price']['max_product_price']) && $product_price_infos['fork_price']['max_product_price'] > $max_value ) ? $product_price_infos['fork_price']['max_product_price'] : $max_value; |
|
367 | - $min_value = (!empty($product_price_infos['fork_price']['min_product_price']) && ( ( $product_price_infos['fork_price']['min_product_price'] < $min_value) || $first ) ) ? $product_price_infos['fork_price']['min_product_price'] : $min_value; |
|
366 | + $max_value = (!empty($product_price_infos['fork_price']['max_product_price']) && $product_price_infos['fork_price']['max_product_price'] > $max_value) ? $product_price_infos['fork_price']['max_product_price'] : $max_value; |
|
367 | + $min_value = (!empty($product_price_infos['fork_price']['min_product_price']) && (($product_price_infos['fork_price']['min_product_price'] < $min_value) || $first)) ? $product_price_infos['fork_price']['min_product_price'] : $min_value; |
|
368 | 368 | } |
369 | 369 | else { |
370 | - if (!empty($product_price_infos) && !empty($product_price_infos['discount']) && !empty($product_price_infos['discount']['discount_exist'] ) && $product_price_infos['discount']['discount_exist'] ) { |
|
371 | - $product_data = (!empty($price_piloting_option) && $price_piloting_option == 'HT') ? $product_price_infos['discount']['discount_et_price'] : $product_price_infos['discount']['discount_ati_price']; |
|
370 | + if (!empty($product_price_infos) && !empty($product_price_infos['discount']) && !empty($product_price_infos['discount']['discount_exist']) && $product_price_infos['discount']['discount_exist']) { |
|
371 | + $product_data = (!empty($price_piloting_option) && $price_piloting_option == 'HT') ? $product_price_infos['discount']['discount_et_price'] : $product_price_infos['discount']['discount_ati_price']; |
|
372 | 372 | |
373 | 373 | } |
374 | 374 | else { |
375 | 375 | |
376 | - $product_data = (!empty($price_piloting_option) && $price_piloting_option == 'HT') ? $product_price_infos['et'] : $product_price_infos['ati']; |
|
376 | + $product_data = (!empty($price_piloting_option) && $price_piloting_option == 'HT') ? $product_price_infos['et'] : $product_price_infos['ati']; |
|
377 | 377 | } |
378 | - $max_value = ( !empty($product_data) && $product_data > $max_value ) ? $product_data : $max_value; |
|
379 | - $min_value = (!empty($product_data) && ( ( $product_data < $min_value) || $first ) ) ? $product_data : $min_value; |
|
378 | + $max_value = (!empty($product_data) && $product_data > $max_value) ? $product_data : $max_value; |
|
379 | + $min_value = (!empty($product_data) && (($product_data < $min_value) || $first)) ? $product_data : $min_value; |
|
380 | 380 | } |
381 | 381 | } |
382 | 382 | else { |
383 | 383 | $product_postmeta = get_post_meta($category_product_id, WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, true); |
384 | 384 | $product_data = $product_postmeta[$attribute_def->code]; |
385 | - $max_value = ( !empty($product_data) && $product_data > $max_value ) ? $product_data : $max_value; |
|
386 | - $min_value = (!empty($product_data) && ( ( $product_data < $min_value) || $first ) ) ? $product_data : $min_value; |
|
385 | + $max_value = (!empty($product_data) && $product_data > $max_value) ? $product_data : $max_value; |
|
386 | + $min_value = (!empty($product_data) && (($product_data < $min_value) || $first)) ? $product_data : $min_value; |
|
387 | 387 | } |
388 | 388 | $first = false; |
389 | 389 | } |
390 | 390 | $category_option['wpshop_category_filterable_attributes'][$attribute_def->id] = array('min' => $min_value, 'max' => $max_value); |
391 | 391 | } |
392 | 392 | /** Update the category option **/ |
393 | - update_option('wpshop_product_category_'.$category_id, $category_option); |
|
393 | + update_option('wpshop_product_category_' . $category_id, $category_option); |
|
394 | 394 | } |
395 | 395 | |
396 | 396 | /** |
@@ -399,66 +399,66 @@ discard block |
||
399 | 399 | * @param std_object $attribute_def |
400 | 400 | * @param array $current_category_child |
401 | 401 | */ |
402 | - function save_values_for_text_filterable_attribute ( $category_id, $attribute_def, $current_category_child ) { |
|
403 | - $category_option = get_option('wpshop_product_category_'.$category_id); |
|
404 | - $category_product_ids = wpshop_categories::get_product_of_category( $category_id ); |
|
402 | + function save_values_for_text_filterable_attribute($category_id, $attribute_def, $current_category_child) { |
|
403 | + $category_option = get_option('wpshop_product_category_' . $category_id); |
|
404 | + $category_product_ids = wpshop_categories::get_product_of_category($category_id); |
|
405 | 405 | /** If there are sub-categories take all products of sub-categories **/ |
406 | 406 | $list_values = array(); |
407 | - if ( !empty($current_category_children) ) { |
|
408 | - foreach ( $current_category_children as $current_category_child ) { |
|
409 | - $sub_categories_product_ids = wpshop_categories::get_product_of_category( $current_category_child->term_taxonomy_id ); |
|
410 | - if ( !empty($sub_categories_product_ids) ) { |
|
411 | - foreach ( $sub_categories_product_ids as $sub_categories_product_id ) { |
|
412 | - if ( !in_array($sub_categories_product_id, $category_product_ids) ) { |
|
407 | + if (!empty($current_category_children)) { |
|
408 | + foreach ($current_category_children as $current_category_child) { |
|
409 | + $sub_categories_product_ids = wpshop_categories::get_product_of_category($current_category_child->term_taxonomy_id); |
|
410 | + if (!empty($sub_categories_product_ids)) { |
|
411 | + foreach ($sub_categories_product_ids as $sub_categories_product_id) { |
|
412 | + if (!in_array($sub_categories_product_id, $category_product_ids)) { |
|
413 | 413 | $category_product_ids[] = $sub_categories_product_id; |
414 | 414 | } |
415 | 415 | } |
416 | 416 | } |
417 | 417 | } |
418 | 418 | } |
419 | - if ( !empty($category_option) && !empty($category_option['wpshop_category_filterable_attributes']) && !empty($category_option['wpshop_category_filterable_attributes'][$attribute_def->id]) ) { |
|
420 | - if ( !empty( $category_product_ids ) ) { |
|
419 | + if (!empty($category_option) && !empty($category_option['wpshop_category_filterable_attributes']) && !empty($category_option['wpshop_category_filterable_attributes'][$attribute_def->id])) { |
|
420 | + if (!empty($category_product_ids)) { |
|
421 | 421 | $product_data = ''; |
422 | - foreach ( $category_product_ids as $category_product_id ) { |
|
422 | + foreach ($category_product_ids as $category_product_id) { |
|
423 | 423 | $product_postmeta = get_post_meta($category_product_id, WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, true); |
424 | - $product_data = ( !empty($product_postmeta[$attribute_def->code]) ) ? $product_postmeta[$attribute_def->code] : ''; |
|
425 | - if ( !in_array( $product_data, $list_values) ) { |
|
424 | + $product_data = (!empty($product_postmeta[$attribute_def->code])) ? $product_postmeta[$attribute_def->code] : ''; |
|
425 | + if (!in_array($product_data, $list_values)) { |
|
426 | 426 | $list_values[] = $product_data; |
427 | - if ( !empty($product_data) ) { |
|
427 | + if (!empty($product_data)) { |
|
428 | 428 | $category_option['wpshop_category_filterable_attributes'][$attribute_def->id][] = $product_data; |
429 | 429 | } |
430 | 430 | } |
431 | 431 | } |
432 | 432 | } |
433 | 433 | } |
434 | - update_option('wpshop_product_category_'.$category_id, $category_option); |
|
434 | + update_option('wpshop_product_category_' . $category_id, $category_option); |
|
435 | 435 | } |
436 | 436 | |
437 | 437 | /** |
438 | 438 | * Save the price which is displayed on website |
439 | 439 | */ |
440 | - public static function save_displayed_price_meta( $product_id = 0 ) { |
|
441 | - $ID = !empty( $_POST['ID'] ) ? (int) $_POST['ID'] : 0; |
|
442 | - $post_type = !empty( $_POST['post_type'] ) ? sanitize_text_field( $_POST['post_type'] ) : ''; |
|
440 | + public static function save_displayed_price_meta($product_id = 0) { |
|
441 | + $ID = !empty($_POST['ID']) ? (int)$_POST['ID'] : 0; |
|
442 | + $post_type = !empty($_POST['post_type']) ? sanitize_text_field($_POST['post_type']) : ''; |
|
443 | 443 | |
444 | - if ( !empty( $product_id ) || ( !empty( $ID ) && !empty($post_type) && $post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT ) ) { |
|
445 | - $product_id = !empty( $product_id ) ? $product_id : $ID; |
|
444 | + if (!empty($product_id) || (!empty($ID) && !empty($post_type) && $post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT)) { |
|
445 | + $product_id = !empty($product_id) ? $product_id : $ID; |
|
446 | 446 | |
447 | 447 | $price_piloting = get_option('wpshop_shop_price_piloting'); |
448 | 448 | $product_data = wpshop_products::get_product_data($product_id); |
449 | 449 | $price_infos = wpshop_prices::check_product_price($product_data); |
450 | 450 | |
451 | - if ( !empty($price_infos) ) { |
|
452 | - if ( !empty($price_infos['discount']) && !empty($price_infos['discount']['discount_exist']) ) { |
|
453 | - $displayed_price = ( !empty($price_piloting) && $price_piloting == 'HT') ? $price_infos['discount']['discount_et_price'] : $price_infos['discount']['discount_ati_price']; |
|
451 | + if (!empty($price_infos)) { |
|
452 | + if (!empty($price_infos['discount']) && !empty($price_infos['discount']['discount_exist'])) { |
|
453 | + $displayed_price = (!empty($price_piloting) && $price_piloting == 'HT') ? $price_infos['discount']['discount_et_price'] : $price_infos['discount']['discount_ati_price']; |
|
454 | 454 | } |
455 | - else if( !empty($price_infos['fork_price']) && !empty($price_infos['fork_price']['have_fork_price']) ) { |
|
455 | + else if (!empty($price_infos['fork_price']) && !empty($price_infos['fork_price']['have_fork_price'])) { |
|
456 | 456 | $displayed_price = $price_infos['fork_price']['min_product_price']; |
457 | 457 | } |
458 | 458 | else { |
459 | - $displayed_price = ( !empty($price_piloting) && $price_piloting == 'HT') ? $price_infos['et'] : $price_infos['ati']; |
|
459 | + $displayed_price = (!empty($price_piloting) && $price_piloting == 'HT') ? $price_infos['et'] : $price_infos['ati']; |
|
460 | 460 | } |
461 | - update_post_meta($product_id, '_wpshop_displayed_price', number_format($displayed_price,2, '.','') ); |
|
461 | + update_post_meta($product_id, '_wpshop_displayed_price', number_format($displayed_price, 2, '.', '')); |
|
462 | 462 | } |
463 | 463 | } |
464 | 464 | } |
@@ -467,19 +467,19 @@ discard block |
||
467 | 467 | * Save values for attributes |
468 | 468 | * @param unknown_type $values |
469 | 469 | */ |
470 | - function stock_values_for_attribute( $categories_id = array() ) { |
|
471 | - @set_time_limit( 900 ); |
|
470 | + function stock_values_for_attribute($categories_id = array()) { |
|
471 | + @set_time_limit(900); |
|
472 | 472 | |
473 | - $tax_input = ( !empty( $_POST['tax_input'] ) && !empty( $_POST['tax_input']['wpshop_product_category'] ) ) ? (int) $_POST['tax_input']['wpshop_product_category'] : ''; |
|
474 | - $post_type = !empty( $_POST['post_type'] ) ? sanitize_text_field( $_POST['post_type'] ) : ''; |
|
475 | - if ( !empty( $tax_input ) && !empty($post_type) && $post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT ) { |
|
473 | + $tax_input = (!empty($_POST['tax_input']) && !empty($_POST['tax_input']['wpshop_product_category'])) ? (int)$_POST['tax_input']['wpshop_product_category'] : ''; |
|
474 | + $post_type = !empty($_POST['post_type']) ? sanitize_text_field($_POST['post_type']) : ''; |
|
475 | + if (!empty($tax_input) && !empty($post_type) && $post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT) { |
|
476 | 476 | $categories_id = $tax_input; |
477 | 477 | } |
478 | 478 | |
479 | - if ( !empty( $categories_id ) ) { |
|
480 | - if ( $categories_id && is_array($categories_id) ) { |
|
481 | - foreach( $categories_id as $taxonomy_id ) { |
|
482 | - if ( $taxonomy_id != 0 ) { |
|
479 | + if (!empty($categories_id)) { |
|
480 | + if ($categories_id && is_array($categories_id)) { |
|
481 | + foreach ($categories_id as $taxonomy_id) { |
|
482 | + if ($taxonomy_id != 0) { |
|
483 | 483 | $current_category_children = array(); |
484 | 484 | $args = array( |
485 | 485 | 'type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, |
@@ -488,23 +488,23 @@ discard block |
||
488 | 488 | ); |
489 | 489 | $current_category_children = get_categories($args); |
490 | 490 | |
491 | - $category_option = get_option('wpshop_product_category_'.$taxonomy_id); |
|
492 | - if ( !empty($category_option) && !empty($category_option['wpshop_category_filterable_attributes']) && is_array($category_option['wpshop_category_filterable_attributes']) ) { |
|
493 | - foreach ( $category_option['wpshop_category_filterable_attributes'] as $k => $filterable_attribute ) { |
|
491 | + $category_option = get_option('wpshop_product_category_' . $taxonomy_id); |
|
492 | + if (!empty($category_option) && !empty($category_option['wpshop_category_filterable_attributes']) && is_array($category_option['wpshop_category_filterable_attributes'])) { |
|
493 | + foreach ($category_option['wpshop_category_filterable_attributes'] as $k => $filterable_attribute) { |
|
494 | 494 | $attribute_def = wpshop_attributes::getElement($k); |
495 | - if ( !empty( $attribute_def) ) { |
|
496 | - switch ( $attribute_def->frontend_input ) { |
|
495 | + if (!empty($attribute_def)) { |
|
496 | + switch ($attribute_def->frontend_input) { |
|
497 | 497 | case 'text' : |
498 | - if ( $attribute_def->data_type == 'decimal' || $attribute_def->data_type == 'integer') { |
|
499 | - $this->save_values_for_integer_filterable_attribute( $taxonomy_id, $attribute_def, $current_category_children ); |
|
498 | + if ($attribute_def->data_type == 'decimal' || $attribute_def->data_type == 'integer') { |
|
499 | + $this->save_values_for_integer_filterable_attribute($taxonomy_id, $attribute_def, $current_category_children); |
|
500 | 500 | } |
501 | 501 | else { |
502 | - $this->save_values_for_text_filterable_attribute( $taxonomy_id, $attribute_def, $current_category_children ); |
|
502 | + $this->save_values_for_text_filterable_attribute($taxonomy_id, $attribute_def, $current_category_children); |
|
503 | 503 | } |
504 | 504 | break; |
505 | 505 | |
506 | 506 | case 'select' : case 'checkbox' : case 'radio' : case 'multiple-select' : |
507 | - $this->save_values_for_list_filterable_attribute( $taxonomy_id, $attribute_def, $current_category_children ); |
|
507 | + $this->save_values_for_list_filterable_attribute($taxonomy_id, $attribute_def, $current_category_children); |
|
508 | 508 | break; |
509 | 509 | |
510 | 510 | } |
@@ -522,22 +522,22 @@ discard block |
||
522 | 522 | * @param integer $category_id |
523 | 523 | * @return array |
524 | 524 | */ |
525 | - function pick_up_filter_search_elements_type ( $category_id ) { |
|
525 | + function pick_up_filter_search_elements_type($category_id) { |
|
526 | 526 | $filter_search_elements = array(); |
527 | - if ( !empty($category_id) ) { |
|
528 | - $category_option = get_option('wpshop_product_category_'.$category_id); |
|
529 | - if ( !empty($category_option) && !empty($category_option['wpshop_category_filterable_attributes']) ) { |
|
530 | - foreach ( $category_option['wpshop_category_filterable_attributes'] as $k => $attribute ) { |
|
527 | + if (!empty($category_id)) { |
|
528 | + $category_option = get_option('wpshop_product_category_' . $category_id); |
|
529 | + if (!empty($category_option) && !empty($category_option['wpshop_category_filterable_attributes'])) { |
|
530 | + foreach ($category_option['wpshop_category_filterable_attributes'] as $k => $attribute) { |
|
531 | 531 | $attribute_def = wpshop_attributes::getElement($k); |
532 | - if ( !empty($attribute_def) ) { |
|
533 | - if ( $attribute_def->frontend_input == 'text' ) { |
|
534 | - $filter_search_elements['_'.$attribute_def->code] = array('type' => 'fork_values'); |
|
532 | + if (!empty($attribute_def)) { |
|
533 | + if ($attribute_def->frontend_input == 'text') { |
|
534 | + $filter_search_elements['_' . $attribute_def->code] = array('type' => 'fork_values'); |
|
535 | 535 | } |
536 | - elseif( in_array( $attribute_def->frontend_input, array('checkbox', 'multiple-select', 'radio', 'select') ) ) { |
|
537 | - $filter_search_elements['_'.$attribute_def->code] = array('type' => 'multiple_select_value'); |
|
536 | + elseif (in_array($attribute_def->frontend_input, array('checkbox', 'multiple-select', 'radio', 'select'))) { |
|
537 | + $filter_search_elements['_' . $attribute_def->code] = array('type' => 'multiple_select_value'); |
|
538 | 538 | } |
539 | - elseif ( !in_array($attribute_def->frontend_input, array('hidden', 'textarea', 'password') ) ) { |
|
540 | - $filter_search_elements['_'.$attribute_def->code] = array('type' => 'select_value'); |
|
539 | + elseif (!in_array($attribute_def->frontend_input, array('hidden', 'textarea', 'password'))) { |
|
540 | + $filter_search_elements['_' . $attribute_def->code] = array('type' => 'select_value'); |
|
541 | 541 | } |
542 | 542 | } |
543 | 543 | } |
@@ -549,28 +549,28 @@ discard block |
||
549 | 549 | /** |
550 | 550 | * AJAX - Action to search with selected attributes values |
551 | 551 | */ |
552 | - function wpshop_ajax_filter_search_action () { |
|
553 | - $_wpnonce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : ''; |
|
552 | + function wpshop_ajax_filter_search_action() { |
|
553 | + $_wpnonce = !empty($_REQUEST['_wpnonce']) ? sanitize_text_field($_REQUEST['_wpnonce']) : ''; |
|
554 | 554 | |
555 | - if ( !wp_verify_nonce( $_wpnonce, 'wpshop_ajax_filter_search_action' ) ) |
|
555 | + if (!wp_verify_nonce($_wpnonce, 'wpshop_ajax_filter_search_action')) |
|
556 | 556 | wp_die(); |
557 | 557 | |
558 | 558 | global $wpdb; |
559 | - $category_id = !empty($_POST['wpshop_filter_search_category_id']) ? wpshop_tools::varSanitizer( $_POST['wpshop_filter_search_category_id'] ) : 0; |
|
559 | + $category_id = !empty($_POST['wpshop_filter_search_category_id']) ? wpshop_tools::varSanitizer($_POST['wpshop_filter_search_category_id']) : 0; |
|
560 | 560 | $filter_search_elements = $this->pick_up_filter_search_elements_type($category_id); |
561 | - $page_id = ( !empty( $_POST['wpshop_filter_search_current_page_id']) ) ? wpshop_tools::varSanitizer( $_POST['wpshop_filter_search_current_page_id'] ) : 1; |
|
561 | + $page_id = (!empty($_POST['wpshop_filter_search_current_page_id'])) ? wpshop_tools::varSanitizer($_POST['wpshop_filter_search_current_page_id']) : 1; |
|
562 | 562 | $request_cmd = ''; |
563 | 563 | $status = false; |
564 | 564 | $data = array(); |
565 | - foreach ( $filter_search_elements as $k=>$filter_search_element) { |
|
566 | - $search = isset( $_REQUEST['filter_search'.$k] ) ? sanitize_text_field( $_REQUEST['filter_search'.$k] ) : ''; |
|
567 | - $amount_min = !isset( $_REQUEST['amount_min'.$k] ) ? 0 : sanitize_text_field( $_REQUEST['amount_min'.$k] ); |
|
568 | - $amount_max = !isset( $_REQUEST['amount_max'.$k] ) ? 0 : sanitize_text_field( $_REQUEST['amount_max'.$k] ); |
|
569 | - $datatype_element = array( 'select_value', 'multiple_select_value', 'fork_values'); |
|
570 | - if ( (in_array($filter_search_element['type'], $datatype_element) && ( isset($search) && $search == 'all_attribute_values' ) ) || |
|
571 | - ( ($filter_search_element['type'] == 'select_value' || $filter_search_element['type'] == 'multiple_select_value' ) && $search == '' ) || |
|
572 | - ( $filter_search_element['type'] == 'fork_values' && ( $amount_min == 0 || $amount_max == 0 ) ) ) { |
|
573 | - unset( $filter_search_elements[$k]); |
|
565 | + foreach ($filter_search_elements as $k=>$filter_search_element) { |
|
566 | + $search = isset($_REQUEST['filter_search' . $k]) ? sanitize_text_field($_REQUEST['filter_search' . $k]) : ''; |
|
567 | + $amount_min = !isset($_REQUEST['amount_min' . $k]) ? 0 : sanitize_text_field($_REQUEST['amount_min' . $k]); |
|
568 | + $amount_max = !isset($_REQUEST['amount_max' . $k]) ? 0 : sanitize_text_field($_REQUEST['amount_max' . $k]); |
|
569 | + $datatype_element = array('select_value', 'multiple_select_value', 'fork_values'); |
|
570 | + if ((in_array($filter_search_element['type'], $datatype_element) && (isset($search) && $search == 'all_attribute_values')) || |
|
571 | + (($filter_search_element['type'] == 'select_value' || $filter_search_element['type'] == 'multiple_select_value') && $search == '') || |
|
572 | + ($filter_search_element['type'] == 'fork_values' && ($amount_min == 0 || $amount_max == 0))) { |
|
573 | + unset($filter_search_elements[$k]); |
|
574 | 574 | } |
575 | 575 | } |
576 | 576 | $request_cmd = ''; |
@@ -589,8 +589,8 @@ discard block |
||
589 | 589 | /** Construct the array for SELECT query IN **/ |
590 | 590 | $categories_id = array(); |
591 | 591 | $categories_id[] = $category_id; |
592 | - if ( !empty($current_category_children) ) { |
|
593 | - foreach ( $current_category_children as $current_category_child ) { |
|
592 | + if (!empty($current_category_children)) { |
|
593 | + foreach ($current_category_children as $current_category_child) { |
|
594 | 594 | $categories_id[] = $current_category_child->term_taxonomy_id; |
595 | 595 | } |
596 | 596 | } |
@@ -599,55 +599,55 @@ discard block |
||
599 | 599 | $array_for_query = implode(',', $categories_id); |
600 | 600 | |
601 | 601 | /** SQL request Construct for pick up all product with one of filter search element value **/ |
602 | - if ( !empty( $filter_search_elements ) ) { |
|
603 | - foreach ( $filter_search_elements as $k=>$filter_search_element ) { |
|
604 | - $search = isset( $_REQUEST['filter_search'.$k] ) ? $_REQUEST['filter_search'.$k] : ''; |
|
605 | - $amount_min = !isset( $_REQUEST['amount_min'.$k] ) ? 0 : sanitize_text_field( $_REQUEST['amount_min'.$k] ); |
|
606 | - $amount_max = !isset( $_REQUEST['amount_max'.$k] ) ? 0 : sanitize_text_field( $_REQUEST['amount_max'.$k] ); |
|
607 | - |
|
608 | - if ( !empty($filter_search_element['type']) && !empty($search) && $filter_search_element['type'] == 'select_value' && $search != 'all_attribute_values') { |
|
609 | - $request_cmd .= 'SELECT meta_key, post_id FROM ' .$wpdb->postmeta. ' INNER JOIN ' .$wpdb->posts. ' ON post_id = ID WHERE (meta_key = "'.$k.'" AND meta_value = "'.$search.'") AND post_type = "'.WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT.'" AND post_status = "publish" '; |
|
610 | - $request_cmd .= ' AND post_id IN (SELECT object_id FROM '.$wpdb->term_relationships.' WHERE term_taxonomy_id IN ('.$array_for_query.') ) '; |
|
602 | + if (!empty($filter_search_elements)) { |
|
603 | + foreach ($filter_search_elements as $k=>$filter_search_element) { |
|
604 | + $search = isset($_REQUEST['filter_search' . $k]) ? $_REQUEST['filter_search' . $k] : ''; |
|
605 | + $amount_min = !isset($_REQUEST['amount_min' . $k]) ? 0 : sanitize_text_field($_REQUEST['amount_min' . $k]); |
|
606 | + $amount_max = !isset($_REQUEST['amount_max' . $k]) ? 0 : sanitize_text_field($_REQUEST['amount_max' . $k]); |
|
607 | + |
|
608 | + if (!empty($filter_search_element['type']) && !empty($search) && $filter_search_element['type'] == 'select_value' && $search != 'all_attribute_values') { |
|
609 | + $request_cmd .= 'SELECT meta_key, post_id FROM ' . $wpdb->postmeta . ' INNER JOIN ' . $wpdb->posts . ' ON post_id = ID WHERE (meta_key = "' . $k . '" AND meta_value = "' . $search . '") AND post_type = "' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '" AND post_status = "publish" '; |
|
610 | + $request_cmd .= ' AND post_id IN (SELECT object_id FROM ' . $wpdb->term_relationships . ' WHERE term_taxonomy_id IN (' . $array_for_query . ') ) '; |
|
611 | 611 | } |
612 | - else if($filter_search_element['type'] == 'fork_values') { |
|
613 | - $request_cmd .= 'SELECT meta_key, post_id FROM ' .$wpdb->postmeta. ' INNER JOIN ' .$wpdb->posts. ' ON post_id = ID WHERE (meta_key = "'.( ( !empty($k) && $k == '_product_price' ) ? '_wpshop_displayed_price' : $k).'" AND meta_value BETWEEN '.$amount_min.' AND '.$amount_max.') AND post_type = "'.WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT.'" AND post_status = "publish"'; |
|
614 | - $request_cmd .= ' AND post_id IN (SELECT object_id FROM '.$wpdb->term_relationships.' WHERE term_taxonomy_id IN ('.$array_for_query.') ) '; |
|
612 | + else if ($filter_search_element['type'] == 'fork_values') { |
|
613 | + $request_cmd .= 'SELECT meta_key, post_id FROM ' . $wpdb->postmeta . ' INNER JOIN ' . $wpdb->posts . ' ON post_id = ID WHERE (meta_key = "' . ((!empty($k) && $k == '_product_price') ? '_wpshop_displayed_price' : $k) . '" AND meta_value BETWEEN ' . $amount_min . ' AND ' . $amount_max . ') AND post_type = "' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '" AND post_status = "publish"'; |
|
614 | + $request_cmd .= ' AND post_id IN (SELECT object_id FROM ' . $wpdb->term_relationships . ' WHERE term_taxonomy_id IN (' . $array_for_query . ') ) '; |
|
615 | 615 | } |
616 | - else if( $filter_search_element['type'] == 'multiple_select_value' ) { |
|
616 | + else if ($filter_search_element['type'] == 'multiple_select_value') { |
|
617 | 617 | /** Check the attribute id **/ |
618 | 618 | $attribute_def = wpshop_attributes::getElement(substr($k, 1), "'valid'", 'code'); |
619 | - if ( !empty($attribute_def) ) { |
|
620 | - $request_cmd .= 'SELECT CONCAT("_", code) AS meta_key, ATT_INT.entity_id AS post_id FROM ' .WPSHOP_DBT_ATTRIBUTE. ', '.WPSHOP_DBT_ATTRIBUTE_VALUES_INTEGER.' AS ATT_INT WHERE attribute_id = id AND attribute_id = '.$attribute_def->id; |
|
619 | + if (!empty($attribute_def)) { |
|
620 | + $request_cmd .= 'SELECT CONCAT("_", code) AS meta_key, ATT_INT.entity_id AS post_id FROM ' . WPSHOP_DBT_ATTRIBUTE . ', ' . WPSHOP_DBT_ATTRIBUTE_VALUES_INTEGER . ' AS ATT_INT WHERE attribute_id = id AND attribute_id = ' . $attribute_def->id; |
|
621 | 621 | $first = true; |
622 | - if ( !empty($search) && is_array($search) ){ |
|
623 | - foreach ( $search as $r ) { |
|
624 | - if ( $first) { |
|
625 | - $request_cmd .= ' AND (value ="' . $r. '"'; |
|
622 | + if (!empty($search) && is_array($search)) { |
|
623 | + foreach ($search as $r) { |
|
624 | + if ($first) { |
|
625 | + $request_cmd .= ' AND (value ="' . $r . '"'; |
|
626 | 626 | $first = false; |
627 | 627 | } |
628 | 628 | else { |
629 | - $request_cmd .= ' OR value ="' . $r. '"'; |
|
629 | + $request_cmd .= ' OR value ="' . $r . '"'; |
|
630 | 630 | } |
631 | 631 | } |
632 | 632 | $request_cmd .= ')'; |
633 | 633 | } |
634 | - elseif( !empty($search) ) { |
|
634 | + elseif (!empty($search)) { |
|
635 | 635 | $request_cmd .= ' AND (value ="' . $search . '" )'; |
636 | 636 | } |
637 | - $request_cmd .= ' AND ATT_INT.entity_id IN (SELECT object_id FROM '.$wpdb->term_relationships.' WHERE term_taxonomy_id IN ('.$array_for_query.') ) '; |
|
637 | + $request_cmd .= ' AND ATT_INT.entity_id IN (SELECT object_id FROM ' . $wpdb->term_relationships . ' WHERE term_taxonomy_id IN (' . $array_for_query . ') ) '; |
|
638 | 638 | |
639 | 639 | |
640 | 640 | } |
641 | 641 | } |
642 | 642 | |
643 | 643 | |
644 | - if ($i < count($filter_search_elements) ) { |
|
644 | + if ($i < count($filter_search_elements)) { |
|
645 | 645 | $request_cmd .= ' UNION '; |
646 | 646 | } |
647 | 647 | $i++; |
648 | 648 | } |
649 | 649 | } else { |
650 | - $request_cmd .= 'SELECT object_id FROM '.$wpdb->term_relationships.' WHERE term_taxonomy_id IN ('.$array_for_query.')'; |
|
650 | + $request_cmd .= 'SELECT object_id FROM ' . $wpdb->term_relationships . ' WHERE term_taxonomy_id IN (' . $array_for_query . ')'; |
|
651 | 651 | } |
652 | 652 | /** SQL Request execution **/ |
653 | 653 | $query = $wpdb->prepare($request_cmd, ''); |
@@ -661,9 +661,9 @@ discard block |
||
661 | 661 | |
662 | 662 | $last = ''; |
663 | 663 | /** Transform the query result array **/ |
664 | - foreach ( $results as $result ) { |
|
665 | - $result->meta_key = ( !empty($result->meta_key) && $result->meta_key == '_wpshop_displayed_price' ) ? '_product_price' : $result->meta_key; |
|
666 | - if ( $last != $result->meta_key ){ |
|
664 | + foreach ($results as $result) { |
|
665 | + $result->meta_key = (!empty($result->meta_key) && $result->meta_key == '_wpshop_displayed_price') ? '_product_price' : $result->meta_key; |
|
666 | + if ($last != $result->meta_key) { |
|
667 | 667 | $filter_search_elements[$result->meta_key]['count'] = 1; |
668 | 668 | $last = $result->meta_key; |
669 | 669 | } |
@@ -677,12 +677,12 @@ discard block |
||
677 | 677 | /** Check the smaller array of attributes **/ |
678 | 678 | $smaller_array = ''; |
679 | 679 | $smaller_array_count = -1; |
680 | - foreach ( $filter_search_elements as $k=>$filter_search_element ) { |
|
681 | - if ( empty($filter_search_element['count']) ) { |
|
680 | + foreach ($filter_search_elements as $k=>$filter_search_element) { |
|
681 | + if (empty($filter_search_element['count'])) { |
|
682 | 682 | $smaller_array_count = 0; |
683 | 683 | $smaller_array = $k; |
684 | 684 | } |
685 | - elseif( $smaller_array_count == -1 || $filter_search_element['count'] <= $smaller_array_count ) { |
|
685 | + elseif ($smaller_array_count == -1 || $filter_search_element['count'] <= $smaller_array_count) { |
|
686 | 686 | $smaller_array_count = $filter_search_element['count']; |
687 | 687 | $smaller_array = $k; |
688 | 688 | } |
@@ -690,21 +690,21 @@ discard block |
||
690 | 690 | } |
691 | 691 | |
692 | 692 | /** Compare the smaller array with the others **/ |
693 | - if ( !empty($smaller_array_count) ) { |
|
693 | + if (!empty($smaller_array_count)) { |
|
694 | 694 | $temp_tab = $filter_search_elements[$smaller_array]['values']; |
695 | - foreach ( $filter_search_elements as $filter_search) { |
|
696 | - foreach ( $temp_tab as $value ) { |
|
697 | - if ( !in_array($value, $filter_search['values']) ) { |
|
695 | + foreach ($filter_search_elements as $filter_search) { |
|
696 | + foreach ($temp_tab as $value) { |
|
697 | + if (!in_array($value, $filter_search['values'])) { |
|
698 | 698 | /** If value don't exist in the smaller array, delete it **/ |
699 | 699 | $key = array_key_exists($value, $temp_tab); |
700 | - if ( $key ) { |
|
700 | + if ($key) { |
|
701 | 701 | unset($temp_tab[$value]); |
702 | 702 | } |
703 | 703 | } |
704 | 704 | } |
705 | 705 | } |
706 | 706 | /** Final result to display the products **/ |
707 | - if ( !empty( $temp_tab) ) { |
|
707 | + if (!empty($temp_tab)) { |
|
708 | 708 | $final_result = $temp_tab; |
709 | 709 | } |
710 | 710 | } |
@@ -713,21 +713,21 @@ discard block |
||
713 | 713 | } |
714 | 714 | |
715 | 715 | $products_count = count($final_result); |
716 | - $products_count = sprintf(__('%s products corresponds to your search.', 'wpshop'),$products_count) ; |
|
716 | + $products_count = sprintf(__('%s products corresponds to your search.', 'wpshop'), $products_count); |
|
717 | 717 | |
718 | 718 | /** If there is products for this filter search **/ |
719 | 719 | $status = true; |
720 | - if ( !empty($final_result) ) { |
|
720 | + if (!empty($final_result)) { |
|
721 | 721 | $data['status'] = true; |
722 | - $data['result'] = do_shortcode( '[wpshop_products pid="' . implode(',', $final_result) . '" cid="' . $category_id . '" container="no" ]' ) ; |
|
722 | + $data['result'] = do_shortcode('[wpshop_products pid="' . implode(',', $final_result) . '" cid="' . $category_id . '" container="no" ]'); |
|
723 | 723 | $data['products_count'] = $products_count; |
724 | 724 | } |
725 | 725 | else { |
726 | 726 | $data['status'] = false; |
727 | - $data['result'] = '<div class="container_product_listing">'.__('There is no product for this filter search.', 'wpshop').'</div>'; |
|
727 | + $data['result'] = '<div class="container_product_listing">' . __('There is no product for this filter search.', 'wpshop') . '</div>'; |
|
728 | 728 | $data['products_count'] = __('No products corresponds to your search', 'wpshop'); |
729 | 729 | } |
730 | - echo json_encode( $data ); |
|
730 | + echo json_encode($data); |
|
731 | 731 | die(); |
732 | 732 | } |
733 | 733 | } |
@@ -1,4 +1,6 @@ discard block |
||
1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
1 | +<?php if ( !defined( 'ABSPATH' ) ) { |
|
2 | + exit; |
|
3 | +} |
|
2 | 4 | class wps_filter_search { |
3 | 5 | |
4 | 6 | /** Define the main directory containing the template for the current plugin |
@@ -106,8 +108,7 @@ discard block |
||
106 | 108 | case 'text' : |
107 | 109 | if ( $attribute_def->data_type == 'decimal' || $attribute_def->data_type == 'integer') { |
108 | 110 | return $this->get_filter_element_for_integer_data( $attribute_def, $category_id, $current_category_children ); |
109 | - } |
|
110 | - else { |
|
111 | + } else { |
|
111 | 112 | return $this->get_filter_element_for_text_data( $attribute_def, $category_id, $current_category_children ); |
112 | 113 | } |
113 | 114 | break; |
@@ -187,8 +188,7 @@ discard block |
||
187 | 188 | } |
188 | 189 | } |
189 | 190 | } |
190 | - } |
|
191 | - else { |
|
191 | + } else { |
|
192 | 192 | foreach ( $attributes_options as $attributes_option ) { |
193 | 193 | if ( in_array($attributes_option->label, $available_attribute_values) ) { |
194 | 194 | $key_value = array_search( $attributes_option->label, $available_attribute_values); |
@@ -224,8 +224,7 @@ discard block |
||
224 | 224 | require( wpshop_tools::get_template_part( WPS_SEARCH_DIR, $this->template_dir, "frontend", "filter_search/filter_elements/element_multiple_select") ); |
225 | 225 | $output = ob_get_contents(); |
226 | 226 | ob_end_clean(); |
227 | - } |
|
228 | - else { |
|
227 | + } else { |
|
229 | 228 | ob_start(); |
230 | 229 | require( wpshop_tools::get_template_part( WPS_SEARCH_DIR, $this->template_dir, "frontend", "filter_search/filter_elements/element_combobox") ); |
231 | 230 | $output = ob_get_contents(); |
@@ -308,8 +307,7 @@ discard block |
||
308 | 307 | foreach( $available_attribute_values as $k => $available_attribute_value ) { |
309 | 308 | if ( $attribute_def->data_type_to_use == 'internal' ) { |
310 | 309 | $attribute_name = get_the_title( $k ); |
311 | - } |
|
312 | - else { |
|
310 | + } else { |
|
313 | 311 | $query = $wpdb->prepare( 'SELECT label FROM ' .WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS. ' WHERE attribute_id = %d AND id = %d', $attribute_def->id, $k); |
314 | 312 | |
315 | 313 | $attribute_name = $wpdb->get_var( $query ); |
@@ -365,21 +363,18 @@ discard block |
||
365 | 363 | |
366 | 364 | $max_value = ( !empty($product_price_infos['fork_price']['max_product_price']) && $product_price_infos['fork_price']['max_product_price'] > $max_value ) ? $product_price_infos['fork_price']['max_product_price'] : $max_value; |
367 | 365 | $min_value = (!empty($product_price_infos['fork_price']['min_product_price']) && ( ( $product_price_infos['fork_price']['min_product_price'] < $min_value) || $first ) ) ? $product_price_infos['fork_price']['min_product_price'] : $min_value; |
368 | - } |
|
369 | - else { |
|
366 | + } else { |
|
370 | 367 | if (!empty($product_price_infos) && !empty($product_price_infos['discount']) && !empty($product_price_infos['discount']['discount_exist'] ) && $product_price_infos['discount']['discount_exist'] ) { |
371 | 368 | $product_data = (!empty($price_piloting_option) && $price_piloting_option == 'HT') ? $product_price_infos['discount']['discount_et_price'] : $product_price_infos['discount']['discount_ati_price']; |
372 | 369 | |
373 | - } |
|
374 | - else { |
|
370 | + } else { |
|
375 | 371 | |
376 | 372 | $product_data = (!empty($price_piloting_option) && $price_piloting_option == 'HT') ? $product_price_infos['et'] : $product_price_infos['ati']; |
377 | 373 | } |
378 | 374 | $max_value = ( !empty($product_data) && $product_data > $max_value ) ? $product_data : $max_value; |
379 | 375 | $min_value = (!empty($product_data) && ( ( $product_data < $min_value) || $first ) ) ? $product_data : $min_value; |
380 | 376 | } |
381 | - } |
|
382 | - else { |
|
377 | + } else { |
|
383 | 378 | $product_postmeta = get_post_meta($category_product_id, WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, true); |
384 | 379 | $product_data = $product_postmeta[$attribute_def->code]; |
385 | 380 | $max_value = ( !empty($product_data) && $product_data > $max_value ) ? $product_data : $max_value; |
@@ -451,11 +446,9 @@ discard block |
||
451 | 446 | if ( !empty($price_infos) ) { |
452 | 447 | if ( !empty($price_infos['discount']) && !empty($price_infos['discount']['discount_exist']) ) { |
453 | 448 | $displayed_price = ( !empty($price_piloting) && $price_piloting == 'HT') ? $price_infos['discount']['discount_et_price'] : $price_infos['discount']['discount_ati_price']; |
454 | - } |
|
455 | - else if( !empty($price_infos['fork_price']) && !empty($price_infos['fork_price']['have_fork_price']) ) { |
|
449 | + } else if( !empty($price_infos['fork_price']) && !empty($price_infos['fork_price']['have_fork_price']) ) { |
|
456 | 450 | $displayed_price = $price_infos['fork_price']['min_product_price']; |
457 | - } |
|
458 | - else { |
|
451 | + } else { |
|
459 | 452 | $displayed_price = ( !empty($price_piloting) && $price_piloting == 'HT') ? $price_infos['et'] : $price_infos['ati']; |
460 | 453 | } |
461 | 454 | update_post_meta($product_id, '_wpshop_displayed_price', number_format($displayed_price,2, '.','') ); |
@@ -497,8 +490,7 @@ discard block |
||
497 | 490 | case 'text' : |
498 | 491 | if ( $attribute_def->data_type == 'decimal' || $attribute_def->data_type == 'integer') { |
499 | 492 | $this->save_values_for_integer_filterable_attribute( $taxonomy_id, $attribute_def, $current_category_children ); |
500 | - } |
|
501 | - else { |
|
493 | + } else { |
|
502 | 494 | $this->save_values_for_text_filterable_attribute( $taxonomy_id, $attribute_def, $current_category_children ); |
503 | 495 | } |
504 | 496 | break; |
@@ -532,11 +524,9 @@ discard block |
||
532 | 524 | if ( !empty($attribute_def) ) { |
533 | 525 | if ( $attribute_def->frontend_input == 'text' ) { |
534 | 526 | $filter_search_elements['_'.$attribute_def->code] = array('type' => 'fork_values'); |
535 | - } |
|
536 | - elseif( in_array( $attribute_def->frontend_input, array('checkbox', 'multiple-select', 'radio', 'select') ) ) { |
|
527 | + } elseif( in_array( $attribute_def->frontend_input, array('checkbox', 'multiple-select', 'radio', 'select') ) ) { |
|
537 | 528 | $filter_search_elements['_'.$attribute_def->code] = array('type' => 'multiple_select_value'); |
538 | - } |
|
539 | - elseif ( !in_array($attribute_def->frontend_input, array('hidden', 'textarea', 'password') ) ) { |
|
529 | + } elseif ( !in_array($attribute_def->frontend_input, array('hidden', 'textarea', 'password') ) ) { |
|
540 | 530 | $filter_search_elements['_'.$attribute_def->code] = array('type' => 'select_value'); |
541 | 531 | } |
542 | 532 | } |
@@ -552,8 +542,9 @@ discard block |
||
552 | 542 | function wpshop_ajax_filter_search_action () { |
553 | 543 | $_wpnonce = !empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : ''; |
554 | 544 | |
555 | - if ( !wp_verify_nonce( $_wpnonce, 'wpshop_ajax_filter_search_action' ) ) |
|
556 | - wp_die(); |
|
545 | + if ( !wp_verify_nonce( $_wpnonce, 'wpshop_ajax_filter_search_action' ) ) { |
|
546 | + wp_die(); |
|
547 | + } |
|
557 | 548 | |
558 | 549 | global $wpdb; |
559 | 550 | $category_id = !empty($_POST['wpshop_filter_search_category_id']) ? wpshop_tools::varSanitizer( $_POST['wpshop_filter_search_category_id'] ) : 0; |
@@ -608,12 +599,10 @@ discard block |
||
608 | 599 | if ( !empty($filter_search_element['type']) && !empty($search) && $filter_search_element['type'] == 'select_value' && $search != 'all_attribute_values') { |
609 | 600 | $request_cmd .= 'SELECT meta_key, post_id FROM ' .$wpdb->postmeta. ' INNER JOIN ' .$wpdb->posts. ' ON post_id = ID WHERE (meta_key = "'.$k.'" AND meta_value = "'.$search.'") AND post_type = "'.WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT.'" AND post_status = "publish" '; |
610 | 601 | $request_cmd .= ' AND post_id IN (SELECT object_id FROM '.$wpdb->term_relationships.' WHERE term_taxonomy_id IN ('.$array_for_query.') ) '; |
611 | - } |
|
612 | - else if($filter_search_element['type'] == 'fork_values') { |
|
602 | + } else if($filter_search_element['type'] == 'fork_values') { |
|
613 | 603 | $request_cmd .= 'SELECT meta_key, post_id FROM ' .$wpdb->postmeta. ' INNER JOIN ' .$wpdb->posts. ' ON post_id = ID WHERE (meta_key = "'.( ( !empty($k) && $k == '_product_price' ) ? '_wpshop_displayed_price' : $k).'" AND meta_value BETWEEN '.$amount_min.' AND '.$amount_max.') AND post_type = "'.WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT.'" AND post_status = "publish"'; |
614 | 604 | $request_cmd .= ' AND post_id IN (SELECT object_id FROM '.$wpdb->term_relationships.' WHERE term_taxonomy_id IN ('.$array_for_query.') ) '; |
615 | - } |
|
616 | - else if( $filter_search_element['type'] == 'multiple_select_value' ) { |
|
605 | + } else if( $filter_search_element['type'] == 'multiple_select_value' ) { |
|
617 | 606 | /** Check the attribute id **/ |
618 | 607 | $attribute_def = wpshop_attributes::getElement(substr($k, 1), "'valid'", 'code'); |
619 | 608 | if ( !empty($attribute_def) ) { |
@@ -624,14 +613,12 @@ discard block |
||
624 | 613 | if ( $first) { |
625 | 614 | $request_cmd .= ' AND (value ="' . $r. '"'; |
626 | 615 | $first = false; |
627 | - } |
|
628 | - else { |
|
616 | + } else { |
|
629 | 617 | $request_cmd .= ' OR value ="' . $r. '"'; |
630 | 618 | } |
631 | 619 | } |
632 | 620 | $request_cmd .= ')'; |
633 | - } |
|
634 | - elseif( !empty($search) ) { |
|
621 | + } elseif( !empty($search) ) { |
|
635 | 622 | $request_cmd .= ' AND (value ="' . $search . '" )'; |
636 | 623 | } |
637 | 624 | $request_cmd .= ' AND ATT_INT.entity_id IN (SELECT object_id FROM '.$wpdb->term_relationships.' WHERE term_taxonomy_id IN ('.$array_for_query.') ) '; |
@@ -666,9 +653,9 @@ discard block |
||
666 | 653 | if ( $last != $result->meta_key ){ |
667 | 654 | $filter_search_elements[$result->meta_key]['count'] = 1; |
668 | 655 | $last = $result->meta_key; |
656 | + } else { |
|
657 | + $filter_search_elements[$result->meta_key]['count']++; |
|
669 | 658 | } |
670 | - else |
|
671 | - $filter_search_elements[$result->meta_key]['count']++; |
|
672 | 659 | |
673 | 660 | $filter_search_elements[$result->meta_key]['values'][$result->post_id] = $result->post_id; |
674 | 661 | } |
@@ -681,8 +668,7 @@ discard block |
||
681 | 668 | if ( empty($filter_search_element['count']) ) { |
682 | 669 | $smaller_array_count = 0; |
683 | 670 | $smaller_array = $k; |
684 | - } |
|
685 | - elseif( $smaller_array_count == -1 || $filter_search_element['count'] <= $smaller_array_count ) { |
|
671 | + } elseif( $smaller_array_count == -1 || $filter_search_element['count'] <= $smaller_array_count ) { |
|
686 | 672 | $smaller_array_count = $filter_search_element['count']; |
687 | 673 | $smaller_array = $k; |
688 | 674 | } |
@@ -707,8 +693,7 @@ discard block |
||
707 | 693 | if ( !empty( $temp_tab) ) { |
708 | 694 | $final_result = $temp_tab; |
709 | 695 | } |
710 | - } |
|
711 | - else { |
|
696 | + } else { |
|
712 | 697 | $final_result = array(); |
713 | 698 | } |
714 | 699 | |
@@ -721,8 +706,7 @@ discard block |
||
721 | 706 | $data['status'] = true; |
722 | 707 | $data['result'] = do_shortcode( '[wpshop_products pid="' . implode(',', $final_result) . '" cid="' . $category_id . '" container="no" ]' ) ; |
723 | 708 | $data['products_count'] = $products_count; |
724 | - } |
|
725 | - else { |
|
709 | + } else { |
|
726 | 710 | $data['status'] = false; |
727 | 711 | $data['result'] = '<div class="container_product_listing">'.__('There is no product for this filter search.', 'wpshop').'</div>'; |
728 | 712 | $data['products_count'] = __('No products corresponds to your search', 'wpshop'); |