Completed
Push — master ( 8cb6bf...057aa1 )
by
unknown
13:40
created
includes/librairies/catalog/products.class.php 3 patches
Doc Comments   +10 added lines, -4 removed lines patch added patch discarded remove patch
@@ -794,6 +794,9 @@  discard block
 block discarded – undo
794 794
         return do_shortcode($string);
795 795
     }
796 796
 
797
+    /**
798
+     * @param integer $page_number
799
+     */
797 800
     public static function wpshop_get_product_by_criteria($criteria = null, $cid = 0, $pid = 0, $display_type, $order = 'ASC', $page_number, $products_per_page = 0, $nb_of_product_limit = 0, $grid_element_nb_per_line = WPSHOP_DISPLAY_GRID_ELEMENT_NUMBER_PER_LINE, $display_pagination = true)
798 801
     {
799 802
         global $wpdb;
@@ -1149,7 +1152,7 @@  discard block
 block discarded – undo
1149 1152
     /**
1150 1153
      * Add a product into the db. This function is used for the EDI
1151 1154
      * @param $name Name of the product
1152
-     * @param $description Description of the product
1155
+     * @param string $description Description of the product
1153 1156
      * @param $attrs List of the attributes and values of the product
1154 1157
      * @return boolean
1155 1158
      */
@@ -1464,10 +1467,10 @@  discard block
 block discarded – undo
1464 1467
     /**
1465 1468
      *    Define output for product
1466 1469
      *
1467
-     *    @param mixed $initialContent The initial product content defined into wordpress basic admin interface
1470
+     *    @param string $initialContent The initial product content defined into wordpress basic admin interface
1468 1471
      *    @param integer $product_id The product identifier we want to get and output attribute for
1469 1472
      *
1470
-     *    @return mixed $content The content to add or to modify the product output in frontend
1473
+     *    @return string $content The content to add or to modify the product output in frontend
1471 1474
      */
1472 1475
     public static function product_complete_sheet_output($initialContent, $product_id)
1473 1476
     {
@@ -2496,7 +2499,7 @@  discard block
 block discarded – undo
2496 2499
 
2497 2500
     /**
2498 2501
      * Retrieve and display the variation for a given product
2499
-     * @param integer $product_id The product identifier to get variation for
2502
+     * @param integer $post_id The product identifier to get variation for
2500 2503
      */
2501 2504
     public static function wpshop_variation($post_id = '', $from_admin = false, $order_id = '', $qty = 1)
2502 2505
     {
@@ -3294,6 +3297,9 @@  discard block
 block discarded – undo
3294 3297
         echo $output;
3295 3298
     }
3296 3299
 
3300
+    /**
3301
+     * @param boolean $has_variation
3302
+     */
3297 3303
     public function wps_get_summary_variations_product($product_id, $the_product, $has_variation)
3298 3304
     {
3299 3305
         global $wpdb, $wpshop_payment;
Please login to merge, or discard this patch.
Indentation   +3125 added lines, -3125 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if (!defined('ABSPATH')) {
2
-    exit;
2
+	exit;
3 3
 }
4 4
 
5 5
 /**
@@ -14,7 +14,7 @@  discard block
 block discarded – undo
14 14
 
15 15
 /*    Check if file is include. No direct access possible with file url    */
16 16
 if (!defined('WPSHOP_VERSION')) {
17
-    die(__('Access is not allowed by this way', 'wpshop'));
17
+	die(__('Access is not allowed by this way', 'wpshop'));
18 18
 }
19 19
 
20 20
 /**
@@ -26,160 +26,160 @@  discard block
 block discarded – undo
26 26
  */
27 27
 class wpshop_products
28 28
 {
29
-    /**
30
-     *    Définition du code de la classe courante
31
-     */
32
-    const currentPageCode = WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT;
33
-    const current_page_variation_code = WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION;
34
-
35
-    public function add_product_to_current_order_interface()
36
-    {
37
-        $output = '';
38
-        $output .= self::products_list_js();
39
-        $output .= '<input type="text" id="wps_order_search_product" />';
40
-        echo $output;
41
-        die();
42
-    }
29
+	/**
30
+	 *    Définition du code de la classe courante
31
+	 */
32
+	const currentPageCode = WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT;
33
+	const current_page_variation_code = WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION;
34
+
35
+	public function add_product_to_current_order_interface()
36
+	{
37
+		$output = '';
38
+		$output .= self::products_list_js();
39
+		$output .= '<input type="text" id="wps_order_search_product" />';
40
+		echo $output;
41
+		die();
42
+	}
43 43
 
44
-    public function products_list_js()
45
-    {
46
-        global $wpdb;
47
-        /** Create a JS Array of products **/
44
+	public function products_list_js()
45
+	{
46
+		global $wpdb;
47
+		/** Create a JS Array of products **/
48 48
 //         $query = $wpdb->prepare('SELECT ID, post_title FROM ' .$wpdb->posts. '  WHERE post_type = %s AND post_status = %s', WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'publish');
49
-        //         $products_post = $wpdb->get_results( $query );
50
-
51
-        $products_post = get_posts(array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'post_status' => 'publish', 'posts_per_page' => -1));
52
-
53
-        if (!empty($products_post)) {
54
-            $products_js_array = 'var products = [';
55
-            foreach ($products_post as $product) {
56
-                $barcode = get_post_meta($product->ID, '_barcode', true);
57
-                $products_js_array .= '{label:"#' . $product->ID . ' ' . str_replace('"', '', $product->post_title) . ' - ' . ((!empty($barcode)) ? $barcode : '') . '", ';
58
-                $products_js_array .= 'value:"' . $product->ID . '", ';
59
-                $products_js_array .= (!empty($barcode)) ? 'desc:"' . $barcode . '"},' : '},';
60
-            }
61
-            $products_js_array .= '];';
62
-        }
63
-        $output = wpshop_display::display_template_element('wps_orders_products_list_js', array('PRODUCTS_JS_ARRAY' => $products_js_array), array(), 'admin');
64
-        return $output;
65
-    }
49
+		//         $products_post = $wpdb->get_results( $query );
50
+
51
+		$products_post = get_posts(array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'post_status' => 'publish', 'posts_per_page' => -1));
52
+
53
+		if (!empty($products_post)) {
54
+			$products_js_array = 'var products = [';
55
+			foreach ($products_post as $product) {
56
+				$barcode = get_post_meta($product->ID, '_barcode', true);
57
+				$products_js_array .= '{label:"#' . $product->ID . ' ' . str_replace('"', '', $product->post_title) . ' - ' . ((!empty($barcode)) ? $barcode : '') . '", ';
58
+				$products_js_array .= 'value:"' . $product->ID . '", ';
59
+				$products_js_array .= (!empty($barcode)) ? 'desc:"' . $barcode . '"},' : '},';
60
+			}
61
+			$products_js_array .= '];';
62
+		}
63
+		$output = wpshop_display::display_template_element('wps_orders_products_list_js', array('PRODUCTS_JS_ARRAY' => $products_js_array), array(), 'admin');
64
+		return $output;
65
+	}
66 66
 
67
-    /**
68
-     *    Déclaration des produits et variations en tant que "post" de wordpress
69
-     *
70
-     *    @see register_post_type()
71
-     */
72
-    public static function create_wpshop_products_type()
73
-    {
74
-
75
-        $options = get_option('wpshop_catalog_product_option', array());
76
-        //$options2 = get_option('wpshop_catalog_categories_option', array());
77
-        /*echo '<pre>'; print_r( $options ); echo '</pre>';
67
+	/**
68
+	 *    Déclaration des produits et variations en tant que "post" de wordpress
69
+	 *
70
+	 *    @see register_post_type()
71
+	 */
72
+	public static function create_wpshop_products_type()
73
+	{
74
+
75
+		$options = get_option('wpshop_catalog_product_option', array());
76
+		//$options2 = get_option('wpshop_catalog_categories_option', array());
77
+		/*echo '<pre>'; print_r( $options ); echo '</pre>';
78 78
         echo '<pre>'; print_r( $options2 ); echo '</pre>'; exit();*/
79 79
 
80
-        $slug = array(
81
-            'slug' => '',
82
-            'with_front' => false,
83
-        );
84
-
85
-        if (empty($options['wpshop_catalog_product_slug']) || $options['wpshop_catalog_product_slug'] == '/') {
86
-            $slug = false;
87
-        } else {
88
-            $slug['slug'] = $options['wpshop_catalog_product_slug'];
89
-            if (!empty($options['wpshop_catalog_product_slug_with_category'])) {
90
-                $slug['slug'] .= '/%' . WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES . '%';
91
-            }
92
-        }
93
-        /*$product_slug .= '/%' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '%';*/
94
-
95
-        /*    Définition des produits     */
96
-        register_post_type(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, apply_filters(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_register', array(
97
-            'labels' => array(
98
-                'name' => __('Products', 'wpshop'),
99
-                'singular_name' => __('Catalog', 'wpshop'),
100
-                'add_new_item' => __('Add new product', 'wpshop'),
101
-                'add_new' => __('Add new product', 'wpshop'),
102
-                'add_new_item' => __('Add new product', 'wpshop'),
103
-                'edit_item' => __('Edit product', 'wpshop'),
104
-                'new_item' => __('New product', 'wpshop'),
105
-                'view_item' => __('View product', 'wpshop'),
106
-                'search_items' => __('Search products', 'wpshop'),
107
-                'not_found' => __('No products found', 'wpshop'),
108
-                'not_found_in_trash' => __('No products found in Trash', 'wpshop'),
109
-                'parent_item_colon' => '',
110
-            ),
111
-            'supports' => unserialize(WPSHOP_REGISTER_POST_TYPE_SUPPORT),
112
-            'public' => true,
113
-            'has_archive' => false,
114
-            'show_in_nav_menus' => true,
115
-            //'rewrite'                 => false,    //    For information see below
116
-            'taxonomies' => array(WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES),
117
-            'menu_icon' => 'dashicons-archive',
118
-            'rewrite' => $slug,
119
-        )));
120
-
121
-        /*    Définition des variations de produit (Déclinaisons)    */
122
-        register_post_type(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, apply_filters(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION . '_register', array(
123
-            'labels' => array(
124
-                'name' => __('Variations', 'wpshop'),
125
-                'singular_name' => __('Variation', 'wpshop'),
126
-                'add_new' => __('Add Variation', 'wpshop'),
127
-                'add_new_item' => __('Add New Variation', 'wpshop'),
128
-                'edit' => __('Edit', 'wpshop'),
129
-                'edit_item' => __('Edit Variation', 'wpshop'),
130
-                'new_item' => __('New Variation', 'wpshop'),
131
-                'view' => __('View Variation', 'wpshop'),
132
-                'view_item' => __('View Variation', 'wpshop'),
133
-                'search_items' => __('Search Variations', 'wpshop'),
134
-                'not_found' => __('No Variations found', 'wpshop'),
135
-                'not_found_in_trash' => __('No Variations found in trash', 'wpshop'),
136
-                'parent_item_colon' => '',
137
-            ),
138
-            'supports' => unserialize(WPSHOP_REGISTER_POST_TYPE_SUPPORT),
139
-            'public' => true,
140
-            'has_archive' => true,
141
-            'show_in_nav_menus' => false,
142
-            'show_in_menu' => false, //'edit.php?post_type=' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT,
143
-
144
-            'publicly_queryable' => false,
145
-            'exclude_from_search' => true,
146
-            'hierarchical' => false,
147
-
148
-            //             'public'                 => true,
149
-            //             'show_ui'                 => false,
150
-            //             'rewrite'                 => false,
151
-            //             'query_var'                => true,
152
-            //             'supports'                 => array( 'title', 'editor', 'page-attributes', 'thumbnail' ),
153
-            //             'show_in_nav_menus'     => false
154
-        )
155
-        ));
156
-
157
-        // add to our plugin init function
158
-        //global $wp_rewrite;
159
-        /*    Slug url is set into option    */
160
-        /*$options = get_option('wpshop_catalog_product_option', array());
80
+		$slug = array(
81
+			'slug' => '',
82
+			'with_front' => false,
83
+		);
84
+
85
+		if (empty($options['wpshop_catalog_product_slug']) || $options['wpshop_catalog_product_slug'] == '/') {
86
+			$slug = false;
87
+		} else {
88
+			$slug['slug'] = $options['wpshop_catalog_product_slug'];
89
+			if (!empty($options['wpshop_catalog_product_slug_with_category'])) {
90
+				$slug['slug'] .= '/%' . WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES . '%';
91
+			}
92
+		}
93
+		/*$product_slug .= '/%' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '%';*/
94
+
95
+		/*    Définition des produits     */
96
+		register_post_type(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, apply_filters(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_register', array(
97
+			'labels' => array(
98
+				'name' => __('Products', 'wpshop'),
99
+				'singular_name' => __('Catalog', 'wpshop'),
100
+				'add_new_item' => __('Add new product', 'wpshop'),
101
+				'add_new' => __('Add new product', 'wpshop'),
102
+				'add_new_item' => __('Add new product', 'wpshop'),
103
+				'edit_item' => __('Edit product', 'wpshop'),
104
+				'new_item' => __('New product', 'wpshop'),
105
+				'view_item' => __('View product', 'wpshop'),
106
+				'search_items' => __('Search products', 'wpshop'),
107
+				'not_found' => __('No products found', 'wpshop'),
108
+				'not_found_in_trash' => __('No products found in Trash', 'wpshop'),
109
+				'parent_item_colon' => '',
110
+			),
111
+			'supports' => unserialize(WPSHOP_REGISTER_POST_TYPE_SUPPORT),
112
+			'public' => true,
113
+			'has_archive' => false,
114
+			'show_in_nav_menus' => true,
115
+			//'rewrite'                 => false,    //    For information see below
116
+			'taxonomies' => array(WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES),
117
+			'menu_icon' => 'dashicons-archive',
118
+			'rewrite' => $slug,
119
+		)));
120
+
121
+		/*    Définition des variations de produit (Déclinaisons)    */
122
+		register_post_type(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, apply_filters(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION . '_register', array(
123
+			'labels' => array(
124
+				'name' => __('Variations', 'wpshop'),
125
+				'singular_name' => __('Variation', 'wpshop'),
126
+				'add_new' => __('Add Variation', 'wpshop'),
127
+				'add_new_item' => __('Add New Variation', 'wpshop'),
128
+				'edit' => __('Edit', 'wpshop'),
129
+				'edit_item' => __('Edit Variation', 'wpshop'),
130
+				'new_item' => __('New Variation', 'wpshop'),
131
+				'view' => __('View Variation', 'wpshop'),
132
+				'view_item' => __('View Variation', 'wpshop'),
133
+				'search_items' => __('Search Variations', 'wpshop'),
134
+				'not_found' => __('No Variations found', 'wpshop'),
135
+				'not_found_in_trash' => __('No Variations found in trash', 'wpshop'),
136
+				'parent_item_colon' => '',
137
+			),
138
+			'supports' => unserialize(WPSHOP_REGISTER_POST_TYPE_SUPPORT),
139
+			'public' => true,
140
+			'has_archive' => true,
141
+			'show_in_nav_menus' => false,
142
+			'show_in_menu' => false, //'edit.php?post_type=' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT,
143
+
144
+			'publicly_queryable' => false,
145
+			'exclude_from_search' => true,
146
+			'hierarchical' => false,
147
+
148
+			//             'public'                 => true,
149
+			//             'show_ui'                 => false,
150
+			//             'rewrite'                 => false,
151
+			//             'query_var'                => true,
152
+			//             'supports'                 => array( 'title', 'editor', 'page-attributes', 'thumbnail' ),
153
+			//             'show_in_nav_menus'     => false
154
+		)
155
+		));
156
+
157
+		// add to our plugin init function
158
+		//global $wp_rewrite;
159
+		/*    Slug url is set into option    */
160
+		/*$options = get_option('wpshop_catalog_product_option', array());
161 161
         $gallery_structure = (!empty($options['wpshop_catalog_product_slug']) ? $options['wpshop_catalog_product_slug'] : 'catalog');
162 162
         $gallery_structure .= !empty($options['wpshop_catalog_product_slug_with_category']) ? '/%' . WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES . '%' : '';
163 163
         $gallery_structure .= '/%' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '%';
164 164
         $wp_rewrite->add_permastruct(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, $gallery_structure, false);
165 165
         $wp_rewrite->add_rewrite_tag('%' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '%', '([^/]+)', WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . "=");*/
166
-        //    flush_rewrite_rules();
167
-    }
166
+		//    flush_rewrite_rules();
167
+	}
168 168
 
169
-    public static function hidden_meta_boxes($hidden, $screen, $use_defaults)
170
-    {
171
-        global $wpdb;
172
-        if (WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT === $screen->post_type) {
173
-            $user_meta_for_wpshop = array('metaboxhidden_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT);
174
-            foreach ($user_meta_for_wpshop as $meta_to_check) {
175
-                $metas_hidden = get_user_meta(get_current_user_id(), $meta_to_check, true);
176
-                if (empty($metas_hidden) && !is_array($metas_hidden)) {
177
-                    $hidden = unserialize(WPSHOP_PRODUCT_HIDDEN_METABOX);
178
-                }
179
-            }
180
-        }
181
-        return $hidden;
182
-    }
169
+	public static function hidden_meta_boxes($hidden, $screen, $use_defaults)
170
+	{
171
+		global $wpdb;
172
+		if (WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT === $screen->post_type) {
173
+			$user_meta_for_wpshop = array('metaboxhidden_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT);
174
+			foreach ($user_meta_for_wpshop as $meta_to_check) {
175
+				$metas_hidden = get_user_meta(get_current_user_id(), $meta_to_check, true);
176
+				if (empty($metas_hidden) && !is_array($metas_hidden)) {
177
+					$hidden = unserialize(WPSHOP_PRODUCT_HIDDEN_METABOX);
178
+				}
179
+			}
180
+		}
181
+		return $hidden;
182
+	}
183 183
 
184 184
 	public static function admin_menu() {
185 185
 		global $submenu;
@@ -206,35 +206,35 @@  discard block
 block discarded – undo
206 206
 		$submenu['edit.php?post_type=wpshop_product'] = $submenu_reorder;
207 207
 	}
208 208
 
209
-    /**
210
-     *    Create the different bow for the product management page looking for the attribute set to create the different boxes
211
-     */
212
-    public static function add_meta_boxes()
213
-    {
214
-        global $post, $currentTabContent;
215
-
216
-        if (!empty($post->post_type) && (($post->post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT) || ($post->post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION))) {
217
-            /*    Get the attribute set list for the current entity    */
218
-            $attributeEntitySetList = wpshop_attributes_set::get_attribute_set_list_for_entity(wpshop_entities::get_entity_identifier_from_code(self::currentPageCode));
219
-            /*    Check if the meta information of the current product already exists     */
220
-            $post_attribute_set_id = get_post_meta($post->ID, WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, true);
221
-            /*    Check if the product has been saved without meta information set    */
222
-            $attribute_set_id = wpshop_attributes::get_attribute_value_content('product_attribute_set_id', $post->ID, self::currentPageCode);
223
-            /*    Unset 'free_product' from list of attributes set    */
224
-            foreach ($attributeEntitySetList as $key_attribute_set => $attribute_set) {
225
-                if ($attribute_set->slug == 'free_product') {
226
-                    unset($attributeEntitySetList[$key_attribute_set]);
227
-                    break;
228
-                }
229
-            }
230
-
231
-            /*    Check if an attribute has already been choosen for the curernt entity or if the user has to choose a entity set before continuing    */
232
-            if (((count($attributeEntitySetList) == 1) || ((count($attributeEntitySetList) > 1) && (($post_attribute_set_id > 0) || (isset($attribute_set_id->value) && ($attribute_set_id->value > 0)))))) {
233
-                if ((count($attributeEntitySetList) == 1) || (($post_attribute_set_id <= 0) && ($attribute_set_id->value <= 0))) {
234
-                    $post_attribute_set_id = $attributeEntitySetList[0]->id;
235
-                } elseif (($post_attribute_set_id <= 0) && ($attribute_set_id->value > 0)) {
236
-                    $post_attribute_set_id = $attribute_set_id->value;
237
-                }
209
+	/**
210
+	 *    Create the different bow for the product management page looking for the attribute set to create the different boxes
211
+	 */
212
+	public static function add_meta_boxes()
213
+	{
214
+		global $post, $currentTabContent;
215
+
216
+		if (!empty($post->post_type) && (($post->post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT) || ($post->post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION))) {
217
+			/*    Get the attribute set list for the current entity    */
218
+			$attributeEntitySetList = wpshop_attributes_set::get_attribute_set_list_for_entity(wpshop_entities::get_entity_identifier_from_code(self::currentPageCode));
219
+			/*    Check if the meta information of the current product already exists     */
220
+			$post_attribute_set_id = get_post_meta($post->ID, WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, true);
221
+			/*    Check if the product has been saved without meta information set    */
222
+			$attribute_set_id = wpshop_attributes::get_attribute_value_content('product_attribute_set_id', $post->ID, self::currentPageCode);
223
+			/*    Unset 'free_product' from list of attributes set    */
224
+			foreach ($attributeEntitySetList as $key_attribute_set => $attribute_set) {
225
+				if ($attribute_set->slug == 'free_product') {
226
+					unset($attributeEntitySetList[$key_attribute_set]);
227
+					break;
228
+				}
229
+			}
230
+
231
+			/*    Check if an attribute has already been choosen for the curernt entity or if the user has to choose a entity set before continuing    */
232
+			if (((count($attributeEntitySetList) == 1) || ((count($attributeEntitySetList) > 1) && (($post_attribute_set_id > 0) || (isset($attribute_set_id->value) && ($attribute_set_id->value > 0)))))) {
233
+				if ((count($attributeEntitySetList) == 1) || (($post_attribute_set_id <= 0) && ($attribute_set_id->value <= 0))) {
234
+					$post_attribute_set_id = $attributeEntitySetList[0]->id;
235
+				} elseif (($post_attribute_set_id <= 0) && ($attribute_set_id->value > 0)) {
236
+					$post_attribute_set_id = $attribute_set_id->value;
237
+				}
238 238
 
239 239
 		/*$post_attribute_set_id = (int) get_post_meta($post->ID, WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, true);
240 240
 
@@ -252,32 +252,32 @@  discard block
 block discarded – undo
252 252
 			}
253 253
 		}*/
254 254
 
255
-                $currentTabContent = wpshop_attributes::entities_attribute_box($post_attribute_set_id, self::currentPageCode, $post->ID);
256
-
257
-                $fixed_box_exist = false;
258
-                /*    Get all the other attribute set for hte current entity    */
259
-                if (isset($currentTabContent['box']) && count($currentTabContent['box']) > 0) {
260
-                    foreach ($currentTabContent['box'] as $boxIdentifier => $boxTitle) {
261
-                        if (!empty($currentTabContent['box'][$boxIdentifier . '_backend_display_type']) && ($currentTabContent['box'][$boxIdentifier . '_backend_display_type'] == 'movable-tab')) {
262
-                            add_meta_box('wpshop_product_' . $boxIdentifier, __($boxTitle, 'wpshop'), array('wpshop_products', 'meta_box_content'), WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'normal', 'default', array('boxIdentifier' => $boxIdentifier));
263
-                        } else {
264
-                            $fixed_box_exist = true;
265
-                        }
266
-
267
-                    }
268
-                }
269
-                if ($fixed_box_exist) {
270
-                    add_meta_box('wpshop_product_fixed_tab', __('Product data', 'wpshop'), array('wpshop_products', 'product_data_meta_box'), WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'normal', 'high', array('currentTabContent' => $currentTabContent));
271
-                    add_meta_box('wpshop_product_fixed_tab', __('Product data', 'wpshop'), array('wpshop_products', 'product_data_meta_box'), WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, 'normal', 'high', array('currentTabContent' => $currentTabContent));
272
-                }
273
-
274
-                add_meta_box('wpshop_wpshop_variations', __('Product variation', 'wpshop'), array('wpshop_products', 'meta_box_variations'), WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'normal', 'default');
275
-                // Actions
276
-                // @since 1.4.3.7 Deleted
277
-                //add_meta_box('wpshop_product_actions', __('Actions', 'wpshop'), array('wpshop_products', 'product_actions_meta_box_content'), WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'side', 'default');
278
-
279
-                /**    Product option    */
280
-                add_meta_box('wpshop_product_options', __('Options', 'wpshop'), array('wpshop_products', 'product_options_meta_box_content'), WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'side', 'default');
255
+				$currentTabContent = wpshop_attributes::entities_attribute_box($post_attribute_set_id, self::currentPageCode, $post->ID);
256
+
257
+				$fixed_box_exist = false;
258
+				/*    Get all the other attribute set for hte current entity    */
259
+				if (isset($currentTabContent['box']) && count($currentTabContent['box']) > 0) {
260
+					foreach ($currentTabContent['box'] as $boxIdentifier => $boxTitle) {
261
+						if (!empty($currentTabContent['box'][$boxIdentifier . '_backend_display_type']) && ($currentTabContent['box'][$boxIdentifier . '_backend_display_type'] == 'movable-tab')) {
262
+							add_meta_box('wpshop_product_' . $boxIdentifier, __($boxTitle, 'wpshop'), array('wpshop_products', 'meta_box_content'), WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'normal', 'default', array('boxIdentifier' => $boxIdentifier));
263
+						} else {
264
+							$fixed_box_exist = true;
265
+						}
266
+
267
+					}
268
+				}
269
+				if ($fixed_box_exist) {
270
+					add_meta_box('wpshop_product_fixed_tab', __('Product data', 'wpshop'), array('wpshop_products', 'product_data_meta_box'), WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'normal', 'high', array('currentTabContent' => $currentTabContent));
271
+					add_meta_box('wpshop_product_fixed_tab', __('Product data', 'wpshop'), array('wpshop_products', 'product_data_meta_box'), WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, 'normal', 'high', array('currentTabContent' => $currentTabContent));
272
+				}
273
+
274
+				add_meta_box('wpshop_wpshop_variations', __('Product variation', 'wpshop'), array('wpshop_products', 'meta_box_variations'), WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'normal', 'default');
275
+				// Actions
276
+				// @since 1.4.3.7 Deleted
277
+				//add_meta_box('wpshop_product_actions', __('Actions', 'wpshop'), array('wpshop_products', 'product_actions_meta_box_content'), WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'side', 'default');
278
+
279
+				/**    Product option    */
280
+				add_meta_box('wpshop_product_options', __('Options', 'wpshop'), array('wpshop_products', 'product_options_meta_box_content'), WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'side', 'default');
281 281
 				/*add_meta_box('wpshop_histo_attrs', __('Historic attributes', 'wpshop'), function($post) {
282 282
 					global $wpdb;
283 283
 					$limit = 40;
@@ -310,21 +310,21 @@  discard block
 block discarded – undo
310 310
 						'total' => $max_page
311 311
 					) );
312 312
 				}, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'side', 'default');*/
313
-            } else if (count($attributeEntitySetList) > 1) {
314
-                $input_def['id'] = 'product_attribute_set_id';
315
-                $input_def['name'] = 'product_attribute_set_id';
316
-                $input_def['value'] = '';
317
-                $input_def['type'] = 'select';
318
-                $input_def['possible_value'] = $attributeEntitySetList;
319
-
320
-                $input_def['value'] = '';
321
-                foreach ($attributeEntitySetList as $set) {
322
-                    if ($set->default_set == 'yes') {
323
-                        $input_def['value'] = $set->id;
324
-                    }
325
-                }
326
-
327
-                $currentTabContent['boxContent']['attribute_set_selector'] = '
313
+			} else if (count($attributeEntitySetList) > 1) {
314
+				$input_def['id'] = 'product_attribute_set_id';
315
+				$input_def['name'] = 'product_attribute_set_id';
316
+				$input_def['value'] = '';
317
+				$input_def['type'] = 'select';
318
+				$input_def['possible_value'] = $attributeEntitySetList;
319
+
320
+				$input_def['value'] = '';
321
+				foreach ($attributeEntitySetList as $set) {
322
+					if ($set->default_set == 'yes') {
323
+						$input_def['value'] = $set->id;
324
+					}
325
+				}
326
+
327
+				$currentTabContent['boxContent']['attribute_set_selector'] = '
328 328
 	<ul class="attribute_set_selector" >
329 329
 		<li class="attribute_set_selector_title_select" ><label for="title" >' . __('Choose a title for your product', 'wpshop') . '</label></li>
330 330
 		<li class="attribute_set_selector_group_selector" ><label for="' . $input_def['id'] . '" >' . __('Choose an attribute group for this product', 'wpshop') . '</label>&nbsp;' . wpshop_form::check_input_type($input_def, self::currentPageCode . '_attribute[integer]') . '</li>
@@ -332,791 +332,791 @@  discard block
 block discarded – undo
332 332
 		<li class="attribute_set_selector_after_save_instruction" >' . __('Once the group chosen, the different attribute will be displayed here', 'wpshop') . '</li>
333 333
 	</ul>';
334 334
 
335
-                add_meta_box('wpshop_product_attribute_set_selector', __('Product attributes', 'wpshop'), array('wpshop_products', 'meta_box_content'), WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'normal', 'high', array('boxIdentifier' => 'attribute_set_selector'));
336
-            }
337
-        }
335
+				add_meta_box('wpshop_product_attribute_set_selector', __('Product attributes', 'wpshop'), array('wpshop_products', 'meta_box_content'), WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'normal', 'high', array('boxIdentifier' => 'attribute_set_selector'));
336
+			}
337
+		}
338 338
 
339
-    }
339
+	}
340 340
 
341
-    /**
342
-     * Add a box into product edition page for options on the product
343
-     *
344
-     * @param object $post
345
-     */
346
-    public static function product_options_meta_box_content($post)
347
-    {
348
-        $output = '';
341
+	/**
342
+	 * Add a box into product edition page for options on the product
343
+	 *
344
+	 * @param object $post
345
+	 */
346
+	public static function product_options_meta_box_content($post)
347
+	{
348
+		$output = '';
349 349
 
350
-        $product_current_options = get_post_meta($post->ID, '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_options', true);
350
+		$product_current_options = get_post_meta($post->ID, '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_options', true);
351 351
 
352
-        $tpl_component = array();
353
-        $tpl_component['ADMIN_PRODUCT_OPTION_FOR_CART_AUTOADD_CHECKBOX_STATE'] = (!empty($product_current_options['cart']) && !empty($product_current_options['cart']['auto_add'])) ? ' checked="checked"' : '';
354
-        $output .= wpshop_display::display_template_element('wpshop_admin_product_option_for_cart', $tpl_component, array('type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'id' => $post->ID), 'admin');
352
+		$tpl_component = array();
353
+		$tpl_component['ADMIN_PRODUCT_OPTION_FOR_CART_AUTOADD_CHECKBOX_STATE'] = (!empty($product_current_options['cart']) && !empty($product_current_options['cart']['auto_add'])) ? ' checked="checked"' : '';
354
+		$output .= wpshop_display::display_template_element('wpshop_admin_product_option_for_cart', $tpl_component, array('type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'id' => $post->ID), 'admin');
355 355
 
356
-        echo $output;
357
-    }
356
+		echo $output;
357
+	}
358 358
 
359
-    /**
360
-     * Display the fixed box
361
-     */
362
-    public static function product_data_meta_box($post, $metaboxArgs)
363
-    {
364
-        $output = '';
359
+	/**
360
+	 * Display the fixed box
361
+	 */
362
+	public static function product_data_meta_box($post, $metaboxArgs)
363
+	{
364
+		$output = '';
365 365
 
366
-        $currentTabContent = $metaboxArgs['args']['currentTabContent'];
366
+		$currentTabContent = $metaboxArgs['args']['currentTabContent'];
367 367
 
368
-        echo '<div id="fixed-tabs" class="wpshop_tabs wpshop_detail_tabs wpshop_product_attribute_tabs" >
368
+		echo '<div id="fixed-tabs" class="wpshop_tabs wpshop_detail_tabs wpshop_product_attribute_tabs" >
369 369
 				<ul>';
370
-        if (!empty($currentTabContent['box'])) {
371
-            foreach ($currentTabContent['box'] as $boxIdentifier => $boxTitle) {
372
-                if (!empty($currentTabContent['boxContent'][$boxIdentifier])) {
373
-                    if ($currentTabContent['box'][$boxIdentifier . '_backend_display_type'] == 'fixed-tab') {
374
-                        echo '<li><a href="#tabs-' . sanitize_title($boxIdentifier) . '">' . __($boxTitle, 'wpshop') . '</a></li>';
375
-                    }
376
-                }
377
-            }
378
-        }
379
-        echo '<li><a href="#tabs-product-related">' . __('Related products', 'wpshop') . '</a></li>';
380
-        echo '<li><a href="#tabs-product-provider">' . __('Providers', 'wpshop') . '</a></li>';
381
-        echo '<li class="wpshop_product_data_display_tab" ><a href="#tabs-product-display">' . __('Product display', 'wpshop') . '</a></li>';
382
-        echo '</ul>';
383
-
384
-        if (!empty($currentTabContent['box'])) {
385
-            foreach ($currentTabContent['box'] as $boxIdentifier => $boxTitle) {
386
-                if (!empty($currentTabContent['boxContent'][$boxIdentifier])) {
387
-                    if ($currentTabContent['box'][$boxIdentifier . '_backend_display_type'] == 'fixed-tab') {
388
-                        echo '<div id="tabs-' . sanitize_title($boxIdentifier) . '">' . $currentTabContent['boxContent'][$boxIdentifier] . '</div>';
389
-                    }
390
-                }
391
-            }
392
-        }
370
+		if (!empty($currentTabContent['box'])) {
371
+			foreach ($currentTabContent['box'] as $boxIdentifier => $boxTitle) {
372
+				if (!empty($currentTabContent['boxContent'][$boxIdentifier])) {
373
+					if ($currentTabContent['box'][$boxIdentifier . '_backend_display_type'] == 'fixed-tab') {
374
+						echo '<li><a href="#tabs-' . sanitize_title($boxIdentifier) . '">' . __($boxTitle, 'wpshop') . '</a></li>';
375
+					}
376
+				}
377
+			}
378
+		}
379
+		echo '<li><a href="#tabs-product-related">' . __('Related products', 'wpshop') . '</a></li>';
380
+		echo '<li><a href="#tabs-product-provider">' . __('Providers', 'wpshop') . '</a></li>';
381
+		echo '<li class="wpshop_product_data_display_tab" ><a href="#tabs-product-display">' . __('Product display', 'wpshop') . '</a></li>';
382
+		echo '</ul>';
383
+
384
+		if (!empty($currentTabContent['box'])) {
385
+			foreach ($currentTabContent['box'] as $boxIdentifier => $boxTitle) {
386
+				if (!empty($currentTabContent['boxContent'][$boxIdentifier])) {
387
+					if ($currentTabContent['box'][$boxIdentifier . '_backend_display_type'] == 'fixed-tab') {
388
+						echo '<div id="tabs-' . sanitize_title($boxIdentifier) . '">' . $currentTabContent['boxContent'][$boxIdentifier] . '</div>';
389
+					}
390
+				}
391
+			}
392
+		}
393 393
 
394
-        echo '<div id="tabs-product-related">' . self::related_products_meta_box_content($post) . '</div>';
395
-        echo '<div id="tabs-product-provider">' . self::provider_products_meta_box_content($post) . '</div>';
396
-        echo '<div id="tabs-product-display">' . self::product_frontend_display_config_meta_box($post) . '</div>';
397
-        if (!empty($currentTabContent['boxMore'])) {
398
-            echo $currentTabContent['boxMore'];
399
-        }
400
-        echo '</div>';
394
+		echo '<div id="tabs-product-related">' . self::related_products_meta_box_content($post) . '</div>';
395
+		echo '<div id="tabs-product-provider">' . self::provider_products_meta_box_content($post) . '</div>';
396
+		echo '<div id="tabs-product-display">' . self::product_frontend_display_config_meta_box($post) . '</div>';
397
+		if (!empty($currentTabContent['boxMore'])) {
398
+			echo $currentTabContent['boxMore'];
399
+		}
400
+		echo '</div>';
401 401
 
402
-        echo $output;
403
-    }
402
+		echo $output;
403
+	}
404 404
 
405
-    /**
406
-     * Output the content for related product metabox
407
-     * @param object $post The current edited post
408
-     * @return string
409
-     */
410
-    public static function related_products_meta_box_content($post)
411
-    {
412
-        $content = $existing_selection = '';
413
-
414
-        if (!empty($post->ID)) {
415
-            $related_products_id = get_post_meta($post->ID, WPSHOP_PRODUCT_RELATED_PRODUCTS, true);
416
-            if (!empty($related_products_id) && !empty($related_products_id[0])) {
417
-                foreach ($related_products_id as $related_product_id) {
418
-                    $existing_selection .= '<option selected value="' . $related_product_id . '" >' . get_the_title($related_product_id) . '</option>';
419
-                }
420
-            }
421
-        }
405
+	/**
406
+	 * Output the content for related product metabox
407
+	 * @param object $post The current edited post
408
+	 * @return string
409
+	 */
410
+	public static function related_products_meta_box_content($post)
411
+	{
412
+		$content = $existing_selection = '';
413
+
414
+		if (!empty($post->ID)) {
415
+			$related_products_id = get_post_meta($post->ID, WPSHOP_PRODUCT_RELATED_PRODUCTS, true);
416
+			if (!empty($related_products_id) && !empty($related_products_id[0])) {
417
+				foreach ($related_products_id as $related_product_id) {
418
+					$existing_selection .= '<option selected value="' . $related_product_id . '" >' . get_the_title($related_product_id) . '</option>';
419
+				}
420
+			}
421
+		}
422 422
 
423
-        $content = '<p>' . __('Type the begin of the product name in the field below in order to add it to the related product list', 'wpshop') . '</p>
423
+		$content = '<p>' . __('Type the begin of the product name in the field below in order to add it to the related product list', 'wpshop') . '</p>
424 424
 			<select name="related_products_list[]" id="related_products_list" class="ajax_chosen_select_related_products" multiple >' . $existing_selection . '</select>
425 425
 			<input type="hidden" id="wpshop_ajax_search_element_type_related_products" name="wpshop_ajax_search_element_type" value="' . $post->post_type . '" />
426 426
 			<input type="hidden" id="wpshop_nonce_ajax_search_related_products" name="wpshop_nonce_ajax_search" value="' . wp_create_nonce("wpshop_element_search") . '" />';
427 427
 
428
-        return $content;
429
-    }
428
+		return $content;
429
+	}
430 430
 
431
-    /**
432
-     * Output the content for related product metabox
433
-     * @param object $post The current edited post
434
-     * @return string
435
-     */
436
-    public static function provider_products_meta_box_content($post)
437
-    {
438
-        $content = $existing_selection = '';
439
-
440
-        if (!empty($post->ID)) {
441
-            $providers_id = get_post_meta($post->ID, WPSHOP_PRODUCT_PROVIDER, true);
442
-            if (!empty($providers_id) && !empty($providers_id[0])) {
443
-                foreach ($providers_id as $provider_id) {
444
-                    $existing_selection .= '<option selected value="' . $provider_id . '" >' . get_the_title($provider_id) . '</option>';
445
-                }
446
-            }
447
-        }
431
+	/**
432
+	 * Output the content for related product metabox
433
+	 * @param object $post The current edited post
434
+	 * @return string
435
+	 */
436
+	public static function provider_products_meta_box_content($post)
437
+	{
438
+		$content = $existing_selection = '';
439
+
440
+		if (!empty($post->ID)) {
441
+			$providers_id = get_post_meta($post->ID, WPSHOP_PRODUCT_PROVIDER, true);
442
+			if (!empty($providers_id) && !empty($providers_id[0])) {
443
+				foreach ($providers_id as $provider_id) {
444
+					$existing_selection .= '<option selected value="' . $provider_id . '" >' . get_the_title($provider_id) . '</option>';
445
+				}
446
+			}
447
+		}
448 448
 
449
-        $content = '<p>' . __('Type the begin of a provider last name/first name in the field below to add', 'wpshop') . '</p>
449
+		$content = '<p>' . __('Type the begin of a provider last name/first name in the field below to add', 'wpshop') . '</p>
450 450
 			<select name="provider_list[]" id="provider_list" class="ajax_chosen_select_provider_products" multiple >' . $existing_selection . '</select>
451 451
 			<input type="hidden" id="wpshop_ajax_search_element_type_provider_products" name="wpshop_ajax_search_element_type" value="' . WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS . '" />
452 452
 			<input type="hidden" id="wpshop_nonce_ajax_search_provider_products" name="wpshop_nonce_ajax_search" value="' . wp_create_nonce("wpshop_element_search") . '" />';
453 453
 
454
-        return $content;
455
-    }
454
+		return $content;
455
+	}
456 456
 
457
-    /**
458
-     * Define the metabox content for the action box
459
-     * @param obejct $post The current element being edited
460
-     */
461
-    public static function product_actions_meta_box_content($post)
462
-    {
463
-        $output = '';
464
-        /*
457
+	/**
458
+	 * Define the metabox content for the action box
459
+	 * @param obejct $post The current element being edited
460
+	 */
461
+	public static function product_actions_meta_box_content($post)
462
+	{
463
+		$output = '';
464
+		/*
465 465
          * Template parameters
466 466
          */
467
-        $template_part = 'wpshop_duplicate_product';
468
-        $tpl_component = array();
469
-        $tpl_component['PRODUCT_ID'] = $post->ID;
470
-        $tpl_component['PRINT_PRODUCT_SHEET_LINK'] = admin_url('admin-post.php?action=wps_product_sheet&pid=' . $post->ID);
471
-        /*
467
+		$template_part = 'wpshop_duplicate_product';
468
+		$tpl_component = array();
469
+		$tpl_component['PRODUCT_ID'] = $post->ID;
470
+		$tpl_component['PRINT_PRODUCT_SHEET_LINK'] = admin_url('admin-post.php?action=wps_product_sheet&pid=' . $post->ID);
471
+		/*
472 472
          * Build template
473 473
          */
474
-        $output = wpshop_display::display_template_element($template_part, $tpl_component, array(), 'admin');
475
-        unset($tpl_component);
474
+		$output = wpshop_display::display_template_element($template_part, $tpl_component, array(), 'admin');
475
+		unset($tpl_component);
476 476
 
477
-        echo $output;
478
-    }
477
+		echo $output;
478
+	}
479 479
 
480
-    /**
481
-     *    Define the content of the product main information box
482
-     */
483
-    public static function meta_box_content($post, $metaboxArgs)
484
-    {
485
-        global $currentTabContent;
480
+	/**
481
+	 *    Define the content of the product main information box
482
+	 */
483
+	public static function meta_box_content($post, $metaboxArgs)
484
+	{
485
+		global $currentTabContent;
486 486
 
487
-        /*    Add the extra fields defined by the default attribute group in the general section    */
488
-        echo '<div class="wpshop_extra_field_container" >' . $currentTabContent['boxContent'][$metaboxArgs['args']['boxIdentifier']] . '</div>';
489
-    }
487
+		/*    Add the extra fields defined by the default attribute group in the general section    */
488
+		echo '<div class="wpshop_extra_field_container" >' . $currentTabContent['boxContent'][$metaboxArgs['args']['boxIdentifier']] . '</div>';
489
+	}
490 490
 
491
-    /**
492
-     * Define the metabox content for product custom display in product
493
-     * @param object $post The current element being edited
494
-     * @return string The metabox content
495
-     */
496
-    public static function product_frontend_display_config_meta_box($post)
497
-    {
498
-        $content = '';
499
-
500
-        $product_attribute_frontend_display_config = null;
501
-        if (!empty($post->ID)) {
502
-            $product_attribute_frontend_display_config = get_post_meta($post->ID, WPSHOP_PRODUCT_FRONT_DISPLAY_CONF, true);
503
-
504
-            $extra_options = get_option('wpshop_extra_options', array());
505
-            $column_count = (!empty($extra_options['WPSHOP_COLUMN_NUMBER_PRODUCT_EDITION_FOR_FRONT_DISPLAY']) ? $extra_options['WPSHOP_COLUMN_NUMBER_PRODUCT_EDITION_FOR_FRONT_DISPLAY'] : 3);
506
-            $attribute_list = wpshop_attributes::getElementWithAttributeAndValue(wpshop_entities::get_entity_identifier_from_code(self::currentPageCode), $post->ID, WPSHOP_CURRENT_LOCALE);
507
-            $column = 1;
508
-
509
-            if (WPSHOP_DEFINED_SHOP_TYPE == 'sale') {
510
-                $sub_tpl_component = array();
511
-                $sub_tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_NAME'] = __('Action on product', 'wpshop');
512
-
513
-                $tpl_component = array();
514
-                $tpl_component['ADMIN_ATTRIBUTE_LABEL'] = __('Add to cart button', 'wpshop');
515
-                $tpl_component['ADMIN_ATTRIBUTE_FD_NAME'] = self::currentPageCode . '_attr_frontend_display[product_action_button][add_to_cart]';
516
-                $tpl_component['ADMIN_ATTRIBUTE_FD_ID'] = $post->ID . '_product_action_button_add_to_cart';
517
-                $button_is_set_to_be_displayed = (WPSHOP_DEFINED_SHOP_TYPE == 'sale') ? 'yes' : 'no';
518
-
519
-                $tpl_component['ADMIN_ATTRIBUTE_COMPLETE_SHEET_CHECK'] = wpshop_attributes::check_attribute_display($button_is_set_to_be_displayed, $product_attribute_frontend_display_config, 'product_action_button', 'add_to_cart', 'complete_sheet') ? ' checked="checked"' : '';
520
-                $tpl_component['ADMIN_ATTRIBUTE_MINI_OUTPUT_CHECK'] = wpshop_attributes::check_attribute_display($button_is_set_to_be_displayed, $product_attribute_frontend_display_config, 'product_action_button', 'add_to_cart', 'mini_output') ? ' checked="checked"' : '';
521
-                $sub_tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_CONTENT'] = wpshop_display::display_template_element('wpshop_admin_attr_config_for_front_display', $tpl_component, array(), 'admin');
522
-                unset($tpl_component);
523
-
524
-                $sub_tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_FD_NAME'] = self::currentPageCode . '_attr_frontend_display[product_action_button][add_to_cart]';
525
-                $sub_tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_FD_ID'] = 'product_action_button_add_to_cart';
526
-                $sub_tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_INPUT_CHECKBOX'] = '';
527
-                $sub_content[1] = wpshop_display::display_template_element('wpshop_admin_attr_set_section_for_front_display', $sub_tpl_component, array(), 'admin');
528
-            }
529
-
530
-            if (!empty($attribute_list[$post->ID]) && is_array($attribute_list[$post->ID])) {
531
-                foreach ($attribute_list[$post->ID] as $attribute_set_section_name => $attribute_set_section_content) {
532
-                    if (!isset($sub_content[$column])) {
533
-                        $sub_content[$column] = '';
534
-                    }
535
-
536
-                    $attribute_sub_output = '';
537
-                    foreach ($attribute_set_section_content['attributes'] as $attribute_id => $attribute_def) {
538
-                        if ($attribute_def['attribute_code'] != 'product_attribute_set_id') {
539
-                            $tpl_component = array();
540
-                            $tpl_component['ADMIN_ATTRIBUTE_LABEL'] = $attribute_def['frontend_label'];
541
-                            $tpl_component['ADMIN_ATTRIBUTE_FD_NAME'] = self::currentPageCode . '_attr_frontend_display[attribute][' . $attribute_def['attribute_code'] . ']';
542
-                            $tpl_component['ADMIN_ATTRIBUTE_FD_ID'] = $post->ID . '_' . $attribute_def['attribute_code'];
543
-                            $tpl_component['ADMIN_ATTRIBUTE_COMPLETE_SHEET_CHECK'] = wpshop_attributes::check_attribute_display($attribute_def['is_visible_in_front'], $product_attribute_frontend_display_config, 'attribute', $attribute_def['attribute_code'], 'complete_sheet') ? ' checked="checked"' : '';
544
-                            $tpl_component['ADMIN_ATTRIBUTE_MINI_OUTPUT_CHECK'] = wpshop_attributes::check_attribute_display($attribute_def['is_visible_in_front_listing'], $product_attribute_frontend_display_config, 'attribute', $attribute_def['attribute_code'], 'mini_output') ? ' checked="checked"' : '';
545
-                            $attribute_sub_output .= wpshop_display::display_template_element('wpshop_admin_attr_config_for_front_display', $tpl_component, array(), 'admin');
546
-                            unset($tpl_component);
547
-                        }
548
-                    }
549
-
550
-                    $tpl_component = array();
551
-                    $tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_NAME'] = $attribute_set_section_name;
552
-                    $tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_CONTENT'] = $attribute_sub_output;
553
-                    $tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_FD_NAME'] = self::currentPageCode . '_attr_frontend_display[attribute_set_section][' . $attribute_set_section_content['code'] . ']';
554
-                    $tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_FD_ID'] = $attribute_set_section_content['code'];
555
-                    $ADMIN_ATTRIBUTE_SET_SECTION_COMPLETE_SHEET_CHECK = wpshop_attributes::check_attribute_display($attribute_set_section_content['display_on_frontend'], $product_attribute_frontend_display_config, 'attribute_set_section', $attribute_set_section_content['code'], 'complete_sheet') ? ' checked="checked"' : '';
556
-                    $tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_INPUT_CHECKBOX'] = '<input type="checkbox" name="' . self::currentPageCode . '_attr_frontend_display[attribute_set_section][' . $attribute_set_section_content['code'] . '][complete_sheet]" id="' . $attribute_set_section_content['code'] . '_complete_sheet" value="yes"' . $ADMIN_ATTRIBUTE_SET_SECTION_COMPLETE_SHEET_CHECK . ' /><label for="' . $attribute_set_section_content['code'] . '_complete_sheet" >' . __('Display in product page', 'wpshop') . '</label>';
557
-                    $sub_content[$column] .= wpshop_display::display_template_element('wpshop_admin_attr_set_section_for_front_display', $tpl_component, array(), 'admin');
558
-                    $column++;
559
-                    if ($column > $column_count) {
560
-                        $column = 1;
561
-                    }
562
-                }
563
-            }
564
-            $tpl_component = array();
565
-            $tpl_component['ADMIN_ATTRIBUTE_FRONTEND_DISPLAY_CONTENT'] = '';
566
-            for ($i = 1; $i <= $column_count; $i++) {
567
-                if (!empty($sub_content[$i])) {
568
-                    $tpl_component['ADMIN_ATTRIBUTE_FRONTEND_DISPLAY_CONTENT'] .= '<div class="alignleft" >' . $sub_content[$i] . '</div>';
569
-                }
570
-
571
-            }
572
-            $tpl_component['ADMIN_ATTRIBUTE_FRONTEND_DISPLAY_CONTENT_CLASS'] = empty($product_attribute_frontend_display_config) ? ' class="wpshopHide" ' : '';
573
-            $tpl_component['ADMIN_PRODUCT_ATTRIBUTE_FRONTEND_DISPLAY_MAIN_CHOICE_CHECK'] = empty($product_attribute_frontend_display_config) ? ' checked="checked"' : '';
574
-            $tpl_component['ADMIN_ATTRIBUTE_FD_NAME'] = self::currentPageCode . '_attr_frontend_display';
575
-
576
-            $content = wpshop_display::display_template_element('wpshop_admin_attr_set_section_for_front_display_default_choice', $tpl_component, array(), 'admin') . '<div class="wpshop_cls"></div>';
577
-        }
491
+	/**
492
+	 * Define the metabox content for product custom display in product
493
+	 * @param object $post The current element being edited
494
+	 * @return string The metabox content
495
+	 */
496
+	public static function product_frontend_display_config_meta_box($post)
497
+	{
498
+		$content = '';
499
+
500
+		$product_attribute_frontend_display_config = null;
501
+		if (!empty($post->ID)) {
502
+			$product_attribute_frontend_display_config = get_post_meta($post->ID, WPSHOP_PRODUCT_FRONT_DISPLAY_CONF, true);
503
+
504
+			$extra_options = get_option('wpshop_extra_options', array());
505
+			$column_count = (!empty($extra_options['WPSHOP_COLUMN_NUMBER_PRODUCT_EDITION_FOR_FRONT_DISPLAY']) ? $extra_options['WPSHOP_COLUMN_NUMBER_PRODUCT_EDITION_FOR_FRONT_DISPLAY'] : 3);
506
+			$attribute_list = wpshop_attributes::getElementWithAttributeAndValue(wpshop_entities::get_entity_identifier_from_code(self::currentPageCode), $post->ID, WPSHOP_CURRENT_LOCALE);
507
+			$column = 1;
508
+
509
+			if (WPSHOP_DEFINED_SHOP_TYPE == 'sale') {
510
+				$sub_tpl_component = array();
511
+				$sub_tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_NAME'] = __('Action on product', 'wpshop');
512
+
513
+				$tpl_component = array();
514
+				$tpl_component['ADMIN_ATTRIBUTE_LABEL'] = __('Add to cart button', 'wpshop');
515
+				$tpl_component['ADMIN_ATTRIBUTE_FD_NAME'] = self::currentPageCode . '_attr_frontend_display[product_action_button][add_to_cart]';
516
+				$tpl_component['ADMIN_ATTRIBUTE_FD_ID'] = $post->ID . '_product_action_button_add_to_cart';
517
+				$button_is_set_to_be_displayed = (WPSHOP_DEFINED_SHOP_TYPE == 'sale') ? 'yes' : 'no';
518
+
519
+				$tpl_component['ADMIN_ATTRIBUTE_COMPLETE_SHEET_CHECK'] = wpshop_attributes::check_attribute_display($button_is_set_to_be_displayed, $product_attribute_frontend_display_config, 'product_action_button', 'add_to_cart', 'complete_sheet') ? ' checked="checked"' : '';
520
+				$tpl_component['ADMIN_ATTRIBUTE_MINI_OUTPUT_CHECK'] = wpshop_attributes::check_attribute_display($button_is_set_to_be_displayed, $product_attribute_frontend_display_config, 'product_action_button', 'add_to_cart', 'mini_output') ? ' checked="checked"' : '';
521
+				$sub_tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_CONTENT'] = wpshop_display::display_template_element('wpshop_admin_attr_config_for_front_display', $tpl_component, array(), 'admin');
522
+				unset($tpl_component);
523
+
524
+				$sub_tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_FD_NAME'] = self::currentPageCode . '_attr_frontend_display[product_action_button][add_to_cart]';
525
+				$sub_tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_FD_ID'] = 'product_action_button_add_to_cart';
526
+				$sub_tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_INPUT_CHECKBOX'] = '';
527
+				$sub_content[1] = wpshop_display::display_template_element('wpshop_admin_attr_set_section_for_front_display', $sub_tpl_component, array(), 'admin');
528
+			}
578 529
 
579
-        return $content;
580
-    }
530
+			if (!empty($attribute_list[$post->ID]) && is_array($attribute_list[$post->ID])) {
531
+				foreach ($attribute_list[$post->ID] as $attribute_set_section_name => $attribute_set_section_content) {
532
+					if (!isset($sub_content[$column])) {
533
+						$sub_content[$column] = '';
534
+					}
535
+
536
+					$attribute_sub_output = '';
537
+					foreach ($attribute_set_section_content['attributes'] as $attribute_id => $attribute_def) {
538
+						if ($attribute_def['attribute_code'] != 'product_attribute_set_id') {
539
+							$tpl_component = array();
540
+							$tpl_component['ADMIN_ATTRIBUTE_LABEL'] = $attribute_def['frontend_label'];
541
+							$tpl_component['ADMIN_ATTRIBUTE_FD_NAME'] = self::currentPageCode . '_attr_frontend_display[attribute][' . $attribute_def['attribute_code'] . ']';
542
+							$tpl_component['ADMIN_ATTRIBUTE_FD_ID'] = $post->ID . '_' . $attribute_def['attribute_code'];
543
+							$tpl_component['ADMIN_ATTRIBUTE_COMPLETE_SHEET_CHECK'] = wpshop_attributes::check_attribute_display($attribute_def['is_visible_in_front'], $product_attribute_frontend_display_config, 'attribute', $attribute_def['attribute_code'], 'complete_sheet') ? ' checked="checked"' : '';
544
+							$tpl_component['ADMIN_ATTRIBUTE_MINI_OUTPUT_CHECK'] = wpshop_attributes::check_attribute_display($attribute_def['is_visible_in_front_listing'], $product_attribute_frontend_display_config, 'attribute', $attribute_def['attribute_code'], 'mini_output') ? ' checked="checked"' : '';
545
+							$attribute_sub_output .= wpshop_display::display_template_element('wpshop_admin_attr_config_for_front_display', $tpl_component, array(), 'admin');
546
+							unset($tpl_component);
547
+						}
548
+					}
581 549
 
582
-    /**
583
-     * Retrieve the attribute list used for sorting product into frontend listing
584
-     * @return array The attribute list to use for listing sorting
585
-     */
586
-    public static function get_sorting_criteria()
587
-    {
588
-        global $wpdb;
550
+					$tpl_component = array();
551
+					$tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_NAME'] = $attribute_set_section_name;
552
+					$tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_CONTENT'] = $attribute_sub_output;
553
+					$tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_FD_NAME'] = self::currentPageCode . '_attr_frontend_display[attribute_set_section][' . $attribute_set_section_content['code'] . ']';
554
+					$tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_FD_ID'] = $attribute_set_section_content['code'];
555
+					$ADMIN_ATTRIBUTE_SET_SECTION_COMPLETE_SHEET_CHECK = wpshop_attributes::check_attribute_display($attribute_set_section_content['display_on_frontend'], $product_attribute_frontend_display_config, 'attribute_set_section', $attribute_set_section_content['code'], 'complete_sheet') ? ' checked="checked"' : '';
556
+					$tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_INPUT_CHECKBOX'] = '<input type="checkbox" name="' . self::currentPageCode . '_attr_frontend_display[attribute_set_section][' . $attribute_set_section_content['code'] . '][complete_sheet]" id="' . $attribute_set_section_content['code'] . '_complete_sheet" value="yes"' . $ADMIN_ATTRIBUTE_SET_SECTION_COMPLETE_SHEET_CHECK . ' /><label for="' . $attribute_set_section_content['code'] . '_complete_sheet" >' . __('Display in product page', 'wpshop') . '</label>';
557
+					$sub_content[$column] .= wpshop_display::display_template_element('wpshop_admin_attr_set_section_for_front_display', $tpl_component, array(), 'admin');
558
+					$column++;
559
+					if ($column > $column_count) {
560
+						$column = 1;
561
+					}
562
+				}
563
+			}
564
+			$tpl_component = array();
565
+			$tpl_component['ADMIN_ATTRIBUTE_FRONTEND_DISPLAY_CONTENT'] = '';
566
+			for ($i = 1; $i <= $column_count; $i++) {
567
+				if (!empty($sub_content[$i])) {
568
+					$tpl_component['ADMIN_ATTRIBUTE_FRONTEND_DISPLAY_CONTENT'] .= '<div class="alignleft" >' . $sub_content[$i] . '</div>';
569
+				}
589 570
 
590
-        $data = array(array('code' => 'title', 'frontend_label' => __('Product name', 'wpshop')), array('code' => 'date', 'frontend_label' => __('Date added', 'wpshop')), array('code' => 'modified', 'frontend_label' => __('Date modified', 'wpshop')), array('code' => 'rand', 'frontend_label' => __('Random', 'wpshop')));
571
+			}
572
+			$tpl_component['ADMIN_ATTRIBUTE_FRONTEND_DISPLAY_CONTENT_CLASS'] = empty($product_attribute_frontend_display_config) ? ' class="wpshopHide" ' : '';
573
+			$tpl_component['ADMIN_PRODUCT_ATTRIBUTE_FRONTEND_DISPLAY_MAIN_CHOICE_CHECK'] = empty($product_attribute_frontend_display_config) ? ' checked="checked"' : '';
574
+			$tpl_component['ADMIN_ATTRIBUTE_FD_NAME'] = self::currentPageCode . '_attr_frontend_display';
591 575
 
592
-        $query = $wpdb->prepare("SELECT code, frontend_label FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE is_used_for_sort_by = %s", 'yes');
593
-        $results = $wpdb->get_results($query, ARRAY_A);
594
-        if (!empty($results)) {
595
-            $data = array_merge($data, $results);
596
-        }
576
+			$content = wpshop_display::display_template_element('wpshop_admin_attr_set_section_for_front_display_default_choice', $tpl_component, array(), 'admin') . '<div class="wpshop_cls"></div>';
577
+		}
597 578
 
598
-        return $data;
599
-    }
579
+		return $content;
580
+	}
581
+
582
+	/**
583
+	 * Retrieve the attribute list used for sorting product into frontend listing
584
+	 * @return array The attribute list to use for listing sorting
585
+	 */
586
+	public static function get_sorting_criteria()
587
+	{
588
+		global $wpdb;
589
+
590
+		$data = array(array('code' => 'title', 'frontend_label' => __('Product name', 'wpshop')), array('code' => 'date', 'frontend_label' => __('Date added', 'wpshop')), array('code' => 'modified', 'frontend_label' => __('Date modified', 'wpshop')), array('code' => 'rand', 'frontend_label' => __('Random', 'wpshop')));
591
+
592
+		$query = $wpdb->prepare("SELECT code, frontend_label FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE is_used_for_sort_by = %s", 'yes');
593
+		$results = $wpdb->get_results($query, ARRAY_A);
594
+		if (!empty($results)) {
595
+			$data = array_merge($data, $results);
596
+		}
597
+
598
+		return $data;
599
+	}
600 600
 
601
-    public static function get_products_matching_attribute($attr_name, $attr_value)
602
-    {
603
-        global $wpdb;
601
+	public static function get_products_matching_attribute($attr_name, $attr_value)
602
+	{
603
+		global $wpdb;
604 604
 
605
-        $products = array();
606
-        $query = "SELECT * FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE code=%s";
607
-        $data = (array) $wpdb->get_row($wpdb->prepare($query, $attr_name));
605
+		$products = array();
606
+		$query = "SELECT * FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE code=%s";
607
+		$data = (array) $wpdb->get_row($wpdb->prepare($query, $attr_name));
608 608
 
609
-        if (!empty($data)) {
610
-            if ($data['data_type_to_use'] == 'custom') {
611
-                // Find which table to take
612
-                if ($data['data_type'] == 'datetime') {$table_name = WPSHOP_DBT_ATTRIBUTE_VALUES_DATETIME;} elseif ($data['data_type'] == 'decimal') {$table_name = WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL;} elseif ($data['data_type'] == 'integer') {$table_name = WPSHOP_DBT_ATTRIBUTE_VALUES_INTEGER;} elseif ($data['data_type'] == 'options') {$table_name = WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS;} elseif ($data['data_type'] == 'text') {$table_name = WPSHOP_DBT_ATTRIBUTE_VALUES_TEXT;} elseif ($data['data_type'] == 'varchar') {$table_name = WPSHOP_DBT_ATTRIBUTE_VALUES_VARCHAR;}
609
+		if (!empty($data)) {
610
+			if ($data['data_type_to_use'] == 'custom') {
611
+				// Find which table to take
612
+				if ($data['data_type'] == 'datetime') {$table_name = WPSHOP_DBT_ATTRIBUTE_VALUES_DATETIME;} elseif ($data['data_type'] == 'decimal') {$table_name = WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL;} elseif ($data['data_type'] == 'integer') {$table_name = WPSHOP_DBT_ATTRIBUTE_VALUES_INTEGER;} elseif ($data['data_type'] == 'options') {$table_name = WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS;} elseif ($data['data_type'] == 'text') {$table_name = WPSHOP_DBT_ATTRIBUTE_VALUES_TEXT;} elseif ($data['data_type'] == 'varchar') {$table_name = WPSHOP_DBT_ATTRIBUTE_VALUES_VARCHAR;}
613 613
 
614
-                if (isset($table_name)) {
615
-                    // If the value is an id of a select, radio or checkbox
616
-                    if (in_array($data['backend_input'], array('select', 'multiple-select', 'radio', 'checkbox'))) {
614
+				if (isset($table_name)) {
615
+					// If the value is an id of a select, radio or checkbox
616
+					if (in_array($data['backend_input'], array('select', 'multiple-select', 'radio', 'checkbox'))) {
617 617
 
618
-                        $query = $wpdb->prepare("
618
+						$query = $wpdb->prepare("
619 619
 							SELECT " . $table_name . ".entity_id FROM " . $table_name . "
620 620
 							INNER JOIN {$wpdb->posts} AS P ON ( ( P.ID = " . $table_name . ".entity_id ) AND ( P.post_status = 'publish' ) )
621 621
 							LEFT JOIN " . WPSHOP_DBT_ATTRIBUTE . " AS ATT ON ATT.id = " . $table_name . ".attribute_id
622 622
 							LEFT JOIN " . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . " AS ATT_OPT ON " . $table_name . ".value = ATT_OPT.id
623 623
 							WHERE ATT.code=%s AND ( ATT_OPT.value=%s OR ATT_OPT.value=%s )", $attr_name, strtolower(__($attr_value, 'wpshop')), $attr_value
624
-                        );
625
-                        $data = $wpdb->get_results($query);
626
-                    } else {
624
+						);
625
+						$data = $wpdb->get_results($query);
626
+					} else {
627 627
 
628
-                        $query = $wpdb->prepare("
628
+						$query = $wpdb->prepare("
629 629
 							SELECT " . $table_name . ".entity_id FROM " . $table_name . "
630 630
 							INNER JOIN {$wpdb->posts} AS P ON ( ( P.ID = " . $table_name . ".entity_id ) AND ( P.post_status = 'publish' ) )
631 631
 							INNER JOIN " . WPSHOP_DBT_ATTRIBUTE . " AS ATT ON ATT.id = " . $table_name . ".attribute_id
632 632
 								INNER JOIN {$wpdb->posts} AS P ON ( ( P.ID = " . $table_name . ".entity_id ) AND ( P.post_status = 'publish' ) )
633 633
 							WHERE ATT.code=%s AND " . $table_name . ".value=%s", $attr_name, sprintf('%.5f', $attr_value) // force useless zero like 48.58000
634
-                        );
635
-                        $data = $wpdb->get_results($query);
636
-
637
-                    }
638
-                } else {
639
-                    return __('Incorrect shortcode', 'wpshop');
640
-                }
641
-
642
-            } elseif ($data['data_type_to_use'] == 'internal') {
643
-                /** Check the ID of manufacturer **/
644
-                $default_value = unserialize($data['default_value']);
645
-                if (!empty($default_value) && !empty($default_value['default_value'])) {
646
-                    $query = get_post($attr_value);
647
-                    $pid = (!empty($query) && !empty($query->ID)) ? $query->ID : '';
648
-                    if (!empty($pid)) {
649
-                        $query = $wpdb->prepare('SELECT post_id AS entity_id FROM ' . $wpdb->postmeta . ' WHERE post_id = ID AND post_status = %s AND meta_key = %s AND meta_value = %s', 'publish', '_' . $data['code'], $pid);
650
-                        $data = $wpdb->get_results($query);
651
-                    }
652
-                }
653
-            } else {
654
-                return __('Incorrect shortcode', 'wpshop');
655
-            }
656
-
657
-        } else {
658
-            return __('Incorrect shortcode', 'wpshop');
659
-        }
634
+						);
635
+						$data = $wpdb->get_results($query);
660 636
 
661
-        if (!empty($data)) {
662
-            foreach ($data as $p) {
663
-                if (!empty($p) && is_object($p) && !empty($p->entity_id)) {
664
-                    $products[] = $p->entity_id;
665
-                }
666
-            }
667
-        }
668
-        return $products;
669
-    }
637
+					}
638
+				} else {
639
+					return __('Incorrect shortcode', 'wpshop');
640
+				}
670 641
 
671
-    /**
672
-     * Related product shortcode reader
673
-     *
674
-     * @param array $atts {
675
-     *    pid : Product idenfifier to get related element for
676
-     *    display_mode : The output mode if defined (grid || list)
677
-     * }
678
-     *
679
-     * @return string
680
-     *
681
-     */
682
-    public static function wpshop_related_products_func($atts)
683
-    {
684
-        global $wp_query;
642
+			} elseif ($data['data_type_to_use'] == 'internal') {
643
+				/** Check the ID of manufacturer **/
644
+				$default_value = unserialize($data['default_value']);
645
+				if (!empty($default_value) && !empty($default_value['default_value'])) {
646
+					$query = get_post($attr_value);
647
+					$pid = (!empty($query) && !empty($query->ID)) ? $query->ID : '';
648
+					if (!empty($pid)) {
649
+						$query = $wpdb->prepare('SELECT post_id AS entity_id FROM ' . $wpdb->postmeta . ' WHERE post_id = ID AND post_status = %s AND meta_key = %s AND meta_value = %s', 'publish', '_' . $data['code'], $pid);
650
+						$data = $wpdb->get_results($query);
651
+					}
652
+				}
653
+			} else {
654
+				return __('Incorrect shortcode', 'wpshop');
655
+			}
685 656
 
686
-        $atts['product_type'] = 'related';
687
-        if (empty($atts['pid'])) {
688
-            $atts['pid'] = $wp_query->posts[0]->ID;
689
-        }
657
+		} else {
658
+			return __('Incorrect shortcode', 'wpshop');
659
+		}
660
+
661
+		if (!empty($data)) {
662
+			foreach ($data as $p) {
663
+				if (!empty($p) && is_object($p) && !empty($p->entity_id)) {
664
+					$products[] = $p->entity_id;
665
+				}
666
+			}
667
+		}
668
+		return $products;
669
+	}
690 670
 
691
-        $related_product_output = self::wpshop_products_func($atts);
671
+	/**
672
+	 * Related product shortcode reader
673
+	 *
674
+	 * @param array $atts {
675
+	 *    pid : Product idenfifier to get related element for
676
+	 *    display_mode : The output mode if defined (grid || list)
677
+	 * }
678
+	 *
679
+	 * @return string
680
+	 *
681
+	 */
682
+	public static function wpshop_related_products_func($atts)
683
+	{
684
+		global $wp_query;
685
+
686
+		$atts['product_type'] = 'related';
687
+		if (empty($atts['pid'])) {
688
+			$atts['pid'] = $wp_query->posts[0]->ID;
689
+		}
692 690
 
693
-        $output = '';
694
-        if (!empty($related_product_output)) {
695
-            ob_start();
696
-            require wpshop_tools::get_template_part(WPS_PRODUCT_DIR, WPS_PRODUCT_TEMPLATES_MAIN_DIR, 'frontend', 'related_product');
697
-            $output = ob_get_contents();
698
-            ob_end_clean();
699
-        }
691
+		$related_product_output = self::wpshop_products_func($atts);
700 692
 
701
-        return $output;
702
-    }
693
+		$output = '';
694
+		if (!empty($related_product_output)) {
695
+			ob_start();
696
+			require wpshop_tools::get_template_part(WPS_PRODUCT_DIR, WPS_PRODUCT_TEMPLATES_MAIN_DIR, 'frontend', 'related_product');
697
+			$output = ob_get_contents();
698
+			ob_end_clean();
699
+		}
703 700
 
704
-    /**
705
-     * Display a list of product from a shortcode
706
-     *
707
-     * @param array $atts {
708
-     *    limit : The number of element to display
709
-     *    order : The information to order list by
710
-     *    sorting : List order (ASC | DESC)
711
-     *    display : Display size (normal | mini)
712
-     *    type : Display tyep (grid | list) only work with display=normal
713
-     *    pagination : The number of element per page
714
-     * display_pagination : Display the pagination or not
715
-     * }
716
-     *
717
-     * @return string
718
-     *
719
-     **/
720
-    public static function wpshop_products_func($atts)
721
-    {
722
-        global $wpdb, $wp_query;
723
-
724
-        $string = '';
725
-        $have_results = false;
726
-        $output_results = true;
727
-        $type = (empty($atts['type']) or !in_array($atts['type'], array('grid', 'list'))) ? WPSHOP_DISPLAY_LIST_TYPE : $atts['type'];
728
-        $pagination = isset($atts['pagination']) ? intval($atts['pagination']) : WPSHOP_ELEMENT_NB_PER_PAGE;
729
-        $cid = !empty($atts['cid']) ? $atts['cid'] : 0;
730
-        $pid = !empty($atts['pid']) ? $atts['pid'] : 0;
731
-        $order_by_sorting = (!empty($atts['sorting']) && ($atts['sorting'] == 'DESC')) ? 'DESC' : 'ASC';
732
-        $limit = isset($atts['limit']) ? intval($atts['limit']) : 0;
733
-        $grid_element_nb_per_line = !empty($atts['grid_element_nb_per_line']) ? $atts['grid_element_nb_per_line'] : WPSHOP_DISPLAY_GRID_ELEMENT_NUMBER_PER_LINE;
734
-        $display_pagination = (!empty($atts['display_pagination'])) ? (($atts['display_pagination'] === "yes") ? true : false) : true;
735
-        $attr = '';
736
-
737
-        $sorting_criteria = self::get_sorting_criteria();
738
-
739
-        /** Get products which have att_name equal to att_value    */
740
-        if (!empty($atts['att_name']) && !empty($atts['att_value'])) {
741
-            $attr = $atts['att_name'] . ':' . $atts['att_value'];
742
-
743
-            $products = self::get_products_matching_attribute($atts['att_name'], $atts['att_value']);
744
-
745
-            // Foreach on the found products
746
-            if (!empty($products)) {
747
-                $pid = implode(',', $products);
748
-                if (empty($pid)) {
749
-                    $output_results = false;
750
-                }
751
-
752
-            } else {
753
-                $output_results = false;
754
-            }
701
+		return $output;
702
+	}
755 703
 
756
-        }
704
+	/**
705
+	 * Display a list of product from a shortcode
706
+	 *
707
+	 * @param array $atts {
708
+	 *    limit : The number of element to display
709
+	 *    order : The information to order list by
710
+	 *    sorting : List order (ASC | DESC)
711
+	 *    display : Display size (normal | mini)
712
+	 *    type : Display tyep (grid | list) only work with display=normal
713
+	 *    pagination : The number of element per page
714
+	 * display_pagination : Display the pagination or not
715
+	 * }
716
+	 *
717
+	 * @return string
718
+	 *
719
+	 **/
720
+	public static function wpshop_products_func($atts)
721
+	{
722
+		global $wpdb, $wp_query;
723
+
724
+		$string = '';
725
+		$have_results = false;
726
+		$output_results = true;
727
+		$type = (empty($atts['type']) or !in_array($atts['type'], array('grid', 'list'))) ? WPSHOP_DISPLAY_LIST_TYPE : $atts['type'];
728
+		$pagination = isset($atts['pagination']) ? intval($atts['pagination']) : WPSHOP_ELEMENT_NB_PER_PAGE;
729
+		$cid = !empty($atts['cid']) ? $atts['cid'] : 0;
730
+		$pid = !empty($atts['pid']) ? $atts['pid'] : 0;
731
+		$order_by_sorting = (!empty($atts['sorting']) && ($atts['sorting'] == 'DESC')) ? 'DESC' : 'ASC';
732
+		$limit = isset($atts['limit']) ? intval($atts['limit']) : 0;
733
+		$grid_element_nb_per_line = !empty($atts['grid_element_nb_per_line']) ? $atts['grid_element_nb_per_line'] : WPSHOP_DISPLAY_GRID_ELEMENT_NUMBER_PER_LINE;
734
+		$display_pagination = (!empty($atts['display_pagination'])) ? (($atts['display_pagination'] === "yes") ? true : false) : true;
735
+		$attr = '';
736
+
737
+		$sorting_criteria = self::get_sorting_criteria();
738
+
739
+		/** Get products which have att_name equal to att_value    */
740
+		if (!empty($atts['att_name']) && !empty($atts['att_value'])) {
741
+			$attr = $atts['att_name'] . ':' . $atts['att_value'];
742
+
743
+			$products = self::get_products_matching_attribute($atts['att_name'], $atts['att_value']);
744
+
745
+			// Foreach on the found products
746
+			if (!empty($products)) {
747
+				$pid = implode(',', $products);
748
+				if (empty($pid)) {
749
+					$output_results = false;
750
+				}
757 751
 
758
-        /** Get related products    */
759
-        if (!empty($atts['product_type'])) {
760
-            switch ($atts['product_type']) {
761
-                case 'related':
762
-                    $product_id = !empty($atts['pid']) ? (int) $atts['pid'] : get_the_ID();
763
-                    $type = !empty($atts['display_mode']) && in_array($atts['display_mode'], array('list', 'grid')) ? $atts['display_mode'] : WPSHOP_DISPLAY_LIST_TYPE;
764
-                    $grid_element_nb_per_line = !empty($atts['grid_element_nb_per_line']) ? $atts['grid_element_nb_per_line'] : WPSHOP_DISPLAY_GRID_ELEMENT_NUMBER_PER_LINE;
765
-
766
-                    $pids = get_post_meta((int) $product_id, WPSHOP_PRODUCT_RELATED_PRODUCTS, true);
767
-                    if (!empty($pids) && !empty($pids[0])) {
768
-                        $pid = implode(',', $pids);
769
-                    }
770
-                    if (empty($pid) || $pid == $product_id) {
771
-                        $output_results = false;
772
-                    }
773
-
774
-                    break;
775
-            }
776
-        }
752
+			} else {
753
+				$output_results = false;
754
+			}
755
+
756
+		}
777 757
 
778
-        /** Output all the products    */
779
-        if ($output_results) {
780
-            $data = self::wpshop_get_product_by_criteria((!empty($atts['order']) ? $atts['order'] : (!empty($atts['creator']) ? ($atts['creator'] == 'current') : '')), $cid, $pid, $type, $order_by_sorting, 1, $pagination, $limit, $grid_element_nb_per_line, $display_pagination);
758
+		/** Get related products    */
759
+		if (!empty($atts['product_type'])) {
760
+			switch ($atts['product_type']) {
761
+				case 'related':
762
+					$product_id = !empty($atts['pid']) ? (int) $atts['pid'] : get_the_ID();
763
+					$type = !empty($atts['display_mode']) && in_array($atts['display_mode'], array('list', 'grid')) ? $atts['display_mode'] : WPSHOP_DISPLAY_LIST_TYPE;
764
+					$grid_element_nb_per_line = !empty($atts['grid_element_nb_per_line']) ? $atts['grid_element_nb_per_line'] : WPSHOP_DISPLAY_GRID_ELEMENT_NUMBER_PER_LINE;
765
+
766
+					$pids = get_post_meta((int) $product_id, WPSHOP_PRODUCT_RELATED_PRODUCTS, true);
767
+					if (!empty($pids) && !empty($pids[0])) {
768
+						$pid = implode(',', $pids);
769
+					}
770
+					if (empty($pid) || $pid == $product_id) {
771
+						$output_results = false;
772
+					}
781 773
 
782
-            if ($data[0]) {
783
-                $have_results = true;
784
-                $string = $data[1];
785
-            }
786
-        }
774
+					break;
775
+			}
776
+		}
777
+
778
+		/** Output all the products    */
779
+		if ($output_results) {
780
+			$data = self::wpshop_get_product_by_criteria((!empty($atts['order']) ? $atts['order'] : (!empty($atts['creator']) ? ($atts['creator'] == 'current') : '')), $cid, $pid, $type, $order_by_sorting, 1, $pagination, $limit, $grid_element_nb_per_line, $display_pagination);
781
+
782
+			if ($data[0]) {
783
+				$have_results = true;
784
+				$string = $data[1];
785
+			}
786
+		}
787
+
788
+		/** If there are result to display    */
789
+		if ($have_results) {
790
+			$sorting = '';
791
+			if (!empty($pid)) {
792
+				$product_list = explode(',', $pid);
793
+				if (count($product_list) == 1) {
794
+					$atts['sorting'] = 'no';
795
+				}
796
+			}
787 797
 
788
-        /** If there are result to display    */
789
-        if ($have_results) {
790
-            $sorting = '';
791
-            if (!empty($pid)) {
792
-                $product_list = explode(',', $pid);
793
-                if (count($product_list) == 1) {
794
-                    $atts['sorting'] = 'no';
795
-                }
796
-            }
797
-
798
-            /*
798
+			/*
799 799
              * Template parameters
800 800
              */
801
-            $template_part = 'product_listing_sorting';
802
-            $tpl_component = array();
801
+			$template_part = 'product_listing_sorting';
802
+			$tpl_component = array();
803 803
 
804
-            /*
804
+			/*
805 805
              * Build template
806 806
              */
807
-            $tpl_way_to_take = wpshop_display::check_way_for_template($template_part);
808
-            if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) {
809
-                /*    Include the old way template part    */
810
-                ob_start();
811
-                require wpshop_display::get_template_file($tpl_way_to_take[1]);
812
-                $sorting = ob_get_contents();
813
-                ob_end_clean();
814
-            } else {
815
-                /*
807
+			$tpl_way_to_take = wpshop_display::check_way_for_template($template_part);
808
+			if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) {
809
+				/*    Include the old way template part    */
810
+				ob_start();
811
+				require wpshop_display::get_template_file($tpl_way_to_take[1]);
812
+				$sorting = ob_get_contents();
813
+				ob_end_clean();
814
+			} else {
815
+				/*
816 816
                  * Display hidden field every times
817 817
                  */
818
-                $sub_template_part = 'product_listing_sorting_hidden_field';
819
-                $sub_tpl_component = array();
820
-                $sub_tpl_component['DISPLAY_TYPE'] = $type;
821
-                $sub_tpl_component['ORDER'] = $order_by_sorting;
822
-                $sub_tpl_component['PRODUCT_NUMBER'] = $pagination;
823
-                $sub_tpl_component['CURRENT_PAGE'] = 1;
824
-                $sub_tpl_component['CATEGORY_ID'] = $cid;
825
-                $sub_tpl_component['PRODUCT_ID'] = $pid;
826
-                $sub_tpl_component['ATTR'] = $attr;
827
-                $tpl_component['SORTING_HIDDEN_FIELDS'] = wpshop_display::display_template_element($sub_template_part, $sub_tpl_component, array(), 'admin');
828
-                unset($sub_tpl_component);
829
-
830
-                if ((!empty($sorting_criteria) && is_array($sorting_criteria))) {
831
-                    $sub_template_part = 'product_listing_sorting_criteria';
832
-                    $sub_tpl_component = array();
833
-                    $criteria = '';
834
-                    foreach ($sorting_criteria as $c):
835
-                        $criteria .= '<option value="' . $c['code'] . '" ' . selected( $atts['order'], $c['code'], false ) . '>' . __($c['frontend_label'], 'wpshop') . '</option>';
836
-                    endforeach;
837
-                    $sub_tpl_component['SORTING_CRITERIA_LIST'] = $criteria;
838
-                    $tpl_component['SORTING_CRITERIA'] = wpshop_display::display_template_element($sub_template_part, $sub_tpl_component);
839
-                    unset($sub_tpl_component);
840
-                }
841
-
842
-                if (empty($atts['sorting']) || (!empty($atts['sorting']) && ($atts['sorting'] != 'no'))) {
843
-                    $tpl_component['DISPLAY_TYPE_STATE_GRID'] = $type == 'grid' ? ' active' : null;
844
-                    $tpl_component['DISPLAY_TYPE_STATE_LIST'] = $type == 'list' ? ' active' : null;
845
-                    $sorting = wpshop_display::display_template_element($template_part, $tpl_component);
846
-                } else if (!empty($atts['sorting']) && ($atts['sorting'] == 'no')) {
847
-                    $sub_template_part = 'product_listing_sorting_criteria_hidden';
848
-                    $sub_tpl_component = array();
849
-                    $sub_tpl_component['CRITERIA_DEFAULT'] = !empty($sorting_criteria[0]['code']) ? $sorting_criteria[0]['code'] : 'title';
850
-                    $tpl_component['SORTING_CRITERIA'] = wpshop_display::display_template_element($sub_template_part, $sub_tpl_component, array(), 'admin');
851
-                    unset($sub_tpl_component);
852
-
853
-                    $template_part = 'product_listing_sorting_hidden';
854
-                    $sorting = wpshop_display::display_template_element($template_part, $tpl_component, array(), 'admin');
855
-                }
856
-            }
857
-            unset($tpl_component);
858
-
859
-            if (!empty($atts) && !empty($atts['container']) && $atts['container'] == 'no') {
860
-                $string = $sorting . '<div data-nonce="' . wp_create_nonce('products_by_criteria') . '" class="wps-catalog-container wps-bloc-loader">' . $string . '</div>';
861
-            } else {
862
-                $string = '<div class="wpshop_products_block">' . $sorting . '<div data-nonce="' . wp_create_nonce('products_by_criteria') . '" class="wps-catalog-container wps-bloc-loader">' . $string . '</div></div>';
863
-            }
864
-        } else if (empty($atts['no_result_message']) || ($atts['no_result_message'] != 'no')) {
865
-            $string = __('There is nothing to output here', 'wpshop');
866
-        }
818
+				$sub_template_part = 'product_listing_sorting_hidden_field';
819
+				$sub_tpl_component = array();
820
+				$sub_tpl_component['DISPLAY_TYPE'] = $type;
821
+				$sub_tpl_component['ORDER'] = $order_by_sorting;
822
+				$sub_tpl_component['PRODUCT_NUMBER'] = $pagination;
823
+				$sub_tpl_component['CURRENT_PAGE'] = 1;
824
+				$sub_tpl_component['CATEGORY_ID'] = $cid;
825
+				$sub_tpl_component['PRODUCT_ID'] = $pid;
826
+				$sub_tpl_component['ATTR'] = $attr;
827
+				$tpl_component['SORTING_HIDDEN_FIELDS'] = wpshop_display::display_template_element($sub_template_part, $sub_tpl_component, array(), 'admin');
828
+				unset($sub_tpl_component);
829
+
830
+				if ((!empty($sorting_criteria) && is_array($sorting_criteria))) {
831
+					$sub_template_part = 'product_listing_sorting_criteria';
832
+					$sub_tpl_component = array();
833
+					$criteria = '';
834
+					foreach ($sorting_criteria as $c):
835
+						$criteria .= '<option value="' . $c['code'] . '" ' . selected( $atts['order'], $c['code'], false ) . '>' . __($c['frontend_label'], 'wpshop') . '</option>';
836
+					endforeach;
837
+					$sub_tpl_component['SORTING_CRITERIA_LIST'] = $criteria;
838
+					$tpl_component['SORTING_CRITERIA'] = wpshop_display::display_template_element($sub_template_part, $sub_tpl_component);
839
+					unset($sub_tpl_component);
840
+				}
867 841
 
868
-        return do_shortcode($string);
869
-    }
842
+				if (empty($atts['sorting']) || (!empty($atts['sorting']) && ($atts['sorting'] != 'no'))) {
843
+					$tpl_component['DISPLAY_TYPE_STATE_GRID'] = $type == 'grid' ? ' active' : null;
844
+					$tpl_component['DISPLAY_TYPE_STATE_LIST'] = $type == 'list' ? ' active' : null;
845
+					$sorting = wpshop_display::display_template_element($template_part, $tpl_component);
846
+				} else if (!empty($atts['sorting']) && ($atts['sorting'] == 'no')) {
847
+					$sub_template_part = 'product_listing_sorting_criteria_hidden';
848
+					$sub_tpl_component = array();
849
+					$sub_tpl_component['CRITERIA_DEFAULT'] = !empty($sorting_criteria[0]['code']) ? $sorting_criteria[0]['code'] : 'title';
850
+					$tpl_component['SORTING_CRITERIA'] = wpshop_display::display_template_element($sub_template_part, $sub_tpl_component, array(), 'admin');
851
+					unset($sub_tpl_component);
852
+
853
+					$template_part = 'product_listing_sorting_hidden';
854
+					$sorting = wpshop_display::display_template_element($template_part, $tpl_component, array(), 'admin');
855
+				}
856
+			}
857
+			unset($tpl_component);
870 858
 
871
-    public static function wpshop_get_product_by_criteria($criteria = null, $cid = 0, $pid = 0, $display_type, $order = 'ASC', $page_number, $products_per_page = 0, $nb_of_product_limit = 0, $grid_element_nb_per_line = WPSHOP_DISPLAY_GRID_ELEMENT_NUMBER_PER_LINE, $display_pagination = true)
872
-    {
873
-        global $wpdb;
859
+			if (!empty($atts) && !empty($atts['container']) && $atts['container'] == 'no') {
860
+				$string = $sorting . '<div data-nonce="' . wp_create_nonce('products_by_criteria') . '" class="wps-catalog-container wps-bloc-loader">' . $string . '</div>';
861
+			} else {
862
+				$string = '<div class="wpshop_products_block">' . $sorting . '<div data-nonce="' . wp_create_nonce('products_by_criteria') . '" class="wps-catalog-container wps-bloc-loader">' . $string . '</div></div>';
863
+			}
864
+		} else if (empty($atts['no_result_message']) || ($atts['no_result_message'] != 'no')) {
865
+			$string = __('There is nothing to output here', 'wpshop');
866
+		}
874 867
 
875
-        $string = '<span id="wpshop_loading">&nbsp;</span>';
876
-        $have_results = false;
877
-        $display_type = (!empty($display_type) && in_array($display_type, array('grid', 'list'))) ? $display_type : 'grid';
868
+		return do_shortcode($string);
869
+	}
878 870
 
879
-        /** Check if Discount are activated */
880
-        $discount_option = get_option('wpshop_catalog_product_option');
871
+	public static function wpshop_get_product_by_criteria($criteria = null, $cid = 0, $pid = 0, $display_type, $order = 'ASC', $page_number, $products_per_page = 0, $nb_of_product_limit = 0, $grid_element_nb_per_line = WPSHOP_DISPLAY_GRID_ELEMENT_NUMBER_PER_LINE, $display_pagination = true)
872
+	{
873
+		global $wpdb;
881 874
 
882
-        if ($criteria == 'product_price' && !empty($discount_option) && !empty($discount_option['discount']) && $discount_option['discount'] == 'on') {
883
-            $criteria = 'wpshop_displayed_price';
884
-        }
875
+		$string = '<span id="wpshop_loading">&nbsp;</span>';
876
+		$have_results = false;
877
+		$display_type = (!empty($display_type) && in_array($display_type, array('grid', 'list'))) ? $display_type : 'grid';
885 878
 
886
-        $query = array(
887
-            'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT,
888
-            'order' => $order,
889
-            'posts_per_page' => $products_per_page,
890
-            'paged' => $page_number,
891
-            'post_status' => 'publish',
892
-        );
893
-
894
-        // If the limit is greater than zero, hide pagination and change posts_per_page var
895
-        if ($nb_of_product_limit > 0) {
896
-            $query['posts_per_page'] = $nb_of_product_limit;
897
-            unset($query['paged']);
898
-        }
899
-        if (!empty($pid)) {
900
-            if (!is_array($pid)) {
901
-                $pid = explode(',', $pid);
902
-            }
879
+		/** Check if Discount are activated */
880
+		$discount_option = get_option('wpshop_catalog_product_option');
903 881
 
904
-            $query['post__in'] = $pid;
905
-        }
906
-        if (!empty($cid)) {
907
-            $cid = explode(',', $cid);
908
-            $query['tax_query'] = array(array(
909
-                'taxonomy' => WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES,
910
-                'field' => 'id',
911
-                'terms' => $cid,
912
-                'operator' => 'IN',
913
-            ));
914
-        }
915
-        if ($criteria != null) {
916
-            switch ($criteria) {
917
-                case 'creator':
918
-                case 'author':
919
-                    $query['author'] = get_current_user_id();
920
-                    break;
921
-                case 'none':
922
-                case 'ID':
923
-                case 'title':
924
-                case 'date':
925
-                case 'modified':
926
-                case 'relevance':
927
-                case 'post__in':
928
-                case 'rand':
929
-                    $query['orderby'] = $criteria;
930
-                    break;
931
-                default:
932
-                    if (!empty($pid)) {
933
-                        $post_meta = get_post_meta($pid, '_' . $criteria, true);
934
-                    } else {
935
-                        $check_meta = $wpdb->prepare("SELECT COUNT(meta_id) as meta_criteria FROM " . $wpdb->postmeta . " WHERE meta_key = %s", '_' . $criteria);
936
-                        $post_meta = $wpdb->get_var($check_meta);
937
-                    }
938
-                    if (!empty($post_meta)) {
939
-                        if (in_array($criteria, array('wpshop_displayed_price', 'product_price'))) {
940
-                            $query['orderby'] = 'meta_value_num';
941
-                        } else {
942
-                            $query['orderby'] = 'meta_value';
943
-                        }
944
-                        $query['meta_key'] = '_' . $criteria;
945
-                    }
946
-                    break;
947
-            }
948
-        } else {
949
-            $query['orderby'] = 'menu_order ID';
950
-        }
951
-        $post_per_page = $query['posts_per_page'];
952
-        $total_products = (!empty($query['post__in'])) ? $query['post__in'] : 0;
953
-        if (!empty($pid) && !empty($query['post__in']) && count($query['post__in']) > $query['posts_per_page']) {
954
-            $tmp_array = array();
955
-
956
-            if (empty($page_number) || $page_number == 1) {
957
-                for ($i = 0; $i < $query['posts_per_page']; $i++) {
958
-                    $tmp_array[] = $query['post__in'][$i];
959
-                }
960
-            } else {
961
-                $begin_number = (($page_number - 1) * $query['posts_per_page']);
962
-                for ($i = $begin_number; $i < $query['posts_per_page'] + $begin_number; $i++) {
963
-                    if (!empty($query['post__in'][$i])) {
964
-                        $tmp_array[] = $query['post__in'][$i];
965
-                    }
966
-                }
967
-            }
968
-            unset($query['post__in']);
969
-            $query['post__in'] = $tmp_array;
970
-            $query['posts_per_page'] = -1;
971
-        }
882
+		if ($criteria == 'product_price' && !empty($discount_option) && !empty($discount_option['discount']) && $discount_option['discount'] == 'on') {
883
+			$criteria = 'wpshop_displayed_price';
884
+		}
972 885
 
973
-        $query['post_status'] = 'publish';
974
-
975
-        $custom_query = new WP_Query($query);
976
-
977
-        if ($custom_query->have_posts()) {
978
-            $have_results = true;
979
-
980
-            // ---------------- //
981
-            // Products listing //
982
-            // ---------------- //
983
-            $current_position = 1;
984
-            $product_list = '';
985
-            while ($custom_query->have_posts()): $custom_query->the_post();
986
-                $cats = get_the_terms(get_the_ID(), WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES);
987
-                $cats = !empty($cats) && is_array($cats) ? array_values($cats) : array();
988
-                $cat_id = empty($cats) ? 0 : $cats[0]->term_id;
989
-                $product_list .= self::product_mini_output(get_the_ID(), $cat_id, $display_type, $current_position, $grid_element_nb_per_line);
990
-                $current_position++;
991
-            endwhile;
992
-            $tpl_component = array();
993
-            $tpl_component['PRODUCT_CONTAINER_TYPE_CLASS'] = ($display_type == 'grid' ? ' ' . $display_type . '_' . $grid_element_nb_per_line : '') . ' ' . $display_type . '_mode';
994
-            $tpl_component['PRODUCT_LIST_DISPLAY_TYPE'] = $display_type;
995
-            $tpl_component['PRODUCT_LIST_PER_LINE'] = $grid_element_nb_per_line;
996
-            $tpl_component['PRODUCT_LIST'] = $product_list;
997
-            $tpl_component['CROSSED_OUT_PRICE'] = '';
998
-            $tpl_component['LOW_STOCK_ALERT_MESSAGE'] = '';
999
-            $string = wpshop_display::display_template_element('product_list_container', $tpl_component);
1000
-
1001
-            // --------------------- //
1002
-            // Pagination management //
1003
-            // --------------------- //
1004
-            if ( $display_pagination ) {
1005
-                if ($nb_of_product_limit == 0) {
1006
-
1007
-                    $paginate = paginate_links(array(
1008
-                        'base' => '%_%',
1009
-                        'format' => '/?page_product=%#%',
1010
-                        'current' => $page_number,
1011
-                        'total' => $custom_query->max_num_pages,
1012
-                        'type' => 'array',
1013
-                        'prev_next' => false,
1014
-                    ));
1015
-                    if (!empty($paginate)) {
1016
-                        $string .= '<ul class="pagination wps-pagination">';
1017
-                        foreach ($paginate as $p) {
1018
-                            $string .= '<li>' . $p . '</li>';
1019
-                        }
1020
-                        $string .= '</ul>';
1021
-                    }
1022
-                }
1023
-
1024
-                if (!empty($pid) && !empty($query['post__in']) && count($total_products) > $post_per_page) {
1025
-                    $paginate = paginate_links(array(
1026
-                        'base' => '%_%',
1027
-                        'format' => '/?page_product=%#%',
1028
-                        'current' => $page_number,
1029
-                        'total' => ceil(count($total_products) / $post_per_page),
1030
-                        'type' => 'array',
1031
-                        'prev_next' => false,
1032
-                    ));
1033
-                    if (!empty($paginate)) {
1034
-                        $string .= '<ul class="pagination wps-pagination">';
1035
-                        foreach ($paginate as $p) {
1036
-                            $string .= '<li>' . $p . '</li>';
1037
-                        }
1038
-                        $string .= '</ul>';
1039
-                    }
1040
-                }
1041
-            }
886
+		$query = array(
887
+			'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT,
888
+			'order' => $order,
889
+			'posts_per_page' => $products_per_page,
890
+			'paged' => $page_number,
891
+			'post_status' => 'publish',
892
+		);
893
+
894
+		// If the limit is greater than zero, hide pagination and change posts_per_page var
895
+		if ($nb_of_product_limit > 0) {
896
+			$query['posts_per_page'] = $nb_of_product_limit;
897
+			unset($query['paged']);
898
+		}
899
+		if (!empty($pid)) {
900
+			if (!is_array($pid)) {
901
+				$pid = explode(',', $pid);
902
+			}
1042 903
 
1043
-        }
1044
-        wp_reset_query(); // important
904
+			$query['post__in'] = $pid;
905
+		}
906
+		if (!empty($cid)) {
907
+			$cid = explode(',', $cid);
908
+			$query['tax_query'] = array(array(
909
+				'taxonomy' => WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES,
910
+				'field' => 'id',
911
+				'terms' => $cid,
912
+				'operator' => 'IN',
913
+			));
914
+		}
915
+		if ($criteria != null) {
916
+			switch ($criteria) {
917
+				case 'creator':
918
+				case 'author':
919
+					$query['author'] = get_current_user_id();
920
+					break;
921
+				case 'none':
922
+				case 'ID':
923
+				case 'title':
924
+				case 'date':
925
+				case 'modified':
926
+				case 'relevance':
927
+				case 'post__in':
928
+				case 'rand':
929
+					$query['orderby'] = $criteria;
930
+					break;
931
+				default:
932
+					if (!empty($pid)) {
933
+						$post_meta = get_post_meta($pid, '_' . $criteria, true);
934
+					} else {
935
+						$check_meta = $wpdb->prepare("SELECT COUNT(meta_id) as meta_criteria FROM " . $wpdb->postmeta . " WHERE meta_key = %s", '_' . $criteria);
936
+						$post_meta = $wpdb->get_var($check_meta);
937
+					}
938
+					if (!empty($post_meta)) {
939
+						if (in_array($criteria, array('wpshop_displayed_price', 'product_price'))) {
940
+							$query['orderby'] = 'meta_value_num';
941
+						} else {
942
+							$query['orderby'] = 'meta_value';
943
+						}
944
+						$query['meta_key'] = '_' . $criteria;
945
+					}
946
+					break;
947
+			}
948
+		} else {
949
+			$query['orderby'] = 'menu_order ID';
950
+		}
951
+		$post_per_page = $query['posts_per_page'];
952
+		$total_products = (!empty($query['post__in'])) ? $query['post__in'] : 0;
953
+		if (!empty($pid) && !empty($query['post__in']) && count($query['post__in']) > $query['posts_per_page']) {
954
+			$tmp_array = array();
955
+
956
+			if (empty($page_number) || $page_number == 1) {
957
+				for ($i = 0; $i < $query['posts_per_page']; $i++) {
958
+					$tmp_array[] = $query['post__in'][$i];
959
+				}
960
+			} else {
961
+				$begin_number = (($page_number - 1) * $query['posts_per_page']);
962
+				for ($i = $begin_number; $i < $query['posts_per_page'] + $begin_number; $i++) {
963
+					if (!empty($query['post__in'][$i])) {
964
+						$tmp_array[] = $query['post__in'][$i];
965
+					}
966
+				}
967
+			}
968
+			unset($query['post__in']);
969
+			$query['post__in'] = $tmp_array;
970
+			$query['posts_per_page'] = -1;
971
+		}
1045 972
 
1046
-        return array($have_results, $string);
1047
-    }
973
+		$query['post_status'] = 'publish';
974
+
975
+		$custom_query = new WP_Query($query);
976
+
977
+		if ($custom_query->have_posts()) {
978
+			$have_results = true;
979
+
980
+			// ---------------- //
981
+			// Products listing //
982
+			// ---------------- //
983
+			$current_position = 1;
984
+			$product_list = '';
985
+			while ($custom_query->have_posts()): $custom_query->the_post();
986
+				$cats = get_the_terms(get_the_ID(), WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES);
987
+				$cats = !empty($cats) && is_array($cats) ? array_values($cats) : array();
988
+				$cat_id = empty($cats) ? 0 : $cats[0]->term_id;
989
+				$product_list .= self::product_mini_output(get_the_ID(), $cat_id, $display_type, $current_position, $grid_element_nb_per_line);
990
+				$current_position++;
991
+			endwhile;
992
+			$tpl_component = array();
993
+			$tpl_component['PRODUCT_CONTAINER_TYPE_CLASS'] = ($display_type == 'grid' ? ' ' . $display_type . '_' . $grid_element_nb_per_line : '') . ' ' . $display_type . '_mode';
994
+			$tpl_component['PRODUCT_LIST_DISPLAY_TYPE'] = $display_type;
995
+			$tpl_component['PRODUCT_LIST_PER_LINE'] = $grid_element_nb_per_line;
996
+			$tpl_component['PRODUCT_LIST'] = $product_list;
997
+			$tpl_component['CROSSED_OUT_PRICE'] = '';
998
+			$tpl_component['LOW_STOCK_ALERT_MESSAGE'] = '';
999
+			$string = wpshop_display::display_template_element('product_list_container', $tpl_component);
1000
+
1001
+			// --------------------- //
1002
+			// Pagination management //
1003
+			// --------------------- //
1004
+			if ( $display_pagination ) {
1005
+				if ($nb_of_product_limit == 0) {
1006
+
1007
+					$paginate = paginate_links(array(
1008
+						'base' => '%_%',
1009
+						'format' => '/?page_product=%#%',
1010
+						'current' => $page_number,
1011
+						'total' => $custom_query->max_num_pages,
1012
+						'type' => 'array',
1013
+						'prev_next' => false,
1014
+					));
1015
+					if (!empty($paginate)) {
1016
+						$string .= '<ul class="pagination wps-pagination">';
1017
+						foreach ($paginate as $p) {
1018
+							$string .= '<li>' . $p . '</li>';
1019
+						}
1020
+						$string .= '</ul>';
1021
+					}
1022
+				}
1048 1023
 
1049
-    /**
1050
-     * Update quantity for a product
1051
-     * @param integer $product_id The product we want to update quantity for
1052
-     * @param decimal $qty The new quantity
1053
-     */
1054
-    public static function reduce_product_stock_qty($product_id, $qty, $variation_id = '')
1055
-    {
1056
-        global $wpdb;
1057
-
1058
-        $product = self::get_product_data($product_id);
1059
-        /** Check if there is variation ***/
1060
-        if (!empty($variation_id) && $variation_id != $product_id) {
1061
-            $variation_post_type = get_post_type($variation_id);
1062
-            if ($variation_post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) {
1063
-                /** Check if variation def is combined **/
1064
-                $variations = get_post_meta($product_id, '_wpshop_variation_defining', true);
1065
-                if (!empty($variations) && !empty($variations['options']) && !empty($variations['options']['priority']) && in_array('combined', $variations['options']['priority'])) {
1066
-                    /** Get post meta of variation */
1067
-                    $variation_metadata = get_post_meta($variation_id, '_wpshop_product_metadata', true);
1068
-                    if (!empty($variation_metadata) && isset($variation_metadata['product_stock'])) {
1069
-                        $product = self::get_product_data($variation_id);
1070
-                        $product_id = $variation_id;
1071
-                    }
1072
-                }
1073
-            }
1074
-        }
1024
+				if (!empty($pid) && !empty($query['post__in']) && count($total_products) > $post_per_page) {
1025
+					$paginate = paginate_links(array(
1026
+						'base' => '%_%',
1027
+						'format' => '/?page_product=%#%',
1028
+						'current' => $page_number,
1029
+						'total' => ceil(count($total_products) / $post_per_page),
1030
+						'type' => 'array',
1031
+						'prev_next' => false,
1032
+					));
1033
+					if (!empty($paginate)) {
1034
+						$string .= '<ul class="pagination wps-pagination">';
1035
+						foreach ($paginate as $p) {
1036
+							$string .= '<li>' . $p . '</li>';
1037
+						}
1038
+						$string .= '</ul>';
1039
+					}
1040
+				}
1041
+			}
1042
+
1043
+		}
1044
+		wp_reset_query(); // important
1075 1045
 
1076
-        if (!empty($product)) {
1077
-            $newQty = $product['product_stock'] - $qty;
1078
-            $value_id = 0;
1079
-            if ($newQty >= 0) {
1080
-                $query = '
1046
+		return array($have_results, $string);
1047
+	}
1048
+
1049
+	/**
1050
+	 * Update quantity for a product
1051
+	 * @param integer $product_id The product we want to update quantity for
1052
+	 * @param decimal $qty The new quantity
1053
+	 */
1054
+	public static function reduce_product_stock_qty($product_id, $qty, $variation_id = '')
1055
+	{
1056
+		global $wpdb;
1057
+
1058
+		$product = self::get_product_data($product_id);
1059
+		/** Check if there is variation ***/
1060
+		if (!empty($variation_id) && $variation_id != $product_id) {
1061
+			$variation_post_type = get_post_type($variation_id);
1062
+			if ($variation_post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) {
1063
+				/** Check if variation def is combined **/
1064
+				$variations = get_post_meta($product_id, '_wpshop_variation_defining', true);
1065
+				if (!empty($variations) && !empty($variations['options']) && !empty($variations['options']['priority']) && in_array('combined', $variations['options']['priority'])) {
1066
+					/** Get post meta of variation */
1067
+					$variation_metadata = get_post_meta($variation_id, '_wpshop_product_metadata', true);
1068
+					if (!empty($variation_metadata) && isset($variation_metadata['product_stock'])) {
1069
+						$product = self::get_product_data($variation_id);
1070
+						$product_id = $variation_id;
1071
+					}
1072
+				}
1073
+			}
1074
+		}
1075
+
1076
+		if (!empty($product)) {
1077
+			$newQty = $product['product_stock'] - $qty;
1078
+			$value_id = 0;
1079
+			if ($newQty >= 0) {
1080
+				$query = '
1081 1081
 					SELECT wp_wpshop__attribute_value_decimal.value_id
1082 1082
 					FROM wp_wpshop__attribute_value_decimal
1083 1083
 					LEFT JOIN wp_wpshop__attribute ON wp_wpshop__attribute_value_decimal.attribute_id = wp_wpshop__attribute.id
1084 1084
 					WHERE wp_wpshop__attribute_value_decimal.entity_id=' . $product_id . ' AND wp_wpshop__attribute.code="product_stock"
1085 1085
 					LIMIT 1
1086 1086
 				';
1087
-                $value_id = $wpdb->get_var($query);
1088
-                $update = $wpdb->update('wp_wpshop__attribute_value_decimal', array('value' => wpshop_tools::wpshop_clean($newQty)), array('value_id' => $value_id));
1089
-            }
1090
-            // Historic
1091
-            $attribute_histo_content = array();
1092
-            $attribute_histo_content['status'] = 'valid';
1093
-            $attribute_histo_content['creation_date'] = current_time('mysql', 0);
1094
-            $attribute_histo_content['creation_date_value'] = (!empty($attribute_histo[0]->creation_date_value)) ? $attribute_histo[0]->creation_date_value : current_time('mysql', 0);
1095
-            $attribute_histo_content['original_value_id'] = $value_id;
1096
-            $attribute_histo_content['entity_type_id'] = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT);
1097
-            $stock_atribute = wpshop_attributes::getElement('product_stock', "'valid'", 'code');
1098
-            $attribute_histo_content['attribute_id'] = $stock_atribute->id;
1099
-            $attribute_histo_content['entity_id'] = $product_id;
1100
-            $attribute_histo_content['value'] = $product['product_stock'];
1101
-            $attribute_histo_content['value_type'] = 'wp_wpshop__attribute_value_decimal';
1102
-            $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_HISTO, $attribute_histo_content);
1103
-
1104
-            $product_meta = get_post_meta($product_id, '_wpshop_product_metadata', true);
1105
-            $product_meta['product_stock'] = $newQty;
1106
-            update_post_meta($product_id, '_wpshop_product_metadata', $product_meta);
1107
-        }
1108
-    }
1087
+				$value_id = $wpdb->get_var($query);
1088
+				$update = $wpdb->update('wp_wpshop__attribute_value_decimal', array('value' => wpshop_tools::wpshop_clean($newQty)), array('value_id' => $value_id));
1089
+			}
1090
+			// Historic
1091
+			$attribute_histo_content = array();
1092
+			$attribute_histo_content['status'] = 'valid';
1093
+			$attribute_histo_content['creation_date'] = current_time('mysql', 0);
1094
+			$attribute_histo_content['creation_date_value'] = (!empty($attribute_histo[0]->creation_date_value)) ? $attribute_histo[0]->creation_date_value : current_time('mysql', 0);
1095
+			$attribute_histo_content['original_value_id'] = $value_id;
1096
+			$attribute_histo_content['entity_type_id'] = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT);
1097
+			$stock_atribute = wpshop_attributes::getElement('product_stock', "'valid'", 'code');
1098
+			$attribute_histo_content['attribute_id'] = $stock_atribute->id;
1099
+			$attribute_histo_content['entity_id'] = $product_id;
1100
+			$attribute_histo_content['value'] = $product['product_stock'];
1101
+			$attribute_histo_content['value_type'] = 'wp_wpshop__attribute_value_decimal';
1102
+			$wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_HISTO, $attribute_histo_content);
1103
+
1104
+			$product_meta = get_post_meta($product_id, '_wpshop_product_metadata', true);
1105
+			$product_meta['product_stock'] = $newQty;
1106
+			update_post_meta($product_id, '_wpshop_product_metadata', $product_meta);
1107
+		}
1108
+	}
1109 1109
 
1110
-    /**
1111
-     * Retrieve an array with complete information about a given product
1112
-     * @param integer $product_id
1113
-     * @param boolean $for_cart_storage
1114
-     * @return array Information about the product defined by first parameter
1115
-     */
1116
-    public static function get_product_data($product_id, $for_cart_storage = false, $post_status = '"publish"')
1117
-    {
1118
-        global $wpdb;
1119
-        $query = $wpdb->prepare('
1110
+	/**
1111
+	 * Retrieve an array with complete information about a given product
1112
+	 * @param integer $product_id
1113
+	 * @param boolean $for_cart_storage
1114
+	 * @return array Information about the product defined by first parameter
1115
+	 */
1116
+	public static function get_product_data($product_id, $for_cart_storage = false, $post_status = '"publish"')
1117
+	{
1118
+		global $wpdb;
1119
+		$query = $wpdb->prepare('
1120 1120
 			SELECT P.*, PM.meta_value AS attribute_set_id
1121 1121
 			FROM ' . $wpdb->posts . ' AS P
1122 1122
 				INNER JOIN ' . $wpdb->postmeta . ' AS PM ON (PM.post_id=P.ID)
@@ -1128,398 +1128,398 @@  discard block
 block discarded – undo
1128 1128
 			LIMIT 1
1129 1129
 		', $product_id);
1130 1130
 
1131
-        $product = $wpdb->get_row($query);
1132
-
1133
-        $product_data = array();
1134
-        $product_meta = array();
1135
-
1136
-        if (!empty($product)) {
1137
-            $product_data['product_id'] = (!empty($product->ID)) ? $product->ID : '';
1138
-            $product_data['post_name'] = (!empty($product->post_name)) ? $product->post_name : '';
1139
-            $product_data['product_name'] = (!empty($product->post_title)) ? $product->post_title : '';
1140
-            $product_data['post_title'] = (!empty($product->post_title)) ? $product->post_title : '';
1141
-
1142
-            $product_data['product_author_id'] = (!empty($product->post_author)) ? $product->post_author : '';
1143
-            $product_data['product_date'] = (!empty($product->post_date)) ? $product->post_date : '';
1144
-            $product_data['product_content'] = (!empty($product->post_content)) ? $product->post_content : '';
1145
-            $product_data['product_excerpt'] = (!empty($product->post_excerpt)) ? $product->post_excerpt : wp_trim_words($product_data['product_content'], apply_filters('excerpt_length', 50), '...');
1146
-
1147
-            $product_data['product_meta_attribute_set_id'] = (!empty($product->attribute_set_id)) ? $product->attribute_set_id : '';
1148
-
1149
-            $data = wpshop_attributes::get_attribute_list_for_item(wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT), $product->ID, WPSHOP_CURRENT_LOCALE, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT);
1150
-            if (!empty($data)) {
1151
-                foreach ($data as $attribute) {
1152
-                    $data_type = 'attribute_value_' . $attribute->data_type;
1153
-                    $value = $attribute->$data_type;
1154
-                    if (in_array($attribute->backend_input, array('select', 'multiple-select', 'radio', 'checkbox'))) {
1155
-                        $value = wpshop_attributes::get_attribute_type_select_option_info($value, 'value');
1156
-                    }
1157
-
1158
-                    /** Special traitment regarding attribute_code    */
1159
-                    switch ($attribute->attribute_code) {
1160
-                        case 'product_weight':
1161
-                            $default_weight_unity = get_option('wpshop_shop_default_weight_unity');
1162
-                            if (!empty($default_weight_unity)) {
1163
-                                $query = $wpdb->prepare('SELECT unit FROM ' . WPSHOP_DBT_ATTRIBUTE_UNIT . ' WHERE id = %d', $default_weight_unity);
1164
-                                $unity = $wpdb->get_var($query);
1165
-                                if ($unity == 'kg') {
1166
-                                    $value *= 1000;
1167
-                                }
1168
-
1169
-                            }
1170
-                            break;
1171
-                        default:
1172
-                            $value = !empty($value) ? $value : 0;
1173
-                            break;
1174
-                    }
1175
-                    $product_data[$attribute->attribute_code] = $value;
1176
-
1177
-                    if (!$for_cart_storage or $for_cart_storage && $attribute->is_recordable_in_cart_meta == 'yes') {
1178
-                        $meta = get_post_meta($product->ID, 'attribute_option_' . $attribute->attribute_code, true);
1179
-                        if (!empty($meta)) {
1180
-                            $product_meta[$attribute->attribute_code] = $meta;
1181
-                        }
1182
-                    }
1183
-
1184
-                    if (($attribute->is_visible_in_front == 'yes') && (!in_array($attribute->attribute_code, unserialize(WPSHOP_ATTRIBUTE_PRICES)))) {
1185
-                        $product_meta['attribute_visible'][$attribute->attribute_code] = $value;
1186
-                    }
1187
-                    if (($attribute->is_visible_in_front_listing == 'yes') && (!in_array($attribute->attribute_code, unserialize(WPSHOP_ATTRIBUTE_PRICES)))) {
1188
-                        $product_meta['attribute_visible_listing'][$attribute->attribute_code] = $value;
1189
-                    }
1190
-                }
1191
-            } else {
1192
-
1193
-            }
1194
-
1195
-            /**    Get datas about product options    */
1196
-            if ($product->post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) {
1197
-                $variation_details = get_post_meta($product->ID, '_wpshop_variations_attribute_def', true);
1198
-
1199
-                foreach ($variation_details as $attribute_code => $attribute_value) {
1200
-                    $variation_id = $attribute_value;
1201
-                    $attribute_definition = wpshop_attributes::getElement($attribute_code, "'valid'", 'code');
1202
-
1203
-                    $product_meta['variation_definition'][$attribute_code]['UNSTYLED_VALUE'] = stripslashes(wpshop_attributes::get_attribute_type_select_option_info($attribute_value, 'label', $attribute_definition->data_type_to_use, true));
1204
-                    $product_meta['variation_definition'][$attribute_code]['NAME'] = $attribute_definition->frontend_label;
1205
-                    switch ($attribute_definition->backend_input) {
1206
-                        case 'select':
1207
-                        case 'multiple-select':
1208
-                        case 'radio':
1209
-                        case 'checkbox':
1210
-                            $attribute_value = wpshop_attributes::get_attribute_type_select_option_info($attribute_value, 'label', $attribute_definition->data_type_to_use, true);
1211
-                            break;
1212
-                    }
1213
-                    $product_meta['variation_definition'][$attribute_code]['VALUE'] = $attribute_value;
1214
-                    $product_meta['variation_definition'][$attribute_code]['ID'] = $variation_id;
1215
-                }
1216
-            }
1217
-
1218
-            $product_data['item_meta'] = !empty($product_meta) ? $product_meta : array();
1219
-
1220
-            /** Get the display definition for the current product for checking custom display    */
1221
-            $product_data['custom_display'] = get_post_meta($product_id, WPSHOP_PRODUCT_FRONT_DISPLAY_CONF, true);
1222
-        }
1131
+		$product = $wpdb->get_row($query);
1223 1132
 
1224
-        return $product_data;
1225
-    }
1133
+		$product_data = array();
1134
+		$product_meta = array();
1226 1135
 
1227
-    /**
1228
-     * Add a product into the db. This function is used for the EDI
1229
-     * @param $name Name of the product
1230
-     * @param $description Description of the product
1231
-     * @param $attrs List of the attributes and values of the product
1232
-     * @return boolean
1233
-     */
1234
-    public function addProduct($name, $description, $attrs = array())
1235
-    {
1236
-        $new_product = wpshop_entities::create_new_entity(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, $name, $description, $attrs);
1237
-        return $new_product[0];
1238
-    }
1136
+		if (!empty($product)) {
1137
+			$product_data['product_id'] = (!empty($product->ID)) ? $product->ID : '';
1138
+			$product_data['post_name'] = (!empty($product->post_name)) ? $product->post_name : '';
1139
+			$product_data['product_name'] = (!empty($product->post_title)) ? $product->post_title : '';
1140
+			$product_data['post_title'] = (!empty($product->post_title)) ? $product->post_title : '';
1239 1141
 
1240
-    /**
1241
-     * Retrieve a product listing
1242
-     * @param boolean $formated If the output have to be formated or not
1243
-     * @param string $product_search Optionnal Define a search term for request
1244
-     * @return object|string If $formated is set to true will display an html output with all product. Else return a wordpress database object with the product list
1245
-     */
1246
-    public static function product_list($formated = false, $product_search = null)
1247
-    {
1248
-        global $wpdb;
1249
-
1250
-        $query_extra_params = $query_extra_params_value = '';
1251
-        if (!empty($product_search)) {
1252
-            $query_extra_params = " AND post_title LIKE '%%" . $product_search . "%%'";
1253
-            if (is_array($product_search)) {
1254
-                $query_extra_params = " AND ID IN (%s)";
1255
-                $query_extra_params_value = implode(",", $product_search);
1256
-            }
1257
-        }
1142
+			$product_data['product_author_id'] = (!empty($product->post_author)) ? $product->post_author : '';
1143
+			$product_data['product_date'] = (!empty($product->post_date)) ? $product->post_date : '';
1144
+			$product_data['product_content'] = (!empty($product->post_content)) ? $product->post_content : '';
1145
+			$product_data['product_excerpt'] = (!empty($product->post_excerpt)) ? $product->post_excerpt : wp_trim_words($product_data['product_content'], apply_filters('excerpt_length', 50), '...');
1146
+
1147
+			$product_data['product_meta_attribute_set_id'] = (!empty($product->attribute_set_id)) ? $product->attribute_set_id : '';
1148
+
1149
+			$data = wpshop_attributes::get_attribute_list_for_item(wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT), $product->ID, WPSHOP_CURRENT_LOCALE, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT);
1150
+			if (!empty($data)) {
1151
+				foreach ($data as $attribute) {
1152
+					$data_type = 'attribute_value_' . $attribute->data_type;
1153
+					$value = $attribute->$data_type;
1154
+					if (in_array($attribute->backend_input, array('select', 'multiple-select', 'radio', 'checkbox'))) {
1155
+						$value = wpshop_attributes::get_attribute_type_select_option_info($value, 'value');
1156
+					}
1157
+
1158
+					/** Special traitment regarding attribute_code    */
1159
+					switch ($attribute->attribute_code) {
1160
+						case 'product_weight':
1161
+							$default_weight_unity = get_option('wpshop_shop_default_weight_unity');
1162
+							if (!empty($default_weight_unity)) {
1163
+								$query = $wpdb->prepare('SELECT unit FROM ' . WPSHOP_DBT_ATTRIBUTE_UNIT . ' WHERE id = %d', $default_weight_unity);
1164
+								$unity = $wpdb->get_var($query);
1165
+								if ($unity == 'kg') {
1166
+									$value *= 1000;
1167
+								}
1168
+
1169
+							}
1170
+							break;
1171
+						default:
1172
+							$value = !empty($value) ? $value : 0;
1173
+							break;
1174
+					}
1175
+					$product_data[$attribute->attribute_code] = $value;
1176
+
1177
+					if (!$for_cart_storage or $for_cart_storage && $attribute->is_recordable_in_cart_meta == 'yes') {
1178
+						$meta = get_post_meta($product->ID, 'attribute_option_' . $attribute->attribute_code, true);
1179
+						if (!empty($meta)) {
1180
+							$product_meta[$attribute->attribute_code] = $meta;
1181
+						}
1182
+					}
1183
+
1184
+					if (($attribute->is_visible_in_front == 'yes') && (!in_array($attribute->attribute_code, unserialize(WPSHOP_ATTRIBUTE_PRICES)))) {
1185
+						$product_meta['attribute_visible'][$attribute->attribute_code] = $value;
1186
+					}
1187
+					if (($attribute->is_visible_in_front_listing == 'yes') && (!in_array($attribute->attribute_code, unserialize(WPSHOP_ATTRIBUTE_PRICES)))) {
1188
+						$product_meta['attribute_visible_listing'][$attribute->attribute_code] = $value;
1189
+					}
1190
+				}
1191
+			} else {
1192
+
1193
+			}
1194
+
1195
+			/**    Get datas about product options    */
1196
+			if ($product->post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) {
1197
+				$variation_details = get_post_meta($product->ID, '_wpshop_variations_attribute_def', true);
1198
+
1199
+				foreach ($variation_details as $attribute_code => $attribute_value) {
1200
+					$variation_id = $attribute_value;
1201
+					$attribute_definition = wpshop_attributes::getElement($attribute_code, "'valid'", 'code');
1202
+
1203
+					$product_meta['variation_definition'][$attribute_code]['UNSTYLED_VALUE'] = stripslashes(wpshop_attributes::get_attribute_type_select_option_info($attribute_value, 'label', $attribute_definition->data_type_to_use, true));
1204
+					$product_meta['variation_definition'][$attribute_code]['NAME'] = $attribute_definition->frontend_label;
1205
+					switch ($attribute_definition->backend_input) {
1206
+						case 'select':
1207
+						case 'multiple-select':
1208
+						case 'radio':
1209
+						case 'checkbox':
1210
+							$attribute_value = wpshop_attributes::get_attribute_type_select_option_info($attribute_value, 'label', $attribute_definition->data_type_to_use, true);
1211
+							break;
1212
+					}
1213
+					$product_meta['variation_definition'][$attribute_code]['VALUE'] = $attribute_value;
1214
+					$product_meta['variation_definition'][$attribute_code]['ID'] = $variation_id;
1215
+				}
1216
+			}
1217
+
1218
+			$product_data['item_meta'] = !empty($product_meta) ? $product_meta : array();
1219
+
1220
+			/** Get the display definition for the current product for checking custom display    */
1221
+			$product_data['custom_display'] = get_post_meta($product_id, WPSHOP_PRODUCT_FRONT_DISPLAY_CONF, true);
1222
+		}
1223
+
1224
+		return $product_data;
1225
+	}
1226
+
1227
+	/**
1228
+	 * Add a product into the db. This function is used for the EDI
1229
+	 * @param $name Name of the product
1230
+	 * @param $description Description of the product
1231
+	 * @param $attrs List of the attributes and values of the product
1232
+	 * @return boolean
1233
+	 */
1234
+	public function addProduct($name, $description, $attrs = array())
1235
+	{
1236
+		$new_product = wpshop_entities::create_new_entity(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, $name, $description, $attrs);
1237
+		return $new_product[0];
1238
+	}
1239
+
1240
+	/**
1241
+	 * Retrieve a product listing
1242
+	 * @param boolean $formated If the output have to be formated or not
1243
+	 * @param string $product_search Optionnal Define a search term for request
1244
+	 * @return object|string If $formated is set to true will display an html output with all product. Else return a wordpress database object with the product list
1245
+	 */
1246
+	public static function product_list($formated = false, $product_search = null)
1247
+	{
1248
+		global $wpdb;
1249
+
1250
+		$query_extra_params = $query_extra_params_value = '';
1251
+		if (!empty($product_search)) {
1252
+			$query_extra_params = " AND post_title LIKE '%%" . $product_search . "%%'";
1253
+			if (is_array($product_search)) {
1254
+				$query_extra_params = " AND ID IN (%s)";
1255
+				$query_extra_params_value = implode(",", $product_search);
1256
+			}
1257
+		}
1258 1258
 
1259
-        $query = $wpdb->prepare("SELECT ID, post_title FROM " . $wpdb->posts . " WHERE post_type=%s AND post_status=%s" . $query_extra_params, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'publish', $query_extra_params_value);
1260
-        $data = $wpdb->get_results($query);
1259
+		$query = $wpdb->prepare("SELECT ID, post_title FROM " . $wpdb->posts . " WHERE post_type=%s AND post_status=%s" . $query_extra_params, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'publish', $query_extra_params_value);
1260
+		$data = $wpdb->get_results($query);
1261 1261
 
1262
-        /*
1262
+		/*
1263 1263
          * Make some arangement on output if parameter is given
1264 1264
          */
1265
-        if ($formated) {
1266
-            $product_string = '';
1267
-            foreach ($data as $d) {
1268
-                $product_string .= '
1265
+		if ($formated) {
1266
+			$product_string = '';
1267
+			foreach ($data as $d) {
1268
+				$product_string .= '
1269 1269
 					<li class="wpshop_shortcode_element_container wpshop_shortcode_element_container_product" >
1270 1270
 						<input type="checkbox" class="wpshop_shortcode_element wpshop_shortcode_element_product" value="' . $d->ID . '" id="' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '-' . $d->ID . '" name="products[]" /><label for="' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '-' . $d->ID . '" > ' . $d->post_title . '</label>
1271 1271
 					</li>';
1272
-            }
1273
-        }
1272
+			}
1273
+		}
1274 1274
 
1275
-        return $formated ? $product_string : $data;
1276
-    }
1275
+		return $formated ? $product_string : $data;
1276
+	}
1277 1277
 
1278
-    /**
1279
-     * Enregistrement des données pour le produit
1280
-     */
1281
-    public function save_product_custom_informations($post_id, $data_to_save = array())
1282
-    {
1283
-        global $wpdb;
1284
-
1285
-        $data_to_save = (!empty($data_to_save)) ? $data_to_save : (array) $_REQUEST;
1286
-        // Apply a filter to extra actions
1287
-        $data_to_save = apply_filters('wps_save_product_extra_filter', $data_to_save);
1288
-
1289
-        if (!empty($data_to_save['post_ID']) && ((get_post_type($data_to_save['post_ID']) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT) || (get_post_type($data_to_save['post_ID']) == "free_product"))) {
1290
-            if (!empty($data_to_save[wpshop_products::currentPageCode . '_attribute'])) {
1291
-                /*    Fill the product reference automatically if nothing is sent    */
1292
-                if (empty($data_to_save[wpshop_products::currentPageCode . '_attribute']['varchar']['product_reference'])) {
1293
-                    $query = "SELECT MAX(ID) AS PDCT_ID FROM {$wpdb->posts}";
1294
-                    $last_ref = $wpdb->get_var($query);
1295
-                    $data_to_save[wpshop_products::currentPageCode . '_attribute']['varchar']['product_reference'] = WPSHOP_PRODUCT_REFERENCE_PREFIX . str_repeat(0, WPSHOP_PRODUCT_REFERENCE_PREFIX_NB_FILL) . $last_ref;
1296
-                } else {
1297
-                    /* Check if the product reference existing in the database */
1298
-                    $ref = $data_to_save[wpshop_products::currentPageCode . '_attribute']['varchar']['product_reference'];
1299
-                    $query = $wpdb->prepare(
1300
-                        "SELECT value_id
1278
+	/**
1279
+	 * Enregistrement des données pour le produit
1280
+	 */
1281
+	public function save_product_custom_informations($post_id, $data_to_save = array())
1282
+	{
1283
+		global $wpdb;
1284
+
1285
+		$data_to_save = (!empty($data_to_save)) ? $data_to_save : (array) $_REQUEST;
1286
+		// Apply a filter to extra actions
1287
+		$data_to_save = apply_filters('wps_save_product_extra_filter', $data_to_save);
1288
+
1289
+		if (!empty($data_to_save['post_ID']) && ((get_post_type($data_to_save['post_ID']) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT) || (get_post_type($data_to_save['post_ID']) == "free_product"))) {
1290
+			if (!empty($data_to_save[wpshop_products::currentPageCode . '_attribute'])) {
1291
+				/*    Fill the product reference automatically if nothing is sent    */
1292
+				if (empty($data_to_save[wpshop_products::currentPageCode . '_attribute']['varchar']['product_reference'])) {
1293
+					$query = "SELECT MAX(ID) AS PDCT_ID FROM {$wpdb->posts}";
1294
+					$last_ref = $wpdb->get_var($query);
1295
+					$data_to_save[wpshop_products::currentPageCode . '_attribute']['varchar']['product_reference'] = WPSHOP_PRODUCT_REFERENCE_PREFIX . str_repeat(0, WPSHOP_PRODUCT_REFERENCE_PREFIX_NB_FILL) . $last_ref;
1296
+				} else {
1297
+					/* Check if the product reference existing in the database */
1298
+					$ref = $data_to_save[wpshop_products::currentPageCode . '_attribute']['varchar']['product_reference'];
1299
+					$query = $wpdb->prepare(
1300
+						"SELECT value_id
1301 1301
 						FROM " . WPSHOP_DBT_ATTRIBUTE_VALUES_VARCHAR . "
1302 1302
 							INNER JOIN {$wpdb->posts} ON ( ID = entity_id )
1303 1303
 						WHERE value = %s
1304 1304
 							AND entity_id != %d
1305 1305
 							AND entity_type_id = %d"
1306
-                        , $ref, $data_to_save['post_ID'], wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT));
1307
-                    $existing_reference = $wpdb->get_var($query);
1308
-
1309
-                    /* If this product reference exist -> Create a new product reference */
1310
-                    if ($wpdb->num_rows > 0) {
1311
-                        $query = "SELECT MAX(ID) AS PDCT_ID FROM " . $wpdb->posts;
1312
-                        $last_ref = $wpdb->get_var($query);
1313
-                        $data_to_save[wpshop_products::currentPageCode . '_attribute']['varchar']['product_reference'] = WPSHOP_PRODUCT_REFERENCE_PREFIX . str_repeat(0, WPSHOP_PRODUCT_REFERENCE_PREFIX_NB_FILL) . $last_ref;
1314
-                    }
1315
-                }
1316
-
1317
-                /*    Save the attributes values into wpshop eav database    */
1318
-                $update_from = !empty($data_to_save[wpshop_products::currentPageCode . '_provenance']) ? $data_to_save[wpshop_products::currentPageCode . '_provenance'] : '';
1319
-                $lang = WPSHOP_CURRENT_LOCALE;
1320
-                if (!empty($data_to_save['icl_post_language'])) {
1321
-                    $query = $wpdb->prepare("SELECT locale FROM " . $wpdb->prefix . "icl_locale_map WHERE code = %s", $data_to_save['icl_post_language']);
1322
-                    $lang = $wpdb->get_var($query);
1323
-                }
1324
-                wpshop_attributes::saveAttributeForEntity($data_to_save[wpshop_products::currentPageCode . '_attribute'], wpshop_entities::get_entity_identifier_from_code(wpshop_products::currentPageCode), $data_to_save['post_ID'], $lang, $update_from);
1325
-
1326
-                /*    Update product price looking for shop parameters    */
1327
-                wpshop_products::calculate_price($data_to_save['post_ID']);
1328
-
1329
-                /*    Save the attributes values into wordpress post metadata database in order to have a backup and to make frontend search working    */
1330
-                $productMetaDatas = array();
1331
-                foreach ($data_to_save[wpshop_products::currentPageCode . '_attribute'] as $attributeType => $attributeValues) {
1332
-                    foreach ($attributeValues as $attributeCode => $attributeValue) {
1333
-                        if ($attributeCode == 'product_attribute_set_id') {
1334
-                            /*    Update the attribute set id for the current product    */
1335
-                            update_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, $attributeValue);
1336
-                        }
1337
-                        if ($attributeType == 'decimal') {
1338
-                            $attributeValue = str_replace(',', '.', $attributeValue);
1339
-                        }
1340
-                        if (($attributeType == 'integer') && !is_array($attributeValue)) {
1341
-                            $attributeValue = (int) $attributeValue;
1342
-                        }
1343
-                        $productMetaDatas[$attributeCode] = $attributeValue;
1344
-                    }
1345
-                }
1346
-                update_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, $productMetaDatas);
1347
-            }
1348
-
1349
-            if (!empty($data_to_save[wpshop_products::currentPageCode . '_attr_frontend_display']) && empty($data_to_save[wpshop_products::currentPageCode . '_attr_frontend_display']['default_config'])) {
1350
-                update_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_FRONT_DISPLAY_CONF, $data_to_save[wpshop_products::currentPageCode . '_attr_frontend_display']);
1351
-            } else if ($data_to_save['action'] != 'autosave') {
1352
-                delete_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_FRONT_DISPLAY_CONF);
1353
-            }
1354
-
1355
-            $product = wpshop_products::get_product_data($data_to_save['post_ID'], false, '"publish"');
1356
-            if (empty($product['product_id'])) {
1357
-                $product['product_id'] = $data_to_save['post_ID'];
1358
-            }
1359
-            $price = wpshop_prices::get_product_price($product, 'just_price_infos', array('mini_output', 'grid'));
1360
-            update_post_meta($data_to_save['post_ID'], '_wps_price_infos', $price);
1361
-
1362
-            /**    Save product variation    */
1363
-            if (!empty($data_to_save[WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION])) {
1364
-                foreach ($data_to_save[WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION] as $variation_id => $variation_definition) {
1365
-
1366
-                    foreach (unserialize(WPSHOP_ATTRIBUTE_PRICES) as $price_attribute_code) {
1367
-                        $price_attr_def = wpshop_attributes::getElement($price_attribute_code, "'valid'", 'code');
1368
-                        if (!empty($variation_definition) && !empty($variation_definition['attribute']) && is_object($price_attr_def) && !empty($variation_definition['attribute'][$price_attr_def->data_type]) && is_array($variation_definition['attribute'][$price_attr_def->data_type]) && !array_key_exists($price_attribute_code, $variation_definition['attribute'][$price_attr_def->data_type])) {
1369
-                            $variation_definition['attribute'][$price_attr_def->data_type][$price_attribute_code] = !empty($data_to_save[wpshop_products::currentPageCode . '_attribute'][$price_attr_def->data_type][$price_attribute_code]) ? $data_to_save[wpshop_products::currentPageCode . '_attribute'][$price_attr_def->data_type][$price_attribute_code] : 0;
1370
-                        }
1371
-                    }
1372
-                    $lang = WPSHOP_CURRENT_LOCALE;
1373
-                    if (!empty($data_to_save['icl_post_language'])) {
1374
-                        $query = $wpdb->prepare("SELECT locale FROM " . $wpdb->prefix . "icl_locale_map WHERE code = %s", $data_to_save['icl_post_language']);
1375
-                        $lang = $wpdb->get_var($query);
1376
-                    }
1377
-                    wpshop_attributes::saveAttributeForEntity($variation_definition['attribute'], wpshop_entities::get_entity_identifier_from_code(wpshop_products::currentPageCode), $variation_id, $lang);
1378
-
1379
-                    /**    Save the attributes values into wordpress post metadata database in order to have a backup and to make frontend search working    */
1380
-                    $variation_metadata = get_post_meta($variation_id, '_wpshop_product_metadata', true);
1381
-                    if (!empty($variation_metadata)) {
1382
-                        $attributes_list = wpshop_attributes::get_attribute_list_for_item(wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION), $variation_id);
1383
-                        if (!empty($attributes_list)) {
1384
-                            foreach ($attributes_list as $attribute) {
1385
-                                $value_key = 'attribute_value_' . $attribute->data_type;
1386
-                                $attributeValue = $attribute->$value_key;
1387
-                                if ($attribute->data_type == 'decimal') {
1388
-                                    $attributeValue = str_replace(',', '.', $attribute->$value_key);
1389
-                                }
1390
-                                if (($attribute->data_type == 'integer') && !is_array($attributeValue)) {
1391
-                                    $attributeValue = (int) $attribute->$value_key;
1392
-                                }
1393
-                                $variation_metadata[$attribute->code] = $attribute->$value_key;
1394
-                            }
1395
-                        }
1396
-                    }
1397
-
1398
-                    foreach ($variation_definition['attribute'] as $attributeType => $attributeValues) {
1399
-                        foreach ($attributeValues as $attributeCode => $attributeValue) {
1400
-                            if ($attributeType == 'decimal') {
1401
-                                $attributeValue = str_replace(',', '.', $attributeValue);
1402
-                            }
1403
-                            if (($attributeType == 'integer') && !is_array($attributeValue)) {
1404
-                                $attributeValue = (int) $attributeValue;
1405
-                            }
1406
-                            $variation_metadata[$attributeCode] = $attributeValue;
1407
-                        }
1408
-                    }
1409
-                    update_post_meta($variation_id, WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, $variation_metadata);
1410
-
1411
-                    /** Save attached picture id **/
1412
-                    $attached_picture_id = (!empty($data_to_save[WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION][$variation_id]['wps_attached_picture_id'])) ? intval($data_to_save[WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION][$variation_id]['wps_attached_picture_id']) : '';
1413
-                    $selected_picture = update_post_meta($variation_id, '_wps_variation_attached_picture', $attached_picture_id);
1414
-
1415
-                    /*    Update product price looking for shop parameters    */
1416
-                    wpshop_products::calculate_price($variation_id);
1417
-                }
1418
-            }
1419
-
1420
-            /*    Update the related products list*/
1421
-            if (!empty($data_to_save['related_products_list'])) {
1422
-                update_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_RELATED_PRODUCTS, $data_to_save['related_products_list']);
1423
-            } else if ($data_to_save['action'] != 'autosave') {
1424
-                delete_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_RELATED_PRODUCTS);
1425
-            }
1426
-            /*    Update the provider list*/
1427
-            if (!empty($data_to_save['provider_list'])) {
1428
-                update_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_PROVIDER, $data_to_save['provider_list']);
1429
-            } else if ($data_to_save['action'] != 'autosave') {
1430
-                delete_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_PROVIDER);
1431
-            }
1432
-
1433
-            /*    Update product options    */
1434
-            if (!empty($data_to_save[WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT]['options'])) {
1435
-                update_post_meta($data_to_save['post_ID'], '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_options', $data_to_save[WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT]['options']);
1436
-            } else if ($data_to_save['action'] != 'autosave') {
1437
-                delete_post_meta($data_to_save['post_ID'], '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_options');
1438
-            }
1439
-
1440
-            /** Add flag on variations to check which type of variation **/
1441
-            $check_product_have_variations = self::get_variation($post_id);
1442
-            if (!empty($check_product_have_variations)) {
1443
-                $variation_flag = self::check_variation_type($post_id);
1444
-                $variation_defining = get_post_meta($post_id, '_wpshop_variation_defining', true);
1445
-                $variation_defining['variation_type'] = $variation_flag;
1446
-                update_post_meta($post_id, '_wpshop_variation_defining', $variation_defining);
1447
-            }
1448
-            add_post_meta($post_id, '_wpshop_variation_defining', array('follow_general_config' => true, 'options' => array('priority' => array('combined'), 'price_behaviour' => array('replacement'), 'price_display' => (!empty($catalog_product_option) && !empty($catalog_product_option['price_display'])) ? $catalog_product_option['price_display'] : array('text_from' => 'on', 'lower_price' => 'on'))), true);
1449
-        }
1306
+						, $ref, $data_to_save['post_ID'], wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT));
1307
+					$existing_reference = $wpdb->get_var($query);
1308
+
1309
+					/* If this product reference exist -> Create a new product reference */
1310
+					if ($wpdb->num_rows > 0) {
1311
+						$query = "SELECT MAX(ID) AS PDCT_ID FROM " . $wpdb->posts;
1312
+						$last_ref = $wpdb->get_var($query);
1313
+						$data_to_save[wpshop_products::currentPageCode . '_attribute']['varchar']['product_reference'] = WPSHOP_PRODUCT_REFERENCE_PREFIX . str_repeat(0, WPSHOP_PRODUCT_REFERENCE_PREFIX_NB_FILL) . $last_ref;
1314
+					}
1315
+				}
1450 1316
 
1451
-        flush_rewrite_rules();
1452
-    }
1317
+				/*    Save the attributes values into wpshop eav database    */
1318
+				$update_from = !empty($data_to_save[wpshop_products::currentPageCode . '_provenance']) ? $data_to_save[wpshop_products::currentPageCode . '_provenance'] : '';
1319
+				$lang = WPSHOP_CURRENT_LOCALE;
1320
+				if (!empty($data_to_save['icl_post_language'])) {
1321
+					$query = $wpdb->prepare("SELECT locale FROM " . $wpdb->prefix . "icl_locale_map WHERE code = %s", $data_to_save['icl_post_language']);
1322
+					$lang = $wpdb->get_var($query);
1323
+				}
1324
+				wpshop_attributes::saveAttributeForEntity($data_to_save[wpshop_products::currentPageCode . '_attribute'], wpshop_entities::get_entity_identifier_from_code(wpshop_products::currentPageCode), $data_to_save['post_ID'], $lang, $update_from);
1325
+
1326
+				/*    Update product price looking for shop parameters    */
1327
+				wpshop_products::calculate_price($data_to_save['post_ID']);
1328
+
1329
+				/*    Save the attributes values into wordpress post metadata database in order to have a backup and to make frontend search working    */
1330
+				$productMetaDatas = array();
1331
+				foreach ($data_to_save[wpshop_products::currentPageCode . '_attribute'] as $attributeType => $attributeValues) {
1332
+					foreach ($attributeValues as $attributeCode => $attributeValue) {
1333
+						if ($attributeCode == 'product_attribute_set_id') {
1334
+							/*    Update the attribute set id for the current product    */
1335
+							update_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, $attributeValue);
1336
+						}
1337
+						if ($attributeType == 'decimal') {
1338
+							$attributeValue = str_replace(',', '.', $attributeValue);
1339
+						}
1340
+						if (($attributeType == 'integer') && !is_array($attributeValue)) {
1341
+							$attributeValue = (int) $attributeValue;
1342
+						}
1343
+						$productMetaDatas[$attributeCode] = $attributeValue;
1344
+					}
1345
+				}
1346
+				update_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, $productMetaDatas);
1347
+			}
1453 1348
 
1454
-    /**
1455
-     * Return the variation type
1456
-     * @param integer $post_id
1457
-     * @return string
1458
-     */
1459
-    public function check_variation_type($post_id)
1460
-    {
1461
-        $variation_type = 'single';
1462
-        if (!empty($variation_type)) {
1463
-            $variations = self::get_variation($post_id);
1464
-            if (!empty($variations)) {
1465
-                foreach ($variations as $variation_id => $variation_data) {
1466
-                    if (!empty($variation_data) && !empty($variation_data['variation_def']) && count($variation_data['variation_def']) == 1) {
1467
-                        return 'single';
1468
-                    } elseif (!empty($variation_data) && !empty($variation_data['variation_def']) && count($variation_data['variation_def']) > 1) {
1469
-                        $variation_type = 'combined';
1470
-                    }
1471
-                }
1472
-            }
1473
-        }
1474
-        return $variation_type;
1475
-    }
1349
+			if (!empty($data_to_save[wpshop_products::currentPageCode . '_attr_frontend_display']) && empty($data_to_save[wpshop_products::currentPageCode . '_attr_frontend_display']['default_config'])) {
1350
+				update_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_FRONT_DISPLAY_CONF, $data_to_save[wpshop_products::currentPageCode . '_attr_frontend_display']);
1351
+			} else if ($data_to_save['action'] != 'autosave') {
1352
+				delete_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_FRONT_DISPLAY_CONF);
1353
+			}
1476 1354
 
1477
-    /**
1478
-     * Allows to define a specific permalink for each product by checking the parent categories
1479
-     *
1480
-     * @param mixed $permalink The actual permalink of the element
1481
-     * @param object $post The post we want to set the permalink for
1482
-     * @param void
1483
-     *
1484
-     * @return mixed The new permalink for the current element
1485
-     */
1486
-    public static function set_product_permalink($permalink, $post, $unknown)
1487
-    {
1488
-        $options = get_option('wpshop_catalog_product_option', array());
1489
-
1490
-        if ($post->post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT/* && 'publish' == $post->post_status */) {
1491
-            if (!isset($options['wpshop_catalog_product_slug_with_category']) || $options['wpshop_catalog_product_slug_with_category'] != 'yes') {
1492
-                return $permalink;
1493
-            } else {
1494
-                $options_cats = get_option('wpshop_catalog_categories_option', array());
1495
-                $product_categories = wp_get_object_terms($post->ID, WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES);
1496
-                if (empty($product_categories)) {
1497
-                    $product_category_slug = $options_cats['wpshop_catalog_no_category_slug'];
1498
-                } else {
1499
-                    $product_category_slug = $product_categories[0]->slug;
1500
-                }
1501
-                $permalink = str_replace('%' . WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES . '%', $product_category_slug, $permalink);
1502
-            }
1503
-        }
1355
+			$product = wpshop_products::get_product_data($data_to_save['post_ID'], false, '"publish"');
1356
+			if (empty($product['product_id'])) {
1357
+				$product['product_id'] = $data_to_save['post_ID'];
1358
+			}
1359
+			$price = wpshop_prices::get_product_price($product, 'just_price_infos', array('mini_output', 'grid'));
1360
+			update_post_meta($data_to_save['post_ID'], '_wps_price_infos', $price);
1361
+
1362
+			/**    Save product variation    */
1363
+			if (!empty($data_to_save[WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION])) {
1364
+				foreach ($data_to_save[WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION] as $variation_id => $variation_definition) {
1365
+
1366
+					foreach (unserialize(WPSHOP_ATTRIBUTE_PRICES) as $price_attribute_code) {
1367
+						$price_attr_def = wpshop_attributes::getElement($price_attribute_code, "'valid'", 'code');
1368
+						if (!empty($variation_definition) && !empty($variation_definition['attribute']) && is_object($price_attr_def) && !empty($variation_definition['attribute'][$price_attr_def->data_type]) && is_array($variation_definition['attribute'][$price_attr_def->data_type]) && !array_key_exists($price_attribute_code, $variation_definition['attribute'][$price_attr_def->data_type])) {
1369
+							$variation_definition['attribute'][$price_attr_def->data_type][$price_attribute_code] = !empty($data_to_save[wpshop_products::currentPageCode . '_attribute'][$price_attr_def->data_type][$price_attribute_code]) ? $data_to_save[wpshop_products::currentPageCode . '_attribute'][$price_attr_def->data_type][$price_attribute_code] : 0;
1370
+						}
1371
+					}
1372
+					$lang = WPSHOP_CURRENT_LOCALE;
1373
+					if (!empty($data_to_save['icl_post_language'])) {
1374
+						$query = $wpdb->prepare("SELECT locale FROM " . $wpdb->prefix . "icl_locale_map WHERE code = %s", $data_to_save['icl_post_language']);
1375
+						$lang = $wpdb->get_var($query);
1376
+					}
1377
+					wpshop_attributes::saveAttributeForEntity($variation_definition['attribute'], wpshop_entities::get_entity_identifier_from_code(wpshop_products::currentPageCode), $variation_id, $lang);
1378
+
1379
+					/**    Save the attributes values into wordpress post metadata database in order to have a backup and to make frontend search working    */
1380
+					$variation_metadata = get_post_meta($variation_id, '_wpshop_product_metadata', true);
1381
+					if (!empty($variation_metadata)) {
1382
+						$attributes_list = wpshop_attributes::get_attribute_list_for_item(wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION), $variation_id);
1383
+						if (!empty($attributes_list)) {
1384
+							foreach ($attributes_list as $attribute) {
1385
+								$value_key = 'attribute_value_' . $attribute->data_type;
1386
+								$attributeValue = $attribute->$value_key;
1387
+								if ($attribute->data_type == 'decimal') {
1388
+									$attributeValue = str_replace(',', '.', $attribute->$value_key);
1389
+								}
1390
+								if (($attribute->data_type == 'integer') && !is_array($attributeValue)) {
1391
+									$attributeValue = (int) $attribute->$value_key;
1392
+								}
1393
+								$variation_metadata[$attribute->code] = $attribute->$value_key;
1394
+							}
1395
+						}
1396
+					}
1504 1397
 
1505
-        return $permalink;
1398
+					foreach ($variation_definition['attribute'] as $attributeType => $attributeValues) {
1399
+						foreach ($attributeValues as $attributeCode => $attributeValue) {
1400
+							if ($attributeType == 'decimal') {
1401
+								$attributeValue = str_replace(',', '.', $attributeValue);
1402
+							}
1403
+							if (($attributeType == 'integer') && !is_array($attributeValue)) {
1404
+								$attributeValue = (int) $attributeValue;
1405
+							}
1406
+							$variation_metadata[$attributeCode] = $attributeValue;
1407
+						}
1408
+					}
1409
+					update_post_meta($variation_id, WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, $variation_metadata);
1506 1410
 
1507
-        //echo '<pre>'; print_r($permalink); echo '</pre>'; exit();
1411
+					/** Save attached picture id **/
1412
+					$attached_picture_id = (!empty($data_to_save[WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION][$variation_id]['wps_attached_picture_id'])) ? intval($data_to_save[WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION][$variation_id]['wps_attached_picture_id']) : '';
1413
+					$selected_picture = update_post_meta($variation_id, '_wps_variation_attached_picture', $attached_picture_id);
1508 1414
 
1509
-        //wpshop_catalog_categories_slug wpshop_catalog_no_category_slug
1415
+					/*    Update product price looking for shop parameters    */
1416
+					wpshop_products::calculate_price($variation_id);
1417
+				}
1418
+			}
1510 1419
 
1511
-        /*if(false) {
1512
-        global $wp_query;
1513
-        $product_categories = wp_get_object_terms( $post->ID, WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES );
1420
+			/*    Update the related products list*/
1421
+			if (!empty($data_to_save['related_products_list'])) {
1422
+				update_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_RELATED_PRODUCTS, $data_to_save['related_products_list']);
1423
+			} else if ($data_to_save['action'] != 'autosave') {
1424
+				delete_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_RELATED_PRODUCTS);
1425
+			}
1426
+			/*    Update the provider list*/
1427
+			if (!empty($data_to_save['provider_list'])) {
1428
+				update_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_PROVIDER, $data_to_save['provider_list']);
1429
+			} else if ($data_to_save['action'] != 'autosave') {
1430
+				delete_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_PROVIDER);
1431
+			}
1432
+
1433
+			/*    Update product options    */
1434
+			if (!empty($data_to_save[WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT]['options'])) {
1435
+				update_post_meta($data_to_save['post_ID'], '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_options', $data_to_save[WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT]['options']);
1436
+			} else if ($data_to_save['action'] != 'autosave') {
1437
+				delete_post_meta($data_to_save['post_ID'], '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_options');
1438
+			}
1439
+
1440
+			/** Add flag on variations to check which type of variation **/
1441
+			$check_product_have_variations = self::get_variation($post_id);
1442
+			if (!empty($check_product_have_variations)) {
1443
+				$variation_flag = self::check_variation_type($post_id);
1444
+				$variation_defining = get_post_meta($post_id, '_wpshop_variation_defining', true);
1445
+				$variation_defining['variation_type'] = $variation_flag;
1446
+				update_post_meta($post_id, '_wpshop_variation_defining', $variation_defining);
1447
+			}
1448
+			add_post_meta($post_id, '_wpshop_variation_defining', array('follow_general_config' => true, 'options' => array('priority' => array('combined'), 'price_behaviour' => array('replacement'), 'price_display' => (!empty($catalog_product_option) && !empty($catalog_product_option['price_display'])) ? $catalog_product_option['price_display'] : array('text_from' => 'on', 'lower_price' => 'on'))), true);
1449
+		}
1450
+
1451
+		flush_rewrite_rules();
1452
+	}
1453
+
1454
+	/**
1455
+	 * Return the variation type
1456
+	 * @param integer $post_id
1457
+	 * @return string
1458
+	 */
1459
+	public function check_variation_type($post_id)
1460
+	{
1461
+		$variation_type = 'single';
1462
+		if (!empty($variation_type)) {
1463
+			$variations = self::get_variation($post_id);
1464
+			if (!empty($variations)) {
1465
+				foreach ($variations as $variation_id => $variation_data) {
1466
+					if (!empty($variation_data) && !empty($variation_data['variation_def']) && count($variation_data['variation_def']) == 1) {
1467
+						return 'single';
1468
+					} elseif (!empty($variation_data) && !empty($variation_data['variation_def']) && count($variation_data['variation_def']) > 1) {
1469
+						$variation_type = 'combined';
1470
+					}
1471
+				}
1472
+			}
1473
+		}
1474
+		return $variation_type;
1475
+	}
1476
+
1477
+	/**
1478
+	 * Allows to define a specific permalink for each product by checking the parent categories
1479
+	 *
1480
+	 * @param mixed $permalink The actual permalink of the element
1481
+	 * @param object $post The post we want to set the permalink for
1482
+	 * @param void
1483
+	 *
1484
+	 * @return mixed The new permalink for the current element
1485
+	 */
1486
+	public static function set_product_permalink($permalink, $post, $unknown)
1487
+	{
1488
+		$options = get_option('wpshop_catalog_product_option', array());
1489
+
1490
+		if ($post->post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT/* && 'publish' == $post->post_status */) {
1491
+			if (!isset($options['wpshop_catalog_product_slug_with_category']) || $options['wpshop_catalog_product_slug_with_category'] != 'yes') {
1492
+				return $permalink;
1493
+			} else {
1494
+				$options_cats = get_option('wpshop_catalog_categories_option', array());
1495
+				$product_categories = wp_get_object_terms($post->ID, WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES);
1496
+				if (empty($product_categories)) {
1497
+					$product_category_slug = $options_cats['wpshop_catalog_no_category_slug'];
1498
+				} else {
1499
+					$product_category_slug = $product_categories[0]->slug;
1500
+				}
1501
+				$permalink = str_replace('%' . WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES . '%', $product_category_slug, $permalink);
1502
+			}
1503
+		}
1504
+
1505
+		return $permalink;
1506
+
1507
+		//echo '<pre>'; print_r($permalink); echo '</pre>'; exit();
1508
+
1509
+		//wpshop_catalog_categories_slug wpshop_catalog_no_category_slug
1510
+
1511
+		/*if(false) {
1512
+        global $wp_query;
1513
+        $product_categories = wp_get_object_terms( $post->ID, WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES );
1514 1514
 
1515 1515
         if(count($product_categories) == 0){            /*    Product has only one category we get the only available slug    */
1516
-        /*        $product_category_slug = WPSHOP_UNCATEGORIZED_PRODUCT_SLUG;
1516
+		/*        $product_category_slug = WPSHOP_UNCATEGORIZED_PRODUCT_SLUG;
1517 1517
         }
1518 1518
         elseif(count($product_categories) == 1){    /*    Product has only one category we get the only available slug    */
1519
-        /*        $product_category_slug = $product_categories[0]->slug;
1519
+		/*        $product_category_slug = $product_categories[0]->slug;
1520 1520
         }
1521 1521
         else{                                                                            /*    Product has several categories choose the slug of the we want    */
1522
-        /*        $product_category_slugs = array();
1522
+		/*        $product_category_slugs = array();
1523 1523
     foreach($product_categories as $product_category){
1524 1524
     $product_category_slugs[] = $product_category->slug;
1525 1525
     }
@@ -1529,457 +1529,457 @@  discard block
 block discarded – undo
1529 1529
     $permalink = str_replace('%' . WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES . '%', $product_category_slug, $permalink);
1530 1530
     return apply_filters('wpshop_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_permalink', $permalink, $post->ID );
1531 1531
     }*/
1532
-    }
1532
+	}
1533 1533
 
1534
-    public static function set_product_request_by_name($query)
1535
-    {
1536
-        $options = get_option('wpshop_catalog_product_option', array());
1534
+	public static function set_product_request_by_name($query)
1535
+	{
1536
+		$options = get_option('wpshop_catalog_product_option', array());
1537 1537
 
1538
-        if ($query->is_main_query() && (2 == count($query->query) || isset($query->query['page'])) && !empty($query->query['name']) && empty($options['wpshop_catalog_product_slug']));
1539
-        //    $query->set( 'post_type', array( 'post', WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'page' ) );
1540
-    }
1538
+		if ($query->is_main_query() && (2 == count($query->query) || isset($query->query['page'])) && !empty($query->query['name']) && empty($options['wpshop_catalog_product_slug']));
1539
+		//    $query->set( 'post_type', array( 'post', WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'page' ) );
1540
+	}
1541 1541
 
1542
-    /**
1543
-     *    Define output for product
1544
-     *
1545
-     *    @param mixed $initialContent The initial product content defined into wordpress basic admin interface
1546
-     *    @param integer $product_id The product identifier we want to get and output attribute for
1547
-     *
1548
-     *    @return mixed $content The content to add or to modify the product output in frontend
1549
-     */
1550
-    public static function product_complete_sheet_output($initialContent, $product_id)
1551
-    {
1552
-        $content = $attributeContentOutput = '';
1553
-        $wps_product_ctr = new wps_product_ctr();
1554
-        /** Log number of view for the current product    */
1555
-        $product_view_number = get_post_meta($product_id, WPSHOP_PRODUCT_VIEW_NB, true);
1556
-        $product_view_number++;
1557
-        update_post_meta($product_id, WPSHOP_PRODUCT_VIEW_NB, $product_view_number);
1558
-
1559
-        /** Get product definition    */
1560
-
1561
-        $product = self::get_product_data($product_id);
1562
-        wp_cache_set('wpshop_product_data_' . $product_id, $product);
1563
-
1564
-        /** Get the product thumbnail    */
1565
-        $productThumbnail = wpshop_display::display_template_element('product_thumbnail_default', array());
1566
-        if (has_post_thumbnail($product_id)) {
1567
-            $thumbnail_url = wp_get_attachment_image_src(get_post_thumbnail_id(), 'full');
1568
-            $tpl_component = array();
1569
-            $tpl_component['PRODUCT_THUMBNAIL_URL'] = $thumbnail_url[0];
1570
-            $tpl_component['PRODUCT_THUMBNAIL'] = get_the_post_thumbnail($product_id, 'wpshop-product-galery');
1571
-            $tpl_component['PRODUCT_THUMBNAIL_FULL'] = get_the_post_thumbnail($product_id, 'full');
1572
-            $image_attributes = wp_get_attachment_metadata(get_post_thumbnail_id());
1573
-            if (!empty($image_attributes) && !empty($image_attributes['sizes']) && is_array($image_attributes['sizes'])) {
1574
-                foreach ($image_attributes['sizes'] as $size_name => $size_def) {
1575
-                    $tpl_component['PRODUCT_THUMBNAIL_' . strtoupper($size_name)] = wp_get_attachment_image(get_post_thumbnail_id(), $size_name);
1576
-                    $tpl_component['PRODUCT_THUMBNAIL_' . strtoupper($size_name)] = (!empty($tpl_component['PRODUCT_THUMBNAIL_' . strtoupper($size_name)])) ? $tpl_component['PRODUCT_THUMBNAIL_' . strtoupper($size_name)] : WPSHOP_DEFAULT_PRODUCT_PICTURE;
1577
-                }
1578
-            }
1579
-            $tpl_component['PRODUCT_THUMBNAIL_WPSHOP-PRODUCT-GALERY'] = (!empty($tpl_component['PRODUCT_THUMBNAIL_WPSHOP-PRODUCT-GALERY'])) ? $tpl_component['PRODUCT_THUMBNAIL_WPSHOP-PRODUCT-GALERY'] : WPSHOP_DEFAULT_PRODUCT_PICTURE;
1580
-            $productThumbnail = wpshop_display::display_template_element('product_thumbnail', $tpl_component);
1581
-            unset($tpl_component);
1582
-        }
1542
+	/**
1543
+	 *    Define output for product
1544
+	 *
1545
+	 *    @param mixed $initialContent The initial product content defined into wordpress basic admin interface
1546
+	 *    @param integer $product_id The product identifier we want to get and output attribute for
1547
+	 *
1548
+	 *    @return mixed $content The content to add or to modify the product output in frontend
1549
+	 */
1550
+	public static function product_complete_sheet_output($initialContent, $product_id)
1551
+	{
1552
+		$content = $attributeContentOutput = '';
1553
+		$wps_product_ctr = new wps_product_ctr();
1554
+		/** Log number of view for the current product    */
1555
+		$product_view_number = get_post_meta($product_id, WPSHOP_PRODUCT_VIEW_NB, true);
1556
+		$product_view_number++;
1557
+		update_post_meta($product_id, WPSHOP_PRODUCT_VIEW_NB, $product_view_number);
1558
+
1559
+		/** Get product definition    */
1560
+
1561
+		$product = self::get_product_data($product_id);
1562
+		wp_cache_set('wpshop_product_data_' . $product_id, $product);
1563
+
1564
+		/** Get the product thumbnail    */
1565
+		$productThumbnail = wpshop_display::display_template_element('product_thumbnail_default', array());
1566
+		if (has_post_thumbnail($product_id)) {
1567
+			$thumbnail_url = wp_get_attachment_image_src(get_post_thumbnail_id(), 'full');
1568
+			$tpl_component = array();
1569
+			$tpl_component['PRODUCT_THUMBNAIL_URL'] = $thumbnail_url[0];
1570
+			$tpl_component['PRODUCT_THUMBNAIL'] = get_the_post_thumbnail($product_id, 'wpshop-product-galery');
1571
+			$tpl_component['PRODUCT_THUMBNAIL_FULL'] = get_the_post_thumbnail($product_id, 'full');
1572
+			$image_attributes = wp_get_attachment_metadata(get_post_thumbnail_id());
1573
+			if (!empty($image_attributes) && !empty($image_attributes['sizes']) && is_array($image_attributes['sizes'])) {
1574
+				foreach ($image_attributes['sizes'] as $size_name => $size_def) {
1575
+					$tpl_component['PRODUCT_THUMBNAIL_' . strtoupper($size_name)] = wp_get_attachment_image(get_post_thumbnail_id(), $size_name);
1576
+					$tpl_component['PRODUCT_THUMBNAIL_' . strtoupper($size_name)] = (!empty($tpl_component['PRODUCT_THUMBNAIL_' . strtoupper($size_name)])) ? $tpl_component['PRODUCT_THUMBNAIL_' . strtoupper($size_name)] : WPSHOP_DEFAULT_PRODUCT_PICTURE;
1577
+				}
1578
+			}
1579
+			$tpl_component['PRODUCT_THUMBNAIL_WPSHOP-PRODUCT-GALERY'] = (!empty($tpl_component['PRODUCT_THUMBNAIL_WPSHOP-PRODUCT-GALERY'])) ? $tpl_component['PRODUCT_THUMBNAIL_WPSHOP-PRODUCT-GALERY'] : WPSHOP_DEFAULT_PRODUCT_PICTURE;
1580
+			$productThumbnail = wpshop_display::display_template_element('product_thumbnail', $tpl_component);
1581
+			unset($tpl_component);
1582
+		}
1583 1583
 
1584
-        $product_document_galery = wps_media_manager_frontend_ctr::get_product_complete_sheet_attachments($product_id);
1585
-
1586
-        /**    Retrieve product attributes for output    */
1587
-        $attributeContentOutput = wpshop_attributes::attribute_of_entity_to_tab(wpshop_entities::get_entity_identifier_from_code(self::currentPageCode), $product_id, $product);
1588
-
1589
-        /** Retrieve product price */
1590
-        $price_attribute = wpshop_attributes::getElement('product_price', "'valid'", 'code');
1591
-        $price_display = wpshop_attributes::check_attribute_display($price_attribute->is_visible_in_front, $product['custom_display'], 'attribute', 'product_price', 'complete_sheet');
1592
-        $catalog_options = get_option('wpshop_catalog_main_option', array());
1593
-        $productPrice = '';
1594
-        $wpshop_price_piloting_option = get_option('wpshop_shop_price_piloting');
1595
-        $check_product_price = wpshop_prices::check_product_price($product);
1596
-        $result_price_piloting = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $check_product_price['et'] : $check_product_price['ati'];
1597
-        if ($price_display && !(!empty($catalog_options) && (!empty($catalog_options['wpshop_catalog_empty_price_behaviour']) && $catalog_options['wpshop_catalog_empty_price_behaviour'] == 'yes') && $result_price_piloting == 0)) {
1598
-            $productPrice = wpshop_prices::get_product_price($product, 'price_display', 'complete_sheet');
1599
-        }
1584
+		$product_document_galery = wps_media_manager_frontend_ctr::get_product_complete_sheet_attachments($product_id);
1585
+
1586
+		/**    Retrieve product attributes for output    */
1587
+		$attributeContentOutput = wpshop_attributes::attribute_of_entity_to_tab(wpshop_entities::get_entity_identifier_from_code(self::currentPageCode), $product_id, $product);
1588
+
1589
+		/** Retrieve product price */
1590
+		$price_attribute = wpshop_attributes::getElement('product_price', "'valid'", 'code');
1591
+		$price_display = wpshop_attributes::check_attribute_display($price_attribute->is_visible_in_front, $product['custom_display'], 'attribute', 'product_price', 'complete_sheet');
1592
+		$catalog_options = get_option('wpshop_catalog_main_option', array());
1593
+		$productPrice = '';
1594
+		$wpshop_price_piloting_option = get_option('wpshop_shop_price_piloting');
1595
+		$check_product_price = wpshop_prices::check_product_price($product);
1596
+		$result_price_piloting = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $check_product_price['et'] : $check_product_price['ati'];
1597
+		if ($price_display && !(!empty($catalog_options) && (!empty($catalog_options['wpshop_catalog_empty_price_behaviour']) && $catalog_options['wpshop_catalog_empty_price_behaviour'] == 'yes') && $result_price_piloting == 0)) {
1598
+			$productPrice = wpshop_prices::get_product_price($product, 'price_display', 'complete_sheet');
1599
+		}
1600 1600
 
1601
-        /** Check if there is at less 1 product in stock    */
1602
-        $productStock = $wps_product_ctr->check_stock($product_id, 1);
1603
-        $productStock = ($productStock === true) ? 1 : null;
1601
+		/** Check if there is at less 1 product in stock    */
1602
+		$productStock = $wps_product_ctr->check_stock($product_id, 1);
1603
+		$productStock = ($productStock === true) ? 1 : null;
1604 1604
 
1605
-        /** if !product stock check product have variation with stock **/
1605
+		/** if !product stock check product have variation with stock **/
1606 1606
 //         if ( empty($productStock) ) {
1607
-        $product_variation_meta = get_post_meta($product_id, '_wpshop_variation_defining', true);
1608
-        if (!empty($product_variation_meta) && !empty($product_variation_meta['options']) && !empty($product_variation_meta['options']['priority']) && in_array('combined', $product_variation_meta['options']['priority'])) {
1609
-            $variations = wpshop_products::get_variation($product_id);
1610
-            if (!empty($variations)) {
1611
-                foreach ($variations as $variation) {
1612
-                    if (!empty($variation) && !empty($variation['variation_dif']) && array_key_exists('product_stock', $variation['variation_dif']) && round($variation['variation_dif']['product_stock']) > 0) {
1613
-                        $productStock = 1;
1614
-                    }
1615
-                }
1616
-            }
1617
-        }
1607
+		$product_variation_meta = get_post_meta($product_id, '_wpshop_variation_defining', true);
1608
+		if (!empty($product_variation_meta) && !empty($product_variation_meta['options']) && !empty($product_variation_meta['options']['priority']) && in_array('combined', $product_variation_meta['options']['priority'])) {
1609
+			$variations = wpshop_products::get_variation($product_id);
1610
+			if (!empty($variations)) {
1611
+				foreach ($variations as $variation) {
1612
+					if (!empty($variation) && !empty($variation['variation_dif']) && array_key_exists('product_stock', $variation['variation_dif']) && round($variation['variation_dif']['product_stock']) > 0) {
1613
+						$productStock = 1;
1614
+					}
1615
+				}
1616
+			}
1617
+		}
1618 1618
 //         }
1619 1619
 
1620
-        /** Define "Add to cart" button     */
1621
-        $add_to_cart_button_display_state = wpshop_attributes::check_attribute_display(((WPSHOP_DEFINED_SHOP_TYPE == 'sale') ? 'yes' : 'no'), $product['custom_display'], 'product_action_button', 'add_to_cart', 'complete_sheet');
1622
-        $display_price_state_when_price_is_empty = true;
1623
-        if (empty($productPrice) && (!empty($catalog_options) || (!empty($catalog_options['wpshop_catalog_empty_price_behaviour']) && $catalog_options['wpshop_catalog_empty_price_behaviour'] == 'yes'))) {
1624
-            $display_price_state_when_price_is_empty = false;
1625
-        } else if (!empty($productPrice)) {
1626
-            $display_price_state_when_price_is_empty = true;
1627
-        }
1628
-        $add_to_cart_button = (true === $add_to_cart_button_display_state) && (true === $display_price_state_when_price_is_empty) ? self::display_add_to_cart_button($product_id, $productStock, 'complete') : '';
1629
-        $product_quantity_chooser_input = (true === $add_to_cart_button_display_state) ? wpshop_display::display_template_element('product_complete_sheet_quantity_chooser', array('PRODUCT_ID' => $product_id)) : '';
1630
-
1631
-        /** Define "Ask a quotation" button    */
1632
-        $quotation_button = self::display_quotation_button($product_id, (!empty($product['quotation_allowed']) ? $product['quotation_allowed'] : null), 'complete');
1633
-
1634
-        /** Template parameters    */
1635
-        $template_part = 'product_complete_tpl';
1636
-        $tpl_component = array();
1637
-
1638
-        $tpl_component['PRODUCT_VARIATIONS'] = wpshop_products::wpshop_variation($product_id);
1639
-        $tpl_component['PRODUCT_ID'] = $product_id;
1640
-        $tpl_component['PRODUCT_TITLE'] = $product['post_title'];
1641
-        $tpl_component['PRODUCT_THUMBNAIL'] = $productThumbnail;
1642
-        $tpl_component['PRODUCT_GALERY_PICS'] = '';
1643
-        $tpl_component['PRODUCT_PRICE'] = $productPrice;
1644
-        $modules_option = get_option('wpshop_modules');
1645
-        $tpl_component['LOW_STOCK_ALERT_MESSAGE'] = '';
1646
-        if (!empty($modules_option) && !empty($modules_option['wpshop_low_stock_alert']) && $modules_option['wpshop_low_stock_alert']['activated'] == 'on') {
1647
-            $wps_marketing_tools = new wps_marketing_tools_ctr();
1648
-            $tpl_component['LOW_STOCK_ALERT_MESSAGE'] = $wps_marketing_tools->display_alert_stock_message(array('id' => $product_id));
1649
-        }
1620
+		/** Define "Add to cart" button     */
1621
+		$add_to_cart_button_display_state = wpshop_attributes::check_attribute_display(((WPSHOP_DEFINED_SHOP_TYPE == 'sale') ? 'yes' : 'no'), $product['custom_display'], 'product_action_button', 'add_to_cart', 'complete_sheet');
1622
+		$display_price_state_when_price_is_empty = true;
1623
+		if (empty($productPrice) && (!empty($catalog_options) || (!empty($catalog_options['wpshop_catalog_empty_price_behaviour']) && $catalog_options['wpshop_catalog_empty_price_behaviour'] == 'yes'))) {
1624
+			$display_price_state_when_price_is_empty = false;
1625
+		} else if (!empty($productPrice)) {
1626
+			$display_price_state_when_price_is_empty = true;
1627
+		}
1628
+		$add_to_cart_button = (true === $add_to_cart_button_display_state) && (true === $display_price_state_when_price_is_empty) ? self::display_add_to_cart_button($product_id, $productStock, 'complete') : '';
1629
+		$product_quantity_chooser_input = (true === $add_to_cart_button_display_state) ? wpshop_display::display_template_element('product_complete_sheet_quantity_chooser', array('PRODUCT_ID' => $product_id)) : '';
1630
+
1631
+		/** Define "Ask a quotation" button    */
1632
+		$quotation_button = self::display_quotation_button($product_id, (!empty($product['quotation_allowed']) ? $product['quotation_allowed'] : null), 'complete');
1633
+
1634
+		/** Template parameters    */
1635
+		$template_part = 'product_complete_tpl';
1636
+		$tpl_component = array();
1637
+
1638
+		$tpl_component['PRODUCT_VARIATIONS'] = wpshop_products::wpshop_variation($product_id);
1639
+		$tpl_component['PRODUCT_ID'] = $product_id;
1640
+		$tpl_component['PRODUCT_TITLE'] = $product['post_title'];
1641
+		$tpl_component['PRODUCT_THUMBNAIL'] = $productThumbnail;
1642
+		$tpl_component['PRODUCT_GALERY_PICS'] = '';
1643
+		$tpl_component['PRODUCT_PRICE'] = $productPrice;
1644
+		$modules_option = get_option('wpshop_modules');
1645
+		$tpl_component['LOW_STOCK_ALERT_MESSAGE'] = '';
1646
+		if (!empty($modules_option) && !empty($modules_option['wpshop_low_stock_alert']) && $modules_option['wpshop_low_stock_alert']['activated'] == 'on') {
1647
+			$wps_marketing_tools = new wps_marketing_tools_ctr();
1648
+			$tpl_component['LOW_STOCK_ALERT_MESSAGE'] = $wps_marketing_tools->display_alert_stock_message(array('id' => $product_id));
1649
+		}
1650 1650
 
1651
-        /** Gallery **/
1652
-        $tpl_component['PRODUCT_COMPLETE_SHEET_GALLERY'] = wps_media_manager_frontend_ctr::get_product_complete_sheet_galery($product_id);
1653
-
1654
-        $product_new_def = self::display_product_special_state('declare_new', 'complete', (!empty($product['declare_new']) ? $product['declare_new'] : 'no'), (!empty($product['set_new_from']) ? $product['set_new_from'] : ''), (!empty($product['set_new_to']) ? $product['set_new_to'] : ''));
1655
-
1656
-        $product_new = $product_new_def['output'];
1657
-        $product_class = $product_new_def['class'];
1658
-
1659
-        $product_featured_def = self::display_product_special_state('highlight_product', 'complete', (!empty($product['highlight_product']) ? $product['highlight_product'] : 'no'), (!empty($product['highlight_from']) ? $product['highlight_from'] : ''), (!empty($product['highlight_to']) ? $product['highlight_to'] : ''));
1660
-        $product_featured = $product_featured_def['output'];
1661
-        $product_class .= $product_featured_def['class'];
1662
-
1663
-        $tpl_component['PRODUCT_IS_NEW'] = $product_new;
1664
-        $tpl_component['PRODUCT_IS_FEATURED'] = $product_featured;
1665
-        $tpl_component['PRODUCT_EXTRA_STATE'] = $tpl_component['PRODUCT_IS_NEW'] . $tpl_component['PRODUCT_IS_FEATURED'];
1666
-
1667
-        $tpl_component['PRODUCT_INITIAL_CONTENT'] = $initialContent;
1668
-        $tpl_component['PRODUCT_BUTTON_ADD_TO_CART'] = $add_to_cart_button;
1669
-        $tpl_component['PRODUCT_BUTTON_QUOTATION'] = $quotation_button;
1670
-        $tpl_component['PRODUCT_QUANTITY_CHOOSER'] = $product_quantity_chooser_input;
1671
-        $tpl_component['PRODUCT_BUTTONS'] = $tpl_component['PRODUCT_BUTTON_QUOTATION'] . $tpl_component['PRODUCT_BUTTON_ADD_TO_CART'];
1672
-        $tpl_component['PRODUCT_GALERY_DOCS'] = $product_document_galery;
1673
-        $tpl_component['PRODUCT_FEATURES'] = $attributeContentOutput;
1674
-        $tpl_component = apply_filters('wps-filter-product-complete-sheet-output', $tpl_component, $product_id);
1675
-
1676
-        /** Build template    */
1677
-        $tpl_way_to_take = wpshop_display::check_way_for_template($template_part);
1678
-        if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) {
1679
-            /*    Include the old way template part    */
1680
-            ob_start();
1681
-            require wpshop_display::get_template_file($tpl_way_to_take[1]);
1682
-            $content = ob_get_contents();
1683
-            ob_end_clean();
1684
-        } else {
1685
-            $content = wpshop_display::display_template_element($template_part, $tpl_component);
1686
-        }
1687
-        unset($tpl_component);
1688
-        return $content;
1689
-    }
1651
+		/** Gallery **/
1652
+		$tpl_component['PRODUCT_COMPLETE_SHEET_GALLERY'] = wps_media_manager_frontend_ctr::get_product_complete_sheet_galery($product_id);
1653
+
1654
+		$product_new_def = self::display_product_special_state('declare_new', 'complete', (!empty($product['declare_new']) ? $product['declare_new'] : 'no'), (!empty($product['set_new_from']) ? $product['set_new_from'] : ''), (!empty($product['set_new_to']) ? $product['set_new_to'] : ''));
1655
+
1656
+		$product_new = $product_new_def['output'];
1657
+		$product_class = $product_new_def['class'];
1658
+
1659
+		$product_featured_def = self::display_product_special_state('highlight_product', 'complete', (!empty($product['highlight_product']) ? $product['highlight_product'] : 'no'), (!empty($product['highlight_from']) ? $product['highlight_from'] : ''), (!empty($product['highlight_to']) ? $product['highlight_to'] : ''));
1660
+		$product_featured = $product_featured_def['output'];
1661
+		$product_class .= $product_featured_def['class'];
1662
+
1663
+		$tpl_component['PRODUCT_IS_NEW'] = $product_new;
1664
+		$tpl_component['PRODUCT_IS_FEATURED'] = $product_featured;
1665
+		$tpl_component['PRODUCT_EXTRA_STATE'] = $tpl_component['PRODUCT_IS_NEW'] . $tpl_component['PRODUCT_IS_FEATURED'];
1666
+
1667
+		$tpl_component['PRODUCT_INITIAL_CONTENT'] = $initialContent;
1668
+		$tpl_component['PRODUCT_BUTTON_ADD_TO_CART'] = $add_to_cart_button;
1669
+		$tpl_component['PRODUCT_BUTTON_QUOTATION'] = $quotation_button;
1670
+		$tpl_component['PRODUCT_QUANTITY_CHOOSER'] = $product_quantity_chooser_input;
1671
+		$tpl_component['PRODUCT_BUTTONS'] = $tpl_component['PRODUCT_BUTTON_QUOTATION'] . $tpl_component['PRODUCT_BUTTON_ADD_TO_CART'];
1672
+		$tpl_component['PRODUCT_GALERY_DOCS'] = $product_document_galery;
1673
+		$tpl_component['PRODUCT_FEATURES'] = $attributeContentOutput;
1674
+		$tpl_component = apply_filters('wps-filter-product-complete-sheet-output', $tpl_component, $product_id);
1675
+
1676
+		/** Build template    */
1677
+		$tpl_way_to_take = wpshop_display::check_way_for_template($template_part);
1678
+		if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) {
1679
+			/*    Include the old way template part    */
1680
+			ob_start();
1681
+			require wpshop_display::get_template_file($tpl_way_to_take[1]);
1682
+			$content = ob_get_contents();
1683
+			ob_end_clean();
1684
+		} else {
1685
+			$content = wpshop_display::display_template_element($template_part, $tpl_component);
1686
+		}
1687
+		unset($tpl_component);
1688
+		return $content;
1689
+	}
1690 1690
 
1691
-    public static function product_mini_output($product_id, $category_id, $output_type = 'list', $current_item_position = 1, $grid_element_nb_per_line = WPSHOP_DISPLAY_GRID_ELEMENT_NUMBER_PER_LINE)
1692
-    {
1693
-        $content = '';
1694
-        $product_information = $product_class = '';
1691
+	public static function product_mini_output($product_id, $category_id, $output_type = 'list', $current_item_position = 1, $grid_element_nb_per_line = WPSHOP_DISPLAY_GRID_ELEMENT_NUMBER_PER_LINE)
1692
+	{
1693
+		$content = '';
1694
+		$product_information = $product_class = '';
1695 1695
 
1696
-        /** Get the product thumbnail    */
1697
-        $productThumbnail = wpshop_display::display_template_element('product_thumbnail_default', array());
1698
-        if (has_post_thumbnail($product_id)) {
1699
-            $productThumbnail = get_the_post_thumbnail($product_id, 'thumbnail');
1700
-        }
1696
+		/** Get the product thumbnail    */
1697
+		$productThumbnail = wpshop_display::display_template_element('product_thumbnail_default', array());
1698
+		if (has_post_thumbnail($product_id)) {
1699
+			$productThumbnail = get_the_post_thumbnail($product_id, 'thumbnail');
1700
+		}
1701 1701
 
1702
-        $product = self::get_product_data($product_id);
1702
+		$product = self::get_product_data($product_id);
1703 1703
 
1704
-        /**    Get the product information for output    */
1705
-        if (!empty($product)) {
1704
+		/**    Get the product information for output    */
1705
+		if (!empty($product)) {
1706 1706
 
1707
-            $product_title = $product['post_title'];
1708
-            $product_name = $product['post_name'];
1709
-            $product_link = get_permalink($product_id);
1710
-            $product_more_informations = $product['product_content'];
1711
-            $product_excerpt = $product['product_excerpt'];
1707
+			$product_title = $product['post_title'];
1708
+			$product_name = $product['post_name'];
1709
+			$product_link = get_permalink($product_id);
1710
+			$product_more_informations = $product['product_content'];
1711
+			$product_excerpt = $product['product_excerpt'];
1712 1712
 
1713
-            if (strpos($product['product_content'], '<!--more-->')) {
1714
-                $post_content = explode('<!--more-->', $product['product_content']);
1715
-                $product_more_informations = $post_content[0];
1716
-            }
1713
+			if (strpos($product['product_content'], '<!--more-->')) {
1714
+				$post_content = explode('<!--more-->', $product['product_content']);
1715
+				$product_more_informations = $post_content[0];
1716
+			}
1717 1717
 
1718
-        } else {
1719
-            $productThumbnail = wpshop_display::display_template_element('product_thumbnail_default', array());
1720
-            $product_title = '<i>' . __('This product does not exist', 'wpshop') . '</i>';
1721
-            $product_link = '';
1722
-            $product_more_informations = '';
1723
-            $product_excerpt = '';
1724
-        }
1718
+		} else {
1719
+			$productThumbnail = wpshop_display::display_template_element('product_thumbnail_default', array());
1720
+			$product_title = '<i>' . __('This product does not exist', 'wpshop') . '</i>';
1721
+			$product_link = '';
1722
+			$product_more_informations = '';
1723
+			$product_excerpt = '';
1724
+		}
1725 1725
 
1726
-        /** Retrieve product price    */
1727
-        $price_attribute = wpshop_attributes::getElement('product_price', "'valid'", 'code');
1728
-        $price_display = wpshop_attributes::check_attribute_display($price_attribute->is_visible_in_front_listing, $product['custom_display'], 'attribute', 'product_price', 'mini_output');
1729
-        $catalog_options = get_option('wpshop_catalog_main_option', array());
1730
-        $productPrice = '';
1731
-        $wpshop_price_piloting_option = get_option('wpshop_shop_price_piloting');
1732
-        $check_product_price = wpshop_prices::check_product_price($product);
1733
-        $result_price_piloting = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $check_product_price['et'] : $check_product_price['ati'];
1734
-        if ($price_display && !(!empty($catalog_options) && (!empty($catalog_options['wpshop_catalog_empty_price_behaviour']) && $catalog_options['wpshop_catalog_empty_price_behaviour'] == 'yes') && $result_price_piloting == 0)) {
1735
-            $product_price_infos = wpshop_prices::get_product_price($product, 'just_price_infos', 'mini_output');
1736
-
1737
-            if (!empty($product_price_infos)) {
1738
-                $tpl_component_price = array();
1739
-                /** Price piloting **/
1726
+		/** Retrieve product price    */
1727
+		$price_attribute = wpshop_attributes::getElement('product_price', "'valid'", 'code');
1728
+		$price_display = wpshop_attributes::check_attribute_display($price_attribute->is_visible_in_front_listing, $product['custom_display'], 'attribute', 'product_price', 'mini_output');
1729
+		$catalog_options = get_option('wpshop_catalog_main_option', array());
1730
+		$productPrice = '';
1731
+		$wpshop_price_piloting_option = get_option('wpshop_shop_price_piloting');
1732
+		$check_product_price = wpshop_prices::check_product_price($product);
1733
+		$result_price_piloting = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $check_product_price['et'] : $check_product_price['ati'];
1734
+		if ($price_display && !(!empty($catalog_options) && (!empty($catalog_options['wpshop_catalog_empty_price_behaviour']) && $catalog_options['wpshop_catalog_empty_price_behaviour'] == 'yes') && $result_price_piloting == 0)) {
1735
+			$product_price_infos = wpshop_prices::get_product_price($product, 'just_price_infos', 'mini_output');
1736
+
1737
+			if (!empty($product_price_infos)) {
1738
+				$tpl_component_price = array();
1739
+				/** Price piloting **/
1740 1740
 				$price_display_option = get_option( 'wpshop_catalog_product_option' );
1741 1741
 				$tpl_component['PRICE_FROM'] = (!empty($price_display_option) && !empty($price_display_option['price_display']) && !empty($price_display_option['price_display']['text_from']) ) ? 'on' : '';
1742
-                $price_ploting = get_option('wpshop_shop_price_piloting');
1743
-                $tpl_component_price['CROSSED_OUT_PRICE'] = (!empty($product_price_infos['CROSSED_OUT_PRICE'])) ? ((!empty($product_price_infos['PRICE_FROM'])) ? __('Price from', 'wpshop') . ' ' : '') . wpshop_display::display_template_element('product_price_template_crossed_out_price', array('CROSSED_OUT_PRICE_VALUE' => $product_price_infos['CROSSED_OUT_PRICE'])) : '';
1744
-                $variations = wpshop_products::get_variation($product_id);
1742
+				$price_ploting = get_option('wpshop_shop_price_piloting');
1743
+				$tpl_component_price['CROSSED_OUT_PRICE'] = (!empty($product_price_infos['CROSSED_OUT_PRICE'])) ? ((!empty($product_price_infos['PRICE_FROM'])) ? __('Price from', 'wpshop') . ' ' : '') . wpshop_display::display_template_element('product_price_template_crossed_out_price', array('CROSSED_OUT_PRICE_VALUE' => $product_price_infos['CROSSED_OUT_PRICE'])) : '';
1744
+				$variations = wpshop_products::get_variation($product_id);
1745 1745
 				$tpl_component_price['PRODUCT_PRICE'] = $product_price_infos['PRODUCT_PRICE'];
1746 1746
 				if(empty($product_price_infos['CROSSED_OUT_PRICE']) && (!empty($variations) && (!empty($product_price_infos['PRICE_FROM']) || !empty( $tpl_component['PRICE_FROM'] ) ))) {
1747 1747
 					$tpl_component_price['PRODUCT_PRICE'] = __('Price from', 'wpshop') . ' ' . $tpl_component_price['PRODUCT_PRICE'];
1748 1748
 				}
1749
-                $tpl_component_price['MESSAGE_SAVE_MONEY'] = $product_price_infos['MESSAGE_SAVE_MONEY'];
1750
-                $tpl_component_price['TAX_PILOTING'] = (!empty($price_ploting) && $price_ploting == 'HT') ? __('ET', 'wpshop') : '';
1751
-                $product_price_infos['MESSAGE_SAVE_MONEY'];
1752
-                $productPrice = wpshop_display::display_template_element('product_price_template_mini_output', $tpl_component_price);
1753
-            } else {
1754
-                $productPrice = wpshop_prices::get_product_price($product, 'price_display', array('mini_output', $output_type));
1755
-            }
1756
-        }
1749
+				$tpl_component_price['MESSAGE_SAVE_MONEY'] = $product_price_infos['MESSAGE_SAVE_MONEY'];
1750
+				$tpl_component_price['TAX_PILOTING'] = (!empty($price_ploting) && $price_ploting == 'HT') ? __('ET', 'wpshop') : '';
1751
+				$product_price_infos['MESSAGE_SAVE_MONEY'];
1752
+				$productPrice = wpshop_display::display_template_element('product_price_template_mini_output', $tpl_component_price);
1753
+			} else {
1754
+				$productPrice = wpshop_prices::get_product_price($product, 'price_display', array('mini_output', $output_type));
1755
+			}
1756
+		}
1757 1757
 
1758
-        /** Check if there is at less 1 product in stock    */
1759
-        $wps_product_ctr = new wps_product_ctr();
1760
-        $productStock = $wps_product_ctr->check_stock($product_id, 1);
1761
-        $productStock = $productStock === true ? 1 : null;
1762
-
1763
-        /** Define "Add to cart" button    */
1764
-        $add_to_cart_button_display_state = wpshop_attributes::check_attribute_display(((WPSHOP_DEFINED_SHOP_TYPE == 'sale') ? 'yes' : 'no'), $product['custom_display'], 'product_action_button', 'add_to_cart', 'mini_output');
1765
-        $display_price_state_when_price_is_empty = false;
1766
-        if (empty($productPrice) && (!empty($catalog_options) || (!empty($catalog_options['wpshop_catalog_empty_price_behaviour']) && $catalog_options['wpshop_catalog_empty_price_behaviour'] == 'yes'))) {
1767
-            $display_price_state_when_price_is_empty = false;
1768
-        } else if (!empty($productPrice)) {
1769
-            $display_price_state_when_price_is_empty = true;
1770
-        }
1771
-        $add_to_cart_button = (true === $add_to_cart_button_display_state) && (true === $display_price_state_when_price_is_empty) ? self::display_add_to_cart_button($product_id, $productStock, 'mini') : '';
1772
-        $product_quantity_chooser_input = (true === $add_to_cart_button_display_state) ? wpshop_display::display_template_element('product_complete_sheet_quantity_chooser', array('PRODUCT_ID' => $product_id)) : '';
1758
+		/** Check if there is at less 1 product in stock    */
1759
+		$wps_product_ctr = new wps_product_ctr();
1760
+		$productStock = $wps_product_ctr->check_stock($product_id, 1);
1761
+		$productStock = $productStock === true ? 1 : null;
1762
+
1763
+		/** Define "Add to cart" button    */
1764
+		$add_to_cart_button_display_state = wpshop_attributes::check_attribute_display(((WPSHOP_DEFINED_SHOP_TYPE == 'sale') ? 'yes' : 'no'), $product['custom_display'], 'product_action_button', 'add_to_cart', 'mini_output');
1765
+		$display_price_state_when_price_is_empty = false;
1766
+		if (empty($productPrice) && (!empty($catalog_options) || (!empty($catalog_options['wpshop_catalog_empty_price_behaviour']) && $catalog_options['wpshop_catalog_empty_price_behaviour'] == 'yes'))) {
1767
+			$display_price_state_when_price_is_empty = false;
1768
+		} else if (!empty($productPrice)) {
1769
+			$display_price_state_when_price_is_empty = true;
1770
+		}
1771
+		$add_to_cart_button = (true === $add_to_cart_button_display_state) && (true === $display_price_state_when_price_is_empty) ? self::display_add_to_cart_button($product_id, $productStock, 'mini') : '';
1772
+		$product_quantity_chooser_input = (true === $add_to_cart_button_display_state) ? wpshop_display::display_template_element('product_complete_sheet_quantity_chooser', array('PRODUCT_ID' => $product_id)) : '';
1773 1773
 
1774
-        /** Define "Ask a quotation" button    */
1775
-        $quotation_button = self::display_quotation_button($product_id, (!empty($product['quotation_allowed']) ? $product['quotation_allowed'] : null));
1776
-        $product_new_def = self::display_product_special_state('declare_new', $output_type, (!empty($product['declare_new']) ? $product['declare_new'] : 'no'), (!empty($product['set_new_from']) ? $product['set_new_from'] : ''), (!empty($product['set_new_to']) ? $product['set_new_to'] : ''));
1774
+		/** Define "Ask a quotation" button    */
1775
+		$quotation_button = self::display_quotation_button($product_id, (!empty($product['quotation_allowed']) ? $product['quotation_allowed'] : null));
1776
+		$product_new_def = self::display_product_special_state('declare_new', $output_type, (!empty($product['declare_new']) ? $product['declare_new'] : 'no'), (!empty($product['set_new_from']) ? $product['set_new_from'] : ''), (!empty($product['set_new_to']) ? $product['set_new_to'] : ''));
1777 1777
 
1778
-        $product_new = $product_new_def['output'];
1779
-        $product_class .= $product_new_def['class'];
1778
+		$product_new = $product_new_def['output'];
1779
+		$product_class .= $product_new_def['class'];
1780 1780
 
1781
-        $product_featured_def = self::display_product_special_state('highlight_product', $output_type, (!empty($product['highlight_product']) ? $product['highlight_product'] : 'no'), (!empty($product['highlight_from']) ? $product['highlight_from'] : ''), (!empty($product['highlight_to']) ? $product['highlight_to'] : ''));
1782
-        $product_featured = $product_featured_def['output'];
1783
-        $product_class .= $product_featured_def['class'];
1781
+		$product_featured_def = self::display_product_special_state('highlight_product', $output_type, (!empty($product['highlight_product']) ? $product['highlight_product'] : 'no'), (!empty($product['highlight_from']) ? $product['highlight_from'] : ''), (!empty($product['highlight_to']) ? $product['highlight_to'] : ''));
1782
+		$product_featured = $product_featured_def['output'];
1783
+		$product_class .= $product_featured_def['class'];
1784 1784
 
1785
-        if (!($current_item_position % $grid_element_nb_per_line)) {
1786
-            $product_class .= ' wpshop_last_product_of_line';
1787
-        }
1785
+		if (!($current_item_position % $grid_element_nb_per_line)) {
1786
+			$product_class .= ' wpshop_last_product_of_line';
1787
+		}
1788 1788
 
1789
-        if (!empty($product['product_id'])) {
1790
-            /** Template parameters    */
1791
-            $template_part = 'product_mini_' . $output_type;
1792
-            $tpl_component = array();
1793
-            $tpl_component['PRODUCT_THUMBNAIL'] = wpshop_display::display_template_element('product_thumbnail_default', array());
1794
-            $tpl_component['PRODUCT_THUMBNAIL_WPSHOP-PRODUCT-GALERY'] = wpshop_display::display_template_element('product_thumbnail_default', array());
1795
-            $tpl_component['PRODUCT_ID'] = $product_id;
1796
-            $tpl_component['PRODUCT_CLASS'] = $product_class;
1797
-            $tpl_component['PRODUCT_BUTTON_ADD_TO_CART'] = $add_to_cart_button;
1798
-            $tpl_component['PRODUCT_BUTTON_QUOTATION'] = $quotation_button;
1799
-            $tpl_component['PRODUCT_QUANTITY_CHOOSER'] = $product_quantity_chooser_input;
1800
-            $tpl_component['PRODUCT_BUTTONS'] = $tpl_component['PRODUCT_BUTTON_ADD_TO_CART'] . $tpl_component['PRODUCT_BUTTON_QUOTATION'];
1801
-            $tpl_component['PRODUCT_PRICE'] = $productPrice;
1802
-            $tpl_component['PRODUCT_PERMALINK'] = $product_link;
1803
-            $tpl_component['PRODUCT_TITLE'] = (!empty($product_title)) ? $product_title : '';
1804
-            $tpl_component['PRODUCT_NAME'] = $product_name;
1805
-            $tpl_component['PRODUCT_DESCRIPTION'] = $product_more_informations;
1806
-            $tpl_component['PRODUCT_IS_NEW'] = $product_new;
1807
-            $tpl_component['PRODUCT_IS_FEATURED'] = $product_featured;
1808
-            $tpl_component['PRODUCT_EXTRA_STATE'] = $tpl_component['PRODUCT_IS_NEW'] . $tpl_component['PRODUCT_IS_FEATURED'];
1809
-            $tpl_component['PRODUCT_THUMBNAIL'] = $productThumbnail;
1810
-
1811
-            if (has_post_thumbnail($product_id)) {
1812
-                $image_attributes = wp_get_attachment_metadata(get_post_thumbnail_id($product_id));
1813
-                if (!empty($image_attributes) && !empty($image_attributes['sizes']) && is_array($image_attributes['sizes'])) {
1814
-                    $existing_image_sizes = get_intermediate_image_sizes();
1815
-                    foreach ($existing_image_sizes as $size_name) {
1816
-                        $tpl_component['PRODUCT_THUMBNAIL_' . strtoupper($size_name)] = wp_get_attachment_image(get_post_thumbnail_id($product_id), $size_name);
1817
-                        $tpl_component['PRODUCT_THUMBNAIL_' . strtoupper($size_name)] = (!empty($tpl_component['PRODUCT_THUMBNAIL_' . strtoupper($size_name)])) ? $tpl_component['PRODUCT_THUMBNAIL_' . strtoupper($size_name)] : WPSHOP_DEFAULT_PRODUCT_PICTURE;
1818
-                    }
1819
-                }
1820
-            }
1821
-
1822
-            $tpl_component['PRODUCT_EXCERPT'] = $product_excerpt;
1823
-            $tpl_component['PRODUCT_OUTPUT_TYPE'] = $output_type;
1824
-            $tpl_component = apply_filters('wps-filter-product-mini-output', $tpl_component, $product_id);
1825
-
1826
-            /** Build template    */
1827
-            $tpl_way_to_take = wpshop_display::check_way_for_template($template_part);
1828
-            if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) {
1829
-                /**    Include the old way template part    */
1830
-                ob_start();
1831
-                require wpshop_display::get_template_file($tpl_way_to_take[1]);
1832
-                $content = ob_get_contents();
1833
-                ob_end_clean();
1834
-            } else {
1835
-                $content = wpshop_display::display_template_element($template_part, $tpl_component);
1836
-            }
1837
-            unset($tpl_component);
1789
+		if (!empty($product['product_id'])) {
1790
+			/** Template parameters    */
1791
+			$template_part = 'product_mini_' . $output_type;
1792
+			$tpl_component = array();
1793
+			$tpl_component['PRODUCT_THUMBNAIL'] = wpshop_display::display_template_element('product_thumbnail_default', array());
1794
+			$tpl_component['PRODUCT_THUMBNAIL_WPSHOP-PRODUCT-GALERY'] = wpshop_display::display_template_element('product_thumbnail_default', array());
1795
+			$tpl_component['PRODUCT_ID'] = $product_id;
1796
+			$tpl_component['PRODUCT_CLASS'] = $product_class;
1797
+			$tpl_component['PRODUCT_BUTTON_ADD_TO_CART'] = $add_to_cart_button;
1798
+			$tpl_component['PRODUCT_BUTTON_QUOTATION'] = $quotation_button;
1799
+			$tpl_component['PRODUCT_QUANTITY_CHOOSER'] = $product_quantity_chooser_input;
1800
+			$tpl_component['PRODUCT_BUTTONS'] = $tpl_component['PRODUCT_BUTTON_ADD_TO_CART'] . $tpl_component['PRODUCT_BUTTON_QUOTATION'];
1801
+			$tpl_component['PRODUCT_PRICE'] = $productPrice;
1802
+			$tpl_component['PRODUCT_PERMALINK'] = $product_link;
1803
+			$tpl_component['PRODUCT_TITLE'] = (!empty($product_title)) ? $product_title : '';
1804
+			$tpl_component['PRODUCT_NAME'] = $product_name;
1805
+			$tpl_component['PRODUCT_DESCRIPTION'] = $product_more_informations;
1806
+			$tpl_component['PRODUCT_IS_NEW'] = $product_new;
1807
+			$tpl_component['PRODUCT_IS_FEATURED'] = $product_featured;
1808
+			$tpl_component['PRODUCT_EXTRA_STATE'] = $tpl_component['PRODUCT_IS_NEW'] . $tpl_component['PRODUCT_IS_FEATURED'];
1809
+			$tpl_component['PRODUCT_THUMBNAIL'] = $productThumbnail;
1810
+
1811
+			if (has_post_thumbnail($product_id)) {
1812
+				$image_attributes = wp_get_attachment_metadata(get_post_thumbnail_id($product_id));
1813
+				if (!empty($image_attributes) && !empty($image_attributes['sizes']) && is_array($image_attributes['sizes'])) {
1814
+					$existing_image_sizes = get_intermediate_image_sizes();
1815
+					foreach ($existing_image_sizes as $size_name) {
1816
+						$tpl_component['PRODUCT_THUMBNAIL_' . strtoupper($size_name)] = wp_get_attachment_image(get_post_thumbnail_id($product_id), $size_name);
1817
+						$tpl_component['PRODUCT_THUMBNAIL_' . strtoupper($size_name)] = (!empty($tpl_component['PRODUCT_THUMBNAIL_' . strtoupper($size_name)])) ? $tpl_component['PRODUCT_THUMBNAIL_' . strtoupper($size_name)] : WPSHOP_DEFAULT_PRODUCT_PICTURE;
1818
+					}
1819
+				}
1820
+			}
1838 1821
 
1839
-        }
1822
+			$tpl_component['PRODUCT_EXCERPT'] = $product_excerpt;
1823
+			$tpl_component['PRODUCT_OUTPUT_TYPE'] = $output_type;
1824
+			$tpl_component = apply_filters('wps-filter-product-mini-output', $tpl_component, $product_id);
1825
+
1826
+			/** Build template    */
1827
+			$tpl_way_to_take = wpshop_display::check_way_for_template($template_part);
1828
+			if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) {
1829
+				/**    Include the old way template part    */
1830
+				ob_start();
1831
+				require wpshop_display::get_template_file($tpl_way_to_take[1]);
1832
+				$content = ob_get_contents();
1833
+				ob_end_clean();
1834
+			} else {
1835
+				$content = wpshop_display::display_template_element($template_part, $tpl_component);
1836
+			}
1837
+			unset($tpl_component);
1840 1838
 
1841
-        return $content;
1842
-    }
1839
+		}
1843 1840
 
1844
-    /**
1845
-     *    Get the products (post) of a given category
1846
-     *
1847
-     *    @param string $category_slug The category slug we want to get the product list for
1848
-     *
1849
-     *    @return mixed $widget_content The output for the product list
1850
-     */
1851
-    public static function get_product_of_category($category_slug, $category_id)
1852
-    {
1853
-        global $top_categories;
1854
-        $widget_content = '';
1855
-        $products = wp_cache_get('wpshop_products_category_' . $category_id);
1856
-        if (false == $products) {
1857
-            $args = array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES => $category_slug);
1858
-            $products = get_posts($args);
1859
-            wp_cache_set('wpshop_products_category_' . $category_id, $products);
1860
-        }
1861
-        if (is_array($products) && (count($products) > 0)) {
1862
-            foreach ($products as $product) {
1863
-                if ($product->post_status == "publish") {
1864
-                    ob_start();
1865
-                    require wpshop_display::get_template_file('categories_products-widget.tpl.php');
1866
-                    $widget_content .= ob_get_contents();
1867
-                    ob_end_clean();
1868
-                }
1869
-            }
1870
-        }
1841
+		return $content;
1842
+	}
1871 1843
 
1872
-        echo $widget_content;
1873
-    }
1844
+	/**
1845
+	 *    Get the products (post) of a given category
1846
+	 *
1847
+	 *    @param string $category_slug The category slug we want to get the product list for
1848
+	 *
1849
+	 *    @return mixed $widget_content The output for the product list
1850
+	 */
1851
+	public static function get_product_of_category($category_slug, $category_id)
1852
+	{
1853
+		global $top_categories;
1854
+		$widget_content = '';
1855
+		$products = wp_cache_get('wpshop_products_category_' . $category_id);
1856
+		if (false == $products) {
1857
+			$args = array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES => $category_slug);
1858
+			$products = get_posts($args);
1859
+			wp_cache_set('wpshop_products_category_' . $category_id, $products);
1860
+		}
1861
+		if (is_array($products) && (count($products) > 0)) {
1862
+			foreach ($products as $product) {
1863
+				if ($product->post_status == "publish") {
1864
+					ob_start();
1865
+					require wpshop_display::get_template_file('categories_products-widget.tpl.php');
1866
+					$widget_content .= ob_get_contents();
1867
+					ob_end_clean();
1868
+				}
1869
+			}
1870
+		}
1871
+
1872
+		echo $widget_content;
1873
+	}
1874 1874
 
1875
-    /**
1876
-     *
1877
-     * @param unknown_type $selected_product
1878
-     * @return string
1879
-     */
1880
-    public function custom_product_list($selected_product = array())
1881
-    {
1882
-        global $wpdb;
1883
-
1884
-        /*    Start the table definition    */
1885
-        $tableId = 'wpshop_product_list';
1886
-        $tableTitles = array();
1887
-        $tableTitles[] = '';
1888
-        $tableTitles[] = __('Id', 'wpshop');
1889
-        $tableTitles[] = __('Quantity', 'wpshop');
1890
-        $tableTitles[] = __('Reference', 'wpshop');
1891
-        $tableTitles[] = __('Product name', 'wpshop');
1892
-        $tableTitles[] = __('Actions', 'wpshop');
1893
-        $tableTitles[] = __('Price', 'wpshop');
1894
-        $tableClasses = array();
1895
-        $tableClasses[] = 'wpshop_product_selector_column';
1896
-        $tableClasses[] = 'wpshop_product_identifier_column';
1897
-        $tableClasses[] = 'wpshop_product_quantity_column';
1898
-        $tableClasses[] = 'wpshop_product_sku_column';
1899
-        $tableClasses[] = 'wpshop_product_name_column';
1900
-        $tableClasses[] = 'wpshop_product_link_column';
1901
-        $tableClasses[] = 'wpshop_product_price_column';
1902
-
1903
-        /*    Get post list    */
1904
-        $has_result = false;
1905
-        $current_line_index = 0;
1906
-        $posts = query_posts(array(
1907
-            'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'posts_per_page' => -1,
1908
-        ));
1909
-        if (!empty($posts)) {
1910
-            $has_result = true;
1911
-            foreach ($posts as $post) {
1912
-                $tableRowsId[$current_line_index] = 'product_' . $post->ID;
1913
-
1914
-                $post_info = get_post_meta($post->ID, '_wpshop_product_metadata', true);
1915
-
1916
-                unset($tableRowValue);
1917
-                $tableRowValue[] = array('class' => 'wpshop_product_selector_cell', 'value' => '<input type="checkbox" name="wp_list_product[]" value="' . $post->ID . '" class="wpshop_product_cb_dialog" id="wpshop_product_cb_dialog_' . $post->ID . '" />');
1918
-                $tableRowValue[] = array('class' => 'wpshop_product_identifier_cell', 'value' => '<label for="wpshop_product_cb_dialog_' . $post->ID . '" >' . WPSHOP_IDENTIFIER_PRODUCT . $post->ID . '</label>');
1919
-                $tableRowValue[] = array('class' => 'wpshop_product_quantity_cell', 'value' => '<a href="#" class="order_product_action_button qty_change">-</a><input type="text" name="wpshop_pdt_qty[' . $post->ID . ']" value="1" class="wpshop_order_product_qty" /><a href="#" class="order_product_action_button qty_change">+</a>');
1920
-                $tableRowValue[] = array('class' => 'wpshop_product_sku_cell', 'value' => (!empty($post_info['product_reference'])) ? $post_info['product_reference'] : '');
1921
-                $tableRowValue[] = array('class' => 'wpshop_product_name_cell', 'value' => $post->post_title);
1922
-                $tableRowValue[] = array('class' => 'wpshop_product_link_cell', 'value' => '<a href="' . $post->guid . '" target="wpshop_product_view_product" target="wpshop_view_product" >' . __('View product', 'wpshop') . '</a><br/>
1875
+	/**
1876
+	 *
1877
+	 * @param unknown_type $selected_product
1878
+	 * @return string
1879
+	 */
1880
+	public function custom_product_list($selected_product = array())
1881
+	{
1882
+		global $wpdb;
1883
+
1884
+		/*    Start the table definition    */
1885
+		$tableId = 'wpshop_product_list';
1886
+		$tableTitles = array();
1887
+		$tableTitles[] = '';
1888
+		$tableTitles[] = __('Id', 'wpshop');
1889
+		$tableTitles[] = __('Quantity', 'wpshop');
1890
+		$tableTitles[] = __('Reference', 'wpshop');
1891
+		$tableTitles[] = __('Product name', 'wpshop');
1892
+		$tableTitles[] = __('Actions', 'wpshop');
1893
+		$tableTitles[] = __('Price', 'wpshop');
1894
+		$tableClasses = array();
1895
+		$tableClasses[] = 'wpshop_product_selector_column';
1896
+		$tableClasses[] = 'wpshop_product_identifier_column';
1897
+		$tableClasses[] = 'wpshop_product_quantity_column';
1898
+		$tableClasses[] = 'wpshop_product_sku_column';
1899
+		$tableClasses[] = 'wpshop_product_name_column';
1900
+		$tableClasses[] = 'wpshop_product_link_column';
1901
+		$tableClasses[] = 'wpshop_product_price_column';
1902
+
1903
+		/*    Get post list    */
1904
+		$has_result = false;
1905
+		$current_line_index = 0;
1906
+		$posts = query_posts(array(
1907
+			'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'posts_per_page' => -1,
1908
+		));
1909
+		if (!empty($posts)) {
1910
+			$has_result = true;
1911
+			foreach ($posts as $post) {
1912
+				$tableRowsId[$current_line_index] = 'product_' . $post->ID;
1913
+
1914
+				$post_info = get_post_meta($post->ID, '_wpshop_product_metadata', true);
1915
+
1916
+				unset($tableRowValue);
1917
+				$tableRowValue[] = array('class' => 'wpshop_product_selector_cell', 'value' => '<input type="checkbox" name="wp_list_product[]" value="' . $post->ID . '" class="wpshop_product_cb_dialog" id="wpshop_product_cb_dialog_' . $post->ID . '" />');
1918
+				$tableRowValue[] = array('class' => 'wpshop_product_identifier_cell', 'value' => '<label for="wpshop_product_cb_dialog_' . $post->ID . '" >' . WPSHOP_IDENTIFIER_PRODUCT . $post->ID . '</label>');
1919
+				$tableRowValue[] = array('class' => 'wpshop_product_quantity_cell', 'value' => '<a href="#" class="order_product_action_button qty_change">-</a><input type="text" name="wpshop_pdt_qty[' . $post->ID . ']" value="1" class="wpshop_order_product_qty" /><a href="#" class="order_product_action_button qty_change">+</a>');
1920
+				$tableRowValue[] = array('class' => 'wpshop_product_sku_cell', 'value' => (!empty($post_info['product_reference'])) ? $post_info['product_reference'] : '');
1921
+				$tableRowValue[] = array('class' => 'wpshop_product_name_cell', 'value' => $post->post_title);
1922
+				$tableRowValue[] = array('class' => 'wpshop_product_link_cell', 'value' => '<a href="' . $post->guid . '" target="wpshop_product_view_product" target="wpshop_view_product" >' . __('View product', 'wpshop') . '</a><br/>
1923 1923
 				<a href="' . admin_url('post.php?post=' . $post->ID . '&action=edit') . '" target="wpshop_edit_product" >' . __('Edit product', 'wpshop') . '</a>');
1924
-                $tableRowValue[] = array('class' => 'wpshop_product_price_cell', 'value' => __('Price ET', 'wpshop') . '&nbsp;:&nbsp;' . ((!empty($post_info[WPSHOP_PRODUCT_PRICE_HT])) ? round($post_info[WPSHOP_PRODUCT_PRICE_HT], 2) . '&nbsp;' . wpshop_tools::wpshop_get_currency() : '') . '<br/>' . __('Price ATI', 'wpshop') . '&nbsp;:&nbsp;' . ((!empty($post_info[WPSHOP_PRODUCT_PRICE_TTC])) ? round($post_info[WPSHOP_PRODUCT_PRICE_TTC], 2) . '&nbsp;' . wpshop_tools::wpshop_get_currency() : ''));
1925
-                $tableRows[] = $tableRowValue;
1924
+				$tableRowValue[] = array('class' => 'wpshop_product_price_cell', 'value' => __('Price ET', 'wpshop') . '&nbsp;:&nbsp;' . ((!empty($post_info[WPSHOP_PRODUCT_PRICE_HT])) ? round($post_info[WPSHOP_PRODUCT_PRICE_HT], 2) . '&nbsp;' . wpshop_tools::wpshop_get_currency() : '') . '<br/>' . __('Price ATI', 'wpshop') . '&nbsp;:&nbsp;' . ((!empty($post_info[WPSHOP_PRODUCT_PRICE_TTC])) ? round($post_info[WPSHOP_PRODUCT_PRICE_TTC], 2) . '&nbsp;' . wpshop_tools::wpshop_get_currency() : ''));
1925
+				$tableRows[] = $tableRowValue;
1926 1926
 
1927
-                $current_line_index++;
1928
-            }
1929
-            wp_reset_query();
1930
-        }
1931
-        $posts = query_posts(array(
1932
-            'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, 'posts_per_page' => -1,
1933
-        ));
1934
-        if (!empty($posts)) {
1935
-            $has_result = true;
1936
-            foreach ($posts as $post) {
1937
-                $tableRowsId[$current_line_index] = 'product_' . $post->ID;
1938
-
1939
-                $post_info = get_post_meta($post->ID, '_wpshop_product_metadata', true);
1940
-
1941
-                unset($tableRowValue);
1942
-                $tableRowValue[] = array('class' => 'wpshop_product_selector_cell', 'value' => '<input type="checkbox" name="wp_list_product[]" value="' . $post->ID . '" class="wpshop_product_cb_dialog" id="wpshop_product_cb_dialog_' . $post->ID . '" />');
1943
-                $tableRowValue[] = array('class' => 'wpshop_product_identifier_cell', 'value' => '<label for="wpshop_product_cb_dialog_' . $post->ID . '" >' . WPSHOP_IDENTIFIER_PRODUCT . $post->ID . '</label>');
1944
-                $tableRowValue[] = array('class' => 'wpshop_product_quantity_cell', 'value' => '<a href="#" class="order_product_action_button qty_change">-</a><input type="text" name="wpshop_pdt_qty[' . $post->ID . ']" value="1" class="wpshop_order_product_qty" /><a href="#" class="order_product_action_button qty_change">+</a>');
1945
-                $tableRowValue[] = array('class' => 'wpshop_product_sku_cell', 'value' => (!empty($post_info['product_reference'])) ? $post_info['product_reference'] : '');
1946
-                $parent_product = wpshop_products::get_parent_variation($post->ID);
1947
-                if (!empty($parent_product) && !empty($parent_product['parent_post'])) {
1948
-                    $product_variations_postmeta = get_post_meta($post->ID, '_wpshop_variations_attribute_def', true);
1949
-                    $query = $wpdb->prepare('SELECT frontend_label FROM ' . WPSHOP_DBT_ATTRIBUTE . ' WHERE code = %s', key($product_variations_postmeta));
1950
-                    $option_name = $wpdb->get_var($query);
1951
-                    $query = $wpdb->prepare('SELECT label FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id = %d', $product_variations_postmeta[key($product_variations_postmeta)]);
1952
-                    $option_value = $wpdb->get_var($query);
1953
-                    $parent_post = $parent_product['parent_post'];
1954
-                    $tableRowValue[] = array('class' => 'wpshop_product_name_cell', 'value' => $parent_post->post_title . ' <br/>(' . $option_name . ' : ' . $option_value . ')');
1955
-                } else {
1956
-                    $tableRowValue[] = array('class' => 'wpshop_product_name_cell', 'value' => $post->post_title);
1957
-                }
1958
-
1959
-                $tableRowValue[] = array('class' => 'wpshop_product_link_cell', 'value' => '<a href="' . $post->guid . '" target="wpshop_product_view_product" target="wpshop_view_product" >' . __('View product', 'wpshop') . '</a><br/>
1927
+				$current_line_index++;
1928
+			}
1929
+			wp_reset_query();
1930
+		}
1931
+		$posts = query_posts(array(
1932
+			'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, 'posts_per_page' => -1,
1933
+		));
1934
+		if (!empty($posts)) {
1935
+			$has_result = true;
1936
+			foreach ($posts as $post) {
1937
+				$tableRowsId[$current_line_index] = 'product_' . $post->ID;
1938
+
1939
+				$post_info = get_post_meta($post->ID, '_wpshop_product_metadata', true);
1940
+
1941
+				unset($tableRowValue);
1942
+				$tableRowValue[] = array('class' => 'wpshop_product_selector_cell', 'value' => '<input type="checkbox" name="wp_list_product[]" value="' . $post->ID . '" class="wpshop_product_cb_dialog" id="wpshop_product_cb_dialog_' . $post->ID . '" />');
1943
+				$tableRowValue[] = array('class' => 'wpshop_product_identifier_cell', 'value' => '<label for="wpshop_product_cb_dialog_' . $post->ID . '" >' . WPSHOP_IDENTIFIER_PRODUCT . $post->ID . '</label>');
1944
+				$tableRowValue[] = array('class' => 'wpshop_product_quantity_cell', 'value' => '<a href="#" class="order_product_action_button qty_change">-</a><input type="text" name="wpshop_pdt_qty[' . $post->ID . ']" value="1" class="wpshop_order_product_qty" /><a href="#" class="order_product_action_button qty_change">+</a>');
1945
+				$tableRowValue[] = array('class' => 'wpshop_product_sku_cell', 'value' => (!empty($post_info['product_reference'])) ? $post_info['product_reference'] : '');
1946
+				$parent_product = wpshop_products::get_parent_variation($post->ID);
1947
+				if (!empty($parent_product) && !empty($parent_product['parent_post'])) {
1948
+					$product_variations_postmeta = get_post_meta($post->ID, '_wpshop_variations_attribute_def', true);
1949
+					$query = $wpdb->prepare('SELECT frontend_label FROM ' . WPSHOP_DBT_ATTRIBUTE . ' WHERE code = %s', key($product_variations_postmeta));
1950
+					$option_name = $wpdb->get_var($query);
1951
+					$query = $wpdb->prepare('SELECT label FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id = %d', $product_variations_postmeta[key($product_variations_postmeta)]);
1952
+					$option_value = $wpdb->get_var($query);
1953
+					$parent_post = $parent_product['parent_post'];
1954
+					$tableRowValue[] = array('class' => 'wpshop_product_name_cell', 'value' => $parent_post->post_title . ' <br/>(' . $option_name . ' : ' . $option_value . ')');
1955
+				} else {
1956
+					$tableRowValue[] = array('class' => 'wpshop_product_name_cell', 'value' => $post->post_title);
1957
+				}
1958
+
1959
+				$tableRowValue[] = array('class' => 'wpshop_product_link_cell', 'value' => '<a href="' . $post->guid . '" target="wpshop_product_view_product" target="wpshop_view_product" >' . __('View product', 'wpshop') . '</a><br/>
1960 1960
 				<a href="' . admin_url('post.php?post=' . $post->ID . '&action=edit') . '" target="wpshop_edit_product" >' . __('Edit product', 'wpshop') . '</a>');
1961
-                $tableRowValue[] = array('class' => 'wpshop_product_price_cell', 'value' => __('Price ET', 'wpshop') . '&nbsp;:&nbsp;' . ((!empty($post_info[WPSHOP_PRODUCT_PRICE_HT])) ? round($post_info[WPSHOP_PRODUCT_PRICE_HT], 2) . '&nbsp;' . wpshop_tools::wpshop_get_currency() : '') . '<br/>' . __('Price ATI', 'wpshop') . '&nbsp;:&nbsp;' . ((!empty($post_info[WPSHOP_PRODUCT_PRICE_TTC])) ? round($post_info[WPSHOP_PRODUCT_PRICE_TTC], 2) . '&nbsp;' . wpshop_tools::wpshop_get_currency() : ''));
1962
-                $tableRows[] = $tableRowValue;
1961
+				$tableRowValue[] = array('class' => 'wpshop_product_price_cell', 'value' => __('Price ET', 'wpshop') . '&nbsp;:&nbsp;' . ((!empty($post_info[WPSHOP_PRODUCT_PRICE_HT])) ? round($post_info[WPSHOP_PRODUCT_PRICE_HT], 2) . '&nbsp;' . wpshop_tools::wpshop_get_currency() : '') . '<br/>' . __('Price ATI', 'wpshop') . '&nbsp;:&nbsp;' . ((!empty($post_info[WPSHOP_PRODUCT_PRICE_TTC])) ? round($post_info[WPSHOP_PRODUCT_PRICE_TTC], 2) . '&nbsp;' . wpshop_tools::wpshop_get_currency() : ''));
1962
+				$tableRows[] = $tableRowValue;
1963 1963
 
1964
-                $current_line_index++;
1965
-            }
1966
-            wp_reset_query();
1967
-        }
1964
+				$current_line_index++;
1965
+			}
1966
+			wp_reset_query();
1967
+		}
1968 1968
 
1969
-        if (!$has_result) {
1970
-            $tableRowsId[] = 'no_product_found';
1971
-            unset($tableRowValue);
1972
-            $tableRowValue[] = array('class' => 'wpshop_product_selector_cell', 'value' => '');
1973
-            $tableRowValue[] = array('class' => 'wpshop_product_identifier_cell', 'value' => '');
1974
-            $tableRowValue[] = array('class' => 'wpshop_product_quantity_cell', 'value' => '');
1975
-            $tableRowValue[] = array('class' => 'wpshop_product_sku_cell', 'value' => __('No element to ouput here', 'wpshop'));
1976
-            $tableRowValue[] = array('class' => 'wpshop_product_name_cell', 'value' => '');
1977
-            $tableRowValue[] = array('class' => 'wpshop_product_link_cell', 'value' => '');
1978
-            $tableRowValue[] = array('class' => 'wpshop_product_price_cell', 'value' => '');
1979
-            $tableRows[] = $tableRowValue;
1980
-        }
1969
+		if (!$has_result) {
1970
+			$tableRowsId[] = 'no_product_found';
1971
+			unset($tableRowValue);
1972
+			$tableRowValue[] = array('class' => 'wpshop_product_selector_cell', 'value' => '');
1973
+			$tableRowValue[] = array('class' => 'wpshop_product_identifier_cell', 'value' => '');
1974
+			$tableRowValue[] = array('class' => 'wpshop_product_quantity_cell', 'value' => '');
1975
+			$tableRowValue[] = array('class' => 'wpshop_product_sku_cell', 'value' => __('No element to ouput here', 'wpshop'));
1976
+			$tableRowValue[] = array('class' => 'wpshop_product_name_cell', 'value' => '');
1977
+			$tableRowValue[] = array('class' => 'wpshop_product_link_cell', 'value' => '');
1978
+			$tableRowValue[] = array('class' => 'wpshop_product_price_cell', 'value' => '');
1979
+			$tableRows[] = $tableRowValue;
1980
+		}
1981 1981
 
1982
-        return wpshop_display::getTable($tableId, $tableTitles, $tableRows, $tableClasses, $tableRowsId, '', false) . '
1982
+		return wpshop_display::getTable($tableId, $tableTitles, $tableRows, $tableClasses, $tableRowsId, '', false) . '
1983 1983
 <script type="text/javascript" >
1984 1984
 	wpshop(document).ready(function(){
1985 1985
 		jQuery("#' . $tableId . '").dataTable( {
@@ -1988,1534 +1988,1534 @@  discard block
 block discarded – undo
1988 1988
 		});
1989 1989
 	});
1990 1990
 </script>';
1991
-    }
1991
+	}
1992 1992
 
1993
-    /**
1994
-     * Allows to manage output for special state for a product (New product/highlight product)
1995
-     *
1996
-     * @param string $special The type of special type we want to output
1997
-     * @param string $output_type The current display type (used for product listing)
1998
-     * @param string $special_state_def The value allowing to test if we have to display a special state for the product
1999
-     * @param datetime $special_state_start The start date if applicable for the special state
2000
-     * @param datetime $special_state_end The end date if applicable for the special state
2001
-     *
2002
-     * @return array $product_special_state The product special state
2003
-     */
2004
-    public static function display_product_special_state($special, $output_type, $special_state_def, $special_state_start, $special_state_end)
2005
-    {
2006
-        $product_special_state = array();
2007
-        $product_special_state['output'] = $product_special_state['class'] = '';
2008
-
2009
-        /** Get product special state definition    */
2010
-        $special_state_def = !empty($special_state_def) ? $special_state_def : 'No';
2011
-        $special_state_start = !empty($special_state_start) ? substr($special_state_start, 0, 10) : null;
2012
-        $special_state_end = !empty($special_state_end) ? substr($special_state_end, 0, 10) : null;
2013
-
2014
-        /** Get current time    */
2015
-        $current_time = substr(current_time('mysql', 0), 0, 10);
2016
-
2017
-        /** PRODUCT MARK AS NEW */
2018
-        $show_product_special_state = false;
2019
-        if ((strtolower(__($special_state_def, 'wpshop')) === strtolower(__('Yes', 'wpshop'))) &&
2020
-            (empty($special_state_start) || ($special_state_start == '0000-00-00') || ($special_state_start >= $current_time)) &&
2021
-            (empty($special_state_end) || ($special_state_end == '0000-00-00') || ($special_state_end <= $current_time))) {
2022
-            $show_product_special_state = true;
2023
-        }
1993
+	/**
1994
+	 * Allows to manage output for special state for a product (New product/highlight product)
1995
+	 *
1996
+	 * @param string $special The type of special type we want to output
1997
+	 * @param string $output_type The current display type (used for product listing)
1998
+	 * @param string $special_state_def The value allowing to test if we have to display a special state for the product
1999
+	 * @param datetime $special_state_start The start date if applicable for the special state
2000
+	 * @param datetime $special_state_end The end date if applicable for the special state
2001
+	 *
2002
+	 * @return array $product_special_state The product special state
2003
+	 */
2004
+	public static function display_product_special_state($special, $output_type, $special_state_def, $special_state_start, $special_state_end)
2005
+	{
2006
+		$product_special_state = array();
2007
+		$product_special_state['output'] = $product_special_state['class'] = '';
2008
+
2009
+		/** Get product special state definition    */
2010
+		$special_state_def = !empty($special_state_def) ? $special_state_def : 'No';
2011
+		$special_state_start = !empty($special_state_start) ? substr($special_state_start, 0, 10) : null;
2012
+		$special_state_end = !empty($special_state_end) ? substr($special_state_end, 0, 10) : null;
2013
+
2014
+		/** Get current time    */
2015
+		$current_time = substr(current_time('mysql', 0), 0, 10);
2016
+
2017
+		/** PRODUCT MARK AS NEW */
2018
+		$show_product_special_state = false;
2019
+		if ((strtolower(__($special_state_def, 'wpshop')) === strtolower(__('Yes', 'wpshop'))) &&
2020
+			(empty($special_state_start) || ($special_state_start == '0000-00-00') || ($special_state_start >= $current_time)) &&
2021
+			(empty($special_state_end) || ($special_state_end == '0000-00-00') || ($special_state_end <= $current_time))) {
2022
+			$show_product_special_state = true;
2023
+		}
2024 2024
 
2025
-        if ($show_product_special_state) {
2026
-            /** Check the type of special output needed    */
2027
-            switch ($special) {
2028
-                case 'declare_new':
2029
-                    $product_special_state['class'] = ' wpshop_product_is_new_' . $output_type;
2030
-                    $template_part = 'product_is_new_sticker';
2031
-                    break;
2032
-
2033
-                case 'highlight_product':
2034
-                    $product_special_state['class'] = ' wpshop_product_featured_' . $output_type;
2035
-                    $template_part = 'product_is_featured_sticker';
2036
-                    break;
2037
-            }
2038
-
2039
-            /** Template parameters    */
2040
-            $tpl_component = array();
2041
-
2042
-            /** Build template        */
2043
-            $tpl_way_to_take = wpshop_display::check_way_for_template($template_part);
2044
-            if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) {
2045
-                /**    Include the old way template part    */
2046
-                ob_start();
2047
-                require wpshop_display::get_template_file($tpl_way_to_take[1]);
2048
-                $product_special_state['output'] = ob_get_contents();
2049
-                ob_end_clean();
2050
-            } else {
2051
-                $product_special_state['output'] = wpshop_display::display_template_element($template_part, $tpl_component);
2052
-            }
2053
-            unset($tpl_component);
2054
-        }
2025
+		if ($show_product_special_state) {
2026
+			/** Check the type of special output needed    */
2027
+			switch ($special) {
2028
+				case 'declare_new':
2029
+					$product_special_state['class'] = ' wpshop_product_is_new_' . $output_type;
2030
+					$template_part = 'product_is_new_sticker';
2031
+					break;
2055 2032
 
2056
-        return $product_special_state;
2057
-    }
2033
+				case 'highlight_product':
2034
+					$product_special_state['class'] = ' wpshop_product_featured_' . $output_type;
2035
+					$template_part = 'product_is_featured_sticker';
2036
+					break;
2037
+			}
2058 2038
 
2059
-    /**
2060
-     * Prepare product price for saving and easier read later
2061
-     *
2062
-     * @param integer $element_id Identifier of current product
2063
-     */
2064
-    public static function calculate_price($element_id)
2065
-    {
2066
-        global $wpdb;
2067
-
2068
-        /**
2069
-         * Récupères les attributs suivants : product_price, price_ht et tva
2070
-         * par rapport à $element_id / Get the next attributes : product_price,
2071
-         * price_ht and tva
2072
-         */
2073
-        $query = $wpdb->prepare(
2074
-            "SELECT ATTR.code, ATTR_VAL.value_id AS id, ATTR_VAL.value, ATTR.id AS attribute_id
2039
+			/** Template parameters    */
2040
+			$tpl_component = array();
2041
+
2042
+			/** Build template        */
2043
+			$tpl_way_to_take = wpshop_display::check_way_for_template($template_part);
2044
+			if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) {
2045
+				/**    Include the old way template part    */
2046
+				ob_start();
2047
+				require wpshop_display::get_template_file($tpl_way_to_take[1]);
2048
+				$product_special_state['output'] = ob_get_contents();
2049
+				ob_end_clean();
2050
+			} else {
2051
+				$product_special_state['output'] = wpshop_display::display_template_element($template_part, $tpl_component);
2052
+			}
2053
+			unset($tpl_component);
2054
+		}
2055
+
2056
+		return $product_special_state;
2057
+	}
2058
+
2059
+	/**
2060
+	 * Prepare product price for saving and easier read later
2061
+	 *
2062
+	 * @param integer $element_id Identifier of current product
2063
+	 */
2064
+	public static function calculate_price($element_id)
2065
+	{
2066
+		global $wpdb;
2067
+
2068
+		/**
2069
+		 * Récupères les attributs suivants : product_price, price_ht et tva
2070
+		 * par rapport à $element_id / Get the next attributes : product_price,
2071
+		 * price_ht and tva
2072
+		 */
2073
+		$query = $wpdb->prepare(
2074
+			"SELECT ATTR.code, ATTR_VAL.value_id AS id, ATTR_VAL.value, ATTR.id AS attribute_id
2075 2075
 			FROM " . WPSHOP_DBT_ATTRIBUTE . " AS ATTR
2076 2076
 				RIGHT JOIN " . WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL . " AS ATTR_VAL ON ((ATTR_VAL.attribute_id = ATTR.id) AND (ATTR_VAL.entity_id = %d))
2077 2077
 			WHERE ATTR.code IN ('" . implode("', '", unserialize(WPSHOP_ATTRIBUTE_PRICES)) . "')",
2078
-            $element_id
2079
-        );
2080
-        $prices_attribute = $wpdb->get_results($query, OBJECT_K);
2081
-
2082
-        /** Si aucun prix trouvé on stop la méthode / If not found price, stop the method */
2083
-        if (empty($prices_attribute)) {
2084
-            return false;
2085
-        } else {
2086
-            /**
2087
-             * Récupère le prix de base selon le pilotage de prix de la boutique / Get
2088
-             * the base amount according on the shop price control
2089
-             */
2090
-            $base_price = $prices_attribute[constant('WPSHOP_PRODUCT_PRICE_' . WPSHOP_PRODUCT_PRICE_PILOT)]->value;
2091
-            $rate_vat = wpshop_prices::get_rate_vat($element_id);
2092
-            $divider_price_ttc = 1 + ($rate_vat->value / 100);
2093
-
2094
-            /**
2095
-             * Informations nécessaire pour crée un attribut / Information needed to
2096
-             * create an attribute
2097
-             */
2098
-            $entity_type_id = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT);
2099
-            $language = WPSHOP_CURRENT_LOCALE;
2100
-            $icl_post_language = !empty($_REQUEST['icl_post_language']) ? sanitize_text_field($_REQUEST['icl_post_language']) : '';
2101
-
2102
-            if (!empty($icl_post_language)) {
2103
-                $query = $wpdb->prepare("SELECT locale FROM " . $wpdb->prefix . "icl_locale_map WHERE code = %s", $icl_post_language);
2104
-                $language = $wpdb->get_var($query);
2105
-            }
2106
-
2107
-            /**
2108
-             * Vérifie la configuration pour savoir comment calculer les prix pour le produit /
2109
-             * Check configuration to know how to make the calcul for the product
2110
-             */
2111
-            if (WPSHOP_PRODUCT_PRICE_PILOT == 'HT') {
2112
-                $price_with_vat = ($base_price * $divider_price_ttc);
2113
-                $price_no_vat = $base_price;
2114
-            } else if (WPSHOP_PRODUCT_PRICE_PILOT == 'TTC') {
2115
-                $price_with_vat = $base_price;
2116
-                $price_no_vat = ($price_with_vat / $divider_price_ttc);
2117
-            }
2118
-
2119
-            /**
2120
-             * Le dernier paramètre permet de ne pas supprimer les attributs du même
2121
-             * type que celui-ci / The last parameter allows not to delete the
2122
-             * attributes of the same type as this one
2123
-             */
2124
-            wpshop_attributes::saveAttributeForEntity(array('decimal' => array('product_price' => $price_with_vat)), $entity_type_id, $element_id, $language, 'wpshop_products');
2125
-            wpshop_attributes::saveAttributeForEntity(array('decimal' => array('price_ht' => $price_no_vat)), $entity_type_id, $element_id, $language, 'wpshop_product');
2126
-
2127
-            /** Ajout ou met à jour de l'attribut tva / Add or update the attribute vat */
2128
-            $vat_amount = $price_with_vat - $price_no_vat;
2129
-            wpshop_attributes::saveAttributeForEntity(array('decimal' => array('tva' => $vat_amount)), $entity_type_id, $element_id, $language, 'wpshop_product');
2130
-
2131
-            /**    Update the product meta information with the calculated prices    */
2132
-            $product_postmeta = get_post_meta($element_id, WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, true);
2133
-            $product_postmeta[WPSHOP_PRODUCT_PRICE_TTC] = number_format(round($price_with_vat, 5), 5, '.', '');
2134
-            $product_postmeta[WPSHOP_PRODUCT_PRICE_HT] = number_format(round($price_no_vat, 5), 5, '.', '');
2135
-            $product_postmeta[WPSHOP_PRODUCT_PRICE_TAX_AMOUNT] = number_format(round($vat_amount, 5), 5, '.', '');
2136
-            $product_postmeta[WPSHOP_PRODUCT_PRICE_TAX] = $rate_vat->id;
2137
-
2138
-            update_post_meta($element_id, WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, $product_postmeta);
2078
+			$element_id
2079
+		);
2080
+		$prices_attribute = $wpdb->get_results($query, OBJECT_K);
2081
+
2082
+		/** Si aucun prix trouvé on stop la méthode / If not found price, stop the method */
2083
+		if (empty($prices_attribute)) {
2084
+			return false;
2085
+		} else {
2086
+			/**
2087
+			 * Récupère le prix de base selon le pilotage de prix de la boutique / Get
2088
+			 * the base amount according on the shop price control
2089
+			 */
2090
+			$base_price = $prices_attribute[constant('WPSHOP_PRODUCT_PRICE_' . WPSHOP_PRODUCT_PRICE_PILOT)]->value;
2091
+			$rate_vat = wpshop_prices::get_rate_vat($element_id);
2092
+			$divider_price_ttc = 1 + ($rate_vat->value / 100);
2093
+
2094
+			/**
2095
+			 * Informations nécessaire pour crée un attribut / Information needed to
2096
+			 * create an attribute
2097
+			 */
2098
+			$entity_type_id = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT);
2099
+			$language = WPSHOP_CURRENT_LOCALE;
2100
+			$icl_post_language = !empty($_REQUEST['icl_post_language']) ? sanitize_text_field($_REQUEST['icl_post_language']) : '';
2101
+
2102
+			if (!empty($icl_post_language)) {
2103
+				$query = $wpdb->prepare("SELECT locale FROM " . $wpdb->prefix . "icl_locale_map WHERE code = %s", $icl_post_language);
2104
+				$language = $wpdb->get_var($query);
2105
+			}
2139 2106
 
2140
-            /** Met à jour la meta _wps_price_infos */
2141
-            $p = wpshop_products::get_product_data($element_id);
2142
-            $price = wpshop_prices::get_product_price($p, 'just_price_infos', array('mini_output', 'grid'));
2143
-            update_post_meta($element_id, '_wps_price_infos', $price);
2107
+			/**
2108
+			 * Vérifie la configuration pour savoir comment calculer les prix pour le produit /
2109
+			 * Check configuration to know how to make the calcul for the product
2110
+			 */
2111
+			if (WPSHOP_PRODUCT_PRICE_PILOT == 'HT') {
2112
+				$price_with_vat = ($base_price * $divider_price_ttc);
2113
+				$price_no_vat = $base_price;
2114
+			} else if (WPSHOP_PRODUCT_PRICE_PILOT == 'TTC') {
2115
+				$price_with_vat = $base_price;
2116
+				$price_no_vat = ($price_with_vat / $divider_price_ttc);
2117
+			}
2144 2118
 
2145
-            /** Met à jour la meta _wpshop_displayed_price */
2146
-            wps_filter_search::save_displayed_price_meta($element_id);
2147
-        }
2119
+			/**
2120
+			 * Le dernier paramètre permet de ne pas supprimer les attributs du même
2121
+			 * type que celui-ci / The last parameter allows not to delete the
2122
+			 * attributes of the same type as this one
2123
+			 */
2124
+			wpshop_attributes::saveAttributeForEntity(array('decimal' => array('product_price' => $price_with_vat)), $entity_type_id, $element_id, $language, 'wpshop_products');
2125
+			wpshop_attributes::saveAttributeForEntity(array('decimal' => array('price_ht' => $price_no_vat)), $entity_type_id, $element_id, $language, 'wpshop_product');
2126
+
2127
+			/** Ajout ou met à jour de l'attribut tva / Add or update the attribute vat */
2128
+			$vat_amount = $price_with_vat - $price_no_vat;
2129
+			wpshop_attributes::saveAttributeForEntity(array('decimal' => array('tva' => $vat_amount)), $entity_type_id, $element_id, $language, 'wpshop_product');
2130
+
2131
+			/**    Update the product meta information with the calculated prices    */
2132
+			$product_postmeta = get_post_meta($element_id, WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, true);
2133
+			$product_postmeta[WPSHOP_PRODUCT_PRICE_TTC] = number_format(round($price_with_vat, 5), 5, '.', '');
2134
+			$product_postmeta[WPSHOP_PRODUCT_PRICE_HT] = number_format(round($price_no_vat, 5), 5, '.', '');
2135
+			$product_postmeta[WPSHOP_PRODUCT_PRICE_TAX_AMOUNT] = number_format(round($vat_amount, 5), 5, '.', '');
2136
+			$product_postmeta[WPSHOP_PRODUCT_PRICE_TAX] = $rate_vat->id;
2137
+
2138
+			update_post_meta($element_id, WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, $product_postmeta);
2139
+
2140
+			/** Met à jour la meta _wps_price_infos */
2141
+			$p = wpshop_products::get_product_data($element_id);
2142
+			$price = wpshop_prices::get_product_price($p, 'just_price_infos', array('mini_output', 'grid'));
2143
+			update_post_meta($element_id, '_wps_price_infos', $price);
2144
+
2145
+			/** Met à jour la meta _wpshop_displayed_price */
2146
+			wps_filter_search::save_displayed_price_meta($element_id);
2147
+		}
2148 2148
 
2149
-        return true;
2150
-    }
2149
+		return true;
2150
+	}
2151 2151
 
2152
-    /**
2153
-     * Allows to get the good button for adding product to cart
2154
-     *
2155
-     * @param integer $product_id The product identifier
2156
-     * @param boolean $productStock If there is the possibility to add the given product to the cart
2157
-     *
2158
-     * @return string $button The html output for the button
2159
-     */
2160
-    public static function display_add_to_cart_button($product_id, $productStock, $output_type = 'mini')
2161
-    {
2162
-        $button = '';
2152
+	/**
2153
+	 * Allows to get the good button for adding product to cart
2154
+	 *
2155
+	 * @param integer $product_id The product identifier
2156
+	 * @param boolean $productStock If there is the possibility to add the given product to the cart
2157
+	 *
2158
+	 * @return string $button The html output for the button
2159
+	 */
2160
+	public static function display_add_to_cart_button($product_id, $productStock, $output_type = 'mini')
2161
+	{
2162
+		$button = '';
2163 2163
 //         $attributes_frontend_display = get_post_meta( $product_id, '_wpshop_product_attributes_frontend_display', true );
2164 2164
 
2165
-        if (WPSHOP_DEFINED_SHOP_TYPE == 'sale' /*&& ( empty($attributes_frontend_display) || ( !empty($attributes_frontend_display) && !empty($attributes_frontend_display['product_action_button']) && !empty($attributes_frontend_display['product_action_button']['mini_output']) && $output_type == 'mini') || ( !empty($attributes_frontend_display) && !empty($attributes_frontend_display['product_action_button']) && !empty($attributes_frontend_display['product_action_button']['complete_sheet']) && $output_type == 'complete') ) */) {
2166
-            /*
2165
+		if (WPSHOP_DEFINED_SHOP_TYPE == 'sale' /*&& ( empty($attributes_frontend_display) || ( !empty($attributes_frontend_display) && !empty($attributes_frontend_display['product_action_button']) && !empty($attributes_frontend_display['product_action_button']['mini_output']) && $output_type == 'mini') || ( !empty($attributes_frontend_display) && !empty($attributes_frontend_display['product_action_button']) && !empty($attributes_frontend_display['product_action_button']['complete_sheet']) && $output_type == 'complete') ) */) {
2166
+			/*
2167 2167
              * Check if current product has variation for button display
2168 2168
              */
2169
-            $variations_exists = get_posts(array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, 'post_parent' => $product_id));
2170
-            $variations_list = (!empty($variations_exists) && is_array(wpshop_attributes::get_attribute_user_defined(array('entity_type_id' => self::currentPageCode)))) ? true : false;
2169
+			$variations_exists = get_posts(array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, 'post_parent' => $product_id));
2170
+			$variations_list = (!empty($variations_exists) && is_array(wpshop_attributes::get_attribute_user_defined(array('entity_type_id' => self::currentPageCode)))) ? true : false;
2171 2171
 
2172
-            /*
2172
+			/*
2173 2173
              * Template parameters
2174 2174
              */
2175 2175
 
2176
-            if (get_post_type($product_id) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT) {
2177
-                /** Check variation stock **/
2178
-                $variations = self::get_variation($product_id);
2179
-                if (!empty($variations)) {
2180
-                    foreach ($variations as $variation) {
2181
-                        if (!empty($variation) && !empty($variation['variation_dif']) && !empty($variation['variation_dif']['product_stock'])) {
2182
-                            $productStock += $variation['variation_dif']['product_stock'];
2183
-                        }
2184
-                    }
2185
-                }
2186
-            }
2187
-
2188
-            $template_part = ($variations_list && ($output_type == 'mini')) ? 'configure_product_button' : (!empty($productStock) ? 'add_to_cart_button' : 'unavailable_product_button');
2176
+			if (get_post_type($product_id) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT) {
2177
+				/** Check variation stock **/
2178
+				$variations = self::get_variation($product_id);
2179
+				if (!empty($variations)) {
2180
+					foreach ($variations as $variation) {
2181
+						if (!empty($variation) && !empty($variation['variation_dif']) && !empty($variation['variation_dif']['product_stock'])) {
2182
+							$productStock += $variation['variation_dif']['product_stock'];
2183
+						}
2184
+					}
2185
+				}
2186
+			}
2187
+
2188
+			$template_part = ($variations_list && ($output_type == 'mini')) ? 'configure_product_button' : (!empty($productStock) ? 'add_to_cart_button' : 'unavailable_product_button');
2189 2189
 						$template_part = apply_filters( 'wps_custom_add_to_cart_button', $template_part, $product_id );
2190 2190
 
2191
-            $tpl_component = array();
2192
-            $tpl_component['PRODUCT_ID'] = $product_id;
2193
-            $tpl_component['PRODUCT_PERMALINK'] = get_permalink($product_id);
2194
-            $tpl_component['PRODUCT_TITLE'] = get_the_title($product_id);
2191
+			$tpl_component = array();
2192
+			$tpl_component['PRODUCT_ID'] = $product_id;
2193
+			$tpl_component['PRODUCT_PERMALINK'] = get_permalink($product_id);
2194
+			$tpl_component['PRODUCT_TITLE'] = get_the_title($product_id);
2195 2195
 
2196
-            /*
2196
+			/*
2197 2197
              * Build template
2198 2198
              */
2199
-            $tpl_way_to_take = wpshop_display::check_way_for_template($template_part);
2200
-            if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) {
2201
-                /*    Include the old way template part    */
2202
-                ob_start();
2203
-                require wpshop_display::get_template_file($tpl_way_to_take[1]);
2204
-                $button = ob_get_contents();
2205
-                ob_end_clean();
2206
-            } else {
2207
-                $button = wpshop_display::display_template_element($template_part, $tpl_component, array(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT => $product_id, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . 'output_type' => $output_type));
2208
-            }
2209
-            unset($tpl_component);
2210
-        }
2211
-        return $button;
2212
-    }
2213
-
2214
-    /**
2215
-     * Allows to get the good button for adding product to a quotation
2216
-     *
2217
-     * @param integer $product_id The product identifier
2218
-     * @param boolean $product_quotation_state The state of the quotation addons
2219
-     *
2220
-     * @return string $button The html output for the button
2221
-     */
2222
-    public static function display_quotation_button($product_id, $product_quotation_state, $output_type = 'mini')
2223
-    {
2224
-        $quotation_button = '';
2225
-
2226
-        if (WPSHOP_ADDONS_QUOTATION && (!empty($product_quotation_state) && strtolower(__($product_quotation_state, 'wpshop')) == strtolower(__('Yes', 'wpshop'))) && (empty($_SESSION['cart']['cart_type']) || ($_SESSION['cart']['cart_type'] == 'quotation'))) {
2227
-            $variations_list = (is_array(wpshop_products::get_variation($product_id)) && is_array(wpshop_attributes::get_attribute_user_defined(array('entity_type_id' => self::currentPageCode)))) ? array_merge(wpshop_products::get_variation($product_id), wpshop_attributes::get_attribute_user_defined(array('entity_type_id' => self::currentPageCode))) : array();
2228
-            /**
2229
-             * Template parameters
2230
-             */
2231
-            $template_part = (!empty($variations_list) && ($output_type == 'mini')) ? 'configure_quotation_button' : 'ask_quotation_button';
2232
-            $tpl_component = array();
2233
-            $tpl_component['PRODUCT_ID'] = $product_id;
2234
-            $tpl_component['PRODUCT_PERMALINK'] = get_permalink($product_id);
2235
-            $tpl_component['PRODUCT_TITLE'] = get_the_title($product_id);
2199
+			$tpl_way_to_take = wpshop_display::check_way_for_template($template_part);
2200
+			if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) {
2201
+				/*    Include the old way template part    */
2202
+				ob_start();
2203
+				require wpshop_display::get_template_file($tpl_way_to_take[1]);
2204
+				$button = ob_get_contents();
2205
+				ob_end_clean();
2206
+			} else {
2207
+				$button = wpshop_display::display_template_element($template_part, $tpl_component, array(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT => $product_id, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . 'output_type' => $output_type));
2208
+			}
2209
+			unset($tpl_component);
2210
+		}
2211
+		return $button;
2212
+	}
2236 2213
 
2237
-            /**
2238
-             * Build template
2239
-             */
2240
-            $tpl_way_to_take = wpshop_display::check_way_for_template($template_part);
2241
-            if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) {
2242
-                /*    Include the old way template part    */
2243
-                ob_start();
2244
-                require wpshop_display::get_template_file($tpl_way_to_take[1]);
2245
-                $quotation_button = ob_get_contents();
2246
-                ob_end_clean();
2247
-            } else {
2248
-                $quotation_button = wpshop_display::display_template_element($template_part, $tpl_component);
2249
-            }
2250
-            unset($tpl_component);
2251
-        }
2214
+	/**
2215
+	 * Allows to get the good button for adding product to a quotation
2216
+	 *
2217
+	 * @param integer $product_id The product identifier
2218
+	 * @param boolean $product_quotation_state The state of the quotation addons
2219
+	 *
2220
+	 * @return string $button The html output for the button
2221
+	 */
2222
+	public static function display_quotation_button($product_id, $product_quotation_state, $output_type = 'mini')
2223
+	{
2224
+		$quotation_button = '';
2225
+
2226
+		if (WPSHOP_ADDONS_QUOTATION && (!empty($product_quotation_state) && strtolower(__($product_quotation_state, 'wpshop')) == strtolower(__('Yes', 'wpshop'))) && (empty($_SESSION['cart']['cart_type']) || ($_SESSION['cart']['cart_type'] == 'quotation'))) {
2227
+			$variations_list = (is_array(wpshop_products::get_variation($product_id)) && is_array(wpshop_attributes::get_attribute_user_defined(array('entity_type_id' => self::currentPageCode)))) ? array_merge(wpshop_products::get_variation($product_id), wpshop_attributes::get_attribute_user_defined(array('entity_type_id' => self::currentPageCode))) : array();
2228
+			/**
2229
+			 * Template parameters
2230
+			 */
2231
+			$template_part = (!empty($variations_list) && ($output_type == 'mini')) ? 'configure_quotation_button' : 'ask_quotation_button';
2232
+			$tpl_component = array();
2233
+			$tpl_component['PRODUCT_ID'] = $product_id;
2234
+			$tpl_component['PRODUCT_PERMALINK'] = get_permalink($product_id);
2235
+			$tpl_component['PRODUCT_TITLE'] = get_the_title($product_id);
2236
+
2237
+			/**
2238
+			 * Build template
2239
+			 */
2240
+			$tpl_way_to_take = wpshop_display::check_way_for_template($template_part);
2241
+			if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) {
2242
+				/*    Include the old way template part    */
2243
+				ob_start();
2244
+				require wpshop_display::get_template_file($tpl_way_to_take[1]);
2245
+				$quotation_button = ob_get_contents();
2246
+				ob_end_clean();
2247
+			} else {
2248
+				$quotation_button = wpshop_display::display_template_element($template_part, $tpl_component);
2249
+			}
2250
+			unset($tpl_component);
2251
+		}
2252 2252
 
2253
-        return $quotation_button;
2254
-    }
2253
+		return $quotation_button;
2254
+	}
2255 2255
 
2256
-    /**
2257
-     * Return the output for a product attachement gallery (picture or document)
2258
-     *
2259
-     * @param string $attachement_type The type of attachement to output. allows to define with type of template to take
2260
-     * @param string $content The gallery content build previously
2261
-     *
2262
-     * @return string The attachement gallery output
2263
-     */
2264
-    public static function display_attachment_gallery($attachement_type, $content)
2265
-    {
2266
-        $galery_output = '';
2267
-
2268
-        /*
2256
+	/**
2257
+	 * Return the output for a product attachement gallery (picture or document)
2258
+	 *
2259
+	 * @param string $attachement_type The type of attachement to output. allows to define with type of template to take
2260
+	 * @param string $content The gallery content build previously
2261
+	 *
2262
+	 * @return string The attachement gallery output
2263
+	 */
2264
+	public static function display_attachment_gallery($attachement_type, $content)
2265
+	{
2266
+		$galery_output = '';
2267
+
2268
+		/*
2269 2269
          * Get the template part for given galery type
2270 2270
          */
2271
-        switch ($attachement_type) {
2272
-            case 'picture':
2273
-                $template_part = 'product_attachment_picture_galery';
2274
-                break;
2275
-            case 'document':
2276
-                $template_part = 'product_attachment_galery';
2277
-                break;
2278
-        }
2271
+		switch ($attachement_type) {
2272
+			case 'picture':
2273
+				$template_part = 'product_attachment_picture_galery';
2274
+				break;
2275
+			case 'document':
2276
+				$template_part = 'product_attachment_galery';
2277
+				break;
2278
+		}
2279 2279
 
2280
-        /*
2280
+		/*
2281 2281
          * Template parameters
2282 2282
          */
2283
-        $tpl_component = array();
2284
-        $tpl_component['PRODUCT_ATTACHMENT_OUTPUT_CONTENT'] = $content;
2285
-        $tpl_component['ATTACHMENT_ITEM_TYPE'] = $attachement_type;
2283
+		$tpl_component = array();
2284
+		$tpl_component['PRODUCT_ATTACHMENT_OUTPUT_CONTENT'] = $content;
2285
+		$tpl_component['ATTACHMENT_ITEM_TYPE'] = $attachement_type;
2286 2286
 
2287
-        /*
2287
+		/*
2288 2288
          * Build template
2289 2289
          */
2290
-        $tpl_way_to_take = wpshop_display::check_way_for_template($template_part);
2291
-        if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) {
2292
-            /*    Include the old way template part    */
2293
-            ob_start();
2294
-            require wpshop_display::get_template_file($tpl_way_to_take[1]);
2295
-            $galery_output = ob_get_contents();
2296
-            ob_end_clean();
2297
-        } else {
2298
-            $galery_output = wpshop_display::display_template_element($template_part, $tpl_component);
2299
-        }
2300
-        unset($tpl_component);
2290
+		$tpl_way_to_take = wpshop_display::check_way_for_template($template_part);
2291
+		if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) {
2292
+			/*    Include the old way template part    */
2293
+			ob_start();
2294
+			require wpshop_display::get_template_file($tpl_way_to_take[1]);
2295
+			$galery_output = ob_get_contents();
2296
+			ob_end_clean();
2297
+		} else {
2298
+			$galery_output = wpshop_display::display_template_element($template_part, $tpl_component);
2299
+		}
2300
+		unset($tpl_component);
2301 2301
 
2302
-        return $galery_output;
2303
-    }
2302
+		return $galery_output;
2303
+	}
2304 2304
 
2305
-    /**
2306
-     * Define the metabox to display in product edition page in backend
2307
-     * @param object $post The current element displayed for edition
2308
-     */
2309
-    public static function meta_box_variations($post)
2310
-    {
2311
-        $output = '';
2312
-        /*    Variations container    */
2313
-        $tpl_component = array();
2314
-        $tpl_component['ADMIN_VARIATION_CONTAINER'] = self::display_variation_admin($post->ID);
2315
-        $tpl_component['LINK_NEW_INTERFACE'] = wp_nonce_url(get_edit_post_link($post->ID) . '&wps_variation_interface=true', 'wps_remove_variation_interface');
2316
-        $output .= wpshop_display::display_template_element('wpshop_admin_variation_metabox', $tpl_component, array(), 'admin');
2317
-        echo '<span class="wpshop_loading_ wpshopHide" ><img src="' . admin_url('images/loading.gif') . '" alt="loading picture" /></span>' . $output . '<div class="wpshop_cls" ></div>';
2318
-    }
2305
+	/**
2306
+	 * Define the metabox to display in product edition page in backend
2307
+	 * @param object $post The current element displayed for edition
2308
+	 */
2309
+	public static function meta_box_variations($post)
2310
+	{
2311
+		$output = '';
2312
+		/*    Variations container    */
2313
+		$tpl_component = array();
2314
+		$tpl_component['ADMIN_VARIATION_CONTAINER'] = self::display_variation_admin($post->ID);
2315
+		$tpl_component['LINK_NEW_INTERFACE'] = wp_nonce_url(get_edit_post_link($post->ID) . '&wps_variation_interface=true', 'wps_remove_variation_interface');
2316
+		$output .= wpshop_display::display_template_element('wpshop_admin_variation_metabox', $tpl_component, array(), 'admin');
2317
+		echo '<span class="wpshop_loading_ wpshopHide" ><img src="' . admin_url('images/loading.gif') . '" alt="loading picture" /></span>' . $output . '<div class="wpshop_cls" ></div>';
2318
+	}
2319 2319
 
2320
-    /**
2321
-     * Call variation creation function with a list of defined variation
2322
-     *
2323
-     * @param array $possible_variations A list of variation to create for the current element
2324
-     * @param integer $element_id The product we want to create variation for
2325
-     *
2326
-     * @return mixed The last created variation identifier
2327
-     */
2328
-    public static function creation_variation_callback($possible_variations, $element_id)
2329
-    {
2330
-        /** Get existing variation    */
2331
-        $existing_variations_in_db = wpshop_products::get_variation($element_id);
2332
-        $existing_variations = array();
2333
-        if (!empty($existing_variations_in_db)) {
2334
-            foreach ($existing_variations_in_db as $variations_def) {
2335
-                $existing_variations[] = $variations_def['variation_def'];
2336
-            }
2337
-        }
2338
-        /** New variation definition    */
2339
-        $attribute_defining_variation = get_post_meta($element_id, '_wpshop_variation_defining', true);
2340
-
2341
-        /**    Read possible values    */
2342
-        foreach ($possible_variations as $variation_definition) {
2343
-            if (in_array($variation_definition, $existing_variations)) {
2344
-                continue;
2345
-            }
2346
-
2347
-            $attribute_to_set = array();
2348
-            foreach ($variation_definition as $attribute_code => $attribute_selected_value) {
2349
-                $attribute = wpshop_attributes::getElement($attribute_code, "'valid'", 'code');
2350
-                $attribute_to_set[$attribute->data_type][$attribute_code] = $attribute_selected_value;
2351
-                if (empty($attribute_defining_variation['attributes']) || (!in_array($attribute_code, $attribute_defining_variation['attributes']))) {
2352
-                    $attribute_defining_variation['attributes'][] = $attribute_code;
2353
-                }
2354
-            }
2355
-            $variation_id = wpshop_products::create_variation($element_id, $attribute_to_set);
2356
-        }
2357
-        update_post_meta($element_id, '_wpshop_variation_defining', $attribute_defining_variation);
2320
+	/**
2321
+	 * Call variation creation function with a list of defined variation
2322
+	 *
2323
+	 * @param array $possible_variations A list of variation to create for the current element
2324
+	 * @param integer $element_id The product we want to create variation for
2325
+	 *
2326
+	 * @return mixed The last created variation identifier
2327
+	 */
2328
+	public static function creation_variation_callback($possible_variations, $element_id)
2329
+	{
2330
+		/** Get existing variation    */
2331
+		$existing_variations_in_db = wpshop_products::get_variation($element_id);
2332
+		$existing_variations = array();
2333
+		if (!empty($existing_variations_in_db)) {
2334
+			foreach ($existing_variations_in_db as $variations_def) {
2335
+				$existing_variations[] = $variations_def['variation_def'];
2336
+			}
2337
+		}
2338
+		/** New variation definition    */
2339
+		$attribute_defining_variation = get_post_meta($element_id, '_wpshop_variation_defining', true);
2358 2340
 
2359
-        return !empty($variation_id) ? $variation_id : 0;
2360
-    }
2341
+		/**    Read possible values    */
2342
+		foreach ($possible_variations as $variation_definition) {
2343
+			if (in_array($variation_definition, $existing_variations)) {
2344
+				continue;
2345
+			}
2361 2346
 
2362
-    /**
2363
-     * Create a new variation for product
2364
-     *
2365
-     * @param integer $head_product The product identifier to create the new variation for
2366
-     * @param array $variation_attributes Attribute list for the variation
2367
-     *
2368
-     * @return mixed <number, WP_Error> The variation identifier or an error in case the creation was not succesfull
2369
-     */
2370
-    public static function create_variation($head_product, $variation_attributes)
2371
-    {
2372
-        /** Create custom title */
2373
-        $title_variation = "";
2374
-        if (!empty($variation_attributes)) {
2375
-            foreach ($variation_attributes as $type => $array) {
2376
-                if (!empty($array)) {
2377
-                    foreach ($array as $code => $value) {
2378
-                        $title_variation .= " " . $code . " " . $value;
2379
-                    }
2380
-                }
2381
-            }
2382
-        }
2347
+			$attribute_to_set = array();
2348
+			foreach ($variation_definition as $attribute_code => $attribute_selected_value) {
2349
+				$attribute = wpshop_attributes::getElement($attribute_code, "'valid'", 'code');
2350
+				$attribute_to_set[$attribute->data_type][$attribute_code] = $attribute_selected_value;
2351
+				if (empty($attribute_defining_variation['attributes']) || (!in_array($attribute_code, $attribute_defining_variation['attributes']))) {
2352
+					$attribute_defining_variation['attributes'][] = $attribute_code;
2353
+				}
2354
+			}
2355
+			$variation_id = wpshop_products::create_variation($element_id, $attribute_to_set);
2356
+		}
2357
+		update_post_meta($element_id, '_wpshop_variation_defining', $attribute_defining_variation);
2383 2358
 
2384
-        $variation = array(
2385
-            'post_title' => sprintf(__('Product %s variation %s', 'wpshop'), $head_product, get_the_title($head_product)) . $title_variation,
2386
-            'post_content' => '',
2387
-            'post_status' => 'publish',
2388
-            'post_author' => get_current_user_id(),
2389
-            'post_parent' => $head_product,
2390
-            'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION,
2391
-        );
2392
-        $variation_id = wp_insert_post($variation);
2393
-
2394
-        wpshop_attributes::saveAttributeForEntity($variation_attributes, wpshop_entities::get_entity_identifier_from_code(wpshop_products::currentPageCode), $variation_id, WPSHOP_CURRENT_LOCALE, '');
2395
-
2396
-        /*    Update product price looking for shop parameters    */
2397
-        wpshop_products::calculate_price($variation_id);
2398
-
2399
-        /*    Save the attributes values into wordpress post metadata database in order to have a backup and to make frontend search working    */
2400
-        $productMetaDatas = array();
2401
-        foreach ($variation_attributes as $attributeType => $attributeValues) {
2402
-            foreach ($attributeValues as $attributeCode => $attributeValue) {
2403
-                if (!empty($attributeValue)) {
2404
-                    $productMetaDatas[$attributeCode] = $attributeValue;
2405
-                }
2406
-            }
2407
-        }
2408
-        update_post_meta($variation_id, '_wpshop_variations_attribute_def', $productMetaDatas);
2409
-        update_post_meta($variation_id, WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, $productMetaDatas);
2410
-        update_post_meta($variation_id, WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, get_post_meta($head_product, WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, true));
2359
+		return !empty($variation_id) ? $variation_id : 0;
2360
+	}
2411 2361
 
2412
-        return $variation_id;
2413
-    }
2362
+	/**
2363
+	 * Create a new variation for product
2364
+	 *
2365
+	 * @param integer $head_product The product identifier to create the new variation for
2366
+	 * @param array $variation_attributes Attribute list for the variation
2367
+	 *
2368
+	 * @return mixed <number, WP_Error> The variation identifier or an error in case the creation was not succesfull
2369
+	 */
2370
+	public static function create_variation($head_product, $variation_attributes)
2371
+	{
2372
+		/** Create custom title */
2373
+		$title_variation = "";
2374
+		if (!empty($variation_attributes)) {
2375
+			foreach ($variation_attributes as $type => $array) {
2376
+				if (!empty($array)) {
2377
+					foreach ($array as $code => $value) {
2378
+						$title_variation .= " " . $code . " " . $value;
2379
+					}
2380
+				}
2381
+			}
2382
+		}
2414 2383
 
2415
-    /**
2416
-     * Get variation list for a given product
2417
-     *
2418
-     * @param integer $head_product The product identifier to get the variation for
2419
-     * @return object The variation list
2420
-     */
2421
-    public static function get_variation($head_product, $type = 'any')
2422
-    {
2423
-        global $wpdb;
2424
-        $variations_output = null;
2425
-        $args = array(
2426
-            'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION,
2427
-            'post_parent' => $head_product,
2428
-            'orderby' => 'ID',
2429
-            'order' => 'ASC',
2430
-            'posts_per_page' => -1,
2431
-            'post_status' => $type,
2432
-        );
2433
-        $variations = get_posts($args);
2434
-
2435
-        if (!empty($variations)) {
2436
-            $head_wpshop_variation_definition = get_post_meta($head_product, '_wpshop_variation_defining', true);
2437
-
2438
-            foreach ($variations as $post_def) {
2439
-                $data = wpshop_attributes::get_attribute_list_for_item(wpshop_entities::get_entity_identifier_from_code(self::currentPageCode), $post_def->ID, WPSHOP_CURRENT_LOCALE, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, "'valid', 'deleted'");
2440
-                foreach ($data as $content) {
2441
-                    $attribute_value = 'attribute_value_' . $content->data_type;
2442
-                    if (!empty($content->$attribute_value)) {
2443
-                        if (!empty($head_wpshop_variation_definition['attributes']) && in_array($content->code, $head_wpshop_variation_definition['attributes'])) {
2444
-                            $variations_output[$post_def->ID]['variation_def'][$content->code] = $content->$attribute_value;
2445
-                        } else {
2446
-                            $variations_output[$post_def->ID]['variation_dif'][$content->code] = $content->$attribute_value;
2447
-                        }
2448
-                    }
2449
-                }
2450
-                $variations_output[$post_def->ID]['post'] = $post_def;
2451
-            }
2452
-        }
2453
-        wp_reset_query();
2454
-        return $variations_output;
2455
-    }
2384
+		$variation = array(
2385
+			'post_title' => sprintf(__('Product %s variation %s', 'wpshop'), $head_product, get_the_title($head_product)) . $title_variation,
2386
+			'post_content' => '',
2387
+			'post_status' => 'publish',
2388
+			'post_author' => get_current_user_id(),
2389
+			'post_parent' => $head_product,
2390
+			'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION,
2391
+		);
2392
+		$variation_id = wp_insert_post($variation);
2393
+
2394
+		wpshop_attributes::saveAttributeForEntity($variation_attributes, wpshop_entities::get_entity_identifier_from_code(wpshop_products::currentPageCode), $variation_id, WPSHOP_CURRENT_LOCALE, '');
2395
+
2396
+		/*    Update product price looking for shop parameters    */
2397
+		wpshop_products::calculate_price($variation_id);
2398
+
2399
+		/*    Save the attributes values into wordpress post metadata database in order to have a backup and to make frontend search working    */
2400
+		$productMetaDatas = array();
2401
+		foreach ($variation_attributes as $attributeType => $attributeValues) {
2402
+			foreach ($attributeValues as $attributeCode => $attributeValue) {
2403
+				if (!empty($attributeValue)) {
2404
+					$productMetaDatas[$attributeCode] = $attributeValue;
2405
+				}
2406
+			}
2407
+		}
2408
+		update_post_meta($variation_id, '_wpshop_variations_attribute_def', $productMetaDatas);
2409
+		update_post_meta($variation_id, WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, $productMetaDatas);
2410
+		update_post_meta($variation_id, WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, get_post_meta($head_product, WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, true));
2456 2411
 
2457
-    /**
2458
-     * Affichage des variations d'un produit dans l'administration
2459
-     *
2460
-     * @param integer $head_product L'identifiant du produit dont on veut afficher les variations
2461
-     * @return string Le code html permettant l'affichage des variations dans l'interface d'édition du produit
2462
-     */
2463
-    public static function display_variation_admin($head_product)
2464
-    {
2465
-        $output = '';
2466
-        $productCurrency = wpshop_tools::wpshop_get_currency();
2467
-        /*    Récupération de la liste des variations pour le produit en cours d'édition    */
2468
-        $variations = self::get_variation($head_product);
2469
-        $price_piloting = get_option('wpshop_shop_price_piloting');
2470
-
2471
-        /*    Affichage de la liste des variations pour le produit en cours d'édition    */
2472
-        if (!empty($variations) && is_array($variations)) {
2473
-            $existing_variation_list = wpshop_display::display_template_element('wpshop_admin_existing_variation_controller', array(), array(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT => $head_product), 'admin');
2474
-
2475
-            foreach ($variations as $variation) {
2476
-                $tpl_component = array();
2477
-
2478
-                $tpl_component['ADMIN_EXISTING_VARIATIONS_CLASS'] = ' wpshop_variation_' . self::currentPageCode;
2479
-                $tpl_component['VARIATION_IDENTIFIER'] = $variation['post']->ID;
2480
-                $tpl_component['VARIATION_DETAIL'] = '  ';
2481
-                $p = (!empty($variation['variation_dif']['product_price']) || !empty($variation['variation_dif']['price_ht'])) ? ((!empty($price_piloting) && $price_piloting == 'HT' && !empty($variation['variation_dif']['price_ht'])) ? $variation['variation_dif']['price_ht'] : (!empty($variation['variation_dif']['product_price'])) ? $variation['variation_dif']['product_price'] : 0) : 0;
2482
-                $tpl_component['VARIATION_DETAIL_PRICE'] = number_format($p, 2, '.', '') . ' ' . $productCurrency . ' ' . ((!empty($price_piloting) && $price_piloting == 'HT') ? __('ET', 'wpshop') : __('ATI', 'wpshop'));
2483
-                if (!empty($price_piloting) && $price_piloting == 'HT') {
2484
-
2485
-                } else {
2486
-
2487
-                }
2488
-                $post_obj = $variation['post'];
2489
-
2490
-                $parent_product_infos = wpshop_products::get_parent_variation($post_obj->ID);
2491
-                if (!empty($parent_product_infos)) {
2492
-                    $parent_post = $parent_product_infos['parent_post'];
2493
-                    $product_option_postmeta = get_post_meta($parent_post->ID, '_wpshop_variation_defining', true);
2494
-                    if (!empty($product_option_postmeta['options']['price_behaviour']) && !empty($product_option_postmeta['options']['price_behaviour'][0]) && $product_option_postmeta['options']['price_behaviour'][0] == 'addition') {
2495
-                        if (!empty($price_piloting) && $price_piloting == 'HT') {
2496
-                            $product_price = ((!empty($variation['variation_dif']['price_ht'])) ? $variation['variation_dif']['price_ht'] : 0) + $parent_product_infos['parent_post_meta']['price_ht'];
2497
-                        } else {
2498
-                            $product_price = ((!empty($variation['variation_dif']['product_price'])) ? $variation['variation_dif']['product_price'] : 0) + $parent_product_infos['parent_post_meta']['product_price'];
2499
-                        }
2500
-                        $tpl_component['VARIATION_DETAIL_SALE_PRICE_INDICATION'] = __('Variation price combined with the parent product price', 'wpshop');
2501
-                    } else {
2502
-                        if (!empty($price_piloting) && $price_piloting == 'HT') {
2503
-                            $product_price = (!empty($variation['variation_dif']['price_ht'])) ? $variation['variation_dif']['price_ht'] : 0;
2504
-                        } else {
2505
-                            $product_price = (!empty($variation['variation_dif']['product_price'])) ? $variation['variation_dif']['product_price'] : 0;
2506
-                        }
2507
-                        $tpl_component['VARIATION_DETAIL_SALE_PRICE_INDICATION'] = __('Only variation\'s price is used', 'wpshop');
2508
-                    }
2509
-                    $product_price = number_format(str_replace(',', '.', $product_price), 2, '.', '') . ' ' . $productCurrency . ' ' . ((!empty($price_piloting) && $price_piloting == 'HT') ? __('ET', 'wpshop') : __('ATI', 'wpshop'));
2510
-                    $tpl_component['VARIATION_DETAIL_SALE_PRICE'] = $product_price;
2511
-                }
2512
-
2513
-                if (!empty($variation['variation_def'])) {
2514
-                    foreach ($variation['variation_def'] as $variation_key => $variation_value) {
2515
-                        if (!empty($variation_value)) {
2516
-                            $attribute_def_for_variation = wpshop_attributes::getElement($variation_key, "'valid'", 'code');
2517
-                            $tpl_component['VARIATION_DETAIL'] .= '<input type="hidden" name="' . self::current_page_variation_code . '[' . $variation['post']->ID . '][attribute][' . $attribute_def_for_variation->data_type . '][' . $variation_key . ']" value="' . $variation_value . '" />' . wpshop_display::display_template_element('wpshop_admin_variation_item_def_header', array('VARIATION_ATTRIBUTE_CODE' => $attribute_def_for_variation->frontend_label, 'VARIATION_ATTRIBUTE_CODE_VALUE' => stripslashes(wpshop_attributes::get_attribute_type_select_option_info($variation_value, 'label', $attribute_def_for_variation->data_type_to_use, true))), array(), 'admin');
2518
-                            $tpl_component['VARIATION_IMAGE_CHOICE'] = '';
2519
-
2520
-                            /** Define Link image to variation interface **/
2521
-                            if (!empty($product_option_postmeta) && !empty($product_option_postmeta['attributes']) && !empty($product_option_postmeta['variation_type']) && ((count($product_option_postmeta['attributes']) == 1 && $product_option_postmeta['variation_type'] == 'single') || ($product_option_postmeta['variation_type'] == 'combined'))) {
2522
-                                $pictures = get_posts(array('post_type' => 'attachment', 'posts_per_page' => -1, 'post_status' => null, 'post_parent' => $head_product));
2523
-
2524
-                                $media_id_data = get_post_meta($head_product, '_wps_product_media', true);
2525
-                                if (!empty($media_id_data)) {
2526
-                                    $medias_ids = explode(',', $media_id_data);
2527
-
2528
-                                    if (!empty($medias_ids)) {
2529
-                                        foreach ($medias_ids as $media_id) {
2530
-                                            if (!empty($media_id)) {
2531
-                                                $pictures[] = get_post($media_id);
2532
-                                            }
2533
-                                        }
2534
-                                    }
2535
-                                }
2536
-
2537
-                                $pictures_data = '';
2538
-                                if (!empty($pictures)) {
2539
-                                    $selected_picture = get_post_meta($variation['post']->ID, '_wps_variation_attached_picture', true);
2540
-
2541
-                                    $done_picture = array();
2542
-                                    foreach ($pictures as $picture) {
2543
-                                        if (!in_array($picture->ID, $done_picture)) {
2544
-                                            if (wp_attachment_is_image($picture->ID)) {
2545
-                                                $checked = ((!empty($selected_picture) && $selected_picture == $picture->ID) ? 'checked="checked"' : '');
2546
-                                                $pictures_data .= wpshop_display::display_template_element('wpshop_admin_variation_picture_choice_element', array('PICTURE_CHOICE_VARIATION_ID' => $picture->ID, 'PRODUCT_VARIATION_ID' => $variation['post']->ID, 'PICTURE_CHOICE_SELECTED' => $checked, 'PICTURE_CHOICE_VARIATION_IMG' => wp_get_attachment_image($picture->ID, 'thumbnail')), array(), 'admin');
2547
-
2548
-                                                $done_picture[] = $picture->ID;
2549
-                                            }
2550
-                                        }
2551
-                                    }
2552
-                                }
2553
-
2554
-                                $tpl_component['VARIATION_IMAGE_CHOICE'] = wpshop_display::display_template_element('wpshop_admin_variation_picture_choice_container', array('PICTURE_CHOICE_CONTAINER_CONTENT' => $pictures_data), array(), 'admin');
2555
-                            }
2556
-
2557
-                        }
2558
-                    }
2559
-                }
2560
-
2561
-                $tpl_component['VARIATION_DETAIL'] = substr($tpl_component['VARIATION_DETAIL'], 0, -2);
2562
-
2563
-                $tpl_component['ADMIN_VARIATION_SPECIFIC_DEFINITION_CONTAINER_CLASS'] = ' wpshopHide';
2564
-                $tpl_component['VARIATION_DEFINITION'] = wpshop_attributes::get_variation_attribute(array('post_id' => $variation['post']->ID, 'input_class' => ' ', 'field_name' => wpshop_products::current_page_variation_code . '[' . $variation['post']->ID . ']', 'page_code' => self::current_page_variation_code, 'field_id' => self::current_page_variation_code . '_' . $variation['post']->ID, 'variation_dif_values' => (!empty($variation['variation_dif']) ? $variation['variation_dif'] : array())));
2565
-                $tpl_component['VARIATION_DEFINITION_CONTENT'] = wpshop_display::display_template_element('wpshop_admin_variation_item_specific_def', $tpl_component, array(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT => $head_product, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION => $variation['post']->ID), 'admin');
2566
-
2567
-                /*    Add the variation definition to output    */
2568
-                $existing_variation_list .= wpshop_display::display_template_element('wpshop_admin_variation_item_def', $tpl_component, array(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT => $head_product, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION => $variation['post']->ID), 'admin');
2569
-            }
2570
-
2571
-            $output .= wpshop_display::display_template_element('wpshop_admin_existing_variation_list', array('ADMIN_EXISTING_VARIATIONS_CONTAINER_CLASS' => '', 'ADMIN_EXISTING_VARIATIONS_CONTAINER' => $existing_variation_list), array(), 'admin');
2572
-            /*    Reset de la liste des résultats pour éviter les comportements indésirables    */
2573
-            wp_reset_query();
2574
-        } else {
2575
-            $output = __('No variation found for this product. Please use button above for create one', 'wpshop');
2576
-        }
2412
+		return $variation_id;
2413
+	}
2577 2414
 
2578
-        return $output;
2579
-    }
2415
+	/**
2416
+	 * Get variation list for a given product
2417
+	 *
2418
+	 * @param integer $head_product The product identifier to get the variation for
2419
+	 * @return object The variation list
2420
+	 */
2421
+	public static function get_variation($head_product, $type = 'any')
2422
+	{
2423
+		global $wpdb;
2424
+		$variations_output = null;
2425
+		$args = array(
2426
+			'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION,
2427
+			'post_parent' => $head_product,
2428
+			'orderby' => 'ID',
2429
+			'order' => 'ASC',
2430
+			'posts_per_page' => -1,
2431
+			'post_status' => $type,
2432
+		);
2433
+		$variations = get_posts($args);
2434
+
2435
+		if (!empty($variations)) {
2436
+			$head_wpshop_variation_definition = get_post_meta($head_product, '_wpshop_variation_defining', true);
2437
+
2438
+			foreach ($variations as $post_def) {
2439
+				$data = wpshop_attributes::get_attribute_list_for_item(wpshop_entities::get_entity_identifier_from_code(self::currentPageCode), $post_def->ID, WPSHOP_CURRENT_LOCALE, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, "'valid', 'deleted'");
2440
+				foreach ($data as $content) {
2441
+					$attribute_value = 'attribute_value_' . $content->data_type;
2442
+					if (!empty($content->$attribute_value)) {
2443
+						if (!empty($head_wpshop_variation_definition['attributes']) && in_array($content->code, $head_wpshop_variation_definition['attributes'])) {
2444
+							$variations_output[$post_def->ID]['variation_def'][$content->code] = $content->$attribute_value;
2445
+						} else {
2446
+							$variations_output[$post_def->ID]['variation_dif'][$content->code] = $content->$attribute_value;
2447
+						}
2448
+					}
2449
+				}
2450
+				$variations_output[$post_def->ID]['post'] = $post_def;
2451
+			}
2452
+		}
2453
+		wp_reset_query();
2454
+		return $variations_output;
2455
+	}
2580 2456
 
2581
-    /**
2582
-     * Retrieve and display the variation for a given product
2583
-     * @param integer $product_id The product identifier to get variation for
2584
-     */
2585
-    public static function wpshop_variation($post_id = '', $from_admin = false, $order_id = '', $qty = 1)
2586
-    {
2587
-        global $wp_query;
2588
-        $output = '';
2589
-
2590
-        $product_id = empty($post_id) ? $wp_query->post->ID : $post_id;
2591
-        $wpshop_product_attributes_frontend_display = get_post_meta($product_id, '_wpshop_product_attributes_frontend_display', true);
2592
-        $head_wpshop_variation_definition = get_post_meta($product_id, '_wpshop_variation_defining', true);
2593
-
2594
-        /**    Get attribute order for current product    */
2595
-        $product_attribute_order_detail = wpshop_attributes_set::getAttributeSetDetails(get_post_meta($product_id, WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, true));
2596
-        $output_order = array();
2597
-        if (count($product_attribute_order_detail) > 0) {
2598
-            if (!empty($product_attribute_order_detail)) {
2599
-                foreach ($product_attribute_order_detail as $product_attr_group_id => $product_attr_group_detail) {
2600
-                    foreach ($product_attr_group_detail['attribut'] as $position => $attribute_def) {
2601
-                        if (!empty($attribute_def->code)) {
2602
-                            $output_order[$attribute_def->code] = $position;
2603
-                        }
2604
-
2605
-                    }
2606
-                }
2607
-            }
2608
-        }
2457
+	/**
2458
+	 * Affichage des variations d'un produit dans l'administration
2459
+	 *
2460
+	 * @param integer $head_product L'identifiant du produit dont on veut afficher les variations
2461
+	 * @return string Le code html permettant l'affichage des variations dans l'interface d'édition du produit
2462
+	 */
2463
+	public static function display_variation_admin($head_product)
2464
+	{
2465
+		$output = '';
2466
+		$productCurrency = wpshop_tools::wpshop_get_currency();
2467
+		/*    Récupération de la liste des variations pour le produit en cours d'édition    */
2468
+		$variations = self::get_variation($head_product);
2469
+		$price_piloting = get_option('wpshop_shop_price_piloting');
2470
+
2471
+		/*    Affichage de la liste des variations pour le produit en cours d'édition    */
2472
+		if (!empty($variations) && is_array($variations)) {
2473
+			$existing_variation_list = wpshop_display::display_template_element('wpshop_admin_existing_variation_controller', array(), array(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT => $head_product), 'admin');
2474
+
2475
+			foreach ($variations as $variation) {
2476
+				$tpl_component = array();
2477
+
2478
+				$tpl_component['ADMIN_EXISTING_VARIATIONS_CLASS'] = ' wpshop_variation_' . self::currentPageCode;
2479
+				$tpl_component['VARIATION_IDENTIFIER'] = $variation['post']->ID;
2480
+				$tpl_component['VARIATION_DETAIL'] = '  ';
2481
+				$p = (!empty($variation['variation_dif']['product_price']) || !empty($variation['variation_dif']['price_ht'])) ? ((!empty($price_piloting) && $price_piloting == 'HT' && !empty($variation['variation_dif']['price_ht'])) ? $variation['variation_dif']['price_ht'] : (!empty($variation['variation_dif']['product_price'])) ? $variation['variation_dif']['product_price'] : 0) : 0;
2482
+				$tpl_component['VARIATION_DETAIL_PRICE'] = number_format($p, 2, '.', '') . ' ' . $productCurrency . ' ' . ((!empty($price_piloting) && $price_piloting == 'HT') ? __('ET', 'wpshop') : __('ATI', 'wpshop'));
2483
+				if (!empty($price_piloting) && $price_piloting == 'HT') {
2484
+
2485
+				} else {
2609 2486
 
2610
-        $variations_params = array();
2611
-        $variation_attribute = array();
2612
-        $variation_attribute_ordered = array();
2613
-        $possible_values = array();
2614
-        $possible_values_for_selection_calculation = array();
2615
-
2616
-        /*    Vérification de l'existence de déclinaison pour le produit    */
2617
-        $wpshop_variation_list = self::get_variation($product_id);
2618
-        if (!empty($wpshop_variation_list)) {
2619
-            foreach ($wpshop_variation_list as $variation) {
2620
-                if (!empty($variation['variation_def'])) {
2621
-                    $display_option = get_post_meta($post_id, '_wpshop_product_attributes_frontend_display', true);
2622
-                    foreach ($variation['variation_def'] as $attribute_code => $attribute_value) {
2623
-                        if (empty($display_option) || (!empty($display_option['attribute']) && !empty($display_option['attribute'][$attribute_code]) && !empty($display_option['attribute'][$attribute_code]['complete_sheet']))) {
2624
-                            $tpl_component = array();
2625
-
2626
-                            $attribute_db_definition = wpshop_attributes::getElement($attribute_code, "'valid'", 'code');
2627
-                            $default_value_is_serial = false;
2628
-                            $attribute_list_first_element = $attribute_db_definition->default_value;
2629
-                            if (!empty($attribute_db_definition->default_value) && ($attribute_db_definition->default_value == serialize(false) || wpshop_tools::is_serialized($attribute_db_definition->default_value))) {
2630
-                                $default_value_is_serial = true;
2631
-                                $tmp_default_value = unserialize($attribute_db_definition->default_value);
2632
-                                $attribute_list_first_element = !empty($tmp_default_value['field_options']['label_for_first_item']) ? $tmp_default_value['field_options']['label_for_first_item'] : null;
2633
-                            }
2634
-
2635
-                            if ($default_value_is_serial && !empty($attribute_list_first_element) && ($attribute_list_first_element != 'none')) {
2636
-                                $possible_values[$attribute_code][0][0] = ($default_value_is_serial && !empty($attribute_list_first_element) && ($attribute_list_first_element != 'none')) ? stripslashes(sprintf($attribute_list_first_element, strtolower($attribute_db_definition->frontend_label))) : __('Choose a value', 'wpshop');
2637
-                            }
2638
-
2639
-                            if (!empty($attribute_value) && ($attribute_db_definition->data_type_to_use == 'custom')) {
2640
-                                $tpl_component['VARIATION_VALUE'] = stripslashes(wpshop_attributes::get_attribute_type_select_option_info($attribute_value, 'label', 'custom'));
2641
-                                $position = wpshop_attributes::get_attribute_type_select_option_info($attribute_value, 'position', 'custom');
2642
-                            } else if (!empty($attribute_value) && ($attribute_db_definition->data_type_to_use == 'internal')) {
2643
-                                $post_def = get_post($attribute_value);
2644
-                                $tpl_component['VARIATION_VALUE'] = stripslashes($post_def->post_title);
2645
-                                $position = $post_def->menu_order;
2646
-                            }
2647
-
2648
-                            if (!empty($variation['variation_dif'])) {
2649
-                                foreach ($variation['variation_dif'] as $attribute_dif_code => $attribute_dif_value) {
2650
-                                    $wpshop_prices_attributes = unserialize(WPSHOP_ATTRIBUTE_PRICES);
2651
-                                    $the_value = $attribute_dif_value;
2652
-                                    if (in_array($attribute_dif_code, $wpshop_prices_attributes)) {
2653
-                                        $the_value = wpshop_display::format_field_output('wpshop_product_price', $attribute_dif_value);
2654
-                                    }
2655
-                                    $tpl_component['VARIATION_DIF_' . strtoupper($attribute_dif_code)] = stripslashes($the_value);
2656
-                                }
2657
-                            }
2658
-                            if (!empty($attribute_value)) {
2659
-                                $possible_values[$attribute_code][$position][$attribute_value] = wpshop_display::display_template_element('product_variation_item_possible_values', $tpl_component, array('type' => 'attribute_for_variation', 'id' => $attribute_code));
2660
-                                $possible_values_for_selection_calculation[$attribute_code][$attribute_value] = $tpl_component['VARIATION_VALUE'];
2661
-                            }
2662
-                            unset($tpl_component);
2663
-                        }
2664
-                    }
2665
-                }
2666
-            }
2667
-
2668
-            $variation_tpl = array();
2669
-            if (!empty($head_wpshop_variation_definition['attributes'])) {
2670
-                foreach ($head_wpshop_variation_definition['attributes'] as $attribute_code) {
2671
-                    $attribute_db_definition = wpshop_attributes::getElement($attribute_code, "'valid'", 'code');
2672
-
2673
-                    if (!empty($attribute_db_definition)) {
2674
-                        $attribute_display_state = wpshop_attributes::check_attribute_display($attribute_db_definition->is_visible_in_front, $wpshop_product_attributes_frontend_display, 'attribute', $attribute_code, 'complete_sheet');
2675
-
2676
-                        $is_required = ((!empty($head_wpshop_variation_definition['options']) && !empty($head_wpshop_variation_definition['options']['required_attributes']) && (in_array($attribute_code, $head_wpshop_variation_definition['options']['required_attributes'])))) ? true : false;
2677
-                        if (!$is_required && $attribute_db_definition->is_required == 'yes') {
2678
-                            $is_required = true;
2679
-                        }
2680
-
2681
-                        $input_def = array();
2682
-                        $input_def['type'] = $attribute_db_definition->frontend_input;
2683
-                        $value = isset($head_wpshop_variation_definition['options']['attributes_default_value'][$attribute_code]) ? $head_wpshop_variation_definition['options']['attributes_default_value'][$attribute_code] : (!empty($attribute_db_definition->default_value) ? $attribute_db_definition->default_value : null);
2684
-                        if (in_array($attribute_db_definition->frontend_input, array('radio', 'checkbox'))) {
2685
-                            unset($possible_values[$attribute_code][0]);
2686
-                            $value = array($value);
2687
-                        }
2688
-                        $input_def['id'] = 'wpshop_variation_attr_' . $attribute_code;
2689
-                        $input_def['name'] = $attribute_code;
2690
-                        $real_possible_values = array();
2691
-                        if (!empty($possible_values[$attribute_code])) {
2692
-                            ksort($possible_values[$attribute_code]);
2693
-                            foreach ($possible_values[$attribute_code] as $position => $def) {
2694
-                                foreach ($def as $attribute_value => $attribute_value_output) {
2695
-                                    $real_possible_values[$attribute_value] = $attribute_value_output;
2696
-                                    if (!empty($attribute_value)) {
2697
-                                        global $wpdb;
2698
-                                        $query = $wpdb->prepare("SELECT post_status FROM " . $wpdb->postmeta . " AS P_META INNER JOIN " . $wpdb->posts . " as P ON ((P.ID = P_META.post_id) AND (P.post_parent = %d)) WHERE P_META.meta_value LIKE '%%" . serialize($attribute_code) . serialize($attribute_value) . "%%'", $product_id);
2699
-                                        if ('draft' == $wpdb->get_var($query)) {
2700
-                                            unset($real_possible_values[$attribute_value]);
2701
-                                        }
2702
-                                    }
2703
-                                }
2704
-                            }
2705
-                        }
2706
-                        $input_def['possible_value'] = $real_possible_values;
2707
-                        $input_def['valueToPut'] = 'index';
2708
-                        $input_def['value'] = $value;
2709
-
2710
-                        $input_def['options']['more_input'] = '';
2711
-                        if (!empty($possible_values_for_selection_calculation[$attribute_code])) {
2712
-                            foreach ($possible_values_for_selection_calculation[$attribute_code] as $value_id => $value) {
2713
-                                $input_def['options']['more_input'] .= '<input type="hidden" disabled="disabled" value="' . str_replace("\\", "", $value) . '" name="' . $input_def['id'] . '_current_value" id="' . $input_def['id'] . '_current_value_' . $value_id . '" />';
2714
-                            }
2715
-                        }
2716
-
2717
-                        $input_def['options_label']['original'] = true;
2718
-                        $input_def['option'] = 'data-nonce="' . wp_create_nonce('wpshop_ajax_wpshop_variation_selection') . '" class="wpshop_variation_selector_input' . ($is_required ? ' attribute_is_required_input attribute_is_required_input_' . $attribute_code . ' ' : '') . ($attribute_db_definition->_display_informations_about_value == 'yes' ? ' wpshop_display_information_about_value' : '') . ' ' . ((is_admin()) ? $attribute_db_definition->backend_css_class : $attribute_db_definition->frontend_css_class) . '" ';
2719
-
2720
-                        if (!empty($real_possible_values)) {
2721
-                            $tpl_component = array();
2722
-                            $attribute_output_def['value'] = isset($head_wpshop_variation_definition['options']['attributes_default_value'][$attribute_code]) ? $head_wpshop_variation_definition['options']['attributes_default_value'][$attribute_code] : $input_def['value'];
2723
-                            $tpl_component['VARIATION_INPUT'] = wpshop_form::check_input_type($input_def, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) . $input_def['options']['more_input'];
2724
-                            $tpl_component['VARIATION_LABEL'] = ($is_required ? '<span class="attribute_is_required attribute_is_required_' . $attribute_code . '" >' . stripslashes($attribute_db_definition->frontend_label) . '</span> <span class="required" >*</span>' : stripslashes($attribute_db_definition->frontend_label));
2725
-                            $tpl_component['VARIATION_CODE'] = $attribute_code;
2726
-                            $tpl_component['VARIATION_LABEL_HELPER'] = !empty($attribute_db_definition->frontend_help_message) ? ' title="' . $attribute_db_definition->frontend_help_message . '" ' : '';
2727
-                            $tpl_component['VARIATION_LABEL_CLASS'] = !empty($attribute_db_definition->frontend_help_message) ? ' wpshop_att_variation_helper' : '';
2728
-                            $tpl_component['VARIATION_IDENTIFIER'] = $input_def['id'];
2729
-                            $tpl_component['VARIATION_PARENT_ID'] = $product_id;
2730
-                            $tpl_component['VARIATION_PARENT_TYPE'] = WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT;
2731
-                            $tpl_component['VARIATION_CONTAINER_CLASS'] = ($is_required ? ' attribute_is_required_container attribute_is_required_container_' . $attribute_code : '') . ' wpshop_variation_' . $attribute_code . ' wpshop_variation_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . ' wpshop_variation_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_' . $product_id;
2732
-                            $tpl_component['VARIATION_REQUIRED_INDICATION'] = ($is_required) ? __('Required variation', 'wpshop') : '';
2733
-                            $variation_tpl['VARIATION_COMPLETE_OUTPUT_' . strtoupper($attribute_code)] = wpshop_display::display_template_element('product_variation_item', $tpl_component);
2734
-                            $variation_attribute_ordered[$output_order[$attribute_code]] = $variation_tpl['VARIATION_COMPLETE_OUTPUT_' . strtoupper($attribute_code)];
2735
-                        }
2736
-
2737
-                        $variation_attribute[] = $attribute_code;
2738
-                    }
2739
-                }
2740
-            }
2487
+				}
2488
+				$post_obj = $variation['post'];
2489
+
2490
+				$parent_product_infos = wpshop_products::get_parent_variation($post_obj->ID);
2491
+				if (!empty($parent_product_infos)) {
2492
+					$parent_post = $parent_product_infos['parent_post'];
2493
+					$product_option_postmeta = get_post_meta($parent_post->ID, '_wpshop_variation_defining', true);
2494
+					if (!empty($product_option_postmeta['options']['price_behaviour']) && !empty($product_option_postmeta['options']['price_behaviour'][0]) && $product_option_postmeta['options']['price_behaviour'][0] == 'addition') {
2495
+						if (!empty($price_piloting) && $price_piloting == 'HT') {
2496
+							$product_price = ((!empty($variation['variation_dif']['price_ht'])) ? $variation['variation_dif']['price_ht'] : 0) + $parent_product_infos['parent_post_meta']['price_ht'];
2497
+						} else {
2498
+							$product_price = ((!empty($variation['variation_dif']['product_price'])) ? $variation['variation_dif']['product_price'] : 0) + $parent_product_infos['parent_post_meta']['product_price'];
2499
+						}
2500
+						$tpl_component['VARIATION_DETAIL_SALE_PRICE_INDICATION'] = __('Variation price combined with the parent product price', 'wpshop');
2501
+					} else {
2502
+						if (!empty($price_piloting) && $price_piloting == 'HT') {
2503
+							$product_price = (!empty($variation['variation_dif']['price_ht'])) ? $variation['variation_dif']['price_ht'] : 0;
2504
+						} else {
2505
+							$product_price = (!empty($variation['variation_dif']['product_price'])) ? $variation['variation_dif']['product_price'] : 0;
2506
+						}
2507
+						$tpl_component['VARIATION_DETAIL_SALE_PRICE_INDICATION'] = __('Only variation\'s price is used', 'wpshop');
2508
+					}
2509
+					$product_price = number_format(str_replace(',', '.', $product_price), 2, '.', '') . ' ' . $productCurrency . ' ' . ((!empty($price_piloting) && $price_piloting == 'HT') ? __('ET', 'wpshop') : __('ATI', 'wpshop'));
2510
+					$tpl_component['VARIATION_DETAIL_SALE_PRICE'] = $product_price;
2511
+				}
2741 2512
 
2742
-        }
2743
-        $variation_tpl['VARIATION_FORM_ELEMENT_ID'] = $product_id;
2744
-        wp_reset_query();
2745
-
2746
-        $attribute_defined_to_be_user_defined = wpshop_attributes::get_attribute_user_defined(array('entity_type_id' => self::currentPageCode));
2747
-        if (!empty($attribute_defined_to_be_user_defined)) {
2748
-            foreach ($attribute_defined_to_be_user_defined as $attribute_not_in_variation_but_user_defined) {
2749
-                $is_required = ((!empty($head_wpshop_variation_definition['options']) && !empty($head_wpshop_variation_definition['options']['required_attributes']) && (in_array($attribute_not_in_variation_but_user_defined->code, $head_wpshop_variation_definition['options']['required_attributes']))) || $attribute_not_in_variation_but_user_defined->is_required == 'yes') ? true : false;
2750
-
2751
-                $attribute_display_state = wpshop_attributes::check_attribute_display($attribute_not_in_variation_but_user_defined->is_visible_in_front, $wpshop_product_attributes_frontend_display, 'attribute', $attribute_not_in_variation_but_user_defined->code, 'complete_sheet');
2752
-                if ($attribute_display_state && array_key_exists($attribute_not_in_variation_but_user_defined->code, $output_order) && !in_array($attribute_not_in_variation_but_user_defined->code, $variation_attribute) && ($attribute_not_in_variation_but_user_defined->is_used_for_variation == 'no')) {
2753
-                    $attribute_output_def = wpshop_attributes::get_attribute_field_definition($attribute_not_in_variation_but_user_defined, (is_array($head_wpshop_variation_definition) && isset($head_wpshop_variation_definition['options']['attributes_default_value'][$attribute_not_in_variation_but_user_defined->code]) ? $head_wpshop_variation_definition['options']['attributes_default_value'][$attribute_not_in_variation_but_user_defined->code] : ''));
2754
-
2755
-                    $tpl_component = array();
2756
-                    $attribute_output_def['option'] = 'data-nonce="' . wp_create_nonce('wpshop_ajax_wpshop_variation_selection') . '" class="wpshop_variation_selector_input' . ($is_required ? ' attribute_is_required_input attribute_is_required_input_' . $attribute_not_in_variation_but_user_defined->code : '') . ' ' . (str_replace('"', '', str_replace('class="', '', $attribute_output_def['option']))) . ' ' . ((is_admin()) ? $attribute_not_in_variation_but_user_defined->backend_css_class : $attribute_not_in_variation_but_user_defined->frontend_css_class) . '" ';
2757
-                    $tpl_component['VARIATION_INPUT'] = wpshop_form::check_input_type($attribute_output_def, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION . '[free]') . $attribute_output_def['options'];
2758
-                    $tpl_component['VARIATION_LABEL'] = ($is_required ? '<span class="attribute_is_required attribute_is_required_' . $attribute_not_in_variation_but_user_defined->code . '" >' . stripslashes($attribute_not_in_variation_but_user_defined->frontend_label) . '</span> <span class="required" >*</span>' : stripslashes($attribute_not_in_variation_but_user_defined->frontend_label));
2759
-                    $tpl_component['VARIATION_CODE'] = $attribute_not_in_variation_but_user_defined->code;
2760
-                    $tpl_component['VARIATION_LABEL_HELPER'] = !empty($attribute_not_in_variation_but_user_defined->frontend_help_message) ? ' title="' . $attribute_not_in_variation_but_user_defined->frontend_help_message . '" ' : '';
2761
-                    $tpl_component['VARIATION_LABEL_CLASS'] = !empty($attribute_not_in_variation_but_user_defined->frontend_help_message) ? ' wpshop_att_variation_helper' : '';
2762
-                    $tpl_component['VARIATION_REQUIRED_INDICATION'] = ($is_required) ? __('Required variation', 'wpshop') : '';
2763
-                    $tpl_component['VARIATION_IDENTIFIER'] = $attribute_output_def['id'];
2764
-                    $tpl_component['VARIATION_PARENT_ID'] = $product_id;
2765
-                    $tpl_component['VARIATION_PARENT_TYPE'] = WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT;
2766
-                    $tpl_component['VARIATION_CONTAINER_CLASS'] = ($is_required ? ' attribute_is_required_container attribute_is_required_container_' . $attribute_not_in_variation_but_user_defined->code : '') . ' wpshop_variation_' . $attribute_not_in_variation_but_user_defined->code . ' wpshop_variation_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . ' wpshop_variation_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_' . $product_id;
2767
-                    $variation_tpl['VARIATION_COMPLETE_OUTPUT_' . strtoupper($attribute_not_in_variation_but_user_defined->code)] = ($attribute_output_def['type'] != 'hidden') ? wpshop_display::display_template_element('product_variation_item', $tpl_component) : wpshop_form::check_input_type($attribute_output_def, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION . '[free]') . $attribute_output_def['options'];
2768
-                    $variation_attribute_ordered[$output_order[$attribute_not_in_variation_but_user_defined->code]] = $variation_tpl['VARIATION_COMPLETE_OUTPUT_' . strtoupper($attribute_not_in_variation_but_user_defined->code)];
2769
-                }
2770
-            }
2771
-        }
2772
-        $variation_tpl['VARIATION_FORM_VARIATION_LIST'] = '';
2773
-        if (!empty($variation_attribute_ordered) && is_array($variation_attribute_ordered)) {
2774
-            ksort($variation_attribute_ordered);
2775
-            foreach ($variation_attribute_ordered as $attribute_variation_to_output) {
2776
-                $variation_tpl['VARIATION_FORM_VARIATION_LIST'] .= $attribute_variation_to_output;
2777
-            }
2778
-        }
2779
-        $variation_tpl['FROM_ADMIN_INDICATOR'] = $variation_tpl['ORDER_ID_INDICATOR'] = '';
2780
-        $variation_tpl['PRODUCT_ADDED_TO_CART_QTY'] = (!empty($qty)) ? $qty : 1;
2781
-        if ($from_admin && !empty($order_id)) {
2782
-            $variation_tpl['FROM_ADMIN_INDICATOR'] = '<input type="hidden" name="wps_orders_from_admin" value="1" />';
2783
-            $variation_tpl['ORDER_ID_INDICATOR'] = '<input type="hidden" name="wps_orders_order_id" value="' . $order_id . '" />';
2784
-        }
2785
-        $output = !empty($variation_tpl['VARIATION_FORM_VARIATION_LIST']) ? wpshop_display::display_template_element('product_variation_form', $variation_tpl) : '';
2513
+				if (!empty($variation['variation_def'])) {
2514
+					foreach ($variation['variation_def'] as $variation_key => $variation_value) {
2515
+						if (!empty($variation_value)) {
2516
+							$attribute_def_for_variation = wpshop_attributes::getElement($variation_key, "'valid'", 'code');
2517
+							$tpl_component['VARIATION_DETAIL'] .= '<input type="hidden" name="' . self::current_page_variation_code . '[' . $variation['post']->ID . '][attribute][' . $attribute_def_for_variation->data_type . '][' . $variation_key . ']" value="' . $variation_value . '" />' . wpshop_display::display_template_element('wpshop_admin_variation_item_def_header', array('VARIATION_ATTRIBUTE_CODE' => $attribute_def_for_variation->frontend_label, 'VARIATION_ATTRIBUTE_CODE_VALUE' => stripslashes(wpshop_attributes::get_attribute_type_select_option_info($variation_value, 'label', $attribute_def_for_variation->data_type_to_use, true))), array(), 'admin');
2518
+							$tpl_component['VARIATION_IMAGE_CHOICE'] = '';
2519
+
2520
+							/** Define Link image to variation interface **/
2521
+							if (!empty($product_option_postmeta) && !empty($product_option_postmeta['attributes']) && !empty($product_option_postmeta['variation_type']) && ((count($product_option_postmeta['attributes']) == 1 && $product_option_postmeta['variation_type'] == 'single') || ($product_option_postmeta['variation_type'] == 'combined'))) {
2522
+								$pictures = get_posts(array('post_type' => 'attachment', 'posts_per_page' => -1, 'post_status' => null, 'post_parent' => $head_product));
2523
+
2524
+								$media_id_data = get_post_meta($head_product, '_wps_product_media', true);
2525
+								if (!empty($media_id_data)) {
2526
+									$medias_ids = explode(',', $media_id_data);
2527
+
2528
+									if (!empty($medias_ids)) {
2529
+										foreach ($medias_ids as $media_id) {
2530
+											if (!empty($media_id)) {
2531
+												$pictures[] = get_post($media_id);
2532
+											}
2533
+										}
2534
+									}
2535
+								}
2536
+
2537
+								$pictures_data = '';
2538
+								if (!empty($pictures)) {
2539
+									$selected_picture = get_post_meta($variation['post']->ID, '_wps_variation_attached_picture', true);
2540
+
2541
+									$done_picture = array();
2542
+									foreach ($pictures as $picture) {
2543
+										if (!in_array($picture->ID, $done_picture)) {
2544
+											if (wp_attachment_is_image($picture->ID)) {
2545
+												$checked = ((!empty($selected_picture) && $selected_picture == $picture->ID) ? 'checked="checked"' : '');
2546
+												$pictures_data .= wpshop_display::display_template_element('wpshop_admin_variation_picture_choice_element', array('PICTURE_CHOICE_VARIATION_ID' => $picture->ID, 'PRODUCT_VARIATION_ID' => $variation['post']->ID, 'PICTURE_CHOICE_SELECTED' => $checked, 'PICTURE_CHOICE_VARIATION_IMG' => wp_get_attachment_image($picture->ID, 'thumbnail')), array(), 'admin');
2547
+
2548
+												$done_picture[] = $picture->ID;
2549
+											}
2550
+										}
2551
+									}
2552
+								}
2553
+
2554
+								$tpl_component['VARIATION_IMAGE_CHOICE'] = wpshop_display::display_template_element('wpshop_admin_variation_picture_choice_container', array('PICTURE_CHOICE_CONTAINER_CONTENT' => $pictures_data), array(), 'admin');
2555
+							}
2556
+
2557
+						}
2558
+					}
2559
+				}
2786 2560
 
2787
-        return $output;
2788
-    }
2561
+				$tpl_component['VARIATION_DETAIL'] = substr($tpl_component['VARIATION_DETAIL'], 0, -2);
2789 2562
 
2790
-    public static function get_parent_variation($variation_id)
2791
-    {
2792
-        $result = array();
2793
-        if (!empty($variation_id)) {
2794
-            $variation_post = get_post($variation_id);
2795
-            if (!empty($variation_post) && !empty($variation_post->post_parent)) {
2796
-                $result['parent_post'] = get_post($variation_post->post_parent);
2797
-                $result['parent_post_meta'] = get_post_meta($variation_post->post_parent, '_wpshop_product_metadata', true);
2798
-            }
2799
-        }
2800
-        return $result;
2801
-    }
2563
+				$tpl_component['ADMIN_VARIATION_SPECIFIC_DEFINITION_CONTAINER_CLASS'] = ' wpshopHide';
2564
+				$tpl_component['VARIATION_DEFINITION'] = wpshop_attributes::get_variation_attribute(array('post_id' => $variation['post']->ID, 'input_class' => ' ', 'field_name' => wpshop_products::current_page_variation_code . '[' . $variation['post']->ID . ']', 'page_code' => self::current_page_variation_code, 'field_id' => self::current_page_variation_code . '_' . $variation['post']->ID, 'variation_dif_values' => (!empty($variation['variation_dif']) ? $variation['variation_dif'] : array())));
2565
+				$tpl_component['VARIATION_DEFINITION_CONTENT'] = wpshop_display::display_template_element('wpshop_admin_variation_item_specific_def', $tpl_component, array(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT => $head_product, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION => $variation['post']->ID), 'admin');
2802 2566
 
2803
-    /**
2804
-     * Display the current configuration for a given product
2805
-     * @param array $shortcode_attribute Some parameters given by the shortcode for display
2806
-     */
2807
-    public function wpshop_product_variations_summary($shortcode_attribute)
2808
-    {
2809
-        $output = '';
2810
-
2811
-        $product_variations_selection_args = array(
2812
-            'CURRENCY_SELECTOR' => wpshop_attributes_unit::wpshop_shop_currency_list_field(),
2813
-            'PRODUCT_VARIATION_SELECTION_DISPLAY' => '',
2814
-        );
2815
-
2816
-        $current_user_id = get_current_user_id();
2817
-
2818
-        if (!empty($_SESSION) && !empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_items'])) {
2819
-            foreach ($_SESSION['cart']['order_items'] as $item_id => $item) {
2820
-                if (!empty($item) && !empty($item['item_id'])) {
2821
-
2822
-                    $free_variations = array();
2823
-                    if (!empty($item['item_meta']) && !empty($item['item_meta']['free_variation'])) {
2824
-                        foreach ($item['item_meta']['free_variation'] as $attribute_code => $attribute_value) {
2825
-                            $free_variations[] = $attribute_code . '-_variation_val_-' . $attribute_value;
2826
-                        }
2827
-                    }
2828
-
2829
-                    $variations = array();
2830
-                    if (!empty($item['item_meta']) && !empty($item['item_meta']['variations'])) {
2831
-                        foreach ($item['item_meta']['variations'] as $variation_id => $variation_def) {
2832
-
2833
-                            if (!empty($variation_def['item_meta']) && !empty($variation_def['item_meta']['variation_definition'])) {
2834
-                                foreach ($variation_def['item_meta']['variation_definition'] as $attribute_code => $attribute_selected_data) {
2835
-                                    $variations[] = $attribute_code . '-_variation_val_-' . $attribute_selected_data['ID'];
2836
-                                }
2837
-                            }
2838
-                        }
2839
-                    }
2840
-                    $product_variation_summary = self::wpshop_ajax_wpshop_variation_selection($item['item_id'], $variations, $free_variations, null, $item['item_qty']);
2841
-
2842
-                    $product_variations_selection_args['PRODUCT_VARIATION_SELECTION_DISPLAY'] .= $product_variation_summary[1]['product_output'];
2843
-                }
2844
-            }
2845
-        }
2567
+				/*    Add the variation definition to output    */
2568
+				$existing_variation_list .= wpshop_display::display_template_element('wpshop_admin_variation_item_def', $tpl_component, array(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT => $head_product, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION => $variation['post']->ID), 'admin');
2569
+			}
2570
+
2571
+			$output .= wpshop_display::display_template_element('wpshop_admin_existing_variation_list', array('ADMIN_EXISTING_VARIATIONS_CONTAINER_CLASS' => '', 'ADMIN_EXISTING_VARIATIONS_CONTAINER' => $existing_variation_list), array(), 'admin');
2572
+			/*    Reset de la liste des résultats pour éviter les comportements indésirables    */
2573
+			wp_reset_query();
2574
+		} else {
2575
+			$output = __('No variation found for this product. Please use button above for create one', 'wpshop');
2576
+		}
2846 2577
 
2847
-        $output .= wpshop_display::display_template_element('wpshop_product_configuration_summary', $product_variations_selection_args);
2578
+		return $output;
2579
+	}
2848 2580
 
2849
-        echo $output;
2850
-    }
2581
+	/**
2582
+	 * Retrieve and display the variation for a given product
2583
+	 * @param integer $product_id The product identifier to get variation for
2584
+	 */
2585
+	public static function wpshop_variation($post_id = '', $from_admin = false, $order_id = '', $qty = 1)
2586
+	{
2587
+		global $wp_query;
2588
+		$output = '';
2589
+
2590
+		$product_id = empty($post_id) ? $wp_query->post->ID : $post_id;
2591
+		$wpshop_product_attributes_frontend_display = get_post_meta($product_id, '_wpshop_product_attributes_frontend_display', true);
2592
+		$head_wpshop_variation_definition = get_post_meta($product_id, '_wpshop_variation_defining', true);
2593
+
2594
+		/**    Get attribute order for current product    */
2595
+		$product_attribute_order_detail = wpshop_attributes_set::getAttributeSetDetails(get_post_meta($product_id, WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, true));
2596
+		$output_order = array();
2597
+		if (count($product_attribute_order_detail) > 0) {
2598
+			if (!empty($product_attribute_order_detail)) {
2599
+				foreach ($product_attribute_order_detail as $product_attr_group_id => $product_attr_group_detail) {
2600
+					foreach ($product_attr_group_detail['attribut'] as $position => $attribute_def) {
2601
+						if (!empty($attribute_def->code)) {
2602
+							$output_order[$attribute_def->code] = $position;
2603
+						}
2604
+
2605
+					}
2606
+				}
2607
+			}
2608
+		}
2609
+
2610
+		$variations_params = array();
2611
+		$variation_attribute = array();
2612
+		$variation_attribute_ordered = array();
2613
+		$possible_values = array();
2614
+		$possible_values_for_selection_calculation = array();
2615
+
2616
+		/*    Vérification de l'existence de déclinaison pour le produit    */
2617
+		$wpshop_variation_list = self::get_variation($product_id);
2618
+		if (!empty($wpshop_variation_list)) {
2619
+			foreach ($wpshop_variation_list as $variation) {
2620
+				if (!empty($variation['variation_def'])) {
2621
+					$display_option = get_post_meta($post_id, '_wpshop_product_attributes_frontend_display', true);
2622
+					foreach ($variation['variation_def'] as $attribute_code => $attribute_value) {
2623
+						if (empty($display_option) || (!empty($display_option['attribute']) && !empty($display_option['attribute'][$attribute_code]) && !empty($display_option['attribute'][$attribute_code]['complete_sheet']))) {
2624
+							$tpl_component = array();
2625
+
2626
+							$attribute_db_definition = wpshop_attributes::getElement($attribute_code, "'valid'", 'code');
2627
+							$default_value_is_serial = false;
2628
+							$attribute_list_first_element = $attribute_db_definition->default_value;
2629
+							if (!empty($attribute_db_definition->default_value) && ($attribute_db_definition->default_value == serialize(false) || wpshop_tools::is_serialized($attribute_db_definition->default_value))) {
2630
+								$default_value_is_serial = true;
2631
+								$tmp_default_value = unserialize($attribute_db_definition->default_value);
2632
+								$attribute_list_first_element = !empty($tmp_default_value['field_options']['label_for_first_item']) ? $tmp_default_value['field_options']['label_for_first_item'] : null;
2633
+							}
2634
+
2635
+							if ($default_value_is_serial && !empty($attribute_list_first_element) && ($attribute_list_first_element != 'none')) {
2636
+								$possible_values[$attribute_code][0][0] = ($default_value_is_serial && !empty($attribute_list_first_element) && ($attribute_list_first_element != 'none')) ? stripslashes(sprintf($attribute_list_first_element, strtolower($attribute_db_definition->frontend_label))) : __('Choose a value', 'wpshop');
2637
+							}
2638
+
2639
+							if (!empty($attribute_value) && ($attribute_db_definition->data_type_to_use == 'custom')) {
2640
+								$tpl_component['VARIATION_VALUE'] = stripslashes(wpshop_attributes::get_attribute_type_select_option_info($attribute_value, 'label', 'custom'));
2641
+								$position = wpshop_attributes::get_attribute_type_select_option_info($attribute_value, 'position', 'custom');
2642
+							} else if (!empty($attribute_value) && ($attribute_db_definition->data_type_to_use == 'internal')) {
2643
+								$post_def = get_post($attribute_value);
2644
+								$tpl_component['VARIATION_VALUE'] = stripslashes($post_def->post_title);
2645
+								$position = $post_def->menu_order;
2646
+							}
2647
+
2648
+							if (!empty($variation['variation_dif'])) {
2649
+								foreach ($variation['variation_dif'] as $attribute_dif_code => $attribute_dif_value) {
2650
+									$wpshop_prices_attributes = unserialize(WPSHOP_ATTRIBUTE_PRICES);
2651
+									$the_value = $attribute_dif_value;
2652
+									if (in_array($attribute_dif_code, $wpshop_prices_attributes)) {
2653
+										$the_value = wpshop_display::format_field_output('wpshop_product_price', $attribute_dif_value);
2654
+									}
2655
+									$tpl_component['VARIATION_DIF_' . strtoupper($attribute_dif_code)] = stripslashes($the_value);
2656
+								}
2657
+							}
2658
+							if (!empty($attribute_value)) {
2659
+								$possible_values[$attribute_code][$position][$attribute_value] = wpshop_display::display_template_element('product_variation_item_possible_values', $tpl_component, array('type' => 'attribute_for_variation', 'id' => $attribute_code));
2660
+								$possible_values_for_selection_calculation[$attribute_code][$attribute_value] = $tpl_component['VARIATION_VALUE'];
2661
+							}
2662
+							unset($tpl_component);
2663
+						}
2664
+					}
2665
+				}
2666
+			}
2667
+
2668
+			$variation_tpl = array();
2669
+			if (!empty($head_wpshop_variation_definition['attributes'])) {
2670
+				foreach ($head_wpshop_variation_definition['attributes'] as $attribute_code) {
2671
+					$attribute_db_definition = wpshop_attributes::getElement($attribute_code, "'valid'", 'code');
2672
+
2673
+					if (!empty($attribute_db_definition)) {
2674
+						$attribute_display_state = wpshop_attributes::check_attribute_display($attribute_db_definition->is_visible_in_front, $wpshop_product_attributes_frontend_display, 'attribute', $attribute_code, 'complete_sheet');
2675
+
2676
+						$is_required = ((!empty($head_wpshop_variation_definition['options']) && !empty($head_wpshop_variation_definition['options']['required_attributes']) && (in_array($attribute_code, $head_wpshop_variation_definition['options']['required_attributes'])))) ? true : false;
2677
+						if (!$is_required && $attribute_db_definition->is_required == 'yes') {
2678
+							$is_required = true;
2679
+						}
2680
+
2681
+						$input_def = array();
2682
+						$input_def['type'] = $attribute_db_definition->frontend_input;
2683
+						$value = isset($head_wpshop_variation_definition['options']['attributes_default_value'][$attribute_code]) ? $head_wpshop_variation_definition['options']['attributes_default_value'][$attribute_code] : (!empty($attribute_db_definition->default_value) ? $attribute_db_definition->default_value : null);
2684
+						if (in_array($attribute_db_definition->frontend_input, array('radio', 'checkbox'))) {
2685
+							unset($possible_values[$attribute_code][0]);
2686
+							$value = array($value);
2687
+						}
2688
+						$input_def['id'] = 'wpshop_variation_attr_' . $attribute_code;
2689
+						$input_def['name'] = $attribute_code;
2690
+						$real_possible_values = array();
2691
+						if (!empty($possible_values[$attribute_code])) {
2692
+							ksort($possible_values[$attribute_code]);
2693
+							foreach ($possible_values[$attribute_code] as $position => $def) {
2694
+								foreach ($def as $attribute_value => $attribute_value_output) {
2695
+									$real_possible_values[$attribute_value] = $attribute_value_output;
2696
+									if (!empty($attribute_value)) {
2697
+										global $wpdb;
2698
+										$query = $wpdb->prepare("SELECT post_status FROM " . $wpdb->postmeta . " AS P_META INNER JOIN " . $wpdb->posts . " as P ON ((P.ID = P_META.post_id) AND (P.post_parent = %d)) WHERE P_META.meta_value LIKE '%%" . serialize($attribute_code) . serialize($attribute_value) . "%%'", $product_id);
2699
+										if ('draft' == $wpdb->get_var($query)) {
2700
+											unset($real_possible_values[$attribute_value]);
2701
+										}
2702
+									}
2703
+								}
2704
+							}
2705
+						}
2706
+						$input_def['possible_value'] = $real_possible_values;
2707
+						$input_def['valueToPut'] = 'index';
2708
+						$input_def['value'] = $value;
2709
+
2710
+						$input_def['options']['more_input'] = '';
2711
+						if (!empty($possible_values_for_selection_calculation[$attribute_code])) {
2712
+							foreach ($possible_values_for_selection_calculation[$attribute_code] as $value_id => $value) {
2713
+								$input_def['options']['more_input'] .= '<input type="hidden" disabled="disabled" value="' . str_replace("\\", "", $value) . '" name="' . $input_def['id'] . '_current_value" id="' . $input_def['id'] . '_current_value_' . $value_id . '" />';
2714
+							}
2715
+						}
2716
+
2717
+						$input_def['options_label']['original'] = true;
2718
+						$input_def['option'] = 'data-nonce="' . wp_create_nonce('wpshop_ajax_wpshop_variation_selection') . '" class="wpshop_variation_selector_input' . ($is_required ? ' attribute_is_required_input attribute_is_required_input_' . $attribute_code . ' ' : '') . ($attribute_db_definition->_display_informations_about_value == 'yes' ? ' wpshop_display_information_about_value' : '') . ' ' . ((is_admin()) ? $attribute_db_definition->backend_css_class : $attribute_db_definition->frontend_css_class) . '" ';
2719
+
2720
+						if (!empty($real_possible_values)) {
2721
+							$tpl_component = array();
2722
+							$attribute_output_def['value'] = isset($head_wpshop_variation_definition['options']['attributes_default_value'][$attribute_code]) ? $head_wpshop_variation_definition['options']['attributes_default_value'][$attribute_code] : $input_def['value'];
2723
+							$tpl_component['VARIATION_INPUT'] = wpshop_form::check_input_type($input_def, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) . $input_def['options']['more_input'];
2724
+							$tpl_component['VARIATION_LABEL'] = ($is_required ? '<span class="attribute_is_required attribute_is_required_' . $attribute_code . '" >' . stripslashes($attribute_db_definition->frontend_label) . '</span> <span class="required" >*</span>' : stripslashes($attribute_db_definition->frontend_label));
2725
+							$tpl_component['VARIATION_CODE'] = $attribute_code;
2726
+							$tpl_component['VARIATION_LABEL_HELPER'] = !empty($attribute_db_definition->frontend_help_message) ? ' title="' . $attribute_db_definition->frontend_help_message . '" ' : '';
2727
+							$tpl_component['VARIATION_LABEL_CLASS'] = !empty($attribute_db_definition->frontend_help_message) ? ' wpshop_att_variation_helper' : '';
2728
+							$tpl_component['VARIATION_IDENTIFIER'] = $input_def['id'];
2729
+							$tpl_component['VARIATION_PARENT_ID'] = $product_id;
2730
+							$tpl_component['VARIATION_PARENT_TYPE'] = WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT;
2731
+							$tpl_component['VARIATION_CONTAINER_CLASS'] = ($is_required ? ' attribute_is_required_container attribute_is_required_container_' . $attribute_code : '') . ' wpshop_variation_' . $attribute_code . ' wpshop_variation_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . ' wpshop_variation_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_' . $product_id;
2732
+							$tpl_component['VARIATION_REQUIRED_INDICATION'] = ($is_required) ? __('Required variation', 'wpshop') : '';
2733
+							$variation_tpl['VARIATION_COMPLETE_OUTPUT_' . strtoupper($attribute_code)] = wpshop_display::display_template_element('product_variation_item', $tpl_component);
2734
+							$variation_attribute_ordered[$output_order[$attribute_code]] = $variation_tpl['VARIATION_COMPLETE_OUTPUT_' . strtoupper($attribute_code)];
2735
+						}
2736
+
2737
+						$variation_attribute[] = $attribute_code;
2738
+					}
2739
+				}
2740
+			}
2741
+
2742
+		}
2743
+		$variation_tpl['VARIATION_FORM_ELEMENT_ID'] = $product_id;
2744
+		wp_reset_query();
2745
+
2746
+		$attribute_defined_to_be_user_defined = wpshop_attributes::get_attribute_user_defined(array('entity_type_id' => self::currentPageCode));
2747
+		if (!empty($attribute_defined_to_be_user_defined)) {
2748
+			foreach ($attribute_defined_to_be_user_defined as $attribute_not_in_variation_but_user_defined) {
2749
+				$is_required = ((!empty($head_wpshop_variation_definition['options']) && !empty($head_wpshop_variation_definition['options']['required_attributes']) && (in_array($attribute_not_in_variation_but_user_defined->code, $head_wpshop_variation_definition['options']['required_attributes']))) || $attribute_not_in_variation_but_user_defined->is_required == 'yes') ? true : false;
2750
+
2751
+				$attribute_display_state = wpshop_attributes::check_attribute_display($attribute_not_in_variation_but_user_defined->is_visible_in_front, $wpshop_product_attributes_frontend_display, 'attribute', $attribute_not_in_variation_but_user_defined->code, 'complete_sheet');
2752
+				if ($attribute_display_state && array_key_exists($attribute_not_in_variation_but_user_defined->code, $output_order) && !in_array($attribute_not_in_variation_but_user_defined->code, $variation_attribute) && ($attribute_not_in_variation_but_user_defined->is_used_for_variation == 'no')) {
2753
+					$attribute_output_def = wpshop_attributes::get_attribute_field_definition($attribute_not_in_variation_but_user_defined, (is_array($head_wpshop_variation_definition) && isset($head_wpshop_variation_definition['options']['attributes_default_value'][$attribute_not_in_variation_but_user_defined->code]) ? $head_wpshop_variation_definition['options']['attributes_default_value'][$attribute_not_in_variation_but_user_defined->code] : ''));
2754
+
2755
+					$tpl_component = array();
2756
+					$attribute_output_def['option'] = 'data-nonce="' . wp_create_nonce('wpshop_ajax_wpshop_variation_selection') . '" class="wpshop_variation_selector_input' . ($is_required ? ' attribute_is_required_input attribute_is_required_input_' . $attribute_not_in_variation_but_user_defined->code : '') . ' ' . (str_replace('"', '', str_replace('class="', '', $attribute_output_def['option']))) . ' ' . ((is_admin()) ? $attribute_not_in_variation_but_user_defined->backend_css_class : $attribute_not_in_variation_but_user_defined->frontend_css_class) . '" ';
2757
+					$tpl_component['VARIATION_INPUT'] = wpshop_form::check_input_type($attribute_output_def, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION . '[free]') . $attribute_output_def['options'];
2758
+					$tpl_component['VARIATION_LABEL'] = ($is_required ? '<span class="attribute_is_required attribute_is_required_' . $attribute_not_in_variation_but_user_defined->code . '" >' . stripslashes($attribute_not_in_variation_but_user_defined->frontend_label) . '</span> <span class="required" >*</span>' : stripslashes($attribute_not_in_variation_but_user_defined->frontend_label));
2759
+					$tpl_component['VARIATION_CODE'] = $attribute_not_in_variation_but_user_defined->code;
2760
+					$tpl_component['VARIATION_LABEL_HELPER'] = !empty($attribute_not_in_variation_but_user_defined->frontend_help_message) ? ' title="' . $attribute_not_in_variation_but_user_defined->frontend_help_message . '" ' : '';
2761
+					$tpl_component['VARIATION_LABEL_CLASS'] = !empty($attribute_not_in_variation_but_user_defined->frontend_help_message) ? ' wpshop_att_variation_helper' : '';
2762
+					$tpl_component['VARIATION_REQUIRED_INDICATION'] = ($is_required) ? __('Required variation', 'wpshop') : '';
2763
+					$tpl_component['VARIATION_IDENTIFIER'] = $attribute_output_def['id'];
2764
+					$tpl_component['VARIATION_PARENT_ID'] = $product_id;
2765
+					$tpl_component['VARIATION_PARENT_TYPE'] = WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT;
2766
+					$tpl_component['VARIATION_CONTAINER_CLASS'] = ($is_required ? ' attribute_is_required_container attribute_is_required_container_' . $attribute_not_in_variation_but_user_defined->code : '') . ' wpshop_variation_' . $attribute_not_in_variation_but_user_defined->code . ' wpshop_variation_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . ' wpshop_variation_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_' . $product_id;
2767
+					$variation_tpl['VARIATION_COMPLETE_OUTPUT_' . strtoupper($attribute_not_in_variation_but_user_defined->code)] = ($attribute_output_def['type'] != 'hidden') ? wpshop_display::display_template_element('product_variation_item', $tpl_component) : wpshop_form::check_input_type($attribute_output_def, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION . '[free]') . $attribute_output_def['options'];
2768
+					$variation_attribute_ordered[$output_order[$attribute_not_in_variation_but_user_defined->code]] = $variation_tpl['VARIATION_COMPLETE_OUTPUT_' . strtoupper($attribute_not_in_variation_but_user_defined->code)];
2769
+				}
2770
+			}
2771
+		}
2772
+		$variation_tpl['VARIATION_FORM_VARIATION_LIST'] = '';
2773
+		if (!empty($variation_attribute_ordered) && is_array($variation_attribute_ordered)) {
2774
+			ksort($variation_attribute_ordered);
2775
+			foreach ($variation_attribute_ordered as $attribute_variation_to_output) {
2776
+				$variation_tpl['VARIATION_FORM_VARIATION_LIST'] .= $attribute_variation_to_output;
2777
+			}
2778
+		}
2779
+		$variation_tpl['FROM_ADMIN_INDICATOR'] = $variation_tpl['ORDER_ID_INDICATOR'] = '';
2780
+		$variation_tpl['PRODUCT_ADDED_TO_CART_QTY'] = (!empty($qty)) ? $qty : 1;
2781
+		if ($from_admin && !empty($order_id)) {
2782
+			$variation_tpl['FROM_ADMIN_INDICATOR'] = '<input type="hidden" name="wps_orders_from_admin" value="1" />';
2783
+			$variation_tpl['ORDER_ID_INDICATOR'] = '<input type="hidden" name="wps_orders_order_id" value="' . $order_id . '" />';
2784
+		}
2785
+		$output = !empty($variation_tpl['VARIATION_FORM_VARIATION_LIST']) ? wpshop_display::display_template_element('product_variation_form', $variation_tpl) : '';
2786
+
2787
+		return $output;
2788
+	}
2789
+
2790
+	public static function get_parent_variation($variation_id)
2791
+	{
2792
+		$result = array();
2793
+		if (!empty($variation_id)) {
2794
+			$variation_post = get_post($variation_id);
2795
+			if (!empty($variation_post) && !empty($variation_post->post_parent)) {
2796
+				$result['parent_post'] = get_post($variation_post->post_parent);
2797
+				$result['parent_post_meta'] = get_post_meta($variation_post->post_parent, '_wpshop_product_metadata', true);
2798
+			}
2799
+		}
2800
+		return $result;
2801
+	}
2802
+
2803
+	/**
2804
+	 * Display the current configuration for a given product
2805
+	 * @param array $shortcode_attribute Some parameters given by the shortcode for display
2806
+	 */
2807
+	public function wpshop_product_variations_summary($shortcode_attribute)
2808
+	{
2809
+		$output = '';
2810
+
2811
+		$product_variations_selection_args = array(
2812
+			'CURRENCY_SELECTOR' => wpshop_attributes_unit::wpshop_shop_currency_list_field(),
2813
+			'PRODUCT_VARIATION_SELECTION_DISPLAY' => '',
2814
+		);
2815
+
2816
+		$current_user_id = get_current_user_id();
2817
+
2818
+		if (!empty($_SESSION) && !empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_items'])) {
2819
+			foreach ($_SESSION['cart']['order_items'] as $item_id => $item) {
2820
+				if (!empty($item) && !empty($item['item_id'])) {
2821
+
2822
+					$free_variations = array();
2823
+					if (!empty($item['item_meta']) && !empty($item['item_meta']['free_variation'])) {
2824
+						foreach ($item['item_meta']['free_variation'] as $attribute_code => $attribute_value) {
2825
+							$free_variations[] = $attribute_code . '-_variation_val_-' . $attribute_value;
2826
+						}
2827
+					}
2828
+
2829
+					$variations = array();
2830
+					if (!empty($item['item_meta']) && !empty($item['item_meta']['variations'])) {
2831
+						foreach ($item['item_meta']['variations'] as $variation_id => $variation_def) {
2832
+
2833
+							if (!empty($variation_def['item_meta']) && !empty($variation_def['item_meta']['variation_definition'])) {
2834
+								foreach ($variation_def['item_meta']['variation_definition'] as $attribute_code => $attribute_selected_data) {
2835
+									$variations[] = $attribute_code . '-_variation_val_-' . $attribute_selected_data['ID'];
2836
+								}
2837
+							}
2838
+						}
2839
+					}
2840
+					$product_variation_summary = self::wpshop_ajax_wpshop_variation_selection($item['item_id'], $variations, $free_variations, null, $item['item_qty']);
2841
+
2842
+					$product_variations_selection_args['PRODUCT_VARIATION_SELECTION_DISPLAY'] .= $product_variation_summary[1]['product_output'];
2843
+				}
2844
+			}
2845
+		}
2846
+
2847
+		$output .= wpshop_display::display_template_element('wpshop_product_configuration_summary', $product_variations_selection_args);
2848
+
2849
+		echo $output;
2850
+	}
2851
+
2852
+	/**
2853
+	 * Affichage du résumé du produit sélectionné avec le prix par option / Display a summary of selected product with the price per option
2854
+	 *
2855
+	 * @param integer $product_id L'identifiant du produit qui est ajouté au panier / The product identifier added to cart
2856
+	 * @param array $wpshop_variation_selected La liste des options ayant un prix sélectionnées par le client / Options list with price selected by the customer
2857
+	 * @param array $wpshop_free_variation La liste des options n'entrainant pas de modification du prix final sélectionnées par le client / Options list without price selected by the customer
2858
+	 * @param string $wpshop_current_for_display Inconnu / Unknown
2859
+	 * @param integer $product_qty La quantité commandée par le client / Quantity ordered by the customer
2860
+	 *
2861
+	 * @return array Le résultat du calcul pour l'affichage / Output result
2862
+	 */
2863
+	public static function wpshop_ajax_wpshop_variation_selection($product_id, $wpshop_variation_selected, $wpshop_free_variation, $wpshop_current_for_display, $product_qty = 1)
2864
+	{
2865
+		global $wpdb;
2866
+
2867
+		$wpshop_cart = new wps_cart();
2868
+		$wpshop_products = new wpshop_products();
2869
+
2870
+		$response = '';
2871
+		$response_status = $has_variation = false;
2872
+		$tpl_component = array();
2873
+
2874
+		// Check if variations exists
2875
+		if (!empty($wpshop_variation_selected) || !empty($wpshop_free_variation)) {
2876
+
2877
+			//Recover all selected variations
2878
+			$variations_selected = array();
2879
+			if (!empty($wpshop_variation_selected)) {
2880
+				foreach ($wpshop_variation_selected as $selected_variation) {
2881
+					$variation_definition = explode('-_variation_val_-', $selected_variation);
2882
+					$variations_selected[$variation_definition[0]] = $variation_definition[1];
2883
+				}
2884
+			}
2851 2885
 
2852
-    /**
2853
-     * Affichage du résumé du produit sélectionné avec le prix par option / Display a summary of selected product with the price per option
2854
-     *
2855
-     * @param integer $product_id L'identifiant du produit qui est ajouté au panier / The product identifier added to cart
2856
-     * @param array $wpshop_variation_selected La liste des options ayant un prix sélectionnées par le client / Options list with price selected by the customer
2857
-     * @param array $wpshop_free_variation La liste des options n'entrainant pas de modification du prix final sélectionnées par le client / Options list without price selected by the customer
2858
-     * @param string $wpshop_current_for_display Inconnu / Unknown
2859
-     * @param integer $product_qty La quantité commandée par le client / Quantity ordered by the customer
2860
-     *
2861
-     * @return array Le résultat du calcul pour l'affichage / Output result
2862
-     */
2863
-    public static function wpshop_ajax_wpshop_variation_selection($product_id, $wpshop_variation_selected, $wpshop_free_variation, $wpshop_current_for_display, $product_qty = 1)
2864
-    {
2865
-        global $wpdb;
2866
-
2867
-        $wpshop_cart = new wps_cart();
2868
-        $wpshop_products = new wpshop_products();
2869
-
2870
-        $response = '';
2871
-        $response_status = $has_variation = false;
2872
-        $tpl_component = array();
2873
-
2874
-        // Check if variations exists
2875
-        if (!empty($wpshop_variation_selected) || !empty($wpshop_free_variation)) {
2876
-
2877
-            //Recover all selected variations
2878
-            $variations_selected = array();
2879
-            if (!empty($wpshop_variation_selected)) {
2880
-                foreach ($wpshop_variation_selected as $selected_variation) {
2881
-                    $variation_definition = explode('-_variation_val_-', $selected_variation);
2882
-                    $variations_selected[$variation_definition[0]] = $variation_definition[1];
2883
-                }
2884
-            }
2885
-
2886
-            // Check variations priority
2887
-            $product_with_variation = wpshop_products::get_variation_by_priority($variations_selected, $product_id);
2888
-
2889
-            // Check if $product_with_variation have variations
2890
-            if (!empty($product_with_variation[$product_id]['variations']) || !empty($wpshop_free_variation)) {
2891
-
2892
-                $formatted_product = $wpshop_cart->prepare_product_to_add_to_cart($product_id, $product_qty, $variations_selected);
2893
-                $product_to_add_to_cart = $formatted_product[0];
2894
-                foreach ($formatted_product[0] as $pid => $product_more_content) {
2895
-                    $order_items[$pid]['product_id'] = $product_more_content['id'];
2896
-
2897
-                    /** For product with variation    */
2898
-                    $order_items[$pid]['product_variation_type'] = !empty($product_more_content['variation_priority']) ? $product_more_content['variation_priority'] : '';
2899
-                    $order_items[$pid]['free_variation'] = !empty($product_more_content['free_variation']) ? $product_more_content['free_variation'] : '';
2900
-                    $order_items[$pid]['product_variation'] = '';
2901
-                    if (!empty($product_more_content['variations'])) {
2902
-                        foreach ($product_more_content['variations'] as $variation_id) {
2903
-                            $order_items[$pid]['product_variation'][] = $variation_id;
2904
-                        }
2905
-                    }
2906
-                }
2907
-
2908
-                // If Product list is not empty, add products to order
2909
-                if (!empty($order_items)) {
2910
-                    foreach ($order_items as $product_id => $d) {
2911
-                        $product_key = $product_id;
2912
-
2913
-                        // Formate datas
2914
-                        $product_id = $head_product_id = $d['product_id'];
2915
-                        $product_variation = !empty($d['product_variation']) ? $d['product_variation'] : null;
2916
-
2917
-                        // If product is a single variation product
2918
-                        if (!empty($product_variation) && (count($product_variation) == 1)) {
2919
-                            $product_id = $product_variation[0];
2920
-                        }
2921
-
2922
-                        // Construct final product
2923
-                        $product = wpshop_products::get_product_data($d['product_id'], true);
2924
-                        $the_product = array_merge(array('product_id' => $d['product_id'], 'product_qty' => 1), $product);
2886
+			// Check variations priority
2887
+			$product_with_variation = wpshop_products::get_variation_by_priority($variations_selected, $product_id);
2888
+
2889
+			// Check if $product_with_variation have variations
2890
+			if (!empty($product_with_variation[$product_id]['variations']) || !empty($wpshop_free_variation)) {
2891
+
2892
+				$formatted_product = $wpshop_cart->prepare_product_to_add_to_cart($product_id, $product_qty, $variations_selected);
2893
+				$product_to_add_to_cart = $formatted_product[0];
2894
+				foreach ($formatted_product[0] as $pid => $product_more_content) {
2895
+					$order_items[$pid]['product_id'] = $product_more_content['id'];
2896
+
2897
+					/** For product with variation    */
2898
+					$order_items[$pid]['product_variation_type'] = !empty($product_more_content['variation_priority']) ? $product_more_content['variation_priority'] : '';
2899
+					$order_items[$pid]['free_variation'] = !empty($product_more_content['free_variation']) ? $product_more_content['free_variation'] : '';
2900
+					$order_items[$pid]['product_variation'] = '';
2901
+					if (!empty($product_more_content['variations'])) {
2902
+						foreach ($product_more_content['variations'] as $variation_id) {
2903
+							$order_items[$pid]['product_variation'][] = $variation_id;
2904
+						}
2905
+					}
2906
+				}
2907
+
2908
+				// If Product list is not empty, add products to order
2909
+				if (!empty($order_items)) {
2910
+					foreach ($order_items as $product_id => $d) {
2911
+						$product_key = $product_id;
2912
+
2913
+						// Formate datas
2914
+						$product_id = $head_product_id = $d['product_id'];
2915
+						$product_variation = !empty($d['product_variation']) ? $d['product_variation'] : null;
2916
+
2917
+						// If product is a single variation product
2918
+						if (!empty($product_variation) && (count($product_variation) == 1)) {
2919
+							$product_id = $product_variation[0];
2920
+						}
2921
+
2922
+						// Construct final product
2923
+						$product = wpshop_products::get_product_data($d['product_id'], true);
2924
+						$the_product = array_merge(array('product_id' => $d['product_id'], 'product_qty' => 1), $product);
2925 2925
 						$the_product['text_from'] = $product_with_variation['text_from'];
2926 2926
 
2927
-                        //    Add variation to product into cart for storage
2928
-                        if (!empty($product_variation)) {
2929
-                            $the_product = wpshop_products::get_variation_price_behaviour($the_product, $product_variation, $head_product_id, array('type' => $d['product_variation_type']));
2930
-                        }
2931
-
2932
-                        // Free Variations Checking
2933
-                        if (!empty($d['free_variation'])) {
2934
-                            $the_product['item_meta']['free_variation'] = $d['free_variation'];
2935
-                            $head_product_id = $the_product['product_id'];
2936
-                        }
2937
-
2938
-                        // If product is a variation, we check parent product general
2939
-                        if (get_post_type($the_product['product_id']) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) {
2940
-                            $parent_def = wpshop_products::get_parent_variation($the_product['product_id']);
2941
-                            if (!empty($parent_def) && !empty($parent_def['parent_post'])) {
2942
-                                $variation_def = get_post_meta($parent_def['parent_post']->ID, '_wpshop_variation_defining', true);
2943
-                                $parent_meta = $parent_def['parent_post_meta'];
2944
-                                if (!empty($variation_def) && !empty($variation_def['options']) && !empty($variation_def['options']['priority']) && in_array('combined', $variation_def['options']['priority']) && !empty($variation_def['options']['price_behaviour']) && in_array('addition', $variation_def['options']['price_behaviour']) && !empty($variation_def['attributes']) && count($variation_def['attributes']) > 1) {
2945
-                                    $the_product['product_price'] += number_format(str_replace(',', '.', $parent_meta['product_price']), 2, '.', '');
2946
-                                    $the_product['price_ht'] += number_format(str_replace(',', '.', $parent_meta['price_ht']), 2, '.', '');
2947
-                                    $the_product['tva'] += number_format(str_replace(',', '.', $parent_meta['tva']), 2, '.', '');
2948
-                                }
2949
-                            }
2950
-                        }
2951
-                    }
2952
-                }
2953
-
2954
-                if (!empty($the_product) && empty($the_product['price_ttc_before_discount']) && empty($the_product['price_ht_before_discount'])) {
2955
-                    $price_infos = wpshop_prices::check_product_price($the_product, true);
2956
-                    if (!empty($price_infos['discount']['discount_exist'])) {
2957
-                        $the_product['price_ttc_before_discount'] = $the_product['product_price'];
2958
-                        $the_product['price_ht_before_discount'] = $the_product['price_ht'];
2959
-                    }
2960
-                    $the_product['price_ht'] = (!empty($price_infos['discount']) && !empty($price_infos['discount']['discount_exist']) && $price_infos['discount']['discount_exist']) ? $price_infos['discount']['discount_et_price'] : $price_infos['et'];
2961
-                    $the_product['product_price'] = (!empty($price_infos['discount']) && !empty($price_infos['discount']['discount_exist']) && $price_infos['discount']['discount_exist']) ? $price_infos['discount']['discount_ati_price'] : $price_infos['ati'];
2962
-                    $the_product['tva'] = (!empty($price_infos['discount']) && !empty($price_infos['discount']['discount_exist']) && $price_infos['discount']['discount_exist']) ? $price_infos['discount']['discount_tva'] : $price_infos['tva'];
2963
-                }
2964
-
2965
-                $product = wpshop_products::get_product_data($product_id, true, '"publish", "draft"');
2966
-                // Add free variations to product
2967
-                if (!empty($wpshop_free_variation)) {
2968
-                    $the_product['item_meta']['free_variation'] = $wpshop_free_variation;
2969
-                }
2970
-                // Change picture if have a selected variation
2971
-                $the_selected_variation = !empty($product_with_variation) && !empty($product_with_variation[$head_product_id]) && !empty($product_with_variation[$head_product_id]['variations']) ? $product_with_variation[$head_product_id]['variations'] : null;
2972
-                $response['wps_product_image'] = $wpshop_products->wps_selected_variation_picture($head_product_id, $the_selected_variation);
2973
-
2974
-                // Price Display
2975
-                $price_attribute = wpshop_attributes::getElement('product_price', "'valid'", 'code');
2976
-                $price_display = wpshop_attributes::check_attribute_display($price_attribute->is_visible_in_front, $product['custom_display'], 'attribute', 'product_price', 'complete_sheet');
2977
-                $productPrice = '';
2978
-                if ($price_display) {
2979
-                    $response['product_price_output'] = wpshop_prices::get_product_price($the_product, 'price_display', 'complete_sheet', false, true);
2980
-                }
2981
-
2982
-                //Get Summary cart
2983
-                $response['product_output'] = $wpshop_products->wps_get_summary_variations_product($product_id, $the_product, (!empty($wpshop_variation_selected) || !empty($wpshop_free_variation) ? true : false));
2984
-                $response_status = true;
2985
-            } else {
2986
-                //Product without variations
2987
-                $product_data = wpshop_products::get_product_data($product_id);
2988
-                $response['product_price_output'] = wpshop_prices::get_product_price($product_data, 'price_display', 'complete_sheet');
2927
+						//    Add variation to product into cart for storage
2928
+						if (!empty($product_variation)) {
2929
+							$the_product = wpshop_products::get_variation_price_behaviour($the_product, $product_variation, $head_product_id, array('type' => $d['product_variation_type']));
2930
+						}
2931
+
2932
+						// Free Variations Checking
2933
+						if (!empty($d['free_variation'])) {
2934
+							$the_product['item_meta']['free_variation'] = $d['free_variation'];
2935
+							$head_product_id = $the_product['product_id'];
2936
+						}
2937
+
2938
+						// If product is a variation, we check parent product general
2939
+						if (get_post_type($the_product['product_id']) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) {
2940
+							$parent_def = wpshop_products::get_parent_variation($the_product['product_id']);
2941
+							if (!empty($parent_def) && !empty($parent_def['parent_post'])) {
2942
+								$variation_def = get_post_meta($parent_def['parent_post']->ID, '_wpshop_variation_defining', true);
2943
+								$parent_meta = $parent_def['parent_post_meta'];
2944
+								if (!empty($variation_def) && !empty($variation_def['options']) && !empty($variation_def['options']['priority']) && in_array('combined', $variation_def['options']['priority']) && !empty($variation_def['options']['price_behaviour']) && in_array('addition', $variation_def['options']['price_behaviour']) && !empty($variation_def['attributes']) && count($variation_def['attributes']) > 1) {
2945
+									$the_product['product_price'] += number_format(str_replace(',', '.', $parent_meta['product_price']), 2, '.', '');
2946
+									$the_product['price_ht'] += number_format(str_replace(',', '.', $parent_meta['price_ht']), 2, '.', '');
2947
+									$the_product['tva'] += number_format(str_replace(',', '.', $parent_meta['tva']), 2, '.', '');
2948
+								}
2949
+							}
2950
+						}
2951
+					}
2952
+				}
2953
+
2954
+				if (!empty($the_product) && empty($the_product['price_ttc_before_discount']) && empty($the_product['price_ht_before_discount'])) {
2955
+					$price_infos = wpshop_prices::check_product_price($the_product, true);
2956
+					if (!empty($price_infos['discount']['discount_exist'])) {
2957
+						$the_product['price_ttc_before_discount'] = $the_product['product_price'];
2958
+						$the_product['price_ht_before_discount'] = $the_product['price_ht'];
2959
+					}
2960
+					$the_product['price_ht'] = (!empty($price_infos['discount']) && !empty($price_infos['discount']['discount_exist']) && $price_infos['discount']['discount_exist']) ? $price_infos['discount']['discount_et_price'] : $price_infos['et'];
2961
+					$the_product['product_price'] = (!empty($price_infos['discount']) && !empty($price_infos['discount']['discount_exist']) && $price_infos['discount']['discount_exist']) ? $price_infos['discount']['discount_ati_price'] : $price_infos['ati'];
2962
+					$the_product['tva'] = (!empty($price_infos['discount']) && !empty($price_infos['discount']['discount_exist']) && $price_infos['discount']['discount_exist']) ? $price_infos['discount']['discount_tva'] : $price_infos['tva'];
2963
+				}
2964
+
2965
+				$product = wpshop_products::get_product_data($product_id, true, '"publish", "draft"');
2966
+				// Add free variations to product
2967
+				if (!empty($wpshop_free_variation)) {
2968
+					$the_product['item_meta']['free_variation'] = $wpshop_free_variation;
2969
+				}
2970
+				// Change picture if have a selected variation
2971
+				$the_selected_variation = !empty($product_with_variation) && !empty($product_with_variation[$head_product_id]) && !empty($product_with_variation[$head_product_id]['variations']) ? $product_with_variation[$head_product_id]['variations'] : null;
2972
+				$response['wps_product_image'] = $wpshop_products->wps_selected_variation_picture($head_product_id, $the_selected_variation);
2973
+
2974
+				// Price Display
2975
+				$price_attribute = wpshop_attributes::getElement('product_price', "'valid'", 'code');
2976
+				$price_display = wpshop_attributes::check_attribute_display($price_attribute->is_visible_in_front, $product['custom_display'], 'attribute', 'product_price', 'complete_sheet');
2977
+				$productPrice = '';
2978
+				if ($price_display) {
2979
+					$response['product_price_output'] = wpshop_prices::get_product_price($the_product, 'price_display', 'complete_sheet', false, true);
2980
+				}
2981
+
2982
+				//Get Summary cart
2983
+				$response['product_output'] = $wpshop_products->wps_get_summary_variations_product($product_id, $the_product, (!empty($wpshop_variation_selected) || !empty($wpshop_free_variation) ? true : false));
2989 2984
 				$response_status = true;
2990
-            }
2991
-        }
2985
+			} else {
2986
+				//Product without variations
2987
+				$product_data = wpshop_products::get_product_data($product_id);
2988
+				$response['product_price_output'] = wpshop_prices::get_product_price($product_data, 'price_display', 'complete_sheet');
2989
+				$response_status = true;
2990
+			}
2991
+		}
2992 2992
 
2993
-        return array($response_status, $response);
2994
-    }
2993
+		return array($response_status, $response);
2994
+	}
2995 2995
 
2996
-    /**
2997
-     * Display information for a given value of an attribute defined as an entity, when attribute option for detail view is set as true
2998
-     *
2999
-     * @param array $shortcode_attribute Some parameters given by the shortcode for display
3000
-     */
3001
-    public function wpshop_product_variation_value_detail($shortcode_attribute)
3002
-    {
3003
-        echo wpshop_display::display_template_element('wpshop_product_variation_value_detail_container', array());
3004
-    }
2996
+	/**
2997
+	 * Display information for a given value of an attribute defined as an entity, when attribute option for detail view is set as true
2998
+	 *
2999
+	 * @param array $shortcode_attribute Some parameters given by the shortcode for display
3000
+	 */
3001
+	public function wpshop_product_variation_value_detail($shortcode_attribute)
3002
+	{
3003
+		echo wpshop_display::display_template_element('wpshop_product_variation_value_detail_container', array());
3004
+	}
3005 3005
 
3006
-    /**
3007
-     * Build the product structure with variation for product choosed by the user into frontend sheet
3008
-     *
3009
-     * @param array $selected_variation THe list of variation choosed by the user in product frontend sheet
3010
-     * @param integer $product_id The basic product choose by the user in frontend
3011
-     *
3012
-     * @return array The product list for adding to the cart build by variation priority
3013
-     */
3014
-    public static function get_variation_by_priority($selected_variation, $product_id, $add_to_cart_action = false)
3015
-    {
3016
-        global $wpdb;
3017
-        $all_required_variations_selected = $no_selected_variation = true;
3018
-        $single_variations = $combined_variations = $product_to_add_to_cart = array();
3019
-
3020
-        // Check if all required variations are selected
3021
-        $required_attributes_list = wpshop_prices::check_required_attributes($product_id);
3022
-        foreach ($selected_variation as $k => $value) {
3023
-            if ($value == 0 && in_array($k, $required_attributes_list)) {
3024
-                $all_required_variations_selected = false;
3025
-            }
3026
-            if ($value != 0) {
3027
-                $no_selected_variation = false;
3028
-            }
3029
-        }
3030
-        if (!empty($selected_variation)) {
3031
-            //Check variations configuration
3032
-            $product_variation_configuration = get_post_meta($product_id, '_wpshop_variation_defining', true);
3033
-            // Check variations type
3034
-            $product_variation_type = (!empty($product_variation_configuration) && !empty($product_variation_configuration['variation_type'])) ? $product_variation_configuration['variation_type'] : 'single';
3035
-            $product_to_add_to_cart[$product_id]['variation_priority'] = $product_variation_type;
3036
-
3037
-            //Check defined variation priority
3038
-            $priority = (!empty($product_variation_configuration['options']) && !empty($product_variation_configuration['options']['priority'][0])) ? $product_variation_configuration['options']['priority'][0] : 'combined';
3039
-            $product_to_add_to_cart[$product_id]['defined_variation_priority'] = $priority;
3040
-
3041
-            // Recover all product variations
3042
-            $query_variation = $selected_variation;
3043
-            // Delete free variations
3044
-            unset($query_variation['free']);
3045
-
3046
-            if ($product_variation_type == 'single') {
3047
-                // Get single variations
3048
-                $single_variations = array();
3049
-                foreach ($selected_variation as $attribute_code => $attribute_value) {
3050
-                    if (isset($attribute_value) && $attribute_code != 'free') {
3051
-                        $query = $wpdb->prepare("SELECT ID FROM " . $wpdb->postmeta . " AS P_META INNER JOIN " . $wpdb->posts . " as P ON ((P.ID = P_META.post_id) AND (P.post_parent = %d)) WHERE P_META.meta_value = '" . serialize(array($attribute_code => $attribute_value)) . "' OR P_META.meta_value = '" . serialize(array($attribute_code => (int) $attribute_value)) . "'", $product_id);
3052
-                        $single_variation_id = $wpdb->get_var($query);
3053
-                        if (!empty($single_variation_id)) {
3054
-                            $single_variations[] = $single_variation_id;
3055
-                            unset($query_variation[$attribute_code]);
3056
-                        }
3057
-                    }
3058
-                }
3059
-            } else {
3060
-                // Get combined variations
3061
-                $query = $wpdb->prepare("SELECT ID FROM " . $wpdb->postmeta . " AS P_META INNER JOIN " . $wpdb->posts . " as P ON ((P.ID = P_META.post_id) AND (P.post_parent = %d)) WHERE P_META.meta_key = '_wpshop_variations_attribute_def' AND P_META.meta_value = '" . serialize($query_variation) . "'", $product_id);
3062
-                $combined_variation_id = $wpdb->get_var($query);
3063
-                if (!empty($combined_variation_id)) {
3064
-                    $combined_variations[] = $combined_variation_id;
3065
-                }
3066
-
3067
-            }
3068
-
3069
-            //If all required variations are not selected
3070
-            if (!$all_required_variations_selected || $no_selected_variation) {
3071
-                $product_to_add_to_cart['text_from'] = 'on';
3072
-                // If we choose to display lower price variation combinaison
3073
-                if (empty($product_variation_configuration) || (!empty($product_variation_configuration) && empty($product_variation_configuration['options'])) || (!empty($product_variation_configuration) && !empty($product_variation_configuration['options']) && !empty($product_variation_configuration['options']['price_display']) && !empty($product_variation_configuration['options']['price_display']['lower_price']))) {
3074
-                    //Get lower price variation combinaison
3075
-                    $lower_price_variations = wpshop_prices::check_product_lower_price($product_id);
3076
-                    if (!empty($lower_price_variations['variations']) && is_array($lower_price_variations['variations'])) {
3077
-                        foreach ($lower_price_variations['variations'] as $lower_price_variation) {
3078
-                            $product_to_add_to_cart[$product_id]['variations'][] = $lower_price_variation;
3079
-                        }
3080
-                    }
3081
-                    $product_to_add_to_cart['display_lower_price'] = true;
3082
-                } else {
3083
-                    $product_to_add_to_cart[$product_id]['variations'] = array();
3084
-                }
3085
-            } else {
3086
-                $product_to_add_to_cart['text_from'] = '';
3087
-                $product_to_add_to_cart[$product_id]['variations'] = (!empty($product_variation_type) && $product_variation_type == 'single') ? $single_variations : $combined_variations;
3088
-            }
3089
-        }
3006
+	/**
3007
+	 * Build the product structure with variation for product choosed by the user into frontend sheet
3008
+	 *
3009
+	 * @param array $selected_variation THe list of variation choosed by the user in product frontend sheet
3010
+	 * @param integer $product_id The basic product choose by the user in frontend
3011
+	 *
3012
+	 * @return array The product list for adding to the cart build by variation priority
3013
+	 */
3014
+	public static function get_variation_by_priority($selected_variation, $product_id, $add_to_cart_action = false)
3015
+	{
3016
+		global $wpdb;
3017
+		$all_required_variations_selected = $no_selected_variation = true;
3018
+		$single_variations = $combined_variations = $product_to_add_to_cart = array();
3019
+
3020
+		// Check if all required variations are selected
3021
+		$required_attributes_list = wpshop_prices::check_required_attributes($product_id);
3022
+		foreach ($selected_variation as $k => $value) {
3023
+			if ($value == 0 && in_array($k, $required_attributes_list)) {
3024
+				$all_required_variations_selected = false;
3025
+			}
3026
+			if ($value != 0) {
3027
+				$no_selected_variation = false;
3028
+			}
3029
+		}
3030
+		if (!empty($selected_variation)) {
3031
+			//Check variations configuration
3032
+			$product_variation_configuration = get_post_meta($product_id, '_wpshop_variation_defining', true);
3033
+			// Check variations type
3034
+			$product_variation_type = (!empty($product_variation_configuration) && !empty($product_variation_configuration['variation_type'])) ? $product_variation_configuration['variation_type'] : 'single';
3035
+			$product_to_add_to_cart[$product_id]['variation_priority'] = $product_variation_type;
3036
+
3037
+			//Check defined variation priority
3038
+			$priority = (!empty($product_variation_configuration['options']) && !empty($product_variation_configuration['options']['priority'][0])) ? $product_variation_configuration['options']['priority'][0] : 'combined';
3039
+			$product_to_add_to_cart[$product_id]['defined_variation_priority'] = $priority;
3040
+
3041
+			// Recover all product variations
3042
+			$query_variation = $selected_variation;
3043
+			// Delete free variations
3044
+			unset($query_variation['free']);
3045
+
3046
+			if ($product_variation_type == 'single') {
3047
+				// Get single variations
3048
+				$single_variations = array();
3049
+				foreach ($selected_variation as $attribute_code => $attribute_value) {
3050
+					if (isset($attribute_value) && $attribute_code != 'free') {
3051
+						$query = $wpdb->prepare("SELECT ID FROM " . $wpdb->postmeta . " AS P_META INNER JOIN " . $wpdb->posts . " as P ON ((P.ID = P_META.post_id) AND (P.post_parent = %d)) WHERE P_META.meta_value = '" . serialize(array($attribute_code => $attribute_value)) . "' OR P_META.meta_value = '" . serialize(array($attribute_code => (int) $attribute_value)) . "'", $product_id);
3052
+						$single_variation_id = $wpdb->get_var($query);
3053
+						if (!empty($single_variation_id)) {
3054
+							$single_variations[] = $single_variation_id;
3055
+							unset($query_variation[$attribute_code]);
3056
+						}
3057
+					}
3058
+				}
3059
+			} else {
3060
+				// Get combined variations
3061
+				$query = $wpdb->prepare("SELECT ID FROM " . $wpdb->postmeta . " AS P_META INNER JOIN " . $wpdb->posts . " as P ON ((P.ID = P_META.post_id) AND (P.post_parent = %d)) WHERE P_META.meta_key = '_wpshop_variations_attribute_def' AND P_META.meta_value = '" . serialize($query_variation) . "'", $product_id);
3062
+				$combined_variation_id = $wpdb->get_var($query);
3063
+				if (!empty($combined_variation_id)) {
3064
+					$combined_variations[] = $combined_variation_id;
3065
+				}
3090 3066
 
3091
-        return $product_to_add_to_cart;
3092
-    }
3067
+			}
3093 3068
 
3094
-    public static function get_variation_price_behaviour($product_into_cart, $product_variations, $head_product_id, $variations_options)
3095
-    {
3096
-        global $wpdb;
3097
-
3098
-        if (!empty($product_variations)) {
3099
-            // Initialize variations total price datas
3100
-            $variations_total_price = array('price_et' => 0, 'vat_amount' => 0, 'price_ati' => 0);
3101
-            $variations_discount_total_price = array('price_et' => 0, 'vat_amount' => 0, 'price_ati' => 0);
3102
-            $vat_rate = 0;
3103
-            $discount_amount = $discount_rate = $special_price = 0;
3104
-            // Recover Head product metadata
3105
-            $head_product_metadata = get_post_meta($head_product_id, '_wpshop_product_metadata', true);
3106
-            $tva_rate_id = (!empty($head_product_metadata['tx_tva'])) ? $head_product_metadata['tx_tva'] : 0;
3107
-            if (!empty($tva_rate_id)) {
3108
-                // Recover VAT Rate of product
3109
-                $query = $wpdb->prepare('SELECT value FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id = %d', $tva_rate_id);
3110
-                $vat_rate = $wpdb->get_var($query);
3111
-            }
3112
-            $price_piloting = get_option('wpshop_shop_price_piloting');
3113
-            foreach ($product_variations as $product_variation) {
3114
-                $variation_metadata['product_price'] = 0;
3115
-                $variation_metadata = get_post_meta($product_variation, '_wpshop_product_metadata', true);
3116
-                if (!empty($variation_metadata)) {
3117
-                    $p_et = ((empty($price_piloting) || $price_piloting == 'TTC') ? ((!empty($variation_metadata['product_price']) ? $variation_metadata['product_price'] : 0) / (1 + ($vat_rate / 100))) : $variation_metadata['price_ht']);
3118
-                    $p_ati = ((empty($price_piloting) || $price_piloting == 'TTC') ? (!empty($variation_metadata['product_price']) ? $variation_metadata['product_price'] : 0) : ($variation_metadata['price_ht'] * (1 + ($vat_rate / 100))));
3119
-
3120
-                    $variations_total_price['price_et'] += $p_et;
3121
-                    $variations_total_price['price_ati'] += $p_ati;
3122
-                    $variations_total_price['vat_amount'] += $p_ati - $p_et;
3123
-
3124
-                    $variation_metadata['tx_tva'] = $product_into_cart['tx_tva'] = $vat_rate;
3125
-
3126
-                    // Check discount
3127
-                    $discount_config = wpshop_prices::check_discount_for_product($product_variation);
3128
-                    if (!empty($discount_config) && !empty($discount_config['value'])) {
3129
-                        $variation_discount_prices = wpshop_prices::calcul_discounted_price($variation_metadata, $discount_config);
3130
-                        $variations_discount_total_price['price_et'] += $variation_discount_prices['price_ht'];
3131
-                        $variations_discount_total_price['price_ati'] += $variation_discount_prices['product_price'];
3132
-                        $variations_discount_total_price['vat_amount'] += $variation_discount_prices['tva'];
3133
-
3134
-                        if (!empty($discount_config['type']) && $discount_config['type'] == 'discount_amount') {
3135
-                            $product_into_cart['discount_amount'] = $discount_amount + $product_into_cart['discount_amount'];
3136
-                        } elseif (!empty($discount_config['type']) && $discount_config['type'] == 'discount_rate') {
3137
-                            $product_into_cart['discount_rate'] = $discount_rate + $discount_config['value'];
3138
-                        } elseif (!empty($discount_config['type']) && $discount_config['type'] == 'special_price') {
3139
-                            $product_into_cart['special_price'] = $special_price + $discount_config['value'];
3140
-                        }
3141
-                    }
3142
-
3143
-                    $product_variation_def = wpshop_products::get_product_data($product_variation, true, '"publish", "draft"');
3144
-                    $product_into_cart['item_meta']['variations'][$product_variation] = $product_variation_def;
3145
-                }
3146
-            }
3147
-
3148
-            // Check if add or replace variation price to head product
3149
-            /**
3150
-             * Since 1.4.3.7
3151
-             * L'option du produit remplace le prix du produit de tête.
3152
-             */
3069
+			//If all required variations are not selected
3070
+			if (!$all_required_variations_selected || $no_selected_variation) {
3071
+				$product_to_add_to_cart['text_from'] = 'on';
3072
+				// If we choose to display lower price variation combinaison
3073
+				if (empty($product_variation_configuration) || (!empty($product_variation_configuration) && empty($product_variation_configuration['options'])) || (!empty($product_variation_configuration) && !empty($product_variation_configuration['options']) && !empty($product_variation_configuration['options']['price_display']) && !empty($product_variation_configuration['options']['price_display']['lower_price']))) {
3074
+					//Get lower price variation combinaison
3075
+					$lower_price_variations = wpshop_prices::check_product_lower_price($product_id);
3076
+					if (!empty($lower_price_variations['variations']) && is_array($lower_price_variations['variations'])) {
3077
+						foreach ($lower_price_variations['variations'] as $lower_price_variation) {
3078
+							$product_to_add_to_cart[$product_id]['variations'][] = $lower_price_variation;
3079
+						}
3080
+					}
3081
+					$product_to_add_to_cart['display_lower_price'] = true;
3082
+				} else {
3083
+					$product_to_add_to_cart[$product_id]['variations'] = array();
3084
+				}
3085
+			} else {
3086
+				$product_to_add_to_cart['text_from'] = '';
3087
+				$product_to_add_to_cart[$product_id]['variations'] = (!empty($product_variation_type) && $product_variation_type == 'single') ? $single_variations : $combined_variations;
3088
+			}
3089
+		}
3090
+
3091
+		return $product_to_add_to_cart;
3092
+	}
3093
+
3094
+	public static function get_variation_price_behaviour($product_into_cart, $product_variations, $head_product_id, $variations_options)
3095
+	{
3096
+		global $wpdb;
3097
+
3098
+		if (!empty($product_variations)) {
3099
+			// Initialize variations total price datas
3100
+			$variations_total_price = array('price_et' => 0, 'vat_amount' => 0, 'price_ati' => 0);
3101
+			$variations_discount_total_price = array('price_et' => 0, 'vat_amount' => 0, 'price_ati' => 0);
3102
+			$vat_rate = 0;
3103
+			$discount_amount = $discount_rate = $special_price = 0;
3104
+			// Recover Head product metadata
3105
+			$head_product_metadata = get_post_meta($head_product_id, '_wpshop_product_metadata', true);
3106
+			$tva_rate_id = (!empty($head_product_metadata['tx_tva'])) ? $head_product_metadata['tx_tva'] : 0;
3107
+			if (!empty($tva_rate_id)) {
3108
+				// Recover VAT Rate of product
3109
+				$query = $wpdb->prepare('SELECT value FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id = %d', $tva_rate_id);
3110
+				$vat_rate = $wpdb->get_var($query);
3111
+			}
3112
+			$price_piloting = get_option('wpshop_shop_price_piloting');
3113
+			foreach ($product_variations as $product_variation) {
3114
+				$variation_metadata['product_price'] = 0;
3115
+				$variation_metadata = get_post_meta($product_variation, '_wpshop_product_metadata', true);
3116
+				if (!empty($variation_metadata)) {
3117
+					$p_et = ((empty($price_piloting) || $price_piloting == 'TTC') ? ((!empty($variation_metadata['product_price']) ? $variation_metadata['product_price'] : 0) / (1 + ($vat_rate / 100))) : $variation_metadata['price_ht']);
3118
+					$p_ati = ((empty($price_piloting) || $price_piloting == 'TTC') ? (!empty($variation_metadata['product_price']) ? $variation_metadata['product_price'] : 0) : ($variation_metadata['price_ht'] * (1 + ($vat_rate / 100))));
3119
+
3120
+					$variations_total_price['price_et'] += $p_et;
3121
+					$variations_total_price['price_ati'] += $p_ati;
3122
+					$variations_total_price['vat_amount'] += $p_ati - $p_et;
3123
+
3124
+					$variation_metadata['tx_tva'] = $product_into_cart['tx_tva'] = $vat_rate;
3125
+
3126
+					// Check discount
3127
+					$discount_config = wpshop_prices::check_discount_for_product($product_variation);
3128
+					if (!empty($discount_config) && !empty($discount_config['value'])) {
3129
+						$variation_discount_prices = wpshop_prices::calcul_discounted_price($variation_metadata, $discount_config);
3130
+						$variations_discount_total_price['price_et'] += $variation_discount_prices['price_ht'];
3131
+						$variations_discount_total_price['price_ati'] += $variation_discount_prices['product_price'];
3132
+						$variations_discount_total_price['vat_amount'] += $variation_discount_prices['tva'];
3133
+
3134
+						if (!empty($discount_config['type']) && $discount_config['type'] == 'discount_amount') {
3135
+							$product_into_cart['discount_amount'] = $discount_amount + $product_into_cart['discount_amount'];
3136
+						} elseif (!empty($discount_config['type']) && $discount_config['type'] == 'discount_rate') {
3137
+							$product_into_cart['discount_rate'] = $discount_rate + $discount_config['value'];
3138
+						} elseif (!empty($discount_config['type']) && $discount_config['type'] == 'special_price') {
3139
+							$product_into_cart['special_price'] = $special_price + $discount_config['value'];
3140
+						}
3141
+					}
3142
+
3143
+					$product_variation_def = wpshop_products::get_product_data($product_variation, true, '"publish", "draft"');
3144
+					$product_into_cart['item_meta']['variations'][$product_variation] = $product_variation_def;
3145
+				}
3146
+			}
3147
+
3148
+			// Check if add or replace variation price to head product
3149
+			/**
3150
+			 * Since 1.4.3.7
3151
+			 * L'option du produit remplace le prix du produit de tête.
3152
+			 */
3153 3153
 			if( true ) {
3154
-                //Replace the product price
3155
-                if (!empty($variations_discount_total_price) && !empty($variations_discount_total_price['price_ati'])) {
3156
-                    $product_into_cart['price_ttc_before_discount'] = $variations_total_price['price_ati'];
3157
-                    $product_into_cart['price_ht_before_discount'] = $variations_total_price['price_et'];
3158
-
3159
-                    $product_into_cart['product_price'] = $variations_discount_total_price['price_ati'];
3160
-                    $product_into_cart['price_ht'] = $variations_discount_total_price['price_et'];
3161
-                    $product_into_cart['tva'] = $variations_discount_total_price['vat_amount'];
3162
-                } else {
3163
-                    $product_into_cart['product_price'] = $variations_total_price['price_ati'];
3164
-                    $product_into_cart['price_ht'] = $variations_total_price['price_et'];
3165
-                    $product_into_cart['tva'] = $variations_total_price['vat_amount'];
3166
-                }
3167
-            } else {
3168
-                // Add variations price to product price
3169
-                if (!empty($variations_discount_total_price) && !empty($variations_discount_total_price['price_ati'])) {
3170
-                    $product_into_cart['price_ttc_before_discount'] = ($product_into_cart['product_price'] + $variations_total_price['price_ati']);
3171
-                    $product_into_cart['price_ht_before_discount'] = ($product_into_cart['price_ht'] + $variations_total_price['price_et']);
3172
-
3173
-                    $product_into_cart['product_price'] += $variations_discount_total_price['price_ati'];
3174
-                    $product_into_cart['price_ht'] += $variations_discount_total_price['price_et'];
3175
-                    $product_into_cart['tva'] += $variations_discount_total_price['vat_amount'];
3176
-                } else {
3177
-                    $product_into_cart['product_price'] += $variations_total_price['price_ati'];
3178
-                    $product_into_cart['price_ht'] += $variations_total_price['price_et'];
3179
-                    $product_into_cart['tva'] += $variations_total_price['vat_amount'];
3180
-                }
3181
-                // Check parent discount
3182
-                $parent_discount_config = wpshop_prices::check_discount_for_product($head_product_id);
3183
-                if (!empty($parent_discount_config)) {
3184
-                    $product_into_cart['price_ttc_before_discount'] = (!empty($product_into_cart['price_ttc_before_discount'])) ? $product_into_cart['price_ttc_before_discount'] : $product_into_cart['product_price'];
3185
-                    $product_into_cart['price_ht_before_discount'] = (!empty($product_into_cart['price_ht_before_discount'])) ? $product_into_cart['price_ht_before_discount'] : $product_into_cart['price_ht'];
3186
-                    $product_into_cart = wpshop_prices::calcul_discounted_price($product_into_cart, $parent_discount_config);
3187
-
3188
-                    if (!empty($parent_discount_config['type']) && $parent_discount_config['type'] == 'discount_amount') {
3189
-                        $product_into_cart['discount_amount'] = $discount_amount + $parent_discount_config['value'];
3190
-                    } elseif (!empty($parent_discount_config['type']) && $parent_discount_config['type'] == 'discount_rate') {
3191
-                        $product_into_cart['discount_rate'] = $discount_rate + $parent_discount_config['value'];
3192
-                    } elseif (!empty($parent_discount_config['type']) && $parent_discount_config['type'] == 'special_price') {
3193
-                        $product_into_cart['special_price'] = $special_price + $parent_discount_config['value'];
3194
-                    }
3195
-                }
3196
-            }
3197
-        } else {
3198
-            // If product have just Free variations
3199
-            $discount_config = wpshop_prices::check_discount_for_product($head_product_id);
3200
-            if (!empty($discount_config)) {
3201
-                $product_into_cart['price_ttc_before_discount'] = (!empty($product_into_cart['price_ttc_before_discount'])) ? $product_into_cart['price_ttc_before_discount'] : $product_into_cart['product_price'];
3202
-                $product_into_cart['price_ht_before_discount'] = (!empty($product_into_cart['price_ht_before_discount'])) ? $product_into_cart['price_ht_before_discount'] : $product_into_cart['price_ht'];
3203
-                $product_into_cart = wpshop_prices::calcul_discounted_price($product_into_cart, $discount_config);
3204
-            }
3205
-        }
3154
+				//Replace the product price
3155
+				if (!empty($variations_discount_total_price) && !empty($variations_discount_total_price['price_ati'])) {
3156
+					$product_into_cart['price_ttc_before_discount'] = $variations_total_price['price_ati'];
3157
+					$product_into_cart['price_ht_before_discount'] = $variations_total_price['price_et'];
3158
+
3159
+					$product_into_cart['product_price'] = $variations_discount_total_price['price_ati'];
3160
+					$product_into_cart['price_ht'] = $variations_discount_total_price['price_et'];
3161
+					$product_into_cart['tva'] = $variations_discount_total_price['vat_amount'];
3162
+				} else {
3163
+					$product_into_cart['product_price'] = $variations_total_price['price_ati'];
3164
+					$product_into_cart['price_ht'] = $variations_total_price['price_et'];
3165
+					$product_into_cart['tva'] = $variations_total_price['vat_amount'];
3166
+				}
3167
+			} else {
3168
+				// Add variations price to product price
3169
+				if (!empty($variations_discount_total_price) && !empty($variations_discount_total_price['price_ati'])) {
3170
+					$product_into_cart['price_ttc_before_discount'] = ($product_into_cart['product_price'] + $variations_total_price['price_ati']);
3171
+					$product_into_cart['price_ht_before_discount'] = ($product_into_cart['price_ht'] + $variations_total_price['price_et']);
3172
+
3173
+					$product_into_cart['product_price'] += $variations_discount_total_price['price_ati'];
3174
+					$product_into_cart['price_ht'] += $variations_discount_total_price['price_et'];
3175
+					$product_into_cart['tva'] += $variations_discount_total_price['vat_amount'];
3176
+				} else {
3177
+					$product_into_cart['product_price'] += $variations_total_price['price_ati'];
3178
+					$product_into_cart['price_ht'] += $variations_total_price['price_et'];
3179
+					$product_into_cart['tva'] += $variations_total_price['vat_amount'];
3180
+				}
3181
+				// Check parent discount
3182
+				$parent_discount_config = wpshop_prices::check_discount_for_product($head_product_id);
3183
+				if (!empty($parent_discount_config)) {
3184
+					$product_into_cart['price_ttc_before_discount'] = (!empty($product_into_cart['price_ttc_before_discount'])) ? $product_into_cart['price_ttc_before_discount'] : $product_into_cart['product_price'];
3185
+					$product_into_cart['price_ht_before_discount'] = (!empty($product_into_cart['price_ht_before_discount'])) ? $product_into_cart['price_ht_before_discount'] : $product_into_cart['price_ht'];
3186
+					$product_into_cart = wpshop_prices::calcul_discounted_price($product_into_cart, $parent_discount_config);
3187
+
3188
+					if (!empty($parent_discount_config['type']) && $parent_discount_config['type'] == 'discount_amount') {
3189
+						$product_into_cart['discount_amount'] = $discount_amount + $parent_discount_config['value'];
3190
+					} elseif (!empty($parent_discount_config['type']) && $parent_discount_config['type'] == 'discount_rate') {
3191
+						$product_into_cart['discount_rate'] = $discount_rate + $parent_discount_config['value'];
3192
+					} elseif (!empty($parent_discount_config['type']) && $parent_discount_config['type'] == 'special_price') {
3193
+						$product_into_cart['special_price'] = $special_price + $parent_discount_config['value'];
3194
+					}
3195
+				}
3196
+			}
3197
+		} else {
3198
+			// If product have just Free variations
3199
+			$discount_config = wpshop_prices::check_discount_for_product($head_product_id);
3200
+			if (!empty($discount_config)) {
3201
+				$product_into_cart['price_ttc_before_discount'] = (!empty($product_into_cart['price_ttc_before_discount'])) ? $product_into_cart['price_ttc_before_discount'] : $product_into_cart['product_price'];
3202
+				$product_into_cart['price_ht_before_discount'] = (!empty($product_into_cart['price_ht_before_discount'])) ? $product_into_cart['price_ht_before_discount'] : $product_into_cart['price_ht'];
3203
+				$product_into_cart = wpshop_prices::calcul_discounted_price($product_into_cart, $discount_config);
3204
+			}
3205
+		}
3206 3206
 
3207
-        // Text From indicator
3208
-        if (!empty($variations_options) && !empty($variations_options['text_from'])) {
3209
-            $product_into_cart['text_from'] = $variations_options['text_from'];
3210
-        }
3211
-        return $product_into_cart;
3212
-    }
3207
+		// Text From indicator
3208
+		if (!empty($variations_options) && !empty($variations_options['text_from'])) {
3209
+			$product_into_cart['text_from'] = $variations_options['text_from'];
3210
+		}
3211
+		return $product_into_cart;
3212
+	}
3213 3213
 
3214
-    /**
3215
-     * Read an array with product options chosen by the customer, order into an array regarding admin definition
3216
-     *
3217
-     * @param array $product_definition_value The array with the selected product option to ordered
3218
-     * @param array $output_order The good order for attribute defined by administrator
3219
-     * @param dtring $from_page A string allowing to take a specific template regarding the current page
3220
-     *
3221
-     * @return array The array containing all product options ordered as the admin configure it
3222
-     */
3223
-    public static function get_selected_variation_display($product_definition_value, $output_order, $from_page = null, $template_part = 'wpshop', $output_type = null)
3224
-    {
3225
-        $variation_attribute_ordered = array();
3226
-        $variation_attribute_ordered['prices'] = array();
3227
-        $variation_attribute_ordered['attribute_list'] = array();
3228
-
3229
-        if (!empty($product_definition_value['variation_definition']) && is_array($product_definition_value['variation_definition'])) {
3230
-            foreach ($product_definition_value['variation_definition'] as $variation_attribute_code => $variation_attribute_detail) {
3231
-                $variation_tpl_component = array();
3232
-                foreach ($variation_attribute_detail as $info_name => $info_value) {
3233
-                    $variation_tpl_component['VARIATION_' . strtoupper($info_name)] = in_array($info_name, unserialize(WPSHOP_ATTRIBUTE_PRICES)) ? wpshop_display::format_field_output('wpshop_product_price', $info_value) : stripslashes($info_value);
3234
-                }
3235
-                $variation_tpl_component['VARIATION_ID'] = $variation_attribute_code;
3236
-                $variation_tpl_component['VARIATION_ATT_CODE'] = $variation_attribute_code;
3237
-                if (!empty($output_order[$variation_attribute_code])) {
3238
-                    $display_data = wpshop_display::display_template_element('cart_variation_detail', $variation_tpl_component, array('page' => $from_page, 'type' => WPSHOP_DBT_ATTRIBUTE, 'id' => $variation_attribute_code), $template_part);
3239
-                    if (!in_array($display_data, $variation_attribute_ordered['attribute_list'])) {
3240
-                        $variation_attribute_ordered['attribute_list'][$output_order[$variation_attribute_code]] = $display_data;
3241
-                    }
3242
-                } else {
3243
-                    $display_data = wpshop_display::display_template_element('cart_variation_detail', $variation_tpl_component, array('page' => $from_page, 'type' => WPSHOP_DBT_ATTRIBUTE, 'id' => $variation_attribute_code), $template_part);
3244
-                    if (!in_array($display_data, $variation_attribute_ordered['attribute_list'])) {
3245
-                        $variation_attribute_ordered['attribute_list'][] = $display_data;
3246
-                    }
3247
-                }
3248
-                unset($variation_tpl_component);
3249
-            }
3250
-        }
3214
+	/**
3215
+	 * Read an array with product options chosen by the customer, order into an array regarding admin definition
3216
+	 *
3217
+	 * @param array $product_definition_value The array with the selected product option to ordered
3218
+	 * @param array $output_order The good order for attribute defined by administrator
3219
+	 * @param dtring $from_page A string allowing to take a specific template regarding the current page
3220
+	 *
3221
+	 * @return array The array containing all product options ordered as the admin configure it
3222
+	 */
3223
+	public static function get_selected_variation_display($product_definition_value, $output_order, $from_page = null, $template_part = 'wpshop', $output_type = null)
3224
+	{
3225
+		$variation_attribute_ordered = array();
3226
+		$variation_attribute_ordered['prices'] = array();
3227
+		$variation_attribute_ordered['attribute_list'] = array();
3228
+
3229
+		if (!empty($product_definition_value['variation_definition']) && is_array($product_definition_value['variation_definition'])) {
3230
+			foreach ($product_definition_value['variation_definition'] as $variation_attribute_code => $variation_attribute_detail) {
3231
+				$variation_tpl_component = array();
3232
+				foreach ($variation_attribute_detail as $info_name => $info_value) {
3233
+					$variation_tpl_component['VARIATION_' . strtoupper($info_name)] = in_array($info_name, unserialize(WPSHOP_ATTRIBUTE_PRICES)) ? wpshop_display::format_field_output('wpshop_product_price', $info_value) : stripslashes($info_value);
3234
+				}
3235
+				$variation_tpl_component['VARIATION_ID'] = $variation_attribute_code;
3236
+				$variation_tpl_component['VARIATION_ATT_CODE'] = $variation_attribute_code;
3237
+				if (!empty($output_order[$variation_attribute_code])) {
3238
+					$display_data = wpshop_display::display_template_element('cart_variation_detail', $variation_tpl_component, array('page' => $from_page, 'type' => WPSHOP_DBT_ATTRIBUTE, 'id' => $variation_attribute_code), $template_part);
3239
+					if (!in_array($display_data, $variation_attribute_ordered['attribute_list'])) {
3240
+						$variation_attribute_ordered['attribute_list'][$output_order[$variation_attribute_code]] = $display_data;
3241
+					}
3242
+				} else {
3243
+					$display_data = wpshop_display::display_template_element('cart_variation_detail', $variation_tpl_component, array('page' => $from_page, 'type' => WPSHOP_DBT_ATTRIBUTE, 'id' => $variation_attribute_code), $template_part);
3244
+					if (!in_array($display_data, $variation_attribute_ordered['attribute_list'])) {
3245
+						$variation_attribute_ordered['attribute_list'][] = $display_data;
3246
+					}
3247
+				}
3248
+				unset($variation_tpl_component);
3249
+			}
3250
+		}
3251 3251
 
3252
-        if (!empty($product_definition_value['variations']) && is_array($product_definition_value['variations'])) {
3253
-            foreach ($product_definition_value['variations'] as $variation_id => $variation_details) {
3254
-                $variation_tpl_component = array();
3255
-                foreach ($variation_details as $info_name => $info_value) {
3256
-                    if ($info_name != 'item_meta') {
3257
-                        $variation_tpl_component['VARIATION_DETAIL_' . strtoupper($info_name)] = in_array($info_name, unserialize(WPSHOP_ATTRIBUTE_PRICES)) ? wpshop_display::format_field_output('wpshop_product_price', $info_value) : stripslashes($info_value);
3258
-                    }
3259
-                }
3260
-                foreach ($variation_details['item_meta']['variation_definition'] as $variation_attribute_code => $variation_attribute_def) {
3261
-                    $variation_tpl_component['VARIATION_NAME'] = stripslashes($variation_attribute_def['NAME']);
3262
-                    $variation_tpl_component['VARIATION_VALUE'] = stripslashes($variation_attribute_def['VALUE']);
3263
-                    $variation_tpl_component['VARIATION_ID'] = $variation_id;
3264
-                    $variation_tpl_component['VARIATION_ATT_CODE'] = $variation_attribute_code;
3265
-
3266
-                    $variation_attribute_ordered['prices'][$variation_attribute_code] = $variation_tpl_component['VARIATION_DETAIL_PRODUCT_PRICE'];
3267
-                }
3268
-                if (!empty($output_order[$variation_attribute_code])) {
3269
-                    $variation_attribute_ordered['attribute_list'][$output_order[$variation_attribute_code]] = wpshop_display::display_template_element('cart_variation_detail', $variation_tpl_component, array('page' => $from_page, 'type' => WPSHOP_DBT_ATTRIBUTE, 'id' => $variation_attribute_code), $template_part);
3270
-                }
3271
-                unset($variation_tpl_component);
3272
-            }
3273
-        }
3252
+		if (!empty($product_definition_value['variations']) && is_array($product_definition_value['variations'])) {
3253
+			foreach ($product_definition_value['variations'] as $variation_id => $variation_details) {
3254
+				$variation_tpl_component = array();
3255
+				foreach ($variation_details as $info_name => $info_value) {
3256
+					if ($info_name != 'item_meta') {
3257
+						$variation_tpl_component['VARIATION_DETAIL_' . strtoupper($info_name)] = in_array($info_name, unserialize(WPSHOP_ATTRIBUTE_PRICES)) ? wpshop_display::format_field_output('wpshop_product_price', $info_value) : stripslashes($info_value);
3258
+					}
3259
+				}
3260
+				foreach ($variation_details['item_meta']['variation_definition'] as $variation_attribute_code => $variation_attribute_def) {
3261
+					$variation_tpl_component['VARIATION_NAME'] = stripslashes($variation_attribute_def['NAME']);
3262
+					$variation_tpl_component['VARIATION_VALUE'] = stripslashes($variation_attribute_def['VALUE']);
3263
+					$variation_tpl_component['VARIATION_ID'] = $variation_id;
3264
+					$variation_tpl_component['VARIATION_ATT_CODE'] = $variation_attribute_code;
3274 3265
 
3275
-        /**    Free Variation part    */
3276
-        if (!empty($product_definition_value['free_variation']) && is_array($product_definition_value['free_variation'])) {
3277
-            foreach ($product_definition_value['free_variation'] as $build_variation_key => $build_variation) {
3278
-                if (strpos($build_variation, '-_variation_val_-')) {
3279
-                    $variation_definition = explode('-_variation_val_-', $build_variation);
3280
-                    $attribute_code = $variation_definition[0];
3281
-                    $attribute_selected_value = $variation_definition[1];
3282
-                } else {
3283
-                    $attribute_code = $build_variation_key;
3284
-                    $attribute_selected_value = $build_variation;
3285
-                }
3286
-
3287
-                $free_variation_attribute_def = wpshop_attributes::getElement($attribute_code, "'valid'", 'code');
3288
-                $variation_tpl_component['VARIATION_NAME'] = stripslashes($free_variation_attribute_def->frontend_label);
3289
-                $value_to_outut = $attribute_selected_value;
3290
-                switch ($free_variation_attribute_def->data_type) {
3291
-                    case 'datetime':
3292
-                        $value_to_outut = mysql2date(get_option('date_format'), $attribute_selected_value, true);
3293
-                        break;
3294
-                }
3295
-
3296
-                if (in_array($free_variation_attribute_def->backend_input, array('select', 'multiple-select'))) {
3297
-                    switch ($free_variation_attribute_def->data_type_to_use) {
3298
-                        case 'custom':
3299
-                        case 'internal':
3300
-                            $possible_values = wpshop_attributes::get_select_output($free_variation_attribute_def);
3301
-                            $value_to_outut = $possible_values['possible_value'][$attribute_selected_value];
3302
-                            break;
3303
-                    }
3304
-                }
3305
-                $variation_tpl_component['VARIATION_VALUE'] = stripslashes($value_to_outut);
3306
-                $variation_tpl_component['VARIATION_ID'] = $attribute_code;
3307
-                $variation_tpl_component['VARIATION_ATT_CODE'] = $attribute_code;
3308
-                if (!empty($value_to_outut) && !empty($output_order[$free_variation_attribute_def->code])) {
3309
-                    $display_data = wpshop_display::display_template_element('cart_variation_detail', $variation_tpl_component, array('page' => $from_page, 'type' => WPSHOP_DBT_ATTRIBUTE, 'id' => $attribute_code), $template_part);
3310
-                    if (!in_array($display_data, $variation_attribute_ordered['attribute_list'])) {
3311
-                        $variation_attribute_ordered['attribute_list'][$output_order[$free_variation_attribute_def->code]] = $display_data;
3312
-                    }
3313
-                }
3314
-                unset($variation_tpl_component);
3315
-            }
3316
-        }
3317
-        return $variation_attribute_ordered;
3318
-    }
3266
+					$variation_attribute_ordered['prices'][$variation_attribute_code] = $variation_tpl_component['VARIATION_DETAIL_PRODUCT_PRICE'];
3267
+				}
3268
+				if (!empty($output_order[$variation_attribute_code])) {
3269
+					$variation_attribute_ordered['attribute_list'][$output_order[$variation_attribute_code]] = wpshop_display::display_template_element('cart_variation_detail', $variation_tpl_component, array('page' => $from_page, 'type' => WPSHOP_DBT_ATTRIBUTE, 'id' => $variation_attribute_code), $template_part);
3270
+				}
3271
+				unset($variation_tpl_component);
3272
+			}
3273
+		}
3319 3274
 
3320
-    public function wps_selected_variation_picture($head_product_id, $variations)
3321
-    {
3322
-        $response = array();
3323
-        /** Selected Product image **/
3324
-        $post_thumbnail_id = get_post_thumbnail_id($head_product_id);
3325
-        if (!empty($post_thumbnail_id)) {
3326
-            $response['img_id'] = $post_thumbnail_id;
3327
-            $response['img'] = wp_get_attachment_image($post_thumbnail_id, 'wpshop-product-galery');
3328
-            $response['img_url'] = wp_get_attachment_url($post_thumbnail_id);
3329
-        }
3275
+		/**    Free Variation part    */
3276
+		if (!empty($product_definition_value['free_variation']) && is_array($product_definition_value['free_variation'])) {
3277
+			foreach ($product_definition_value['free_variation'] as $build_variation_key => $build_variation) {
3278
+				if (strpos($build_variation, '-_variation_val_-')) {
3279
+					$variation_definition = explode('-_variation_val_-', $build_variation);
3280
+					$attribute_code = $variation_definition[0];
3281
+					$attribute_selected_value = $variation_definition[1];
3282
+				} else {
3283
+					$attribute_code = $build_variation_key;
3284
+					$attribute_selected_value = $build_variation;
3285
+				}
3330 3286
 
3331
-        /** check if have one variation **/
3332
-        if (!empty($variations) && count($variations) == 1) {
3333
-            $variation_attached_image_id = get_post_meta($variations[0], '_wps_variation_attached_picture', true);
3334
-            if (!empty($variation_attached_image_id)) {
3335
-                $response['img_id'] = $variation_attached_image_id;
3336
-                $response['img'] = wp_get_attachment_image($variation_attached_image_id, 'wpshop-product-galery');
3337
-                $response['img_url'] = wp_get_attachment_url($variation_attached_image_id);
3338
-            }
3339
-        }
3340
-        return $response;
3341
-    }
3287
+				$free_variation_attribute_def = wpshop_attributes::getElement($attribute_code, "'valid'", 'code');
3288
+				$variation_tpl_component['VARIATION_NAME'] = stripslashes($free_variation_attribute_def->frontend_label);
3289
+				$value_to_outut = $attribute_selected_value;
3290
+				switch ($free_variation_attribute_def->data_type) {
3291
+					case 'datetime':
3292
+						$value_to_outut = mysql2date(get_option('date_format'), $attribute_selected_value, true);
3293
+						break;
3294
+				}
3342 3295
 
3343
-    /** Add a meta box of product sales history in product administration panel **/
3344
-    public function meta_box_product_sale_informations()
3345
-    {
3346
-        global $post;
3347
-        $product_id = $post->ID;
3348
-
3349
-        $variations = self::get_variation($product_id);
3350
-
3351
-        $sales_informations = array();
3352
-        /** Query **/
3353
-        $data_to_compare = '"item_id";s:' . strlen($product_id) . ':"' . $product_id . '";';
3354
-        $query_args = array('posts_per_page' => -1, 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ORDER, 'meta_query' => array(array('key' => '_order_postmeta', 'value' => $data_to_compare, 'compare' => 'LIKE')));
3355
-        $orders = new WP_Query($query_args);
3356
-        if (!empty($orders) && !empty($orders->posts)) {
3357
-            foreach ($orders->posts as $order) {
3358
-                $order_meta = get_post_meta($order->ID, '_order_postmeta', true);
3359
-                $order_info = get_post_meta($order->ID, '_order_info', true);
3360
-                $sales_informations[] = array(
3361
-                    'order_key' => (!empty($order_meta) && !empty($order_meta['order_key'])) ? $order_meta['order_key'] : '',
3362
-                    'order_date' => (!empty($order_meta) && !empty($order_meta['order_date'])) ? $order_meta['order_date'] : '',
3363
-                    'customer_firstname' => (!empty($order_info) && !empty($order_info['billing']) && !empty($order_info['billing']['address']) && !empty($order_info['billing']['address']['address_first_name'])) ? $order_info['billing']['address']['address_first_name'] : '',
3364
-                    'customer_name' => (!empty($order_info) && !empty($order_info['billing']) && !empty($order_info['billing']['address']) && !empty($order_info['billing']['address']['address_last_name'])) ? $order_info['billing']['address']['address_last_name'] : '',
3365
-                    'customer_email' => (!empty($order_info) && !empty($order_info['billing']) && !empty($order_info['billing']['address']) && !empty($order_info['billing']['address']['address_user_email'])) ? $order_info['billing']['address']['address_user_email'] : '',
3366
-                );
3367
-            }
3368
-        }
3296
+				if (in_array($free_variation_attribute_def->backend_input, array('select', 'multiple-select'))) {
3297
+					switch ($free_variation_attribute_def->data_type_to_use) {
3298
+						case 'custom':
3299
+						case 'internal':
3300
+							$possible_values = wpshop_attributes::get_select_output($free_variation_attribute_def);
3301
+							$value_to_outut = $possible_values['possible_value'][$attribute_selected_value];
3302
+							break;
3303
+					}
3304
+				}
3305
+				$variation_tpl_component['VARIATION_VALUE'] = stripslashes($value_to_outut);
3306
+				$variation_tpl_component['VARIATION_ID'] = $attribute_code;
3307
+				$variation_tpl_component['VARIATION_ATT_CODE'] = $attribute_code;
3308
+				if (!empty($value_to_outut) && !empty($output_order[$free_variation_attribute_def->code])) {
3309
+					$display_data = wpshop_display::display_template_element('cart_variation_detail', $variation_tpl_component, array('page' => $from_page, 'type' => WPSHOP_DBT_ATTRIBUTE, 'id' => $attribute_code), $template_part);
3310
+					if (!in_array($display_data, $variation_attribute_ordered['attribute_list'])) {
3311
+						$variation_attribute_ordered['attribute_list'][$output_order[$free_variation_attribute_def->code]] = $display_data;
3312
+					}
3313
+				}
3314
+				unset($variation_tpl_component);
3315
+			}
3316
+		}
3317
+		return $variation_attribute_ordered;
3318
+	}
3369 3319
 
3370
-        /** If product has been ordered **/
3371
-        $output = '';
3372
-        if (!empty($sales_informations)) {
3373
-            $output .= '<p>' . __('This product has been ordered', 'wpshop') . ' :</p>';
3374
-            $output .= '<ul>';
3375
-            foreach ($sales_informations as $sales_information) {
3376
-                $output .= '<li>' . sprintf(__('Ordered by %s %s (%s) on %s (Order ref. : %s)', 'wpshop'), $sales_information['customer_name'], $sales_information['customer_firstname'], $sales_information['customer_email'], $sales_information['order_date'], $sales_information['order_key']) . '</li>';
3377
-            }
3378
-            $output .= '</ul>';
3379
-        } else {
3380
-            $output .= __('This product has never been ordered', 'wpshop');
3381
-        }
3320
+	public function wps_selected_variation_picture($head_product_id, $variations)
3321
+	{
3322
+		$response = array();
3323
+		/** Selected Product image **/
3324
+		$post_thumbnail_id = get_post_thumbnail_id($head_product_id);
3325
+		if (!empty($post_thumbnail_id)) {
3326
+			$response['img_id'] = $post_thumbnail_id;
3327
+			$response['img'] = wp_get_attachment_image($post_thumbnail_id, 'wpshop-product-galery');
3328
+			$response['img_url'] = wp_get_attachment_url($post_thumbnail_id);
3329
+		}
3382 3330
 
3383
-        echo $output;
3384
-    }
3331
+		/** check if have one variation **/
3332
+		if (!empty($variations) && count($variations) == 1) {
3333
+			$variation_attached_image_id = get_post_meta($variations[0], '_wps_variation_attached_picture', true);
3334
+			if (!empty($variation_attached_image_id)) {
3335
+				$response['img_id'] = $variation_attached_image_id;
3336
+				$response['img'] = wp_get_attachment_image($variation_attached_image_id, 'wpshop-product-galery');
3337
+				$response['img_url'] = wp_get_attachment_url($variation_attached_image_id);
3338
+			}
3339
+		}
3340
+		return $response;
3341
+	}
3385 3342
 
3386
-    public function wps_get_summary_variations_product($product_id, $the_product, $has_variation)
3387
-    {
3388
-        global $wpdb, $wpshop_payment;
3389
-        $output = '';
3390
-        $tpl_component = array();
3391
-        /**    Get attribute order for current product    */
3392
-        $product_attribute_order_detail = wpshop_attributes_set::getAttributeSetDetails(get_post_meta($product_id, WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, true));
3393
-        $output_order = array();
3394
-        if (count($product_attribute_order_detail) > 0) {
3395
-            foreach ($product_attribute_order_detail as $product_attr_group_id => $product_attr_group_detail) {
3396
-                foreach ($product_attr_group_detail['attribut'] as $position => $attribute_def) {
3397
-                    if (!empty($attribute_def->code)) {
3398
-                        $output_order[$attribute_def->code] = $position;
3399
-                    }
3400
-
3401
-                }
3402
-            }
3403
-        }
3404
-        $variation_attribute_ordered = array();
3405
-
3406
-        /** Check if product is a variation and change his name **/
3407
-        $product_post_type = get_post_type($the_product['product_id']);
3408
-        if (!empty($product_post_type) && $product_post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) {
3409
-            $parent_infos = wpshop_products::get_parent_variation($the_product['product_id']);
3410
-            $parent_post = (!empty($parent_infos) && !empty($parent_infos['parent_post'])) ? $parent_infos['parent_post'] : array();
3411
-            $the_product['product_name'] = $the_product['post_title'] = $parent_post->post_title;
3412
-        }
3343
+	/** Add a meta box of product sales history in product administration panel **/
3344
+	public function meta_box_product_sale_informations()
3345
+	{
3346
+		global $post;
3347
+		$product_id = $post->ID;
3348
+
3349
+		$variations = self::get_variation($product_id);
3350
+
3351
+		$sales_informations = array();
3352
+		/** Query **/
3353
+		$data_to_compare = '"item_id";s:' . strlen($product_id) . ':"' . $product_id . '";';
3354
+		$query_args = array('posts_per_page' => -1, 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ORDER, 'meta_query' => array(array('key' => '_order_postmeta', 'value' => $data_to_compare, 'compare' => 'LIKE')));
3355
+		$orders = new WP_Query($query_args);
3356
+		if (!empty($orders) && !empty($orders->posts)) {
3357
+			foreach ($orders->posts as $order) {
3358
+				$order_meta = get_post_meta($order->ID, '_order_postmeta', true);
3359
+				$order_info = get_post_meta($order->ID, '_order_info', true);
3360
+				$sales_informations[] = array(
3361
+					'order_key' => (!empty($order_meta) && !empty($order_meta['order_key'])) ? $order_meta['order_key'] : '',
3362
+					'order_date' => (!empty($order_meta) && !empty($order_meta['order_date'])) ? $order_meta['order_date'] : '',
3363
+					'customer_firstname' => (!empty($order_info) && !empty($order_info['billing']) && !empty($order_info['billing']['address']) && !empty($order_info['billing']['address']['address_first_name'])) ? $order_info['billing']['address']['address_first_name'] : '',
3364
+					'customer_name' => (!empty($order_info) && !empty($order_info['billing']) && !empty($order_info['billing']['address']) && !empty($order_info['billing']['address']['address_last_name'])) ? $order_info['billing']['address']['address_last_name'] : '',
3365
+					'customer_email' => (!empty($order_info) && !empty($order_info['billing']) && !empty($order_info['billing']['address']) && !empty($order_info['billing']['address']['address_user_email'])) ? $order_info['billing']['address']['address_user_email'] : '',
3366
+				);
3367
+			}
3368
+		}
3413 3369
 
3414
-        foreach ($the_product as $product_definition_key => $product_definition_value) {
3415
-            if ($product_definition_key != 'item_meta') {
3416
-                $tpl_component['PRODUCT_MAIN_INFO_' . strtoupper($product_definition_key)] = $product_definition_value;
3417
-                if (!empty($wpshop_current_for_display) && in_array($product_definition_key, unserialize(WPSHOP_ATTRIBUTE_PRICES))) {
3418
-                    $tpl_component['PRODUCT_MAIN_INFO_' . strtoupper($product_definition_key)] = $product_definition_value;
3419
-                }
3420
-            } else {
3421
-                $variation_attribute_ordered = wpshop_products::get_selected_variation_display($product_definition_value, $output_order, 'selection_summary');
3422
-            }
3423
-        }
3370
+		/** If product has been ordered **/
3371
+		$output = '';
3372
+		if (!empty($sales_informations)) {
3373
+			$output .= '<p>' . __('This product has been ordered', 'wpshop') . ' :</p>';
3374
+			$output .= '<ul>';
3375
+			foreach ($sales_informations as $sales_information) {
3376
+				$output .= '<li>' . sprintf(__('Ordered by %s %s (%s) on %s (Order ref. : %s)', 'wpshop'), $sales_information['customer_name'], $sales_information['customer_firstname'], $sales_information['customer_email'], $sales_information['order_date'], $sales_information['order_key']) . '</li>';
3377
+			}
3378
+			$output .= '</ul>';
3379
+		} else {
3380
+			$output .= __('This product has never been ordered', 'wpshop');
3381
+		}
3424 3382
 
3425
-        ksort($variation_attribute_ordered['attribute_list']);
3426
-        $tpl_component['PRODUCT_VARIATION_SUMMARY_DETAILS'] = '';
3427
-        foreach ($variation_attribute_ordered['attribute_list'] as $attribute_variation_to_output) {
3428
-            $tpl_component['PRODUCT_VARIATION_SUMMARY_DETAILS'] .= $attribute_variation_to_output;
3429
-        }
3383
+		echo $output;
3384
+	}
3430 3385
 
3431
-        /**    For security get all attributes defined as user defined or used in variation in order to set default value to empty    */
3432
-        $attribute_list = wpshop_attributes::getElement('yes', "'valid'", "is_used_for_variation", true);
3433
-        if (!empty($attribute_list)) {
3434
-            foreach ($attribute_list as $attribute_def) {
3435
-                $tpl_component['VARIATION_SUMMARY_ATTRIBUTE_PER_PRICE_' . strtoupper($attribute_def->code)] = '-';
3436
-            }
3437
-        }
3386
+	public function wps_get_summary_variations_product($product_id, $the_product, $has_variation)
3387
+	{
3388
+		global $wpdb, $wpshop_payment;
3389
+		$output = '';
3390
+		$tpl_component = array();
3391
+		/**    Get attribute order for current product    */
3392
+		$product_attribute_order_detail = wpshop_attributes_set::getAttributeSetDetails(get_post_meta($product_id, WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, true));
3393
+		$output_order = array();
3394
+		if (count($product_attribute_order_detail) > 0) {
3395
+			foreach ($product_attribute_order_detail as $product_attr_group_id => $product_attr_group_detail) {
3396
+				foreach ($product_attr_group_detail['attribut'] as $position => $attribute_def) {
3397
+					if (!empty($attribute_def->code)) {
3398
+						$output_order[$attribute_def->code] = $position;
3399
+					}
3438 3400
 
3439
-        /**    Fill the array with all prices for different variations    */
3440
-        foreach ($variation_attribute_ordered['prices'] as $attribute => $prices) {
3441
-            $tpl_component['VARIATION_SUMMARY_ATTRIBUTE_PER_PRICE_' . strtoupper($attribute)] = $prices;
3442
-        }
3401
+				}
3402
+			}
3403
+		}
3404
+		$variation_attribute_ordered = array();
3405
+
3406
+		/** Check if product is a variation and change his name **/
3407
+		$product_post_type = get_post_type($the_product['product_id']);
3408
+		if (!empty($product_post_type) && $product_post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) {
3409
+			$parent_infos = wpshop_products::get_parent_variation($the_product['product_id']);
3410
+			$parent_post = (!empty($parent_infos) && !empty($parent_infos['parent_post'])) ? $parent_infos['parent_post'] : array();
3411
+			$the_product['product_name'] = $the_product['post_title'] = $parent_post->post_title;
3412
+		}
3443 3413
 
3444
-        $tpl_component['PRODUCT_VARIATION_SUMMARY_MORE_CONTENT'] = '';
3445
-        $query = $wpdb->prepare("SELECT post_id, meta_value FROM " . $wpdb->postmeta . " WHERE meta_key = %s ", '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_options');
3446
-        $post_list_with_options = $wpdb->get_results($query);
3447
-        if (!empty($post_list_with_options)) {
3448
-            $additionnal_price = 0;
3449
-            foreach ($post_list_with_options as $product_info) {
3450
-                $product_meta = unserialize($product_info->meta_value);
3451
-                if (!empty($product_meta['cart']) && !empty($product_meta['cart']['auto_add']) && ($product_meta['cart']['auto_add'] == 'yes')) {
3452
-                    $product = wpshop_products::get_product_data($product_info->post_id, true, '"publish", "draft"');
3453
-
3454
-                    $the_product = array_merge(array(
3455
-                        'product_id' => $product_info->post_id,
3456
-                        'product_qty' => 1,
3457
-                    ), $product);
3458
-
3459
-                    $additionnal_price += (!$different_currency || ($change_rate == 1)) ? $the_product['product_price'] : ($the_product['product_price'] * $change_rate);
3460
-                    $tpl_component['AUTO_PRODUCT_NAME'] = $the_product['product_name'];
3461
-
3462
-                    $tpl_component['AUTO_PRODUCT_PRODUCT_PRICE'] = wpshop_display::format_field_output('wpshop_product_price', (!$different_currency || ($change_rate == 1)) ? $the_product['product_price'] : ($the_product['product_price'] * $change_rate));
3463
-                    $tpl_component['PRODUCT_VARIATION_SUMMARY_MORE_CONTENT'] = wpshop_display::display_template_element('wpshop_product_configuration_summary_detail_auto_product', $tpl_component);
3464
-                }
3465
-            }
3466
-        }
3414
+		foreach ($the_product as $product_definition_key => $product_definition_value) {
3415
+			if ($product_definition_key != 'item_meta') {
3416
+				$tpl_component['PRODUCT_MAIN_INFO_' . strtoupper($product_definition_key)] = $product_definition_value;
3417
+				if (!empty($wpshop_current_for_display) && in_array($product_definition_key, unserialize(WPSHOP_ATTRIBUTE_PRICES))) {
3418
+					$tpl_component['PRODUCT_MAIN_INFO_' . strtoupper($product_definition_key)] = $product_definition_value;
3419
+				}
3420
+			} else {
3421
+				$variation_attribute_ordered = wpshop_products::get_selected_variation_display($product_definition_value, $output_order, 'selection_summary');
3422
+			}
3423
+		}
3467 3424
 
3468
-        $tpl_component['PRODUCT_VARIATION_SUMMARY_GRAND_TOTAL'] = '';
3469
-        $tpl_component['SUMMARY_FINAL_RESULT_PRICE_NO_FORMAT'] = '';
3470
-        if (!empty($additionnal_price)) {
3471
-            $tpl_component['SUMMARY_FINAL_RESULT_PRICE'] = wpshop_display::format_field_output('wpshop_product_price', $tpl_component['PRODUCT_MAIN_INFO_PRODUCT_PRICE'] + $additionnal_price);
3472
-            $tpl_component['SUMMARY_FINAL_RESULT_PRICE_NO_FORMAT'] = ($tpl_component['PRODUCT_MAIN_INFO_PRODUCT_PRICE'] + $additionnal_price);
3473
-            $tpl_component['PRODUCT_VARIATION_SUMMARY_GRAND_TOTAL'] = wpshop_display::display_template_element('wpshop_product_configuration_summary_detail_final_result', $tpl_component);
3474
-        }
3425
+		ksort($variation_attribute_ordered['attribute_list']);
3426
+		$tpl_component['PRODUCT_VARIATION_SUMMARY_DETAILS'] = '';
3427
+		foreach ($variation_attribute_ordered['attribute_list'] as $attribute_variation_to_output) {
3428
+			$tpl_component['PRODUCT_VARIATION_SUMMARY_DETAILS'] .= $attribute_variation_to_output;
3429
+		}
3430
+
3431
+		/**    For security get all attributes defined as user defined or used in variation in order to set default value to empty    */
3432
+		$attribute_list = wpshop_attributes::getElement('yes', "'valid'", "is_used_for_variation", true);
3433
+		if (!empty($attribute_list)) {
3434
+			foreach ($attribute_list as $attribute_def) {
3435
+				$tpl_component['VARIATION_SUMMARY_ATTRIBUTE_PER_PRICE_' . strtoupper($attribute_def->code)] = '-';
3436
+			}
3437
+		}
3438
+
3439
+		/**    Fill the array with all prices for different variations    */
3440
+		foreach ($variation_attribute_ordered['prices'] as $attribute => $prices) {
3441
+			$tpl_component['VARIATION_SUMMARY_ATTRIBUTE_PER_PRICE_' . strtoupper($attribute)] = $prices;
3442
+		}
3443
+
3444
+		$tpl_component['PRODUCT_VARIATION_SUMMARY_MORE_CONTENT'] = '';
3445
+		$query = $wpdb->prepare("SELECT post_id, meta_value FROM " . $wpdb->postmeta . " WHERE meta_key = %s ", '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_options');
3446
+		$post_list_with_options = $wpdb->get_results($query);
3447
+		if (!empty($post_list_with_options)) {
3448
+			$additionnal_price = 0;
3449
+			foreach ($post_list_with_options as $product_info) {
3450
+				$product_meta = unserialize($product_info->meta_value);
3451
+				if (!empty($product_meta['cart']) && !empty($product_meta['cart']['auto_add']) && ($product_meta['cart']['auto_add'] == 'yes')) {
3452
+					$product = wpshop_products::get_product_data($product_info->post_id, true, '"publish", "draft"');
3453
+
3454
+					$the_product = array_merge(array(
3455
+						'product_id' => $product_info->post_id,
3456
+						'product_qty' => 1,
3457
+					), $product);
3458
+
3459
+					$additionnal_price += (!$different_currency || ($change_rate == 1)) ? $the_product['product_price'] : ($the_product['product_price'] * $change_rate);
3460
+					$tpl_component['AUTO_PRODUCT_NAME'] = $the_product['product_name'];
3461
+
3462
+					$tpl_component['AUTO_PRODUCT_PRODUCT_PRICE'] = wpshop_display::format_field_output('wpshop_product_price', (!$different_currency || ($change_rate == 1)) ? $the_product['product_price'] : ($the_product['product_price'] * $change_rate));
3463
+					$tpl_component['PRODUCT_VARIATION_SUMMARY_MORE_CONTENT'] = wpshop_display::display_template_element('wpshop_product_configuration_summary_detail_auto_product', $tpl_component);
3464
+				}
3465
+			}
3466
+		}
3475 3467
 
3476
-        /**    Call informtion for partial payment    */
3477
-        $partial_payment = $wpshop_payment->partial_payment_calcul($tpl_component['SUMMARY_FINAL_RESULT_PRICE_NO_FORMAT']);
3478
-        $tpl_component['PARTIAL_PAYMENT_INFO'] = !empty($partial_payment['amount_to_pay']) ? $partial_payment['display'] : '';
3468
+		$tpl_component['PRODUCT_VARIATION_SUMMARY_GRAND_TOTAL'] = '';
3469
+		$tpl_component['SUMMARY_FINAL_RESULT_PRICE_NO_FORMAT'] = '';
3470
+		if (!empty($additionnal_price)) {
3471
+			$tpl_component['SUMMARY_FINAL_RESULT_PRICE'] = wpshop_display::format_field_output('wpshop_product_price', $tpl_component['PRODUCT_MAIN_INFO_PRODUCT_PRICE'] + $additionnal_price);
3472
+			$tpl_component['SUMMARY_FINAL_RESULT_PRICE_NO_FORMAT'] = ($tpl_component['PRODUCT_MAIN_INFO_PRODUCT_PRICE'] + $additionnal_price);
3473
+			$tpl_component['PRODUCT_VARIATION_SUMMARY_GRAND_TOTAL'] = wpshop_display::display_template_element('wpshop_product_configuration_summary_detail_final_result', $tpl_component);
3474
+		}
3479 3475
 
3480
-        /**    Define the current selected currency for the order summary    */
3476
+		/**    Call informtion for partial payment    */
3477
+		$partial_payment = $wpshop_payment->partial_payment_calcul($tpl_component['SUMMARY_FINAL_RESULT_PRICE_NO_FORMAT']);
3478
+		$tpl_component['PARTIAL_PAYMENT_INFO'] = !empty($partial_payment['amount_to_pay']) ? $partial_payment['display'] : '';
3479
+
3480
+		/**    Define the current selected currency for the order summary    */
3481 3481
 //         $response['product_output'] = $has_variation ? wpshop_display::display_template_element('wpshop_product_configuration_summary_detail', $tpl_component) : '';
3482
-        $output = $has_variation ? wpshop_display::display_template_element('wpshop_product_configuration_summary_detail', $tpl_component) : '';
3483
-        return $output;
3484
-    }
3482
+		$output = $has_variation ? wpshop_display::display_template_element('wpshop_product_configuration_summary_detail', $tpl_component) : '';
3483
+		return $output;
3484
+	}
3485 3485
 
3486
-    /**
3487
-     * Get product ID if ID = "id-parent__id-variation" or "id-variation" or "id-parent"
3488
-     * @param string $ID ID product variations or not
3489
-     * @return string Return ID
3490
-     */
3491
-    public static function get_id_variation($ID)
3492
-    {
3493
-        $result = explode('__', $ID);
3494
-        return end($result);
3495
-    }
3486
+	/**
3487
+	 * Get product ID if ID = "id-parent__id-variation" or "id-variation" or "id-parent"
3488
+	 * @param string $ID ID product variations or not
3489
+	 * @return string Return ID
3490
+	 */
3491
+	public static function get_id_variation($ID)
3492
+	{
3493
+		$result = explode('__', $ID);
3494
+		return end($result);
3495
+	}
3496 3496
 
3497
-    /**
3498
-     * Update all variations definitions who not modified
3499
-     * @param array $new_value
3500
-     * @param array $old_value
3501
-     * @return array $new_value
3502
-     */
3503
-    public static function update_wpshop_catalog_product_option($new_value, $old_value)
3504
-    {
3505
-        global $wpdb;
3506
-        $query = $wpdb->prepare('SELECT post_id, meta_value FROM ' . $wpdb->postmeta . ' WHERE meta_key LIKE %s AND meta_value LIKE %s', '_wpshop_variation_defining', '%' . serialize('follow_general_config') . '%');
3507
-        foreach ($wpdb->get_results($query) as $wpshop_variation_defining) {
3508
-            $wpshop_variation_defining_value = unserialize($wpshop_variation_defining->meta_value);
3509
-            $wpshop_variation_defining_value['options']['price_display'] = $new_value['price_display'];
3510
-            update_post_meta($wpshop_variation_defining->post_id, '_wpshop_variation_defining', $wpshop_variation_defining_value);
3511
-        }
3512
-        return $new_value;
3513
-    }
3497
+	/**
3498
+	 * Update all variations definitions who not modified
3499
+	 * @param array $new_value
3500
+	 * @param array $old_value
3501
+	 * @return array $new_value
3502
+	 */
3503
+	public static function update_wpshop_catalog_product_option($new_value, $old_value)
3504
+	{
3505
+		global $wpdb;
3506
+		$query = $wpdb->prepare('SELECT post_id, meta_value FROM ' . $wpdb->postmeta . ' WHERE meta_key LIKE %s AND meta_value LIKE %s', '_wpshop_variation_defining', '%' . serialize('follow_general_config') . '%');
3507
+		foreach ($wpdb->get_results($query) as $wpshop_variation_defining) {
3508
+			$wpshop_variation_defining_value = unserialize($wpshop_variation_defining->meta_value);
3509
+			$wpshop_variation_defining_value['options']['price_display'] = $new_value['price_display'];
3510
+			update_post_meta($wpshop_variation_defining->post_id, '_wpshop_variation_defining', $wpshop_variation_defining_value);
3511
+		}
3512
+		return $new_value;
3513
+	}
3514 3514
 
3515
-    public static function variation_parameters_save($current_post_id, $options)
3516
-    {
3515
+	public static function variation_parameters_save($current_post_id, $options)
3516
+	{
3517 3517
 		$variation_post_meta = get_post_meta($current_post_id, '_wpshop_variation_defining', true);
3518
-        $variation_post_meta['options'] = $options;
3518
+		$variation_post_meta['options'] = $options;
3519 3519
 		$variation_post_meta['follow_general_config'] = true;
3520 3520
 		if( $variation_post_meta['follow_general_config'] ) {
3521 3521
 			$shop_option = get_option('wpshop_catalog_product_option', array());
@@ -3531,6 +3531,6 @@  discard block
 block discarded – undo
3531 3531
 				}
3532 3532
 			}
3533 3533
 		}
3534
-        update_post_meta($current_post_id, '_wpshop_variation_defining', $variation_post_meta);
3535
-    }
3534
+		update_post_meta($current_post_id, '_wpshop_variation_defining', $variation_post_meta);
3535
+	}
3536 3536
 }
Please login to merge, or discard this patch.
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -184,20 +184,20 @@  discard block
 block discarded – undo
184 184
 	public static function admin_menu() {
185 185
 		global $submenu;
186 186
 		$attributeEntitySetList = wpshop_attributes_set::get_attribute_set_list_for_entity(wpshop_entities::get_entity_identifier_from_code(self::currentPageCode));
187
-		$entities_to_unset = array( 'free_product', 'default' );
187
+		$entities_to_unset = array('free_product', 'default');
188 188
 		$submenu_before = $submenu['edit.php?post_type=wpshop_product'];
189 189
 		foreach ($attributeEntitySetList as $key_attribute_set => $attribute_set) {
190
-			if ( !( in_array( $attribute_set->slug, $entities_to_unset ) || in_array( $attribute_set->name, $entities_to_unset ) ) ) {
191
-				add_submenu_page( 'edit.php?post_type=wpshop_product', sprintf( __( 'Add %s', 'wpshop' ), $attribute_set->name), sprintf( __( 'Add %s', 'wpshop' ), $attribute_set->name), 'edit_posts', 'post-new.php?attribute_set=' . $attribute_set->id . '&post_type=wpshop_product');
190
+			if (!(in_array($attribute_set->slug, $entities_to_unset) || in_array($attribute_set->name, $entities_to_unset))) {
191
+				add_submenu_page('edit.php?post_type=wpshop_product', sprintf(__('Add %s', 'wpshop'), $attribute_set->name), sprintf(__('Add %s', 'wpshop'), $attribute_set->name), 'edit_posts', 'post-new.php?attribute_set=' . $attribute_set->id . '&post_type=wpshop_product');
192 192
 			}
193 193
 		}
194
-		$submenu_new_elements = array_diff_key ( $submenu['edit.php?post_type=wpshop_product'], $submenu_before );
194
+		$submenu_new_elements = array_diff_key($submenu['edit.php?post_type=wpshop_product'], $submenu_before);
195 195
 		$submenu_reorder = array();
196
-		foreach( $submenu_before as $key => $element ) {
197
-			if( empty( $submenu_reorder[$key] ) ) {
196
+		foreach ($submenu_before as $key => $element) {
197
+			if (empty($submenu_reorder[$key])) {
198 198
 				$submenu_reorder[$key] = $element;
199
-				if( in_array( 'post-new.php?post_type=wpshop_product', $element ) ) {
200
-					$submenu_reorder = array_merge( $submenu_reorder, array_values( $submenu_new_elements ) );
199
+				if (in_array('post-new.php?post_type=wpshop_product', $element)) {
200
+					$submenu_reorder = array_merge($submenu_reorder, array_values($submenu_new_elements));
201 201
 				}
202 202
 			} else {
203 203
 				$submenu_reorder[] = $element;
@@ -604,12 +604,12 @@  discard block
 block discarded – undo
604 604
 
605 605
         $products = array();
606 606
         $query = "SELECT * FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE code=%s";
607
-        $data = (array) $wpdb->get_row($wpdb->prepare($query, $attr_name));
607
+        $data = (array)$wpdb->get_row($wpdb->prepare($query, $attr_name));
608 608
 
609 609
         if (!empty($data)) {
610 610
             if ($data['data_type_to_use'] == 'custom') {
611 611
                 // Find which table to take
612
-                if ($data['data_type'] == 'datetime') {$table_name = WPSHOP_DBT_ATTRIBUTE_VALUES_DATETIME;} elseif ($data['data_type'] == 'decimal') {$table_name = WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL;} elseif ($data['data_type'] == 'integer') {$table_name = WPSHOP_DBT_ATTRIBUTE_VALUES_INTEGER;} elseif ($data['data_type'] == 'options') {$table_name = WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS;} elseif ($data['data_type'] == 'text') {$table_name = WPSHOP_DBT_ATTRIBUTE_VALUES_TEXT;} elseif ($data['data_type'] == 'varchar') {$table_name = WPSHOP_DBT_ATTRIBUTE_VALUES_VARCHAR;}
612
+                if ($data['data_type'] == 'datetime') {$table_name = WPSHOP_DBT_ATTRIBUTE_VALUES_DATETIME; } elseif ($data['data_type'] == 'decimal') {$table_name = WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL; } elseif ($data['data_type'] == 'integer') {$table_name = WPSHOP_DBT_ATTRIBUTE_VALUES_INTEGER; } elseif ($data['data_type'] == 'options') {$table_name = WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS; } elseif ($data['data_type'] == 'text') {$table_name = WPSHOP_DBT_ATTRIBUTE_VALUES_TEXT; } elseif ($data['data_type'] == 'varchar') {$table_name = WPSHOP_DBT_ATTRIBUTE_VALUES_VARCHAR; }
613 613
 
614 614
                 if (isset($table_name)) {
615 615
                     // If the value is an id of a select, radio or checkbox
@@ -759,11 +759,11 @@  discard block
 block discarded – undo
759 759
         if (!empty($atts['product_type'])) {
760 760
             switch ($atts['product_type']) {
761 761
                 case 'related':
762
-                    $product_id = !empty($atts['pid']) ? (int) $atts['pid'] : get_the_ID();
762
+                    $product_id = !empty($atts['pid']) ? (int)$atts['pid'] : get_the_ID();
763 763
                     $type = !empty($atts['display_mode']) && in_array($atts['display_mode'], array('list', 'grid')) ? $atts['display_mode'] : WPSHOP_DISPLAY_LIST_TYPE;
764 764
                     $grid_element_nb_per_line = !empty($atts['grid_element_nb_per_line']) ? $atts['grid_element_nb_per_line'] : WPSHOP_DISPLAY_GRID_ELEMENT_NUMBER_PER_LINE;
765 765
 
766
-                    $pids = get_post_meta((int) $product_id, WPSHOP_PRODUCT_RELATED_PRODUCTS, true);
766
+                    $pids = get_post_meta((int)$product_id, WPSHOP_PRODUCT_RELATED_PRODUCTS, true);
767 767
                     if (!empty($pids) && !empty($pids[0])) {
768 768
                         $pid = implode(',', $pids);
769 769
                     }
@@ -832,7 +832,7 @@  discard block
 block discarded – undo
832 832
                     $sub_tpl_component = array();
833 833
                     $criteria = '';
834 834
                     foreach ($sorting_criteria as $c):
835
-                        $criteria .= '<option value="' . $c['code'] . '" ' . selected( $atts['order'], $c['code'], false ) . '>' . __($c['frontend_label'], 'wpshop') . '</option>';
835
+                        $criteria .= '<option value="' . $c['code'] . '" ' . selected($atts['order'], $c['code'], false) . '>' . __($c['frontend_label'], 'wpshop') . '</option>';
836 836
                     endforeach;
837 837
                     $sub_tpl_component['SORTING_CRITERIA_LIST'] = $criteria;
838 838
                     $tpl_component['SORTING_CRITERIA'] = wpshop_display::display_template_element($sub_template_part, $sub_tpl_component);
@@ -1001,7 +1001,7 @@  discard block
 block discarded – undo
1001 1001
             // --------------------- //
1002 1002
             // Pagination management //
1003 1003
             // --------------------- //
1004
-            if ( $display_pagination ) {
1004
+            if ($display_pagination) {
1005 1005
                 if ($nb_of_product_limit == 0) {
1006 1006
 
1007 1007
                     $paginate = paginate_links(array(
@@ -1282,7 +1282,7 @@  discard block
 block discarded – undo
1282 1282
     {
1283 1283
         global $wpdb;
1284 1284
 
1285
-        $data_to_save = (!empty($data_to_save)) ? $data_to_save : (array) $_REQUEST;
1285
+        $data_to_save = (!empty($data_to_save)) ? $data_to_save : (array)$_REQUEST;
1286 1286
         // Apply a filter to extra actions
1287 1287
         $data_to_save = apply_filters('wps_save_product_extra_filter', $data_to_save);
1288 1288
 
@@ -1338,7 +1338,7 @@  discard block
 block discarded – undo
1338 1338
                             $attributeValue = str_replace(',', '.', $attributeValue);
1339 1339
                         }
1340 1340
                         if (($attributeType == 'integer') && !is_array($attributeValue)) {
1341
-                            $attributeValue = (int) $attributeValue;
1341
+                            $attributeValue = (int)$attributeValue;
1342 1342
                         }
1343 1343
                         $productMetaDatas[$attributeCode] = $attributeValue;
1344 1344
                     }
@@ -1388,7 +1388,7 @@  discard block
 block discarded – undo
1388 1388
                                     $attributeValue = str_replace(',', '.', $attribute->$value_key);
1389 1389
                                 }
1390 1390
                                 if (($attribute->data_type == 'integer') && !is_array($attributeValue)) {
1391
-                                    $attributeValue = (int) $attribute->$value_key;
1391
+                                    $attributeValue = (int)$attribute->$value_key;
1392 1392
                                 }
1393 1393
                                 $variation_metadata[$attribute->code] = $attribute->$value_key;
1394 1394
                             }
@@ -1401,7 +1401,7 @@  discard block
 block discarded – undo
1401 1401
                                 $attributeValue = str_replace(',', '.', $attributeValue);
1402 1402
                             }
1403 1403
                             if (($attributeType == 'integer') && !is_array($attributeValue)) {
1404
-                                $attributeValue = (int) $attributeValue;
1404
+                                $attributeValue = (int)$attributeValue;
1405 1405
                             }
1406 1406
                             $variation_metadata[$attributeCode] = $attributeValue;
1407 1407
                         }
@@ -1737,13 +1737,13 @@  discard block
 block discarded – undo
1737 1737
             if (!empty($product_price_infos)) {
1738 1738
                 $tpl_component_price = array();
1739 1739
                 /** Price piloting **/
1740
-				$price_display_option = get_option( 'wpshop_catalog_product_option' );
1741
-				$tpl_component['PRICE_FROM'] = (!empty($price_display_option) && !empty($price_display_option['price_display']) && !empty($price_display_option['price_display']['text_from']) ) ? 'on' : '';
1740
+				$price_display_option = get_option('wpshop_catalog_product_option');
1741
+				$tpl_component['PRICE_FROM'] = (!empty($price_display_option) && !empty($price_display_option['price_display']) && !empty($price_display_option['price_display']['text_from'])) ? 'on' : '';
1742 1742
                 $price_ploting = get_option('wpshop_shop_price_piloting');
1743 1743
                 $tpl_component_price['CROSSED_OUT_PRICE'] = (!empty($product_price_infos['CROSSED_OUT_PRICE'])) ? ((!empty($product_price_infos['PRICE_FROM'])) ? __('Price from', 'wpshop') . ' ' : '') . wpshop_display::display_template_element('product_price_template_crossed_out_price', array('CROSSED_OUT_PRICE_VALUE' => $product_price_infos['CROSSED_OUT_PRICE'])) : '';
1744 1744
                 $variations = wpshop_products::get_variation($product_id);
1745 1745
 				$tpl_component_price['PRODUCT_PRICE'] = $product_price_infos['PRODUCT_PRICE'];
1746
-				if(empty($product_price_infos['CROSSED_OUT_PRICE']) && (!empty($variations) && (!empty($product_price_infos['PRICE_FROM']) || !empty( $tpl_component['PRICE_FROM'] ) ))) {
1746
+				if (empty($product_price_infos['CROSSED_OUT_PRICE']) && (!empty($variations) && (!empty($product_price_infos['PRICE_FROM']) || !empty($tpl_component['PRICE_FROM'])))) {
1747 1747
 					$tpl_component_price['PRODUCT_PRICE'] = __('Price from', 'wpshop') . ' ' . $tpl_component_price['PRODUCT_PRICE'];
1748 1748
 				}
1749 1749
                 $tpl_component_price['MESSAGE_SAVE_MONEY'] = $product_price_infos['MESSAGE_SAVE_MONEY'];
@@ -2186,7 +2186,7 @@  discard block
 block discarded – undo
2186 2186
             }
2187 2187
 
2188 2188
             $template_part = ($variations_list && ($output_type == 'mini')) ? 'configure_product_button' : (!empty($productStock) ? 'add_to_cart_button' : 'unavailable_product_button');
2189
-						$template_part = apply_filters( 'wps_custom_add_to_cart_button', $template_part, $product_id );
2189
+						$template_part = apply_filters('wps_custom_add_to_cart_button', $template_part, $product_id);
2190 2190
 
2191 2191
             $tpl_component = array();
2192 2192
             $tpl_component['PRODUCT_ID'] = $product_id;
@@ -3048,7 +3048,7 @@  discard block
 block discarded – undo
3048 3048
                 $single_variations = array();
3049 3049
                 foreach ($selected_variation as $attribute_code => $attribute_value) {
3050 3050
                     if (isset($attribute_value) && $attribute_code != 'free') {
3051
-                        $query = $wpdb->prepare("SELECT ID FROM " . $wpdb->postmeta . " AS P_META INNER JOIN " . $wpdb->posts . " as P ON ((P.ID = P_META.post_id) AND (P.post_parent = %d)) WHERE P_META.meta_value = '" . serialize(array($attribute_code => $attribute_value)) . "' OR P_META.meta_value = '" . serialize(array($attribute_code => (int) $attribute_value)) . "'", $product_id);
3051
+                        $query = $wpdb->prepare("SELECT ID FROM " . $wpdb->postmeta . " AS P_META INNER JOIN " . $wpdb->posts . " as P ON ((P.ID = P_META.post_id) AND (P.post_parent = %d)) WHERE P_META.meta_value = '" . serialize(array($attribute_code => $attribute_value)) . "' OR P_META.meta_value = '" . serialize(array($attribute_code => (int)$attribute_value)) . "'", $product_id);
3052 3052
                         $single_variation_id = $wpdb->get_var($query);
3053 3053
                         if (!empty($single_variation_id)) {
3054 3054
                             $single_variations[] = $single_variation_id;
@@ -3150,7 +3150,7 @@  discard block
 block discarded – undo
3150 3150
              * Since 1.4.3.7
3151 3151
              * L'option du produit remplace le prix du produit de tête.
3152 3152
              */
3153
-			if( true ) {
3153
+			if (true) {
3154 3154
                 //Replace the product price
3155 3155
                 if (!empty($variations_discount_total_price) && !empty($variations_discount_total_price['price_ati'])) {
3156 3156
                     $product_into_cart['price_ttc_before_discount'] = $variations_total_price['price_ati'];
@@ -3517,16 +3517,16 @@  discard block
 block discarded – undo
3517 3517
 		$variation_post_meta = get_post_meta($current_post_id, '_wpshop_variation_defining', true);
3518 3518
         $variation_post_meta['options'] = $options;
3519 3519
 		$variation_post_meta['follow_general_config'] = true;
3520
-		if( $variation_post_meta['follow_general_config'] ) {
3520
+		if ($variation_post_meta['follow_general_config']) {
3521 3521
 			$shop_option = get_option('wpshop_catalog_product_option', array());
3522
-			if( isset( $shop_option ) ) {
3522
+			if (isset($shop_option)) {
3523 3523
 				$variation_post_meta['options']['price_display'] = $shop_option['price_display'];
3524 3524
 			}
3525 3525
 		}
3526 3526
 		$variations = wpshop_attributes::get_variation_available_attribute($current_post_id);
3527
-		if( !empty( $variations['available'] ) ) {
3528
-			foreach( $variations['available'] as $key => $value ) {
3529
-				if( !in_array( $value['attribute_complete_def']->code, $variation_post_meta['attributes'] ) ) {
3527
+		if (!empty($variations['available'])) {
3528
+			foreach ($variations['available'] as $key => $value) {
3529
+				if (!in_array($value['attribute_complete_def']->code, $variation_post_meta['attributes'])) {
3530 3530
 					$variation_post_meta['attributes'][] = $value['attribute_complete_def']->code;
3531 3531
 				}
3532 3532
 			}
Please login to merge, or discard this patch.
includes/modules/wps_orders/controller/wps_orders_ctr.php 2 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -124,7 +124,7 @@  discard block
 block discarded – undo
124 124
 		/**
125 125
 		 *	Build an array with the different items to add to an order
126 126
 		 *
127
-		 *	@param array $products The item list to add to the order
127
+		 *	@param array $product The item list to add to the order
128 128
 		 *
129 129
 		 *	@return array $item_list The item to add to order
130 130
 		 */
@@ -418,7 +418,7 @@  discard block
 block discarded – undo
418 418
 	 *
419 419
 	 * @method wps_token_order_customer
420 420
 	 * @param  int $order_id OrderID.
421
-	 * @return mixed sha1 or false.
421
+	 * @return false|string sha1 or false.
422 422
 	 */
423 423
 	public static function wps_token_order_customer( $order_id, $date = null ) {
424 424
 		$date = isset( $date ) ? $date : date( 'Ym' );
Please login to merge, or discard this patch.
Spacing   +161 added lines, -161 removed lines patch added patch discarded remove patch
@@ -1,4 +1,4 @@  discard block
 block discarded – undo
1
-<?php if ( ! defined( 'ABSPATH' ) ) { exit;
1
+<?php if (!defined('ABSPATH')) { exit;
2 2
 }
3 3
 class wps_orders_ctr {
4 4
 
@@ -20,24 +20,24 @@  discard block
 block discarded – undo
20 20
 
21 21
 		/** Template Load */
22 22
 		// add_filter( 'wpshop_custom_template', array( &$this, 'custom_template_load' ) );
23
-		add_shortcode( 'order_customer_informations', array( &$this, 'display_order_customer_informations' ) );
24
-		add_shortcode( 'wps_orders_in_customer_account', array( $this, 'display_orders_in_account' ) );
25
-		add_action( 'wp_enqueue_scripts', array( $this, 'wps_orders_scripts' ) );
23
+		add_shortcode('order_customer_informations', array(&$this, 'display_order_customer_informations'));
24
+		add_shortcode('wps_orders_in_customer_account', array($this, 'display_orders_in_account'));
25
+		add_action('wp_enqueue_scripts', array($this, 'wps_orders_scripts'));
26 26
 		/**	Include the different javascript	*/
27
-		add_action( 'admin_init', array( &$this, 'admin_js' ) );
27
+		add_action('admin_init', array(&$this, 'admin_js'));
28 28
 
29 29
 		/** Ajax Actions */
30 30
 		// add_action( 'wp_ajax_wps_add_product_to_quotation', array( &$this, 'wps_add_product_to_quotation') );
31 31
 		// add_action( 'wap_ajax_wps_change_product_list', array( &$this, 'wps_change_product_list') );
32 32
 		// add_action( 'wap_ajax_wps_orders_load_variations_container', array( &$this, 'wps_orders_load_variations_container') );
33 33
 		// add_action( 'wap_ajax_wps_order_refresh_in_admin', array( &$this, 'wps_order_refresh_in_admin') );
34
-		add_action( 'wp_ajax_wps_orders_load_details', array( $this, 'wps_orders_load_details' ) );
34
+		add_action('wp_ajax_wps_orders_load_details', array($this, 'wps_orders_load_details'));
35 35
 		// Add a product sale historic in administration product panel
36
-		add_action( 'wp_ajax_wps_order_choose_customer', array( $this, 'wps_order_choose_customer' ) );
36
+		add_action('wp_ajax_wps_order_choose_customer', array($this, 'wps_order_choose_customer'));
37 37
 		/** For delete order */
38
-		add_action( 'wp_ajax_wps_delete_order', array( $this, 'wps_delete_order' ) );
38
+		add_action('wp_ajax_wps_delete_order', array($this, 'wps_delete_order'));
39 39
 		/** Invoice Page */
40
-		add_action( 'admin_post_wps_invoice', array( $this, 'wps_invoice_output' ) );
40
+		add_action('admin_post_wps_invoice', array($this, 'wps_invoice_output'));
41 41
 	}
42 42
 
43 43
 		/**
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
 		 */
55 55
 	function wps_orders_scripts() {
56 56
 
57
-		wp_enqueue_script( 'wps_orders_fronend', WPS_ORDERS_URL . WPS_ORDERS_DIR . '/assets/frontend/js/wps_orders.js' );
57
+		wp_enqueue_script('wps_orders_fronend', WPS_ORDERS_URL . WPS_ORDERS_DIR . '/assets/frontend/js/wps_orders.js');
58 58
 	}
59 59
 
60 60
 	function display_order_customer_informations() {
@@ -62,23 +62,23 @@  discard block
 block discarded – undo
62 62
 		global $post_id;
63 63
 		global $wpdb;
64 64
 		$output = '';
65
-		if ( ! empty( $post_id ) ) {
66
-			$order_postmeta = get_post_meta( $post_id, '_order_postmeta', true );
67
-			$order_info = get_post_meta( $post_id, '_order_info', true );
65
+		if (!empty($post_id)) {
66
+			$order_postmeta = get_post_meta($post_id, '_order_postmeta', true);
67
+			$order_info = get_post_meta($post_id, '_order_info', true);
68 68
 			/** Check the order status */
69
-			if ( ! empty( $order_postmeta ) ) {
70
-				if ( ! empty( $order_postmeta['order_status'] )  && $order_postmeta['order_status'] != 'awaiting_payment' ) {
71
-					$output = wps_address::display_an_address( $order_info['billing']['address'] );
72
-					$output .= wps_address::display_an_address( $order_info['shipping']['address'] );
69
+			if (!empty($order_postmeta)) {
70
+				if (!empty($order_postmeta['order_status']) && $order_postmeta['order_status'] != 'awaiting_payment') {
71
+					$output = wps_address::display_an_address($order_info['billing']['address']);
72
+					$output .= wps_address::display_an_address($order_info['shipping']['address']);
73 73
 				} else {
74
-					$output = wps_address::display_an_address( $order_info['billing']['address'] );
74
+					$output = wps_address::display_an_address($order_info['billing']['address']);
75 75
 				}
76 76
 			}
77 77
 		} else {
78 78
 			/** Display  "Choose customer or create one" Interface */
79 79
 			$tpl_component = array();
80 80
 			$args = array(
81
-			'show_option_all' => __( 'Choose a customer', 'wpshop' ),
81
+			'show_option_all' => __('Choose a customer', 'wpshop'),
82 82
 			'orderby' => 'display_name',
83 83
 			'order' => 'ASC',
84 84
 			'include' => null, // string
@@ -92,10 +92,10 @@  discard block
 block discarded – undo
92 92
 						'id' => null, // integer
93 93
 						'class' => 'chosen_select', // string
94 94
 						'blog_id' => $GLOBALS['blog_id'],
95
-			'who' => null,// string
95
+			'who' => null, // string
96 96
 			);
97
-			$tpl_component['CUSTOMERS_LIST'] = wp_dropdown_users( $args );
98
-			$output = wpshop_display::display_template_element( 'wps_orders_choose_customer_interface', $tpl_component, array(), 'admin' );
97
+			$tpl_component['CUSTOMERS_LIST'] = wp_dropdown_users($args);
98
+			$output = wpshop_display::display_template_element('wps_orders_choose_customer_interface', $tpl_component, array(), 'admin');
99 99
 		}
100 100
 		return $output;
101 101
 	}
@@ -106,16 +106,16 @@  discard block
 block discarded – undo
106 106
 		 * @param integer $customer_id
107 107
 		 * @return string
108 108
 		 */
109
-	function display_orders_in_account( $customer_id = '' ) {
109
+	function display_orders_in_account($customer_id = '') {
110 110
 
111 111
 		$output = '';
112
-		$customer_id = ( ! empty( $customer_id ) ) ? $customer_id : get_current_user_id();
113
-		$from_admin = ( ! empty( $customer_id ) ) ? true : false;
112
+		$customer_id = (!empty($customer_id)) ? $customer_id : get_current_user_id();
113
+		$from_admin = (!empty($customer_id)) ? true : false;
114 114
 		$wps_orders_mdl = new wps_orders_mdl();
115
-		$orders = $wps_orders_mdl->get_customer_orders( $customer_id );
115
+		$orders = $wps_orders_mdl->get_customer_orders($customer_id);
116 116
 		// Display orders
117 117
 		ob_start();
118
-		require_once( wpshop_tools::get_template_part( WPS_ORDERS_DIR, $this->template_dir, 'frontend', 'orders_list_in_account' ) );
118
+		require_once(wpshop_tools::get_template_part(WPS_ORDERS_DIR, $this->template_dir, 'frontend', 'orders_list_in_account'));
119 119
 		$output = ob_get_contents();
120 120
 		ob_end_clean();
121 121
 		return $output;
@@ -128,105 +128,105 @@  discard block
 block discarded – undo
128 128
 		 *
129 129
 		 *	@return array $item_list The item to add to order
130 130
 		 */
131
-	function add_product_to_order( $product ) {
131
+	function add_product_to_order($product) {
132 132
 
133 133
 		global $wpdb;
134
-		if ( ! empty( $product ) && empty( $product['price_ttc_before_discount'] ) && empty( $product['price_ht_before_discount'] ) ) {
135
-			$price_infos = wpshop_prices::check_product_price( $product, true );
136
-			$product['price_ht'] = ( ! empty( $price_infos['discount'] ) && ! empty( $price_infos['discount']['discount_exist'] ) && $price_infos['discount']['discount_exist']) ?  $price_infos['discount']['discount_et_price'] : $price_infos['et'];
137
-			$product['product_price'] = ( ! empty( $price_infos['discount'] ) && ! empty( $price_infos['discount']['discount_exist'] ) && $price_infos['discount']['discount_exist']) ? $price_infos['discount']['discount_ati_price'] : $price_infos['ati'];
138
-			$product['tva'] = ( ! empty( $price_infos['discount'] ) && ! empty( $price_infos['discount']['discount_exist'] ) && $price_infos['discount']['discount_exist']) ? $price_infos['discount']['discount_tva'] : $price_infos['tva'];
134
+		if (!empty($product) && empty($product['price_ttc_before_discount']) && empty($product['price_ht_before_discount'])) {
135
+			$price_infos = wpshop_prices::check_product_price($product, true);
136
+			$product['price_ht'] = (!empty($price_infos['discount']) && !empty($price_infos['discount']['discount_exist']) && $price_infos['discount']['discount_exist']) ? $price_infos['discount']['discount_et_price'] : $price_infos['et'];
137
+			$product['product_price'] = (!empty($price_infos['discount']) && !empty($price_infos['discount']['discount_exist']) && $price_infos['discount']['discount_exist']) ? $price_infos['discount']['discount_ati_price'] : $price_infos['ati'];
138
+			$product['tva'] = (!empty($price_infos['discount']) && !empty($price_infos['discount']['discount_exist']) && $price_infos['discount']['discount_exist']) ? $price_infos['discount']['discount_tva'] : $price_infos['tva'];
139 139
 		}
140 140
 
141
-		$price_piloting = get_option( 'wpshop_shop_price_piloting' );
142
-		if ( ! empty( $price_piloting ) && $price_piloting == 'HT' ) {
141
+		$price_piloting = get_option('wpshop_shop_price_piloting');
142
+		if (!empty($price_piloting) && $price_piloting == 'HT') {
143 143
 			$total_ht = $product['price_ht'] * $product['product_qty'];
144
-			$tva_total_amount = $total_ht * ( $product['tx_tva'] / 100 );
144
+			$tva_total_amount = $total_ht * ($product['tx_tva'] / 100);
145 145
 			$total_ttc = $total_ht + $tva_total_amount;
146 146
 		} else {
147 147
 			$total_ttc = $product['product_price'] * $product['product_qty'];
148
-			$total_ht  = $total_ttc / ( 1 + ( $product['tx_tva'] / 100 ) );
148
+			$total_ht  = $total_ttc / (1 + ($product['tx_tva'] / 100));
149 149
 			$tva_total_amount = $total_ttc - $total_ht;
150 150
 		}
151 151
 
152
-		$tva = ! empty( $product[ WPSHOP_PRODUCT_PRICE_TAX ] ) ? $product[ WPSHOP_PRODUCT_PRICE_TAX ] : null;
152
+		$tva = !empty($product[WPSHOP_PRODUCT_PRICE_TAX]) ? $product[WPSHOP_PRODUCT_PRICE_TAX] : null;
153 153
 		$item_discount_type = $item_discount_value = $item_discount_amount = 0;
154
-		$d_amount = ! empty( $product ) && ! empty( $product['discount_amount'] ) ? wpshop_tools::formate_number( $product['discount_amount'] ) : null;
155
-		$d_rate = ! empty( $product ) && ! empty( $product['discount_rate'] ) ? wpshop_tools::formate_number( $product['discount_rate'] ) : null;
156
-		$d_special = ! empty( $product ) && ! empty( $product['special_price'] ) ? wpshop_tools::formate_number( $product['special_price'] ) : null;
157
-		if ( ! empty( $d_amount ) ) {
154
+		$d_amount = !empty($product) && !empty($product['discount_amount']) ? wpshop_tools::formate_number($product['discount_amount']) : null;
155
+		$d_rate = !empty($product) && !empty($product['discount_rate']) ? wpshop_tools::formate_number($product['discount_rate']) : null;
156
+		$d_special = !empty($product) && !empty($product['special_price']) ? wpshop_tools::formate_number($product['special_price']) : null;
157
+		if (!empty($d_amount)) {
158 158
 			$item_discount_type = 'discount_amount';
159 159
 			$item_discount_amount = $product['discount_amount'];
160 160
 			$item_discount_value = $product['discount_amount'];
161
-		} elseif ( ! empty( $d_rate ) ) {
161
+		} elseif (!empty($d_rate)) {
162 162
 			$item_discount_type = 'discount_rate';
163 163
 			$item_discount_amount = $product['discount_rate'];
164 164
 			$item_discount_value = $product['discount_rate'];
165
-		} elseif ( ! empty( $d_special ) ) {
165
+		} elseif (!empty($d_special)) {
166 166
 			$item_discount_type = 'special_price';
167 167
 			$item_discount_amount = $product['special_price'];
168 168
 			$item_discount_value = $product['special_price'];
169 169
 		}
170 170
 
171
-		$item = array( 'item_id' => $product['product_id'], 'item_ref' => ! empty( $product['product_reference'] ) ? $product['product_reference'] : null, 'item_name' => ! empty( $product['product_name'] ) ? $product['product_name'] : 'wpshop_product_' . $product['product_id'], 'item_qty' => $product['product_qty'], 'item_pu_ht' => $product['price_ht'], 'item_pu_ttc' => $product['product_price'], 'item_ecotaxe_ht' => 0, 'item_ecotaxe_tva' => 19.6, 'item_ecotaxe_ttc' => 0, 'item_discount_type' => $item_discount_type, 'item_discount_value' => $item_discount_value, 'item_discount_amount' => $item_discount_amount, 'item_tva_rate' => $tva, 'item_tva_amount' => $product['tva'], 'item_total_ht' => $total_ht, 'item_tva_total_amount' => $tva_total_amount, 'item_total_ttc' => $total_ttc, 'item_meta' => ! empty( $product['item_meta'] ) ? $product['item_meta'] : array() );
172
-		if ( isset( $product['is_downloadable_'] ) ) {
171
+		$item = array('item_id' => $product['product_id'], 'item_ref' => !empty($product['product_reference']) ? $product['product_reference'] : null, 'item_name' => !empty($product['product_name']) ? $product['product_name'] : 'wpshop_product_' . $product['product_id'], 'item_qty' => $product['product_qty'], 'item_pu_ht' => $product['price_ht'], 'item_pu_ttc' => $product['product_price'], 'item_ecotaxe_ht' => 0, 'item_ecotaxe_tva' => 19.6, 'item_ecotaxe_ttc' => 0, 'item_discount_type' => $item_discount_type, 'item_discount_value' => $item_discount_value, 'item_discount_amount' => $item_discount_amount, 'item_tva_rate' => $tva, 'item_tva_amount' => $product['tva'], 'item_total_ht' => $total_ht, 'item_tva_total_amount' => $tva_total_amount, 'item_total_ttc' => $total_ttc, 'item_meta' => !empty($product['item_meta']) ? $product['item_meta'] : array());
172
+		if (isset($product['is_downloadable_'])) {
173 173
 			$item['item_is_downloadable_'] = $product['is_downloadable_'];
174 174
 		}
175
-		$array_not_to_do = array( WPSHOP_PRODUCT_PRICE_HT, WPSHOP_PRODUCT_PRICE_TTC, WPSHOP_PRODUCT_PRICE_TAX_AMOUNT, 'product_qty', WPSHOP_PRODUCT_PRICE_TAX, 'product_id', 'product_reference', 'product_name', 'variations' );
176
-		if ( ! empty( $product['item_meta'] ) ) {
177
-			foreach ( $product['item_meta'] as $key => $value ) {
178
-				if ( ! isset( $item[ 'item_' . $key ] ) && ! in_array( $key, $array_not_to_do ) && ! empty( $product[ $key ] ) ) {
179
-					$item[ 'item_' . $key ] = $product[ $key ];
175
+		$array_not_to_do = array(WPSHOP_PRODUCT_PRICE_HT, WPSHOP_PRODUCT_PRICE_TTC, WPSHOP_PRODUCT_PRICE_TAX_AMOUNT, 'product_qty', WPSHOP_PRODUCT_PRICE_TAX, 'product_id', 'product_reference', 'product_name', 'variations');
176
+		if (!empty($product['item_meta'])) {
177
+			foreach ($product['item_meta'] as $key => $value) {
178
+				if (!isset($item['item_' . $key]) && !in_array($key, $array_not_to_do) && !empty($product[$key])) {
179
+					$item['item_' . $key] = $product[$key];
180 180
 				}
181 181
 			}
182 182
 		}
183 183
 
184 184
 		/** Check if it's a variation product */
185
-		if ( ! empty( $product ) && ! empty( $product['item_meta'] ) && ! empty( $product['item_meta']['variations'] ) ) {
186
-			foreach ( $product['item_meta']['variations'] as $k => $variation ) {
187
-				$product_variation_def = get_post_meta( $k, '_wpshop_variations_attribute_def', true );
188
-				if ( ! empty( $product_variation_def ) ) {
189
-					foreach ( $product_variation_def as $attribute_code => $variation_id ) {
190
-						$variation_attribute_def = wpshop_attributes::getElement( $attribute_code, '"valid"', 'code' );
191
-						if ( ! empty( $variation_attribute_def ) ) {
192
-							$item['item_meta']['variation_definition'][ $attribute_code ]['NAME'] = $variation_attribute_def->frontend_label;
193
-							if ( $variation_attribute_def->data_type_to_use == 'custom' ) {
194
-								$query = $wpdb->prepare( 'SELECT label FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id=%d', $variation_id );
195
-								$variation_name = $wpdb->get_var( $query );
185
+		if (!empty($product) && !empty($product['item_meta']) && !empty($product['item_meta']['variations'])) {
186
+			foreach ($product['item_meta']['variations'] as $k => $variation) {
187
+				$product_variation_def = get_post_meta($k, '_wpshop_variations_attribute_def', true);
188
+				if (!empty($product_variation_def)) {
189
+					foreach ($product_variation_def as $attribute_code => $variation_id) {
190
+						$variation_attribute_def = wpshop_attributes::getElement($attribute_code, '"valid"', 'code');
191
+						if (!empty($variation_attribute_def)) {
192
+							$item['item_meta']['variation_definition'][$attribute_code]['NAME'] = $variation_attribute_def->frontend_label;
193
+							if ($variation_attribute_def->data_type_to_use == 'custom') {
194
+								$query = $wpdb->prepare('SELECT label FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id=%d', $variation_id);
195
+								$variation_name = $wpdb->get_var($query);
196 196
 							} else {
197
-								$variation_post = get_post( $variation_id );
197
+								$variation_post = get_post($variation_id);
198 198
 								$variation_name = $variation_post->post_title;
199 199
 							}
200
-							$item['item_meta']['variation_definition'][ $attribute_code ]['UNSTYLED_VALUE'] = $variation_name;
201
-							$item['item_meta']['variation_definition'][ $attribute_code ]['VALUE'] = $variation_name;
200
+							$item['item_meta']['variation_definition'][$attribute_code]['UNSTYLED_VALUE'] = $variation_name;
201
+							$item['item_meta']['variation_definition'][$attribute_code]['VALUE'] = $variation_name;
202 202
 						}
203 203
 					}
204 204
 				}
205 205
 			}
206 206
 		} else {
207 207
 				/** Check if it's product with one variation */
208
-				$product_variation_def = get_post_meta( $product['product_id'], '_wpshop_variations_attribute_def', true );
209
-			if ( ! empty( $product_variation_def ) ) {
210
-				foreach ( $product_variation_def as $attribute_code => $variation_id ) {
211
-					$variation_attribute_def = wpshop_attributes::getElement( $attribute_code, '"valid"', 'code' );
212
-					if ( ! empty( $variation_attribute_def ) ) {
213
-							$item['item_meta']['variation_definition'][ $attribute_code ]['NAME'] = $variation_attribute_def->frontend_label;
214
-						if ( $variation_attribute_def->data_type_to_use == 'custom' ) {
215
-								$query = $wpdb->prepare( 'SELECT label FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id=%d', $variation_id );
216
-							$variation_name = $wpdb->get_var( $query );
208
+				$product_variation_def = get_post_meta($product['product_id'], '_wpshop_variations_attribute_def', true);
209
+			if (!empty($product_variation_def)) {
210
+				foreach ($product_variation_def as $attribute_code => $variation_id) {
211
+					$variation_attribute_def = wpshop_attributes::getElement($attribute_code, '"valid"', 'code');
212
+					if (!empty($variation_attribute_def)) {
213
+							$item['item_meta']['variation_definition'][$attribute_code]['NAME'] = $variation_attribute_def->frontend_label;
214
+						if ($variation_attribute_def->data_type_to_use == 'custom') {
215
+								$query = $wpdb->prepare('SELECT label FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id=%d', $variation_id);
216
+							$variation_name = $wpdb->get_var($query);
217 217
 						} else {
218
-							$variation_post = get_post( $variation_id );
218
+							$variation_post = get_post($variation_id);
219 219
 							$variation_name = $variation_post->post_title;
220 220
 						}
221
-						$item['item_meta']['variation_definition'][ $attribute_code ]['UNSTYLED_VALUE'] = $variation_name;
222
-						$item['item_meta']['variation_definition'][ $attribute_code ]['VALUE'] = $variation_name;
221
+						$item['item_meta']['variation_definition'][$attribute_code]['UNSTYLED_VALUE'] = $variation_name;
222
+						$item['item_meta']['variation_definition'][$attribute_code]['VALUE'] = $variation_name;
223 223
 					}
224 224
 				}
225 225
 			}
226 226
 		}
227 227
 
228 228
 		/**	On ajoute la possibilité d'étendre les données produits ajoutées dans le panier / Add possibility to extends product data saved into cart	*/
229
-		$item = apply_filters( 'wpshop-add-product-to-order', $item, $product );
229
+		$item = apply_filters('wpshop-add-product-to-order', $item, $product);
230 230
 		return $item;
231 231
 	}
232 232
 
@@ -235,40 +235,40 @@  discard block
 block discarded – undo
235 235
 		 */
236 236
 	function wps_invoice_output() {
237 237
 
238
-		$order_id = ( ! empty( $_GET['order_id'] )) ? (int) $_GET['order_id'] : null;
239
-		$invoice_ref = ( ! empty( $_GET['invoice_ref'] )) ? sanitize_text_field( $_GET['invoice_ref'] ) : null;
240
-		$mode = ( ! empty( $_GET['mode'] )) ? sanitize_text_field( $_GET['mode'] ) : 'html';
241
-		$is_credit_slip = ( ! empty( $_GET['credit_slip'] )) ? sanitize_text_field( $_GET['credit_slip'] ) : null;
238
+		$order_id = (!empty($_GET['order_id'])) ? (int)$_GET['order_id'] : null;
239
+		$invoice_ref = (!empty($_GET['invoice_ref'])) ? sanitize_text_field($_GET['invoice_ref']) : null;
240
+		$mode = (!empty($_GET['mode'])) ? sanitize_text_field($_GET['mode']) : 'html';
241
+		$is_credit_slip = (!empty($_GET['credit_slip'])) ? sanitize_text_field($_GET['credit_slip']) : null;
242 242
 		$user_id = get_current_user_id();
243
-		if ( ! empty( $order_id ) && $user_id != 0 ) {
243
+		if (!empty($order_id) && $user_id != 0) {
244 244
 			/**	Order reading	*/
245
-			$order_postmeta = get_post_meta( $order_id, '_order_postmeta', true );
245
+			$order_postmeta = get_post_meta($order_id, '_order_postmeta', true);
246 246
 			/**	Start invoice display	*/
247
-			if ( ! empty( $is_credit_slip ) ) {
248
-				$html_content = wpshop_modules_billing::generate_html_invoice( $order_id, $invoice_ref, 'credit_slip' );
247
+			if (!empty($is_credit_slip)) {
248
+				$html_content = wpshop_modules_billing::generate_html_invoice($order_id, $invoice_ref, 'credit_slip');
249 249
 			} else {
250
-				$html_content = wpshop_modules_billing::generate_html_invoice( $order_id, $invoice_ref );
250
+				$html_content = wpshop_modules_billing::generate_html_invoice($order_id, $invoice_ref);
251 251
 			}
252 252
 
253
-			if ( $mode == 'pdf' ) {
254
-				require_once( WPSHOP_LIBRAIRIES_DIR . 'HTML2PDF/html2pdf.class.php' );
253
+			if ($mode == 'pdf') {
254
+				require_once(WPSHOP_LIBRAIRIES_DIR . 'HTML2PDF/html2pdf.class.php');
255 255
 				try {
256 256
 					// $html_content = wpshop_display::display_template_element('invoice_print_page_content_css', array(), array(), 'common') . '<page>' . $html_content . '</page>';
257
-					$html_content = wpshop_display::display_template_element( 'invoice_page_content_css', array(), array(), 'common' ) . '<page>' . $html_content . '</page>';
258
-					$html2pdf = new HTML2PDF( 'P', 'A4', 'fr' );
259
-					$html2pdf->setDefaultFont( 'Arial' );
260
-					$html2pdf->writeHTML( $html_content );
261
-					$html2pdf->Output( 'order_' . $order_id . '.pdf', 'D' );
257
+					$html_content = wpshop_display::display_template_element('invoice_page_content_css', array(), array(), 'common') . '<page>' . $html_content . '</page>';
258
+					$html2pdf = new HTML2PDF('P', 'A4', 'fr');
259
+					$html2pdf->setDefaultFont('Arial');
260
+					$html2pdf->writeHTML($html_content);
261
+					$html2pdf->Output('order_' . $order_id . '.pdf', 'D');
262 262
 				} catch (HTML2PDF_exception $e) {
263 263
 					echo $e;
264 264
 					exit;
265 265
 				}
266 266
 			} else {
267
-				$order_invoice_ref = ( ! empty( $order_postmeta['order_invoice_ref'] ) ) ? $order_postmeta['order_invoice_ref'] : '';
268
-				$tpl_component['INVOICE_CSS'] = wpshop_display::display_template_element( 'invoice_page_content_css', array(), array(), 'common' );
267
+				$order_invoice_ref = (!empty($order_postmeta['order_invoice_ref'])) ? $order_postmeta['order_invoice_ref'] : '';
268
+				$tpl_component['INVOICE_CSS'] = wpshop_display::display_template_element('invoice_page_content_css', array(), array(), 'common');
269 269
 				$tpl_component['INVOICE_MAIN_PAGE'] = $html_content;
270
-				$tpl_component['INVOICE_TITLE_PAGE'] = sprintf( __( 'Invoice %1$s for order %3$s (#%2$s)', 'wpshop' ), $order_invoice_ref, $order_id, $order_postmeta['order_key'] );
271
-				echo wpshop_display::display_template_element( 'invoice_page', $tpl_component, array(), 'common' );
270
+				$tpl_component['INVOICE_TITLE_PAGE'] = sprintf(__('Invoice %1$s for order %3$s (#%2$s)', 'wpshop'), $order_invoice_ref, $order_id, $order_postmeta['order_key']);
271
+				echo wpshop_display::display_template_element('invoice_page', $tpl_component, array(), 'common');
272 272
 			}
273 273
 		}
274 274
 		die();
@@ -280,21 +280,21 @@  discard block
 block discarded – undo
280 280
 		 */
281 281
 	function wps_orders_load_details() {
282 282
 
283
-		check_ajax_referer( 'wps_orders_load_details' );
284
-		$order_id = ( ! empty( $_POST['order_id'] ) ) ? wpshop_tools::varSanitizer( $_POST['order_id'] ) : '';
283
+		check_ajax_referer('wps_orders_load_details');
284
+		$order_id = (!empty($_POST['order_id'])) ? wpshop_tools::varSanitizer($_POST['order_id']) : '';
285 285
 		$user_id = get_current_user_id();
286 286
 		$status = false;
287 287
 		$result = '';
288
-		if ( ! empty( $order_id ) ) {
289
-			$order = get_post( $order_id );
290
-			$order_infos = get_post_meta( $order_id, '_order_postmeta', true );
291
-			$order_key = ( ! empty( $order_infos['order_key'] ) ) ? $order_infos['order_key'] : '-';
292
-			if ( ! empty( $order ) && ! empty( $user_id ) && $order->post_type == WPSHOP_NEWTYPE_IDENTIFIER_ORDER && $order->post_author == $user_id ) {
293
-				$result = do_shortcode( '[wps_cart cart_type="summary" oid="' . $order_id . '"]' );
288
+		if (!empty($order_id)) {
289
+			$order = get_post($order_id);
290
+			$order_infos = get_post_meta($order_id, '_order_postmeta', true);
291
+			$order_key = (!empty($order_infos['order_key'])) ? $order_infos['order_key'] : '-';
292
+			if (!empty($order) && !empty($user_id) && $order->post_type == WPSHOP_NEWTYPE_IDENTIFIER_ORDER && $order->post_author == $user_id) {
293
+				$result = do_shortcode('[wps_cart cart_type="summary" oid="' . $order_id . '"]');
294 294
 				$status = true;
295 295
 			}
296 296
 		}
297
-		echo json_encode( array( 'status' => $status, 'title' => sprintf( __( 'Order n° %s details', 'wpshop' ), $order_key ), 'content' => $result ) );
297
+		echo json_encode(array('status' => $status, 'title' => sprintf(__('Order n° %s details', 'wpshop'), $order_key), 'content' => $result));
298 298
 		wp_die();
299 299
 	}
300 300
 
@@ -303,60 +303,60 @@  discard block
 block discarded – undo
303 303
 		 */
304 304
 	function wps_order_choose_customer() {
305 305
 
306
-		$_wpnonce = ! empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : '';
307
-		if ( ! wp_verify_nonce( $_wpnonce, 'wps_order_choose_customer' ) ) {
306
+		$_wpnonce = !empty($_REQUEST['_wpnonce']) ? sanitize_text_field($_REQUEST['_wpnonce']) : '';
307
+		if (!wp_verify_nonce($_wpnonce, 'wps_order_choose_customer')) {
308 308
 				wp_die();
309 309
 		}
310 310
 
311 311
 		$status = false;
312 312
 		$billing_data = $shipping_data = '';
313
-		$customer_id = ( ! empty( $_POST['customer_id'] ) ) ? intval( $_POST['customer_id'] ): null;
314
-		if ( ! empty( $customer_id ) ) {
313
+		$customer_id = (!empty($_POST['customer_id'])) ? intval($_POST['customer_id']) : null;
314
+		if (!empty($customer_id)) {
315 315
 			$wps_address = new wps_address();
316
-			$billing_option = get_option( 'wpshop_billing_address' );
317
-			$shipping_option = get_option( 'wpshop_shipping_address_choice' );
316
+			$billing_option = get_option('wpshop_billing_address');
317
+			$shipping_option = get_option('wpshop_shipping_address_choice');
318 318
 			$billing_option = $billing_option['choice'];
319
-			$customer_addresses_list = wps_address::get_addresses_list( $customer_id );
319
+			$customer_addresses_list = wps_address::get_addresses_list($customer_id);
320 320
 			$status = true;
321
-			$billing_data = '<div class="wps-alert-info">' . sprintf( __( 'No Billing address created, <a href="%s" title="' . __( 'Create a new billing address', 'wpshop' ) . '" class="thickbox">create one</a>', 'wpshop' ),admin_url( 'admin-ajax.php' ) . '?action=wps-add-an-address-in-admin&address_type=' . $billing_option . '&customer_id=' . $customer_id . '&height=600' ) . '</div>';
322
-			if ( ! empty( $shipping_option ) && ! empty( $shipping_option['activate'] ) ) {
321
+			$billing_data = '<div class="wps-alert-info">' . sprintf(__('No Billing address created, <a href="%s" title="' . __('Create a new billing address', 'wpshop') . '" class="thickbox">create one</a>', 'wpshop'), admin_url('admin-ajax.php') . '?action=wps-add-an-address-in-admin&address_type=' . $billing_option . '&customer_id=' . $customer_id . '&height=600') . '</div>';
322
+			if (!empty($shipping_option) && !empty($shipping_option['activate'])) {
323 323
 				$shipping_option = $shipping_option['choice'];
324
-				$shipping_data = '<div class="wps-alert-info">' . sprintf( __( 'No shipping address created, <a href="%s" title="' . __( 'Create a new shipping address', 'wpshop' ) . '" class="thickbox">create one</a>', 'wpshop' ),admin_url( 'admin-ajax.php' ) . '?action=wps-add-an-address-in-admin&address_type=' . $shipping_option . '&customer_id=' . $customer_id . '&height=600' ) . '</div>';
324
+				$shipping_data = '<div class="wps-alert-info">' . sprintf(__('No shipping address created, <a href="%s" title="' . __('Create a new shipping address', 'wpshop') . '" class="thickbox">create one</a>', 'wpshop'), admin_url('admin-ajax.php') . '?action=wps-add-an-address-in-admin&address_type=' . $shipping_option . '&customer_id=' . $customer_id . '&height=600') . '</div>';
325 325
 			}
326 326
 
327
-			if ( ! empty( $customer_addresses_list ) ) {
328
-				foreach ( $customer_addresses_list as $address_type => $customer_addresses ) {
329
-					if ( $billing_option == $address_type ) {
330
-						$billing_data = $wps_address->display_address_in_administration( $customer_addresses, $address_type );
327
+			if (!empty($customer_addresses_list)) {
328
+				foreach ($customer_addresses_list as $address_type => $customer_addresses) {
329
+					if ($billing_option == $address_type) {
330
+						$billing_data = $wps_address->display_address_in_administration($customer_addresses, $address_type);
331 331
 					} else {
332
-						$shipping_data = $wps_address->display_address_in_administration( $customer_addresses, $address_type );
332
+						$shipping_data = $wps_address->display_address_in_administration($customer_addresses, $address_type);
333 333
 					}
334 334
 				}
335 335
 			}
336 336
 		}
337
-		echo json_encode( array( 'status' => $status, 'billing_data' => $billing_data, 'shipping_data' => $shipping_data ) );
337
+		echo json_encode(array('status' => $status, 'billing_data' => $billing_data, 'shipping_data' => $shipping_data));
338 338
 		wp_die();
339 339
 	}
340 340
 
341
-	static function pay_quotation( $order_id ) {
341
+	static function pay_quotation($order_id) {
342 342
 
343 343
 		$status = true;
344
-		$order_id = (int) $order_id;
345
-		$order_meta = get_post_meta( $order_id, '_order_postmeta', true );
346
-		$order_info = get_post_meta( $order_id, '_order_info', true );
347
-		$_SESSION['shipping_method'] = isset( $order_meta['order_payment']['shipping_method'] ) ? $order_meta['order_payment']['shipping_method'] : 'No Shipping method required';
348
-		if ( isset( $order_info['billing']['address_id'] ) ) {
344
+		$order_id = (int)$order_id;
345
+		$order_meta = get_post_meta($order_id, '_order_postmeta', true);
346
+		$order_info = get_post_meta($order_id, '_order_info', true);
347
+		$_SESSION['shipping_method'] = isset($order_meta['order_payment']['shipping_method']) ? $order_meta['order_payment']['shipping_method'] : 'No Shipping method required';
348
+		if (isset($order_info['billing']['address_id'])) {
349 349
 			$_SESSION['billing_address'] = $order_info['billing']['address_id'];
350 350
 			$_SESSION['cart'] = $order_meta;
351 351
 			$_SESSION['cart']['order_id'] = $order_id;
352 352
     		$_SESSION['cart']['cart_type'] = 'cart';
353 353
 			$_SESSION['cart']['order_shipping_cost_fixe'] = 'on';
354
-			$permalink = get_permalink( get_option( 'wpshop_cart_page_id' ) ) . '?order_step=5';
354
+			$permalink = get_permalink(get_option('wpshop_cart_page_id')) . '?order_step=5';
355 355
 		} else {
356
-			$status = self::add_order_to_session( $order_id );
357
-			$permalink = get_permalink( wpshop_tools::get_page_id( get_option( 'wpshop_checkout_page_id' ) ) );
356
+			$status = self::add_order_to_session($order_id);
357
+			$permalink = get_permalink(wpshop_tools::get_page_id(get_option('wpshop_checkout_page_id')));
358 358
 		}
359
-		return array( 'status' => $status, 'permalink' => $permalink );
359
+		return array('status' => $status, 'permalink' => $permalink);
360 360
 	}
361 361
 
362 362
 	/**
@@ -365,54 +365,54 @@  discard block
 block discarded – undo
365 365
 	 * @method add_order_to_session
366 366
 	 * @param  int $order_id Id of order.
367 367
 	 */
368
-	public static function add_order_to_session( $order_id ) {
368
+	public static function add_order_to_session($order_id) {
369 369
 
370
-		$order_meta = get_post_meta( $order_id, '_order_postmeta', true );
371
-		if ( $order_meta != false ) {
370
+		$order_meta = get_post_meta($order_id, '_order_postmeta', true);
371
+		if ($order_meta != false) {
372 372
 			$_SESSION['cart'] = array();
373 373
 			$_SESSION['cart']['order_amount_to_pay_now'] = $order_meta['order_amount_to_pay_now'];
374 374
 			$_SESSION['cart']['order_items'] = array();
375
-			if ( ! empty( $order_meta ) && ! empty( $order_meta['order_items'] ) ) {
375
+			if (!empty($order_meta) && !empty($order_meta['order_items'])) {
376 376
 				$wpshop_cart_type = 'cart';
377
-				foreach ( $order_meta['order_items'] as $item ) {
378
-					$_SESSION['cart']['order_items'][ $item['item_id'] ] = $item;
377
+				foreach ($order_meta['order_items'] as $item) {
378
+					$_SESSION['cart']['order_items'][$item['item_id']] = $item;
379 379
 				}
380 380
 				$wps_cart_ctr = new wps_cart();
381
-				$order = $wps_cart_ctr->calcul_cart_information( array() );
382
-				$wps_cart_ctr->store_cart_in_session( $order );
381
+				$order = $wps_cart_ctr->calcul_cart_information(array());
382
+				$wps_cart_ctr->store_cart_in_session($order);
383 383
 			}
384 384
 			$_SESSION['order_id'] = $order_id;
385 385
 		}
386
-		return (bool) ($order_meta != false);
386
+		return (bool)($order_meta != false);
387 387
 	}
388 388
 	/**
389 389
 	 * AJAX - Delete order by order_id
390 390
 	 */
391 391
 	public function wps_delete_order() {
392 392
 
393
-		$_wpnonce = ! empty( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : '';
394
-		if ( ! wp_verify_nonce( $_wpnonce, 'wps_delete_order' ) ) {
393
+		$_wpnonce = !empty($_REQUEST['_wpnonce']) ? sanitize_text_field($_REQUEST['_wpnonce']) : '';
394
+		if (!wp_verify_nonce($_wpnonce, 'wps_delete_order')) {
395 395
 				wp_die();
396 396
 		}
397 397
 
398 398
 		$status = false;
399 399
 		$output = '';
400
-		$order_id = ! empty( $_POST['order_id'] ) ? (int) $_POST['order_id'] : 0;
401
-		if ( $order_id ) {
402
-			$order_meta = get_post_meta( $order_id, '_order_postmeta', true );
400
+		$order_id = !empty($_POST['order_id']) ? (int)$_POST['order_id'] : 0;
401
+		if ($order_id) {
402
+			$order_meta = get_post_meta($order_id, '_order_postmeta', true);
403 403
 			$wps_credit = new wps_credit();
404
-			$wps_credit->create_an_credit( $order_id );
404
+			$wps_credit->create_an_credit($order_id);
405 405
 			$order_meta['order_status'] = 'canceled';
406
-			$order_meta['order_payment']['refunded_action']['refunded_date'] = current_time( 'mysql', 0 );
406
+			$order_meta['order_payment']['refunded_action']['refunded_date'] = current_time('mysql', 0);
407 407
 			$order_meta['order_payment']['refunded_action']['author'] = get_current_user_id();
408
-			update_post_meta( $order_id, '_order_postmeta', $order_meta );
408
+			update_post_meta($order_id, '_order_postmeta', $order_meta);
409 409
 			ob_start();
410
-			require( wpshop_tools::get_template_part( WPS_ORDERS_DIR, $this->template_dir, 'frontend', 'order_row_in_account' ) );
410
+			require(wpshop_tools::get_template_part(WPS_ORDERS_DIR, $this->template_dir, 'frontend', 'order_row_in_account'));
411 411
 			$output = ob_get_contents();
412 412
 			ob_end_clean();
413 413
 			$status = true;
414 414
 		}
415
-		echo json_encode( array( 'status' => $status, 'row' => $output ) );
415
+		echo json_encode(array('status' => $status, 'row' => $output));
416 416
 		wp_die();
417 417
 	}
418 418
 
@@ -423,13 +423,13 @@  discard block
 block discarded – undo
423 423
 	 * @param  int $order_id OrderID.
424 424
 	 * @return mixed sha1 or false.
425 425
 	 */
426
-	public static function wps_token_order_customer( $order_id, $date = null ) {
427
-		$date = isset( $date ) ? $date : date( 'Ym' );
428
-		$order_metadata = get_post_meta( $order_id, '_order_postmeta', true );
429
-		if ( ! isset( $order_metadata['customer_id'] ) ) {
426
+	public static function wps_token_order_customer($order_id, $date = null) {
427
+		$date = isset($date) ? $date : date('Ym');
428
+		$order_metadata = get_post_meta($order_id, '_order_postmeta', true);
429
+		if (!isset($order_metadata['customer_id'])) {
430 430
 			return false;
431 431
 		}
432
-		return sha1( site_url() . '_' . $order_id . '_' . $order_metadata['customer_id'] . '_' . $date );
432
+		return sha1(site_url() . '_' . $order_id . '_' . $order_metadata['customer_id'] . '_' . $date);
433 433
 	}
434 434
 
435 435
 	/**
@@ -440,9 +440,9 @@  discard block
 block discarded – undo
440 440
 	 * @param	int    $order_id	OrderID.
441 441
 	 * @return	boolean
442 442
 	 */
443
-	public static function wps_verify_token_order( $token, $order_id ) {
444
-		$current_month = self::wps_token_order_customer( $order_id );
445
-		$last_month = self::wps_token_order_customer( $order_id, date_format( date_create( date( 'Y-m' ) . ' - 1month' ), 'Ym' ) );
446
-		return (bool) ( (bool) $current_month && (bool) $last_month && ( $token === $current_month || $token === $last_month ) );
443
+	public static function wps_verify_token_order($token, $order_id) {
444
+		$current_month = self::wps_token_order_customer($order_id);
445
+		$last_month = self::wps_token_order_customer($order_id, date_format(date_create(date('Y-m') . ' - 1month'), 'Ym'));
446
+		return (bool)((bool)$current_month && (bool)$last_month && ($token === $current_month || $token === $last_month));
447 447
 	}
448 448
 }
Please login to merge, or discard this patch.
includes/modules/wps_download_file/controller/wps_download_file_ctr.php 2 patches
Doc Comments   +4 added lines patch added patch discarded remove patch
@@ -7,6 +7,10 @@
 block discarded – undo
7 7
 	}
8 8
 
9 9
 	// Function to find download link by
10
+
11
+	/**
12
+	 * @param integer $oid
13
+	 */
10 14
 	public static function get_product_download_link( $oid, $item ) {
11 15
 		$parent_def = array();
12 16
 		$item_id = $item['item_id'];
Please login to merge, or discard this patch.
Spacing   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -1,19 +1,19 @@  discard block
 block discarded – undo
1
-<?php if ( !defined( 'ABSPATH' ) ) exit;
1
+<?php if (!defined('ABSPATH')) exit;
2 2
 
3 3
 class wps_download_file_ctr {
4 4
 	public function __construct() {
5
-		add_action( 'admin_post_wps_download_file', array( $this, 'wps_download_file' ) );
6
-		add_action( 'admin_post_nopriv_wps_download_file', array( $this, 'wps_download_file' ) );
5
+		add_action('admin_post_wps_download_file', array($this, 'wps_download_file'));
6
+		add_action('admin_post_nopriv_wps_download_file', array($this, 'wps_download_file'));
7 7
 	}
8 8
 
9 9
 	// Function to find download link by
10
-	public static function get_product_download_link( $oid, $item ) {
10
+	public static function get_product_download_link($oid, $item) {
11 11
 		$parent_def = array();
12 12
 		$item_id = $item['item_id'];
13
-		$item_post_type = get_post_type( $item['item_id'] );
14
-		if ( WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION === $item_post_type ) {
15
-			$parent_def = wpshop_products::get_parent_variation( $item['item_id'] );
16
-			if ( ! empty( $parent_def ) && ! empty( $parent_def['parent_post'] ) ) {
13
+		$item_post_type = get_post_type($item['item_id']);
14
+		if (WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION === $item_post_type) {
15
+			$parent_def = wpshop_products::get_parent_variation($item['item_id']);
16
+			if (!empty($parent_def) && !empty($parent_def['parent_post'])) {
17 17
 				$parent_post = $parent_def['parent_post'];
18 18
 				$item_id = $parent_post->ID;
19 19
 			}
@@ -22,21 +22,21 @@  discard block
 block discarded – undo
22 22
 		$download_link = false;
23 23
 		$item_id_for_download = null;
24 24
 		/** Check if the product or the head product is a download product	*/
25
-		if ( ! empty( $parent_def ) ) {
25
+		if (!empty($parent_def)) {
26 26
 			$parent_meta = $parent_def['parent_post_meta'];
27
-			if ( ! empty( $parent_meta['is_downloadable_'] ) ) {
27
+			if (!empty($parent_meta['is_downloadable_'])) {
28 28
 				global $wpdb;
29
-				$downloadable_option_value = $wpdb->get_var( $wpdb->prepare( 'SELECT value FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id = %d', $parent_meta['is_downloadable_'] ) );
30
-				if ( ! empty( $downloadable_option_value ) ) {
29
+				$downloadable_option_value = $wpdb->get_var($wpdb->prepare('SELECT value FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id = %d', $parent_meta['is_downloadable_']));
30
+				if (!empty($downloadable_option_value)) {
31 31
 					$item['item_is_downloadable_'] = $downloadable_option_value;
32 32
 				}
33 33
 			}
34 34
 		}
35
-		if ( ! empty( $item ) && ! empty( $item['item_is_downloadable_'] ) && ( strtolower( __( $item['item_is_downloadable_'], 'wpshop' ) ) === strtolower( __( 'Yes', 'wpshop' ) ) ) ) {
35
+		if (!empty($item) && !empty($item['item_is_downloadable_']) && (strtolower(__($item['item_is_downloadable_'], 'wpshop')) === strtolower(__('Yes', 'wpshop')))) {
36 36
 			$item_id_for_download = $item_id;
37
-			if ( isset( $item['item_meta']['variations'] ) ) {
38
-				foreach ( $item['item_meta']['variations'] as $variation_id => $variation ) {
39
-					if ( isset( $variation['item_meta']['is_downloadable_'] ) ) {
37
+			if (isset($item['item_meta']['variations'])) {
38
+				foreach ($item['item_meta']['variations'] as $variation_id => $variation) {
39
+					if (isset($variation['item_meta']['is_downloadable_'])) {
40 40
 						$item_id_for_download = $item_id . '__' . $variation_id;
41 41
 					}
42 42
 				}
@@ -44,20 +44,20 @@  discard block
 block discarded – undo
44 44
 		}
45 45
 
46 46
 		/** In case there is a item identifier defined for download */
47
-		if ( null !== $item_id_for_download ) {
48
-			$download_codes = get_user_meta( get_current_user_id(), '_order_download_codes_' . $oid, true );
47
+		if (null !== $item_id_for_download) {
48
+			$download_codes = get_user_meta(get_current_user_id(), '_order_download_codes_' . $oid, true);
49 49
 			/**	Check if the current product exist into download code list, if not check if there is a composition between parent product and children product	*/
50
-			if ( empty( $download_codes[ $item_id_for_download ] ) ) {
51
-				$item_id_component = explode( '__', $item_id_for_download );
52
-				if ( ! empty( $item_id_component ) && ( $item_id_component[0] !== $item_id_for_download ) ) {
50
+			if (empty($download_codes[$item_id_for_download])) {
51
+				$item_id_component = explode('__', $item_id_for_download);
52
+				if (!empty($item_id_component) && ($item_id_component[0] !== $item_id_for_download)) {
53 53
 					$item_id_for_download = $item_id_component[0];
54
-				} elseif ( ! empty( $download_codes[ $item['item_id'] ] ) ) {
54
+				} elseif (!empty($download_codes[$item['item_id']])) {
55 55
 					$item_id_for_download = $item['item_id'];
56 56
 				}
57 57
 			}
58 58
 
59
-			if ( ! empty( $download_codes ) && ! empty( $download_codes[ $item_id_for_download ] ) && ! empty( $download_codes[ $item_id_for_download ]['download_code'] ) ) {
60
-				$download_link = admin_url( 'admin-post.php?action=wps_download_file&amp;oid=' . $oid . '&amp;download=' . $download_codes[ $item_id_for_download ]['download_code'] );
59
+			if (!empty($download_codes) && !empty($download_codes[$item_id_for_download]) && !empty($download_codes[$item_id_for_download]['download_code'])) {
60
+				$download_link = admin_url('admin-post.php?action=wps_download_file&amp;oid=' . $oid . '&amp;download=' . $download_codes[$item_id_for_download]['download_code']);
61 61
 			}
62 62
 		}
63 63
 		return $download_link;
@@ -65,31 +65,31 @@  discard block
 block discarded – undo
65 65
 
66 66
 	// Download product downloadable
67 67
 	public function wps_download_file() {
68
-		$download = !empty( $_GET['download'] ) ? sanitize_text_field( $_GET['download'] ) : '';
69
-		$oid = !empty( $_GET['oid'] ) ? (int) $_GET['oid'] : 0;
68
+		$download = !empty($_GET['download']) ? sanitize_text_field($_GET['download']) : '';
69
+		$oid = !empty($_GET['oid']) ? (int)$_GET['oid'] : 0;
70 70
 
71
-		if ( !empty( $download ) && !empty( $oid ) ) {
71
+		if (!empty($download) && !empty($oid)) {
72 72
 			$variation_id = '';
73 73
 			$order = get_post_meta($oid, '_order_postmeta', true);
74
-			if(!empty($order) && !empty( $order['customer_id'] )) {
75
-				$download_codes = get_user_meta( /*wps_customer_ctr::get_author_id_by_customer_id(*/ $order['customer_id'] /*)*/, '_order_download_codes_'.$oid, true);
76
-				if ( !empty($download_codes) && is_array($download_codes) ) {
77
-					foreach ( $download_codes as $downloadable_product_id => $d ) {
74
+			if (!empty($order) && !empty($order['customer_id'])) {
75
+				$download_codes = get_user_meta( /*wps_customer_ctr::get_author_id_by_customer_id(*/ $order['customer_id'] /*)*/, '_order_download_codes_' . $oid, true);
76
+				if (!empty($download_codes) && is_array($download_codes)) {
77
+					foreach ($download_codes as $downloadable_product_id => $d) {
78 78
 						$is_encrypted = false;
79
-						if ( $d['download_code'] == $download ) {
80
-							wpshop_tools::create_custom_hook ('encrypt_actions_for_downloadable_product', array( 'order_id' => $oid, 'download_product_id' => $downloadable_product_id ) );
79
+						if ($d['download_code'] == $download) {
80
+							wpshop_tools::create_custom_hook('encrypt_actions_for_downloadable_product', array('order_id' => $oid, 'download_product_id' => $downloadable_product_id));
81 81
 
82
-							if ( get_post_type( $downloadable_product_id ) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION ) {
83
-								$parent_def = wpshop_products::get_parent_variation( $downloadable_product_id );
84
-								if ( !empty($parent_def) && !empty($parent_def['parent_post']) ) {
82
+							if (get_post_type($downloadable_product_id) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) {
83
+								$parent_def = wpshop_products::get_parent_variation($downloadable_product_id);
84
+								if (!empty($parent_def) && !empty($parent_def['parent_post'])) {
85 85
 									$parent_post = $parent_def['parent_post'];
86 86
 									$variation_id = $downloadable_product_id;
87 87
 									$downloadable_product_id = $parent_post->ID;
88 88
 								}
89 89
 
90 90
 							} else {
91
-								$downloadable_product_id = explode( "__", $downloadable_product_id );
92
-								$downloadable_product_id = isset( $downloadable_product_id[1] ) ? $downloadable_product_id[1] : $downloadable_product_id[0];
91
+								$downloadable_product_id = explode("__", $downloadable_product_id);
92
+								$downloadable_product_id = isset($downloadable_product_id[1]) ? $downloadable_product_id[1] : $downloadable_product_id[0];
93 93
 							}
94 94
 
95 95
 							$link = wpshop_attributes::get_attribute_option_output(
@@ -97,24 +97,24 @@  discard block
 block discarded – undo
97 97
 								'is_downloadable_', 'file_url', $order
98 98
 							);
99 99
 
100
-							if ( $link !== false ) {
100
+							if ($link !== false) {
101 101
 								$uploads = wp_upload_dir();
102 102
 								$basedir = $uploads['basedir'];
103 103
 								$pos = strpos($link, 'uploads');
104
-								$link = $basedir.substr($link,$pos+7);
104
+								$link = $basedir . substr($link, $pos + 7);
105 105
 								/** If plugin is encrypted **/
106
-								$encrypted_plugin_path = get_post_meta( $oid, '_download_file_path_'.$oid.'_'.( ( !empty( $variation_id ) && get_post_type( $variation_id ) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION ) ? $variation_id : $downloadable_product_id ), true);
107
-								if ( !empty($encrypted_plugin_path) ) {
108
-									$link = WPSHOP_UPLOAD_DIR.$encrypted_plugin_path;
106
+								$encrypted_plugin_path = get_post_meta($oid, '_download_file_path_' . $oid . '_' . ((!empty($variation_id) && get_post_type($variation_id) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) ? $variation_id : $downloadable_product_id), true);
107
+								if (!empty($encrypted_plugin_path)) {
108
+									$link = WPSHOP_UPLOAD_DIR . $encrypted_plugin_path;
109 109
 									$is_encrypted = true;
110 110
 								}
111 111
 
112
-								$overload_force_download = apply_filters( 'wps_download_file_overload_force_download', false );
113
-								if ( !$overload_force_download ) {
112
+								$overload_force_download = apply_filters('wps_download_file_overload_force_download', false);
113
+								if (!$overload_force_download) {
114 114
 									wpshop_tools::forceDownload($link, $is_encrypted);
115 115
 								}
116 116
 								else {
117
-									wpshop_tools::wpshop_safe_redirect( str_replace( WP_CONTENT_DIR, WP_CONTENT_URL, $link ) );
117
+									wpshop_tools::wpshop_safe_redirect(str_replace(WP_CONTENT_DIR, WP_CONTENT_URL, $link));
118 118
 								}
119 119
 							}
120 120
 						}
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
122 122
 				}
123 123
 			}
124 124
 			else {
125
-				wp_redirect( get_permalink( wpshop_tools::get_page_id( get_option('wpshop_myaccount_page_id') ) ) );
125
+				wp_redirect(get_permalink(wpshop_tools::get_page_id(get_option('wpshop_myaccount_page_id'))));
126 126
 			}
127 127
 		}
128 128
 		echo __('Impossible to download the file you requested', 'wpshop');
Please login to merge, or discard this patch.