Completed
Push — master ( 99f797...f10213 )
by
unknown
25:45 queued 11:31
created
includes/librairies/catalog/products.class.php 1 patch
Indentation   +3123 added lines, -3123 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,47 +252,47 @@  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');
281
-            } else if (count($attributeEntitySetList) > 1) {
282
-                $input_def['id'] = 'product_attribute_set_id';
283
-                $input_def['name'] = 'product_attribute_set_id';
284
-                $input_def['value'] = '';
285
-                $input_def['type'] = 'select';
286
-                $input_def['possible_value'] = $attributeEntitySetList;
287
-
288
-                $input_def['value'] = '';
289
-                foreach ($attributeEntitySetList as $set) {
290
-                    if ($set->default_set == 'yes') {
291
-                        $input_def['value'] = $set->id;
292
-                    }
293
-                }
294
-
295
-                $currentTabContent['boxContent']['attribute_set_selector'] = '
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
+			} else if (count($attributeEntitySetList) > 1) {
282
+				$input_def['id'] = 'product_attribute_set_id';
283
+				$input_def['name'] = 'product_attribute_set_id';
284
+				$input_def['value'] = '';
285
+				$input_def['type'] = 'select';
286
+				$input_def['possible_value'] = $attributeEntitySetList;
287
+
288
+				$input_def['value'] = '';
289
+				foreach ($attributeEntitySetList as $set) {
290
+					if ($set->default_set == 'yes') {
291
+						$input_def['value'] = $set->id;
292
+					}
293
+				}
294
+
295
+				$currentTabContent['boxContent']['attribute_set_selector'] = '
296 296
 	<ul class="attribute_set_selector" >
297 297
 		<li class="attribute_set_selector_title_select" ><label for="title" >' . __('Choose a title for your product', 'wpshop') . '</label></li>
298 298
 		<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>
@@ -300,791 +300,791 @@  discard block
 block discarded – undo
300 300
 		<li class="attribute_set_selector_after_save_instruction" >' . __('Once the group chosen, the different attribute will be displayed here', 'wpshop') . '</li>
301 301
 	</ul>';
302 302
 
303
-                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'));
304
-            }
305
-        }
303
+				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'));
304
+			}
305
+		}
306 306
 
307
-    }
307
+	}
308 308
 
309
-    /**
310
-     * Add a box into product edition page for options on the product
311
-     *
312
-     * @param object $post
313
-     */
314
-    public static function product_options_meta_box_content($post)
315
-    {
316
-        $output = '';
309
+	/**
310
+	 * Add a box into product edition page for options on the product
311
+	 *
312
+	 * @param object $post
313
+	 */
314
+	public static function product_options_meta_box_content($post)
315
+	{
316
+		$output = '';
317 317
 
318
-        $product_current_options = get_post_meta($post->ID, '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_options', true);
318
+		$product_current_options = get_post_meta($post->ID, '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_options', true);
319 319
 
320
-        $tpl_component = array();
321
-        $tpl_component['ADMIN_PRODUCT_OPTION_FOR_CART_AUTOADD_CHECKBOX_STATE'] = (!empty($product_current_options['cart']) && !empty($product_current_options['cart']['auto_add'])) ? ' checked="checked"' : '';
322
-        $output .= wpshop_display::display_template_element('wpshop_admin_product_option_for_cart', $tpl_component, array('type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'id' => $post->ID), 'admin');
320
+		$tpl_component = array();
321
+		$tpl_component['ADMIN_PRODUCT_OPTION_FOR_CART_AUTOADD_CHECKBOX_STATE'] = (!empty($product_current_options['cart']) && !empty($product_current_options['cart']['auto_add'])) ? ' checked="checked"' : '';
322
+		$output .= wpshop_display::display_template_element('wpshop_admin_product_option_for_cart', $tpl_component, array('type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'id' => $post->ID), 'admin');
323 323
 
324
-        echo $output;
325
-    }
324
+		echo $output;
325
+	}
326 326
 
327
-    /**
328
-     * Display the fixed box
329
-     */
330
-    public static function product_data_meta_box($post, $metaboxArgs)
331
-    {
332
-        $output = '';
327
+	/**
328
+	 * Display the fixed box
329
+	 */
330
+	public static function product_data_meta_box($post, $metaboxArgs)
331
+	{
332
+		$output = '';
333 333
 
334
-        $currentTabContent = $metaboxArgs['args']['currentTabContent'];
334
+		$currentTabContent = $metaboxArgs['args']['currentTabContent'];
335 335
 
336
-        echo '<div id="fixed-tabs" class="wpshop_tabs wpshop_detail_tabs wpshop_product_attribute_tabs" >
336
+		echo '<div id="fixed-tabs" class="wpshop_tabs wpshop_detail_tabs wpshop_product_attribute_tabs" >
337 337
 				<ul>';
338
-        if (!empty($currentTabContent['box'])) {
339
-            foreach ($currentTabContent['box'] as $boxIdentifier => $boxTitle) {
340
-                if (!empty($currentTabContent['boxContent'][$boxIdentifier])) {
341
-                    if ($currentTabContent['box'][$boxIdentifier . '_backend_display_type'] == 'fixed-tab') {
342
-                        echo '<li><a href="#tabs-' . sanitize_title($boxIdentifier) . '">' . __($boxTitle, 'wpshop') . '</a></li>';
343
-                    }
344
-                }
345
-            }
346
-        }
347
-        echo '<li><a href="#tabs-product-related">' . __('Related products', 'wpshop') . '</a></li>';
348
-        echo '<li><a href="#tabs-product-provider">' . __('Providers', 'wpshop') . '</a></li>';
349
-        echo '<li class="wpshop_product_data_display_tab" ><a href="#tabs-product-display">' . __('Product display', 'wpshop') . '</a></li>';
350
-        echo '</ul>';
351
-
352
-        if (!empty($currentTabContent['box'])) {
353
-            foreach ($currentTabContent['box'] as $boxIdentifier => $boxTitle) {
354
-                if (!empty($currentTabContent['boxContent'][$boxIdentifier])) {
355
-                    if ($currentTabContent['box'][$boxIdentifier . '_backend_display_type'] == 'fixed-tab') {
356
-                        echo '<div id="tabs-' . sanitize_title($boxIdentifier) . '">' . $currentTabContent['boxContent'][$boxIdentifier] . '</div>';
357
-                    }
358
-                }
359
-            }
360
-        }
338
+		if (!empty($currentTabContent['box'])) {
339
+			foreach ($currentTabContent['box'] as $boxIdentifier => $boxTitle) {
340
+				if (!empty($currentTabContent['boxContent'][$boxIdentifier])) {
341
+					if ($currentTabContent['box'][$boxIdentifier . '_backend_display_type'] == 'fixed-tab') {
342
+						echo '<li><a href="#tabs-' . sanitize_title($boxIdentifier) . '">' . __($boxTitle, 'wpshop') . '</a></li>';
343
+					}
344
+				}
345
+			}
346
+		}
347
+		echo '<li><a href="#tabs-product-related">' . __('Related products', 'wpshop') . '</a></li>';
348
+		echo '<li><a href="#tabs-product-provider">' . __('Providers', 'wpshop') . '</a></li>';
349
+		echo '<li class="wpshop_product_data_display_tab" ><a href="#tabs-product-display">' . __('Product display', 'wpshop') . '</a></li>';
350
+		echo '</ul>';
351
+
352
+		if (!empty($currentTabContent['box'])) {
353
+			foreach ($currentTabContent['box'] as $boxIdentifier => $boxTitle) {
354
+				if (!empty($currentTabContent['boxContent'][$boxIdentifier])) {
355
+					if ($currentTabContent['box'][$boxIdentifier . '_backend_display_type'] == 'fixed-tab') {
356
+						echo '<div id="tabs-' . sanitize_title($boxIdentifier) . '">' . $currentTabContent['boxContent'][$boxIdentifier] . '</div>';
357
+					}
358
+				}
359
+			}
360
+		}
361 361
 
362
-        echo '<div id="tabs-product-related">' . self::related_products_meta_box_content($post) . '</div>';
363
-        echo '<div id="tabs-product-provider">' . self::provider_products_meta_box_content($post) . '</div>';
364
-        echo '<div id="tabs-product-display">' . self::product_frontend_display_config_meta_box($post) . '</div>';
365
-        if (!empty($currentTabContent['boxMore'])) {
366
-            echo $currentTabContent['boxMore'];
367
-        }
368
-        echo '</div>';
362
+		echo '<div id="tabs-product-related">' . self::related_products_meta_box_content($post) . '</div>';
363
+		echo '<div id="tabs-product-provider">' . self::provider_products_meta_box_content($post) . '</div>';
364
+		echo '<div id="tabs-product-display">' . self::product_frontend_display_config_meta_box($post) . '</div>';
365
+		if (!empty($currentTabContent['boxMore'])) {
366
+			echo $currentTabContent['boxMore'];
367
+		}
368
+		echo '</div>';
369 369
 
370
-        echo $output;
371
-    }
370
+		echo $output;
371
+	}
372 372
 
373
-    /**
374
-     * Output the content for related product metabox
375
-     * @param object $post The current edited post
376
-     * @return string
377
-     */
378
-    public static function related_products_meta_box_content($post)
379
-    {
380
-        $content = $existing_selection = '';
381
-
382
-        if (!empty($post->ID)) {
383
-            $related_products_id = get_post_meta($post->ID, WPSHOP_PRODUCT_RELATED_PRODUCTS, true);
384
-            if (!empty($related_products_id) && !empty($related_products_id[0])) {
385
-                foreach ($related_products_id as $related_product_id) {
386
-                    $existing_selection .= '<option selected value="' . $related_product_id . '" >' . get_the_title($related_product_id) . '</option>';
387
-                }
388
-            }
389
-        }
373
+	/**
374
+	 * Output the content for related product metabox
375
+	 * @param object $post The current edited post
376
+	 * @return string
377
+	 */
378
+	public static function related_products_meta_box_content($post)
379
+	{
380
+		$content = $existing_selection = '';
381
+
382
+		if (!empty($post->ID)) {
383
+			$related_products_id = get_post_meta($post->ID, WPSHOP_PRODUCT_RELATED_PRODUCTS, true);
384
+			if (!empty($related_products_id) && !empty($related_products_id[0])) {
385
+				foreach ($related_products_id as $related_product_id) {
386
+					$existing_selection .= '<option selected value="' . $related_product_id . '" >' . get_the_title($related_product_id) . '</option>';
387
+				}
388
+			}
389
+		}
390 390
 
391
-        $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>
391
+		$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>
392 392
 			<select name="related_products_list[]" id="related_products_list" class="ajax_chosen_select_related_products" multiple >' . $existing_selection . '</select>
393 393
 			<input type="hidden" id="wpshop_ajax_search_element_type_related_products" name="wpshop_ajax_search_element_type" value="' . $post->post_type . '" />
394 394
 			<input type="hidden" id="wpshop_nonce_ajax_search_related_products" name="wpshop_nonce_ajax_search" value="' . wp_create_nonce("wpshop_element_search") . '" />';
395 395
 
396
-        return $content;
397
-    }
396
+		return $content;
397
+	}
398 398
 
399
-    /**
400
-     * Output the content for related product metabox
401
-     * @param object $post The current edited post
402
-     * @return string
403
-     */
404
-    public static function provider_products_meta_box_content($post)
405
-    {
406
-        $content = $existing_selection = '';
407
-
408
-        if (!empty($post->ID)) {
409
-            $providers_id = get_post_meta($post->ID, WPSHOP_PRODUCT_PROVIDER, true);
410
-            if (!empty($providers_id) && !empty($providers_id[0])) {
411
-                foreach ($providers_id as $provider_id) {
412
-                    $existing_selection .= '<option selected value="' . $provider_id . '" >' . get_the_title($provider_id) . '</option>';
413
-                }
414
-            }
415
-        }
399
+	/**
400
+	 * Output the content for related product metabox
401
+	 * @param object $post The current edited post
402
+	 * @return string
403
+	 */
404
+	public static function provider_products_meta_box_content($post)
405
+	{
406
+		$content = $existing_selection = '';
407
+
408
+		if (!empty($post->ID)) {
409
+			$providers_id = get_post_meta($post->ID, WPSHOP_PRODUCT_PROVIDER, true);
410
+			if (!empty($providers_id) && !empty($providers_id[0])) {
411
+				foreach ($providers_id as $provider_id) {
412
+					$existing_selection .= '<option selected value="' . $provider_id . '" >' . get_the_title($provider_id) . '</option>';
413
+				}
414
+			}
415
+		}
416 416
 
417
-        $content = '<p>' . __('Type the begin of a provider last name/first name in the field below to add', 'wpshop') . '</p>
417
+		$content = '<p>' . __('Type the begin of a provider last name/first name in the field below to add', 'wpshop') . '</p>
418 418
 			<select name="provider_list[]" id="provider_list" class="ajax_chosen_select_provider_products" multiple >' . $existing_selection . '</select>
419 419
 			<input type="hidden" id="wpshop_ajax_search_element_type_provider_products" name="wpshop_ajax_search_element_type" value="' . WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS . '" />
420 420
 			<input type="hidden" id="wpshop_nonce_ajax_search_provider_products" name="wpshop_nonce_ajax_search" value="' . wp_create_nonce("wpshop_element_search") . '" />';
421 421
 
422
-        return $content;
423
-    }
422
+		return $content;
423
+	}
424 424
 
425
-    /**
426
-     * Define the metabox content for the action box
427
-     * @param obejct $post The current element being edited
428
-     */
429
-    public static function product_actions_meta_box_content($post)
430
-    {
431
-        $output = '';
432
-        /*
425
+	/**
426
+	 * Define the metabox content for the action box
427
+	 * @param obejct $post The current element being edited
428
+	 */
429
+	public static function product_actions_meta_box_content($post)
430
+	{
431
+		$output = '';
432
+		/*
433 433
          * Template parameters
434 434
          */
435
-        $template_part = 'wpshop_duplicate_product';
436
-        $tpl_component = array();
437
-        $tpl_component['PRODUCT_ID'] = $post->ID;
438
-        $tpl_component['PRINT_PRODUCT_SHEET_LINK'] = admin_url('admin-post.php?action=wps_product_sheet&pid=' . $post->ID);
439
-        /*
435
+		$template_part = 'wpshop_duplicate_product';
436
+		$tpl_component = array();
437
+		$tpl_component['PRODUCT_ID'] = $post->ID;
438
+		$tpl_component['PRINT_PRODUCT_SHEET_LINK'] = admin_url('admin-post.php?action=wps_product_sheet&pid=' . $post->ID);
439
+		/*
440 440
          * Build template
441 441
          */
442
-        $output = wpshop_display::display_template_element($template_part, $tpl_component, array(), 'admin');
443
-        unset($tpl_component);
442
+		$output = wpshop_display::display_template_element($template_part, $tpl_component, array(), 'admin');
443
+		unset($tpl_component);
444 444
 
445
-        echo $output;
446
-    }
445
+		echo $output;
446
+	}
447 447
 
448
-    /**
449
-     *    Define the content of the product main information box
450
-     */
451
-    public static function meta_box_content($post, $metaboxArgs)
452
-    {
453
-        global $currentTabContent;
448
+	/**
449
+	 *    Define the content of the product main information box
450
+	 */
451
+	public static function meta_box_content($post, $metaboxArgs)
452
+	{
453
+		global $currentTabContent;
454 454
 
455
-        /*    Add the extra fields defined by the default attribute group in the general section    */
456
-        echo '<div class="wpshop_extra_field_container" >' . $currentTabContent['boxContent'][$metaboxArgs['args']['boxIdentifier']] . '</div>';
457
-    }
455
+		/*    Add the extra fields defined by the default attribute group in the general section    */
456
+		echo '<div class="wpshop_extra_field_container" >' . $currentTabContent['boxContent'][$metaboxArgs['args']['boxIdentifier']] . '</div>';
457
+	}
458 458
 
459
-    /**
460
-     * Define the metabox content for product custom display in product
461
-     * @param object $post The current element being edited
462
-     * @return string The metabox content
463
-     */
464
-    public static function product_frontend_display_config_meta_box($post)
465
-    {
466
-        $content = '';
467
-
468
-        $product_attribute_frontend_display_config = null;
469
-        if (!empty($post->ID)) {
470
-            $product_attribute_frontend_display_config = get_post_meta($post->ID, WPSHOP_PRODUCT_FRONT_DISPLAY_CONF, true);
471
-
472
-            $extra_options = get_option('wpshop_extra_options', array());
473
-            $column_count = (!empty($extra_options['WPSHOP_COLUMN_NUMBER_PRODUCT_EDITION_FOR_FRONT_DISPLAY']) ? $extra_options['WPSHOP_COLUMN_NUMBER_PRODUCT_EDITION_FOR_FRONT_DISPLAY'] : 3);
474
-            $attribute_list = wpshop_attributes::getElementWithAttributeAndValue(wpshop_entities::get_entity_identifier_from_code(self::currentPageCode), $post->ID, WPSHOP_CURRENT_LOCALE);
475
-            $column = 1;
476
-
477
-            if (WPSHOP_DEFINED_SHOP_TYPE == 'sale') {
478
-                $sub_tpl_component = array();
479
-                $sub_tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_NAME'] = __('Action on product', 'wpshop');
480
-
481
-                $tpl_component = array();
482
-                $tpl_component['ADMIN_ATTRIBUTE_LABEL'] = __('Add to cart button', 'wpshop');
483
-                $tpl_component['ADMIN_ATTRIBUTE_FD_NAME'] = self::currentPageCode . '_attr_frontend_display[product_action_button][add_to_cart]';
484
-                $tpl_component['ADMIN_ATTRIBUTE_FD_ID'] = $post->ID . '_product_action_button_add_to_cart';
485
-                $button_is_set_to_be_displayed = (WPSHOP_DEFINED_SHOP_TYPE == 'sale') ? 'yes' : 'no';
486
-
487
-                $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"' : '';
488
-                $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"' : '';
489
-                $sub_tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_CONTENT'] = wpshop_display::display_template_element('wpshop_admin_attr_config_for_front_display', $tpl_component, array(), 'admin');
490
-                unset($tpl_component);
491
-
492
-                $sub_tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_FD_NAME'] = self::currentPageCode . '_attr_frontend_display[product_action_button][add_to_cart]';
493
-                $sub_tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_FD_ID'] = 'product_action_button_add_to_cart';
494
-                $sub_tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_INPUT_CHECKBOX'] = '';
495
-                $sub_content[1] = wpshop_display::display_template_element('wpshop_admin_attr_set_section_for_front_display', $sub_tpl_component, array(), 'admin');
496
-            }
497
-
498
-            if (!empty($attribute_list[$post->ID]) && is_array($attribute_list[$post->ID])) {
499
-                foreach ($attribute_list[$post->ID] as $attribute_set_section_name => $attribute_set_section_content) {
500
-                    if (!isset($sub_content[$column])) {
501
-                        $sub_content[$column] = '';
502
-                    }
503
-
504
-                    $attribute_sub_output = '';
505
-                    foreach ($attribute_set_section_content['attributes'] as $attribute_id => $attribute_def) {
506
-                        if ($attribute_def['attribute_code'] != 'product_attribute_set_id') {
507
-                            $tpl_component = array();
508
-                            $tpl_component['ADMIN_ATTRIBUTE_LABEL'] = $attribute_def['frontend_label'];
509
-                            $tpl_component['ADMIN_ATTRIBUTE_FD_NAME'] = self::currentPageCode . '_attr_frontend_display[attribute][' . $attribute_def['attribute_code'] . ']';
510
-                            $tpl_component['ADMIN_ATTRIBUTE_FD_ID'] = $post->ID . '_' . $attribute_def['attribute_code'];
511
-                            $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"' : '';
512
-                            $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"' : '';
513
-                            $attribute_sub_output .= wpshop_display::display_template_element('wpshop_admin_attr_config_for_front_display', $tpl_component, array(), 'admin');
514
-                            unset($tpl_component);
515
-                        }
516
-                    }
517
-
518
-                    $tpl_component = array();
519
-                    $tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_NAME'] = $attribute_set_section_name;
520
-                    $tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_CONTENT'] = $attribute_sub_output;
521
-                    $tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_FD_NAME'] = self::currentPageCode . '_attr_frontend_display[attribute_set_section][' . $attribute_set_section_content['code'] . ']';
522
-                    $tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_FD_ID'] = $attribute_set_section_content['code'];
523
-                    $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"' : '';
524
-                    $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>';
525
-                    $sub_content[$column] .= wpshop_display::display_template_element('wpshop_admin_attr_set_section_for_front_display', $tpl_component, array(), 'admin');
526
-                    $column++;
527
-                    if ($column > $column_count) {
528
-                        $column = 1;
529
-                    }
530
-                }
531
-            }
532
-            $tpl_component = array();
533
-            $tpl_component['ADMIN_ATTRIBUTE_FRONTEND_DISPLAY_CONTENT'] = '';
534
-            for ($i = 1; $i <= $column_count; $i++) {
535
-                if (!empty($sub_content[$i])) {
536
-                    $tpl_component['ADMIN_ATTRIBUTE_FRONTEND_DISPLAY_CONTENT'] .= '<div class="alignleft" >' . $sub_content[$i] . '</div>';
537
-                }
538
-
539
-            }
540
-            $tpl_component['ADMIN_ATTRIBUTE_FRONTEND_DISPLAY_CONTENT_CLASS'] = empty($product_attribute_frontend_display_config) ? ' class="wpshopHide" ' : '';
541
-            $tpl_component['ADMIN_PRODUCT_ATTRIBUTE_FRONTEND_DISPLAY_MAIN_CHOICE_CHECK'] = empty($product_attribute_frontend_display_config) ? ' checked="checked"' : '';
542
-            $tpl_component['ADMIN_ATTRIBUTE_FD_NAME'] = self::currentPageCode . '_attr_frontend_display';
543
-
544
-            $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>';
545
-        }
459
+	/**
460
+	 * Define the metabox content for product custom display in product
461
+	 * @param object $post The current element being edited
462
+	 * @return string The metabox content
463
+	 */
464
+	public static function product_frontend_display_config_meta_box($post)
465
+	{
466
+		$content = '';
467
+
468
+		$product_attribute_frontend_display_config = null;
469
+		if (!empty($post->ID)) {
470
+			$product_attribute_frontend_display_config = get_post_meta($post->ID, WPSHOP_PRODUCT_FRONT_DISPLAY_CONF, true);
471
+
472
+			$extra_options = get_option('wpshop_extra_options', array());
473
+			$column_count = (!empty($extra_options['WPSHOP_COLUMN_NUMBER_PRODUCT_EDITION_FOR_FRONT_DISPLAY']) ? $extra_options['WPSHOP_COLUMN_NUMBER_PRODUCT_EDITION_FOR_FRONT_DISPLAY'] : 3);
474
+			$attribute_list = wpshop_attributes::getElementWithAttributeAndValue(wpshop_entities::get_entity_identifier_from_code(self::currentPageCode), $post->ID, WPSHOP_CURRENT_LOCALE);
475
+			$column = 1;
476
+
477
+			if (WPSHOP_DEFINED_SHOP_TYPE == 'sale') {
478
+				$sub_tpl_component = array();
479
+				$sub_tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_NAME'] = __('Action on product', 'wpshop');
480
+
481
+				$tpl_component = array();
482
+				$tpl_component['ADMIN_ATTRIBUTE_LABEL'] = __('Add to cart button', 'wpshop');
483
+				$tpl_component['ADMIN_ATTRIBUTE_FD_NAME'] = self::currentPageCode . '_attr_frontend_display[product_action_button][add_to_cart]';
484
+				$tpl_component['ADMIN_ATTRIBUTE_FD_ID'] = $post->ID . '_product_action_button_add_to_cart';
485
+				$button_is_set_to_be_displayed = (WPSHOP_DEFINED_SHOP_TYPE == 'sale') ? 'yes' : 'no';
486
+
487
+				$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"' : '';
488
+				$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"' : '';
489
+				$sub_tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_CONTENT'] = wpshop_display::display_template_element('wpshop_admin_attr_config_for_front_display', $tpl_component, array(), 'admin');
490
+				unset($tpl_component);
491
+
492
+				$sub_tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_FD_NAME'] = self::currentPageCode . '_attr_frontend_display[product_action_button][add_to_cart]';
493
+				$sub_tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_FD_ID'] = 'product_action_button_add_to_cart';
494
+				$sub_tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_INPUT_CHECKBOX'] = '';
495
+				$sub_content[1] = wpshop_display::display_template_element('wpshop_admin_attr_set_section_for_front_display', $sub_tpl_component, array(), 'admin');
496
+			}
546 497
 
547
-        return $content;
548
-    }
498
+			if (!empty($attribute_list[$post->ID]) && is_array($attribute_list[$post->ID])) {
499
+				foreach ($attribute_list[$post->ID] as $attribute_set_section_name => $attribute_set_section_content) {
500
+					if (!isset($sub_content[$column])) {
501
+						$sub_content[$column] = '';
502
+					}
503
+
504
+					$attribute_sub_output = '';
505
+					foreach ($attribute_set_section_content['attributes'] as $attribute_id => $attribute_def) {
506
+						if ($attribute_def['attribute_code'] != 'product_attribute_set_id') {
507
+							$tpl_component = array();
508
+							$tpl_component['ADMIN_ATTRIBUTE_LABEL'] = $attribute_def['frontend_label'];
509
+							$tpl_component['ADMIN_ATTRIBUTE_FD_NAME'] = self::currentPageCode . '_attr_frontend_display[attribute][' . $attribute_def['attribute_code'] . ']';
510
+							$tpl_component['ADMIN_ATTRIBUTE_FD_ID'] = $post->ID . '_' . $attribute_def['attribute_code'];
511
+							$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"' : '';
512
+							$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"' : '';
513
+							$attribute_sub_output .= wpshop_display::display_template_element('wpshop_admin_attr_config_for_front_display', $tpl_component, array(), 'admin');
514
+							unset($tpl_component);
515
+						}
516
+					}
517
+
518
+					$tpl_component = array();
519
+					$tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_NAME'] = $attribute_set_section_name;
520
+					$tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_CONTENT'] = $attribute_sub_output;
521
+					$tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_FD_NAME'] = self::currentPageCode . '_attr_frontend_display[attribute_set_section][' . $attribute_set_section_content['code'] . ']';
522
+					$tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_FD_ID'] = $attribute_set_section_content['code'];
523
+					$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"' : '';
524
+					$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>';
525
+					$sub_content[$column] .= wpshop_display::display_template_element('wpshop_admin_attr_set_section_for_front_display', $tpl_component, array(), 'admin');
526
+					$column++;
527
+					if ($column > $column_count) {
528
+						$column = 1;
529
+					}
530
+				}
531
+			}
532
+			$tpl_component = array();
533
+			$tpl_component['ADMIN_ATTRIBUTE_FRONTEND_DISPLAY_CONTENT'] = '';
534
+			for ($i = 1; $i <= $column_count; $i++) {
535
+				if (!empty($sub_content[$i])) {
536
+					$tpl_component['ADMIN_ATTRIBUTE_FRONTEND_DISPLAY_CONTENT'] .= '<div class="alignleft" >' . $sub_content[$i] . '</div>';
537
+				}
549 538
 
550
-    /**
551
-     * Retrieve the attribute list used for sorting product into frontend listing
552
-     * @return array The attribute list to use for listing sorting
553
-     */
554
-    public static function get_sorting_criteria()
555
-    {
556
-        global $wpdb;
539
+			}
540
+			$tpl_component['ADMIN_ATTRIBUTE_FRONTEND_DISPLAY_CONTENT_CLASS'] = empty($product_attribute_frontend_display_config) ? ' class="wpshopHide" ' : '';
541
+			$tpl_component['ADMIN_PRODUCT_ATTRIBUTE_FRONTEND_DISPLAY_MAIN_CHOICE_CHECK'] = empty($product_attribute_frontend_display_config) ? ' checked="checked"' : '';
542
+			$tpl_component['ADMIN_ATTRIBUTE_FD_NAME'] = self::currentPageCode . '_attr_frontend_display';
557 543
 
558
-        $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')));
544
+			$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>';
545
+		}
559 546
 
560
-        $query = $wpdb->prepare("SELECT code, frontend_label FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE is_used_for_sort_by = %s", 'yes');
561
-        $results = $wpdb->get_results($query, ARRAY_A);
562
-        if (!empty($results)) {
563
-            $data = array_merge($data, $results);
564
-        }
547
+		return $content;
548
+	}
565 549
 
566
-        return $data;
567
-    }
550
+	/**
551
+	 * Retrieve the attribute list used for sorting product into frontend listing
552
+	 * @return array The attribute list to use for listing sorting
553
+	 */
554
+	public static function get_sorting_criteria()
555
+	{
556
+		global $wpdb;
557
+
558
+		$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')));
559
+
560
+		$query = $wpdb->prepare("SELECT code, frontend_label FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE is_used_for_sort_by = %s", 'yes');
561
+		$results = $wpdb->get_results($query, ARRAY_A);
562
+		if (!empty($results)) {
563
+			$data = array_merge($data, $results);
564
+		}
568 565
 
569
-    public static function get_products_matching_attribute($attr_name, $attr_value)
570
-    {
571
-        global $wpdb;
566
+		return $data;
567
+	}
568
+
569
+	public static function get_products_matching_attribute($attr_name, $attr_value)
570
+	{
571
+		global $wpdb;
572 572
 
573
-        $products = array();
574
-        $query = "SELECT * FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE code=%s";
575
-        $data = (array) $wpdb->get_row($wpdb->prepare($query, $attr_name));
573
+		$products = array();
574
+		$query = "SELECT * FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE code=%s";
575
+		$data = (array) $wpdb->get_row($wpdb->prepare($query, $attr_name));
576 576
 
577
-        if (!empty($data)) {
578
-            if ($data['data_type_to_use'] == 'custom') {
579
-                // Find which table to take
580
-                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;}
577
+		if (!empty($data)) {
578
+			if ($data['data_type_to_use'] == 'custom') {
579
+				// Find which table to take
580
+				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;}
581 581
 
582
-                if (isset($table_name)) {
583
-                    // If the value is an id of a select, radio or checkbox
584
-                    if (in_array($data['backend_input'], array('select', 'multiple-select', 'radio', 'checkbox'))) {
582
+				if (isset($table_name)) {
583
+					// If the value is an id of a select, radio or checkbox
584
+					if (in_array($data['backend_input'], array('select', 'multiple-select', 'radio', 'checkbox'))) {
585 585
 
586
-                        $query = $wpdb->prepare("
586
+						$query = $wpdb->prepare("
587 587
 							SELECT " . $table_name . ".entity_id FROM " . $table_name . "
588 588
 							INNER JOIN {$wpdb->posts} AS P ON ( ( P.ID = " . $table_name . ".entity_id ) AND ( P.post_status = 'publish' ) )
589 589
 							LEFT JOIN " . WPSHOP_DBT_ATTRIBUTE . " AS ATT ON ATT.id = " . $table_name . ".attribute_id
590 590
 							LEFT JOIN " . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . " AS ATT_OPT ON " . $table_name . ".value = ATT_OPT.id
591 591
 							WHERE ATT.code=%s AND ( ATT_OPT.value=%s OR ATT_OPT.value=%s )", $attr_name, strtolower(__($attr_value, 'wpshop')), $attr_value
592
-                        );
593
-                        $data = $wpdb->get_results($query);
594
-                    } else {
592
+						);
593
+						$data = $wpdb->get_results($query);
594
+					} else {
595 595
 
596
-                        $query = $wpdb->prepare("
596
+						$query = $wpdb->prepare("
597 597
 							SELECT " . $table_name . ".entity_id FROM " . $table_name . "
598 598
 							INNER JOIN {$wpdb->posts} AS P ON ( ( P.ID = " . $table_name . ".entity_id ) AND ( P.post_status = 'publish' ) )
599 599
 							INNER JOIN " . WPSHOP_DBT_ATTRIBUTE . " AS ATT ON ATT.id = " . $table_name . ".attribute_id
600 600
 								INNER JOIN {$wpdb->posts} AS P ON ( ( P.ID = " . $table_name . ".entity_id ) AND ( P.post_status = 'publish' ) )
601 601
 							WHERE ATT.code=%s AND " . $table_name . ".value=%s", $attr_name, sprintf('%.5f', $attr_value) // force useless zero like 48.58000
602
-                        );
603
-                        $data = $wpdb->get_results($query);
604
-
605
-                    }
606
-                } else {
607
-                    return __('Incorrect shortcode', 'wpshop');
608
-                }
609
-
610
-            } elseif ($data['data_type_to_use'] == 'internal') {
611
-                /** Check the ID of manufacturer **/
612
-                $default_value = unserialize($data['default_value']);
613
-                if (!empty($default_value) && !empty($default_value['default_value'])) {
614
-                    $query = get_post($attr_value);
615
-                    $pid = (!empty($query) && !empty($query->ID)) ? $query->ID : '';
616
-                    if (!empty($pid)) {
617
-                        $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);
618
-                        $data = $wpdb->get_results($query);
619
-                    }
620
-                }
621
-            } else {
622
-                return __('Incorrect shortcode', 'wpshop');
623
-            }
624
-
625
-        } else {
626
-            return __('Incorrect shortcode', 'wpshop');
627
-        }
602
+						);
603
+						$data = $wpdb->get_results($query);
628 604
 
629
-        if (!empty($data)) {
630
-            foreach ($data as $p) {
631
-                if (!empty($p) && is_object($p) && !empty($p->entity_id)) {
632
-                    $products[] = $p->entity_id;
633
-                }
634
-            }
635
-        }
636
-        return $products;
637
-    }
605
+					}
606
+				} else {
607
+					return __('Incorrect shortcode', 'wpshop');
608
+				}
638 609
 
639
-    /**
640
-     * Related product shortcode reader
641
-     *
642
-     * @param array $atts {
643
-     *    pid : Product idenfifier to get related element for
644
-     *    display_mode : The output mode if defined (grid || list)
645
-     * }
646
-     *
647
-     * @return string
648
-     *
649
-     */
650
-    public static function wpshop_related_products_func($atts)
651
-    {
652
-        global $wp_query;
610
+			} elseif ($data['data_type_to_use'] == 'internal') {
611
+				/** Check the ID of manufacturer **/
612
+				$default_value = unserialize($data['default_value']);
613
+				if (!empty($default_value) && !empty($default_value['default_value'])) {
614
+					$query = get_post($attr_value);
615
+					$pid = (!empty($query) && !empty($query->ID)) ? $query->ID : '';
616
+					if (!empty($pid)) {
617
+						$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);
618
+						$data = $wpdb->get_results($query);
619
+					}
620
+				}
621
+			} else {
622
+				return __('Incorrect shortcode', 'wpshop');
623
+			}
653 624
 
654
-        $atts['product_type'] = 'related';
655
-        if (empty($atts['pid'])) {
656
-            $atts['pid'] = $wp_query->posts[0]->ID;
657
-        }
625
+		} else {
626
+			return __('Incorrect shortcode', 'wpshop');
627
+		}
658 628
 
659
-        $related_product_output = self::wpshop_products_func($atts);
629
+		if (!empty($data)) {
630
+			foreach ($data as $p) {
631
+				if (!empty($p) && is_object($p) && !empty($p->entity_id)) {
632
+					$products[] = $p->entity_id;
633
+				}
634
+			}
635
+		}
636
+		return $products;
637
+	}
660 638
 
661
-        $output = '';
662
-        if (!empty($related_product_output)) {
663
-            ob_start();
664
-            require wpshop_tools::get_template_part(WPS_PRODUCT_DIR, WPS_PRODUCT_TEMPLATES_MAIN_DIR, 'frontend', 'related_product');
665
-            $output = ob_get_contents();
666
-            ob_end_clean();
667
-        }
639
+	/**
640
+	 * Related product shortcode reader
641
+	 *
642
+	 * @param array $atts {
643
+	 *    pid : Product idenfifier to get related element for
644
+	 *    display_mode : The output mode if defined (grid || list)
645
+	 * }
646
+	 *
647
+	 * @return string
648
+	 *
649
+	 */
650
+	public static function wpshop_related_products_func($atts)
651
+	{
652
+		global $wp_query;
653
+
654
+		$atts['product_type'] = 'related';
655
+		if (empty($atts['pid'])) {
656
+			$atts['pid'] = $wp_query->posts[0]->ID;
657
+		}
668 658
 
669
-        return $output;
670
-    }
659
+		$related_product_output = self::wpshop_products_func($atts);
671 660
 
672
-    /**
673
-     * Display a list of product from a shortcode
674
-     *
675
-     * @param array $atts {
676
-     *    limit : The number of element to display
677
-     *    order : The information to order list by
678
-     *    sorting : List order (ASC | DESC)
679
-     *    display : Display size (normal | mini)
680
-     *    type : Display tyep (grid | list) only work with display=normal
681
-     *    pagination : The number of element per page
682
-     * display_pagination : Display the pagination or not
683
-     * }
684
-     *
685
-     * @return string
686
-     *
687
-     **/
688
-    public static function wpshop_products_func($atts)
689
-    {
690
-        global $wpdb, $wp_query;
691
-
692
-        $string = '';
693
-        $have_results = false;
694
-        $output_results = true;
695
-        $type = (empty($atts['type']) or !in_array($atts['type'], array('grid', 'list'))) ? WPSHOP_DISPLAY_LIST_TYPE : $atts['type'];
696
-        $pagination = isset($atts['pagination']) ? intval($atts['pagination']) : WPSHOP_ELEMENT_NB_PER_PAGE;
697
-        $cid = !empty($atts['cid']) ? $atts['cid'] : 0;
698
-        $pid = !empty($atts['pid']) ? $atts['pid'] : 0;
699
-        $order_by_sorting = (!empty($atts['sorting']) && ($atts['sorting'] == 'DESC')) ? 'DESC' : 'ASC';
700
-        $limit = isset($atts['limit']) ? intval($atts['limit']) : 0;
701
-        $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;
702
-        $display_pagination = (!empty($atts['display_pagination'])) ? (($atts['display_pagination'] === "yes") ? true : false) : true;
703
-        $attr = '';
704
-
705
-        $sorting_criteria = self::get_sorting_criteria();
706
-
707
-        /** Get products which have att_name equal to att_value    */
708
-        if (!empty($atts['att_name']) && !empty($atts['att_value'])) {
709
-            $attr = $atts['att_name'] . ':' . $atts['att_value'];
710
-
711
-            $products = self::get_products_matching_attribute($atts['att_name'], $atts['att_value']);
712
-
713
-            // Foreach on the found products
714
-            if (!empty($products)) {
715
-                $pid = implode(',', $products);
716
-                if (empty($pid)) {
717
-                    $output_results = false;
718
-                }
719
-
720
-            } else {
721
-                $output_results = false;
722
-            }
661
+		$output = '';
662
+		if (!empty($related_product_output)) {
663
+			ob_start();
664
+			require wpshop_tools::get_template_part(WPS_PRODUCT_DIR, WPS_PRODUCT_TEMPLATES_MAIN_DIR, 'frontend', 'related_product');
665
+			$output = ob_get_contents();
666
+			ob_end_clean();
667
+		}
723 668
 
724
-        }
669
+		return $output;
670
+	}
725 671
 
726
-        /** Get related products    */
727
-        if (!empty($atts['product_type'])) {
728
-            switch ($atts['product_type']) {
729
-                case 'related':
730
-                    $product_id = !empty($atts['pid']) ? (int) $atts['pid'] : get_the_ID();
731
-                    $type = !empty($atts['display_mode']) && in_array($atts['display_mode'], array('list', 'grid')) ? $atts['display_mode'] : WPSHOP_DISPLAY_LIST_TYPE;
732
-                    $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;
733
-
734
-                    $pids = get_post_meta((int) $product_id, WPSHOP_PRODUCT_RELATED_PRODUCTS, true);
735
-                    if (!empty($pids) && !empty($pids[0])) {
736
-                        $pid = implode(',', $pids);
737
-                    }
738
-                    if (empty($pid) || $pid == $product_id) {
739
-                        $output_results = false;
740
-                    }
741
-
742
-                    break;
743
-            }
744
-        }
672
+	/**
673
+	 * Display a list of product from a shortcode
674
+	 *
675
+	 * @param array $atts {
676
+	 *    limit : The number of element to display
677
+	 *    order : The information to order list by
678
+	 *    sorting : List order (ASC | DESC)
679
+	 *    display : Display size (normal | mini)
680
+	 *    type : Display tyep (grid | list) only work with display=normal
681
+	 *    pagination : The number of element per page
682
+	 * display_pagination : Display the pagination or not
683
+	 * }
684
+	 *
685
+	 * @return string
686
+	 *
687
+	 **/
688
+	public static function wpshop_products_func($atts)
689
+	{
690
+		global $wpdb, $wp_query;
691
+
692
+		$string = '';
693
+		$have_results = false;
694
+		$output_results = true;
695
+		$type = (empty($atts['type']) or !in_array($atts['type'], array('grid', 'list'))) ? WPSHOP_DISPLAY_LIST_TYPE : $atts['type'];
696
+		$pagination = isset($atts['pagination']) ? intval($atts['pagination']) : WPSHOP_ELEMENT_NB_PER_PAGE;
697
+		$cid = !empty($atts['cid']) ? $atts['cid'] : 0;
698
+		$pid = !empty($atts['pid']) ? $atts['pid'] : 0;
699
+		$order_by_sorting = (!empty($atts['sorting']) && ($atts['sorting'] == 'DESC')) ? 'DESC' : 'ASC';
700
+		$limit = isset($atts['limit']) ? intval($atts['limit']) : 0;
701
+		$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;
702
+		$display_pagination = (!empty($atts['display_pagination'])) ? (($atts['display_pagination'] === "yes") ? true : false) : true;
703
+		$attr = '';
704
+
705
+		$sorting_criteria = self::get_sorting_criteria();
706
+
707
+		/** Get products which have att_name equal to att_value    */
708
+		if (!empty($atts['att_name']) && !empty($atts['att_value'])) {
709
+			$attr = $atts['att_name'] . ':' . $atts['att_value'];
710
+
711
+			$products = self::get_products_matching_attribute($atts['att_name'], $atts['att_value']);
712
+
713
+			// Foreach on the found products
714
+			if (!empty($products)) {
715
+				$pid = implode(',', $products);
716
+				if (empty($pid)) {
717
+					$output_results = false;
718
+				}
745 719
 
746
-        /** Output all the products    */
747
-        if ($output_results) {
748
-            $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);
720
+			} else {
721
+				$output_results = false;
722
+			}
749 723
 
750
-            if ($data[0]) {
751
-                $have_results = true;
752
-                $string = $data[1];
753
-            }
754
-        }
724
+		}
755 725
 
756
-        /** If there are result to display    */
757
-        if ($have_results) {
758
-            $sorting = '';
759
-            if (!empty($pid)) {
760
-                $product_list = explode(',', $pid);
761
-                if (count($product_list) == 1) {
762
-                    $atts['sorting'] = 'no';
763
-                }
764
-            }
765
-
766
-            /*
726
+		/** Get related products    */
727
+		if (!empty($atts['product_type'])) {
728
+			switch ($atts['product_type']) {
729
+				case 'related':
730
+					$product_id = !empty($atts['pid']) ? (int) $atts['pid'] : get_the_ID();
731
+					$type = !empty($atts['display_mode']) && in_array($atts['display_mode'], array('list', 'grid')) ? $atts['display_mode'] : WPSHOP_DISPLAY_LIST_TYPE;
732
+					$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;
733
+
734
+					$pids = get_post_meta((int) $product_id, WPSHOP_PRODUCT_RELATED_PRODUCTS, true);
735
+					if (!empty($pids) && !empty($pids[0])) {
736
+						$pid = implode(',', $pids);
737
+					}
738
+					if (empty($pid) || $pid == $product_id) {
739
+						$output_results = false;
740
+					}
741
+
742
+					break;
743
+			}
744
+		}
745
+
746
+		/** Output all the products    */
747
+		if ($output_results) {
748
+			$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);
749
+
750
+			if ($data[0]) {
751
+				$have_results = true;
752
+				$string = $data[1];
753
+			}
754
+		}
755
+
756
+		/** If there are result to display    */
757
+		if ($have_results) {
758
+			$sorting = '';
759
+			if (!empty($pid)) {
760
+				$product_list = explode(',', $pid);
761
+				if (count($product_list) == 1) {
762
+					$atts['sorting'] = 'no';
763
+				}
764
+			}
765
+
766
+			/*
767 767
              * Template parameters
768 768
              */
769
-            $template_part = 'product_listing_sorting';
770
-            $tpl_component = array();
769
+			$template_part = 'product_listing_sorting';
770
+			$tpl_component = array();
771 771
 
772
-            /*
772
+			/*
773 773
              * Build template
774 774
              */
775
-            $tpl_way_to_take = wpshop_display::check_way_for_template($template_part);
776
-            if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) {
777
-                /*    Include the old way template part    */
778
-                ob_start();
779
-                require wpshop_display::get_template_file($tpl_way_to_take[1]);
780
-                $sorting = ob_get_contents();
781
-                ob_end_clean();
782
-            } else {
783
-                /*
775
+			$tpl_way_to_take = wpshop_display::check_way_for_template($template_part);
776
+			if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) {
777
+				/*    Include the old way template part    */
778
+				ob_start();
779
+				require wpshop_display::get_template_file($tpl_way_to_take[1]);
780
+				$sorting = ob_get_contents();
781
+				ob_end_clean();
782
+			} else {
783
+				/*
784 784
                  * Display hidden field every times
785 785
                  */
786
-                $sub_template_part = 'product_listing_sorting_hidden_field';
787
-                $sub_tpl_component = array();
788
-                $sub_tpl_component['DISPLAY_TYPE'] = $type;
789
-                $sub_tpl_component['ORDER'] = $order_by_sorting;
790
-                $sub_tpl_component['PRODUCT_NUMBER'] = $pagination;
791
-                $sub_tpl_component['CURRENT_PAGE'] = 1;
792
-                $sub_tpl_component['CATEGORY_ID'] = $cid;
793
-                $sub_tpl_component['PRODUCT_ID'] = $pid;
794
-                $sub_tpl_component['ATTR'] = $attr;
795
-                $tpl_component['SORTING_HIDDEN_FIELDS'] = wpshop_display::display_template_element($sub_template_part, $sub_tpl_component, array(), 'admin');
796
-                unset($sub_tpl_component);
797
-
798
-                if ((!empty($sorting_criteria) && is_array($sorting_criteria))) {
799
-                    $sub_template_part = 'product_listing_sorting_criteria';
800
-                    $sub_tpl_component = array();
801
-                    $criteria = '';
802
-                    foreach ($sorting_criteria as $c):
803
-                        $criteria .= '<option value="' . $c['code'] . '">' . __($c['frontend_label'], 'wpshop') . '</option>';
804
-                    endforeach;
805
-                    $sub_tpl_component['SORTING_CRITERIA_LIST'] = $criteria;
806
-                    $tpl_component['SORTING_CRITERIA'] = wpshop_display::display_template_element($sub_template_part, $sub_tpl_component);
807
-                    unset($sub_tpl_component);
808
-                }
809
-
810
-                if (empty($atts['sorting']) || (!empty($atts['sorting']) && ($atts['sorting'] != 'no'))) {
811
-                    $tpl_component['DISPLAY_TYPE_STATE_GRID'] = $type == 'grid' ? ' active' : null;
812
-                    $tpl_component['DISPLAY_TYPE_STATE_LIST'] = $type == 'list' ? ' active' : null;
813
-                    $sorting = wpshop_display::display_template_element($template_part, $tpl_component);
814
-                } else if (!empty($atts['sorting']) && ($atts['sorting'] == 'no')) {
815
-                    $sub_template_part = 'product_listing_sorting_criteria_hidden';
816
-                    $sub_tpl_component = array();
817
-                    $sub_tpl_component['CRITERIA_DEFAULT'] = !empty($sorting_criteria[0]['code']) ? $sorting_criteria[0]['code'] : 'title';
818
-                    $tpl_component['SORTING_CRITERIA'] = wpshop_display::display_template_element($sub_template_part, $sub_tpl_component, array(), 'admin');
819
-                    unset($sub_tpl_component);
820
-
821
-                    $template_part = 'product_listing_sorting_hidden';
822
-                    $sorting = wpshop_display::display_template_element($template_part, $tpl_component, array(), 'admin');
823
-                }
824
-            }
825
-            unset($tpl_component);
826
-
827
-            if (!empty($atts) && !empty($atts['container']) && $atts['container'] == 'no') {
828
-                $string = $sorting . '<div data-nonce="' . wp_create_nonce('products_by_criteria') . '" class="wps-catalog-container wps-bloc-loader">' . $string . '</div>';
829
-            } else {
830
-                $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>';
831
-            }
832
-        } else if (empty($atts['no_result_message']) || ($atts['no_result_message'] != 'no')) {
833
-            $string = __('There is nothing to output here', 'wpshop');
834
-        }
786
+				$sub_template_part = 'product_listing_sorting_hidden_field';
787
+				$sub_tpl_component = array();
788
+				$sub_tpl_component['DISPLAY_TYPE'] = $type;
789
+				$sub_tpl_component['ORDER'] = $order_by_sorting;
790
+				$sub_tpl_component['PRODUCT_NUMBER'] = $pagination;
791
+				$sub_tpl_component['CURRENT_PAGE'] = 1;
792
+				$sub_tpl_component['CATEGORY_ID'] = $cid;
793
+				$sub_tpl_component['PRODUCT_ID'] = $pid;
794
+				$sub_tpl_component['ATTR'] = $attr;
795
+				$tpl_component['SORTING_HIDDEN_FIELDS'] = wpshop_display::display_template_element($sub_template_part, $sub_tpl_component, array(), 'admin');
796
+				unset($sub_tpl_component);
797
+
798
+				if ((!empty($sorting_criteria) && is_array($sorting_criteria))) {
799
+					$sub_template_part = 'product_listing_sorting_criteria';
800
+					$sub_tpl_component = array();
801
+					$criteria = '';
802
+					foreach ($sorting_criteria as $c):
803
+						$criteria .= '<option value="' . $c['code'] . '">' . __($c['frontend_label'], 'wpshop') . '</option>';
804
+					endforeach;
805
+					$sub_tpl_component['SORTING_CRITERIA_LIST'] = $criteria;
806
+					$tpl_component['SORTING_CRITERIA'] = wpshop_display::display_template_element($sub_template_part, $sub_tpl_component);
807
+					unset($sub_tpl_component);
808
+				}
835 809
 
836
-        return do_shortcode($string);
837
-    }
810
+				if (empty($atts['sorting']) || (!empty($atts['sorting']) && ($atts['sorting'] != 'no'))) {
811
+					$tpl_component['DISPLAY_TYPE_STATE_GRID'] = $type == 'grid' ? ' active' : null;
812
+					$tpl_component['DISPLAY_TYPE_STATE_LIST'] = $type == 'list' ? ' active' : null;
813
+					$sorting = wpshop_display::display_template_element($template_part, $tpl_component);
814
+				} else if (!empty($atts['sorting']) && ($atts['sorting'] == 'no')) {
815
+					$sub_template_part = 'product_listing_sorting_criteria_hidden';
816
+					$sub_tpl_component = array();
817
+					$sub_tpl_component['CRITERIA_DEFAULT'] = !empty($sorting_criteria[0]['code']) ? $sorting_criteria[0]['code'] : 'title';
818
+					$tpl_component['SORTING_CRITERIA'] = wpshop_display::display_template_element($sub_template_part, $sub_tpl_component, array(), 'admin');
819
+					unset($sub_tpl_component);
820
+
821
+					$template_part = 'product_listing_sorting_hidden';
822
+					$sorting = wpshop_display::display_template_element($template_part, $tpl_component, array(), 'admin');
823
+				}
824
+			}
825
+			unset($tpl_component);
838 826
 
839
-    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)
840
-    {
841
-        global $wpdb;
827
+			if (!empty($atts) && !empty($atts['container']) && $atts['container'] == 'no') {
828
+				$string = $sorting . '<div data-nonce="' . wp_create_nonce('products_by_criteria') . '" class="wps-catalog-container wps-bloc-loader">' . $string . '</div>';
829
+			} else {
830
+				$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>';
831
+			}
832
+		} else if (empty($atts['no_result_message']) || ($atts['no_result_message'] != 'no')) {
833
+			$string = __('There is nothing to output here', 'wpshop');
834
+		}
842 835
 
843
-        $string = '<span id="wpshop_loading">&nbsp;</span>';
844
-        $have_results = false;
845
-        $display_type = (!empty($display_type) && in_array($display_type, array('grid', 'list'))) ? $display_type : 'grid';
836
+		return do_shortcode($string);
837
+	}
846 838
 
847
-        /** Check if Discount are activated */
848
-        $discount_option = get_option('wpshop_catalog_product_option');
839
+	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)
840
+	{
841
+		global $wpdb;
849 842
 
850
-        if ($criteria == 'product_price' && !empty($discount_option) && !empty($discount_option['discount']) && $discount_option['discount'] == 'on') {
851
-            $criteria = 'wpshop_displayed_price';
852
-        }
843
+		$string = '<span id="wpshop_loading">&nbsp;</span>';
844
+		$have_results = false;
845
+		$display_type = (!empty($display_type) && in_array($display_type, array('grid', 'list'))) ? $display_type : 'grid';
853 846
 
854
-        $query = array(
855
-            'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT,
856
-            'order' => $order,
857
-            'posts_per_page' => $products_per_page,
858
-            'paged' => $page_number,
859
-            'post_status' => 'publish',
860
-        );
861
-
862
-        // If the limit is greater than zero, hide pagination and change posts_per_page var
863
-        if ($nb_of_product_limit > 0) {
864
-            $query['posts_per_page'] = $nb_of_product_limit;
865
-            unset($query['paged']);
866
-        }
867
-        if (!empty($pid)) {
868
-            if (!is_array($pid)) {
869
-                $pid = explode(',', $pid);
870
-            }
847
+		/** Check if Discount are activated */
848
+		$discount_option = get_option('wpshop_catalog_product_option');
871 849
 
872
-            $query['post__in'] = $pid;
873
-        }
874
-        if (!empty($cid)) {
875
-            $cid = explode(',', $cid);
876
-            $query['tax_query'] = array(array(
877
-                'taxonomy' => WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES,
878
-                'field' => 'id',
879
-                'terms' => $cid,
880
-                'operator' => 'IN',
881
-            ));
882
-        }
883
-        if ($criteria != null) {
884
-            switch ($criteria) {
885
-                case 'creator':
886
-                case 'author':
887
-                    $query['author'] = get_current_user_id();
888
-                    break;
889
-                case 'none':
890
-                case 'ID':
891
-                case 'title':
892
-                case 'date':
893
-                case 'modified':
894
-                case 'relevance':
895
-                case 'post__in':
896
-                case 'rand':
897
-                    $query['orderby'] = $criteria;
898
-                    break;
899
-                default:
900
-                    if (!empty($pid)) {
901
-                        $post_meta = get_post_meta($pid, '_' . $criteria, true);
902
-                    } else {
903
-                        $check_meta = $wpdb->prepare("SELECT COUNT(meta_id) as meta_criteria FROM " . $wpdb->postmeta . " WHERE meta_key = %s", '_' . $criteria);
904
-                        $post_meta = $wpdb->get_var($check_meta);
905
-                    }
906
-                    if (!empty($post_meta)) {
907
-                        if (in_array($criteria, array('wpshop_displayed_price', 'product_price'))) {
908
-                            $query['orderby'] = 'meta_value_num';
909
-                        } else {
910
-                            $query['orderby'] = 'meta_value';
911
-                        }
912
-                        $query['meta_key'] = '_' . $criteria;
913
-                    }
914
-                    break;
915
-            }
916
-        } else {
917
-            $query['orderby'] = 'menu_order ID';
918
-        }
919
-        $post_per_page = $query['posts_per_page'];
920
-        $total_products = (!empty($query['post__in'])) ? $query['post__in'] : 0;
921
-        if (!empty($pid) && !empty($query['post__in']) && count($query['post__in']) > $query['posts_per_page']) {
922
-            $tmp_array = array();
923
-
924
-            if (empty($page_number) || $page_number == 1) {
925
-                for ($i = 0; $i < $query['posts_per_page']; $i++) {
926
-                    $tmp_array[] = $query['post__in'][$i];
927
-                }
928
-            } else {
929
-                $begin_number = (($page_number - 1) * $query['posts_per_page']);
930
-                for ($i = $begin_number; $i < $query['posts_per_page'] + $begin_number; $i++) {
931
-                    if (!empty($query['post__in'][$i])) {
932
-                        $tmp_array[] = $query['post__in'][$i];
933
-                    }
934
-                }
935
-            }
936
-            unset($query['post__in']);
937
-            $query['post__in'] = $tmp_array;
938
-            $query['posts_per_page'] = -1;
939
-        }
850
+		if ($criteria == 'product_price' && !empty($discount_option) && !empty($discount_option['discount']) && $discount_option['discount'] == 'on') {
851
+			$criteria = 'wpshop_displayed_price';
852
+		}
940 853
 
941
-        $query['post_status'] = 'publish';
942
-
943
-        $custom_query = new WP_Query($query);
944
-
945
-        if ($custom_query->have_posts()) {
946
-            $have_results = true;
947
-
948
-            // ---------------- //
949
-            // Products listing //
950
-            // ---------------- //
951
-            $current_position = 1;
952
-            $product_list = '';
953
-            while ($custom_query->have_posts()): $custom_query->the_post();
954
-                $cats = get_the_terms(get_the_ID(), WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES);
955
-                $cats = !empty($cats) && is_array($cats) ? array_values($cats) : array();
956
-                $cat_id = empty($cats) ? 0 : $cats[0]->term_id;
957
-                $product_list .= self::product_mini_output(get_the_ID(), $cat_id, $display_type, $current_position, $grid_element_nb_per_line);
958
-                $current_position++;
959
-            endwhile;
960
-            $tpl_component = array();
961
-            $tpl_component['PRODUCT_CONTAINER_TYPE_CLASS'] = ($display_type == 'grid' ? ' ' . $display_type . '_' . $grid_element_nb_per_line : '') . ' ' . $display_type . '_mode';
962
-            $tpl_component['PRODUCT_LIST_DISPLAY_TYPE'] = $display_type;
963
-            $tpl_component['PRODUCT_LIST_PER_LINE'] = $grid_element_nb_per_line;
964
-            $tpl_component['PRODUCT_LIST'] = $product_list;
965
-            $tpl_component['CROSSED_OUT_PRICE'] = '';
966
-            $tpl_component['LOW_STOCK_ALERT_MESSAGE'] = '';
967
-            $string = wpshop_display::display_template_element('product_list_container', $tpl_component);
968
-
969
-            // --------------------- //
970
-            // Pagination management //
971
-            // --------------------- //
972
-            if ($display_pagination) {
973
-                if ($nb_of_product_limit == 0) {
974
-
975
-                    $paginate = paginate_links(array(
976
-                        'base' => '%_%',
977
-                        'format' => '/?page_product=%#%',
978
-                        'current' => $page_number,
979
-                        'total' => $custom_query->max_num_pages,
980
-                        'type' => 'array',
981
-                        'prev_next' => false,
982
-                    ));
983
-                    if (!empty($paginate)) {
984
-                        $string .= '<ul class="pagination wps-pagination">';
985
-                        foreach ($paginate as $p) {
986
-                            $string .= '<li>' . $p . '</li>';
987
-                        }
988
-                        $string .= '</ul>';
989
-                    }
990
-                }
991
-
992
-                if (!empty($pid) && !empty($query['post__in']) && count($total_products) > $post_per_page) {
993
-                    $paginate = paginate_links(array(
994
-                        'base' => '%_%',
995
-                        'format' => '/?page_product=%#%',
996
-                        'current' => $page_number,
997
-                        'total' => ceil(count($total_products) / $post_per_page),
998
-                        'type' => 'array',
999
-                        'prev_next' => false,
1000
-                    ));
1001
-                    if (!empty($paginate)) {
1002
-                        $string .= '<ul class="pagination wps-pagination">';
1003
-                        foreach ($paginate as $p) {
1004
-                            $string .= '<li>' . $p . '</li>';
1005
-                        }
1006
-                        $string .= '</ul>';
1007
-                    }
1008
-                }
1009
-            }
854
+		$query = array(
855
+			'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT,
856
+			'order' => $order,
857
+			'posts_per_page' => $products_per_page,
858
+			'paged' => $page_number,
859
+			'post_status' => 'publish',
860
+		);
861
+
862
+		// If the limit is greater than zero, hide pagination and change posts_per_page var
863
+		if ($nb_of_product_limit > 0) {
864
+			$query['posts_per_page'] = $nb_of_product_limit;
865
+			unset($query['paged']);
866
+		}
867
+		if (!empty($pid)) {
868
+			if (!is_array($pid)) {
869
+				$pid = explode(',', $pid);
870
+			}
1010 871
 
1011
-        }
1012
-        wp_reset_query(); // important
872
+			$query['post__in'] = $pid;
873
+		}
874
+		if (!empty($cid)) {
875
+			$cid = explode(',', $cid);
876
+			$query['tax_query'] = array(array(
877
+				'taxonomy' => WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES,
878
+				'field' => 'id',
879
+				'terms' => $cid,
880
+				'operator' => 'IN',
881
+			));
882
+		}
883
+		if ($criteria != null) {
884
+			switch ($criteria) {
885
+				case 'creator':
886
+				case 'author':
887
+					$query['author'] = get_current_user_id();
888
+					break;
889
+				case 'none':
890
+				case 'ID':
891
+				case 'title':
892
+				case 'date':
893
+				case 'modified':
894
+				case 'relevance':
895
+				case 'post__in':
896
+				case 'rand':
897
+					$query['orderby'] = $criteria;
898
+					break;
899
+				default:
900
+					if (!empty($pid)) {
901
+						$post_meta = get_post_meta($pid, '_' . $criteria, true);
902
+					} else {
903
+						$check_meta = $wpdb->prepare("SELECT COUNT(meta_id) as meta_criteria FROM " . $wpdb->postmeta . " WHERE meta_key = %s", '_' . $criteria);
904
+						$post_meta = $wpdb->get_var($check_meta);
905
+					}
906
+					if (!empty($post_meta)) {
907
+						if (in_array($criteria, array('wpshop_displayed_price', 'product_price'))) {
908
+							$query['orderby'] = 'meta_value_num';
909
+						} else {
910
+							$query['orderby'] = 'meta_value';
911
+						}
912
+						$query['meta_key'] = '_' . $criteria;
913
+					}
914
+					break;
915
+			}
916
+		} else {
917
+			$query['orderby'] = 'menu_order ID';
918
+		}
919
+		$post_per_page = $query['posts_per_page'];
920
+		$total_products = (!empty($query['post__in'])) ? $query['post__in'] : 0;
921
+		if (!empty($pid) && !empty($query['post__in']) && count($query['post__in']) > $query['posts_per_page']) {
922
+			$tmp_array = array();
923
+
924
+			if (empty($page_number) || $page_number == 1) {
925
+				for ($i = 0; $i < $query['posts_per_page']; $i++) {
926
+					$tmp_array[] = $query['post__in'][$i];
927
+				}
928
+			} else {
929
+				$begin_number = (($page_number - 1) * $query['posts_per_page']);
930
+				for ($i = $begin_number; $i < $query['posts_per_page'] + $begin_number; $i++) {
931
+					if (!empty($query['post__in'][$i])) {
932
+						$tmp_array[] = $query['post__in'][$i];
933
+					}
934
+				}
935
+			}
936
+			unset($query['post__in']);
937
+			$query['post__in'] = $tmp_array;
938
+			$query['posts_per_page'] = -1;
939
+		}
1013 940
 
1014
-        return array($have_results, $string);
1015
-    }
941
+		$query['post_status'] = 'publish';
942
+
943
+		$custom_query = new WP_Query($query);
944
+
945
+		if ($custom_query->have_posts()) {
946
+			$have_results = true;
947
+
948
+			// ---------------- //
949
+			// Products listing //
950
+			// ---------------- //
951
+			$current_position = 1;
952
+			$product_list = '';
953
+			while ($custom_query->have_posts()): $custom_query->the_post();
954
+				$cats = get_the_terms(get_the_ID(), WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES);
955
+				$cats = !empty($cats) && is_array($cats) ? array_values($cats) : array();
956
+				$cat_id = empty($cats) ? 0 : $cats[0]->term_id;
957
+				$product_list .= self::product_mini_output(get_the_ID(), $cat_id, $display_type, $current_position, $grid_element_nb_per_line);
958
+				$current_position++;
959
+			endwhile;
960
+			$tpl_component = array();
961
+			$tpl_component['PRODUCT_CONTAINER_TYPE_CLASS'] = ($display_type == 'grid' ? ' ' . $display_type . '_' . $grid_element_nb_per_line : '') . ' ' . $display_type . '_mode';
962
+			$tpl_component['PRODUCT_LIST_DISPLAY_TYPE'] = $display_type;
963
+			$tpl_component['PRODUCT_LIST_PER_LINE'] = $grid_element_nb_per_line;
964
+			$tpl_component['PRODUCT_LIST'] = $product_list;
965
+			$tpl_component['CROSSED_OUT_PRICE'] = '';
966
+			$tpl_component['LOW_STOCK_ALERT_MESSAGE'] = '';
967
+			$string = wpshop_display::display_template_element('product_list_container', $tpl_component);
968
+
969
+			// --------------------- //
970
+			// Pagination management //
971
+			// --------------------- //
972
+			if ($display_pagination) {
973
+				if ($nb_of_product_limit == 0) {
974
+
975
+					$paginate = paginate_links(array(
976
+						'base' => '%_%',
977
+						'format' => '/?page_product=%#%',
978
+						'current' => $page_number,
979
+						'total' => $custom_query->max_num_pages,
980
+						'type' => 'array',
981
+						'prev_next' => false,
982
+					));
983
+					if (!empty($paginate)) {
984
+						$string .= '<ul class="pagination wps-pagination">';
985
+						foreach ($paginate as $p) {
986
+							$string .= '<li>' . $p . '</li>';
987
+						}
988
+						$string .= '</ul>';
989
+					}
990
+				}
1016 991
 
1017
-    /**
1018
-     * Update quantity for a product
1019
-     * @param integer $product_id The product we want to update quantity for
1020
-     * @param decimal $qty The new quantity
1021
-     */
1022
-    public static function reduce_product_stock_qty($product_id, $qty, $variation_id = '')
1023
-    {
1024
-        global $wpdb;
1025
-
1026
-        $product = self::get_product_data($product_id);
1027
-        /** Check if there is variation ***/
1028
-        if (!empty($variation_id) && $variation_id != $product_id) {
1029
-            $variation_post_type = get_post_type($variation_id);
1030
-            if ($variation_post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) {
1031
-                /** Check if variation def is combined **/
1032
-                $variations = get_post_meta($product_id, '_wpshop_variation_defining', true);
1033
-                if (!empty($variations) && !empty($variations['options']) && !empty($variations['options']['priority']) && in_array('combined', $variations['options']['priority'])) {
1034
-                    /** Get post meta of variation */
1035
-                    $variation_metadata = get_post_meta($variation_id, '_wpshop_product_metadata', true);
1036
-                    if (!empty($variation_metadata) && isset($variation_metadata['product_stock'])) {
1037
-                        $product = self::get_product_data($variation_id);
1038
-                        $product_id = $variation_id;
1039
-                    }
1040
-                }
1041
-            }
1042
-        }
992
+				if (!empty($pid) && !empty($query['post__in']) && count($total_products) > $post_per_page) {
993
+					$paginate = paginate_links(array(
994
+						'base' => '%_%',
995
+						'format' => '/?page_product=%#%',
996
+						'current' => $page_number,
997
+						'total' => ceil(count($total_products) / $post_per_page),
998
+						'type' => 'array',
999
+						'prev_next' => false,
1000
+					));
1001
+					if (!empty($paginate)) {
1002
+						$string .= '<ul class="pagination wps-pagination">';
1003
+						foreach ($paginate as $p) {
1004
+							$string .= '<li>' . $p . '</li>';
1005
+						}
1006
+						$string .= '</ul>';
1007
+					}
1008
+				}
1009
+			}
1010
+
1011
+		}
1012
+		wp_reset_query(); // important
1013
+
1014
+		return array($have_results, $string);
1015
+	}
1016
+
1017
+	/**
1018
+	 * Update quantity for a product
1019
+	 * @param integer $product_id The product we want to update quantity for
1020
+	 * @param decimal $qty The new quantity
1021
+	 */
1022
+	public static function reduce_product_stock_qty($product_id, $qty, $variation_id = '')
1023
+	{
1024
+		global $wpdb;
1025
+
1026
+		$product = self::get_product_data($product_id);
1027
+		/** Check if there is variation ***/
1028
+		if (!empty($variation_id) && $variation_id != $product_id) {
1029
+			$variation_post_type = get_post_type($variation_id);
1030
+			if ($variation_post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) {
1031
+				/** Check if variation def is combined **/
1032
+				$variations = get_post_meta($product_id, '_wpshop_variation_defining', true);
1033
+				if (!empty($variations) && !empty($variations['options']) && !empty($variations['options']['priority']) && in_array('combined', $variations['options']['priority'])) {
1034
+					/** Get post meta of variation */
1035
+					$variation_metadata = get_post_meta($variation_id, '_wpshop_product_metadata', true);
1036
+					if (!empty($variation_metadata) && isset($variation_metadata['product_stock'])) {
1037
+						$product = self::get_product_data($variation_id);
1038
+						$product_id = $variation_id;
1039
+					}
1040
+				}
1041
+			}
1042
+		}
1043 1043
 
1044
-        if (!empty($product)) {
1045
-            $newQty = $product['product_stock'] - $qty;
1046
-            $value_id = 0;
1047
-            if ($newQty >= 0) {
1048
-                $query = '
1044
+		if (!empty($product)) {
1045
+			$newQty = $product['product_stock'] - $qty;
1046
+			$value_id = 0;
1047
+			if ($newQty >= 0) {
1048
+				$query = '
1049 1049
 					SELECT wp_wpshop__attribute_value_decimal.value_id
1050 1050
 					FROM wp_wpshop__attribute_value_decimal
1051 1051
 					LEFT JOIN wp_wpshop__attribute ON wp_wpshop__attribute_value_decimal.attribute_id = wp_wpshop__attribute.id
1052 1052
 					WHERE wp_wpshop__attribute_value_decimal.entity_id=' . $product_id . ' AND wp_wpshop__attribute.code="product_stock"
1053 1053
 					LIMIT 1
1054 1054
 				';
1055
-                $value_id = $wpdb->get_var($query);
1056
-                $update = $wpdb->update('wp_wpshop__attribute_value_decimal', array('value' => wpshop_tools::wpshop_clean($newQty)), array('value_id' => $value_id));
1057
-            }
1058
-            // Historic
1059
-            $attribute_histo_content = array();
1060
-            $attribute_histo_content['status'] = 'valid';
1061
-            $attribute_histo_content['creation_date'] = current_time('mysql', 0);
1062
-            $attribute_histo_content['creation_date_value'] = (!empty($attribute_histo[0]->creation_date_value)) ? $attribute_histo[0]->creation_date_value : current_time('mysql', 0);
1063
-            $attribute_histo_content['original_value_id'] = $value_id;
1064
-            $attribute_histo_content['entity_type_id'] = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT);
1065
-            $stock_atribute = wpshop_attributes::getElement('product_stock', "'valid'", 'code');
1066
-            $attribute_histo_content['attribute_id'] = $stock_atribute->id;
1067
-            $attribute_histo_content['entity_id'] = $product_id;
1068
-            $attribute_histo_content['value'] = $product['product_stock'];
1069
-            $attribute_histo_content['value_type'] = 'wp_wpshop__attribute_value_decimal';
1070
-            $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_HISTO, $attribute_histo_content);
1071
-
1072
-            $product_meta = get_post_meta($product_id, '_wpshop_product_metadata', true);
1073
-            $product_meta['product_stock'] = $newQty;
1074
-            update_post_meta($product_id, '_wpshop_product_metadata', $product_meta);
1075
-        }
1076
-    }
1055
+				$value_id = $wpdb->get_var($query);
1056
+				$update = $wpdb->update('wp_wpshop__attribute_value_decimal', array('value' => wpshop_tools::wpshop_clean($newQty)), array('value_id' => $value_id));
1057
+			}
1058
+			// Historic
1059
+			$attribute_histo_content = array();
1060
+			$attribute_histo_content['status'] = 'valid';
1061
+			$attribute_histo_content['creation_date'] = current_time('mysql', 0);
1062
+			$attribute_histo_content['creation_date_value'] = (!empty($attribute_histo[0]->creation_date_value)) ? $attribute_histo[0]->creation_date_value : current_time('mysql', 0);
1063
+			$attribute_histo_content['original_value_id'] = $value_id;
1064
+			$attribute_histo_content['entity_type_id'] = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT);
1065
+			$stock_atribute = wpshop_attributes::getElement('product_stock', "'valid'", 'code');
1066
+			$attribute_histo_content['attribute_id'] = $stock_atribute->id;
1067
+			$attribute_histo_content['entity_id'] = $product_id;
1068
+			$attribute_histo_content['value'] = $product['product_stock'];
1069
+			$attribute_histo_content['value_type'] = 'wp_wpshop__attribute_value_decimal';
1070
+			$wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_HISTO, $attribute_histo_content);
1071
+
1072
+			$product_meta = get_post_meta($product_id, '_wpshop_product_metadata', true);
1073
+			$product_meta['product_stock'] = $newQty;
1074
+			update_post_meta($product_id, '_wpshop_product_metadata', $product_meta);
1075
+		}
1076
+	}
1077 1077
 
1078
-    /**
1079
-     * Retrieve an array with complete information about a given product
1080
-     * @param integer $product_id
1081
-     * @param boolean $for_cart_storage
1082
-     * @return array Information about the product defined by first parameter
1083
-     */
1084
-    public static function get_product_data($product_id, $for_cart_storage = false, $post_status = '"publish"')
1085
-    {
1086
-        global $wpdb;
1087
-        $query = $wpdb->prepare('
1078
+	/**
1079
+	 * Retrieve an array with complete information about a given product
1080
+	 * @param integer $product_id
1081
+	 * @param boolean $for_cart_storage
1082
+	 * @return array Information about the product defined by first parameter
1083
+	 */
1084
+	public static function get_product_data($product_id, $for_cart_storage = false, $post_status = '"publish"')
1085
+	{
1086
+		global $wpdb;
1087
+		$query = $wpdb->prepare('
1088 1088
 			SELECT P.*, PM.meta_value AS attribute_set_id
1089 1089
 			FROM ' . $wpdb->posts . ' AS P
1090 1090
 				INNER JOIN ' . $wpdb->postmeta . ' AS PM ON (PM.post_id=P.ID)
@@ -1096,398 +1096,398 @@  discard block
 block discarded – undo
1096 1096
 			LIMIT 1
1097 1097
 		', $product_id);
1098 1098
 
1099
-        $product = $wpdb->get_row($query);
1100
-
1101
-        $product_data = array();
1102
-        $product_meta = array();
1103
-
1104
-        if (!empty($product)) {
1105
-            $product_data['product_id'] = (!empty($product->ID)) ? $product->ID : '';
1106
-            $product_data['post_name'] = (!empty($product->post_name)) ? $product->post_name : '';
1107
-            $product_data['product_name'] = (!empty($product->post_title)) ? $product->post_title : '';
1108
-            $product_data['post_title'] = (!empty($product->post_title)) ? $product->post_title : '';
1109
-
1110
-            $product_data['product_author_id'] = (!empty($product->post_author)) ? $product->post_author : '';
1111
-            $product_data['product_date'] = (!empty($product->post_date)) ? $product->post_date : '';
1112
-            $product_data['product_content'] = (!empty($product->post_content)) ? $product->post_content : '';
1113
-            $product_data['product_excerpt'] = (!empty($product->post_excerpt)) ? $product->post_excerpt : wp_trim_words($product_data['product_content'], apply_filters('excerpt_length', 50), '...');
1114
-
1115
-            $product_data['product_meta_attribute_set_id'] = (!empty($product->attribute_set_id)) ? $product->attribute_set_id : '';
1116
-
1117
-            $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);
1118
-            if (!empty($data)) {
1119
-                foreach ($data as $attribute) {
1120
-                    $data_type = 'attribute_value_' . $attribute->data_type;
1121
-                    $value = $attribute->$data_type;
1122
-                    if (in_array($attribute->backend_input, array('select', 'multiple-select', 'radio', 'checkbox'))) {
1123
-                        $value = wpshop_attributes::get_attribute_type_select_option_info($value, 'value');
1124
-                    }
1125
-
1126
-                    /** Special traitment regarding attribute_code    */
1127
-                    switch ($attribute->attribute_code) {
1128
-                        case 'product_weight':
1129
-                            $default_weight_unity = get_option('wpshop_shop_default_weight_unity');
1130
-                            if (!empty($default_weight_unity)) {
1131
-                                $query = $wpdb->prepare('SELECT unit FROM ' . WPSHOP_DBT_ATTRIBUTE_UNIT . ' WHERE id = %d', $default_weight_unity);
1132
-                                $unity = $wpdb->get_var($query);
1133
-                                if ($unity == 'kg') {
1134
-                                    $value *= 1000;
1135
-                                }
1136
-
1137
-                            }
1138
-                            break;
1139
-                        default:
1140
-                            $value = !empty($value) ? $value : 0;
1141
-                            break;
1142
-                    }
1143
-                    $product_data[$attribute->attribute_code] = $value;
1144
-
1145
-                    if (!$for_cart_storage or $for_cart_storage && $attribute->is_recordable_in_cart_meta == 'yes') {
1146
-                        $meta = get_post_meta($product->ID, 'attribute_option_' . $attribute->attribute_code, true);
1147
-                        if (!empty($meta)) {
1148
-                            $product_meta[$attribute->attribute_code] = $meta;
1149
-                        }
1150
-                    }
1151
-
1152
-                    if (($attribute->is_visible_in_front == 'yes') && (!in_array($attribute->attribute_code, unserialize(WPSHOP_ATTRIBUTE_PRICES)))) {
1153
-                        $product_meta['attribute_visible'][$attribute->attribute_code] = $value;
1154
-                    }
1155
-                    if (($attribute->is_visible_in_front_listing == 'yes') && (!in_array($attribute->attribute_code, unserialize(WPSHOP_ATTRIBUTE_PRICES)))) {
1156
-                        $product_meta['attribute_visible_listing'][$attribute->attribute_code] = $value;
1157
-                    }
1158
-                }
1159
-            } else {
1160
-
1161
-            }
1162
-
1163
-            /**    Get datas about product options    */
1164
-            if ($product->post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) {
1165
-                $variation_details = get_post_meta($product->ID, '_wpshop_variations_attribute_def', true);
1166
-
1167
-                foreach ($variation_details as $attribute_code => $attribute_value) {
1168
-                    $variation_id = $attribute_value;
1169
-                    $attribute_definition = wpshop_attributes::getElement($attribute_code, "'valid'", 'code');
1170
-
1171
-                    $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));
1172
-                    $product_meta['variation_definition'][$attribute_code]['NAME'] = $attribute_definition->frontend_label;
1173
-                    switch ($attribute_definition->backend_input) {
1174
-                        case 'select':
1175
-                        case 'multiple-select':
1176
-                        case 'radio':
1177
-                        case 'checkbox':
1178
-                            $attribute_value = wpshop_attributes::get_attribute_type_select_option_info($attribute_value, 'label', $attribute_definition->data_type_to_use, true);
1179
-                            break;
1180
-                    }
1181
-                    $product_meta['variation_definition'][$attribute_code]['VALUE'] = $attribute_value;
1182
-                    $product_meta['variation_definition'][$attribute_code]['ID'] = $variation_id;
1183
-                }
1184
-            }
1185
-
1186
-            $product_data['item_meta'] = !empty($product_meta) ? $product_meta : array();
1187
-
1188
-            /** Get the display definition for the current product for checking custom display    */
1189
-            $product_data['custom_display'] = get_post_meta($product_id, WPSHOP_PRODUCT_FRONT_DISPLAY_CONF, true);
1190
-        }
1099
+		$product = $wpdb->get_row($query);
1100
+
1101
+		$product_data = array();
1102
+		$product_meta = array();
1103
+
1104
+		if (!empty($product)) {
1105
+			$product_data['product_id'] = (!empty($product->ID)) ? $product->ID : '';
1106
+			$product_data['post_name'] = (!empty($product->post_name)) ? $product->post_name : '';
1107
+			$product_data['product_name'] = (!empty($product->post_title)) ? $product->post_title : '';
1108
+			$product_data['post_title'] = (!empty($product->post_title)) ? $product->post_title : '';
1109
+
1110
+			$product_data['product_author_id'] = (!empty($product->post_author)) ? $product->post_author : '';
1111
+			$product_data['product_date'] = (!empty($product->post_date)) ? $product->post_date : '';
1112
+			$product_data['product_content'] = (!empty($product->post_content)) ? $product->post_content : '';
1113
+			$product_data['product_excerpt'] = (!empty($product->post_excerpt)) ? $product->post_excerpt : wp_trim_words($product_data['product_content'], apply_filters('excerpt_length', 50), '...');
1114
+
1115
+			$product_data['product_meta_attribute_set_id'] = (!empty($product->attribute_set_id)) ? $product->attribute_set_id : '';
1116
+
1117
+			$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);
1118
+			if (!empty($data)) {
1119
+				foreach ($data as $attribute) {
1120
+					$data_type = 'attribute_value_' . $attribute->data_type;
1121
+					$value = $attribute->$data_type;
1122
+					if (in_array($attribute->backend_input, array('select', 'multiple-select', 'radio', 'checkbox'))) {
1123
+						$value = wpshop_attributes::get_attribute_type_select_option_info($value, 'value');
1124
+					}
1125
+
1126
+					/** Special traitment regarding attribute_code    */
1127
+					switch ($attribute->attribute_code) {
1128
+						case 'product_weight':
1129
+							$default_weight_unity = get_option('wpshop_shop_default_weight_unity');
1130
+							if (!empty($default_weight_unity)) {
1131
+								$query = $wpdb->prepare('SELECT unit FROM ' . WPSHOP_DBT_ATTRIBUTE_UNIT . ' WHERE id = %d', $default_weight_unity);
1132
+								$unity = $wpdb->get_var($query);
1133
+								if ($unity == 'kg') {
1134
+									$value *= 1000;
1135
+								}
1136
+
1137
+							}
1138
+							break;
1139
+						default:
1140
+							$value = !empty($value) ? $value : 0;
1141
+							break;
1142
+					}
1143
+					$product_data[$attribute->attribute_code] = $value;
1144
+
1145
+					if (!$for_cart_storage or $for_cart_storage && $attribute->is_recordable_in_cart_meta == 'yes') {
1146
+						$meta = get_post_meta($product->ID, 'attribute_option_' . $attribute->attribute_code, true);
1147
+						if (!empty($meta)) {
1148
+							$product_meta[$attribute->attribute_code] = $meta;
1149
+						}
1150
+					}
1151
+
1152
+					if (($attribute->is_visible_in_front == 'yes') && (!in_array($attribute->attribute_code, unserialize(WPSHOP_ATTRIBUTE_PRICES)))) {
1153
+						$product_meta['attribute_visible'][$attribute->attribute_code] = $value;
1154
+					}
1155
+					if (($attribute->is_visible_in_front_listing == 'yes') && (!in_array($attribute->attribute_code, unserialize(WPSHOP_ATTRIBUTE_PRICES)))) {
1156
+						$product_meta['attribute_visible_listing'][$attribute->attribute_code] = $value;
1157
+					}
1158
+				}
1159
+			} else {
1191 1160
 
1192
-        return $product_data;
1193
-    }
1161
+			}
1194 1162
 
1195
-    /**
1196
-     * Add a product into the db. This function is used for the EDI
1197
-     * @param $name Name of the product
1198
-     * @param $description Description of the product
1199
-     * @param $attrs List of the attributes and values of the product
1200
-     * @return boolean
1201
-     */
1202
-    public function addProduct($name, $description, $attrs = array())
1203
-    {
1204
-        $new_product = wpshop_entities::create_new_entity(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, $name, $description, $attrs);
1205
-        return $new_product[0];
1206
-    }
1163
+			/**    Get datas about product options    */
1164
+			if ($product->post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) {
1165
+				$variation_details = get_post_meta($product->ID, '_wpshop_variations_attribute_def', true);
1166
+
1167
+				foreach ($variation_details as $attribute_code => $attribute_value) {
1168
+					$variation_id = $attribute_value;
1169
+					$attribute_definition = wpshop_attributes::getElement($attribute_code, "'valid'", 'code');
1170
+
1171
+					$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));
1172
+					$product_meta['variation_definition'][$attribute_code]['NAME'] = $attribute_definition->frontend_label;
1173
+					switch ($attribute_definition->backend_input) {
1174
+						case 'select':
1175
+						case 'multiple-select':
1176
+						case 'radio':
1177
+						case 'checkbox':
1178
+							$attribute_value = wpshop_attributes::get_attribute_type_select_option_info($attribute_value, 'label', $attribute_definition->data_type_to_use, true);
1179
+							break;
1180
+					}
1181
+					$product_meta['variation_definition'][$attribute_code]['VALUE'] = $attribute_value;
1182
+					$product_meta['variation_definition'][$attribute_code]['ID'] = $variation_id;
1183
+				}
1184
+			}
1207 1185
 
1208
-    /**
1209
-     * Retrieve a product listing
1210
-     * @param boolean $formated If the output have to be formated or not
1211
-     * @param string $product_search Optionnal Define a search term for request
1212
-     * @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
1213
-     */
1214
-    public static function product_list($formated = false, $product_search = null)
1215
-    {
1216
-        global $wpdb;
1217
-
1218
-        $query_extra_params = $query_extra_params_value = '';
1219
-        if (!empty($product_search)) {
1220
-            $query_extra_params = " AND post_title LIKE '%%" . $product_search . "%%'";
1221
-            if (is_array($product_search)) {
1222
-                $query_extra_params = " AND ID IN (%s)";
1223
-                $query_extra_params_value = implode(",", $product_search);
1224
-            }
1225
-        }
1186
+			$product_data['item_meta'] = !empty($product_meta) ? $product_meta : array();
1187
+
1188
+			/** Get the display definition for the current product for checking custom display    */
1189
+			$product_data['custom_display'] = get_post_meta($product_id, WPSHOP_PRODUCT_FRONT_DISPLAY_CONF, true);
1190
+		}
1191
+
1192
+		return $product_data;
1193
+	}
1194
+
1195
+	/**
1196
+	 * Add a product into the db. This function is used for the EDI
1197
+	 * @param $name Name of the product
1198
+	 * @param $description Description of the product
1199
+	 * @param $attrs List of the attributes and values of the product
1200
+	 * @return boolean
1201
+	 */
1202
+	public function addProduct($name, $description, $attrs = array())
1203
+	{
1204
+		$new_product = wpshop_entities::create_new_entity(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, $name, $description, $attrs);
1205
+		return $new_product[0];
1206
+	}
1207
+
1208
+	/**
1209
+	 * Retrieve a product listing
1210
+	 * @param boolean $formated If the output have to be formated or not
1211
+	 * @param string $product_search Optionnal Define a search term for request
1212
+	 * @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
1213
+	 */
1214
+	public static function product_list($formated = false, $product_search = null)
1215
+	{
1216
+		global $wpdb;
1217
+
1218
+		$query_extra_params = $query_extra_params_value = '';
1219
+		if (!empty($product_search)) {
1220
+			$query_extra_params = " AND post_title LIKE '%%" . $product_search . "%%'";
1221
+			if (is_array($product_search)) {
1222
+				$query_extra_params = " AND ID IN (%s)";
1223
+				$query_extra_params_value = implode(",", $product_search);
1224
+			}
1225
+		}
1226 1226
 
1227
-        $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);
1228
-        $data = $wpdb->get_results($query);
1227
+		$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);
1228
+		$data = $wpdb->get_results($query);
1229 1229
 
1230
-        /*
1230
+		/*
1231 1231
          * Make some arangement on output if parameter is given
1232 1232
          */
1233
-        if ($formated) {
1234
-            $product_string = '';
1235
-            foreach ($data as $d) {
1236
-                $product_string .= '
1233
+		if ($formated) {
1234
+			$product_string = '';
1235
+			foreach ($data as $d) {
1236
+				$product_string .= '
1237 1237
 					<li class="wpshop_shortcode_element_container wpshop_shortcode_element_container_product" >
1238 1238
 						<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>
1239 1239
 					</li>';
1240
-            }
1241
-        }
1240
+			}
1241
+		}
1242 1242
 
1243
-        return $formated ? $product_string : $data;
1244
-    }
1243
+		return $formated ? $product_string : $data;
1244
+	}
1245 1245
 
1246
-    /**
1247
-     * Enregistrement des données pour le produit
1248
-     */
1249
-    public function save_product_custom_informations($post_id, $data_to_save = array())
1250
-    {
1251
-        global $wpdb;
1252
-
1253
-        $data_to_save = (!empty($data_to_save)) ? $data_to_save : (array) $_REQUEST;
1254
-        // Apply a filter to extra actions
1255
-        $data_to_save = apply_filters('wps_save_product_extra_filter', $data_to_save);
1256
-
1257
-        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"))) {
1258
-            if (!empty($data_to_save[wpshop_products::currentPageCode . '_attribute'])) {
1259
-                /*    Fill the product reference automatically if nothing is sent    */
1260
-                if (empty($data_to_save[wpshop_products::currentPageCode . '_attribute']['varchar']['product_reference'])) {
1261
-                    $query = "SELECT MAX(ID) AS PDCT_ID FROM {$wpdb->posts}";
1262
-                    $last_ref = $wpdb->get_var($query);
1263
-                    $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;
1264
-                } else {
1265
-                    /* Check if the product reference existing in the database */
1266
-                    $ref = $data_to_save[wpshop_products::currentPageCode . '_attribute']['varchar']['product_reference'];
1267
-                    $query = $wpdb->prepare(
1268
-                        "SELECT value_id
1246
+	/**
1247
+	 * Enregistrement des données pour le produit
1248
+	 */
1249
+	public function save_product_custom_informations($post_id, $data_to_save = array())
1250
+	{
1251
+		global $wpdb;
1252
+
1253
+		$data_to_save = (!empty($data_to_save)) ? $data_to_save : (array) $_REQUEST;
1254
+		// Apply a filter to extra actions
1255
+		$data_to_save = apply_filters('wps_save_product_extra_filter', $data_to_save);
1256
+
1257
+		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"))) {
1258
+			if (!empty($data_to_save[wpshop_products::currentPageCode . '_attribute'])) {
1259
+				/*    Fill the product reference automatically if nothing is sent    */
1260
+				if (empty($data_to_save[wpshop_products::currentPageCode . '_attribute']['varchar']['product_reference'])) {
1261
+					$query = "SELECT MAX(ID) AS PDCT_ID FROM {$wpdb->posts}";
1262
+					$last_ref = $wpdb->get_var($query);
1263
+					$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;
1264
+				} else {
1265
+					/* Check if the product reference existing in the database */
1266
+					$ref = $data_to_save[wpshop_products::currentPageCode . '_attribute']['varchar']['product_reference'];
1267
+					$query = $wpdb->prepare(
1268
+						"SELECT value_id
1269 1269
 						FROM " . WPSHOP_DBT_ATTRIBUTE_VALUES_VARCHAR . "
1270 1270
 							INNER JOIN {$wpdb->posts} ON ( ID = entity_id )
1271 1271
 						WHERE value = %s
1272 1272
 							AND entity_id != %d
1273 1273
 							AND entity_type_id = %d"
1274
-                        , $ref, $data_to_save['post_ID'], wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT));
1275
-                    $existing_reference = $wpdb->get_var($query);
1276
-
1277
-                    /* If this product reference exist -> Create a new product reference */
1278
-                    if ($wpdb->num_rows > 0) {
1279
-                        $query = "SELECT MAX(ID) AS PDCT_ID FROM " . $wpdb->posts;
1280
-                        $last_ref = $wpdb->get_var($query);
1281
-                        $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;
1282
-                    }
1283
-                }
1284
-
1285
-                /*    Save the attributes values into wpshop eav database    */
1286
-                $update_from = !empty($data_to_save[wpshop_products::currentPageCode . '_provenance']) ? $data_to_save[wpshop_products::currentPageCode . '_provenance'] : '';
1287
-                $lang = WPSHOP_CURRENT_LOCALE;
1288
-                if (!empty($data_to_save['icl_post_language'])) {
1289
-                    $query = $wpdb->prepare("SELECT locale FROM " . $wpdb->prefix . "icl_locale_map WHERE code = %s", $data_to_save['icl_post_language']);
1290
-                    $lang = $wpdb->get_var($query);
1291
-                }
1292
-                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);
1293
-
1294
-                /*    Update product price looking for shop parameters    */
1295
-                wpshop_products::calculate_price($data_to_save['post_ID']);
1296
-
1297
-                /*    Save the attributes values into wordpress post metadata database in order to have a backup and to make frontend search working    */
1298
-                $productMetaDatas = array();
1299
-                foreach ($data_to_save[wpshop_products::currentPageCode . '_attribute'] as $attributeType => $attributeValues) {
1300
-                    foreach ($attributeValues as $attributeCode => $attributeValue) {
1301
-                        if ($attributeCode == 'product_attribute_set_id') {
1302
-                            /*    Update the attribute set id for the current product    */
1303
-                            update_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, $attributeValue);
1304
-                        }
1305
-                        if ($attributeType == 'decimal') {
1306
-                            $attributeValue = str_replace(',', '.', $attributeValue);
1307
-                        }
1308
-                        if (($attributeType == 'integer') && !is_array($attributeValue)) {
1309
-                            $attributeValue = (int) $attributeValue;
1310
-                        }
1311
-                        $productMetaDatas[$attributeCode] = $attributeValue;
1312
-                    }
1313
-                }
1314
-                update_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, $productMetaDatas);
1315
-            }
1316
-
1317
-            if (!empty($data_to_save[wpshop_products::currentPageCode . '_attr_frontend_display']) && empty($data_to_save[wpshop_products::currentPageCode . '_attr_frontend_display']['default_config'])) {
1318
-                update_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_FRONT_DISPLAY_CONF, $data_to_save[wpshop_products::currentPageCode . '_attr_frontend_display']);
1319
-            } else if ($data_to_save['action'] != 'autosave') {
1320
-                delete_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_FRONT_DISPLAY_CONF);
1321
-            }
1322
-
1323
-            $product = wpshop_products::get_product_data($data_to_save['post_ID'], false, '"publish"');
1324
-            if (empty($product['product_id'])) {
1325
-                $product['product_id'] = $data_to_save['post_ID'];
1326
-            }
1327
-            $price = wpshop_prices::get_product_price($product, 'just_price_infos', array('mini_output', 'grid'));
1328
-            update_post_meta($data_to_save['post_ID'], '_wps_price_infos', $price);
1329
-
1330
-            /**    Save product variation    */
1331
-            if (!empty($data_to_save[WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION])) {
1332
-                foreach ($data_to_save[WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION] as $variation_id => $variation_definition) {
1333
-
1334
-                    foreach (unserialize(WPSHOP_ATTRIBUTE_PRICES) as $price_attribute_code) {
1335
-                        $price_attr_def = wpshop_attributes::getElement($price_attribute_code, "'valid'", 'code');
1336
-                        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])) {
1337
-                            $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;
1338
-                        }
1339
-                    }
1340
-                    $lang = WPSHOP_CURRENT_LOCALE;
1341
-                    if (!empty($data_to_save['icl_post_language'])) {
1342
-                        $query = $wpdb->prepare("SELECT locale FROM " . $wpdb->prefix . "icl_locale_map WHERE code = %s", $data_to_save['icl_post_language']);
1343
-                        $lang = $wpdb->get_var($query);
1344
-                    }
1345
-                    wpshop_attributes::saveAttributeForEntity($variation_definition['attribute'], wpshop_entities::get_entity_identifier_from_code(wpshop_products::currentPageCode), $variation_id, $lang);
1346
-
1347
-                    /**    Save the attributes values into wordpress post metadata database in order to have a backup and to make frontend search working    */
1348
-                    $variation_metadata = get_post_meta($variation_id, '_wpshop_product_metadata', true);
1349
-                    if (!empty($variation_metadata)) {
1350
-                        $attributes_list = wpshop_attributes::get_attribute_list_for_item(wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION), $variation_id);
1351
-                        if (!empty($attributes_list)) {
1352
-                            foreach ($attributes_list as $attribute) {
1353
-                                $value_key = 'attribute_value_' . $attribute->data_type;
1354
-                                $attributeValue = $attribute->$value_key;
1355
-                                if ($attribute->data_type == 'decimal') {
1356
-                                    $attributeValue = str_replace(',', '.', $attribute->$value_key);
1357
-                                }
1358
-                                if (($attribute->data_type == 'integer') && !is_array($attributeValue)) {
1359
-                                    $attributeValue = (int) $attribute->$value_key;
1360
-                                }
1361
-                                $variation_metadata[$attribute->code] = $attribute->$value_key;
1362
-                            }
1363
-                        }
1364
-                    }
1365
-
1366
-                    foreach ($variation_definition['attribute'] as $attributeType => $attributeValues) {
1367
-                        foreach ($attributeValues as $attributeCode => $attributeValue) {
1368
-                            if ($attributeType == 'decimal') {
1369
-                                $attributeValue = str_replace(',', '.', $attributeValue);
1370
-                            }
1371
-                            if (($attributeType == 'integer') && !is_array($attributeValue)) {
1372
-                                $attributeValue = (int) $attributeValue;
1373
-                            }
1374
-                            $variation_metadata[$attributeCode] = $attributeValue;
1375
-                        }
1376
-                    }
1377
-                    update_post_meta($variation_id, WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, $variation_metadata);
1378
-
1379
-                    /** Save attached picture id **/
1380
-                    $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']) : '';
1381
-                    $selected_picture = update_post_meta($variation_id, '_wps_variation_attached_picture', $attached_picture_id);
1382
-
1383
-                    /*    Update product price looking for shop parameters    */
1384
-                    wpshop_products::calculate_price($variation_id);
1385
-                }
1386
-            }
1387
-
1388
-            /*    Update the related products list*/
1389
-            if (!empty($data_to_save['related_products_list'])) {
1390
-                update_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_RELATED_PRODUCTS, $data_to_save['related_products_list']);
1391
-            } else if ($data_to_save['action'] != 'autosave') {
1392
-                delete_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_RELATED_PRODUCTS);
1393
-            }
1394
-            /*    Update the provider list*/
1395
-            if (!empty($data_to_save['provider_list'])) {
1396
-                update_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_PROVIDER, $data_to_save['provider_list']);
1397
-            } else if ($data_to_save['action'] != 'autosave') {
1398
-                delete_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_PROVIDER);
1399
-            }
1400
-
1401
-            /*    Update product options    */
1402
-            if (!empty($data_to_save[WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT]['options'])) {
1403
-                update_post_meta($data_to_save['post_ID'], '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_options', $data_to_save[WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT]['options']);
1404
-            } else if ($data_to_save['action'] != 'autosave') {
1405
-                delete_post_meta($data_to_save['post_ID'], '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_options');
1406
-            }
1407
-
1408
-            /** Add flag on variations to check which type of variation **/
1409
-            $check_product_have_variations = self::get_variation($post_id);
1410
-            if (!empty($check_product_have_variations)) {
1411
-                $variation_flag = self::check_variation_type($post_id);
1412
-                $variation_defining = get_post_meta($post_id, '_wpshop_variation_defining', true);
1413
-                $variation_defining['variation_type'] = $variation_flag;
1414
-                update_post_meta($post_id, '_wpshop_variation_defining', $variation_defining);
1415
-            }
1416
-            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);
1417
-        }
1274
+						, $ref, $data_to_save['post_ID'], wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT));
1275
+					$existing_reference = $wpdb->get_var($query);
1276
+
1277
+					/* If this product reference exist -> Create a new product reference */
1278
+					if ($wpdb->num_rows > 0) {
1279
+						$query = "SELECT MAX(ID) AS PDCT_ID FROM " . $wpdb->posts;
1280
+						$last_ref = $wpdb->get_var($query);
1281
+						$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;
1282
+					}
1283
+				}
1418 1284
 
1419
-        flush_rewrite_rules();
1420
-    }
1285
+				/*    Save the attributes values into wpshop eav database    */
1286
+				$update_from = !empty($data_to_save[wpshop_products::currentPageCode . '_provenance']) ? $data_to_save[wpshop_products::currentPageCode . '_provenance'] : '';
1287
+				$lang = WPSHOP_CURRENT_LOCALE;
1288
+				if (!empty($data_to_save['icl_post_language'])) {
1289
+					$query = $wpdb->prepare("SELECT locale FROM " . $wpdb->prefix . "icl_locale_map WHERE code = %s", $data_to_save['icl_post_language']);
1290
+					$lang = $wpdb->get_var($query);
1291
+				}
1292
+				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);
1293
+
1294
+				/*    Update product price looking for shop parameters    */
1295
+				wpshop_products::calculate_price($data_to_save['post_ID']);
1296
+
1297
+				/*    Save the attributes values into wordpress post metadata database in order to have a backup and to make frontend search working    */
1298
+				$productMetaDatas = array();
1299
+				foreach ($data_to_save[wpshop_products::currentPageCode . '_attribute'] as $attributeType => $attributeValues) {
1300
+					foreach ($attributeValues as $attributeCode => $attributeValue) {
1301
+						if ($attributeCode == 'product_attribute_set_id') {
1302
+							/*    Update the attribute set id for the current product    */
1303
+							update_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, $attributeValue);
1304
+						}
1305
+						if ($attributeType == 'decimal') {
1306
+							$attributeValue = str_replace(',', '.', $attributeValue);
1307
+						}
1308
+						if (($attributeType == 'integer') && !is_array($attributeValue)) {
1309
+							$attributeValue = (int) $attributeValue;
1310
+						}
1311
+						$productMetaDatas[$attributeCode] = $attributeValue;
1312
+					}
1313
+				}
1314
+				update_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, $productMetaDatas);
1315
+			}
1421 1316
 
1422
-    /**
1423
-     * Return the variation type
1424
-     * @param integer $post_id
1425
-     * @return string
1426
-     */
1427
-    public function check_variation_type($post_id)
1428
-    {
1429
-        $variation_type = 'single';
1430
-        if (!empty($variation_type)) {
1431
-            $variations = self::get_variation($post_id);
1432
-            if (!empty($variations)) {
1433
-                foreach ($variations as $variation_id => $variation_data) {
1434
-                    if (!empty($variation_data) && !empty($variation_data['variation_def']) && count($variation_data['variation_def']) == 1) {
1435
-                        return 'single';
1436
-                    } elseif (!empty($variation_data) && !empty($variation_data['variation_def']) && count($variation_data['variation_def']) > 1) {
1437
-                        $variation_type = 'combined';
1438
-                    }
1439
-                }
1440
-            }
1441
-        }
1442
-        return $variation_type;
1443
-    }
1317
+			if (!empty($data_to_save[wpshop_products::currentPageCode . '_attr_frontend_display']) && empty($data_to_save[wpshop_products::currentPageCode . '_attr_frontend_display']['default_config'])) {
1318
+				update_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_FRONT_DISPLAY_CONF, $data_to_save[wpshop_products::currentPageCode . '_attr_frontend_display']);
1319
+			} else if ($data_to_save['action'] != 'autosave') {
1320
+				delete_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_FRONT_DISPLAY_CONF);
1321
+			}
1444 1322
 
1445
-    /**
1446
-     * Allows to define a specific permalink for each product by checking the parent categories
1447
-     *
1448
-     * @param mixed $permalink The actual permalink of the element
1449
-     * @param object $post The post we want to set the permalink for
1450
-     * @param void
1451
-     *
1452
-     * @return mixed The new permalink for the current element
1453
-     */
1454
-    public static function set_product_permalink($permalink, $post, $unknown)
1455
-    {
1456
-        $options = get_option('wpshop_catalog_product_option', array());
1457
-
1458
-        if ($post->post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT/* && 'publish' == $post->post_status */) {
1459
-            if (!isset($options['wpshop_catalog_product_slug_with_category']) || $options['wpshop_catalog_product_slug_with_category'] != 'yes') {
1460
-                return $permalink;
1461
-            } else {
1462
-                $options_cats = get_option('wpshop_catalog_categories_option', array());
1463
-                $product_categories = wp_get_object_terms($post->ID, WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES);
1464
-                if (empty($product_categories)) {
1465
-                    $product_category_slug = $options_cats['wpshop_catalog_no_category_slug'];
1466
-                } else {
1467
-                    $product_category_slug = $product_categories[0]->slug;
1468
-                }
1469
-                $permalink = str_replace('%' . WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES . '%', $product_category_slug, $permalink);
1470
-            }
1471
-        }
1323
+			$product = wpshop_products::get_product_data($data_to_save['post_ID'], false, '"publish"');
1324
+			if (empty($product['product_id'])) {
1325
+				$product['product_id'] = $data_to_save['post_ID'];
1326
+			}
1327
+			$price = wpshop_prices::get_product_price($product, 'just_price_infos', array('mini_output', 'grid'));
1328
+			update_post_meta($data_to_save['post_ID'], '_wps_price_infos', $price);
1329
+
1330
+			/**    Save product variation    */
1331
+			if (!empty($data_to_save[WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION])) {
1332
+				foreach ($data_to_save[WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION] as $variation_id => $variation_definition) {
1333
+
1334
+					foreach (unserialize(WPSHOP_ATTRIBUTE_PRICES) as $price_attribute_code) {
1335
+						$price_attr_def = wpshop_attributes::getElement($price_attribute_code, "'valid'", 'code');
1336
+						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])) {
1337
+							$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;
1338
+						}
1339
+					}
1340
+					$lang = WPSHOP_CURRENT_LOCALE;
1341
+					if (!empty($data_to_save['icl_post_language'])) {
1342
+						$query = $wpdb->prepare("SELECT locale FROM " . $wpdb->prefix . "icl_locale_map WHERE code = %s", $data_to_save['icl_post_language']);
1343
+						$lang = $wpdb->get_var($query);
1344
+					}
1345
+					wpshop_attributes::saveAttributeForEntity($variation_definition['attribute'], wpshop_entities::get_entity_identifier_from_code(wpshop_products::currentPageCode), $variation_id, $lang);
1346
+
1347
+					/**    Save the attributes values into wordpress post metadata database in order to have a backup and to make frontend search working    */
1348
+					$variation_metadata = get_post_meta($variation_id, '_wpshop_product_metadata', true);
1349
+					if (!empty($variation_metadata)) {
1350
+						$attributes_list = wpshop_attributes::get_attribute_list_for_item(wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION), $variation_id);
1351
+						if (!empty($attributes_list)) {
1352
+							foreach ($attributes_list as $attribute) {
1353
+								$value_key = 'attribute_value_' . $attribute->data_type;
1354
+								$attributeValue = $attribute->$value_key;
1355
+								if ($attribute->data_type == 'decimal') {
1356
+									$attributeValue = str_replace(',', '.', $attribute->$value_key);
1357
+								}
1358
+								if (($attribute->data_type == 'integer') && !is_array($attributeValue)) {
1359
+									$attributeValue = (int) $attribute->$value_key;
1360
+								}
1361
+								$variation_metadata[$attribute->code] = $attribute->$value_key;
1362
+							}
1363
+						}
1364
+					}
1365
+
1366
+					foreach ($variation_definition['attribute'] as $attributeType => $attributeValues) {
1367
+						foreach ($attributeValues as $attributeCode => $attributeValue) {
1368
+							if ($attributeType == 'decimal') {
1369
+								$attributeValue = str_replace(',', '.', $attributeValue);
1370
+							}
1371
+							if (($attributeType == 'integer') && !is_array($attributeValue)) {
1372
+								$attributeValue = (int) $attributeValue;
1373
+							}
1374
+							$variation_metadata[$attributeCode] = $attributeValue;
1375
+						}
1376
+					}
1377
+					update_post_meta($variation_id, WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, $variation_metadata);
1378
+
1379
+					/** Save attached picture id **/
1380
+					$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']) : '';
1381
+					$selected_picture = update_post_meta($variation_id, '_wps_variation_attached_picture', $attached_picture_id);
1382
+
1383
+					/*    Update product price looking for shop parameters    */
1384
+					wpshop_products::calculate_price($variation_id);
1385
+				}
1386
+			}
1387
+
1388
+			/*    Update the related products list*/
1389
+			if (!empty($data_to_save['related_products_list'])) {
1390
+				update_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_RELATED_PRODUCTS, $data_to_save['related_products_list']);
1391
+			} else if ($data_to_save['action'] != 'autosave') {
1392
+				delete_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_RELATED_PRODUCTS);
1393
+			}
1394
+			/*    Update the provider list*/
1395
+			if (!empty($data_to_save['provider_list'])) {
1396
+				update_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_PROVIDER, $data_to_save['provider_list']);
1397
+			} else if ($data_to_save['action'] != 'autosave') {
1398
+				delete_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_PROVIDER);
1399
+			}
1400
+
1401
+			/*    Update product options    */
1402
+			if (!empty($data_to_save[WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT]['options'])) {
1403
+				update_post_meta($data_to_save['post_ID'], '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_options', $data_to_save[WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT]['options']);
1404
+			} else if ($data_to_save['action'] != 'autosave') {
1405
+				delete_post_meta($data_to_save['post_ID'], '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_options');
1406
+			}
1407
+
1408
+			/** Add flag on variations to check which type of variation **/
1409
+			$check_product_have_variations = self::get_variation($post_id);
1410
+			if (!empty($check_product_have_variations)) {
1411
+				$variation_flag = self::check_variation_type($post_id);
1412
+				$variation_defining = get_post_meta($post_id, '_wpshop_variation_defining', true);
1413
+				$variation_defining['variation_type'] = $variation_flag;
1414
+				update_post_meta($post_id, '_wpshop_variation_defining', $variation_defining);
1415
+			}
1416
+			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);
1417
+		}
1418
+
1419
+		flush_rewrite_rules();
1420
+	}
1421
+
1422
+	/**
1423
+	 * Return the variation type
1424
+	 * @param integer $post_id
1425
+	 * @return string
1426
+	 */
1427
+	public function check_variation_type($post_id)
1428
+	{
1429
+		$variation_type = 'single';
1430
+		if (!empty($variation_type)) {
1431
+			$variations = self::get_variation($post_id);
1432
+			if (!empty($variations)) {
1433
+				foreach ($variations as $variation_id => $variation_data) {
1434
+					if (!empty($variation_data) && !empty($variation_data['variation_def']) && count($variation_data['variation_def']) == 1) {
1435
+						return 'single';
1436
+					} elseif (!empty($variation_data) && !empty($variation_data['variation_def']) && count($variation_data['variation_def']) > 1) {
1437
+						$variation_type = 'combined';
1438
+					}
1439
+				}
1440
+			}
1441
+		}
1442
+		return $variation_type;
1443
+	}
1444
+
1445
+	/**
1446
+	 * Allows to define a specific permalink for each product by checking the parent categories
1447
+	 *
1448
+	 * @param mixed $permalink The actual permalink of the element
1449
+	 * @param object $post The post we want to set the permalink for
1450
+	 * @param void
1451
+	 *
1452
+	 * @return mixed The new permalink for the current element
1453
+	 */
1454
+	public static function set_product_permalink($permalink, $post, $unknown)
1455
+	{
1456
+		$options = get_option('wpshop_catalog_product_option', array());
1457
+
1458
+		if ($post->post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT/* && 'publish' == $post->post_status */) {
1459
+			if (!isset($options['wpshop_catalog_product_slug_with_category']) || $options['wpshop_catalog_product_slug_with_category'] != 'yes') {
1460
+				return $permalink;
1461
+			} else {
1462
+				$options_cats = get_option('wpshop_catalog_categories_option', array());
1463
+				$product_categories = wp_get_object_terms($post->ID, WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES);
1464
+				if (empty($product_categories)) {
1465
+					$product_category_slug = $options_cats['wpshop_catalog_no_category_slug'];
1466
+				} else {
1467
+					$product_category_slug = $product_categories[0]->slug;
1468
+				}
1469
+				$permalink = str_replace('%' . WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES . '%', $product_category_slug, $permalink);
1470
+			}
1471
+		}
1472 1472
 
1473
-        return $permalink;
1473
+		return $permalink;
1474 1474
 
1475
-        //echo '<pre>'; print_r($permalink); echo '</pre>'; exit();
1475
+		//echo '<pre>'; print_r($permalink); echo '</pre>'; exit();
1476 1476
 
1477
-        //wpshop_catalog_categories_slug wpshop_catalog_no_category_slug
1477
+		//wpshop_catalog_categories_slug wpshop_catalog_no_category_slug
1478 1478
 
1479
-        /*if(false) {
1479
+		/*if(false) {
1480 1480
         global $wp_query;
1481 1481
         $product_categories = wp_get_object_terms( $post->ID, WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES );
1482 1482
 
1483 1483
         if(count($product_categories) == 0){            /*    Product has only one category we get the only available slug    */
1484
-        /*        $product_category_slug = WPSHOP_UNCATEGORIZED_PRODUCT_SLUG;
1484
+		/*        $product_category_slug = WPSHOP_UNCATEGORIZED_PRODUCT_SLUG;
1485 1485
         }
1486 1486
         elseif(count($product_categories) == 1){    /*    Product has only one category we get the only available slug    */
1487
-        /*        $product_category_slug = $product_categories[0]->slug;
1487
+		/*        $product_category_slug = $product_categories[0]->slug;
1488 1488
         }
1489 1489
         else{                                                                            /*    Product has several categories choose the slug of the we want    */
1490
-        /*        $product_category_slugs = array();
1490
+		/*        $product_category_slugs = array();
1491 1491
     foreach($product_categories as $product_category){
1492 1492
     $product_category_slugs[] = $product_category->slug;
1493 1493
     }
@@ -1497,457 +1497,457 @@  discard block
 block discarded – undo
1497 1497
     $permalink = str_replace('%' . WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES . '%', $product_category_slug, $permalink);
1498 1498
     return apply_filters('wpshop_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_permalink', $permalink, $post->ID );
1499 1499
     }*/
1500
-    }
1500
+	}
1501 1501
 
1502
-    public static function set_product_request_by_name($query)
1503
-    {
1504
-        $options = get_option('wpshop_catalog_product_option', array());
1502
+	public static function set_product_request_by_name($query)
1503
+	{
1504
+		$options = get_option('wpshop_catalog_product_option', array());
1505 1505
 
1506
-        if ($query->is_main_query() && (2 == count($query->query) || isset($query->query['page'])) && !empty($query->query['name']) && empty($options['wpshop_catalog_product_slug']));
1507
-        //    $query->set( 'post_type', array( 'post', WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'page' ) );
1508
-    }
1506
+		if ($query->is_main_query() && (2 == count($query->query) || isset($query->query['page'])) && !empty($query->query['name']) && empty($options['wpshop_catalog_product_slug']));
1507
+		//    $query->set( 'post_type', array( 'post', WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'page' ) );
1508
+	}
1509 1509
 
1510
-    /**
1511
-     *    Define output for product
1512
-     *
1513
-     *    @param mixed $initialContent The initial product content defined into wordpress basic admin interface
1514
-     *    @param integer $product_id The product identifier we want to get and output attribute for
1515
-     *
1516
-     *    @return mixed $content The content to add or to modify the product output in frontend
1517
-     */
1518
-    public static function product_complete_sheet_output($initialContent, $product_id)
1519
-    {
1520
-        $content = $attributeContentOutput = '';
1521
-        $wps_product_ctr = new wps_product_ctr();
1522
-        /** Log number of view for the current product    */
1523
-        $product_view_number = get_post_meta($product_id, WPSHOP_PRODUCT_VIEW_NB, true);
1524
-        $product_view_number++;
1525
-        update_post_meta($product_id, WPSHOP_PRODUCT_VIEW_NB, $product_view_number);
1526
-
1527
-        /** Get product definition    */
1528
-
1529
-        $product = self::get_product_data($product_id);
1530
-        wp_cache_set('wpshop_product_data_' . $product_id, $product);
1531
-
1532
-        /** Get the product thumbnail    */
1533
-        $productThumbnail = wpshop_display::display_template_element('product_thumbnail_default', array());
1534
-        if (has_post_thumbnail($product_id)) {
1535
-            $thumbnail_url = wp_get_attachment_image_src(get_post_thumbnail_id(), 'full');
1536
-            $tpl_component = array();
1537
-            $tpl_component['PRODUCT_THUMBNAIL_URL'] = $thumbnail_url[0];
1538
-            $tpl_component['PRODUCT_THUMBNAIL'] = get_the_post_thumbnail($product_id, 'wpshop-product-galery');
1539
-            $tpl_component['PRODUCT_THUMBNAIL_FULL'] = get_the_post_thumbnail($product_id, 'full');
1540
-            $image_attributes = wp_get_attachment_metadata(get_post_thumbnail_id());
1541
-            if (!empty($image_attributes) && !empty($image_attributes['sizes']) && is_array($image_attributes['sizes'])) {
1542
-                foreach ($image_attributes['sizes'] as $size_name => $size_def) {
1543
-                    $tpl_component['PRODUCT_THUMBNAIL_' . strtoupper($size_name)] = wp_get_attachment_image(get_post_thumbnail_id(), $size_name);
1544
-                    $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;
1545
-                }
1546
-            }
1547
-            $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;
1548
-            $productThumbnail = wpshop_display::display_template_element('product_thumbnail', $tpl_component);
1549
-            unset($tpl_component);
1550
-        }
1510
+	/**
1511
+	 *    Define output for product
1512
+	 *
1513
+	 *    @param mixed $initialContent The initial product content defined into wordpress basic admin interface
1514
+	 *    @param integer $product_id The product identifier we want to get and output attribute for
1515
+	 *
1516
+	 *    @return mixed $content The content to add or to modify the product output in frontend
1517
+	 */
1518
+	public static function product_complete_sheet_output($initialContent, $product_id)
1519
+	{
1520
+		$content = $attributeContentOutput = '';
1521
+		$wps_product_ctr = new wps_product_ctr();
1522
+		/** Log number of view for the current product    */
1523
+		$product_view_number = get_post_meta($product_id, WPSHOP_PRODUCT_VIEW_NB, true);
1524
+		$product_view_number++;
1525
+		update_post_meta($product_id, WPSHOP_PRODUCT_VIEW_NB, $product_view_number);
1526
+
1527
+		/** Get product definition    */
1528
+
1529
+		$product = self::get_product_data($product_id);
1530
+		wp_cache_set('wpshop_product_data_' . $product_id, $product);
1531
+
1532
+		/** Get the product thumbnail    */
1533
+		$productThumbnail = wpshop_display::display_template_element('product_thumbnail_default', array());
1534
+		if (has_post_thumbnail($product_id)) {
1535
+			$thumbnail_url = wp_get_attachment_image_src(get_post_thumbnail_id(), 'full');
1536
+			$tpl_component = array();
1537
+			$tpl_component['PRODUCT_THUMBNAIL_URL'] = $thumbnail_url[0];
1538
+			$tpl_component['PRODUCT_THUMBNAIL'] = get_the_post_thumbnail($product_id, 'wpshop-product-galery');
1539
+			$tpl_component['PRODUCT_THUMBNAIL_FULL'] = get_the_post_thumbnail($product_id, 'full');
1540
+			$image_attributes = wp_get_attachment_metadata(get_post_thumbnail_id());
1541
+			if (!empty($image_attributes) && !empty($image_attributes['sizes']) && is_array($image_attributes['sizes'])) {
1542
+				foreach ($image_attributes['sizes'] as $size_name => $size_def) {
1543
+					$tpl_component['PRODUCT_THUMBNAIL_' . strtoupper($size_name)] = wp_get_attachment_image(get_post_thumbnail_id(), $size_name);
1544
+					$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;
1545
+				}
1546
+			}
1547
+			$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;
1548
+			$productThumbnail = wpshop_display::display_template_element('product_thumbnail', $tpl_component);
1549
+			unset($tpl_component);
1550
+		}
1551 1551
 
1552
-        $product_document_galery = wps_media_manager_frontend_ctr::get_product_complete_sheet_attachments($product_id);
1553
-
1554
-        /**    Retrieve product attributes for output    */
1555
-        $attributeContentOutput = wpshop_attributes::attribute_of_entity_to_tab(wpshop_entities::get_entity_identifier_from_code(self::currentPageCode), $product_id, $product);
1556
-
1557
-        /** Retrieve product price */
1558
-        $price_attribute = wpshop_attributes::getElement('product_price', "'valid'", 'code');
1559
-        $price_display = wpshop_attributes::check_attribute_display($price_attribute->is_visible_in_front, $product['custom_display'], 'attribute', 'product_price', 'complete_sheet');
1560
-        $catalog_options = get_option('wpshop_catalog_main_option', array());
1561
-        $productPrice = '';
1562
-        $wpshop_price_piloting_option = get_option('wpshop_shop_price_piloting');
1563
-        $check_product_price = wpshop_prices::check_product_price($product);
1564
-        $result_price_piloting = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $check_product_price['et'] : $check_product_price['ati'];
1565
-        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)) {
1566
-            $productPrice = wpshop_prices::get_product_price($product, 'price_display', 'complete_sheet');
1567
-        }
1552
+		$product_document_galery = wps_media_manager_frontend_ctr::get_product_complete_sheet_attachments($product_id);
1553
+
1554
+		/**    Retrieve product attributes for output    */
1555
+		$attributeContentOutput = wpshop_attributes::attribute_of_entity_to_tab(wpshop_entities::get_entity_identifier_from_code(self::currentPageCode), $product_id, $product);
1556
+
1557
+		/** Retrieve product price */
1558
+		$price_attribute = wpshop_attributes::getElement('product_price', "'valid'", 'code');
1559
+		$price_display = wpshop_attributes::check_attribute_display($price_attribute->is_visible_in_front, $product['custom_display'], 'attribute', 'product_price', 'complete_sheet');
1560
+		$catalog_options = get_option('wpshop_catalog_main_option', array());
1561
+		$productPrice = '';
1562
+		$wpshop_price_piloting_option = get_option('wpshop_shop_price_piloting');
1563
+		$check_product_price = wpshop_prices::check_product_price($product);
1564
+		$result_price_piloting = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $check_product_price['et'] : $check_product_price['ati'];
1565
+		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)) {
1566
+			$productPrice = wpshop_prices::get_product_price($product, 'price_display', 'complete_sheet');
1567
+		}
1568 1568
 
1569
-        /** Check if there is at less 1 product in stock    */
1570
-        $productStock = $wps_product_ctr->check_stock($product_id, 1);
1571
-        $productStock = ($productStock === true) ? 1 : null;
1569
+		/** Check if there is at less 1 product in stock    */
1570
+		$productStock = $wps_product_ctr->check_stock($product_id, 1);
1571
+		$productStock = ($productStock === true) ? 1 : null;
1572 1572
 
1573
-        /** if !product stock check product have variation with stock **/
1573
+		/** if !product stock check product have variation with stock **/
1574 1574
 //         if ( empty($productStock) ) {
1575
-        $product_variation_meta = get_post_meta($product_id, '_wpshop_variation_defining', true);
1576
-        if (!empty($product_variation_meta) && !empty($product_variation_meta['options']) && !empty($product_variation_meta['options']['priority']) && in_array('combined', $product_variation_meta['options']['priority'])) {
1577
-            $variations = wpshop_products::get_variation($product_id);
1578
-            if (!empty($variations)) {
1579
-                foreach ($variations as $variation) {
1580
-                    if (!empty($variation) && !empty($variation['variation_dif']) && array_key_exists('product_stock', $variation['variation_dif']) && round($variation['variation_dif']['product_stock']) > 0) {
1581
-                        $productStock = 1;
1582
-                    }
1583
-                }
1584
-            }
1585
-        }
1575
+		$product_variation_meta = get_post_meta($product_id, '_wpshop_variation_defining', true);
1576
+		if (!empty($product_variation_meta) && !empty($product_variation_meta['options']) && !empty($product_variation_meta['options']['priority']) && in_array('combined', $product_variation_meta['options']['priority'])) {
1577
+			$variations = wpshop_products::get_variation($product_id);
1578
+			if (!empty($variations)) {
1579
+				foreach ($variations as $variation) {
1580
+					if (!empty($variation) && !empty($variation['variation_dif']) && array_key_exists('product_stock', $variation['variation_dif']) && round($variation['variation_dif']['product_stock']) > 0) {
1581
+						$productStock = 1;
1582
+					}
1583
+				}
1584
+			}
1585
+		}
1586 1586
 //         }
1587 1587
 
1588
-        /** Define "Add to cart" button     */
1589
-        $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');
1590
-        $display_price_state_when_price_is_empty = true;
1591
-        if (empty($productPrice) && (!empty($catalog_options) || (!empty($catalog_options['wpshop_catalog_empty_price_behaviour']) && $catalog_options['wpshop_catalog_empty_price_behaviour'] == 'yes'))) {
1592
-            $display_price_state_when_price_is_empty = false;
1593
-        } else if (!empty($productPrice)) {
1594
-            $display_price_state_when_price_is_empty = true;
1595
-        }
1596
-        $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') : '';
1597
-        $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)) : '';
1598
-
1599
-        /** Define "Ask a quotation" button    */
1600
-        $quotation_button = self::display_quotation_button($product_id, (!empty($product['quotation_allowed']) ? $product['quotation_allowed'] : null), 'complete');
1601
-
1602
-        /** Template parameters    */
1603
-        $template_part = 'product_complete_tpl';
1604
-        $tpl_component = array();
1605
-
1606
-        $tpl_component['PRODUCT_VARIATIONS'] = wpshop_products::wpshop_variation($product_id);
1607
-        $tpl_component['PRODUCT_ID'] = $product_id;
1608
-        $tpl_component['PRODUCT_TITLE'] = $product['post_title'];
1609
-        $tpl_component['PRODUCT_THUMBNAIL'] = $productThumbnail;
1610
-        $tpl_component['PRODUCT_GALERY_PICS'] = '';
1611
-        $tpl_component['PRODUCT_PRICE'] = $productPrice;
1612
-        $modules_option = get_option('wpshop_modules');
1613
-        $tpl_component['LOW_STOCK_ALERT_MESSAGE'] = '';
1614
-        if (!empty($modules_option) && !empty($modules_option['wpshop_low_stock_alert']) && $modules_option['wpshop_low_stock_alert']['activated'] == 'on') {
1615
-            $wps_marketing_tools = new wps_marketing_tools_ctr();
1616
-            $tpl_component['LOW_STOCK_ALERT_MESSAGE'] = $wps_marketing_tools->display_alert_stock_message(array('id' => $product_id));
1617
-        }
1588
+		/** Define "Add to cart" button     */
1589
+		$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');
1590
+		$display_price_state_when_price_is_empty = true;
1591
+		if (empty($productPrice) && (!empty($catalog_options) || (!empty($catalog_options['wpshop_catalog_empty_price_behaviour']) && $catalog_options['wpshop_catalog_empty_price_behaviour'] == 'yes'))) {
1592
+			$display_price_state_when_price_is_empty = false;
1593
+		} else if (!empty($productPrice)) {
1594
+			$display_price_state_when_price_is_empty = true;
1595
+		}
1596
+		$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') : '';
1597
+		$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)) : '';
1598
+
1599
+		/** Define "Ask a quotation" button    */
1600
+		$quotation_button = self::display_quotation_button($product_id, (!empty($product['quotation_allowed']) ? $product['quotation_allowed'] : null), 'complete');
1601
+
1602
+		/** Template parameters    */
1603
+		$template_part = 'product_complete_tpl';
1604
+		$tpl_component = array();
1605
+
1606
+		$tpl_component['PRODUCT_VARIATIONS'] = wpshop_products::wpshop_variation($product_id);
1607
+		$tpl_component['PRODUCT_ID'] = $product_id;
1608
+		$tpl_component['PRODUCT_TITLE'] = $product['post_title'];
1609
+		$tpl_component['PRODUCT_THUMBNAIL'] = $productThumbnail;
1610
+		$tpl_component['PRODUCT_GALERY_PICS'] = '';
1611
+		$tpl_component['PRODUCT_PRICE'] = $productPrice;
1612
+		$modules_option = get_option('wpshop_modules');
1613
+		$tpl_component['LOW_STOCK_ALERT_MESSAGE'] = '';
1614
+		if (!empty($modules_option) && !empty($modules_option['wpshop_low_stock_alert']) && $modules_option['wpshop_low_stock_alert']['activated'] == 'on') {
1615
+			$wps_marketing_tools = new wps_marketing_tools_ctr();
1616
+			$tpl_component['LOW_STOCK_ALERT_MESSAGE'] = $wps_marketing_tools->display_alert_stock_message(array('id' => $product_id));
1617
+		}
1618 1618
 
1619
-        /** Gallery **/
1620
-        $tpl_component['PRODUCT_COMPLETE_SHEET_GALLERY'] = wps_media_manager_frontend_ctr::get_product_complete_sheet_galery($product_id);
1621
-
1622
-        $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'] : ''));
1623
-
1624
-        $product_new = $product_new_def['output'];
1625
-        $product_class = $product_new_def['class'];
1626
-
1627
-        $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'] : ''));
1628
-        $product_featured = $product_featured_def['output'];
1629
-        $product_class .= $product_featured_def['class'];
1630
-
1631
-        $tpl_component['PRODUCT_IS_NEW'] = $product_new;
1632
-        $tpl_component['PRODUCT_IS_FEATURED'] = $product_featured;
1633
-        $tpl_component['PRODUCT_EXTRA_STATE'] = $tpl_component['PRODUCT_IS_NEW'] . $tpl_component['PRODUCT_IS_FEATURED'];
1634
-
1635
-        $tpl_component['PRODUCT_INITIAL_CONTENT'] = $initialContent;
1636
-        $tpl_component['PRODUCT_BUTTON_ADD_TO_CART'] = $add_to_cart_button;
1637
-        $tpl_component['PRODUCT_BUTTON_QUOTATION'] = $quotation_button;
1638
-        $tpl_component['PRODUCT_QUANTITY_CHOOSER'] = $product_quantity_chooser_input;
1639
-        $tpl_component['PRODUCT_BUTTONS'] = $tpl_component['PRODUCT_BUTTON_QUOTATION'] . $tpl_component['PRODUCT_BUTTON_ADD_TO_CART'];
1640
-        $tpl_component['PRODUCT_GALERY_DOCS'] = $product_document_galery;
1641
-        $tpl_component['PRODUCT_FEATURES'] = $attributeContentOutput;
1642
-        $tpl_component = apply_filters('wps-filter-product-complete-sheet-output', $tpl_component, $product_id);
1643
-
1644
-        /** Build template    */
1645
-        $tpl_way_to_take = wpshop_display::check_way_for_template($template_part);
1646
-        if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) {
1647
-            /*    Include the old way template part    */
1648
-            ob_start();
1649
-            require wpshop_display::get_template_file($tpl_way_to_take[1]);
1650
-            $content = ob_get_contents();
1651
-            ob_end_clean();
1652
-        } else {
1653
-            $content = wpshop_display::display_template_element($template_part, $tpl_component);
1654
-        }
1655
-        unset($tpl_component);
1656
-        return $content;
1657
-    }
1619
+		/** Gallery **/
1620
+		$tpl_component['PRODUCT_COMPLETE_SHEET_GALLERY'] = wps_media_manager_frontend_ctr::get_product_complete_sheet_galery($product_id);
1621
+
1622
+		$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'] : ''));
1623
+
1624
+		$product_new = $product_new_def['output'];
1625
+		$product_class = $product_new_def['class'];
1626
+
1627
+		$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'] : ''));
1628
+		$product_featured = $product_featured_def['output'];
1629
+		$product_class .= $product_featured_def['class'];
1630
+
1631
+		$tpl_component['PRODUCT_IS_NEW'] = $product_new;
1632
+		$tpl_component['PRODUCT_IS_FEATURED'] = $product_featured;
1633
+		$tpl_component['PRODUCT_EXTRA_STATE'] = $tpl_component['PRODUCT_IS_NEW'] . $tpl_component['PRODUCT_IS_FEATURED'];
1634
+
1635
+		$tpl_component['PRODUCT_INITIAL_CONTENT'] = $initialContent;
1636
+		$tpl_component['PRODUCT_BUTTON_ADD_TO_CART'] = $add_to_cart_button;
1637
+		$tpl_component['PRODUCT_BUTTON_QUOTATION'] = $quotation_button;
1638
+		$tpl_component['PRODUCT_QUANTITY_CHOOSER'] = $product_quantity_chooser_input;
1639
+		$tpl_component['PRODUCT_BUTTONS'] = $tpl_component['PRODUCT_BUTTON_QUOTATION'] . $tpl_component['PRODUCT_BUTTON_ADD_TO_CART'];
1640
+		$tpl_component['PRODUCT_GALERY_DOCS'] = $product_document_galery;
1641
+		$tpl_component['PRODUCT_FEATURES'] = $attributeContentOutput;
1642
+		$tpl_component = apply_filters('wps-filter-product-complete-sheet-output', $tpl_component, $product_id);
1643
+
1644
+		/** Build template    */
1645
+		$tpl_way_to_take = wpshop_display::check_way_for_template($template_part);
1646
+		if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) {
1647
+			/*    Include the old way template part    */
1648
+			ob_start();
1649
+			require wpshop_display::get_template_file($tpl_way_to_take[1]);
1650
+			$content = ob_get_contents();
1651
+			ob_end_clean();
1652
+		} else {
1653
+			$content = wpshop_display::display_template_element($template_part, $tpl_component);
1654
+		}
1655
+		unset($tpl_component);
1656
+		return $content;
1657
+	}
1658 1658
 
1659
-    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)
1660
-    {
1661
-        $content = '';
1662
-        $product_information = $product_class = '';
1659
+	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)
1660
+	{
1661
+		$content = '';
1662
+		$product_information = $product_class = '';
1663 1663
 
1664
-        /** Get the product thumbnail    */
1665
-        $productThumbnail = wpshop_display::display_template_element('product_thumbnail_default', array());
1666
-        if (has_post_thumbnail($product_id)) {
1667
-            $productThumbnail = get_the_post_thumbnail($product_id, 'thumbnail');
1668
-        }
1664
+		/** Get the product thumbnail    */
1665
+		$productThumbnail = wpshop_display::display_template_element('product_thumbnail_default', array());
1666
+		if (has_post_thumbnail($product_id)) {
1667
+			$productThumbnail = get_the_post_thumbnail($product_id, 'thumbnail');
1668
+		}
1669 1669
 
1670
-        $product = self::get_product_data($product_id);
1670
+		$product = self::get_product_data($product_id);
1671 1671
 
1672
-        /**    Get the product information for output    */
1673
-        if (!empty($product)) {
1672
+		/**    Get the product information for output    */
1673
+		if (!empty($product)) {
1674 1674
 
1675
-            $product_title = $product['post_title'];
1676
-            $product_name = $product['post_name'];
1677
-            $product_link = get_permalink($product_id);
1678
-            $product_more_informations = $product['product_content'];
1679
-            $product_excerpt = $product['product_excerpt'];
1675
+			$product_title = $product['post_title'];
1676
+			$product_name = $product['post_name'];
1677
+			$product_link = get_permalink($product_id);
1678
+			$product_more_informations = $product['product_content'];
1679
+			$product_excerpt = $product['product_excerpt'];
1680 1680
 
1681
-            if (strpos($product['product_content'], '<!--more-->')) {
1682
-                $post_content = explode('<!--more-->', $product['product_content']);
1683
-                $product_more_informations = $post_content[0];
1684
-            }
1681
+			if (strpos($product['product_content'], '<!--more-->')) {
1682
+				$post_content = explode('<!--more-->', $product['product_content']);
1683
+				$product_more_informations = $post_content[0];
1684
+			}
1685 1685
 
1686
-        } else {
1687
-            $productThumbnail = wpshop_display::display_template_element('product_thumbnail_default', array());
1688
-            $product_title = '<i>' . __('This product does not exist', 'wpshop') . '</i>';
1689
-            $product_link = '';
1690
-            $product_more_informations = '';
1691
-            $product_excerpt = '';
1692
-        }
1686
+		} else {
1687
+			$productThumbnail = wpshop_display::display_template_element('product_thumbnail_default', array());
1688
+			$product_title = '<i>' . __('This product does not exist', 'wpshop') . '</i>';
1689
+			$product_link = '';
1690
+			$product_more_informations = '';
1691
+			$product_excerpt = '';
1692
+		}
1693 1693
 
1694
-        /** Retrieve product price    */
1695
-        $price_attribute = wpshop_attributes::getElement('product_price', "'valid'", 'code');
1696
-        $price_display = wpshop_attributes::check_attribute_display($price_attribute->is_visible_in_front_listing, $product['custom_display'], 'attribute', 'product_price', 'mini_output');
1697
-        $catalog_options = get_option('wpshop_catalog_main_option', array());
1698
-        $productPrice = '';
1699
-        $wpshop_price_piloting_option = get_option('wpshop_shop_price_piloting');
1700
-        $check_product_price = wpshop_prices::check_product_price($product);
1701
-        $result_price_piloting = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $check_product_price['et'] : $check_product_price['ati'];
1702
-        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)) {
1703
-            $product_price_infos = wpshop_prices::get_product_price($product, 'just_price_infos', 'mini_output');
1704
-
1705
-            if (!empty($product_price_infos)) {
1706
-                $tpl_component_price = array();
1707
-                /** Price piloting **/
1694
+		/** Retrieve product price    */
1695
+		$price_attribute = wpshop_attributes::getElement('product_price', "'valid'", 'code');
1696
+		$price_display = wpshop_attributes::check_attribute_display($price_attribute->is_visible_in_front_listing, $product['custom_display'], 'attribute', 'product_price', 'mini_output');
1697
+		$catalog_options = get_option('wpshop_catalog_main_option', array());
1698
+		$productPrice = '';
1699
+		$wpshop_price_piloting_option = get_option('wpshop_shop_price_piloting');
1700
+		$check_product_price = wpshop_prices::check_product_price($product);
1701
+		$result_price_piloting = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $check_product_price['et'] : $check_product_price['ati'];
1702
+		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)) {
1703
+			$product_price_infos = wpshop_prices::get_product_price($product, 'just_price_infos', 'mini_output');
1704
+
1705
+			if (!empty($product_price_infos)) {
1706
+				$tpl_component_price = array();
1707
+				/** Price piloting **/
1708 1708
 				$price_display_option = get_option( 'wpshop_catalog_product_option' );
1709 1709
 				$tpl_component['PRICE_FROM'] = (!empty($price_display_option) && !empty($price_display_option['price_display']) && !empty($price_display_option['price_display']['text_from']) ) ? 'on' : '';
1710
-                $price_ploting = get_option('wpshop_shop_price_piloting');
1711
-                $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'])) : '';
1712
-                $variations = wpshop_products::get_variation($product_id);
1710
+				$price_ploting = get_option('wpshop_shop_price_piloting');
1711
+				$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'])) : '';
1712
+				$variations = wpshop_products::get_variation($product_id);
1713 1713
 				$tpl_component_price['PRODUCT_PRICE'] = $product_price_infos['PRODUCT_PRICE'];
1714 1714
 				if(empty($product_price_infos['CROSSED_OUT_PRICE']) && (!empty($variations) && (!empty($product_price_infos['PRICE_FROM']) || !empty( $tpl_component['PRICE_FROM'] ) ))) {
1715 1715
 					$tpl_component_price['PRODUCT_PRICE'] = __('Price from', 'wpshop') . ' ' . $tpl_component_price['PRODUCT_PRICE'];
1716 1716
 				}
1717
-                $tpl_component_price['MESSAGE_SAVE_MONEY'] = $product_price_infos['MESSAGE_SAVE_MONEY'];
1718
-                $tpl_component_price['TAX_PILOTING'] = (!empty($price_ploting) && $price_ploting == 'HT') ? __('ET', 'wpshop') : '';
1719
-                $product_price_infos['MESSAGE_SAVE_MONEY'];
1720
-                $productPrice = wpshop_display::display_template_element('product_price_template_mini_output', $tpl_component_price);
1721
-            } else {
1722
-                $productPrice = wpshop_prices::get_product_price($product, 'price_display', array('mini_output', $output_type));
1723
-            }
1724
-        }
1717
+				$tpl_component_price['MESSAGE_SAVE_MONEY'] = $product_price_infos['MESSAGE_SAVE_MONEY'];
1718
+				$tpl_component_price['TAX_PILOTING'] = (!empty($price_ploting) && $price_ploting == 'HT') ? __('ET', 'wpshop') : '';
1719
+				$product_price_infos['MESSAGE_SAVE_MONEY'];
1720
+				$productPrice = wpshop_display::display_template_element('product_price_template_mini_output', $tpl_component_price);
1721
+			} else {
1722
+				$productPrice = wpshop_prices::get_product_price($product, 'price_display', array('mini_output', $output_type));
1723
+			}
1724
+		}
1725 1725
 
1726
-        /** Check if there is at less 1 product in stock    */
1727
-        $wps_product_ctr = new wps_product_ctr();
1728
-        $productStock = $wps_product_ctr->check_stock($product_id, 1);
1729
-        $productStock = $productStock === true ? 1 : null;
1730
-
1731
-        /** Define "Add to cart" button    */
1732
-        $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');
1733
-        $display_price_state_when_price_is_empty = false;
1734
-        if (empty($productPrice) && (!empty($catalog_options) || (!empty($catalog_options['wpshop_catalog_empty_price_behaviour']) && $catalog_options['wpshop_catalog_empty_price_behaviour'] == 'yes'))) {
1735
-            $display_price_state_when_price_is_empty = false;
1736
-        } else if (!empty($productPrice)) {
1737
-            $display_price_state_when_price_is_empty = true;
1738
-        }
1739
-        $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') : '';
1740
-        $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)) : '';
1726
+		/** Check if there is at less 1 product in stock    */
1727
+		$wps_product_ctr = new wps_product_ctr();
1728
+		$productStock = $wps_product_ctr->check_stock($product_id, 1);
1729
+		$productStock = $productStock === true ? 1 : null;
1730
+
1731
+		/** Define "Add to cart" button    */
1732
+		$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');
1733
+		$display_price_state_when_price_is_empty = false;
1734
+		if (empty($productPrice) && (!empty($catalog_options) || (!empty($catalog_options['wpshop_catalog_empty_price_behaviour']) && $catalog_options['wpshop_catalog_empty_price_behaviour'] == 'yes'))) {
1735
+			$display_price_state_when_price_is_empty = false;
1736
+		} else if (!empty($productPrice)) {
1737
+			$display_price_state_when_price_is_empty = true;
1738
+		}
1739
+		$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') : '';
1740
+		$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)) : '';
1741 1741
 
1742
-        /** Define "Ask a quotation" button    */
1743
-        $quotation_button = self::display_quotation_button($product_id, (!empty($product['quotation_allowed']) ? $product['quotation_allowed'] : null));
1744
-        $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'] : ''));
1742
+		/** Define "Ask a quotation" button    */
1743
+		$quotation_button = self::display_quotation_button($product_id, (!empty($product['quotation_allowed']) ? $product['quotation_allowed'] : null));
1744
+		$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'] : ''));
1745 1745
 
1746
-        $product_new = $product_new_def['output'];
1747
-        $product_class .= $product_new_def['class'];
1746
+		$product_new = $product_new_def['output'];
1747
+		$product_class .= $product_new_def['class'];
1748 1748
 
1749
-        $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'] : ''));
1750
-        $product_featured = $product_featured_def['output'];
1751
-        $product_class .= $product_featured_def['class'];
1749
+		$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'] : ''));
1750
+		$product_featured = $product_featured_def['output'];
1751
+		$product_class .= $product_featured_def['class'];
1752 1752
 
1753
-        if (!($current_item_position % $grid_element_nb_per_line)) {
1754
-            $product_class .= ' wpshop_last_product_of_line';
1755
-        }
1753
+		if (!($current_item_position % $grid_element_nb_per_line)) {
1754
+			$product_class .= ' wpshop_last_product_of_line';
1755
+		}
1756 1756
 
1757
-        if (!empty($product['product_id'])) {
1758
-            /** Template parameters    */
1759
-            $template_part = 'product_mini_' . $output_type;
1760
-            $tpl_component = array();
1761
-            $tpl_component['PRODUCT_THUMBNAIL'] = wpshop_display::display_template_element('product_thumbnail_default', array());
1762
-            $tpl_component['PRODUCT_THUMBNAIL_WPSHOP-PRODUCT-GALERY'] = wpshop_display::display_template_element('product_thumbnail_default', array());
1763
-            $tpl_component['PRODUCT_ID'] = $product_id;
1764
-            $tpl_component['PRODUCT_CLASS'] = $product_class;
1765
-            $tpl_component['PRODUCT_BUTTON_ADD_TO_CART'] = $add_to_cart_button;
1766
-            $tpl_component['PRODUCT_BUTTON_QUOTATION'] = $quotation_button;
1767
-            $tpl_component['PRODUCT_QUANTITY_CHOOSER'] = $product_quantity_chooser_input;
1768
-            $tpl_component['PRODUCT_BUTTONS'] = $tpl_component['PRODUCT_BUTTON_ADD_TO_CART'] . $tpl_component['PRODUCT_BUTTON_QUOTATION'];
1769
-            $tpl_component['PRODUCT_PRICE'] = $productPrice;
1770
-            $tpl_component['PRODUCT_PERMALINK'] = $product_link;
1771
-            $tpl_component['PRODUCT_TITLE'] = (!empty($product_title)) ? $product_title : '';
1772
-            $tpl_component['PRODUCT_NAME'] = $product_name;
1773
-            $tpl_component['PRODUCT_DESCRIPTION'] = $product_more_informations;
1774
-            $tpl_component['PRODUCT_IS_NEW'] = $product_new;
1775
-            $tpl_component['PRODUCT_IS_FEATURED'] = $product_featured;
1776
-            $tpl_component['PRODUCT_EXTRA_STATE'] = $tpl_component['PRODUCT_IS_NEW'] . $tpl_component['PRODUCT_IS_FEATURED'];
1777
-            $tpl_component['PRODUCT_THUMBNAIL'] = $productThumbnail;
1778
-
1779
-            if (has_post_thumbnail($product_id)) {
1780
-                $image_attributes = wp_get_attachment_metadata(get_post_thumbnail_id($product_id));
1781
-                if (!empty($image_attributes) && !empty($image_attributes['sizes']) && is_array($image_attributes['sizes'])) {
1782
-                    $existing_image_sizes = get_intermediate_image_sizes();
1783
-                    foreach ($existing_image_sizes as $size_name) {
1784
-                        $tpl_component['PRODUCT_THUMBNAIL_' . strtoupper($size_name)] = wp_get_attachment_image(get_post_thumbnail_id($product_id), $size_name);
1785
-                        $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;
1786
-                    }
1787
-                }
1788
-            }
1789
-
1790
-            $tpl_component['PRODUCT_EXCERPT'] = $product_excerpt;
1791
-            $tpl_component['PRODUCT_OUTPUT_TYPE'] = $output_type;
1792
-            $tpl_component = apply_filters('wps-filter-product-mini-output', $tpl_component, $product_id);
1793
-
1794
-            /** Build template    */
1795
-            $tpl_way_to_take = wpshop_display::check_way_for_template($template_part);
1796
-            if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) {
1797
-                /**    Include the old way template part    */
1798
-                ob_start();
1799
-                require wpshop_display::get_template_file($tpl_way_to_take[1]);
1800
-                $content = ob_get_contents();
1801
-                ob_end_clean();
1802
-            } else {
1803
-                $content = wpshop_display::display_template_element($template_part, $tpl_component);
1804
-            }
1805
-            unset($tpl_component);
1757
+		if (!empty($product['product_id'])) {
1758
+			/** Template parameters    */
1759
+			$template_part = 'product_mini_' . $output_type;
1760
+			$tpl_component = array();
1761
+			$tpl_component['PRODUCT_THUMBNAIL'] = wpshop_display::display_template_element('product_thumbnail_default', array());
1762
+			$tpl_component['PRODUCT_THUMBNAIL_WPSHOP-PRODUCT-GALERY'] = wpshop_display::display_template_element('product_thumbnail_default', array());
1763
+			$tpl_component['PRODUCT_ID'] = $product_id;
1764
+			$tpl_component['PRODUCT_CLASS'] = $product_class;
1765
+			$tpl_component['PRODUCT_BUTTON_ADD_TO_CART'] = $add_to_cart_button;
1766
+			$tpl_component['PRODUCT_BUTTON_QUOTATION'] = $quotation_button;
1767
+			$tpl_component['PRODUCT_QUANTITY_CHOOSER'] = $product_quantity_chooser_input;
1768
+			$tpl_component['PRODUCT_BUTTONS'] = $tpl_component['PRODUCT_BUTTON_ADD_TO_CART'] . $tpl_component['PRODUCT_BUTTON_QUOTATION'];
1769
+			$tpl_component['PRODUCT_PRICE'] = $productPrice;
1770
+			$tpl_component['PRODUCT_PERMALINK'] = $product_link;
1771
+			$tpl_component['PRODUCT_TITLE'] = (!empty($product_title)) ? $product_title : '';
1772
+			$tpl_component['PRODUCT_NAME'] = $product_name;
1773
+			$tpl_component['PRODUCT_DESCRIPTION'] = $product_more_informations;
1774
+			$tpl_component['PRODUCT_IS_NEW'] = $product_new;
1775
+			$tpl_component['PRODUCT_IS_FEATURED'] = $product_featured;
1776
+			$tpl_component['PRODUCT_EXTRA_STATE'] = $tpl_component['PRODUCT_IS_NEW'] . $tpl_component['PRODUCT_IS_FEATURED'];
1777
+			$tpl_component['PRODUCT_THUMBNAIL'] = $productThumbnail;
1778
+
1779
+			if (has_post_thumbnail($product_id)) {
1780
+				$image_attributes = wp_get_attachment_metadata(get_post_thumbnail_id($product_id));
1781
+				if (!empty($image_attributes) && !empty($image_attributes['sizes']) && is_array($image_attributes['sizes'])) {
1782
+					$existing_image_sizes = get_intermediate_image_sizes();
1783
+					foreach ($existing_image_sizes as $size_name) {
1784
+						$tpl_component['PRODUCT_THUMBNAIL_' . strtoupper($size_name)] = wp_get_attachment_image(get_post_thumbnail_id($product_id), $size_name);
1785
+						$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;
1786
+					}
1787
+				}
1788
+			}
1806 1789
 
1807
-        }
1790
+			$tpl_component['PRODUCT_EXCERPT'] = $product_excerpt;
1791
+			$tpl_component['PRODUCT_OUTPUT_TYPE'] = $output_type;
1792
+			$tpl_component = apply_filters('wps-filter-product-mini-output', $tpl_component, $product_id);
1793
+
1794
+			/** Build template    */
1795
+			$tpl_way_to_take = wpshop_display::check_way_for_template($template_part);
1796
+			if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) {
1797
+				/**    Include the old way template part    */
1798
+				ob_start();
1799
+				require wpshop_display::get_template_file($tpl_way_to_take[1]);
1800
+				$content = ob_get_contents();
1801
+				ob_end_clean();
1802
+			} else {
1803
+				$content = wpshop_display::display_template_element($template_part, $tpl_component);
1804
+			}
1805
+			unset($tpl_component);
1808 1806
 
1809
-        return $content;
1810
-    }
1807
+		}
1811 1808
 
1812
-    /**
1813
-     *    Get the products (post) of a given category
1814
-     *
1815
-     *    @param string $category_slug The category slug we want to get the product list for
1816
-     *
1817
-     *    @return mixed $widget_content The output for the product list
1818
-     */
1819
-    public static function get_product_of_category($category_slug, $category_id)
1820
-    {
1821
-        global $top_categories;
1822
-        $widget_content = '';
1823
-        $products = wp_cache_get('wpshop_products_category_' . $category_id);
1824
-        if (false == $products) {
1825
-            $args = array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES => $category_slug);
1826
-            $products = get_posts($args);
1827
-            wp_cache_set('wpshop_products_category_' . $category_id, $products);
1828
-        }
1829
-        if (is_array($products) && (count($products) > 0)) {
1830
-            foreach ($products as $product) {
1831
-                if ($product->post_status == "publish") {
1832
-                    ob_start();
1833
-                    require wpshop_display::get_template_file('categories_products-widget.tpl.php');
1834
-                    $widget_content .= ob_get_contents();
1835
-                    ob_end_clean();
1836
-                }
1837
-            }
1838
-        }
1809
+		return $content;
1810
+	}
1839 1811
 
1840
-        echo $widget_content;
1841
-    }
1812
+	/**
1813
+	 *    Get the products (post) of a given category
1814
+	 *
1815
+	 *    @param string $category_slug The category slug we want to get the product list for
1816
+	 *
1817
+	 *    @return mixed $widget_content The output for the product list
1818
+	 */
1819
+	public static function get_product_of_category($category_slug, $category_id)
1820
+	{
1821
+		global $top_categories;
1822
+		$widget_content = '';
1823
+		$products = wp_cache_get('wpshop_products_category_' . $category_id);
1824
+		if (false == $products) {
1825
+			$args = array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES => $category_slug);
1826
+			$products = get_posts($args);
1827
+			wp_cache_set('wpshop_products_category_' . $category_id, $products);
1828
+		}
1829
+		if (is_array($products) && (count($products) > 0)) {
1830
+			foreach ($products as $product) {
1831
+				if ($product->post_status == "publish") {
1832
+					ob_start();
1833
+					require wpshop_display::get_template_file('categories_products-widget.tpl.php');
1834
+					$widget_content .= ob_get_contents();
1835
+					ob_end_clean();
1836
+				}
1837
+			}
1838
+		}
1842 1839
 
1843
-    /**
1844
-     *
1845
-     * @param unknown_type $selected_product
1846
-     * @return string
1847
-     */
1848
-    public function custom_product_list($selected_product = array())
1849
-    {
1850
-        global $wpdb;
1851
-
1852
-        /*    Start the table definition    */
1853
-        $tableId = 'wpshop_product_list';
1854
-        $tableTitles = array();
1855
-        $tableTitles[] = '';
1856
-        $tableTitles[] = __('Id', 'wpshop');
1857
-        $tableTitles[] = __('Quantity', 'wpshop');
1858
-        $tableTitles[] = __('Reference', 'wpshop');
1859
-        $tableTitles[] = __('Product name', 'wpshop');
1860
-        $tableTitles[] = __('Actions', 'wpshop');
1861
-        $tableTitles[] = __('Price', 'wpshop');
1862
-        $tableClasses = array();
1863
-        $tableClasses[] = 'wpshop_product_selector_column';
1864
-        $tableClasses[] = 'wpshop_product_identifier_column';
1865
-        $tableClasses[] = 'wpshop_product_quantity_column';
1866
-        $tableClasses[] = 'wpshop_product_sku_column';
1867
-        $tableClasses[] = 'wpshop_product_name_column';
1868
-        $tableClasses[] = 'wpshop_product_link_column';
1869
-        $tableClasses[] = 'wpshop_product_price_column';
1870
-
1871
-        /*    Get post list    */
1872
-        $has_result = false;
1873
-        $current_line_index = 0;
1874
-        $posts = query_posts(array(
1875
-            'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'posts_per_page' => -1,
1876
-        ));
1877
-        if (!empty($posts)) {
1878
-            $has_result = true;
1879
-            foreach ($posts as $post) {
1880
-                $tableRowsId[$current_line_index] = 'product_' . $post->ID;
1881
-
1882
-                $post_info = get_post_meta($post->ID, '_wpshop_product_metadata', true);
1883
-
1884
-                unset($tableRowValue);
1885
-                $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 . '" />');
1886
-                $tableRowValue[] = array('class' => 'wpshop_product_identifier_cell', 'value' => '<label for="wpshop_product_cb_dialog_' . $post->ID . '" >' . WPSHOP_IDENTIFIER_PRODUCT . $post->ID . '</label>');
1887
-                $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>');
1888
-                $tableRowValue[] = array('class' => 'wpshop_product_sku_cell', 'value' => (!empty($post_info['product_reference'])) ? $post_info['product_reference'] : '');
1889
-                $tableRowValue[] = array('class' => 'wpshop_product_name_cell', 'value' => $post->post_title);
1890
-                $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/>
1840
+		echo $widget_content;
1841
+	}
1842
+
1843
+	/**
1844
+	 *
1845
+	 * @param unknown_type $selected_product
1846
+	 * @return string
1847
+	 */
1848
+	public function custom_product_list($selected_product = array())
1849
+	{
1850
+		global $wpdb;
1851
+
1852
+		/*    Start the table definition    */
1853
+		$tableId = 'wpshop_product_list';
1854
+		$tableTitles = array();
1855
+		$tableTitles[] = '';
1856
+		$tableTitles[] = __('Id', 'wpshop');
1857
+		$tableTitles[] = __('Quantity', 'wpshop');
1858
+		$tableTitles[] = __('Reference', 'wpshop');
1859
+		$tableTitles[] = __('Product name', 'wpshop');
1860
+		$tableTitles[] = __('Actions', 'wpshop');
1861
+		$tableTitles[] = __('Price', 'wpshop');
1862
+		$tableClasses = array();
1863
+		$tableClasses[] = 'wpshop_product_selector_column';
1864
+		$tableClasses[] = 'wpshop_product_identifier_column';
1865
+		$tableClasses[] = 'wpshop_product_quantity_column';
1866
+		$tableClasses[] = 'wpshop_product_sku_column';
1867
+		$tableClasses[] = 'wpshop_product_name_column';
1868
+		$tableClasses[] = 'wpshop_product_link_column';
1869
+		$tableClasses[] = 'wpshop_product_price_column';
1870
+
1871
+		/*    Get post list    */
1872
+		$has_result = false;
1873
+		$current_line_index = 0;
1874
+		$posts = query_posts(array(
1875
+			'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'posts_per_page' => -1,
1876
+		));
1877
+		if (!empty($posts)) {
1878
+			$has_result = true;
1879
+			foreach ($posts as $post) {
1880
+				$tableRowsId[$current_line_index] = 'product_' . $post->ID;
1881
+
1882
+				$post_info = get_post_meta($post->ID, '_wpshop_product_metadata', true);
1883
+
1884
+				unset($tableRowValue);
1885
+				$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 . '" />');
1886
+				$tableRowValue[] = array('class' => 'wpshop_product_identifier_cell', 'value' => '<label for="wpshop_product_cb_dialog_' . $post->ID . '" >' . WPSHOP_IDENTIFIER_PRODUCT . $post->ID . '</label>');
1887
+				$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>');
1888
+				$tableRowValue[] = array('class' => 'wpshop_product_sku_cell', 'value' => (!empty($post_info['product_reference'])) ? $post_info['product_reference'] : '');
1889
+				$tableRowValue[] = array('class' => 'wpshop_product_name_cell', 'value' => $post->post_title);
1890
+				$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/>
1891 1891
 				<a href="' . admin_url('post.php?post=' . $post->ID . '&action=edit') . '" target="wpshop_edit_product" >' . __('Edit product', 'wpshop') . '</a>');
1892
-                $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() : ''));
1893
-                $tableRows[] = $tableRowValue;
1892
+				$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() : ''));
1893
+				$tableRows[] = $tableRowValue;
1894 1894
 
1895
-                $current_line_index++;
1896
-            }
1897
-            wp_reset_query();
1898
-        }
1899
-        $posts = query_posts(array(
1900
-            'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, 'posts_per_page' => -1,
1901
-        ));
1902
-        if (!empty($posts)) {
1903
-            $has_result = true;
1904
-            foreach ($posts as $post) {
1905
-                $tableRowsId[$current_line_index] = 'product_' . $post->ID;
1906
-
1907
-                $post_info = get_post_meta($post->ID, '_wpshop_product_metadata', true);
1908
-
1909
-                unset($tableRowValue);
1910
-                $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 . '" />');
1911
-                $tableRowValue[] = array('class' => 'wpshop_product_identifier_cell', 'value' => '<label for="wpshop_product_cb_dialog_' . $post->ID . '" >' . WPSHOP_IDENTIFIER_PRODUCT . $post->ID . '</label>');
1912
-                $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>');
1913
-                $tableRowValue[] = array('class' => 'wpshop_product_sku_cell', 'value' => (!empty($post_info['product_reference'])) ? $post_info['product_reference'] : '');
1914
-                $parent_product = wpshop_products::get_parent_variation($post->ID);
1915
-                if (!empty($parent_product) && !empty($parent_product['parent_post'])) {
1916
-                    $product_variations_postmeta = get_post_meta($post->ID, '_wpshop_variations_attribute_def', true);
1917
-                    $query = $wpdb->prepare('SELECT frontend_label FROM ' . WPSHOP_DBT_ATTRIBUTE . ' WHERE code = %s', key($product_variations_postmeta));
1918
-                    $option_name = $wpdb->get_var($query);
1919
-                    $query = $wpdb->prepare('SELECT label FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id = %d', $product_variations_postmeta[key($product_variations_postmeta)]);
1920
-                    $option_value = $wpdb->get_var($query);
1921
-                    $parent_post = $parent_product['parent_post'];
1922
-                    $tableRowValue[] = array('class' => 'wpshop_product_name_cell', 'value' => $parent_post->post_title . ' <br/>(' . $option_name . ' : ' . $option_value . ')');
1923
-                } else {
1924
-                    $tableRowValue[] = array('class' => 'wpshop_product_name_cell', 'value' => $post->post_title);
1925
-                }
1926
-
1927
-                $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/>
1895
+				$current_line_index++;
1896
+			}
1897
+			wp_reset_query();
1898
+		}
1899
+		$posts = query_posts(array(
1900
+			'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, 'posts_per_page' => -1,
1901
+		));
1902
+		if (!empty($posts)) {
1903
+			$has_result = true;
1904
+			foreach ($posts as $post) {
1905
+				$tableRowsId[$current_line_index] = 'product_' . $post->ID;
1906
+
1907
+				$post_info = get_post_meta($post->ID, '_wpshop_product_metadata', true);
1908
+
1909
+				unset($tableRowValue);
1910
+				$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 . '" />');
1911
+				$tableRowValue[] = array('class' => 'wpshop_product_identifier_cell', 'value' => '<label for="wpshop_product_cb_dialog_' . $post->ID . '" >' . WPSHOP_IDENTIFIER_PRODUCT . $post->ID . '</label>');
1912
+				$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>');
1913
+				$tableRowValue[] = array('class' => 'wpshop_product_sku_cell', 'value' => (!empty($post_info['product_reference'])) ? $post_info['product_reference'] : '');
1914
+				$parent_product = wpshop_products::get_parent_variation($post->ID);
1915
+				if (!empty($parent_product) && !empty($parent_product['parent_post'])) {
1916
+					$product_variations_postmeta = get_post_meta($post->ID, '_wpshop_variations_attribute_def', true);
1917
+					$query = $wpdb->prepare('SELECT frontend_label FROM ' . WPSHOP_DBT_ATTRIBUTE . ' WHERE code = %s', key($product_variations_postmeta));
1918
+					$option_name = $wpdb->get_var($query);
1919
+					$query = $wpdb->prepare('SELECT label FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id = %d', $product_variations_postmeta[key($product_variations_postmeta)]);
1920
+					$option_value = $wpdb->get_var($query);
1921
+					$parent_post = $parent_product['parent_post'];
1922
+					$tableRowValue[] = array('class' => 'wpshop_product_name_cell', 'value' => $parent_post->post_title . ' <br/>(' . $option_name . ' : ' . $option_value . ')');
1923
+				} else {
1924
+					$tableRowValue[] = array('class' => 'wpshop_product_name_cell', 'value' => $post->post_title);
1925
+				}
1926
+
1927
+				$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/>
1928 1928
 				<a href="' . admin_url('post.php?post=' . $post->ID . '&action=edit') . '" target="wpshop_edit_product" >' . __('Edit product', 'wpshop') . '</a>');
1929
-                $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() : ''));
1930
-                $tableRows[] = $tableRowValue;
1929
+				$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() : ''));
1930
+				$tableRows[] = $tableRowValue;
1931 1931
 
1932
-                $current_line_index++;
1933
-            }
1934
-            wp_reset_query();
1935
-        }
1932
+				$current_line_index++;
1933
+			}
1934
+			wp_reset_query();
1935
+		}
1936 1936
 
1937
-        if (!$has_result) {
1938
-            $tableRowsId[] = 'no_product_found';
1939
-            unset($tableRowValue);
1940
-            $tableRowValue[] = array('class' => 'wpshop_product_selector_cell', 'value' => '');
1941
-            $tableRowValue[] = array('class' => 'wpshop_product_identifier_cell', 'value' => '');
1942
-            $tableRowValue[] = array('class' => 'wpshop_product_quantity_cell', 'value' => '');
1943
-            $tableRowValue[] = array('class' => 'wpshop_product_sku_cell', 'value' => __('No element to ouput here', 'wpshop'));
1944
-            $tableRowValue[] = array('class' => 'wpshop_product_name_cell', 'value' => '');
1945
-            $tableRowValue[] = array('class' => 'wpshop_product_link_cell', 'value' => '');
1946
-            $tableRowValue[] = array('class' => 'wpshop_product_price_cell', 'value' => '');
1947
-            $tableRows[] = $tableRowValue;
1948
-        }
1937
+		if (!$has_result) {
1938
+			$tableRowsId[] = 'no_product_found';
1939
+			unset($tableRowValue);
1940
+			$tableRowValue[] = array('class' => 'wpshop_product_selector_cell', 'value' => '');
1941
+			$tableRowValue[] = array('class' => 'wpshop_product_identifier_cell', 'value' => '');
1942
+			$tableRowValue[] = array('class' => 'wpshop_product_quantity_cell', 'value' => '');
1943
+			$tableRowValue[] = array('class' => 'wpshop_product_sku_cell', 'value' => __('No element to ouput here', 'wpshop'));
1944
+			$tableRowValue[] = array('class' => 'wpshop_product_name_cell', 'value' => '');
1945
+			$tableRowValue[] = array('class' => 'wpshop_product_link_cell', 'value' => '');
1946
+			$tableRowValue[] = array('class' => 'wpshop_product_price_cell', 'value' => '');
1947
+			$tableRows[] = $tableRowValue;
1948
+		}
1949 1949
 
1950
-        return wpshop_display::getTable($tableId, $tableTitles, $tableRows, $tableClasses, $tableRowsId, '', false) . '
1950
+		return wpshop_display::getTable($tableId, $tableTitles, $tableRows, $tableClasses, $tableRowsId, '', false) . '
1951 1951
 <script type="text/javascript" >
1952 1952
 	wpshop(document).ready(function(){
1953 1953
 		jQuery("#' . $tableId . '").dataTable( {
@@ -1956,1533 +1956,1533 @@  discard block
 block discarded – undo
1956 1956
 		});
1957 1957
 	});
1958 1958
 </script>';
1959
-    }
1959
+	}
1960 1960
 
1961
-    /**
1962
-     * Allows to manage output for special state for a product (New product/highlight product)
1963
-     *
1964
-     * @param string $special The type of special type we want to output
1965
-     * @param string $output_type The current display type (used for product listing)
1966
-     * @param string $special_state_def The value allowing to test if we have to display a special state for the product
1967
-     * @param datetime $special_state_start The start date if applicable for the special state
1968
-     * @param datetime $special_state_end The end date if applicable for the special state
1969
-     *
1970
-     * @return array $product_special_state The product special state
1971
-     */
1972
-    public static function display_product_special_state($special, $output_type, $special_state_def, $special_state_start, $special_state_end)
1973
-    {
1974
-        $product_special_state = array();
1975
-        $product_special_state['output'] = $product_special_state['class'] = '';
1976
-
1977
-        /** Get product special state definition    */
1978
-        $special_state_def = !empty($special_state_def) ? $special_state_def : 'No';
1979
-        $special_state_start = !empty($special_state_start) ? substr($special_state_start, 0, 10) : null;
1980
-        $special_state_end = !empty($special_state_end) ? substr($special_state_end, 0, 10) : null;
1981
-
1982
-        /** Get current time    */
1983
-        $current_time = substr(current_time('mysql', 0), 0, 10);
1984
-
1985
-        /** PRODUCT MARK AS NEW */
1986
-        $show_product_special_state = false;
1987
-        if ((strtolower(__($special_state_def, 'wpshop')) === strtolower(__('Yes', 'wpshop'))) &&
1988
-            (empty($special_state_start) || ($special_state_start == '0000-00-00') || ($special_state_start >= $current_time)) &&
1989
-            (empty($special_state_end) || ($special_state_end == '0000-00-00') || ($special_state_end <= $current_time))) {
1990
-            $show_product_special_state = true;
1991
-        }
1961
+	/**
1962
+	 * Allows to manage output for special state for a product (New product/highlight product)
1963
+	 *
1964
+	 * @param string $special The type of special type we want to output
1965
+	 * @param string $output_type The current display type (used for product listing)
1966
+	 * @param string $special_state_def The value allowing to test if we have to display a special state for the product
1967
+	 * @param datetime $special_state_start The start date if applicable for the special state
1968
+	 * @param datetime $special_state_end The end date if applicable for the special state
1969
+	 *
1970
+	 * @return array $product_special_state The product special state
1971
+	 */
1972
+	public static function display_product_special_state($special, $output_type, $special_state_def, $special_state_start, $special_state_end)
1973
+	{
1974
+		$product_special_state = array();
1975
+		$product_special_state['output'] = $product_special_state['class'] = '';
1976
+
1977
+		/** Get product special state definition    */
1978
+		$special_state_def = !empty($special_state_def) ? $special_state_def : 'No';
1979
+		$special_state_start = !empty($special_state_start) ? substr($special_state_start, 0, 10) : null;
1980
+		$special_state_end = !empty($special_state_end) ? substr($special_state_end, 0, 10) : null;
1981
+
1982
+		/** Get current time    */
1983
+		$current_time = substr(current_time('mysql', 0), 0, 10);
1984
+
1985
+		/** PRODUCT MARK AS NEW */
1986
+		$show_product_special_state = false;
1987
+		if ((strtolower(__($special_state_def, 'wpshop')) === strtolower(__('Yes', 'wpshop'))) &&
1988
+			(empty($special_state_start) || ($special_state_start == '0000-00-00') || ($special_state_start >= $current_time)) &&
1989
+			(empty($special_state_end) || ($special_state_end == '0000-00-00') || ($special_state_end <= $current_time))) {
1990
+			$show_product_special_state = true;
1991
+		}
1992 1992
 
1993
-        if ($show_product_special_state) {
1994
-            /** Check the type of special output needed    */
1995
-            switch ($special) {
1996
-                case 'declare_new':
1997
-                    $product_special_state['class'] = ' wpshop_product_is_new_' . $output_type;
1998
-                    $template_part = 'product_is_new_sticker';
1999
-                    break;
2000
-
2001
-                case 'highlight_product':
2002
-                    $product_special_state['class'] = ' wpshop_product_featured_' . $output_type;
2003
-                    $template_part = 'product_is_featured_sticker';
2004
-                    break;
2005
-            }
2006
-
2007
-            /** Template parameters    */
2008
-            $tpl_component = array();
2009
-
2010
-            /** Build template        */
2011
-            $tpl_way_to_take = wpshop_display::check_way_for_template($template_part);
2012
-            if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) {
2013
-                /**    Include the old way template part    */
2014
-                ob_start();
2015
-                require wpshop_display::get_template_file($tpl_way_to_take[1]);
2016
-                $product_special_state['output'] = ob_get_contents();
2017
-                ob_end_clean();
2018
-            } else {
2019
-                $product_special_state['output'] = wpshop_display::display_template_element($template_part, $tpl_component);
2020
-            }
2021
-            unset($tpl_component);
2022
-        }
1993
+		if ($show_product_special_state) {
1994
+			/** Check the type of special output needed    */
1995
+			switch ($special) {
1996
+				case 'declare_new':
1997
+					$product_special_state['class'] = ' wpshop_product_is_new_' . $output_type;
1998
+					$template_part = 'product_is_new_sticker';
1999
+					break;
2023 2000
 
2024
-        return $product_special_state;
2025
-    }
2001
+				case 'highlight_product':
2002
+					$product_special_state['class'] = ' wpshop_product_featured_' . $output_type;
2003
+					$template_part = 'product_is_featured_sticker';
2004
+					break;
2005
+			}
2026 2006
 
2027
-    /**
2028
-     * Prepare product price for saving and easier read later
2029
-     *
2030
-     * @param integer $element_id Identifier of current product
2031
-     */
2032
-    public static function calculate_price($element_id)
2033
-    {
2034
-        global $wpdb;
2035
-
2036
-        /**
2037
-         * Récupères les attributs suivants : product_price, price_ht et tva
2038
-         * par rapport à $element_id / Get the next attributes : product_price,
2039
-         * price_ht and tva
2040
-         */
2041
-        $query = $wpdb->prepare(
2042
-            "SELECT ATTR.code, ATTR_VAL.value_id AS id, ATTR_VAL.value, ATTR.id AS attribute_id
2007
+			/** Template parameters    */
2008
+			$tpl_component = array();
2009
+
2010
+			/** Build template        */
2011
+			$tpl_way_to_take = wpshop_display::check_way_for_template($template_part);
2012
+			if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) {
2013
+				/**    Include the old way template part    */
2014
+				ob_start();
2015
+				require wpshop_display::get_template_file($tpl_way_to_take[1]);
2016
+				$product_special_state['output'] = ob_get_contents();
2017
+				ob_end_clean();
2018
+			} else {
2019
+				$product_special_state['output'] = wpshop_display::display_template_element($template_part, $tpl_component);
2020
+			}
2021
+			unset($tpl_component);
2022
+		}
2023
+
2024
+		return $product_special_state;
2025
+	}
2026
+
2027
+	/**
2028
+	 * Prepare product price for saving and easier read later
2029
+	 *
2030
+	 * @param integer $element_id Identifier of current product
2031
+	 */
2032
+	public static function calculate_price($element_id)
2033
+	{
2034
+		global $wpdb;
2035
+
2036
+		/**
2037
+		 * Récupères les attributs suivants : product_price, price_ht et tva
2038
+		 * par rapport à $element_id / Get the next attributes : product_price,
2039
+		 * price_ht and tva
2040
+		 */
2041
+		$query = $wpdb->prepare(
2042
+			"SELECT ATTR.code, ATTR_VAL.value_id AS id, ATTR_VAL.value, ATTR.id AS attribute_id
2043 2043
 			FROM " . WPSHOP_DBT_ATTRIBUTE . " AS ATTR
2044 2044
 				RIGHT JOIN " . WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL . " AS ATTR_VAL ON ((ATTR_VAL.attribute_id = ATTR.id) AND (ATTR_VAL.entity_id = %d))
2045 2045
 			WHERE ATTR.code IN ('" . implode("', '", unserialize(WPSHOP_ATTRIBUTE_PRICES)) . "')",
2046
-            $element_id
2047
-        );
2048
-        $prices_attribute = $wpdb->get_results($query, OBJECT_K);
2049
-
2050
-        /** Si aucun prix trouvé on stop la méthode / If not found price, stop the method */
2051
-        if (empty($prices_attribute)) {
2052
-            return false;
2053
-        } else {
2054
-            /**
2055
-             * Récupère le prix de base selon le pilotage de prix de la boutique / Get
2056
-             * the base amount according on the shop price control
2057
-             */
2058
-            $base_price = $prices_attribute[constant('WPSHOP_PRODUCT_PRICE_' . WPSHOP_PRODUCT_PRICE_PILOT)]->value;
2059
-            $rate_vat = wpshop_prices::get_rate_vat($element_id);
2060
-            $divider_price_ttc = 1 + ($rate_vat->value / 100);
2061
-
2062
-            /**
2063
-             * Informations nécessaire pour crée un attribut / Information needed to
2064
-             * create an attribute
2065
-             */
2066
-            $entity_type_id = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT);
2067
-            $language = WPSHOP_CURRENT_LOCALE;
2068
-            $icl_post_language = !empty($_REQUEST['icl_post_language']) ? sanitize_text_field($_REQUEST['icl_post_language']) : '';
2069
-
2070
-            if (!empty($icl_post_language)) {
2071
-                $query = $wpdb->prepare("SELECT locale FROM " . $wpdb->prefix . "icl_locale_map WHERE code = %s", $icl_post_language);
2072
-                $language = $wpdb->get_var($query);
2073
-            }
2074
-
2075
-            /**
2076
-             * Vérifie la configuration pour savoir comment calculer les prix pour le produit /
2077
-             * Check configuration to know how to make the calcul for the product
2078
-             */
2079
-            if (WPSHOP_PRODUCT_PRICE_PILOT == 'HT') {
2080
-                $price_with_vat = ($base_price * $divider_price_ttc);
2081
-                $price_no_vat = $base_price;
2082
-            } else if (WPSHOP_PRODUCT_PRICE_PILOT == 'TTC') {
2083
-                $price_with_vat = $base_price;
2084
-                $price_no_vat = ($price_with_vat / $divider_price_ttc);
2085
-            }
2086
-
2087
-            /**
2088
-             * Le dernier paramètre permet de ne pas supprimer les attributs du même
2089
-             * type que celui-ci / The last parameter allows not to delete the
2090
-             * attributes of the same type as this one
2091
-             */
2092
-            wpshop_attributes::saveAttributeForEntity(array('decimal' => array('product_price' => $price_with_vat)), $entity_type_id, $element_id, $language, 'wpshop_products');
2093
-            wpshop_attributes::saveAttributeForEntity(array('decimal' => array('price_ht' => $price_no_vat)), $entity_type_id, $element_id, $language, 'wpshop_product');
2094
-
2095
-            /** Ajout ou met à jour de l'attribut tva / Add or update the attribute vat */
2096
-            $vat_amount = $price_with_vat - $price_no_vat;
2097
-            wpshop_attributes::saveAttributeForEntity(array('decimal' => array('tva' => $vat_amount)), $entity_type_id, $element_id, $language, 'wpshop_product');
2098
-
2099
-            /**    Update the product meta information with the calculated prices    */
2100
-            $product_postmeta = get_post_meta($element_id, WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, true);
2101
-            $product_postmeta[WPSHOP_PRODUCT_PRICE_TTC] = number_format(round($price_with_vat, 5), 5, '.', '');
2102
-            $product_postmeta[WPSHOP_PRODUCT_PRICE_HT] = number_format(round($price_no_vat, 5), 5, '.', '');
2103
-            $product_postmeta[WPSHOP_PRODUCT_PRICE_TAX_AMOUNT] = number_format(round($vat_amount, 5), 5, '.', '');
2104
-            $product_postmeta[WPSHOP_PRODUCT_PRICE_TAX] = $rate_vat->id;
2105
-
2106
-            update_post_meta($element_id, WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, $product_postmeta);
2046
+			$element_id
2047
+		);
2048
+		$prices_attribute = $wpdb->get_results($query, OBJECT_K);
2049
+
2050
+		/** Si aucun prix trouvé on stop la méthode / If not found price, stop the method */
2051
+		if (empty($prices_attribute)) {
2052
+			return false;
2053
+		} else {
2054
+			/**
2055
+			 * Récupère le prix de base selon le pilotage de prix de la boutique / Get
2056
+			 * the base amount according on the shop price control
2057
+			 */
2058
+			$base_price = $prices_attribute[constant('WPSHOP_PRODUCT_PRICE_' . WPSHOP_PRODUCT_PRICE_PILOT)]->value;
2059
+			$rate_vat = wpshop_prices::get_rate_vat($element_id);
2060
+			$divider_price_ttc = 1 + ($rate_vat->value / 100);
2061
+
2062
+			/**
2063
+			 * Informations nécessaire pour crée un attribut / Information needed to
2064
+			 * create an attribute
2065
+			 */
2066
+			$entity_type_id = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT);
2067
+			$language = WPSHOP_CURRENT_LOCALE;
2068
+			$icl_post_language = !empty($_REQUEST['icl_post_language']) ? sanitize_text_field($_REQUEST['icl_post_language']) : '';
2069
+
2070
+			if (!empty($icl_post_language)) {
2071
+				$query = $wpdb->prepare("SELECT locale FROM " . $wpdb->prefix . "icl_locale_map WHERE code = %s", $icl_post_language);
2072
+				$language = $wpdb->get_var($query);
2073
+			}
2107 2074
 
2108
-            /** Met à jour la meta _wps_price_infos */
2109
-            $p = wpshop_products::get_product_data($element_id);
2110
-            $price = wpshop_prices::get_product_price($p, 'just_price_infos', array('mini_output', 'grid'));
2111
-            update_post_meta($element_id, '_wps_price_infos', $price);
2075
+			/**
2076
+			 * Vérifie la configuration pour savoir comment calculer les prix pour le produit /
2077
+			 * Check configuration to know how to make the calcul for the product
2078
+			 */
2079
+			if (WPSHOP_PRODUCT_PRICE_PILOT == 'HT') {
2080
+				$price_with_vat = ($base_price * $divider_price_ttc);
2081
+				$price_no_vat = $base_price;
2082
+			} else if (WPSHOP_PRODUCT_PRICE_PILOT == 'TTC') {
2083
+				$price_with_vat = $base_price;
2084
+				$price_no_vat = ($price_with_vat / $divider_price_ttc);
2085
+			}
2112 2086
 
2113
-            /** Met à jour la meta _wpshop_displayed_price */
2114
-            wps_filter_search::save_displayed_price_meta($element_id);
2115
-        }
2087
+			/**
2088
+			 * Le dernier paramètre permet de ne pas supprimer les attributs du même
2089
+			 * type que celui-ci / The last parameter allows not to delete the
2090
+			 * attributes of the same type as this one
2091
+			 */
2092
+			wpshop_attributes::saveAttributeForEntity(array('decimal' => array('product_price' => $price_with_vat)), $entity_type_id, $element_id, $language, 'wpshop_products');
2093
+			wpshop_attributes::saveAttributeForEntity(array('decimal' => array('price_ht' => $price_no_vat)), $entity_type_id, $element_id, $language, 'wpshop_product');
2094
+
2095
+			/** Ajout ou met à jour de l'attribut tva / Add or update the attribute vat */
2096
+			$vat_amount = $price_with_vat - $price_no_vat;
2097
+			wpshop_attributes::saveAttributeForEntity(array('decimal' => array('tva' => $vat_amount)), $entity_type_id, $element_id, $language, 'wpshop_product');
2098
+
2099
+			/**    Update the product meta information with the calculated prices    */
2100
+			$product_postmeta = get_post_meta($element_id, WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, true);
2101
+			$product_postmeta[WPSHOP_PRODUCT_PRICE_TTC] = number_format(round($price_with_vat, 5), 5, '.', '');
2102
+			$product_postmeta[WPSHOP_PRODUCT_PRICE_HT] = number_format(round($price_no_vat, 5), 5, '.', '');
2103
+			$product_postmeta[WPSHOP_PRODUCT_PRICE_TAX_AMOUNT] = number_format(round($vat_amount, 5), 5, '.', '');
2104
+			$product_postmeta[WPSHOP_PRODUCT_PRICE_TAX] = $rate_vat->id;
2105
+
2106
+			update_post_meta($element_id, WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, $product_postmeta);
2107
+
2108
+			/** Met à jour la meta _wps_price_infos */
2109
+			$p = wpshop_products::get_product_data($element_id);
2110
+			$price = wpshop_prices::get_product_price($p, 'just_price_infos', array('mini_output', 'grid'));
2111
+			update_post_meta($element_id, '_wps_price_infos', $price);
2112
+
2113
+			/** Met à jour la meta _wpshop_displayed_price */
2114
+			wps_filter_search::save_displayed_price_meta($element_id);
2115
+		}
2116 2116
 
2117
-        return true;
2118
-    }
2117
+		return true;
2118
+	}
2119 2119
 
2120
-    /**
2121
-     * Allows to get the good button for adding product to cart
2122
-     *
2123
-     * @param integer $product_id The product identifier
2124
-     * @param boolean $productStock If there is the possibility to add the given product to the cart
2125
-     *
2126
-     * @return string $button The html output for the button
2127
-     */
2128
-    public static function display_add_to_cart_button($product_id, $productStock, $output_type = 'mini')
2129
-    {
2130
-        $button = '';
2120
+	/**
2121
+	 * Allows to get the good button for adding product to cart
2122
+	 *
2123
+	 * @param integer $product_id The product identifier
2124
+	 * @param boolean $productStock If there is the possibility to add the given product to the cart
2125
+	 *
2126
+	 * @return string $button The html output for the button
2127
+	 */
2128
+	public static function display_add_to_cart_button($product_id, $productStock, $output_type = 'mini')
2129
+	{
2130
+		$button = '';
2131 2131
 //         $attributes_frontend_display = get_post_meta( $product_id, '_wpshop_product_attributes_frontend_display', true );
2132 2132
 
2133
-        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') ) */) {
2134
-            /*
2133
+		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') ) */) {
2134
+			/*
2135 2135
              * Check if current product has variation for button display
2136 2136
              */
2137
-            $variations_exists = get_posts(array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, 'post_parent' => $product_id));
2138
-            $variations_list = (!empty($variations_exists) && is_array(wpshop_attributes::get_attribute_user_defined(array('entity_type_id' => self::currentPageCode)))) ? true : false;
2137
+			$variations_exists = get_posts(array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, 'post_parent' => $product_id));
2138
+			$variations_list = (!empty($variations_exists) && is_array(wpshop_attributes::get_attribute_user_defined(array('entity_type_id' => self::currentPageCode)))) ? true : false;
2139 2139
 
2140
-            /*
2140
+			/*
2141 2141
              * Template parameters
2142 2142
              */
2143 2143
 
2144
-            if (get_post_type($product_id) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT) {
2145
-                /** Check variation stock **/
2146
-                $variations = self::get_variation($product_id);
2147
-                if (!empty($variations)) {
2148
-                    foreach ($variations as $variation) {
2149
-                        if (!empty($variation) && !empty($variation['variation_dif']) && !empty($variation['variation_dif']['product_stock'])) {
2150
-                            $productStock += $variation['variation_dif']['product_stock'];
2151
-                        }
2152
-                    }
2153
-                }
2154
-            }
2155
-
2156
-            $template_part = ($variations_list && ($output_type == 'mini')) ? 'configure_product_button' : (!empty($productStock) ? 'add_to_cart_button' : 'unavailable_product_button');
2144
+			if (get_post_type($product_id) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT) {
2145
+				/** Check variation stock **/
2146
+				$variations = self::get_variation($product_id);
2147
+				if (!empty($variations)) {
2148
+					foreach ($variations as $variation) {
2149
+						if (!empty($variation) && !empty($variation['variation_dif']) && !empty($variation['variation_dif']['product_stock'])) {
2150
+							$productStock += $variation['variation_dif']['product_stock'];
2151
+						}
2152
+					}
2153
+				}
2154
+			}
2155
+
2156
+			$template_part = ($variations_list && ($output_type == 'mini')) ? 'configure_product_button' : (!empty($productStock) ? 'add_to_cart_button' : 'unavailable_product_button');
2157 2157
 						$template_part = apply_filters( 'wps_custom_add_to_cart_button', $template_part, $product_id );
2158 2158
 
2159
-            $tpl_component = array();
2160
-            $tpl_component['PRODUCT_ID'] = $product_id;
2161
-            $tpl_component['PRODUCT_PERMALINK'] = get_permalink($product_id);
2162
-            $tpl_component['PRODUCT_TITLE'] = get_the_title($product_id);
2159
+			$tpl_component = array();
2160
+			$tpl_component['PRODUCT_ID'] = $product_id;
2161
+			$tpl_component['PRODUCT_PERMALINK'] = get_permalink($product_id);
2162
+			$tpl_component['PRODUCT_TITLE'] = get_the_title($product_id);
2163 2163
 
2164
-            /*
2164
+			/*
2165 2165
              * Build template
2166 2166
              */
2167
-            $tpl_way_to_take = wpshop_display::check_way_for_template($template_part);
2168
-            if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) {
2169
-                /*    Include the old way template part    */
2170
-                ob_start();
2171
-                require wpshop_display::get_template_file($tpl_way_to_take[1]);
2172
-                $button = ob_get_contents();
2173
-                ob_end_clean();
2174
-            } else {
2175
-                $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));
2176
-            }
2177
-            unset($tpl_component);
2178
-        }
2179
-        return $button;
2180
-    }
2181
-
2182
-    /**
2183
-     * Allows to get the good button for adding product to a quotation
2184
-     *
2185
-     * @param integer $product_id The product identifier
2186
-     * @param boolean $product_quotation_state The state of the quotation addons
2187
-     *
2188
-     * @return string $button The html output for the button
2189
-     */
2190
-    public static function display_quotation_button($product_id, $product_quotation_state, $output_type = 'mini')
2191
-    {
2192
-        $quotation_button = '';
2193
-
2194
-        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'))) {
2195
-            $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();
2196
-            /**
2197
-             * Template parameters
2198
-             */
2199
-            $template_part = (!empty($variations_list) && ($output_type == 'mini')) ? 'configure_quotation_button' : 'ask_quotation_button';
2200
-            $tpl_component = array();
2201
-            $tpl_component['PRODUCT_ID'] = $product_id;
2202
-            $tpl_component['PRODUCT_PERMALINK'] = get_permalink($product_id);
2203
-            $tpl_component['PRODUCT_TITLE'] = get_the_title($product_id);
2167
+			$tpl_way_to_take = wpshop_display::check_way_for_template($template_part);
2168
+			if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) {
2169
+				/*    Include the old way template part    */
2170
+				ob_start();
2171
+				require wpshop_display::get_template_file($tpl_way_to_take[1]);
2172
+				$button = ob_get_contents();
2173
+				ob_end_clean();
2174
+			} else {
2175
+				$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));
2176
+			}
2177
+			unset($tpl_component);
2178
+		}
2179
+		return $button;
2180
+	}
2204 2181
 
2205
-            /**
2206
-             * Build template
2207
-             */
2208
-            $tpl_way_to_take = wpshop_display::check_way_for_template($template_part);
2209
-            if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) {
2210
-                /*    Include the old way template part    */
2211
-                ob_start();
2212
-                require wpshop_display::get_template_file($tpl_way_to_take[1]);
2213
-                $quotation_button = ob_get_contents();
2214
-                ob_end_clean();
2215
-            } else {
2216
-                $quotation_button = wpshop_display::display_template_element($template_part, $tpl_component);
2217
-            }
2218
-            unset($tpl_component);
2219
-        }
2182
+	/**
2183
+	 * Allows to get the good button for adding product to a quotation
2184
+	 *
2185
+	 * @param integer $product_id The product identifier
2186
+	 * @param boolean $product_quotation_state The state of the quotation addons
2187
+	 *
2188
+	 * @return string $button The html output for the button
2189
+	 */
2190
+	public static function display_quotation_button($product_id, $product_quotation_state, $output_type = 'mini')
2191
+	{
2192
+		$quotation_button = '';
2193
+
2194
+		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'))) {
2195
+			$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();
2196
+			/**
2197
+			 * Template parameters
2198
+			 */
2199
+			$template_part = (!empty($variations_list) && ($output_type == 'mini')) ? 'configure_quotation_button' : 'ask_quotation_button';
2200
+			$tpl_component = array();
2201
+			$tpl_component['PRODUCT_ID'] = $product_id;
2202
+			$tpl_component['PRODUCT_PERMALINK'] = get_permalink($product_id);
2203
+			$tpl_component['PRODUCT_TITLE'] = get_the_title($product_id);
2204
+
2205
+			/**
2206
+			 * Build template
2207
+			 */
2208
+			$tpl_way_to_take = wpshop_display::check_way_for_template($template_part);
2209
+			if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) {
2210
+				/*    Include the old way template part    */
2211
+				ob_start();
2212
+				require wpshop_display::get_template_file($tpl_way_to_take[1]);
2213
+				$quotation_button = ob_get_contents();
2214
+				ob_end_clean();
2215
+			} else {
2216
+				$quotation_button = wpshop_display::display_template_element($template_part, $tpl_component);
2217
+			}
2218
+			unset($tpl_component);
2219
+		}
2220 2220
 
2221
-        return $quotation_button;
2222
-    }
2221
+		return $quotation_button;
2222
+	}
2223 2223
 
2224
-    /**
2225
-     * Return the output for a product attachement gallery (picture or document)
2226
-     *
2227
-     * @param string $attachement_type The type of attachement to output. allows to define with type of template to take
2228
-     * @param string $content The gallery content build previously
2229
-     *
2230
-     * @return string The attachement gallery output
2231
-     */
2232
-    public static function display_attachment_gallery($attachement_type, $content)
2233
-    {
2234
-        $galery_output = '';
2235
-
2236
-        /*
2224
+	/**
2225
+	 * Return the output for a product attachement gallery (picture or document)
2226
+	 *
2227
+	 * @param string $attachement_type The type of attachement to output. allows to define with type of template to take
2228
+	 * @param string $content The gallery content build previously
2229
+	 *
2230
+	 * @return string The attachement gallery output
2231
+	 */
2232
+	public static function display_attachment_gallery($attachement_type, $content)
2233
+	{
2234
+		$galery_output = '';
2235
+
2236
+		/*
2237 2237
          * Get the template part for given galery type
2238 2238
          */
2239
-        switch ($attachement_type) {
2240
-            case 'picture':
2241
-                $template_part = 'product_attachment_picture_galery';
2242
-                break;
2243
-            case 'document':
2244
-                $template_part = 'product_attachment_galery';
2245
-                break;
2246
-        }
2239
+		switch ($attachement_type) {
2240
+			case 'picture':
2241
+				$template_part = 'product_attachment_picture_galery';
2242
+				break;
2243
+			case 'document':
2244
+				$template_part = 'product_attachment_galery';
2245
+				break;
2246
+		}
2247 2247
 
2248
-        /*
2248
+		/*
2249 2249
          * Template parameters
2250 2250
          */
2251
-        $tpl_component = array();
2252
-        $tpl_component['PRODUCT_ATTACHMENT_OUTPUT_CONTENT'] = $content;
2253
-        $tpl_component['ATTACHMENT_ITEM_TYPE'] = $attachement_type;
2251
+		$tpl_component = array();
2252
+		$tpl_component['PRODUCT_ATTACHMENT_OUTPUT_CONTENT'] = $content;
2253
+		$tpl_component['ATTACHMENT_ITEM_TYPE'] = $attachement_type;
2254 2254
 
2255
-        /*
2255
+		/*
2256 2256
          * Build template
2257 2257
          */
2258
-        $tpl_way_to_take = wpshop_display::check_way_for_template($template_part);
2259
-        if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) {
2260
-            /*    Include the old way template part    */
2261
-            ob_start();
2262
-            require wpshop_display::get_template_file($tpl_way_to_take[1]);
2263
-            $galery_output = ob_get_contents();
2264
-            ob_end_clean();
2265
-        } else {
2266
-            $galery_output = wpshop_display::display_template_element($template_part, $tpl_component);
2267
-        }
2268
-        unset($tpl_component);
2258
+		$tpl_way_to_take = wpshop_display::check_way_for_template($template_part);
2259
+		if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) {
2260
+			/*    Include the old way template part    */
2261
+			ob_start();
2262
+			require wpshop_display::get_template_file($tpl_way_to_take[1]);
2263
+			$galery_output = ob_get_contents();
2264
+			ob_end_clean();
2265
+		} else {
2266
+			$galery_output = wpshop_display::display_template_element($template_part, $tpl_component);
2267
+		}
2268
+		unset($tpl_component);
2269 2269
 
2270
-        return $galery_output;
2271
-    }
2270
+		return $galery_output;
2271
+	}
2272 2272
 
2273
-    /**
2274
-     * Define the metabox to display in product edition page in backend
2275
-     * @param object $post The current element displayed for edition
2276
-     */
2277
-    public static function meta_box_variations($post)
2278
-    {
2279
-        $output = '';
2280
-        /*    Variations container    */
2281
-        $tpl_component = array();
2282
-        $tpl_component['ADMIN_VARIATION_CONTAINER'] = self::display_variation_admin($post->ID);
2283
-        $tpl_component['LINK_NEW_INTERFACE'] = wp_nonce_url(get_edit_post_link($post->ID) . '&wps_variation_interface=true', 'wps_remove_variation_interface');
2284
-        $output .= wpshop_display::display_template_element('wpshop_admin_variation_metabox', $tpl_component, array(), 'admin');
2285
-        echo '<span class="wpshop_loading_ wpshopHide" ><img src="' . admin_url('images/loading.gif') . '" alt="loading picture" /></span>' . $output . '<div class="wpshop_cls" ></div>';
2286
-    }
2273
+	/**
2274
+	 * Define the metabox to display in product edition page in backend
2275
+	 * @param object $post The current element displayed for edition
2276
+	 */
2277
+	public static function meta_box_variations($post)
2278
+	{
2279
+		$output = '';
2280
+		/*    Variations container    */
2281
+		$tpl_component = array();
2282
+		$tpl_component['ADMIN_VARIATION_CONTAINER'] = self::display_variation_admin($post->ID);
2283
+		$tpl_component['LINK_NEW_INTERFACE'] = wp_nonce_url(get_edit_post_link($post->ID) . '&wps_variation_interface=true', 'wps_remove_variation_interface');
2284
+		$output .= wpshop_display::display_template_element('wpshop_admin_variation_metabox', $tpl_component, array(), 'admin');
2285
+		echo '<span class="wpshop_loading_ wpshopHide" ><img src="' . admin_url('images/loading.gif') . '" alt="loading picture" /></span>' . $output . '<div class="wpshop_cls" ></div>';
2286
+	}
2287 2287
 
2288
-    /**
2289
-     * Call variation creation function with a list of defined variation
2290
-     *
2291
-     * @param array $possible_variations A list of variation to create for the current element
2292
-     * @param integer $element_id The product we want to create variation for
2293
-     *
2294
-     * @return mixed The last created variation identifier
2295
-     */
2296
-    public static function creation_variation_callback($possible_variations, $element_id)
2297
-    {
2298
-        /** Get existing variation    */
2299
-        $existing_variations_in_db = wpshop_products::get_variation($element_id);
2300
-        $existing_variations = array();
2301
-        if (!empty($existing_variations_in_db)) {
2302
-            foreach ($existing_variations_in_db as $variations_def) {
2303
-                $existing_variations[] = $variations_def['variation_def'];
2304
-            }
2305
-        }
2306
-        /** New variation definition    */
2307
-        $attribute_defining_variation = get_post_meta($element_id, '_wpshop_variation_defining', true);
2308
-
2309
-        /**    Read possible values    */
2310
-        foreach ($possible_variations as $variation_definition) {
2311
-            if (in_array($variation_definition, $existing_variations)) {
2312
-                continue;
2313
-            }
2314
-
2315
-            $attribute_to_set = array();
2316
-            foreach ($variation_definition as $attribute_code => $attribute_selected_value) {
2317
-                $attribute = wpshop_attributes::getElement($attribute_code, "'valid'", 'code');
2318
-                $attribute_to_set[$attribute->data_type][$attribute_code] = $attribute_selected_value;
2319
-                if (empty($attribute_defining_variation['attributes']) || (!in_array($attribute_code, $attribute_defining_variation['attributes']))) {
2320
-                    $attribute_defining_variation['attributes'][] = $attribute_code;
2321
-                }
2322
-            }
2323
-            $variation_id = wpshop_products::create_variation($element_id, $attribute_to_set);
2324
-        }
2325
-        update_post_meta($element_id, '_wpshop_variation_defining', $attribute_defining_variation);
2288
+	/**
2289
+	 * Call variation creation function with a list of defined variation
2290
+	 *
2291
+	 * @param array $possible_variations A list of variation to create for the current element
2292
+	 * @param integer $element_id The product we want to create variation for
2293
+	 *
2294
+	 * @return mixed The last created variation identifier
2295
+	 */
2296
+	public static function creation_variation_callback($possible_variations, $element_id)
2297
+	{
2298
+		/** Get existing variation    */
2299
+		$existing_variations_in_db = wpshop_products::get_variation($element_id);
2300
+		$existing_variations = array();
2301
+		if (!empty($existing_variations_in_db)) {
2302
+			foreach ($existing_variations_in_db as $variations_def) {
2303
+				$existing_variations[] = $variations_def['variation_def'];
2304
+			}
2305
+		}
2306
+		/** New variation definition    */
2307
+		$attribute_defining_variation = get_post_meta($element_id, '_wpshop_variation_defining', true);
2326 2308
 
2327
-        return !empty($variation_id) ? $variation_id : 0;
2328
-    }
2309
+		/**    Read possible values    */
2310
+		foreach ($possible_variations as $variation_definition) {
2311
+			if (in_array($variation_definition, $existing_variations)) {
2312
+				continue;
2313
+			}
2329 2314
 
2330
-    /**
2331
-     * Create a new variation for product
2332
-     *
2333
-     * @param integer $head_product The product identifier to create the new variation for
2334
-     * @param array $variation_attributes Attribute list for the variation
2335
-     *
2336
-     * @return mixed <number, WP_Error> The variation identifier or an error in case the creation was not succesfull
2337
-     */
2338
-    public static function create_variation($head_product, $variation_attributes)
2339
-    {
2340
-        /** Create custom title */
2341
-        $title_variation = "";
2342
-        if (!empty($variation_attributes)) {
2343
-            foreach ($variation_attributes as $type => $array) {
2344
-                if (!empty($array)) {
2345
-                    foreach ($array as $code => $value) {
2346
-                        $title_variation .= " " . $code . " " . $value;
2347
-                    }
2348
-                }
2349
-            }
2350
-        }
2315
+			$attribute_to_set = array();
2316
+			foreach ($variation_definition as $attribute_code => $attribute_selected_value) {
2317
+				$attribute = wpshop_attributes::getElement($attribute_code, "'valid'", 'code');
2318
+				$attribute_to_set[$attribute->data_type][$attribute_code] = $attribute_selected_value;
2319
+				if (empty($attribute_defining_variation['attributes']) || (!in_array($attribute_code, $attribute_defining_variation['attributes']))) {
2320
+					$attribute_defining_variation['attributes'][] = $attribute_code;
2321
+				}
2322
+			}
2323
+			$variation_id = wpshop_products::create_variation($element_id, $attribute_to_set);
2324
+		}
2325
+		update_post_meta($element_id, '_wpshop_variation_defining', $attribute_defining_variation);
2351 2326
 
2352
-        $variation = array(
2353
-            'post_title' => sprintf(__('Product %s variation %s', 'wpshop'), $head_product, get_the_title($head_product)) . $title_variation,
2354
-            'post_content' => '',
2355
-            'post_status' => 'publish',
2356
-            'post_author' => get_current_user_id(),
2357
-            'post_parent' => $head_product,
2358
-            'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION,
2359
-        );
2360
-        $variation_id = wp_insert_post($variation);
2361
-
2362
-        wpshop_attributes::saveAttributeForEntity($variation_attributes, wpshop_entities::get_entity_identifier_from_code(wpshop_products::currentPageCode), $variation_id, WPSHOP_CURRENT_LOCALE, '');
2363
-
2364
-        /*    Update product price looking for shop parameters    */
2365
-        wpshop_products::calculate_price($variation_id);
2366
-
2367
-        /*    Save the attributes values into wordpress post metadata database in order to have a backup and to make frontend search working    */
2368
-        $productMetaDatas = array();
2369
-        foreach ($variation_attributes as $attributeType => $attributeValues) {
2370
-            foreach ($attributeValues as $attributeCode => $attributeValue) {
2371
-                if (!empty($attributeValue)) {
2372
-                    $productMetaDatas[$attributeCode] = $attributeValue;
2373
-                }
2374
-            }
2375
-        }
2376
-        update_post_meta($variation_id, '_wpshop_variations_attribute_def', $productMetaDatas);
2377
-        update_post_meta($variation_id, WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, $productMetaDatas);
2378
-        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));
2327
+		return !empty($variation_id) ? $variation_id : 0;
2328
+	}
2379 2329
 
2380
-        return $variation_id;
2381
-    }
2330
+	/**
2331
+	 * Create a new variation for product
2332
+	 *
2333
+	 * @param integer $head_product The product identifier to create the new variation for
2334
+	 * @param array $variation_attributes Attribute list for the variation
2335
+	 *
2336
+	 * @return mixed <number, WP_Error> The variation identifier or an error in case the creation was not succesfull
2337
+	 */
2338
+	public static function create_variation($head_product, $variation_attributes)
2339
+	{
2340
+		/** Create custom title */
2341
+		$title_variation = "";
2342
+		if (!empty($variation_attributes)) {
2343
+			foreach ($variation_attributes as $type => $array) {
2344
+				if (!empty($array)) {
2345
+					foreach ($array as $code => $value) {
2346
+						$title_variation .= " " . $code . " " . $value;
2347
+					}
2348
+				}
2349
+			}
2350
+		}
2382 2351
 
2383
-    /**
2384
-     * Get variation list for a given product
2385
-     *
2386
-     * @param integer $head_product The product identifier to get the variation for
2387
-     * @return object The variation list
2388
-     */
2389
-    public static function get_variation($head_product)
2390
-    {
2391
-        global $wpdb;
2392
-        $variations_output = null;
2393
-        $args = array(
2394
-            'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION,
2395
-            'post_parent' => $head_product,
2396
-            'orderby' => 'ID',
2397
-            'order' => 'ASC',
2398
-            'posts_per_page' => -1,
2399
-            'post_status' => 'any',
2400
-        );
2401
-        $variations = get_posts($args);
2402
-
2403
-        if (!empty($variations)) {
2404
-            $head_wpshop_variation_definition = get_post_meta($head_product, '_wpshop_variation_defining', true);
2405
-
2406
-            foreach ($variations as $post_def) {
2407
-                $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'");
2408
-                foreach ($data as $content) {
2409
-                    $attribute_value = 'attribute_value_' . $content->data_type;
2410
-                    if (!empty($content->$attribute_value)) {
2411
-                        if (!empty($head_wpshop_variation_definition['attributes']) && in_array($content->code, $head_wpshop_variation_definition['attributes'])) {
2412
-                            $variations_output[$post_def->ID]['variation_def'][$content->code] = $content->$attribute_value;
2413
-                        } else {
2414
-                            $variations_output[$post_def->ID]['variation_dif'][$content->code] = $content->$attribute_value;
2415
-                        }
2416
-                    }
2417
-                }
2418
-                $variations_output[$post_def->ID]['post'] = $post_def;
2419
-            }
2420
-        }
2421
-        wp_reset_query();
2422
-        return $variations_output;
2423
-    }
2352
+		$variation = array(
2353
+			'post_title' => sprintf(__('Product %s variation %s', 'wpshop'), $head_product, get_the_title($head_product)) . $title_variation,
2354
+			'post_content' => '',
2355
+			'post_status' => 'publish',
2356
+			'post_author' => get_current_user_id(),
2357
+			'post_parent' => $head_product,
2358
+			'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION,
2359
+		);
2360
+		$variation_id = wp_insert_post($variation);
2361
+
2362
+		wpshop_attributes::saveAttributeForEntity($variation_attributes, wpshop_entities::get_entity_identifier_from_code(wpshop_products::currentPageCode), $variation_id, WPSHOP_CURRENT_LOCALE, '');
2363
+
2364
+		/*    Update product price looking for shop parameters    */
2365
+		wpshop_products::calculate_price($variation_id);
2366
+
2367
+		/*    Save the attributes values into wordpress post metadata database in order to have a backup and to make frontend search working    */
2368
+		$productMetaDatas = array();
2369
+		foreach ($variation_attributes as $attributeType => $attributeValues) {
2370
+			foreach ($attributeValues as $attributeCode => $attributeValue) {
2371
+				if (!empty($attributeValue)) {
2372
+					$productMetaDatas[$attributeCode] = $attributeValue;
2373
+				}
2374
+			}
2375
+		}
2376
+		update_post_meta($variation_id, '_wpshop_variations_attribute_def', $productMetaDatas);
2377
+		update_post_meta($variation_id, WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, $productMetaDatas);
2378
+		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));
2424 2379
 
2425
-    /**
2426
-     * Affichage des variations d'un produit dans l'administration
2427
-     *
2428
-     * @param integer $head_product L'identifiant du produit dont on veut afficher les variations
2429
-     * @return string Le code html permettant l'affichage des variations dans l'interface d'édition du produit
2430
-     */
2431
-    public static function display_variation_admin($head_product)
2432
-    {
2433
-        $output = '';
2434
-        $productCurrency = wpshop_tools::wpshop_get_currency();
2435
-        /*    Récupération de la liste des variations pour le produit en cours d'édition    */
2436
-        $variations = self::get_variation($head_product);
2437
-        $price_piloting = get_option('wpshop_shop_price_piloting');
2438
-
2439
-        /*    Affichage de la liste des variations pour le produit en cours d'édition    */
2440
-        if (!empty($variations) && is_array($variations)) {
2441
-            $existing_variation_list = wpshop_display::display_template_element('wpshop_admin_existing_variation_controller', array(), array(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT => $head_product), 'admin');
2442
-
2443
-            foreach ($variations as $variation) {
2444
-                $tpl_component = array();
2445
-
2446
-                $tpl_component['ADMIN_EXISTING_VARIATIONS_CLASS'] = ' wpshop_variation_' . self::currentPageCode;
2447
-                $tpl_component['VARIATION_IDENTIFIER'] = $variation['post']->ID;
2448
-                $tpl_component['VARIATION_DETAIL'] = '  ';
2449
-                $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;
2450
-                $tpl_component['VARIATION_DETAIL_PRICE'] = number_format($p, 2, '.', '') . ' ' . $productCurrency . ' ' . ((!empty($price_piloting) && $price_piloting == 'HT') ? __('ET', 'wpshop') : __('ATI', 'wpshop'));
2451
-                if (!empty($price_piloting) && $price_piloting == 'HT') {
2452
-
2453
-                } else {
2454
-
2455
-                }
2456
-                $post_obj = $variation['post'];
2457
-
2458
-                $parent_product_infos = wpshop_products::get_parent_variation($post_obj->ID);
2459
-                if (!empty($parent_product_infos)) {
2460
-                    $parent_post = $parent_product_infos['parent_post'];
2461
-                    $product_option_postmeta = get_post_meta($parent_post->ID, '_wpshop_variation_defining', true);
2462
-                    if (!empty($product_option_postmeta['options']['price_behaviour']) && !empty($product_option_postmeta['options']['price_behaviour'][0]) && $product_option_postmeta['options']['price_behaviour'][0] == 'addition') {
2463
-                        if (!empty($price_piloting) && $price_piloting == 'HT') {
2464
-                            $product_price = ((!empty($variation['variation_dif']['price_ht'])) ? $variation['variation_dif']['price_ht'] : 0) + $parent_product_infos['parent_post_meta']['price_ht'];
2465
-                        } else {
2466
-                            $product_price = ((!empty($variation['variation_dif']['product_price'])) ? $variation['variation_dif']['product_price'] : 0) + $parent_product_infos['parent_post_meta']['product_price'];
2467
-                        }
2468
-                        $tpl_component['VARIATION_DETAIL_SALE_PRICE_INDICATION'] = __('Variation price combined with the parent product price', 'wpshop');
2469
-                    } else {
2470
-                        if (!empty($price_piloting) && $price_piloting == 'HT') {
2471
-                            $product_price = (!empty($variation['variation_dif']['price_ht'])) ? $variation['variation_dif']['price_ht'] : 0;
2472
-                        } else {
2473
-                            $product_price = (!empty($variation['variation_dif']['product_price'])) ? $variation['variation_dif']['product_price'] : 0;
2474
-                        }
2475
-                        $tpl_component['VARIATION_DETAIL_SALE_PRICE_INDICATION'] = __('Only variation\'s price is used', 'wpshop');
2476
-                    }
2477
-                    $product_price = number_format(str_replace(',', '.', $product_price), 2, '.', '') . ' ' . $productCurrency . ' ' . ((!empty($price_piloting) && $price_piloting == 'HT') ? __('ET', 'wpshop') : __('ATI', 'wpshop'));
2478
-                    $tpl_component['VARIATION_DETAIL_SALE_PRICE'] = $product_price;
2479
-                }
2480
-
2481
-                if (!empty($variation['variation_def'])) {
2482
-                    foreach ($variation['variation_def'] as $variation_key => $variation_value) {
2483
-                        if (!empty($variation_value)) {
2484
-                            $attribute_def_for_variation = wpshop_attributes::getElement($variation_key, "'valid'", 'code');
2485
-                            $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');
2486
-                            $tpl_component['VARIATION_IMAGE_CHOICE'] = '';
2487
-
2488
-                            /** Define Link image to variation interface **/
2489
-                            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'))) {
2490
-                                $pictures = get_posts(array('post_type' => 'attachment', 'posts_per_page' => -1, 'post_status' => null, 'post_parent' => $head_product));
2491
-
2492
-                                $media_id_data = get_post_meta($head_product, '_wps_product_media', true);
2493
-                                if (!empty($media_id_data)) {
2494
-                                    $medias_ids = explode(',', $media_id_data);
2495
-
2496
-                                    if (!empty($medias_ids)) {
2497
-                                        foreach ($medias_ids as $media_id) {
2498
-                                            if (!empty($media_id)) {
2499
-                                                $pictures[] = get_post($media_id);
2500
-                                            }
2501
-                                        }
2502
-                                    }
2503
-                                }
2504
-
2505
-                                $pictures_data = '';
2506
-                                if (!empty($pictures)) {
2507
-                                    $selected_picture = get_post_meta($variation['post']->ID, '_wps_variation_attached_picture', true);
2508
-
2509
-                                    $done_picture = array();
2510
-                                    foreach ($pictures as $picture) {
2511
-                                        if (!in_array($picture->ID, $done_picture)) {
2512
-                                            if (wp_attachment_is_image($picture->ID)) {
2513
-                                                $checked = ((!empty($selected_picture) && $selected_picture == $picture->ID) ? 'checked="checked"' : '');
2514
-                                                $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');
2515
-
2516
-                                                $done_picture[] = $picture->ID;
2517
-                                            }
2518
-                                        }
2519
-                                    }
2520
-                                }
2521
-
2522
-                                $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');
2523
-                            }
2524
-
2525
-                        }
2526
-                    }
2527
-                }
2528
-
2529
-                $tpl_component['VARIATION_DETAIL'] = substr($tpl_component['VARIATION_DETAIL'], 0, -2);
2530
-
2531
-                $tpl_component['ADMIN_VARIATION_SPECIFIC_DEFINITION_CONTAINER_CLASS'] = ' wpshopHide';
2532
-                $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())));
2533
-                $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');
2534
-
2535
-                /*    Add the variation definition to output    */
2536
-                $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');
2537
-            }
2538
-
2539
-            $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');
2540
-            /*    Reset de la liste des résultats pour éviter les comportements indésirables    */
2541
-            wp_reset_query();
2542
-        } else {
2543
-            $output = __('No variation found for this product. Please use button above for create one', 'wpshop');
2544
-        }
2380
+		return $variation_id;
2381
+	}
2545 2382
 
2546
-        return $output;
2547
-    }
2383
+	/**
2384
+	 * Get variation list for a given product
2385
+	 *
2386
+	 * @param integer $head_product The product identifier to get the variation for
2387
+	 * @return object The variation list
2388
+	 */
2389
+	public static function get_variation($head_product)
2390
+	{
2391
+		global $wpdb;
2392
+		$variations_output = null;
2393
+		$args = array(
2394
+			'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION,
2395
+			'post_parent' => $head_product,
2396
+			'orderby' => 'ID',
2397
+			'order' => 'ASC',
2398
+			'posts_per_page' => -1,
2399
+			'post_status' => 'any',
2400
+		);
2401
+		$variations = get_posts($args);
2402
+
2403
+		if (!empty($variations)) {
2404
+			$head_wpshop_variation_definition = get_post_meta($head_product, '_wpshop_variation_defining', true);
2405
+
2406
+			foreach ($variations as $post_def) {
2407
+				$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'");
2408
+				foreach ($data as $content) {
2409
+					$attribute_value = 'attribute_value_' . $content->data_type;
2410
+					if (!empty($content->$attribute_value)) {
2411
+						if (!empty($head_wpshop_variation_definition['attributes']) && in_array($content->code, $head_wpshop_variation_definition['attributes'])) {
2412
+							$variations_output[$post_def->ID]['variation_def'][$content->code] = $content->$attribute_value;
2413
+						} else {
2414
+							$variations_output[$post_def->ID]['variation_dif'][$content->code] = $content->$attribute_value;
2415
+						}
2416
+					}
2417
+				}
2418
+				$variations_output[$post_def->ID]['post'] = $post_def;
2419
+			}
2420
+		}
2421
+		wp_reset_query();
2422
+		return $variations_output;
2423
+	}
2548 2424
 
2549
-    /**
2550
-     * Retrieve and display the variation for a given product
2551
-     * @param integer $product_id The product identifier to get variation for
2552
-     */
2553
-    public static function wpshop_variation($post_id = '', $from_admin = false, $order_id = '', $qty = 1)
2554
-    {
2555
-        global $wp_query;
2556
-        $output = '';
2557
-
2558
-        $product_id = empty($post_id) ? $wp_query->post->ID : $post_id;
2559
-        $wpshop_product_attributes_frontend_display = get_post_meta($product_id, '_wpshop_product_attributes_frontend_display', true);
2560
-        $head_wpshop_variation_definition = get_post_meta($product_id, '_wpshop_variation_defining', true);
2561
-
2562
-        /**    Get attribute order for current product    */
2563
-        $product_attribute_order_detail = wpshop_attributes_set::getAttributeSetDetails(get_post_meta($product_id, WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, true));
2564
-        $output_order = array();
2565
-        if (count($product_attribute_order_detail) > 0) {
2566
-            if (!empty($product_attribute_order_detail)) {
2567
-                foreach ($product_attribute_order_detail as $product_attr_group_id => $product_attr_group_detail) {
2568
-                    foreach ($product_attr_group_detail['attribut'] as $position => $attribute_def) {
2569
-                        if (!empty($attribute_def->code)) {
2570
-                            $output_order[$attribute_def->code] = $position;
2571
-                        }
2572
-
2573
-                    }
2574
-                }
2575
-            }
2576
-        }
2425
+	/**
2426
+	 * Affichage des variations d'un produit dans l'administration
2427
+	 *
2428
+	 * @param integer $head_product L'identifiant du produit dont on veut afficher les variations
2429
+	 * @return string Le code html permettant l'affichage des variations dans l'interface d'édition du produit
2430
+	 */
2431
+	public static function display_variation_admin($head_product)
2432
+	{
2433
+		$output = '';
2434
+		$productCurrency = wpshop_tools::wpshop_get_currency();
2435
+		/*    Récupération de la liste des variations pour le produit en cours d'édition    */
2436
+		$variations = self::get_variation($head_product);
2437
+		$price_piloting = get_option('wpshop_shop_price_piloting');
2438
+
2439
+		/*    Affichage de la liste des variations pour le produit en cours d'édition    */
2440
+		if (!empty($variations) && is_array($variations)) {
2441
+			$existing_variation_list = wpshop_display::display_template_element('wpshop_admin_existing_variation_controller', array(), array(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT => $head_product), 'admin');
2442
+
2443
+			foreach ($variations as $variation) {
2444
+				$tpl_component = array();
2445
+
2446
+				$tpl_component['ADMIN_EXISTING_VARIATIONS_CLASS'] = ' wpshop_variation_' . self::currentPageCode;
2447
+				$tpl_component['VARIATION_IDENTIFIER'] = $variation['post']->ID;
2448
+				$tpl_component['VARIATION_DETAIL'] = '  ';
2449
+				$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;
2450
+				$tpl_component['VARIATION_DETAIL_PRICE'] = number_format($p, 2, '.', '') . ' ' . $productCurrency . ' ' . ((!empty($price_piloting) && $price_piloting == 'HT') ? __('ET', 'wpshop') : __('ATI', 'wpshop'));
2451
+				if (!empty($price_piloting) && $price_piloting == 'HT') {
2452
+
2453
+				} else {
2577 2454
 
2578
-        $variations_params = array();
2579
-        $variation_attribute = array();
2580
-        $variation_attribute_ordered = array();
2581
-        $possible_values = array();
2582
-        $possible_values_for_selection_calculation = array();
2583
-
2584
-        /*    Vérification de l'existence de déclinaison pour le produit    */
2585
-        $wpshop_variation_list = self::get_variation($product_id);
2586
-        if (!empty($wpshop_variation_list)) {
2587
-            foreach ($wpshop_variation_list as $variation) {
2588
-                if (!empty($variation['variation_def'])) {
2589
-                    $display_option = get_post_meta($post_id, '_wpshop_product_attributes_frontend_display', true);
2590
-                    foreach ($variation['variation_def'] as $attribute_code => $attribute_value) {
2591
-                        if (empty($display_option) || (!empty($display_option['attribute']) && !empty($display_option['attribute'][$attribute_code]) && !empty($display_option['attribute'][$attribute_code]['complete_sheet']))) {
2592
-                            $tpl_component = array();
2593
-
2594
-                            $attribute_db_definition = wpshop_attributes::getElement($attribute_code, "'valid'", 'code');
2595
-                            $default_value_is_serial = false;
2596
-                            $attribute_list_first_element = $attribute_db_definition->default_value;
2597
-                            if (!empty($attribute_db_definition->default_value) && ($attribute_db_definition->default_value == serialize(false) || wpshop_tools::is_serialized($attribute_db_definition->default_value))) {
2598
-                                $default_value_is_serial = true;
2599
-                                $tmp_default_value = unserialize($attribute_db_definition->default_value);
2600
-                                $attribute_list_first_element = !empty($tmp_default_value['field_options']['label_for_first_item']) ? $tmp_default_value['field_options']['label_for_first_item'] : null;
2601
-                            }
2602
-
2603
-                            if ($default_value_is_serial && !empty($attribute_list_first_element) && ($attribute_list_first_element != 'none')) {
2604
-                                $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');
2605
-                            }
2606
-
2607
-                            if (!empty($attribute_value) && ($attribute_db_definition->data_type_to_use == 'custom')) {
2608
-                                $tpl_component['VARIATION_VALUE'] = stripslashes(wpshop_attributes::get_attribute_type_select_option_info($attribute_value, 'label', 'custom'));
2609
-                                $position = wpshop_attributes::get_attribute_type_select_option_info($attribute_value, 'position', 'custom');
2610
-                            } else if (!empty($attribute_value) && ($attribute_db_definition->data_type_to_use == 'internal')) {
2611
-                                $post_def = get_post($attribute_value);
2612
-                                $tpl_component['VARIATION_VALUE'] = stripslashes($post_def->post_title);
2613
-                                $position = $post_def->menu_order;
2614
-                            }
2615
-
2616
-                            if (!empty($variation['variation_dif'])) {
2617
-                                foreach ($variation['variation_dif'] as $attribute_dif_code => $attribute_dif_value) {
2618
-                                    $wpshop_prices_attributes = unserialize(WPSHOP_ATTRIBUTE_PRICES);
2619
-                                    $the_value = $attribute_dif_value;
2620
-                                    if (in_array($attribute_dif_code, $wpshop_prices_attributes)) {
2621
-                                        $the_value = wpshop_display::format_field_output('wpshop_product_price', $attribute_dif_value);
2622
-                                    }
2623
-                                    $tpl_component['VARIATION_DIF_' . strtoupper($attribute_dif_code)] = stripslashes($the_value);
2624
-                                }
2625
-                            }
2626
-                            if (!empty($attribute_value)) {
2627
-                                $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));
2628
-                                $possible_values_for_selection_calculation[$attribute_code][$attribute_value] = $tpl_component['VARIATION_VALUE'];
2629
-                            }
2630
-                            unset($tpl_component);
2631
-                        }
2632
-                    }
2633
-                }
2634
-            }
2635
-
2636
-            $variation_tpl = array();
2637
-            if (!empty($head_wpshop_variation_definition['attributes'])) {
2638
-                foreach ($head_wpshop_variation_definition['attributes'] as $attribute_code) {
2639
-                    $attribute_db_definition = wpshop_attributes::getElement($attribute_code, "'valid'", 'code');
2640
-
2641
-                    if (!empty($attribute_db_definition)) {
2642
-                        $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');
2643
-
2644
-                        $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;
2645
-                        if (!$is_required && $attribute_db_definition->is_required == 'yes') {
2646
-                            $is_required = true;
2647
-                        }
2648
-
2649
-                        $input_def = array();
2650
-                        $input_def['type'] = $attribute_db_definition->frontend_input;
2651
-                        $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);
2652
-                        if (in_array($attribute_db_definition->frontend_input, array('radio', 'checkbox'))) {
2653
-                            unset($possible_values[$attribute_code][0]);
2654
-                            $value = array($value);
2655
-                        }
2656
-                        $input_def['id'] = 'wpshop_variation_attr_' . $attribute_code;
2657
-                        $input_def['name'] = $attribute_code;
2658
-                        $real_possible_values = array();
2659
-                        if (!empty($possible_values[$attribute_code])) {
2660
-                            ksort($possible_values[$attribute_code]);
2661
-                            foreach ($possible_values[$attribute_code] as $position => $def) {
2662
-                                foreach ($def as $attribute_value => $attribute_value_output) {
2663
-                                    $real_possible_values[$attribute_value] = $attribute_value_output;
2664
-                                    if (!empty($attribute_value)) {
2665
-                                        global $wpdb;
2666
-                                        $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);
2667
-                                        if ('draft' == $wpdb->get_var($query)) {
2668
-                                            unset($real_possible_values[$attribute_value]);
2669
-                                        }
2670
-                                    }
2671
-                                }
2672
-                            }
2673
-                        }
2674
-                        $input_def['possible_value'] = $real_possible_values;
2675
-                        $input_def['valueToPut'] = 'index';
2676
-                        $input_def['value'] = $value;
2677
-
2678
-                        $input_def['options']['more_input'] = '';
2679
-                        if (!empty($possible_values_for_selection_calculation[$attribute_code])) {
2680
-                            foreach ($possible_values_for_selection_calculation[$attribute_code] as $value_id => $value) {
2681
-                                $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 . '" />';
2682
-                            }
2683
-                        }
2684
-
2685
-                        $input_def['options_label']['original'] = true;
2686
-                        $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) . '" ';
2687
-
2688
-                        if (!empty($real_possible_values)) {
2689
-                            $tpl_component = array();
2690
-                            $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'];
2691
-                            $tpl_component['VARIATION_INPUT'] = wpshop_form::check_input_type($input_def, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) . $input_def['options']['more_input'];
2692
-                            $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));
2693
-                            $tpl_component['VARIATION_CODE'] = $attribute_code;
2694
-                            $tpl_component['VARIATION_LABEL_HELPER'] = !empty($attribute_db_definition->frontend_help_message) ? ' title="' . $attribute_db_definition->frontend_help_message . '" ' : '';
2695
-                            $tpl_component['VARIATION_LABEL_CLASS'] = !empty($attribute_db_definition->frontend_help_message) ? ' wpshop_att_variation_helper' : '';
2696
-                            $tpl_component['VARIATION_IDENTIFIER'] = $input_def['id'];
2697
-                            $tpl_component['VARIATION_PARENT_ID'] = $product_id;
2698
-                            $tpl_component['VARIATION_PARENT_TYPE'] = WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT;
2699
-                            $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;
2700
-                            $tpl_component['VARIATION_REQUIRED_INDICATION'] = ($is_required) ? __('Required variation', 'wpshop') : '';
2701
-                            $variation_tpl['VARIATION_COMPLETE_OUTPUT_' . strtoupper($attribute_code)] = wpshop_display::display_template_element('product_variation_item', $tpl_component);
2702
-                            $variation_attribute_ordered[$output_order[$attribute_code]] = $variation_tpl['VARIATION_COMPLETE_OUTPUT_' . strtoupper($attribute_code)];
2703
-                        }
2704
-
2705
-                        $variation_attribute[] = $attribute_code;
2706
-                    }
2707
-                }
2708
-            }
2455
+				}
2456
+				$post_obj = $variation['post'];
2457
+
2458
+				$parent_product_infos = wpshop_products::get_parent_variation($post_obj->ID);
2459
+				if (!empty($parent_product_infos)) {
2460
+					$parent_post = $parent_product_infos['parent_post'];
2461
+					$product_option_postmeta = get_post_meta($parent_post->ID, '_wpshop_variation_defining', true);
2462
+					if (!empty($product_option_postmeta['options']['price_behaviour']) && !empty($product_option_postmeta['options']['price_behaviour'][0]) && $product_option_postmeta['options']['price_behaviour'][0] == 'addition') {
2463
+						if (!empty($price_piloting) && $price_piloting == 'HT') {
2464
+							$product_price = ((!empty($variation['variation_dif']['price_ht'])) ? $variation['variation_dif']['price_ht'] : 0) + $parent_product_infos['parent_post_meta']['price_ht'];
2465
+						} else {
2466
+							$product_price = ((!empty($variation['variation_dif']['product_price'])) ? $variation['variation_dif']['product_price'] : 0) + $parent_product_infos['parent_post_meta']['product_price'];
2467
+						}
2468
+						$tpl_component['VARIATION_DETAIL_SALE_PRICE_INDICATION'] = __('Variation price combined with the parent product price', 'wpshop');
2469
+					} else {
2470
+						if (!empty($price_piloting) && $price_piloting == 'HT') {
2471
+							$product_price = (!empty($variation['variation_dif']['price_ht'])) ? $variation['variation_dif']['price_ht'] : 0;
2472
+						} else {
2473
+							$product_price = (!empty($variation['variation_dif']['product_price'])) ? $variation['variation_dif']['product_price'] : 0;
2474
+						}
2475
+						$tpl_component['VARIATION_DETAIL_SALE_PRICE_INDICATION'] = __('Only variation\'s price is used', 'wpshop');
2476
+					}
2477
+					$product_price = number_format(str_replace(',', '.', $product_price), 2, '.', '') . ' ' . $productCurrency . ' ' . ((!empty($price_piloting) && $price_piloting == 'HT') ? __('ET', 'wpshop') : __('ATI', 'wpshop'));
2478
+					$tpl_component['VARIATION_DETAIL_SALE_PRICE'] = $product_price;
2479
+				}
2709 2480
 
2710
-        }
2711
-        $variation_tpl['VARIATION_FORM_ELEMENT_ID'] = $product_id;
2712
-        wp_reset_query();
2713
-
2714
-        $attribute_defined_to_be_user_defined = wpshop_attributes::get_attribute_user_defined(array('entity_type_id' => self::currentPageCode));
2715
-        if (!empty($attribute_defined_to_be_user_defined)) {
2716
-            foreach ($attribute_defined_to_be_user_defined as $attribute_not_in_variation_but_user_defined) {
2717
-                $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;
2718
-
2719
-                $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');
2720
-                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')) {
2721
-                    $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] : ''));
2722
-
2723
-                    $tpl_component = array();
2724
-                    $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) . '" ';
2725
-                    $tpl_component['VARIATION_INPUT'] = wpshop_form::check_input_type($attribute_output_def, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION . '[free]') . $attribute_output_def['options'];
2726
-                    $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));
2727
-                    $tpl_component['VARIATION_CODE'] = $attribute_not_in_variation_but_user_defined->code;
2728
-                    $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 . '" ' : '';
2729
-                    $tpl_component['VARIATION_LABEL_CLASS'] = !empty($attribute_not_in_variation_but_user_defined->frontend_help_message) ? ' wpshop_att_variation_helper' : '';
2730
-                    $tpl_component['VARIATION_REQUIRED_INDICATION'] = ($is_required) ? __('Required variation', 'wpshop') : '';
2731
-                    $tpl_component['VARIATION_IDENTIFIER'] = $attribute_output_def['id'];
2732
-                    $tpl_component['VARIATION_PARENT_ID'] = $product_id;
2733
-                    $tpl_component['VARIATION_PARENT_TYPE'] = WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT;
2734
-                    $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;
2735
-                    $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'];
2736
-                    $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)];
2737
-                }
2738
-            }
2739
-        }
2740
-        $variation_tpl['VARIATION_FORM_VARIATION_LIST'] = '';
2741
-        if (!empty($variation_attribute_ordered) && is_array($variation_attribute_ordered)) {
2742
-            ksort($variation_attribute_ordered);
2743
-            foreach ($variation_attribute_ordered as $attribute_variation_to_output) {
2744
-                $variation_tpl['VARIATION_FORM_VARIATION_LIST'] .= $attribute_variation_to_output;
2745
-            }
2746
-        }
2747
-        $variation_tpl['FROM_ADMIN_INDICATOR'] = $variation_tpl['ORDER_ID_INDICATOR'] = '';
2748
-        $variation_tpl['PRODUCT_ADDED_TO_CART_QTY'] = (!empty($qty)) ? $qty : 1;
2749
-        if ($from_admin && !empty($order_id)) {
2750
-            $variation_tpl['FROM_ADMIN_INDICATOR'] = '<input type="hidden" name="wps_orders_from_admin" value="1" />';
2751
-            $variation_tpl['ORDER_ID_INDICATOR'] = '<input type="hidden" name="wps_orders_order_id" value="' . $order_id . '" />';
2752
-        }
2753
-        $output = !empty($variation_tpl['VARIATION_FORM_VARIATION_LIST']) ? wpshop_display::display_template_element('product_variation_form', $variation_tpl) : '';
2481
+				if (!empty($variation['variation_def'])) {
2482
+					foreach ($variation['variation_def'] as $variation_key => $variation_value) {
2483
+						if (!empty($variation_value)) {
2484
+							$attribute_def_for_variation = wpshop_attributes::getElement($variation_key, "'valid'", 'code');
2485
+							$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');
2486
+							$tpl_component['VARIATION_IMAGE_CHOICE'] = '';
2487
+
2488
+							/** Define Link image to variation interface **/
2489
+							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'))) {
2490
+								$pictures = get_posts(array('post_type' => 'attachment', 'posts_per_page' => -1, 'post_status' => null, 'post_parent' => $head_product));
2491
+
2492
+								$media_id_data = get_post_meta($head_product, '_wps_product_media', true);
2493
+								if (!empty($media_id_data)) {
2494
+									$medias_ids = explode(',', $media_id_data);
2495
+
2496
+									if (!empty($medias_ids)) {
2497
+										foreach ($medias_ids as $media_id) {
2498
+											if (!empty($media_id)) {
2499
+												$pictures[] = get_post($media_id);
2500
+											}
2501
+										}
2502
+									}
2503
+								}
2504
+
2505
+								$pictures_data = '';
2506
+								if (!empty($pictures)) {
2507
+									$selected_picture = get_post_meta($variation['post']->ID, '_wps_variation_attached_picture', true);
2508
+
2509
+									$done_picture = array();
2510
+									foreach ($pictures as $picture) {
2511
+										if (!in_array($picture->ID, $done_picture)) {
2512
+											if (wp_attachment_is_image($picture->ID)) {
2513
+												$checked = ((!empty($selected_picture) && $selected_picture == $picture->ID) ? 'checked="checked"' : '');
2514
+												$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');
2515
+
2516
+												$done_picture[] = $picture->ID;
2517
+											}
2518
+										}
2519
+									}
2520
+								}
2521
+
2522
+								$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');
2523
+							}
2524
+
2525
+						}
2526
+					}
2527
+				}
2754 2528
 
2755
-        return $output;
2756
-    }
2529
+				$tpl_component['VARIATION_DETAIL'] = substr($tpl_component['VARIATION_DETAIL'], 0, -2);
2757 2530
 
2758
-    public static function get_parent_variation($variation_id)
2759
-    {
2760
-        $result = array();
2761
-        if (!empty($variation_id)) {
2762
-            $variation_post = get_post($variation_id);
2763
-            if (!empty($variation_post) && !empty($variation_post->post_parent)) {
2764
-                $result['parent_post'] = get_post($variation_post->post_parent);
2765
-                $result['parent_post_meta'] = get_post_meta($variation_post->post_parent, '_wpshop_product_metadata', true);
2766
-            }
2767
-        }
2768
-        return $result;
2769
-    }
2531
+				$tpl_component['ADMIN_VARIATION_SPECIFIC_DEFINITION_CONTAINER_CLASS'] = ' wpshopHide';
2532
+				$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())));
2533
+				$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');
2770 2534
 
2771
-    /**
2772
-     * Display the current configuration for a given product
2773
-     * @param array $shortcode_attribute Some parameters given by the shortcode for display
2774
-     */
2775
-    public function wpshop_product_variations_summary($shortcode_attribute)
2776
-    {
2777
-        $output = '';
2778
-
2779
-        $product_variations_selection_args = array(
2780
-            'CURRENCY_SELECTOR' => wpshop_attributes_unit::wpshop_shop_currency_list_field(),
2781
-            'PRODUCT_VARIATION_SELECTION_DISPLAY' => '',
2782
-        );
2783
-
2784
-        $current_user_id = get_current_user_id();
2785
-
2786
-        if (!empty($_SESSION) && !empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_items'])) {
2787
-            foreach ($_SESSION['cart']['order_items'] as $item_id => $item) {
2788
-                if (!empty($item) && !empty($item['item_id'])) {
2789
-
2790
-                    $free_variations = array();
2791
-                    if (!empty($item['item_meta']) && !empty($item['item_meta']['free_variation'])) {
2792
-                        foreach ($item['item_meta']['free_variation'] as $attribute_code => $attribute_value) {
2793
-                            $free_variations[] = $attribute_code . '-_variation_val_-' . $attribute_value;
2794
-                        }
2795
-                    }
2796
-
2797
-                    $variations = array();
2798
-                    if (!empty($item['item_meta']) && !empty($item['item_meta']['variations'])) {
2799
-                        foreach ($item['item_meta']['variations'] as $variation_id => $variation_def) {
2800
-
2801
-                            if (!empty($variation_def['item_meta']) && !empty($variation_def['item_meta']['variation_definition'])) {
2802
-                                foreach ($variation_def['item_meta']['variation_definition'] as $attribute_code => $attribute_selected_data) {
2803
-                                    $variations[] = $attribute_code . '-_variation_val_-' . $attribute_selected_data['ID'];
2804
-                                }
2805
-                            }
2806
-                        }
2807
-                    }
2808
-                    $product_variation_summary = self::wpshop_ajax_wpshop_variation_selection($item['item_id'], $variations, $free_variations, null, $item['item_qty']);
2809
-
2810
-                    $product_variations_selection_args['PRODUCT_VARIATION_SELECTION_DISPLAY'] .= $product_variation_summary[1]['product_output'];
2811
-                }
2812
-            }
2813
-        }
2535
+				/*    Add the variation definition to output    */
2536
+				$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');
2537
+			}
2814 2538
 
2815
-        $output .= wpshop_display::display_template_element('wpshop_product_configuration_summary', $product_variations_selection_args);
2539
+			$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');
2540
+			/*    Reset de la liste des résultats pour éviter les comportements indésirables    */
2541
+			wp_reset_query();
2542
+		} else {
2543
+			$output = __('No variation found for this product. Please use button above for create one', 'wpshop');
2544
+		}
2816 2545
 
2817
-        echo $output;
2818
-    }
2546
+		return $output;
2547
+	}
2548
+
2549
+	/**
2550
+	 * Retrieve and display the variation for a given product
2551
+	 * @param integer $product_id The product identifier to get variation for
2552
+	 */
2553
+	public static function wpshop_variation($post_id = '', $from_admin = false, $order_id = '', $qty = 1)
2554
+	{
2555
+		global $wp_query;
2556
+		$output = '';
2557
+
2558
+		$product_id = empty($post_id) ? $wp_query->post->ID : $post_id;
2559
+		$wpshop_product_attributes_frontend_display = get_post_meta($product_id, '_wpshop_product_attributes_frontend_display', true);
2560
+		$head_wpshop_variation_definition = get_post_meta($product_id, '_wpshop_variation_defining', true);
2561
+
2562
+		/**    Get attribute order for current product    */
2563
+		$product_attribute_order_detail = wpshop_attributes_set::getAttributeSetDetails(get_post_meta($product_id, WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, true));
2564
+		$output_order = array();
2565
+		if (count($product_attribute_order_detail) > 0) {
2566
+			if (!empty($product_attribute_order_detail)) {
2567
+				foreach ($product_attribute_order_detail as $product_attr_group_id => $product_attr_group_detail) {
2568
+					foreach ($product_attr_group_detail['attribut'] as $position => $attribute_def) {
2569
+						if (!empty($attribute_def->code)) {
2570
+							$output_order[$attribute_def->code] = $position;
2571
+						}
2572
+
2573
+					}
2574
+				}
2575
+			}
2576
+		}
2577
+
2578
+		$variations_params = array();
2579
+		$variation_attribute = array();
2580
+		$variation_attribute_ordered = array();
2581
+		$possible_values = array();
2582
+		$possible_values_for_selection_calculation = array();
2583
+
2584
+		/*    Vérification de l'existence de déclinaison pour le produit    */
2585
+		$wpshop_variation_list = self::get_variation($product_id);
2586
+		if (!empty($wpshop_variation_list)) {
2587
+			foreach ($wpshop_variation_list as $variation) {
2588
+				if (!empty($variation['variation_def'])) {
2589
+					$display_option = get_post_meta($post_id, '_wpshop_product_attributes_frontend_display', true);
2590
+					foreach ($variation['variation_def'] as $attribute_code => $attribute_value) {
2591
+						if (empty($display_option) || (!empty($display_option['attribute']) && !empty($display_option['attribute'][$attribute_code]) && !empty($display_option['attribute'][$attribute_code]['complete_sheet']))) {
2592
+							$tpl_component = array();
2593
+
2594
+							$attribute_db_definition = wpshop_attributes::getElement($attribute_code, "'valid'", 'code');
2595
+							$default_value_is_serial = false;
2596
+							$attribute_list_first_element = $attribute_db_definition->default_value;
2597
+							if (!empty($attribute_db_definition->default_value) && ($attribute_db_definition->default_value == serialize(false) || wpshop_tools::is_serialized($attribute_db_definition->default_value))) {
2598
+								$default_value_is_serial = true;
2599
+								$tmp_default_value = unserialize($attribute_db_definition->default_value);
2600
+								$attribute_list_first_element = !empty($tmp_default_value['field_options']['label_for_first_item']) ? $tmp_default_value['field_options']['label_for_first_item'] : null;
2601
+							}
2602
+
2603
+							if ($default_value_is_serial && !empty($attribute_list_first_element) && ($attribute_list_first_element != 'none')) {
2604
+								$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');
2605
+							}
2606
+
2607
+							if (!empty($attribute_value) && ($attribute_db_definition->data_type_to_use == 'custom')) {
2608
+								$tpl_component['VARIATION_VALUE'] = stripslashes(wpshop_attributes::get_attribute_type_select_option_info($attribute_value, 'label', 'custom'));
2609
+								$position = wpshop_attributes::get_attribute_type_select_option_info($attribute_value, 'position', 'custom');
2610
+							} else if (!empty($attribute_value) && ($attribute_db_definition->data_type_to_use == 'internal')) {
2611
+								$post_def = get_post($attribute_value);
2612
+								$tpl_component['VARIATION_VALUE'] = stripslashes($post_def->post_title);
2613
+								$position = $post_def->menu_order;
2614
+							}
2615
+
2616
+							if (!empty($variation['variation_dif'])) {
2617
+								foreach ($variation['variation_dif'] as $attribute_dif_code => $attribute_dif_value) {
2618
+									$wpshop_prices_attributes = unserialize(WPSHOP_ATTRIBUTE_PRICES);
2619
+									$the_value = $attribute_dif_value;
2620
+									if (in_array($attribute_dif_code, $wpshop_prices_attributes)) {
2621
+										$the_value = wpshop_display::format_field_output('wpshop_product_price', $attribute_dif_value);
2622
+									}
2623
+									$tpl_component['VARIATION_DIF_' . strtoupper($attribute_dif_code)] = stripslashes($the_value);
2624
+								}
2625
+							}
2626
+							if (!empty($attribute_value)) {
2627
+								$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));
2628
+								$possible_values_for_selection_calculation[$attribute_code][$attribute_value] = $tpl_component['VARIATION_VALUE'];
2629
+							}
2630
+							unset($tpl_component);
2631
+						}
2632
+					}
2633
+				}
2634
+			}
2635
+
2636
+			$variation_tpl = array();
2637
+			if (!empty($head_wpshop_variation_definition['attributes'])) {
2638
+				foreach ($head_wpshop_variation_definition['attributes'] as $attribute_code) {
2639
+					$attribute_db_definition = wpshop_attributes::getElement($attribute_code, "'valid'", 'code');
2640
+
2641
+					if (!empty($attribute_db_definition)) {
2642
+						$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');
2643
+
2644
+						$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;
2645
+						if (!$is_required && $attribute_db_definition->is_required == 'yes') {
2646
+							$is_required = true;
2647
+						}
2648
+
2649
+						$input_def = array();
2650
+						$input_def['type'] = $attribute_db_definition->frontend_input;
2651
+						$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);
2652
+						if (in_array($attribute_db_definition->frontend_input, array('radio', 'checkbox'))) {
2653
+							unset($possible_values[$attribute_code][0]);
2654
+							$value = array($value);
2655
+						}
2656
+						$input_def['id'] = 'wpshop_variation_attr_' . $attribute_code;
2657
+						$input_def['name'] = $attribute_code;
2658
+						$real_possible_values = array();
2659
+						if (!empty($possible_values[$attribute_code])) {
2660
+							ksort($possible_values[$attribute_code]);
2661
+							foreach ($possible_values[$attribute_code] as $position => $def) {
2662
+								foreach ($def as $attribute_value => $attribute_value_output) {
2663
+									$real_possible_values[$attribute_value] = $attribute_value_output;
2664
+									if (!empty($attribute_value)) {
2665
+										global $wpdb;
2666
+										$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);
2667
+										if ('draft' == $wpdb->get_var($query)) {
2668
+											unset($real_possible_values[$attribute_value]);
2669
+										}
2670
+									}
2671
+								}
2672
+							}
2673
+						}
2674
+						$input_def['possible_value'] = $real_possible_values;
2675
+						$input_def['valueToPut'] = 'index';
2676
+						$input_def['value'] = $value;
2677
+
2678
+						$input_def['options']['more_input'] = '';
2679
+						if (!empty($possible_values_for_selection_calculation[$attribute_code])) {
2680
+							foreach ($possible_values_for_selection_calculation[$attribute_code] as $value_id => $value) {
2681
+								$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 . '" />';
2682
+							}
2683
+						}
2684
+
2685
+						$input_def['options_label']['original'] = true;
2686
+						$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) . '" ';
2687
+
2688
+						if (!empty($real_possible_values)) {
2689
+							$tpl_component = array();
2690
+							$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'];
2691
+							$tpl_component['VARIATION_INPUT'] = wpshop_form::check_input_type($input_def, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) . $input_def['options']['more_input'];
2692
+							$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));
2693
+							$tpl_component['VARIATION_CODE'] = $attribute_code;
2694
+							$tpl_component['VARIATION_LABEL_HELPER'] = !empty($attribute_db_definition->frontend_help_message) ? ' title="' . $attribute_db_definition->frontend_help_message . '" ' : '';
2695
+							$tpl_component['VARIATION_LABEL_CLASS'] = !empty($attribute_db_definition->frontend_help_message) ? ' wpshop_att_variation_helper' : '';
2696
+							$tpl_component['VARIATION_IDENTIFIER'] = $input_def['id'];
2697
+							$tpl_component['VARIATION_PARENT_ID'] = $product_id;
2698
+							$tpl_component['VARIATION_PARENT_TYPE'] = WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT;
2699
+							$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;
2700
+							$tpl_component['VARIATION_REQUIRED_INDICATION'] = ($is_required) ? __('Required variation', 'wpshop') : '';
2701
+							$variation_tpl['VARIATION_COMPLETE_OUTPUT_' . strtoupper($attribute_code)] = wpshop_display::display_template_element('product_variation_item', $tpl_component);
2702
+							$variation_attribute_ordered[$output_order[$attribute_code]] = $variation_tpl['VARIATION_COMPLETE_OUTPUT_' . strtoupper($attribute_code)];
2703
+						}
2704
+
2705
+						$variation_attribute[] = $attribute_code;
2706
+					}
2707
+				}
2708
+			}
2709
+
2710
+		}
2711
+		$variation_tpl['VARIATION_FORM_ELEMENT_ID'] = $product_id;
2712
+		wp_reset_query();
2713
+
2714
+		$attribute_defined_to_be_user_defined = wpshop_attributes::get_attribute_user_defined(array('entity_type_id' => self::currentPageCode));
2715
+		if (!empty($attribute_defined_to_be_user_defined)) {
2716
+			foreach ($attribute_defined_to_be_user_defined as $attribute_not_in_variation_but_user_defined) {
2717
+				$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;
2718
+
2719
+				$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');
2720
+				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')) {
2721
+					$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] : ''));
2722
+
2723
+					$tpl_component = array();
2724
+					$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) . '" ';
2725
+					$tpl_component['VARIATION_INPUT'] = wpshop_form::check_input_type($attribute_output_def, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION . '[free]') . $attribute_output_def['options'];
2726
+					$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));
2727
+					$tpl_component['VARIATION_CODE'] = $attribute_not_in_variation_but_user_defined->code;
2728
+					$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 . '" ' : '';
2729
+					$tpl_component['VARIATION_LABEL_CLASS'] = !empty($attribute_not_in_variation_but_user_defined->frontend_help_message) ? ' wpshop_att_variation_helper' : '';
2730
+					$tpl_component['VARIATION_REQUIRED_INDICATION'] = ($is_required) ? __('Required variation', 'wpshop') : '';
2731
+					$tpl_component['VARIATION_IDENTIFIER'] = $attribute_output_def['id'];
2732
+					$tpl_component['VARIATION_PARENT_ID'] = $product_id;
2733
+					$tpl_component['VARIATION_PARENT_TYPE'] = WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT;
2734
+					$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;
2735
+					$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'];
2736
+					$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)];
2737
+				}
2738
+			}
2739
+		}
2740
+		$variation_tpl['VARIATION_FORM_VARIATION_LIST'] = '';
2741
+		if (!empty($variation_attribute_ordered) && is_array($variation_attribute_ordered)) {
2742
+			ksort($variation_attribute_ordered);
2743
+			foreach ($variation_attribute_ordered as $attribute_variation_to_output) {
2744
+				$variation_tpl['VARIATION_FORM_VARIATION_LIST'] .= $attribute_variation_to_output;
2745
+			}
2746
+		}
2747
+		$variation_tpl['FROM_ADMIN_INDICATOR'] = $variation_tpl['ORDER_ID_INDICATOR'] = '';
2748
+		$variation_tpl['PRODUCT_ADDED_TO_CART_QTY'] = (!empty($qty)) ? $qty : 1;
2749
+		if ($from_admin && !empty($order_id)) {
2750
+			$variation_tpl['FROM_ADMIN_INDICATOR'] = '<input type="hidden" name="wps_orders_from_admin" value="1" />';
2751
+			$variation_tpl['ORDER_ID_INDICATOR'] = '<input type="hidden" name="wps_orders_order_id" value="' . $order_id . '" />';
2752
+		}
2753
+		$output = !empty($variation_tpl['VARIATION_FORM_VARIATION_LIST']) ? wpshop_display::display_template_element('product_variation_form', $variation_tpl) : '';
2754
+
2755
+		return $output;
2756
+	}
2757
+
2758
+	public static function get_parent_variation($variation_id)
2759
+	{
2760
+		$result = array();
2761
+		if (!empty($variation_id)) {
2762
+			$variation_post = get_post($variation_id);
2763
+			if (!empty($variation_post) && !empty($variation_post->post_parent)) {
2764
+				$result['parent_post'] = get_post($variation_post->post_parent);
2765
+				$result['parent_post_meta'] = get_post_meta($variation_post->post_parent, '_wpshop_product_metadata', true);
2766
+			}
2767
+		}
2768
+		return $result;
2769
+	}
2770
+
2771
+	/**
2772
+	 * Display the current configuration for a given product
2773
+	 * @param array $shortcode_attribute Some parameters given by the shortcode for display
2774
+	 */
2775
+	public function wpshop_product_variations_summary($shortcode_attribute)
2776
+	{
2777
+		$output = '';
2778
+
2779
+		$product_variations_selection_args = array(
2780
+			'CURRENCY_SELECTOR' => wpshop_attributes_unit::wpshop_shop_currency_list_field(),
2781
+			'PRODUCT_VARIATION_SELECTION_DISPLAY' => '',
2782
+		);
2783
+
2784
+		$current_user_id = get_current_user_id();
2785
+
2786
+		if (!empty($_SESSION) && !empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_items'])) {
2787
+			foreach ($_SESSION['cart']['order_items'] as $item_id => $item) {
2788
+				if (!empty($item) && !empty($item['item_id'])) {
2789
+
2790
+					$free_variations = array();
2791
+					if (!empty($item['item_meta']) && !empty($item['item_meta']['free_variation'])) {
2792
+						foreach ($item['item_meta']['free_variation'] as $attribute_code => $attribute_value) {
2793
+							$free_variations[] = $attribute_code . '-_variation_val_-' . $attribute_value;
2794
+						}
2795
+					}
2796
+
2797
+					$variations = array();
2798
+					if (!empty($item['item_meta']) && !empty($item['item_meta']['variations'])) {
2799
+						foreach ($item['item_meta']['variations'] as $variation_id => $variation_def) {
2800
+
2801
+							if (!empty($variation_def['item_meta']) && !empty($variation_def['item_meta']['variation_definition'])) {
2802
+								foreach ($variation_def['item_meta']['variation_definition'] as $attribute_code => $attribute_selected_data) {
2803
+									$variations[] = $attribute_code . '-_variation_val_-' . $attribute_selected_data['ID'];
2804
+								}
2805
+							}
2806
+						}
2807
+					}
2808
+					$product_variation_summary = self::wpshop_ajax_wpshop_variation_selection($item['item_id'], $variations, $free_variations, null, $item['item_qty']);
2809
+
2810
+					$product_variations_selection_args['PRODUCT_VARIATION_SELECTION_DISPLAY'] .= $product_variation_summary[1]['product_output'];
2811
+				}
2812
+			}
2813
+		}
2814
+
2815
+		$output .= wpshop_display::display_template_element('wpshop_product_configuration_summary', $product_variations_selection_args);
2816
+
2817
+		echo $output;
2818
+	}
2819
+
2820
+	/**
2821
+	 * Affichage du résumé du produit sélectionné avec le prix par option / Display a summary of selected product with the price per option
2822
+	 *
2823
+	 * @param integer $product_id L'identifiant du produit qui est ajouté au panier / The product identifier added to cart
2824
+	 * @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
2825
+	 * @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
2826
+	 * @param string $wpshop_current_for_display Inconnu / Unknown
2827
+	 * @param integer $product_qty La quantité commandée par le client / Quantity ordered by the customer
2828
+	 *
2829
+	 * @return array Le résultat du calcul pour l'affichage / Output result
2830
+	 */
2831
+	public static function wpshop_ajax_wpshop_variation_selection($product_id, $wpshop_variation_selected, $wpshop_free_variation, $wpshop_current_for_display, $product_qty = 1)
2832
+	{
2833
+		global $wpdb;
2834
+
2835
+		$wpshop_cart = new wps_cart();
2836
+		$wpshop_products = new wpshop_products();
2837
+
2838
+		$response = '';
2839
+		$response_status = $has_variation = false;
2840
+		$tpl_component = array();
2841
+
2842
+		// Check if variations exists
2843
+		if (!empty($wpshop_variation_selected) || !empty($wpshop_free_variation)) {
2844
+
2845
+			//Recover all selected variations
2846
+			$variations_selected = array();
2847
+			if (!empty($wpshop_variation_selected)) {
2848
+				foreach ($wpshop_variation_selected as $selected_variation) {
2849
+					$variation_definition = explode('-_variation_val_-', $selected_variation);
2850
+					$variations_selected[$variation_definition[0]] = $variation_definition[1];
2851
+				}
2852
+			}
2853
+
2854
+			// Check variations priority
2855
+			$product_with_variation = wpshop_products::get_variation_by_priority($variations_selected, $product_id);
2856
+
2857
+			// Check if $product_with_variation have variations
2858
+			if (!empty($product_with_variation[$product_id]['variations']) || !empty($wpshop_free_variation)) {
2859
+
2860
+				$formatted_product = $wpshop_cart->prepare_product_to_add_to_cart($product_id, $product_qty, $variations_selected);
2861
+				$product_to_add_to_cart = $formatted_product[0];
2862
+				foreach ($formatted_product[0] as $pid => $product_more_content) {
2863
+					$order_items[$pid]['product_id'] = $product_more_content['id'];
2864
+
2865
+					/** For product with variation    */
2866
+					$order_items[$pid]['product_variation_type'] = !empty($product_more_content['variation_priority']) ? $product_more_content['variation_priority'] : '';
2867
+					$order_items[$pid]['free_variation'] = !empty($product_more_content['free_variation']) ? $product_more_content['free_variation'] : '';
2868
+					$order_items[$pid]['product_variation'] = '';
2869
+					if (!empty($product_more_content['variations'])) {
2870
+						foreach ($product_more_content['variations'] as $variation_id) {
2871
+							$order_items[$pid]['product_variation'][] = $variation_id;
2872
+						}
2873
+					}
2874
+				}
2875
+
2876
+				// If Product list is not empty, add products to order
2877
+				if (!empty($order_items)) {
2878
+					foreach ($order_items as $product_id => $d) {
2879
+						$product_key = $product_id;
2880
+
2881
+						// Formate datas
2882
+						$product_id = $head_product_id = $d['product_id'];
2883
+						$product_variation = !empty($d['product_variation']) ? $d['product_variation'] : null;
2819 2884
 
2820
-    /**
2821
-     * Affichage du résumé du produit sélectionné avec le prix par option / Display a summary of selected product with the price per option
2822
-     *
2823
-     * @param integer $product_id L'identifiant du produit qui est ajouté au panier / The product identifier added to cart
2824
-     * @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
2825
-     * @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
2826
-     * @param string $wpshop_current_for_display Inconnu / Unknown
2827
-     * @param integer $product_qty La quantité commandée par le client / Quantity ordered by the customer
2828
-     *
2829
-     * @return array Le résultat du calcul pour l'affichage / Output result
2830
-     */
2831
-    public static function wpshop_ajax_wpshop_variation_selection($product_id, $wpshop_variation_selected, $wpshop_free_variation, $wpshop_current_for_display, $product_qty = 1)
2832
-    {
2833
-        global $wpdb;
2834
-
2835
-        $wpshop_cart = new wps_cart();
2836
-        $wpshop_products = new wpshop_products();
2837
-
2838
-        $response = '';
2839
-        $response_status = $has_variation = false;
2840
-        $tpl_component = array();
2841
-
2842
-        // Check if variations exists
2843
-        if (!empty($wpshop_variation_selected) || !empty($wpshop_free_variation)) {
2844
-
2845
-            //Recover all selected variations
2846
-            $variations_selected = array();
2847
-            if (!empty($wpshop_variation_selected)) {
2848
-                foreach ($wpshop_variation_selected as $selected_variation) {
2849
-                    $variation_definition = explode('-_variation_val_-', $selected_variation);
2850
-                    $variations_selected[$variation_definition[0]] = $variation_definition[1];
2851
-                }
2852
-            }
2853
-
2854
-            // Check variations priority
2855
-            $product_with_variation = wpshop_products::get_variation_by_priority($variations_selected, $product_id);
2856
-
2857
-            // Check if $product_with_variation have variations
2858
-            if (!empty($product_with_variation[$product_id]['variations']) || !empty($wpshop_free_variation)) {
2859
-
2860
-                $formatted_product = $wpshop_cart->prepare_product_to_add_to_cart($product_id, $product_qty, $variations_selected);
2861
-                $product_to_add_to_cart = $formatted_product[0];
2862
-                foreach ($formatted_product[0] as $pid => $product_more_content) {
2863
-                    $order_items[$pid]['product_id'] = $product_more_content['id'];
2864
-
2865
-                    /** For product with variation    */
2866
-                    $order_items[$pid]['product_variation_type'] = !empty($product_more_content['variation_priority']) ? $product_more_content['variation_priority'] : '';
2867
-                    $order_items[$pid]['free_variation'] = !empty($product_more_content['free_variation']) ? $product_more_content['free_variation'] : '';
2868
-                    $order_items[$pid]['product_variation'] = '';
2869
-                    if (!empty($product_more_content['variations'])) {
2870
-                        foreach ($product_more_content['variations'] as $variation_id) {
2871
-                            $order_items[$pid]['product_variation'][] = $variation_id;
2872
-                        }
2873
-                    }
2874
-                }
2875
-
2876
-                // If Product list is not empty, add products to order
2877
-                if (!empty($order_items)) {
2878
-                    foreach ($order_items as $product_id => $d) {
2879
-                        $product_key = $product_id;
2880
-
2881
-                        // Formate datas
2882
-                        $product_id = $head_product_id = $d['product_id'];
2883
-                        $product_variation = !empty($d['product_variation']) ? $d['product_variation'] : null;
2884
-
2885
-                        // If product is a single variation product
2886
-                        if (!empty($product_variation) && (count($product_variation) == 1)) {
2887
-                            $product_id = $product_variation[0];
2888
-                        }
2889
-
2890
-                        // Construct final product
2891
-                        $product = wpshop_products::get_product_data($d['product_id'], true);
2892
-                        $the_product = array_merge(array('product_id' => $d['product_id'], 'product_qty' => 1), $product);
2885
+						// If product is a single variation product
2886
+						if (!empty($product_variation) && (count($product_variation) == 1)) {
2887
+							$product_id = $product_variation[0];
2888
+						}
2889
+
2890
+						// Construct final product
2891
+						$product = wpshop_products::get_product_data($d['product_id'], true);
2892
+						$the_product = array_merge(array('product_id' => $d['product_id'], 'product_qty' => 1), $product);
2893 2893
 						$the_product['text_from'] = $product_with_variation['text_from'];
2894 2894
 
2895
-                        //    Add variation to product into cart for storage
2896
-                        if (!empty($product_variation)) {
2897
-                            $the_product = wpshop_products::get_variation_price_behaviour($the_product, $product_variation, $head_product_id, array('type' => $d['product_variation_type']));
2898
-                        }
2899
-
2900
-                        // Free Variations Checking
2901
-                        if (!empty($d['free_variation'])) {
2902
-                            $the_product['item_meta']['free_variation'] = $d['free_variation'];
2903
-                            $head_product_id = $the_product['product_id'];
2904
-                        }
2905
-
2906
-                        // If product is a variation, we check parent product general
2907
-                        if (get_post_type($the_product['product_id']) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) {
2908
-                            $parent_def = wpshop_products::get_parent_variation($the_product['product_id']);
2909
-                            if (!empty($parent_def) && !empty($parent_def['parent_post'])) {
2910
-                                $variation_def = get_post_meta($parent_def['parent_post']->ID, '_wpshop_variation_defining', true);
2911
-                                $parent_meta = $parent_def['parent_post_meta'];
2912
-                                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) {
2913
-                                    $the_product['product_price'] += number_format(str_replace(',', '.', $parent_meta['product_price']), 2, '.', '');
2914
-                                    $the_product['price_ht'] += number_format(str_replace(',', '.', $parent_meta['price_ht']), 2, '.', '');
2915
-                                    $the_product['tva'] += number_format(str_replace(',', '.', $parent_meta['tva']), 2, '.', '');
2916
-                                }
2917
-                            }
2918
-                        }
2919
-                    }
2920
-                }
2921
-
2922
-                if (!empty($the_product) && empty($the_product['price_ttc_before_discount']) && empty($the_product['price_ht_before_discount'])) {
2923
-                    $price_infos = wpshop_prices::check_product_price($the_product, true);
2924
-                    if (!empty($price_infos['discount']['discount_exist'])) {
2925
-                        $the_product['price_ttc_before_discount'] = $the_product['product_price'];
2926
-                        $the_product['price_ht_before_discount'] = $the_product['price_ht'];
2927
-                    }
2928
-                    $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'];
2929
-                    $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'];
2930
-                    $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'];
2931
-                }
2932
-
2933
-                $product = wpshop_products::get_product_data($product_id, true, '"publish", "draft"');
2934
-                // Add free variations to product
2935
-                if (!empty($wpshop_free_variation)) {
2936
-                    $the_product['item_meta']['free_variation'] = $wpshop_free_variation;
2937
-                }
2938
-                // Change picture if have a selected variation
2939
-                $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;
2940
-                $response['wps_product_image'] = $wpshop_products->wps_selected_variation_picture($head_product_id, $the_selected_variation);
2941
-
2942
-                // Price Display
2943
-                $price_attribute = wpshop_attributes::getElement('product_price', "'valid'", 'code');
2944
-                $price_display = wpshop_attributes::check_attribute_display($price_attribute->is_visible_in_front, $product['custom_display'], 'attribute', 'product_price', 'complete_sheet');
2945
-                $productPrice = '';
2946
-                if ($price_display) {
2947
-                    $response['product_price_output'] = wpshop_prices::get_product_price($the_product, 'price_display', 'complete_sheet', false, true);
2948
-                }
2949
-
2950
-                //Get Summary cart
2951
-                $response['product_output'] = $wpshop_products->wps_get_summary_variations_product($product_id, $the_product, (!empty($wpshop_variation_selected) || !empty($wpshop_free_variation) ? true : false));
2952
-                $response_status = true;
2953
-            } else {
2954
-                //Product without variations
2955
-                $product_data = wpshop_products::get_product_data($product_id);
2956
-                $response['product_price_output'] = wpshop_prices::get_product_price($product_data, 'price_display', 'complete_sheet');
2957
-            }
2958
-        }
2895
+						//    Add variation to product into cart for storage
2896
+						if (!empty($product_variation)) {
2897
+							$the_product = wpshop_products::get_variation_price_behaviour($the_product, $product_variation, $head_product_id, array('type' => $d['product_variation_type']));
2898
+						}
2899
+
2900
+						// Free Variations Checking
2901
+						if (!empty($d['free_variation'])) {
2902
+							$the_product['item_meta']['free_variation'] = $d['free_variation'];
2903
+							$head_product_id = $the_product['product_id'];
2904
+						}
2905
+
2906
+						// If product is a variation, we check parent product general
2907
+						if (get_post_type($the_product['product_id']) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) {
2908
+							$parent_def = wpshop_products::get_parent_variation($the_product['product_id']);
2909
+							if (!empty($parent_def) && !empty($parent_def['parent_post'])) {
2910
+								$variation_def = get_post_meta($parent_def['parent_post']->ID, '_wpshop_variation_defining', true);
2911
+								$parent_meta = $parent_def['parent_post_meta'];
2912
+								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) {
2913
+									$the_product['product_price'] += number_format(str_replace(',', '.', $parent_meta['product_price']), 2, '.', '');
2914
+									$the_product['price_ht'] += number_format(str_replace(',', '.', $parent_meta['price_ht']), 2, '.', '');
2915
+									$the_product['tva'] += number_format(str_replace(',', '.', $parent_meta['tva']), 2, '.', '');
2916
+								}
2917
+							}
2918
+						}
2919
+					}
2920
+				}
2959 2921
 
2960
-        return array($response_status, $response);
2961
-    }
2922
+				if (!empty($the_product) && empty($the_product['price_ttc_before_discount']) && empty($the_product['price_ht_before_discount'])) {
2923
+					$price_infos = wpshop_prices::check_product_price($the_product, true);
2924
+					if (!empty($price_infos['discount']['discount_exist'])) {
2925
+						$the_product['price_ttc_before_discount'] = $the_product['product_price'];
2926
+						$the_product['price_ht_before_discount'] = $the_product['price_ht'];
2927
+					}
2928
+					$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'];
2929
+					$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'];
2930
+					$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'];
2931
+				}
2962 2932
 
2963
-    /**
2964
-     * Display information for a given value of an attribute defined as an entity, when attribute option for detail view is set as true
2965
-     *
2966
-     * @param array $shortcode_attribute Some parameters given by the shortcode for display
2967
-     */
2968
-    public function wpshop_product_variation_value_detail($shortcode_attribute)
2969
-    {
2970
-        echo wpshop_display::display_template_element('wpshop_product_variation_value_detail_container', array());
2971
-    }
2933
+				$product = wpshop_products::get_product_data($product_id, true, '"publish", "draft"');
2934
+				// Add free variations to product
2935
+				if (!empty($wpshop_free_variation)) {
2936
+					$the_product['item_meta']['free_variation'] = $wpshop_free_variation;
2937
+				}
2938
+				// Change picture if have a selected variation
2939
+				$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;
2940
+				$response['wps_product_image'] = $wpshop_products->wps_selected_variation_picture($head_product_id, $the_selected_variation);
2941
+
2942
+				// Price Display
2943
+				$price_attribute = wpshop_attributes::getElement('product_price', "'valid'", 'code');
2944
+				$price_display = wpshop_attributes::check_attribute_display($price_attribute->is_visible_in_front, $product['custom_display'], 'attribute', 'product_price', 'complete_sheet');
2945
+				$productPrice = '';
2946
+				if ($price_display) {
2947
+					$response['product_price_output'] = wpshop_prices::get_product_price($the_product, 'price_display', 'complete_sheet', false, true);
2948
+				}
2972 2949
 
2973
-    /**
2974
-     * Build the product structure with variation for product choosed by the user into frontend sheet
2975
-     *
2976
-     * @param array $selected_variation THe list of variation choosed by the user in product frontend sheet
2977
-     * @param integer $product_id The basic product choose by the user in frontend
2978
-     *
2979
-     * @return array The product list for adding to the cart build by variation priority
2980
-     */
2981
-    public static function get_variation_by_priority($selected_variation, $product_id, $add_to_cart_action = false)
2982
-    {
2983
-        global $wpdb;
2984
-        $all_required_variations_selected = $no_selected_variation = true;
2985
-        $single_variations = $combined_variations = $product_to_add_to_cart = array();
2986
-
2987
-        // Check if all required variations are selected
2988
-        $required_attributes_list = wpshop_prices::check_required_attributes($product_id);
2989
-        foreach ($selected_variation as $k => $value) {
2990
-            if ($value == 0 && in_array($k, $required_attributes_list)) {
2991
-                $all_required_variations_selected = false;
2992
-            }
2993
-            if ($value != 0) {
2994
-                $no_selected_variation = false;
2995
-            }
2996
-        }
2997
-        if (!empty($selected_variation)) {
2998
-            //Check variations configuration
2999
-            $product_variation_configuration = get_post_meta($product_id, '_wpshop_variation_defining', true);
3000
-            // Check variations type
3001
-            $product_variation_type = (!empty($product_variation_configuration) && !empty($product_variation_configuration['variation_type'])) ? $product_variation_configuration['variation_type'] : 'single';
3002
-            $product_to_add_to_cart[$product_id]['variation_priority'] = $product_variation_type;
3003
-
3004
-            //Check defined variation priority
3005
-            $priority = (!empty($product_variation_configuration['options']) && !empty($product_variation_configuration['options']['priority'][0])) ? $product_variation_configuration['options']['priority'][0] : 'combined';
3006
-            $product_to_add_to_cart[$product_id]['defined_variation_priority'] = $priority;
3007
-
3008
-            // Recover all product variations
3009
-            $query_variation = $selected_variation;
3010
-            // Delete free variations
3011
-            unset($query_variation['free']);
3012
-
3013
-            if ($product_variation_type == 'single') {
3014
-                // Get single variations
3015
-                $single_variations = array();
3016
-                foreach ($selected_variation as $attribute_code => $attribute_value) {
3017
-                    if (isset($attribute_value) && $attribute_code != 'free') {
3018
-                        $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)) . "'", $product_id);
3019
-                        $single_variation_id = $wpdb->get_var($query);
3020
-                        if (!empty($single_variation_id)) {
3021
-                            $single_variations[] = $single_variation_id;
3022
-                            unset($query_variation[$attribute_code]);
3023
-                        }
3024
-                    }
3025
-                }
3026
-            } else {
3027
-                // Get combined variations
3028
-                $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);
3029
-                $combined_variation_id = $wpdb->get_var($query);
3030
-                if (!empty($combined_variation_id)) {
3031
-                    $combined_variations[] = $combined_variation_id;
3032
-                }
3033
-
3034
-            }
3035
-
3036
-            //If all required variations are not selected
3037
-            if (!$all_required_variations_selected || $no_selected_variation) {
3038
-                $product_to_add_to_cart['text_from'] = 'on';
3039
-                // If we choose to display lower price variation combinaison
3040
-                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']))) {
3041
-                    //Get lower price variation combinaison
3042
-                    $lower_price_variations = wpshop_prices::check_product_lower_price($product_id);
3043
-                    if (!empty($lower_price_variations['variations']) && is_array($lower_price_variations['variations'])) {
3044
-                        foreach ($lower_price_variations['variations'] as $lower_price_variation) {
3045
-                            $product_to_add_to_cart[$product_id]['variations'][] = $lower_price_variation;
3046
-                        }
3047
-                    }
3048
-                    $product_to_add_to_cart['display_lower_price'] = true;
3049
-                } else {
3050
-                    $product_to_add_to_cart[$product_id]['variations'] = array();
3051
-                }
3052
-            } else {
3053
-                $product_to_add_to_cart['text_from'] = '';
3054
-                $product_to_add_to_cart[$product_id]['variations'] = (!empty($product_variation_type) && $product_variation_type == 'single') ? $single_variations : $combined_variations;
3055
-            }
3056
-        }
2950
+				//Get Summary cart
2951
+				$response['product_output'] = $wpshop_products->wps_get_summary_variations_product($product_id, $the_product, (!empty($wpshop_variation_selected) || !empty($wpshop_free_variation) ? true : false));
2952
+				$response_status = true;
2953
+			} else {
2954
+				//Product without variations
2955
+				$product_data = wpshop_products::get_product_data($product_id);
2956
+				$response['product_price_output'] = wpshop_prices::get_product_price($product_data, 'price_display', 'complete_sheet');
2957
+			}
2958
+		}
3057 2959
 
3058
-        return $product_to_add_to_cart;
3059
-    }
2960
+		return array($response_status, $response);
2961
+	}
3060 2962
 
3061
-    public static function get_variation_price_behaviour($product_into_cart, $product_variations, $head_product_id, $variations_options)
3062
-    {
3063
-        global $wpdb;
3064
-
3065
-        if (!empty($product_variations)) {
3066
-            // Initialize variations total price datas
3067
-            $variations_total_price = array('price_et' => 0, 'vat_amount' => 0, 'price_ati' => 0);
3068
-            $variations_discount_total_price = array('price_et' => 0, 'vat_amount' => 0, 'price_ati' => 0);
3069
-            $vat_rate = 0;
3070
-            $discount_amount = $discount_rate = $special_price = 0;
3071
-            // Recover Head product metadata
3072
-            $head_product_metadata = get_post_meta($head_product_id, '_wpshop_product_metadata', true);
3073
-            $tva_rate_id = (!empty($head_product_metadata['tx_tva'])) ? $head_product_metadata['tx_tva'] : 0;
3074
-            if (!empty($tva_rate_id)) {
3075
-                // Recover VAT Rate of product
3076
-                $query = $wpdb->prepare('SELECT value FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id = %d', $tva_rate_id);
3077
-                $vat_rate = $wpdb->get_var($query);
3078
-            }
3079
-            $price_piloting = get_option('wpshop_shop_price_piloting');
3080
-            foreach ($product_variations as $product_variation) {
3081
-                $variation_metadata['product_price'] = 0;
3082
-                $variation_metadata = get_post_meta($product_variation, '_wpshop_product_metadata', true);
3083
-                if (!empty($variation_metadata)) {
3084
-                    $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']);
3085
-                    $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))));
3086
-
3087
-                    $variations_total_price['price_et'] += $p_et;
3088
-                    $variations_total_price['price_ati'] += $p_ati;
3089
-                    $variations_total_price['vat_amount'] += $p_ati - $p_et;
3090
-
3091
-                    $variation_metadata['tx_tva'] = $product_into_cart['tx_tva'] = $vat_rate;
3092
-
3093
-                    // Check discount
3094
-                    $discount_config = wpshop_prices::check_discount_for_product($product_variation);
3095
-                    if (!empty($discount_config) && !empty($discount_config['value'])) {
3096
-                        $variation_discount_prices = wpshop_prices::calcul_discounted_price($variation_metadata, $discount_config);
3097
-                        $variations_discount_total_price['price_et'] += $variation_discount_prices['price_ht'];
3098
-                        $variations_discount_total_price['price_ati'] += $variation_discount_prices['product_price'];
3099
-                        $variations_discount_total_price['vat_amount'] += $variation_discount_prices['tva'];
3100
-
3101
-                        if (!empty($discount_config['type']) && $discount_config['type'] == 'discount_amount') {
3102
-                            $product_into_cart['discount_amount'] = $discount_amount + $product_into_cart['discount_amount'];
3103
-                        } elseif (!empty($discount_config['type']) && $discount_config['type'] == 'discount_rate') {
3104
-                            $product_into_cart['discount_rate'] = $discount_rate + $discount_config['value'];
3105
-                        } elseif (!empty($discount_config['type']) && $discount_config['type'] == 'special_price') {
3106
-                            $product_into_cart['special_price'] = $special_price + $discount_config['value'];
3107
-                        }
3108
-                    }
3109
-
3110
-                    $product_variation_def = wpshop_products::get_product_data($product_variation, true, '"publish", "draft"');
3111
-                    $product_into_cart['item_meta']['variations'][$product_variation] = $product_variation_def;
3112
-                }
3113
-            }
3114
-
3115
-            // Check if add or replace variation price to head product
3116
-            /**
3117
-             * Since 1.4.3.7
3118
-             * L'option du produit remplace le prix du produit de tête.
3119
-             */
2963
+	/**
2964
+	 * Display information for a given value of an attribute defined as an entity, when attribute option for detail view is set as true
2965
+	 *
2966
+	 * @param array $shortcode_attribute Some parameters given by the shortcode for display
2967
+	 */
2968
+	public function wpshop_product_variation_value_detail($shortcode_attribute)
2969
+	{
2970
+		echo wpshop_display::display_template_element('wpshop_product_variation_value_detail_container', array());
2971
+	}
2972
+
2973
+	/**
2974
+	 * Build the product structure with variation for product choosed by the user into frontend sheet
2975
+	 *
2976
+	 * @param array $selected_variation THe list of variation choosed by the user in product frontend sheet
2977
+	 * @param integer $product_id The basic product choose by the user in frontend
2978
+	 *
2979
+	 * @return array The product list for adding to the cart build by variation priority
2980
+	 */
2981
+	public static function get_variation_by_priority($selected_variation, $product_id, $add_to_cart_action = false)
2982
+	{
2983
+		global $wpdb;
2984
+		$all_required_variations_selected = $no_selected_variation = true;
2985
+		$single_variations = $combined_variations = $product_to_add_to_cart = array();
2986
+
2987
+		// Check if all required variations are selected
2988
+		$required_attributes_list = wpshop_prices::check_required_attributes($product_id);
2989
+		foreach ($selected_variation as $k => $value) {
2990
+			if ($value == 0 && in_array($k, $required_attributes_list)) {
2991
+				$all_required_variations_selected = false;
2992
+			}
2993
+			if ($value != 0) {
2994
+				$no_selected_variation = false;
2995
+			}
2996
+		}
2997
+		if (!empty($selected_variation)) {
2998
+			//Check variations configuration
2999
+			$product_variation_configuration = get_post_meta($product_id, '_wpshop_variation_defining', true);
3000
+			// Check variations type
3001
+			$product_variation_type = (!empty($product_variation_configuration) && !empty($product_variation_configuration['variation_type'])) ? $product_variation_configuration['variation_type'] : 'single';
3002
+			$product_to_add_to_cart[$product_id]['variation_priority'] = $product_variation_type;
3003
+
3004
+			//Check defined variation priority
3005
+			$priority = (!empty($product_variation_configuration['options']) && !empty($product_variation_configuration['options']['priority'][0])) ? $product_variation_configuration['options']['priority'][0] : 'combined';
3006
+			$product_to_add_to_cart[$product_id]['defined_variation_priority'] = $priority;
3007
+
3008
+			// Recover all product variations
3009
+			$query_variation = $selected_variation;
3010
+			// Delete free variations
3011
+			unset($query_variation['free']);
3012
+
3013
+			if ($product_variation_type == 'single') {
3014
+				// Get single variations
3015
+				$single_variations = array();
3016
+				foreach ($selected_variation as $attribute_code => $attribute_value) {
3017
+					if (isset($attribute_value) && $attribute_code != 'free') {
3018
+						$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)) . "'", $product_id);
3019
+						$single_variation_id = $wpdb->get_var($query);
3020
+						if (!empty($single_variation_id)) {
3021
+							$single_variations[] = $single_variation_id;
3022
+							unset($query_variation[$attribute_code]);
3023
+						}
3024
+					}
3025
+				}
3026
+			} else {
3027
+				// Get combined variations
3028
+				$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);
3029
+				$combined_variation_id = $wpdb->get_var($query);
3030
+				if (!empty($combined_variation_id)) {
3031
+					$combined_variations[] = $combined_variation_id;
3032
+				}
3033
+
3034
+			}
3035
+
3036
+			//If all required variations are not selected
3037
+			if (!$all_required_variations_selected || $no_selected_variation) {
3038
+				$product_to_add_to_cart['text_from'] = 'on';
3039
+				// If we choose to display lower price variation combinaison
3040
+				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']))) {
3041
+					//Get lower price variation combinaison
3042
+					$lower_price_variations = wpshop_prices::check_product_lower_price($product_id);
3043
+					if (!empty($lower_price_variations['variations']) && is_array($lower_price_variations['variations'])) {
3044
+						foreach ($lower_price_variations['variations'] as $lower_price_variation) {
3045
+							$product_to_add_to_cart[$product_id]['variations'][] = $lower_price_variation;
3046
+						}
3047
+					}
3048
+					$product_to_add_to_cart['display_lower_price'] = true;
3049
+				} else {
3050
+					$product_to_add_to_cart[$product_id]['variations'] = array();
3051
+				}
3052
+			} else {
3053
+				$product_to_add_to_cart['text_from'] = '';
3054
+				$product_to_add_to_cart[$product_id]['variations'] = (!empty($product_variation_type) && $product_variation_type == 'single') ? $single_variations : $combined_variations;
3055
+			}
3056
+		}
3057
+
3058
+		return $product_to_add_to_cart;
3059
+	}
3060
+
3061
+	public static function get_variation_price_behaviour($product_into_cart, $product_variations, $head_product_id, $variations_options)
3062
+	{
3063
+		global $wpdb;
3064
+
3065
+		if (!empty($product_variations)) {
3066
+			// Initialize variations total price datas
3067
+			$variations_total_price = array('price_et' => 0, 'vat_amount' => 0, 'price_ati' => 0);
3068
+			$variations_discount_total_price = array('price_et' => 0, 'vat_amount' => 0, 'price_ati' => 0);
3069
+			$vat_rate = 0;
3070
+			$discount_amount = $discount_rate = $special_price = 0;
3071
+			// Recover Head product metadata
3072
+			$head_product_metadata = get_post_meta($head_product_id, '_wpshop_product_metadata', true);
3073
+			$tva_rate_id = (!empty($head_product_metadata['tx_tva'])) ? $head_product_metadata['tx_tva'] : 0;
3074
+			if (!empty($tva_rate_id)) {
3075
+				// Recover VAT Rate of product
3076
+				$query = $wpdb->prepare('SELECT value FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id = %d', $tva_rate_id);
3077
+				$vat_rate = $wpdb->get_var($query);
3078
+			}
3079
+			$price_piloting = get_option('wpshop_shop_price_piloting');
3080
+			foreach ($product_variations as $product_variation) {
3081
+				$variation_metadata['product_price'] = 0;
3082
+				$variation_metadata = get_post_meta($product_variation, '_wpshop_product_metadata', true);
3083
+				if (!empty($variation_metadata)) {
3084
+					$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']);
3085
+					$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))));
3086
+
3087
+					$variations_total_price['price_et'] += $p_et;
3088
+					$variations_total_price['price_ati'] += $p_ati;
3089
+					$variations_total_price['vat_amount'] += $p_ati - $p_et;
3090
+
3091
+					$variation_metadata['tx_tva'] = $product_into_cart['tx_tva'] = $vat_rate;
3092
+
3093
+					// Check discount
3094
+					$discount_config = wpshop_prices::check_discount_for_product($product_variation);
3095
+					if (!empty($discount_config) && !empty($discount_config['value'])) {
3096
+						$variation_discount_prices = wpshop_prices::calcul_discounted_price($variation_metadata, $discount_config);
3097
+						$variations_discount_total_price['price_et'] += $variation_discount_prices['price_ht'];
3098
+						$variations_discount_total_price['price_ati'] += $variation_discount_prices['product_price'];
3099
+						$variations_discount_total_price['vat_amount'] += $variation_discount_prices['tva'];
3100
+
3101
+						if (!empty($discount_config['type']) && $discount_config['type'] == 'discount_amount') {
3102
+							$product_into_cart['discount_amount'] = $discount_amount + $product_into_cart['discount_amount'];
3103
+						} elseif (!empty($discount_config['type']) && $discount_config['type'] == 'discount_rate') {
3104
+							$product_into_cart['discount_rate'] = $discount_rate + $discount_config['value'];
3105
+						} elseif (!empty($discount_config['type']) && $discount_config['type'] == 'special_price') {
3106
+							$product_into_cart['special_price'] = $special_price + $discount_config['value'];
3107
+						}
3108
+					}
3109
+
3110
+					$product_variation_def = wpshop_products::get_product_data($product_variation, true, '"publish", "draft"');
3111
+					$product_into_cart['item_meta']['variations'][$product_variation] = $product_variation_def;
3112
+				}
3113
+			}
3114
+
3115
+			// Check if add or replace variation price to head product
3116
+			/**
3117
+			 * Since 1.4.3.7
3118
+			 * L'option du produit remplace le prix du produit de tête.
3119
+			 */
3120 3120
 			if( true ) {
3121
-                //Replace the product price
3122
-                if (!empty($variations_discount_total_price) && !empty($variations_discount_total_price['price_ati'])) {
3123
-                    $product_into_cart['price_ttc_before_discount'] = $variations_total_price['price_ati'];
3124
-                    $product_into_cart['price_ht_before_discount'] = $variations_total_price['price_et'];
3125
-
3126
-                    $product_into_cart['product_price'] = $variations_discount_total_price['price_ati'];
3127
-                    $product_into_cart['price_ht'] = $variations_discount_total_price['price_et'];
3128
-                    $product_into_cart['tva'] = $variations_discount_total_price['vat_amount'];
3129
-                } else {
3130
-                    $product_into_cart['product_price'] = $variations_total_price['price_ati'];
3131
-                    $product_into_cart['price_ht'] = $variations_total_price['price_et'];
3132
-                    $product_into_cart['tva'] = $variations_total_price['vat_amount'];
3133
-                }
3134
-            } else {
3135
-                // Add variations price to product price
3136
-                if (!empty($variations_discount_total_price) && !empty($variations_discount_total_price['price_ati'])) {
3137
-                    $product_into_cart['price_ttc_before_discount'] = ($product_into_cart['product_price'] + $variations_total_price['price_ati']);
3138
-                    $product_into_cart['price_ht_before_discount'] = ($product_into_cart['price_ht'] + $variations_total_price['price_et']);
3139
-
3140
-                    $product_into_cart['product_price'] += $variations_discount_total_price['price_ati'];
3141
-                    $product_into_cart['price_ht'] += $variations_discount_total_price['price_et'];
3142
-                    $product_into_cart['tva'] += $variations_discount_total_price['vat_amount'];
3143
-                } else {
3144
-                    $product_into_cart['product_price'] += $variations_total_price['price_ati'];
3145
-                    $product_into_cart['price_ht'] += $variations_total_price['price_et'];
3146
-                    $product_into_cart['tva'] += $variations_total_price['vat_amount'];
3147
-                }
3148
-                // Check parent discount
3149
-                $parent_discount_config = wpshop_prices::check_discount_for_product($head_product_id);
3150
-                if (!empty($parent_discount_config)) {
3151
-                    $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'];
3152
-                    $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'];
3153
-                    $product_into_cart = wpshop_prices::calcul_discounted_price($product_into_cart, $parent_discount_config);
3154
-
3155
-                    if (!empty($parent_discount_config['type']) && $parent_discount_config['type'] == 'discount_amount') {
3156
-                        $product_into_cart['discount_amount'] = $discount_amount + $parent_discount_config['value'];
3157
-                    } elseif (!empty($parent_discount_config['type']) && $parent_discount_config['type'] == 'discount_rate') {
3158
-                        $product_into_cart['discount_rate'] = $discount_rate + $parent_discount_config['value'];
3159
-                    } elseif (!empty($parent_discount_config['type']) && $parent_discount_config['type'] == 'special_price') {
3160
-                        $product_into_cart['special_price'] = $special_price + $parent_discount_config['value'];
3161
-                    }
3162
-                }
3163
-            }
3164
-        } else {
3165
-            // If product have just Free variations
3166
-            $discount_config = wpshop_prices::check_discount_for_product($head_product_id);
3167
-            if (!empty($discount_config)) {
3168
-                $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'];
3169
-                $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'];
3170
-                $product_into_cart = wpshop_prices::calcul_discounted_price($product_into_cart, $discount_config);
3171
-            }
3172
-        }
3121
+				//Replace the product price
3122
+				if (!empty($variations_discount_total_price) && !empty($variations_discount_total_price['price_ati'])) {
3123
+					$product_into_cart['price_ttc_before_discount'] = $variations_total_price['price_ati'];
3124
+					$product_into_cart['price_ht_before_discount'] = $variations_total_price['price_et'];
3125
+
3126
+					$product_into_cart['product_price'] = $variations_discount_total_price['price_ati'];
3127
+					$product_into_cart['price_ht'] = $variations_discount_total_price['price_et'];
3128
+					$product_into_cart['tva'] = $variations_discount_total_price['vat_amount'];
3129
+				} else {
3130
+					$product_into_cart['product_price'] = $variations_total_price['price_ati'];
3131
+					$product_into_cart['price_ht'] = $variations_total_price['price_et'];
3132
+					$product_into_cart['tva'] = $variations_total_price['vat_amount'];
3133
+				}
3134
+			} else {
3135
+				// Add variations price to product price
3136
+				if (!empty($variations_discount_total_price) && !empty($variations_discount_total_price['price_ati'])) {
3137
+					$product_into_cart['price_ttc_before_discount'] = ($product_into_cart['product_price'] + $variations_total_price['price_ati']);
3138
+					$product_into_cart['price_ht_before_discount'] = ($product_into_cart['price_ht'] + $variations_total_price['price_et']);
3139
+
3140
+					$product_into_cart['product_price'] += $variations_discount_total_price['price_ati'];
3141
+					$product_into_cart['price_ht'] += $variations_discount_total_price['price_et'];
3142
+					$product_into_cart['tva'] += $variations_discount_total_price['vat_amount'];
3143
+				} else {
3144
+					$product_into_cart['product_price'] += $variations_total_price['price_ati'];
3145
+					$product_into_cart['price_ht'] += $variations_total_price['price_et'];
3146
+					$product_into_cart['tva'] += $variations_total_price['vat_amount'];
3147
+				}
3148
+				// Check parent discount
3149
+				$parent_discount_config = wpshop_prices::check_discount_for_product($head_product_id);
3150
+				if (!empty($parent_discount_config)) {
3151
+					$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'];
3152
+					$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'];
3153
+					$product_into_cart = wpshop_prices::calcul_discounted_price($product_into_cart, $parent_discount_config);
3154
+
3155
+					if (!empty($parent_discount_config['type']) && $parent_discount_config['type'] == 'discount_amount') {
3156
+						$product_into_cart['discount_amount'] = $discount_amount + $parent_discount_config['value'];
3157
+					} elseif (!empty($parent_discount_config['type']) && $parent_discount_config['type'] == 'discount_rate') {
3158
+						$product_into_cart['discount_rate'] = $discount_rate + $parent_discount_config['value'];
3159
+					} elseif (!empty($parent_discount_config['type']) && $parent_discount_config['type'] == 'special_price') {
3160
+						$product_into_cart['special_price'] = $special_price + $parent_discount_config['value'];
3161
+					}
3162
+				}
3163
+			}
3164
+		} else {
3165
+			// If product have just Free variations
3166
+			$discount_config = wpshop_prices::check_discount_for_product($head_product_id);
3167
+			if (!empty($discount_config)) {
3168
+				$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'];
3169
+				$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'];
3170
+				$product_into_cart = wpshop_prices::calcul_discounted_price($product_into_cart, $discount_config);
3171
+			}
3172
+		}
3173 3173
 
3174
-        // Text From indicator
3175
-        if (!empty($variations_options) && !empty($variations_options['text_from'])) {
3176
-            $product_into_cart['text_from'] = $variations_options['text_from'];
3177
-        }
3178
-        return $product_into_cart;
3179
-    }
3174
+		// Text From indicator
3175
+		if (!empty($variations_options) && !empty($variations_options['text_from'])) {
3176
+			$product_into_cart['text_from'] = $variations_options['text_from'];
3177
+		}
3178
+		return $product_into_cart;
3179
+	}
3180 3180
 
3181
-    /**
3182
-     * Read an array with product options chosen by the customer, order into an array regarding admin definition
3183
-     *
3184
-     * @param array $product_definition_value The array with the selected product option to ordered
3185
-     * @param array $output_order The good order for attribute defined by administrator
3186
-     * @param dtring $from_page A string allowing to take a specific template regarding the current page
3187
-     *
3188
-     * @return array The array containing all product options ordered as the admin configure it
3189
-     */
3190
-    public static function get_selected_variation_display($product_definition_value, $output_order, $from_page = null, $template_part = 'wpshop', $output_type = null)
3191
-    {
3192
-        $variation_attribute_ordered = array();
3193
-        $variation_attribute_ordered['prices'] = array();
3194
-        $variation_attribute_ordered['attribute_list'] = array();
3195
-
3196
-        if (!empty($product_definition_value['variation_definition']) && is_array($product_definition_value['variation_definition'])) {
3197
-            foreach ($product_definition_value['variation_definition'] as $variation_attribute_code => $variation_attribute_detail) {
3198
-                $variation_tpl_component = array();
3199
-                foreach ($variation_attribute_detail as $info_name => $info_value) {
3200
-                    $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);
3201
-                }
3202
-                $variation_tpl_component['VARIATION_ID'] = $variation_attribute_code;
3203
-                $variation_tpl_component['VARIATION_ATT_CODE'] = $variation_attribute_code;
3204
-                if (!empty($output_order[$variation_attribute_code])) {
3205
-                    $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);
3206
-                    if (!in_array($display_data, $variation_attribute_ordered['attribute_list'])) {
3207
-                        $variation_attribute_ordered['attribute_list'][$output_order[$variation_attribute_code]] = $display_data;
3208
-                    }
3209
-                } else {
3210
-                    $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);
3211
-                    if (!in_array($display_data, $variation_attribute_ordered['attribute_list'])) {
3212
-                        $variation_attribute_ordered['attribute_list'][] = $display_data;
3213
-                    }
3214
-                }
3215
-                unset($variation_tpl_component);
3216
-            }
3217
-        }
3181
+	/**
3182
+	 * Read an array with product options chosen by the customer, order into an array regarding admin definition
3183
+	 *
3184
+	 * @param array $product_definition_value The array with the selected product option to ordered
3185
+	 * @param array $output_order The good order for attribute defined by administrator
3186
+	 * @param dtring $from_page A string allowing to take a specific template regarding the current page
3187
+	 *
3188
+	 * @return array The array containing all product options ordered as the admin configure it
3189
+	 */
3190
+	public static function get_selected_variation_display($product_definition_value, $output_order, $from_page = null, $template_part = 'wpshop', $output_type = null)
3191
+	{
3192
+		$variation_attribute_ordered = array();
3193
+		$variation_attribute_ordered['prices'] = array();
3194
+		$variation_attribute_ordered['attribute_list'] = array();
3195
+
3196
+		if (!empty($product_definition_value['variation_definition']) && is_array($product_definition_value['variation_definition'])) {
3197
+			foreach ($product_definition_value['variation_definition'] as $variation_attribute_code => $variation_attribute_detail) {
3198
+				$variation_tpl_component = array();
3199
+				foreach ($variation_attribute_detail as $info_name => $info_value) {
3200
+					$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);
3201
+				}
3202
+				$variation_tpl_component['VARIATION_ID'] = $variation_attribute_code;
3203
+				$variation_tpl_component['VARIATION_ATT_CODE'] = $variation_attribute_code;
3204
+				if (!empty($output_order[$variation_attribute_code])) {
3205
+					$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);
3206
+					if (!in_array($display_data, $variation_attribute_ordered['attribute_list'])) {
3207
+						$variation_attribute_ordered['attribute_list'][$output_order[$variation_attribute_code]] = $display_data;
3208
+					}
3209
+				} else {
3210
+					$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);
3211
+					if (!in_array($display_data, $variation_attribute_ordered['attribute_list'])) {
3212
+						$variation_attribute_ordered['attribute_list'][] = $display_data;
3213
+					}
3214
+				}
3215
+				unset($variation_tpl_component);
3216
+			}
3217
+		}
3218 3218
 
3219
-        if (!empty($product_definition_value['variations']) && is_array($product_definition_value['variations'])) {
3220
-            foreach ($product_definition_value['variations'] as $variation_id => $variation_details) {
3221
-                $variation_tpl_component = array();
3222
-                foreach ($variation_details as $info_name => $info_value) {
3223
-                    if ($info_name != 'item_meta') {
3224
-                        $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);
3225
-                    }
3226
-                }
3227
-                foreach ($variation_details['item_meta']['variation_definition'] as $variation_attribute_code => $variation_attribute_def) {
3228
-                    $variation_tpl_component['VARIATION_NAME'] = stripslashes($variation_attribute_def['NAME']);
3229
-                    $variation_tpl_component['VARIATION_VALUE'] = stripslashes($variation_attribute_def['VALUE']);
3230
-                    $variation_tpl_component['VARIATION_ID'] = $variation_id;
3231
-                    $variation_tpl_component['VARIATION_ATT_CODE'] = $variation_attribute_code;
3232
-
3233
-                    $variation_attribute_ordered['prices'][$variation_attribute_code] = $variation_tpl_component['VARIATION_DETAIL_PRODUCT_PRICE'];
3234
-                }
3235
-                if (!empty($output_order[$variation_attribute_code])) {
3236
-                    $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);
3237
-                }
3238
-                unset($variation_tpl_component);
3239
-            }
3240
-        }
3219
+		if (!empty($product_definition_value['variations']) && is_array($product_definition_value['variations'])) {
3220
+			foreach ($product_definition_value['variations'] as $variation_id => $variation_details) {
3221
+				$variation_tpl_component = array();
3222
+				foreach ($variation_details as $info_name => $info_value) {
3223
+					if ($info_name != 'item_meta') {
3224
+						$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);
3225
+					}
3226
+				}
3227
+				foreach ($variation_details['item_meta']['variation_definition'] as $variation_attribute_code => $variation_attribute_def) {
3228
+					$variation_tpl_component['VARIATION_NAME'] = stripslashes($variation_attribute_def['NAME']);
3229
+					$variation_tpl_component['VARIATION_VALUE'] = stripslashes($variation_attribute_def['VALUE']);
3230
+					$variation_tpl_component['VARIATION_ID'] = $variation_id;
3231
+					$variation_tpl_component['VARIATION_ATT_CODE'] = $variation_attribute_code;
3241 3232
 
3242
-        /**    Free Variation part    */
3243
-        if (!empty($product_definition_value['free_variation']) && is_array($product_definition_value['free_variation'])) {
3244
-            foreach ($product_definition_value['free_variation'] as $build_variation_key => $build_variation) {
3245
-                if (strpos($build_variation, '-_variation_val_-')) {
3246
-                    $variation_definition = explode('-_variation_val_-', $build_variation);
3247
-                    $attribute_code = $variation_definition[0];
3248
-                    $attribute_selected_value = $variation_definition[1];
3249
-                } else {
3250
-                    $attribute_code = $build_variation_key;
3251
-                    $attribute_selected_value = $build_variation;
3252
-                }
3253
-
3254
-                $free_variation_attribute_def = wpshop_attributes::getElement($attribute_code, "'valid'", 'code');
3255
-                $variation_tpl_component['VARIATION_NAME'] = stripslashes($free_variation_attribute_def->frontend_label);
3256
-                $value_to_outut = $attribute_selected_value;
3257
-                switch ($free_variation_attribute_def->data_type) {
3258
-                    case 'datetime':
3259
-                        $value_to_outut = mysql2date(get_option('date_format'), $attribute_selected_value, true);
3260
-                        break;
3261
-                }
3262
-
3263
-                if (in_array($free_variation_attribute_def->backend_input, array('select', 'multiple-select'))) {
3264
-                    switch ($free_variation_attribute_def->data_type_to_use) {
3265
-                        case 'custom':
3266
-                        case 'internal':
3267
-                            $possible_values = wpshop_attributes::get_select_output($free_variation_attribute_def);
3268
-                            $value_to_outut = $possible_values['possible_value'][$attribute_selected_value];
3269
-                            break;
3270
-                    }
3271
-                }
3272
-                $variation_tpl_component['VARIATION_VALUE'] = stripslashes($value_to_outut);
3273
-                $variation_tpl_component['VARIATION_ID'] = $attribute_code;
3274
-                $variation_tpl_component['VARIATION_ATT_CODE'] = $attribute_code;
3275
-                if (!empty($value_to_outut) && !empty($output_order[$free_variation_attribute_def->code])) {
3276
-                    $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);
3277
-                    if (!in_array($display_data, $variation_attribute_ordered['attribute_list'])) {
3278
-                        $variation_attribute_ordered['attribute_list'][$output_order[$free_variation_attribute_def->code]] = $display_data;
3279
-                    }
3280
-                }
3281
-                unset($variation_tpl_component);
3282
-            }
3283
-        }
3284
-        return $variation_attribute_ordered;
3285
-    }
3233
+					$variation_attribute_ordered['prices'][$variation_attribute_code] = $variation_tpl_component['VARIATION_DETAIL_PRODUCT_PRICE'];
3234
+				}
3235
+				if (!empty($output_order[$variation_attribute_code])) {
3236
+					$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);
3237
+				}
3238
+				unset($variation_tpl_component);
3239
+			}
3240
+		}
3286 3241
 
3287
-    public function wps_selected_variation_picture($head_product_id, $variations)
3288
-    {
3289
-        $response = array();
3290
-        /** Selected Product image **/
3291
-        $post_thumbnail_id = get_post_thumbnail_id($head_product_id);
3292
-        if (!empty($post_thumbnail_id)) {
3293
-            $response['img_id'] = $post_thumbnail_id;
3294
-            $response['img'] = wp_get_attachment_image($post_thumbnail_id, 'wpshop-product-galery');
3295
-            $response['img_url'] = wp_get_attachment_url($post_thumbnail_id);
3296
-        }
3242
+		/**    Free Variation part    */
3243
+		if (!empty($product_definition_value['free_variation']) && is_array($product_definition_value['free_variation'])) {
3244
+			foreach ($product_definition_value['free_variation'] as $build_variation_key => $build_variation) {
3245
+				if (strpos($build_variation, '-_variation_val_-')) {
3246
+					$variation_definition = explode('-_variation_val_-', $build_variation);
3247
+					$attribute_code = $variation_definition[0];
3248
+					$attribute_selected_value = $variation_definition[1];
3249
+				} else {
3250
+					$attribute_code = $build_variation_key;
3251
+					$attribute_selected_value = $build_variation;
3252
+				}
3297 3253
 
3298
-        /** check if have one variation **/
3299
-        if (!empty($variations) && count($variations) == 1) {
3300
-            $variation_attached_image_id = get_post_meta($variations[0], '_wps_variation_attached_picture', true);
3301
-            if (!empty($variation_attached_image_id)) {
3302
-                $response['img_id'] = $variation_attached_image_id;
3303
-                $response['img'] = wp_get_attachment_image($variation_attached_image_id, 'wpshop-product-galery');
3304
-                $response['img_url'] = wp_get_attachment_url($variation_attached_image_id);
3305
-            }
3306
-        }
3307
-        return $response;
3308
-    }
3254
+				$free_variation_attribute_def = wpshop_attributes::getElement($attribute_code, "'valid'", 'code');
3255
+				$variation_tpl_component['VARIATION_NAME'] = stripslashes($free_variation_attribute_def->frontend_label);
3256
+				$value_to_outut = $attribute_selected_value;
3257
+				switch ($free_variation_attribute_def->data_type) {
3258
+					case 'datetime':
3259
+						$value_to_outut = mysql2date(get_option('date_format'), $attribute_selected_value, true);
3260
+						break;
3261
+				}
3309 3262
 
3310
-    /** Add a meta box of product sales history in product administration panel **/
3311
-    public function meta_box_product_sale_informations()
3312
-    {
3313
-        global $post;
3314
-        $product_id = $post->ID;
3315
-
3316
-        $variations = self::get_variation($product_id);
3317
-
3318
-        $sales_informations = array();
3319
-        /** Query **/
3320
-        $data_to_compare = '"item_id";s:' . strlen($product_id) . ':"' . $product_id . '";';
3321
-        $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')));
3322
-        $orders = new WP_Query($query_args);
3323
-        if (!empty($orders) && !empty($orders->posts)) {
3324
-            foreach ($orders->posts as $order) {
3325
-                $order_meta = get_post_meta($order->ID, '_order_postmeta', true);
3326
-                $order_info = get_post_meta($order->ID, '_order_info', true);
3327
-                $sales_informations[] = array(
3328
-                    'order_key' => (!empty($order_meta) && !empty($order_meta['order_key'])) ? $order_meta['order_key'] : '',
3329
-                    'order_date' => (!empty($order_meta) && !empty($order_meta['order_date'])) ? $order_meta['order_date'] : '',
3330
-                    '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'] : '',
3331
-                    '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'] : '',
3332
-                    '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'] : '',
3333
-                );
3334
-            }
3335
-        }
3263
+				if (in_array($free_variation_attribute_def->backend_input, array('select', 'multiple-select'))) {
3264
+					switch ($free_variation_attribute_def->data_type_to_use) {
3265
+						case 'custom':
3266
+						case 'internal':
3267
+							$possible_values = wpshop_attributes::get_select_output($free_variation_attribute_def);
3268
+							$value_to_outut = $possible_values['possible_value'][$attribute_selected_value];
3269
+							break;
3270
+					}
3271
+				}
3272
+				$variation_tpl_component['VARIATION_VALUE'] = stripslashes($value_to_outut);
3273
+				$variation_tpl_component['VARIATION_ID'] = $attribute_code;
3274
+				$variation_tpl_component['VARIATION_ATT_CODE'] = $attribute_code;
3275
+				if (!empty($value_to_outut) && !empty($output_order[$free_variation_attribute_def->code])) {
3276
+					$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);
3277
+					if (!in_array($display_data, $variation_attribute_ordered['attribute_list'])) {
3278
+						$variation_attribute_ordered['attribute_list'][$output_order[$free_variation_attribute_def->code]] = $display_data;
3279
+					}
3280
+				}
3281
+				unset($variation_tpl_component);
3282
+			}
3283
+		}
3284
+		return $variation_attribute_ordered;
3285
+	}
3336 3286
 
3337
-        /** If product has been ordered **/
3338
-        $output = '';
3339
-        if (!empty($sales_informations)) {
3340
-            $output .= '<p>' . __('This product has been ordered', 'wpshop') . ' :</p>';
3341
-            $output .= '<ul>';
3342
-            foreach ($sales_informations as $sales_information) {
3343
-                $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>';
3344
-            }
3345
-            $output .= '</ul>';
3346
-        } else {
3347
-            $output .= __('This product has never been ordered', 'wpshop');
3348
-        }
3287
+	public function wps_selected_variation_picture($head_product_id, $variations)
3288
+	{
3289
+		$response = array();
3290
+		/** Selected Product image **/
3291
+		$post_thumbnail_id = get_post_thumbnail_id($head_product_id);
3292
+		if (!empty($post_thumbnail_id)) {
3293
+			$response['img_id'] = $post_thumbnail_id;
3294
+			$response['img'] = wp_get_attachment_image($post_thumbnail_id, 'wpshop-product-galery');
3295
+			$response['img_url'] = wp_get_attachment_url($post_thumbnail_id);
3296
+		}
3349 3297
 
3350
-        echo $output;
3351
-    }
3298
+		/** check if have one variation **/
3299
+		if (!empty($variations) && count($variations) == 1) {
3300
+			$variation_attached_image_id = get_post_meta($variations[0], '_wps_variation_attached_picture', true);
3301
+			if (!empty($variation_attached_image_id)) {
3302
+				$response['img_id'] = $variation_attached_image_id;
3303
+				$response['img'] = wp_get_attachment_image($variation_attached_image_id, 'wpshop-product-galery');
3304
+				$response['img_url'] = wp_get_attachment_url($variation_attached_image_id);
3305
+			}
3306
+		}
3307
+		return $response;
3308
+	}
3352 3309
 
3353
-    public function wps_get_summary_variations_product($product_id, $the_product, $has_variation)
3354
-    {
3355
-        global $wpdb, $wpshop_payment;
3356
-        $output = '';
3357
-        $tpl_component = array();
3358
-        /**    Get attribute order for current product    */
3359
-        $product_attribute_order_detail = wpshop_attributes_set::getAttributeSetDetails(get_post_meta($product_id, WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, true));
3360
-        $output_order = array();
3361
-        if (count($product_attribute_order_detail) > 0) {
3362
-            foreach ($product_attribute_order_detail as $product_attr_group_id => $product_attr_group_detail) {
3363
-                foreach ($product_attr_group_detail['attribut'] as $position => $attribute_def) {
3364
-                    if (!empty($attribute_def->code)) {
3365
-                        $output_order[$attribute_def->code] = $position;
3366
-                    }
3367
-
3368
-                }
3369
-            }
3370
-        }
3371
-        $variation_attribute_ordered = array();
3372
-
3373
-        /** Check if product is a variation and change his name **/
3374
-        $product_post_type = get_post_type($the_product['product_id']);
3375
-        if (!empty($product_post_type) && $product_post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) {
3376
-            $parent_infos = wpshop_products::get_parent_variation($the_product['product_id']);
3377
-            $parent_post = (!empty($parent_infos) && !empty($parent_infos['parent_post'])) ? $parent_infos['parent_post'] : array();
3378
-            $the_product['product_name'] = $the_product['post_title'] = $parent_post->post_title;
3379
-        }
3310
+	/** Add a meta box of product sales history in product administration panel **/
3311
+	public function meta_box_product_sale_informations()
3312
+	{
3313
+		global $post;
3314
+		$product_id = $post->ID;
3315
+
3316
+		$variations = self::get_variation($product_id);
3317
+
3318
+		$sales_informations = array();
3319
+		/** Query **/
3320
+		$data_to_compare = '"item_id";s:' . strlen($product_id) . ':"' . $product_id . '";';
3321
+		$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')));
3322
+		$orders = new WP_Query($query_args);
3323
+		if (!empty($orders) && !empty($orders->posts)) {
3324
+			foreach ($orders->posts as $order) {
3325
+				$order_meta = get_post_meta($order->ID, '_order_postmeta', true);
3326
+				$order_info = get_post_meta($order->ID, '_order_info', true);
3327
+				$sales_informations[] = array(
3328
+					'order_key' => (!empty($order_meta) && !empty($order_meta['order_key'])) ? $order_meta['order_key'] : '',
3329
+					'order_date' => (!empty($order_meta) && !empty($order_meta['order_date'])) ? $order_meta['order_date'] : '',
3330
+					'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'] : '',
3331
+					'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'] : '',
3332
+					'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'] : '',
3333
+				);
3334
+			}
3335
+		}
3380 3336
 
3381
-        foreach ($the_product as $product_definition_key => $product_definition_value) {
3382
-            if ($product_definition_key != 'item_meta') {
3383
-                $tpl_component['PRODUCT_MAIN_INFO_' . strtoupper($product_definition_key)] = $product_definition_value;
3384
-                if (!empty($wpshop_current_for_display) && in_array($product_definition_key, unserialize(WPSHOP_ATTRIBUTE_PRICES))) {
3385
-                    $tpl_component['PRODUCT_MAIN_INFO_' . strtoupper($product_definition_key)] = $product_definition_value;
3386
-                }
3387
-            } else {
3388
-                $variation_attribute_ordered = wpshop_products::get_selected_variation_display($product_definition_value, $output_order, 'selection_summary');
3389
-            }
3390
-        }
3337
+		/** If product has been ordered **/
3338
+		$output = '';
3339
+		if (!empty($sales_informations)) {
3340
+			$output .= '<p>' . __('This product has been ordered', 'wpshop') . ' :</p>';
3341
+			$output .= '<ul>';
3342
+			foreach ($sales_informations as $sales_information) {
3343
+				$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>';
3344
+			}
3345
+			$output .= '</ul>';
3346
+		} else {
3347
+			$output .= __('This product has never been ordered', 'wpshop');
3348
+		}
3391 3349
 
3392
-        ksort($variation_attribute_ordered['attribute_list']);
3393
-        $tpl_component['PRODUCT_VARIATION_SUMMARY_DETAILS'] = '';
3394
-        foreach ($variation_attribute_ordered['attribute_list'] as $attribute_variation_to_output) {
3395
-            $tpl_component['PRODUCT_VARIATION_SUMMARY_DETAILS'] .= $attribute_variation_to_output;
3396
-        }
3350
+		echo $output;
3351
+	}
3397 3352
 
3398
-        /**    For security get all attributes defined as user defined or used in variation in order to set default value to empty    */
3399
-        $attribute_list = wpshop_attributes::getElement('yes', "'valid'", "is_used_for_variation", true);
3400
-        if (!empty($attribute_list)) {
3401
-            foreach ($attribute_list as $attribute_def) {
3402
-                $tpl_component['VARIATION_SUMMARY_ATTRIBUTE_PER_PRICE_' . strtoupper($attribute_def->code)] = '-';
3403
-            }
3404
-        }
3353
+	public function wps_get_summary_variations_product($product_id, $the_product, $has_variation)
3354
+	{
3355
+		global $wpdb, $wpshop_payment;
3356
+		$output = '';
3357
+		$tpl_component = array();
3358
+		/**    Get attribute order for current product    */
3359
+		$product_attribute_order_detail = wpshop_attributes_set::getAttributeSetDetails(get_post_meta($product_id, WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, true));
3360
+		$output_order = array();
3361
+		if (count($product_attribute_order_detail) > 0) {
3362
+			foreach ($product_attribute_order_detail as $product_attr_group_id => $product_attr_group_detail) {
3363
+				foreach ($product_attr_group_detail['attribut'] as $position => $attribute_def) {
3364
+					if (!empty($attribute_def->code)) {
3365
+						$output_order[$attribute_def->code] = $position;
3366
+					}
3405 3367
 
3406
-        /**    Fill the array with all prices for different variations    */
3407
-        foreach ($variation_attribute_ordered['prices'] as $attribute => $prices) {
3408
-            $tpl_component['VARIATION_SUMMARY_ATTRIBUTE_PER_PRICE_' . strtoupper($attribute)] = $prices;
3409
-        }
3368
+				}
3369
+			}
3370
+		}
3371
+		$variation_attribute_ordered = array();
3372
+
3373
+		/** Check if product is a variation and change his name **/
3374
+		$product_post_type = get_post_type($the_product['product_id']);
3375
+		if (!empty($product_post_type) && $product_post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) {
3376
+			$parent_infos = wpshop_products::get_parent_variation($the_product['product_id']);
3377
+			$parent_post = (!empty($parent_infos) && !empty($parent_infos['parent_post'])) ? $parent_infos['parent_post'] : array();
3378
+			$the_product['product_name'] = $the_product['post_title'] = $parent_post->post_title;
3379
+		}
3410 3380
 
3411
-        $tpl_component['PRODUCT_VARIATION_SUMMARY_MORE_CONTENT'] = '';
3412
-        $query = $wpdb->prepare("SELECT post_id, meta_value FROM " . $wpdb->postmeta . " WHERE meta_key = %s ", '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_options');
3413
-        $post_list_with_options = $wpdb->get_results($query);
3414
-        if (!empty($post_list_with_options)) {
3415
-            $additionnal_price = 0;
3416
-            foreach ($post_list_with_options as $product_info) {
3417
-                $product_meta = unserialize($product_info->meta_value);
3418
-                if (!empty($product_meta['cart']) && !empty($product_meta['cart']['auto_add']) && ($product_meta['cart']['auto_add'] == 'yes')) {
3419
-                    $product = wpshop_products::get_product_data($product_info->post_id, true, '"publish", "draft"');
3420
-
3421
-                    $the_product = array_merge(array(
3422
-                        'product_id' => $product_info->post_id,
3423
-                        'product_qty' => 1,
3424
-                    ), $product);
3425
-
3426
-                    $additionnal_price += (!$different_currency || ($change_rate == 1)) ? $the_product['product_price'] : ($the_product['product_price'] * $change_rate);
3427
-                    $tpl_component['AUTO_PRODUCT_NAME'] = $the_product['product_name'];
3428
-
3429
-                    $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));
3430
-                    $tpl_component['PRODUCT_VARIATION_SUMMARY_MORE_CONTENT'] = wpshop_display::display_template_element('wpshop_product_configuration_summary_detail_auto_product', $tpl_component);
3431
-                }
3432
-            }
3433
-        }
3381
+		foreach ($the_product as $product_definition_key => $product_definition_value) {
3382
+			if ($product_definition_key != 'item_meta') {
3383
+				$tpl_component['PRODUCT_MAIN_INFO_' . strtoupper($product_definition_key)] = $product_definition_value;
3384
+				if (!empty($wpshop_current_for_display) && in_array($product_definition_key, unserialize(WPSHOP_ATTRIBUTE_PRICES))) {
3385
+					$tpl_component['PRODUCT_MAIN_INFO_' . strtoupper($product_definition_key)] = $product_definition_value;
3386
+				}
3387
+			} else {
3388
+				$variation_attribute_ordered = wpshop_products::get_selected_variation_display($product_definition_value, $output_order, 'selection_summary');
3389
+			}
3390
+		}
3434 3391
 
3435
-        $tpl_component['PRODUCT_VARIATION_SUMMARY_GRAND_TOTAL'] = '';
3436
-        $tpl_component['SUMMARY_FINAL_RESULT_PRICE_NO_FORMAT'] = '';
3437
-        if (!empty($additionnal_price)) {
3438
-            $tpl_component['SUMMARY_FINAL_RESULT_PRICE'] = wpshop_display::format_field_output('wpshop_product_price', $tpl_component['PRODUCT_MAIN_INFO_PRODUCT_PRICE'] + $additionnal_price);
3439
-            $tpl_component['SUMMARY_FINAL_RESULT_PRICE_NO_FORMAT'] = ($tpl_component['PRODUCT_MAIN_INFO_PRODUCT_PRICE'] + $additionnal_price);
3440
-            $tpl_component['PRODUCT_VARIATION_SUMMARY_GRAND_TOTAL'] = wpshop_display::display_template_element('wpshop_product_configuration_summary_detail_final_result', $tpl_component);
3441
-        }
3392
+		ksort($variation_attribute_ordered['attribute_list']);
3393
+		$tpl_component['PRODUCT_VARIATION_SUMMARY_DETAILS'] = '';
3394
+		foreach ($variation_attribute_ordered['attribute_list'] as $attribute_variation_to_output) {
3395
+			$tpl_component['PRODUCT_VARIATION_SUMMARY_DETAILS'] .= $attribute_variation_to_output;
3396
+		}
3442 3397
 
3443
-        /**    Call informtion for partial payment    */
3444
-        $partial_payment = $wpshop_payment->partial_payment_calcul($tpl_component['SUMMARY_FINAL_RESULT_PRICE_NO_FORMAT']);
3445
-        $tpl_component['PARTIAL_PAYMENT_INFO'] = !empty($partial_payment['amount_to_pay']) ? $partial_payment['display'] : '';
3398
+		/**    For security get all attributes defined as user defined or used in variation in order to set default value to empty    */
3399
+		$attribute_list = wpshop_attributes::getElement('yes', "'valid'", "is_used_for_variation", true);
3400
+		if (!empty($attribute_list)) {
3401
+			foreach ($attribute_list as $attribute_def) {
3402
+				$tpl_component['VARIATION_SUMMARY_ATTRIBUTE_PER_PRICE_' . strtoupper($attribute_def->code)] = '-';
3403
+			}
3404
+		}
3446 3405
 
3447
-        /**    Define the current selected currency for the order summary    */
3406
+		/**    Fill the array with all prices for different variations    */
3407
+		foreach ($variation_attribute_ordered['prices'] as $attribute => $prices) {
3408
+			$tpl_component['VARIATION_SUMMARY_ATTRIBUTE_PER_PRICE_' . strtoupper($attribute)] = $prices;
3409
+		}
3410
+
3411
+		$tpl_component['PRODUCT_VARIATION_SUMMARY_MORE_CONTENT'] = '';
3412
+		$query = $wpdb->prepare("SELECT post_id, meta_value FROM " . $wpdb->postmeta . " WHERE meta_key = %s ", '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_options');
3413
+		$post_list_with_options = $wpdb->get_results($query);
3414
+		if (!empty($post_list_with_options)) {
3415
+			$additionnal_price = 0;
3416
+			foreach ($post_list_with_options as $product_info) {
3417
+				$product_meta = unserialize($product_info->meta_value);
3418
+				if (!empty($product_meta['cart']) && !empty($product_meta['cart']['auto_add']) && ($product_meta['cart']['auto_add'] == 'yes')) {
3419
+					$product = wpshop_products::get_product_data($product_info->post_id, true, '"publish", "draft"');
3420
+
3421
+					$the_product = array_merge(array(
3422
+						'product_id' => $product_info->post_id,
3423
+						'product_qty' => 1,
3424
+					), $product);
3425
+
3426
+					$additionnal_price += (!$different_currency || ($change_rate == 1)) ? $the_product['product_price'] : ($the_product['product_price'] * $change_rate);
3427
+					$tpl_component['AUTO_PRODUCT_NAME'] = $the_product['product_name'];
3428
+
3429
+					$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));
3430
+					$tpl_component['PRODUCT_VARIATION_SUMMARY_MORE_CONTENT'] = wpshop_display::display_template_element('wpshop_product_configuration_summary_detail_auto_product', $tpl_component);
3431
+				}
3432
+			}
3433
+		}
3434
+
3435
+		$tpl_component['PRODUCT_VARIATION_SUMMARY_GRAND_TOTAL'] = '';
3436
+		$tpl_component['SUMMARY_FINAL_RESULT_PRICE_NO_FORMAT'] = '';
3437
+		if (!empty($additionnal_price)) {
3438
+			$tpl_component['SUMMARY_FINAL_RESULT_PRICE'] = wpshop_display::format_field_output('wpshop_product_price', $tpl_component['PRODUCT_MAIN_INFO_PRODUCT_PRICE'] + $additionnal_price);
3439
+			$tpl_component['SUMMARY_FINAL_RESULT_PRICE_NO_FORMAT'] = ($tpl_component['PRODUCT_MAIN_INFO_PRODUCT_PRICE'] + $additionnal_price);
3440
+			$tpl_component['PRODUCT_VARIATION_SUMMARY_GRAND_TOTAL'] = wpshop_display::display_template_element('wpshop_product_configuration_summary_detail_final_result', $tpl_component);
3441
+		}
3442
+
3443
+		/**    Call informtion for partial payment    */
3444
+		$partial_payment = $wpshop_payment->partial_payment_calcul($tpl_component['SUMMARY_FINAL_RESULT_PRICE_NO_FORMAT']);
3445
+		$tpl_component['PARTIAL_PAYMENT_INFO'] = !empty($partial_payment['amount_to_pay']) ? $partial_payment['display'] : '';
3446
+
3447
+		/**    Define the current selected currency for the order summary    */
3448 3448
 //         $response['product_output'] = $has_variation ? wpshop_display::display_template_element('wpshop_product_configuration_summary_detail', $tpl_component) : '';
3449
-        $output = $has_variation ? wpshop_display::display_template_element('wpshop_product_configuration_summary_detail', $tpl_component) : '';
3450
-        return $output;
3451
-    }
3449
+		$output = $has_variation ? wpshop_display::display_template_element('wpshop_product_configuration_summary_detail', $tpl_component) : '';
3450
+		return $output;
3451
+	}
3452 3452
 
3453
-    /**
3454
-     * Get product ID if ID = "id-parent__id-variation" or "id-variation" or "id-parent"
3455
-     * @param string $ID ID product variations or not
3456
-     * @return string Return ID
3457
-     */
3458
-    public static function get_id_variation($ID)
3459
-    {
3460
-        $result = explode('__', $ID);
3461
-        return end($result);
3462
-    }
3453
+	/**
3454
+	 * Get product ID if ID = "id-parent__id-variation" or "id-variation" or "id-parent"
3455
+	 * @param string $ID ID product variations or not
3456
+	 * @return string Return ID
3457
+	 */
3458
+	public static function get_id_variation($ID)
3459
+	{
3460
+		$result = explode('__', $ID);
3461
+		return end($result);
3462
+	}
3463 3463
 
3464
-    /**
3465
-     * Update all variations definitions who not modified
3466
-     * @param array $new_value
3467
-     * @param array $old_value
3468
-     * @return array $new_value
3469
-     */
3470
-    public static function update_wpshop_catalog_product_option($new_value, $old_value)
3471
-    {
3472
-        global $wpdb;
3473
-        $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') . '%');
3474
-        foreach ($wpdb->get_results($query) as $wpshop_variation_defining) {
3475
-            $wpshop_variation_defining_value = unserialize($wpshop_variation_defining->meta_value);
3476
-            $wpshop_variation_defining_value['options']['price_display'] = $new_value['price_display'];
3477
-            update_post_meta($wpshop_variation_defining->post_id, '_wpshop_variation_defining', $wpshop_variation_defining_value);
3478
-        }
3479
-        return $new_value;
3480
-    }
3464
+	/**
3465
+	 * Update all variations definitions who not modified
3466
+	 * @param array $new_value
3467
+	 * @param array $old_value
3468
+	 * @return array $new_value
3469
+	 */
3470
+	public static function update_wpshop_catalog_product_option($new_value, $old_value)
3471
+	{
3472
+		global $wpdb;
3473
+		$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') . '%');
3474
+		foreach ($wpdb->get_results($query) as $wpshop_variation_defining) {
3475
+			$wpshop_variation_defining_value = unserialize($wpshop_variation_defining->meta_value);
3476
+			$wpshop_variation_defining_value['options']['price_display'] = $new_value['price_display'];
3477
+			update_post_meta($wpshop_variation_defining->post_id, '_wpshop_variation_defining', $wpshop_variation_defining_value);
3478
+		}
3479
+		return $new_value;
3480
+	}
3481 3481
 
3482
-    public static function variation_parameters_save($current_post_id, $options)
3483
-    {
3482
+	public static function variation_parameters_save($current_post_id, $options)
3483
+	{
3484 3484
 		$variation_post_meta = get_post_meta($current_post_id, '_wpshop_variation_defining', true);
3485
-        $variation_post_meta['options'] = $options;
3485
+		$variation_post_meta['options'] = $options;
3486 3486
 		$variation_post_meta['follow_general_config'] = true;
3487 3487
 		$variations = wpshop_attributes::get_variation_available_attribute($current_post_id);
3488 3488
 		if( !empty( $variations['available'] ) ) {
@@ -3492,6 +3492,6 @@  discard block
 block discarded – undo
3492 3492
 				}
3493 3493
 			}
3494 3494
 		}
3495
-        update_post_meta($current_post_id, '_wpshop_variation_defining', $variation_post_meta);
3496
-    }
3495
+		update_post_meta($current_post_id, '_wpshop_variation_defining', $variation_post_meta);
3496
+	}
3497 3497
 }
Please login to merge, or discard this patch.