@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php if (!defined('ABSPATH')) { |
| 2 | - exit; |
|
| 2 | + exit; |
|
| 3 | 3 | } |
| 4 | 4 | |
| 5 | 5 | /** |
@@ -14,7 +14,7 @@ discard block |
||
| 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 | /** |
@@ -25,156 +25,156 @@ discard block |
||
| 25 | 25 | * @subpackage librairies |
| 26 | 26 | */ |
| 27 | 27 | class wpshop_products { |
| 28 | - /** |
|
| 29 | - * Définition du code de la classe courante |
|
| 30 | - */ |
|
| 31 | - const currentPageCode = WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT; |
|
| 32 | - const current_page_variation_code = WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION; |
|
| 33 | - |
|
| 34 | - public function add_product_to_current_order_interface() |
|
| 35 | - { |
|
| 36 | - $output = ''; |
|
| 37 | - $output .= self::products_list_js(); |
|
| 38 | - $output .= '<input type="text" id="wps_order_search_product" />'; |
|
| 39 | - echo $output; |
|
| 40 | - die(); |
|
| 41 | - } |
|
| 28 | + /** |
|
| 29 | + * Définition du code de la classe courante |
|
| 30 | + */ |
|
| 31 | + const currentPageCode = WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT; |
|
| 32 | + const current_page_variation_code = WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION; |
|
| 33 | + |
|
| 34 | + public function add_product_to_current_order_interface() |
|
| 35 | + { |
|
| 36 | + $output = ''; |
|
| 37 | + $output .= self::products_list_js(); |
|
| 38 | + $output .= '<input type="text" id="wps_order_search_product" />'; |
|
| 39 | + echo $output; |
|
| 40 | + die(); |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - public function products_list_js() |
|
| 44 | - { |
|
| 45 | - global $wpdb; |
|
| 46 | - $products_post = get_posts(array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'post_status' => 'publish', 'posts_per_page' => -1)); |
|
| 47 | - |
|
| 48 | - if (!empty($products_post)) { |
|
| 49 | - $products_js_array = 'var products = ['; |
|
| 50 | - foreach ($products_post as $product) { |
|
| 51 | - $barcode = get_post_meta($product->ID, '_barcode', true); |
|
| 52 | - $products_js_array .= '{label:"#' . $product->ID . ' ' . str_replace('"', '', $product->post_title) . ' - ' . ((!empty($barcode)) ? $barcode : '') . '", '; |
|
| 53 | - $products_js_array .= 'value:"' . $product->ID . '", '; |
|
| 54 | - $products_js_array .= (!empty($barcode)) ? 'desc:"' . $barcode . '"},' : '},'; |
|
| 55 | - } |
|
| 56 | - $products_js_array .= '];'; |
|
| 57 | - } |
|
| 58 | - $output = wpshop_display::display_template_element('wps_orders_products_list_js', array('PRODUCTS_JS_ARRAY' => $products_js_array), array(), 'admin'); |
|
| 59 | - return $output; |
|
| 60 | - } |
|
| 43 | + public function products_list_js() |
|
| 44 | + { |
|
| 45 | + global $wpdb; |
|
| 46 | + $products_post = get_posts(array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'post_status' => 'publish', 'posts_per_page' => -1)); |
|
| 47 | + |
|
| 48 | + if (!empty($products_post)) { |
|
| 49 | + $products_js_array = 'var products = ['; |
|
| 50 | + foreach ($products_post as $product) { |
|
| 51 | + $barcode = get_post_meta($product->ID, '_barcode', true); |
|
| 52 | + $products_js_array .= '{label:"#' . $product->ID . ' ' . str_replace('"', '', $product->post_title) . ' - ' . ((!empty($barcode)) ? $barcode : '') . '", '; |
|
| 53 | + $products_js_array .= 'value:"' . $product->ID . '", '; |
|
| 54 | + $products_js_array .= (!empty($barcode)) ? 'desc:"' . $barcode . '"},' : '},'; |
|
| 55 | + } |
|
| 56 | + $products_js_array .= '];'; |
|
| 57 | + } |
|
| 58 | + $output = wpshop_display::display_template_element('wps_orders_products_list_js', array('PRODUCTS_JS_ARRAY' => $products_js_array), array(), 'admin'); |
|
| 59 | + return $output; |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - /** |
|
| 63 | - * Déclaration des produits et variations en tant que "post" de wordpress |
|
| 64 | - * |
|
| 65 | - * @see register_post_type() |
|
| 66 | - */ |
|
| 67 | - public static function create_wpshop_products_type() |
|
| 68 | - { |
|
| 69 | - |
|
| 70 | - $options = get_option('wpshop_catalog_product_option', array()); |
|
| 71 | - //$options2 = get_option('wpshop_catalog_categories_option', array()); |
|
| 72 | - /*echo '<pre>'; print_r( $options ); echo '</pre>'; |
|
| 62 | + /** |
|
| 63 | + * Déclaration des produits et variations en tant que "post" de wordpress |
|
| 64 | + * |
|
| 65 | + * @see register_post_type() |
|
| 66 | + */ |
|
| 67 | + public static function create_wpshop_products_type() |
|
| 68 | + { |
|
| 69 | + |
|
| 70 | + $options = get_option('wpshop_catalog_product_option', array()); |
|
| 71 | + //$options2 = get_option('wpshop_catalog_categories_option', array()); |
|
| 72 | + /*echo '<pre>'; print_r( $options ); echo '</pre>'; |
|
| 73 | 73 | echo '<pre>'; print_r( $options2 ); echo '</pre>'; exit();*/ |
| 74 | 74 | |
| 75 | - $slug = array( |
|
| 76 | - 'slug' => '', |
|
| 77 | - 'with_front' => false, |
|
| 78 | - ); |
|
| 79 | - |
|
| 80 | - if (empty($options['wpshop_catalog_product_slug']) || $options['wpshop_catalog_product_slug'] == '/') { |
|
| 81 | - $slug = false; |
|
| 82 | - } else { |
|
| 83 | - $slug['slug'] = $options['wpshop_catalog_product_slug']; |
|
| 84 | - if (!empty($options['wpshop_catalog_product_slug_with_category'])) { |
|
| 85 | - $slug['slug'] .= '/%' . WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES . '%'; |
|
| 86 | - } |
|
| 87 | - } |
|
| 88 | - /*$product_slug .= '/%' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '%';*/ |
|
| 89 | - |
|
| 90 | - /* Définition des produits */ |
|
| 91 | - register_post_type(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, apply_filters(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_register', array( |
|
| 92 | - 'labels' => array( |
|
| 93 | - 'name' => __('Products', 'wpshop'), |
|
| 94 | - 'singular_name' => __('Catalog', 'wpshop'), |
|
| 95 | - 'add_new_item' => __('Add new product', 'wpshop'), |
|
| 96 | - 'add_new' => __('Add new product', 'wpshop'), |
|
| 97 | - 'add_new_item' => __('Add new product', 'wpshop'), |
|
| 98 | - 'edit_item' => __('Edit product', 'wpshop'), |
|
| 99 | - 'new_item' => __('New product', 'wpshop'), |
|
| 100 | - 'view_item' => __('View product', 'wpshop'), |
|
| 101 | - 'search_items' => __('Search products', 'wpshop'), |
|
| 102 | - 'not_found' => __('No products found', 'wpshop'), |
|
| 103 | - 'not_found_in_trash' => __('No products found in Trash', 'wpshop'), |
|
| 104 | - 'parent_item_colon' => '', |
|
| 105 | - ), |
|
| 106 | - 'supports' => unserialize(WPSHOP_REGISTER_POST_TYPE_SUPPORT), |
|
| 107 | - 'public' => true, |
|
| 108 | - 'has_archive' => true, |
|
| 109 | - 'show_in_nav_menus' => true, |
|
| 110 | - //'rewrite' => false, // For information see below |
|
| 111 | - 'taxonomies' => array(WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES), |
|
| 112 | - 'menu_icon' => 'dashicons-archive', |
|
| 113 | - 'rewrite' => $slug, |
|
| 114 | - ))); |
|
| 115 | - |
|
| 116 | - /* Définition des variations de produit (Déclinaisons) */ |
|
| 117 | - register_post_type(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, apply_filters(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION . '_register', array( |
|
| 118 | - 'labels' => array( |
|
| 119 | - 'name' => __('Variations', 'wpshop'), |
|
| 120 | - 'singular_name' => __('Variation', 'wpshop'), |
|
| 121 | - 'add_new' => __('Add Variation', 'wpshop'), |
|
| 122 | - 'add_new_item' => __('Add New Variation', 'wpshop'), |
|
| 123 | - 'edit' => __('Edit', 'wpshop'), |
|
| 124 | - 'edit_item' => __('Edit Variation', 'wpshop'), |
|
| 125 | - 'new_item' => __('New Variation', 'wpshop'), |
|
| 126 | - 'view' => __('View Variation', 'wpshop'), |
|
| 127 | - 'view_item' => __('View Variation', 'wpshop'), |
|
| 128 | - 'search_items' => __('Search Variations', 'wpshop'), |
|
| 129 | - 'not_found' => __('No Variations found', 'wpshop'), |
|
| 130 | - 'not_found_in_trash' => __('No Variations found in trash', 'wpshop'), |
|
| 131 | - 'parent_item_colon' => '', |
|
| 132 | - ), |
|
| 133 | - 'supports' => unserialize(WPSHOP_REGISTER_POST_TYPE_SUPPORT), |
|
| 134 | - 'public' => true, |
|
| 135 | - 'has_archive' => true, |
|
| 136 | - 'show_in_nav_menus' => false, |
|
| 137 | - 'show_in_menu' => false, //'edit.php?post_type=' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, |
|
| 138 | - |
|
| 139 | - 'publicly_queryable' => false, |
|
| 140 | - 'exclude_from_search' => true, |
|
| 141 | - 'hierarchical' => false, |
|
| 142 | - |
|
| 143 | - // 'public' => true, |
|
| 144 | - // 'show_ui' => false, |
|
| 145 | - // 'rewrite' => false, |
|
| 146 | - // 'query_var' => true, |
|
| 147 | - // 'supports' => array( 'title', 'editor', 'page-attributes', 'thumbnail' ), |
|
| 148 | - // 'show_in_nav_menus' => false |
|
| 149 | - ) |
|
| 150 | - )); |
|
| 151 | - |
|
| 152 | - // add to our plugin init function |
|
| 153 | - //global $wp_rewrite; |
|
| 154 | - /* Slug url is set into option */ |
|
| 155 | - /*$options = get_option('wpshop_catalog_product_option', array()); |
|
| 75 | + $slug = array( |
|
| 76 | + 'slug' => '', |
|
| 77 | + 'with_front' => false, |
|
| 78 | + ); |
|
| 79 | + |
|
| 80 | + if (empty($options['wpshop_catalog_product_slug']) || $options['wpshop_catalog_product_slug'] == '/') { |
|
| 81 | + $slug = false; |
|
| 82 | + } else { |
|
| 83 | + $slug['slug'] = $options['wpshop_catalog_product_slug']; |
|
| 84 | + if (!empty($options['wpshop_catalog_product_slug_with_category'])) { |
|
| 85 | + $slug['slug'] .= '/%' . WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES . '%'; |
|
| 86 | + } |
|
| 87 | + } |
|
| 88 | + /*$product_slug .= '/%' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '%';*/ |
|
| 89 | + |
|
| 90 | + /* Définition des produits */ |
|
| 91 | + register_post_type(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, apply_filters(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_register', array( |
|
| 92 | + 'labels' => array( |
|
| 93 | + 'name' => __('Products', 'wpshop'), |
|
| 94 | + 'singular_name' => __('Catalog', 'wpshop'), |
|
| 95 | + 'add_new_item' => __('Add new product', 'wpshop'), |
|
| 96 | + 'add_new' => __('Add new product', 'wpshop'), |
|
| 97 | + 'add_new_item' => __('Add new product', 'wpshop'), |
|
| 98 | + 'edit_item' => __('Edit product', 'wpshop'), |
|
| 99 | + 'new_item' => __('New product', 'wpshop'), |
|
| 100 | + 'view_item' => __('View product', 'wpshop'), |
|
| 101 | + 'search_items' => __('Search products', 'wpshop'), |
|
| 102 | + 'not_found' => __('No products found', 'wpshop'), |
|
| 103 | + 'not_found_in_trash' => __('No products found in Trash', 'wpshop'), |
|
| 104 | + 'parent_item_colon' => '', |
|
| 105 | + ), |
|
| 106 | + 'supports' => unserialize(WPSHOP_REGISTER_POST_TYPE_SUPPORT), |
|
| 107 | + 'public' => true, |
|
| 108 | + 'has_archive' => true, |
|
| 109 | + 'show_in_nav_menus' => true, |
|
| 110 | + //'rewrite' => false, // For information see below |
|
| 111 | + 'taxonomies' => array(WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES), |
|
| 112 | + 'menu_icon' => 'dashicons-archive', |
|
| 113 | + 'rewrite' => $slug, |
|
| 114 | + ))); |
|
| 115 | + |
|
| 116 | + /* Définition des variations de produit (Déclinaisons) */ |
|
| 117 | + register_post_type(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, apply_filters(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION . '_register', array( |
|
| 118 | + 'labels' => array( |
|
| 119 | + 'name' => __('Variations', 'wpshop'), |
|
| 120 | + 'singular_name' => __('Variation', 'wpshop'), |
|
| 121 | + 'add_new' => __('Add Variation', 'wpshop'), |
|
| 122 | + 'add_new_item' => __('Add New Variation', 'wpshop'), |
|
| 123 | + 'edit' => __('Edit', 'wpshop'), |
|
| 124 | + 'edit_item' => __('Edit Variation', 'wpshop'), |
|
| 125 | + 'new_item' => __('New Variation', 'wpshop'), |
|
| 126 | + 'view' => __('View Variation', 'wpshop'), |
|
| 127 | + 'view_item' => __('View Variation', 'wpshop'), |
|
| 128 | + 'search_items' => __('Search Variations', 'wpshop'), |
|
| 129 | + 'not_found' => __('No Variations found', 'wpshop'), |
|
| 130 | + 'not_found_in_trash' => __('No Variations found in trash', 'wpshop'), |
|
| 131 | + 'parent_item_colon' => '', |
|
| 132 | + ), |
|
| 133 | + 'supports' => unserialize(WPSHOP_REGISTER_POST_TYPE_SUPPORT), |
|
| 134 | + 'public' => true, |
|
| 135 | + 'has_archive' => true, |
|
| 136 | + 'show_in_nav_menus' => false, |
|
| 137 | + 'show_in_menu' => false, //'edit.php?post_type=' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, |
|
| 138 | + |
|
| 139 | + 'publicly_queryable' => false, |
|
| 140 | + 'exclude_from_search' => true, |
|
| 141 | + 'hierarchical' => false, |
|
| 142 | + |
|
| 143 | + // 'public' => true, |
|
| 144 | + // 'show_ui' => false, |
|
| 145 | + // 'rewrite' => false, |
|
| 146 | + // 'query_var' => true, |
|
| 147 | + // 'supports' => array( 'title', 'editor', 'page-attributes', 'thumbnail' ), |
|
| 148 | + // 'show_in_nav_menus' => false |
|
| 149 | + ) |
|
| 150 | + )); |
|
| 151 | + |
|
| 152 | + // add to our plugin init function |
|
| 153 | + //global $wp_rewrite; |
|
| 154 | + /* Slug url is set into option */ |
|
| 155 | + /*$options = get_option('wpshop_catalog_product_option', array()); |
|
| 156 | 156 | $gallery_structure = (!empty($options['wpshop_catalog_product_slug']) ? $options['wpshop_catalog_product_slug'] : 'catalog'); |
| 157 | 157 | $gallery_structure .= !empty($options['wpshop_catalog_product_slug_with_category']) ? '/%' . WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES . '%' : ''; |
| 158 | 158 | $gallery_structure .= '/%' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '%'; |
| 159 | 159 | $wp_rewrite->add_permastruct(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, $gallery_structure, false); |
| 160 | 160 | $wp_rewrite->add_rewrite_tag('%' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '%', '([^/]+)', WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . "=");*/ |
| 161 | - // flush_rewrite_rules(); |
|
| 162 | - } |
|
| 161 | + // flush_rewrite_rules(); |
|
| 162 | + } |
|
| 163 | 163 | |
| 164 | - public static function hidden_meta_boxes($hidden, $screen, $use_defaults) |
|
| 165 | - { |
|
| 166 | - global $wpdb; |
|
| 167 | - if (WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT === $screen->post_type) { |
|
| 168 | - $user_meta_for_wpshop = array('metaboxhidden_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT); |
|
| 169 | - foreach ($user_meta_for_wpshop as $meta_to_check) { |
|
| 170 | - $metas_hidden = get_user_meta(get_current_user_id(), $meta_to_check, true); |
|
| 171 | - if (empty($metas_hidden) && !is_array($metas_hidden)) { |
|
| 172 | - $hidden = unserialize(WPSHOP_PRODUCT_HIDDEN_METABOX); |
|
| 173 | - } |
|
| 174 | - } |
|
| 175 | - } |
|
| 176 | - return $hidden; |
|
| 177 | - } |
|
| 164 | + public static function hidden_meta_boxes($hidden, $screen, $use_defaults) |
|
| 165 | + { |
|
| 166 | + global $wpdb; |
|
| 167 | + if (WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT === $screen->post_type) { |
|
| 168 | + $user_meta_for_wpshop = array('metaboxhidden_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT); |
|
| 169 | + foreach ($user_meta_for_wpshop as $meta_to_check) { |
|
| 170 | + $metas_hidden = get_user_meta(get_current_user_id(), $meta_to_check, true); |
|
| 171 | + if (empty($metas_hidden) && !is_array($metas_hidden)) { |
|
| 172 | + $hidden = unserialize(WPSHOP_PRODUCT_HIDDEN_METABOX); |
|
| 173 | + } |
|
| 174 | + } |
|
| 175 | + } |
|
| 176 | + return $hidden; |
|
| 177 | + } |
|
| 178 | 178 | |
| 179 | 179 | public static function admin_menu() { |
| 180 | 180 | global $submenu; |
@@ -201,35 +201,35 @@ discard block |
||
| 201 | 201 | $submenu['edit.php?post_type=wpshop_product'] = $submenu_reorder; |
| 202 | 202 | } |
| 203 | 203 | |
| 204 | - /** |
|
| 205 | - * Create the different bow for the product management page looking for the attribute set to create the different boxes |
|
| 206 | - */ |
|
| 207 | - public static function add_meta_boxes() |
|
| 208 | - { |
|
| 209 | - global $post, $currentTabContent; |
|
| 210 | - |
|
| 211 | - if (!empty($post->post_type) && (($post->post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT) || ($post->post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION))) { |
|
| 212 | - /* Get the attribute set list for the current entity */ |
|
| 213 | - $attributeEntitySetList = wpshop_attributes_set::get_attribute_set_list_for_entity(wpshop_entities::get_entity_identifier_from_code(self::currentPageCode)); |
|
| 214 | - /* Check if the meta information of the current product already exists */ |
|
| 215 | - $post_attribute_set_id = get_post_meta($post->ID, WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, true); |
|
| 216 | - /* Check if the product has been saved without meta information set */ |
|
| 217 | - $attribute_set_id = wpshop_attributes::get_attribute_value_content('product_attribute_set_id', $post->ID, self::currentPageCode); |
|
| 218 | - /* Unset 'free_product' from list of attributes set */ |
|
| 219 | - foreach ($attributeEntitySetList as $key_attribute_set => $attribute_set) { |
|
| 220 | - if ($attribute_set->slug == 'free_product') { |
|
| 221 | - unset($attributeEntitySetList[$key_attribute_set]); |
|
| 222 | - break; |
|
| 223 | - } |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - /* Check if an attribute has already been choosen for the curernt entity or if the user has to choose a entity set before continuing */ |
|
| 227 | - if (((count($attributeEntitySetList) == 1) || ((count($attributeEntitySetList) > 1) && (($post_attribute_set_id > 0) || (isset($attribute_set_id->value) && ($attribute_set_id->value > 0)))))) { |
|
| 228 | - if ((count($attributeEntitySetList) == 1) || (($post_attribute_set_id <= 0) && ($attribute_set_id->value <= 0))) { |
|
| 229 | - $post_attribute_set_id = $attributeEntitySetList[0]->id; |
|
| 230 | - } elseif (($post_attribute_set_id <= 0) && ($attribute_set_id->value > 0)) { |
|
| 231 | - $post_attribute_set_id = $attribute_set_id->value; |
|
| 232 | - } |
|
| 204 | + /** |
|
| 205 | + * Create the different bow for the product management page looking for the attribute set to create the different boxes |
|
| 206 | + */ |
|
| 207 | + public static function add_meta_boxes() |
|
| 208 | + { |
|
| 209 | + global $post, $currentTabContent; |
|
| 210 | + |
|
| 211 | + if (!empty($post->post_type) && (($post->post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT) || ($post->post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION))) { |
|
| 212 | + /* Get the attribute set list for the current entity */ |
|
| 213 | + $attributeEntitySetList = wpshop_attributes_set::get_attribute_set_list_for_entity(wpshop_entities::get_entity_identifier_from_code(self::currentPageCode)); |
|
| 214 | + /* Check if the meta information of the current product already exists */ |
|
| 215 | + $post_attribute_set_id = get_post_meta($post->ID, WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, true); |
|
| 216 | + /* Check if the product has been saved without meta information set */ |
|
| 217 | + $attribute_set_id = wpshop_attributes::get_attribute_value_content('product_attribute_set_id', $post->ID, self::currentPageCode); |
|
| 218 | + /* Unset 'free_product' from list of attributes set */ |
|
| 219 | + foreach ($attributeEntitySetList as $key_attribute_set => $attribute_set) { |
|
| 220 | + if ($attribute_set->slug == 'free_product') { |
|
| 221 | + unset($attributeEntitySetList[$key_attribute_set]); |
|
| 222 | + break; |
|
| 223 | + } |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + /* Check if an attribute has already been choosen for the curernt entity or if the user has to choose a entity set before continuing */ |
|
| 227 | + if (((count($attributeEntitySetList) == 1) || ((count($attributeEntitySetList) > 1) && (($post_attribute_set_id > 0) || (isset($attribute_set_id->value) && ($attribute_set_id->value > 0)))))) { |
|
| 228 | + if ((count($attributeEntitySetList) == 1) || (($post_attribute_set_id <= 0) && ($attribute_set_id->value <= 0))) { |
|
| 229 | + $post_attribute_set_id = $attributeEntitySetList[0]->id; |
|
| 230 | + } elseif (($post_attribute_set_id <= 0) && ($attribute_set_id->value > 0)) { |
|
| 231 | + $post_attribute_set_id = $attribute_set_id->value; |
|
| 232 | + } |
|
| 233 | 233 | |
| 234 | 234 | /*$post_attribute_set_id = (int) get_post_meta($post->ID, WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, true); |
| 235 | 235 | |
@@ -247,47 +247,47 @@ discard block |
||
| 247 | 247 | } |
| 248 | 248 | }*/ |
| 249 | 249 | |
| 250 | - $currentTabContent = wpshop_attributes::entities_attribute_box($post_attribute_set_id, self::currentPageCode, $post->ID); |
|
| 251 | - |
|
| 252 | - $fixed_box_exist = false; |
|
| 253 | - /* Get all the other attribute set for hte current entity */ |
|
| 254 | - if (isset($currentTabContent['box']) && count($currentTabContent['box']) > 0) { |
|
| 255 | - foreach ($currentTabContent['box'] as $boxIdentifier => $boxTitle) { |
|
| 256 | - if (!empty($currentTabContent['box'][$boxIdentifier . '_backend_display_type']) && ($currentTabContent['box'][$boxIdentifier . '_backend_display_type'] == 'movable-tab')) { |
|
| 257 | - add_meta_box('wpshop_product_' . $boxIdentifier, __($boxTitle, 'wpshop'), array('wpshop_products', 'meta_box_content'), WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'normal', 'default', array('boxIdentifier' => $boxIdentifier)); |
|
| 258 | - } else { |
|
| 259 | - $fixed_box_exist = true; |
|
| 260 | - } |
|
| 261 | - |
|
| 262 | - } |
|
| 263 | - } |
|
| 264 | - if ($fixed_box_exist) { |
|
| 265 | - 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)); |
|
| 266 | - 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)); |
|
| 267 | - } |
|
| 268 | - |
|
| 269 | - add_meta_box('wpshop_wpshop_variations', __('Product variation', 'wpshop'), array('wpshop_products', 'meta_box_variations'), WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'normal', 'default'); |
|
| 270 | - // Actions |
|
| 271 | - // @since 1.4.3.7 Deleted |
|
| 272 | - //add_meta_box('wpshop_product_actions', __('Actions', 'wpshop'), array('wpshop_products', 'product_actions_meta_box_content'), WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'side', 'default'); |
|
| 273 | - |
|
| 274 | - /** Product option */ |
|
| 275 | - add_meta_box('wpshop_product_options', __('Options', 'wpshop'), array('wpshop_products', 'product_options_meta_box_content'), WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'side', 'default'); |
|
| 276 | - } else if (count($attributeEntitySetList) > 1) { |
|
| 277 | - $input_def['id'] = 'product_attribute_set_id'; |
|
| 278 | - $input_def['name'] = 'product_attribute_set_id'; |
|
| 279 | - $input_def['value'] = ''; |
|
| 280 | - $input_def['type'] = 'select'; |
|
| 281 | - $input_def['possible_value'] = $attributeEntitySetList; |
|
| 282 | - |
|
| 283 | - $input_def['value'] = ''; |
|
| 284 | - foreach ($attributeEntitySetList as $set) { |
|
| 285 | - if ($set->default_set == 'yes') { |
|
| 286 | - $input_def['value'] = $set->id; |
|
| 287 | - } |
|
| 288 | - } |
|
| 289 | - |
|
| 290 | - $currentTabContent['boxContent']['attribute_set_selector'] = ' |
|
| 250 | + $currentTabContent = wpshop_attributes::entities_attribute_box($post_attribute_set_id, self::currentPageCode, $post->ID); |
|
| 251 | + |
|
| 252 | + $fixed_box_exist = false; |
|
| 253 | + /* Get all the other attribute set for hte current entity */ |
|
| 254 | + if (isset($currentTabContent['box']) && count($currentTabContent['box']) > 0) { |
|
| 255 | + foreach ($currentTabContent['box'] as $boxIdentifier => $boxTitle) { |
|
| 256 | + if (!empty($currentTabContent['box'][$boxIdentifier . '_backend_display_type']) && ($currentTabContent['box'][$boxIdentifier . '_backend_display_type'] == 'movable-tab')) { |
|
| 257 | + add_meta_box('wpshop_product_' . $boxIdentifier, __($boxTitle, 'wpshop'), array('wpshop_products', 'meta_box_content'), WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'normal', 'default', array('boxIdentifier' => $boxIdentifier)); |
|
| 258 | + } else { |
|
| 259 | + $fixed_box_exist = true; |
|
| 260 | + } |
|
| 261 | + |
|
| 262 | + } |
|
| 263 | + } |
|
| 264 | + if ($fixed_box_exist) { |
|
| 265 | + 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)); |
|
| 266 | + 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)); |
|
| 267 | + } |
|
| 268 | + |
|
| 269 | + add_meta_box('wpshop_wpshop_variations', __('Product variation', 'wpshop'), array('wpshop_products', 'meta_box_variations'), WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'normal', 'default'); |
|
| 270 | + // Actions |
|
| 271 | + // @since 1.4.3.7 Deleted |
|
| 272 | + //add_meta_box('wpshop_product_actions', __('Actions', 'wpshop'), array('wpshop_products', 'product_actions_meta_box_content'), WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'side', 'default'); |
|
| 273 | + |
|
| 274 | + /** Product option */ |
|
| 275 | + add_meta_box('wpshop_product_options', __('Options', 'wpshop'), array('wpshop_products', 'product_options_meta_box_content'), WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'side', 'default'); |
|
| 276 | + } else if (count($attributeEntitySetList) > 1) { |
|
| 277 | + $input_def['id'] = 'product_attribute_set_id'; |
|
| 278 | + $input_def['name'] = 'product_attribute_set_id'; |
|
| 279 | + $input_def['value'] = ''; |
|
| 280 | + $input_def['type'] = 'select'; |
|
| 281 | + $input_def['possible_value'] = $attributeEntitySetList; |
|
| 282 | + |
|
| 283 | + $input_def['value'] = ''; |
|
| 284 | + foreach ($attributeEntitySetList as $set) { |
|
| 285 | + if ($set->default_set == 'yes') { |
|
| 286 | + $input_def['value'] = $set->id; |
|
| 287 | + } |
|
| 288 | + } |
|
| 289 | + |
|
| 290 | + $currentTabContent['boxContent']['attribute_set_selector'] = ' |
|
| 291 | 291 | <ul class="attribute_set_selector" > |
| 292 | 292 | <li class="attribute_set_selector_title_select" ><label for="title" >' . __('Choose a title for your product', 'wpshop') . '</label></li> |
| 293 | 293 | <li class="attribute_set_selector_group_selector" ><label for="' . $input_def['id'] . '" >' . __('Choose an attribute group for this product', 'wpshop') . '</label> ' . wpshop_form::check_input_type($input_def, self::currentPageCode . '_attribute[integer]') . '</li> |
@@ -295,699 +295,699 @@ discard block |
||
| 295 | 295 | <li class="attribute_set_selector_after_save_instruction" >' . __('Once the group chosen, the different attribute will be displayed here', 'wpshop') . '</li> |
| 296 | 296 | </ul>'; |
| 297 | 297 | |
| 298 | - 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')); |
|
| 299 | - } |
|
| 300 | - } |
|
| 298 | + 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')); |
|
| 299 | + } |
|
| 300 | + } |
|
| 301 | 301 | |
| 302 | - } |
|
| 302 | + } |
|
| 303 | 303 | |
| 304 | - /** |
|
| 305 | - * Add a box into product edition page for options on the product |
|
| 306 | - * |
|
| 307 | - * @param object $post |
|
| 308 | - */ |
|
| 309 | - public static function product_options_meta_box_content($post) |
|
| 310 | - { |
|
| 311 | - $output = ''; |
|
| 304 | + /** |
|
| 305 | + * Add a box into product edition page for options on the product |
|
| 306 | + * |
|
| 307 | + * @param object $post |
|
| 308 | + */ |
|
| 309 | + public static function product_options_meta_box_content($post) |
|
| 310 | + { |
|
| 311 | + $output = ''; |
|
| 312 | 312 | |
| 313 | - $product_current_options = get_post_meta($post->ID, '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_options', true); |
|
| 313 | + $product_current_options = get_post_meta($post->ID, '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_options', true); |
|
| 314 | 314 | |
| 315 | - $tpl_component = array(); |
|
| 316 | - $tpl_component['ADMIN_PRODUCT_OPTION_FOR_CART_AUTOADD_CHECKBOX_STATE'] = (!empty($product_current_options['cart']) && !empty($product_current_options['cart']['auto_add'])) ? ' checked="checked"' : ''; |
|
| 317 | - $output .= wpshop_display::display_template_element('wpshop_admin_product_option_for_cart', $tpl_component, array('type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'id' => $post->ID), 'admin'); |
|
| 315 | + $tpl_component = array(); |
|
| 316 | + $tpl_component['ADMIN_PRODUCT_OPTION_FOR_CART_AUTOADD_CHECKBOX_STATE'] = (!empty($product_current_options['cart']) && !empty($product_current_options['cart']['auto_add'])) ? ' checked="checked"' : ''; |
|
| 317 | + $output .= wpshop_display::display_template_element('wpshop_admin_product_option_for_cart', $tpl_component, array('type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'id' => $post->ID), 'admin'); |
|
| 318 | 318 | |
| 319 | - echo $output; |
|
| 320 | - } |
|
| 319 | + echo $output; |
|
| 320 | + } |
|
| 321 | 321 | |
| 322 | - /** |
|
| 323 | - * Display the fixed box |
|
| 324 | - */ |
|
| 325 | - public static function product_data_meta_box($post, $metaboxArgs) |
|
| 326 | - { |
|
| 327 | - $output = ''; |
|
| 322 | + /** |
|
| 323 | + * Display the fixed box |
|
| 324 | + */ |
|
| 325 | + public static function product_data_meta_box($post, $metaboxArgs) |
|
| 326 | + { |
|
| 327 | + $output = ''; |
|
| 328 | 328 | |
| 329 | - $currentTabContent = $metaboxArgs['args']['currentTabContent']; |
|
| 329 | + $currentTabContent = $metaboxArgs['args']['currentTabContent']; |
|
| 330 | 330 | |
| 331 | - echo '<div id="fixed-tabs" class="wpshop_tabs wpshop_detail_tabs wpshop_product_attribute_tabs" > |
|
| 331 | + echo '<div id="fixed-tabs" class="wpshop_tabs wpshop_detail_tabs wpshop_product_attribute_tabs" > |
|
| 332 | 332 | <ul>'; |
| 333 | - if (!empty($currentTabContent['box'])) { |
|
| 334 | - foreach ($currentTabContent['box'] as $boxIdentifier => $boxTitle) { |
|
| 335 | - if (!empty($currentTabContent['boxContent'][$boxIdentifier])) { |
|
| 336 | - if ($currentTabContent['box'][$boxIdentifier . '_backend_display_type'] == 'fixed-tab') { |
|
| 337 | - echo '<li><a href="#tabs-' . sanitize_title($boxIdentifier) . '">' . __($boxTitle, 'wpshop') . '</a></li>'; |
|
| 338 | - } |
|
| 339 | - } |
|
| 340 | - } |
|
| 341 | - } |
|
| 342 | - echo '<li><a href="#tabs-product-related">' . __('Related products', 'wpshop') . '</a></li>'; |
|
| 343 | - echo '<li><a href="#tabs-product-provider">' . __('Providers', 'wpshop') . '</a></li>'; |
|
| 344 | - echo '<li class="wpshop_product_data_display_tab" ><a href="#tabs-product-display">' . __('Product display', 'wpshop') . '</a></li>'; |
|
| 345 | - echo '</ul>'; |
|
| 346 | - |
|
| 347 | - if (!empty($currentTabContent['box'])) { |
|
| 348 | - foreach ($currentTabContent['box'] as $boxIdentifier => $boxTitle) { |
|
| 349 | - if (!empty($currentTabContent['boxContent'][$boxIdentifier])) { |
|
| 350 | - if ($currentTabContent['box'][$boxIdentifier . '_backend_display_type'] == 'fixed-tab') { |
|
| 351 | - echo '<div id="tabs-' . sanitize_title($boxIdentifier) . '">' . $currentTabContent['boxContent'][$boxIdentifier] . '</div>'; |
|
| 352 | - } |
|
| 353 | - } |
|
| 354 | - } |
|
| 355 | - } |
|
| 333 | + if (!empty($currentTabContent['box'])) { |
|
| 334 | + foreach ($currentTabContent['box'] as $boxIdentifier => $boxTitle) { |
|
| 335 | + if (!empty($currentTabContent['boxContent'][$boxIdentifier])) { |
|
| 336 | + if ($currentTabContent['box'][$boxIdentifier . '_backend_display_type'] == 'fixed-tab') { |
|
| 337 | + echo '<li><a href="#tabs-' . sanitize_title($boxIdentifier) . '">' . __($boxTitle, 'wpshop') . '</a></li>'; |
|
| 338 | + } |
|
| 339 | + } |
|
| 340 | + } |
|
| 341 | + } |
|
| 342 | + echo '<li><a href="#tabs-product-related">' . __('Related products', 'wpshop') . '</a></li>'; |
|
| 343 | + echo '<li><a href="#tabs-product-provider">' . __('Providers', 'wpshop') . '</a></li>'; |
|
| 344 | + echo '<li class="wpshop_product_data_display_tab" ><a href="#tabs-product-display">' . __('Product display', 'wpshop') . '</a></li>'; |
|
| 345 | + echo '</ul>'; |
|
| 346 | + |
|
| 347 | + if (!empty($currentTabContent['box'])) { |
|
| 348 | + foreach ($currentTabContent['box'] as $boxIdentifier => $boxTitle) { |
|
| 349 | + if (!empty($currentTabContent['boxContent'][$boxIdentifier])) { |
|
| 350 | + if ($currentTabContent['box'][$boxIdentifier . '_backend_display_type'] == 'fixed-tab') { |
|
| 351 | + echo '<div id="tabs-' . sanitize_title($boxIdentifier) . '">' . $currentTabContent['boxContent'][$boxIdentifier] . '</div>'; |
|
| 352 | + } |
|
| 353 | + } |
|
| 354 | + } |
|
| 355 | + } |
|
| 356 | 356 | |
| 357 | - echo '<div id="tabs-product-related">' . self::related_products_meta_box_content($post) . '</div>'; |
|
| 358 | - echo '<div id="tabs-product-display">' . self::product_frontend_display_config_meta_box($post) . '</div>'; |
|
| 359 | - if (!empty($currentTabContent['boxMore'])) { |
|
| 360 | - echo $currentTabContent['boxMore']; |
|
| 361 | - } |
|
| 362 | - echo '</div>'; |
|
| 357 | + echo '<div id="tabs-product-related">' . self::related_products_meta_box_content($post) . '</div>'; |
|
| 358 | + echo '<div id="tabs-product-display">' . self::product_frontend_display_config_meta_box($post) . '</div>'; |
|
| 359 | + if (!empty($currentTabContent['boxMore'])) { |
|
| 360 | + echo $currentTabContent['boxMore']; |
|
| 361 | + } |
|
| 362 | + echo '</div>'; |
|
| 363 | 363 | |
| 364 | - echo $output; |
|
| 365 | - } |
|
| 364 | + echo $output; |
|
| 365 | + } |
|
| 366 | 366 | |
| 367 | - /** |
|
| 368 | - * Output the content for related product metabox |
|
| 369 | - * @param object $post The current edited post |
|
| 370 | - * @return string |
|
| 371 | - */ |
|
| 372 | - public static function related_products_meta_box_content($post) |
|
| 373 | - { |
|
| 374 | - $content = $existing_selection = ''; |
|
| 375 | - |
|
| 376 | - if (!empty($post->ID)) { |
|
| 377 | - $related_products_id = get_post_meta($post->ID, WPSHOP_PRODUCT_RELATED_PRODUCTS, true); |
|
| 378 | - if (!empty($related_products_id) && !empty($related_products_id[0])) { |
|
| 379 | - foreach ($related_products_id as $related_product_id) { |
|
| 380 | - $existing_selection .= '<option selected value="' . $related_product_id . '" >' . get_the_title($related_product_id) . '</option>'; |
|
| 381 | - } |
|
| 382 | - } |
|
| 383 | - } |
|
| 367 | + /** |
|
| 368 | + * Output the content for related product metabox |
|
| 369 | + * @param object $post The current edited post |
|
| 370 | + * @return string |
|
| 371 | + */ |
|
| 372 | + public static function related_products_meta_box_content($post) |
|
| 373 | + { |
|
| 374 | + $content = $existing_selection = ''; |
|
| 375 | + |
|
| 376 | + if (!empty($post->ID)) { |
|
| 377 | + $related_products_id = get_post_meta($post->ID, WPSHOP_PRODUCT_RELATED_PRODUCTS, true); |
|
| 378 | + if (!empty($related_products_id) && !empty($related_products_id[0])) { |
|
| 379 | + foreach ($related_products_id as $related_product_id) { |
|
| 380 | + $existing_selection .= '<option selected value="' . $related_product_id . '" >' . get_the_title($related_product_id) . '</option>'; |
|
| 381 | + } |
|
| 382 | + } |
|
| 383 | + } |
|
| 384 | 384 | |
| 385 | - $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> |
|
| 385 | + $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> |
|
| 386 | 386 | <select name="related_products_list[]" id="related_products_list" class="ajax_chosen_select_related_products" multiple >' . $existing_selection . '</select> |
| 387 | 387 | <input type="hidden" id="wpshop_ajax_search_element_type_related_products" name="wpshop_ajax_search_element_type" value="' . $post->post_type . '" /> |
| 388 | 388 | <input type="hidden" id="wpshop_nonce_ajax_search_related_products" name="wpshop_nonce_ajax_search" value="' . wp_create_nonce("wpshop_element_search") . '" />'; |
| 389 | 389 | |
| 390 | - return $content; |
|
| 391 | - } |
|
| 390 | + return $content; |
|
| 391 | + } |
|
| 392 | 392 | |
| 393 | - /** |
|
| 394 | - * Define the metabox content for the action box |
|
| 395 | - * @param obejct $post The current element being edited |
|
| 396 | - */ |
|
| 397 | - public static function product_actions_meta_box_content($post) |
|
| 398 | - { |
|
| 399 | - $output = ''; |
|
| 400 | - /* |
|
| 393 | + /** |
|
| 394 | + * Define the metabox content for the action box |
|
| 395 | + * @param obejct $post The current element being edited |
|
| 396 | + */ |
|
| 397 | + public static function product_actions_meta_box_content($post) |
|
| 398 | + { |
|
| 399 | + $output = ''; |
|
| 400 | + /* |
|
| 401 | 401 | * Template parameters |
| 402 | 402 | */ |
| 403 | - $template_part = 'wpshop_duplicate_product'; |
|
| 404 | - $tpl_component = array(); |
|
| 405 | - $tpl_component['PRODUCT_ID'] = $post->ID; |
|
| 406 | - $tpl_component['PRINT_PRODUCT_SHEET_LINK'] = admin_url('admin-post.php?action=wps_product_sheet&pid=' . $post->ID); |
|
| 407 | - /* |
|
| 403 | + $template_part = 'wpshop_duplicate_product'; |
|
| 404 | + $tpl_component = array(); |
|
| 405 | + $tpl_component['PRODUCT_ID'] = $post->ID; |
|
| 406 | + $tpl_component['PRINT_PRODUCT_SHEET_LINK'] = admin_url('admin-post.php?action=wps_product_sheet&pid=' . $post->ID); |
|
| 407 | + /* |
|
| 408 | 408 | * Build template |
| 409 | 409 | */ |
| 410 | - $output = wpshop_display::display_template_element($template_part, $tpl_component, array(), 'admin'); |
|
| 411 | - unset($tpl_component); |
|
| 410 | + $output = wpshop_display::display_template_element($template_part, $tpl_component, array(), 'admin'); |
|
| 411 | + unset($tpl_component); |
|
| 412 | 412 | |
| 413 | - echo $output; |
|
| 414 | - } |
|
| 413 | + echo $output; |
|
| 414 | + } |
|
| 415 | 415 | |
| 416 | - /** |
|
| 417 | - * Define the content of the product main information box |
|
| 418 | - */ |
|
| 419 | - public static function meta_box_content($post, $metaboxArgs) |
|
| 420 | - { |
|
| 421 | - global $currentTabContent; |
|
| 416 | + /** |
|
| 417 | + * Define the content of the product main information box |
|
| 418 | + */ |
|
| 419 | + public static function meta_box_content($post, $metaboxArgs) |
|
| 420 | + { |
|
| 421 | + global $currentTabContent; |
|
| 422 | 422 | |
| 423 | - /* Add the extra fields defined by the default attribute group in the general section */ |
|
| 424 | - echo '<div class="wpshop_extra_field_container" >' . $currentTabContent['boxContent'][$metaboxArgs['args']['boxIdentifier']] . '</div>'; |
|
| 425 | - } |
|
| 423 | + /* Add the extra fields defined by the default attribute group in the general section */ |
|
| 424 | + echo '<div class="wpshop_extra_field_container" >' . $currentTabContent['boxContent'][$metaboxArgs['args']['boxIdentifier']] . '</div>'; |
|
| 425 | + } |
|
| 426 | 426 | |
| 427 | - /** |
|
| 428 | - * Define the metabox content for product custom display in product |
|
| 429 | - * @param object $post The current element being edited |
|
| 430 | - * @return string The metabox content |
|
| 431 | - */ |
|
| 432 | - public static function product_frontend_display_config_meta_box($post) |
|
| 433 | - { |
|
| 434 | - $content = ''; |
|
| 435 | - |
|
| 436 | - $product_attribute_frontend_display_config = null; |
|
| 437 | - if (!empty($post->ID)) { |
|
| 438 | - $product_attribute_frontend_display_config = get_post_meta($post->ID, WPSHOP_PRODUCT_FRONT_DISPLAY_CONF, true); |
|
| 439 | - |
|
| 440 | - $extra_options = get_option('wpshop_extra_options', array()); |
|
| 441 | - $column_count = (!empty($extra_options['WPSHOP_COLUMN_NUMBER_PRODUCT_EDITION_FOR_FRONT_DISPLAY']) ? $extra_options['WPSHOP_COLUMN_NUMBER_PRODUCT_EDITION_FOR_FRONT_DISPLAY'] : 3); |
|
| 442 | - $attribute_list = wpshop_attributes::getElementWithAttributeAndValue(wpshop_entities::get_entity_identifier_from_code(self::currentPageCode), $post->ID, WPSHOP_CURRENT_LOCALE); |
|
| 443 | - $column = 1; |
|
| 444 | - |
|
| 445 | - if (WPSHOP_DEFINED_SHOP_TYPE == 'sale') { |
|
| 446 | - $sub_tpl_component = array(); |
|
| 447 | - $sub_tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_NAME'] = __('Action on product', 'wpshop'); |
|
| 448 | - |
|
| 449 | - $tpl_component = array(); |
|
| 450 | - $tpl_component['ADMIN_ATTRIBUTE_LABEL'] = __('Add to cart button', 'wpshop'); |
|
| 451 | - $tpl_component['ADMIN_ATTRIBUTE_FD_NAME'] = self::currentPageCode . '_attr_frontend_display[product_action_button][add_to_cart]'; |
|
| 452 | - $tpl_component['ADMIN_ATTRIBUTE_FD_ID'] = $post->ID . '_product_action_button_add_to_cart'; |
|
| 453 | - $button_is_set_to_be_displayed = (WPSHOP_DEFINED_SHOP_TYPE == 'sale') ? 'yes' : 'no'; |
|
| 454 | - |
|
| 455 | - $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"' : ''; |
|
| 456 | - $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"' : ''; |
|
| 457 | - $sub_tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_CONTENT'] = wpshop_display::display_template_element('wpshop_admin_attr_config_for_front_display', $tpl_component, array(), 'admin'); |
|
| 458 | - unset($tpl_component); |
|
| 459 | - |
|
| 460 | - $sub_tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_FD_NAME'] = self::currentPageCode . '_attr_frontend_display[product_action_button][add_to_cart]'; |
|
| 461 | - $sub_tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_FD_ID'] = 'product_action_button_add_to_cart'; |
|
| 462 | - $sub_tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_INPUT_CHECKBOX'] = ''; |
|
| 463 | - $sub_content[1] = wpshop_display::display_template_element('wpshop_admin_attr_set_section_for_front_display', $sub_tpl_component, array(), 'admin'); |
|
| 464 | - } |
|
| 465 | - |
|
| 466 | - if (!empty($attribute_list[$post->ID]) && is_array($attribute_list[$post->ID])) { |
|
| 467 | - foreach ($attribute_list[$post->ID] as $attribute_set_section_name => $attribute_set_section_content) { |
|
| 468 | - if (!isset($sub_content[$column])) { |
|
| 469 | - $sub_content[$column] = ''; |
|
| 470 | - } |
|
| 471 | - |
|
| 472 | - $attribute_sub_output = ''; |
|
| 473 | - foreach ($attribute_set_section_content['attributes'] as $attribute_id => $attribute_def) { |
|
| 474 | - if ($attribute_def['attribute_code'] != 'product_attribute_set_id') { |
|
| 475 | - $tpl_component = array(); |
|
| 476 | - $tpl_component['ADMIN_ATTRIBUTE_LABEL'] = $attribute_def['frontend_label']; |
|
| 477 | - $tpl_component['ADMIN_ATTRIBUTE_FD_NAME'] = self::currentPageCode . '_attr_frontend_display[attribute][' . $attribute_def['attribute_code'] . ']'; |
|
| 478 | - $tpl_component['ADMIN_ATTRIBUTE_FD_ID'] = $post->ID . '_' . $attribute_def['attribute_code']; |
|
| 479 | - $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"' : ''; |
|
| 480 | - $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"' : ''; |
|
| 481 | - $attribute_sub_output .= wpshop_display::display_template_element('wpshop_admin_attr_config_for_front_display', $tpl_component, array(), 'admin'); |
|
| 482 | - unset($tpl_component); |
|
| 483 | - } |
|
| 484 | - } |
|
| 485 | - |
|
| 486 | - $tpl_component = array(); |
|
| 487 | - $tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_NAME'] = $attribute_set_section_name; |
|
| 488 | - $tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_CONTENT'] = $attribute_sub_output; |
|
| 489 | - $tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_FD_NAME'] = self::currentPageCode . '_attr_frontend_display[attribute_set_section][' . $attribute_set_section_content['code'] . ']'; |
|
| 490 | - $tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_FD_ID'] = $attribute_set_section_content['code']; |
|
| 491 | - $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"' : ''; |
|
| 492 | - $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>'; |
|
| 493 | - $sub_content[$column] .= wpshop_display::display_template_element('wpshop_admin_attr_set_section_for_front_display', $tpl_component, array(), 'admin'); |
|
| 494 | - $column++; |
|
| 495 | - if ($column > $column_count) { |
|
| 496 | - $column = 1; |
|
| 497 | - } |
|
| 498 | - } |
|
| 499 | - } |
|
| 500 | - $tpl_component = array(); |
|
| 501 | - $tpl_component['ADMIN_ATTRIBUTE_FRONTEND_DISPLAY_CONTENT'] = ''; |
|
| 502 | - for ($i = 1; $i <= $column_count; $i++) { |
|
| 503 | - if (!empty($sub_content[$i])) { |
|
| 504 | - $tpl_component['ADMIN_ATTRIBUTE_FRONTEND_DISPLAY_CONTENT'] .= '<div class="alignleft" >' . $sub_content[$i] . '</div>'; |
|
| 505 | - } |
|
| 506 | - |
|
| 507 | - } |
|
| 508 | - $tpl_component['ADMIN_ATTRIBUTE_FRONTEND_DISPLAY_CONTENT_CLASS'] = empty($product_attribute_frontend_display_config) ? ' class="wpshopHide" ' : ''; |
|
| 509 | - $tpl_component['ADMIN_PRODUCT_ATTRIBUTE_FRONTEND_DISPLAY_MAIN_CHOICE_CHECK'] = empty($product_attribute_frontend_display_config) ? ' checked="checked"' : ''; |
|
| 510 | - $tpl_component['ADMIN_ATTRIBUTE_FD_NAME'] = self::currentPageCode . '_attr_frontend_display'; |
|
| 511 | - |
|
| 512 | - $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>'; |
|
| 513 | - } |
|
| 427 | + /** |
|
| 428 | + * Define the metabox content for product custom display in product |
|
| 429 | + * @param object $post The current element being edited |
|
| 430 | + * @return string The metabox content |
|
| 431 | + */ |
|
| 432 | + public static function product_frontend_display_config_meta_box($post) |
|
| 433 | + { |
|
| 434 | + $content = ''; |
|
| 435 | + |
|
| 436 | + $product_attribute_frontend_display_config = null; |
|
| 437 | + if (!empty($post->ID)) { |
|
| 438 | + $product_attribute_frontend_display_config = get_post_meta($post->ID, WPSHOP_PRODUCT_FRONT_DISPLAY_CONF, true); |
|
| 439 | + |
|
| 440 | + $extra_options = get_option('wpshop_extra_options', array()); |
|
| 441 | + $column_count = (!empty($extra_options['WPSHOP_COLUMN_NUMBER_PRODUCT_EDITION_FOR_FRONT_DISPLAY']) ? $extra_options['WPSHOP_COLUMN_NUMBER_PRODUCT_EDITION_FOR_FRONT_DISPLAY'] : 3); |
|
| 442 | + $attribute_list = wpshop_attributes::getElementWithAttributeAndValue(wpshop_entities::get_entity_identifier_from_code(self::currentPageCode), $post->ID, WPSHOP_CURRENT_LOCALE); |
|
| 443 | + $column = 1; |
|
| 444 | + |
|
| 445 | + if (WPSHOP_DEFINED_SHOP_TYPE == 'sale') { |
|
| 446 | + $sub_tpl_component = array(); |
|
| 447 | + $sub_tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_NAME'] = __('Action on product', 'wpshop'); |
|
| 448 | + |
|
| 449 | + $tpl_component = array(); |
|
| 450 | + $tpl_component['ADMIN_ATTRIBUTE_LABEL'] = __('Add to cart button', 'wpshop'); |
|
| 451 | + $tpl_component['ADMIN_ATTRIBUTE_FD_NAME'] = self::currentPageCode . '_attr_frontend_display[product_action_button][add_to_cart]'; |
|
| 452 | + $tpl_component['ADMIN_ATTRIBUTE_FD_ID'] = $post->ID . '_product_action_button_add_to_cart'; |
|
| 453 | + $button_is_set_to_be_displayed = (WPSHOP_DEFINED_SHOP_TYPE == 'sale') ? 'yes' : 'no'; |
|
| 454 | + |
|
| 455 | + $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"' : ''; |
|
| 456 | + $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"' : ''; |
|
| 457 | + $sub_tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_CONTENT'] = wpshop_display::display_template_element('wpshop_admin_attr_config_for_front_display', $tpl_component, array(), 'admin'); |
|
| 458 | + unset($tpl_component); |
|
| 459 | + |
|
| 460 | + $sub_tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_FD_NAME'] = self::currentPageCode . '_attr_frontend_display[product_action_button][add_to_cart]'; |
|
| 461 | + $sub_tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_FD_ID'] = 'product_action_button_add_to_cart'; |
|
| 462 | + $sub_tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_INPUT_CHECKBOX'] = ''; |
|
| 463 | + $sub_content[1] = wpshop_display::display_template_element('wpshop_admin_attr_set_section_for_front_display', $sub_tpl_component, array(), 'admin'); |
|
| 464 | + } |
|
| 514 | 465 | |
| 515 | - return $content; |
|
| 516 | - } |
|
| 466 | + if (!empty($attribute_list[$post->ID]) && is_array($attribute_list[$post->ID])) { |
|
| 467 | + foreach ($attribute_list[$post->ID] as $attribute_set_section_name => $attribute_set_section_content) { |
|
| 468 | + if (!isset($sub_content[$column])) { |
|
| 469 | + $sub_content[$column] = ''; |
|
| 470 | + } |
|
| 471 | + |
|
| 472 | + $attribute_sub_output = ''; |
|
| 473 | + foreach ($attribute_set_section_content['attributes'] as $attribute_id => $attribute_def) { |
|
| 474 | + if ($attribute_def['attribute_code'] != 'product_attribute_set_id') { |
|
| 475 | + $tpl_component = array(); |
|
| 476 | + $tpl_component['ADMIN_ATTRIBUTE_LABEL'] = $attribute_def['frontend_label']; |
|
| 477 | + $tpl_component['ADMIN_ATTRIBUTE_FD_NAME'] = self::currentPageCode . '_attr_frontend_display[attribute][' . $attribute_def['attribute_code'] . ']'; |
|
| 478 | + $tpl_component['ADMIN_ATTRIBUTE_FD_ID'] = $post->ID . '_' . $attribute_def['attribute_code']; |
|
| 479 | + $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"' : ''; |
|
| 480 | + $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"' : ''; |
|
| 481 | + $attribute_sub_output .= wpshop_display::display_template_element('wpshop_admin_attr_config_for_front_display', $tpl_component, array(), 'admin'); |
|
| 482 | + unset($tpl_component); |
|
| 483 | + } |
|
| 484 | + } |
|
| 485 | + |
|
| 486 | + $tpl_component = array(); |
|
| 487 | + $tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_NAME'] = $attribute_set_section_name; |
|
| 488 | + $tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_CONTENT'] = $attribute_sub_output; |
|
| 489 | + $tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_FD_NAME'] = self::currentPageCode . '_attr_frontend_display[attribute_set_section][' . $attribute_set_section_content['code'] . ']'; |
|
| 490 | + $tpl_component['ADMIN_ATTRIBUTE_SET_SECTION_FD_ID'] = $attribute_set_section_content['code']; |
|
| 491 | + $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"' : ''; |
|
| 492 | + $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>'; |
|
| 493 | + $sub_content[$column] .= wpshop_display::display_template_element('wpshop_admin_attr_set_section_for_front_display', $tpl_component, array(), 'admin'); |
|
| 494 | + $column++; |
|
| 495 | + if ($column > $column_count) { |
|
| 496 | + $column = 1; |
|
| 497 | + } |
|
| 498 | + } |
|
| 499 | + } |
|
| 500 | + $tpl_component = array(); |
|
| 501 | + $tpl_component['ADMIN_ATTRIBUTE_FRONTEND_DISPLAY_CONTENT'] = ''; |
|
| 502 | + for ($i = 1; $i <= $column_count; $i++) { |
|
| 503 | + if (!empty($sub_content[$i])) { |
|
| 504 | + $tpl_component['ADMIN_ATTRIBUTE_FRONTEND_DISPLAY_CONTENT'] .= '<div class="alignleft" >' . $sub_content[$i] . '</div>'; |
|
| 505 | + } |
|
| 506 | + |
|
| 507 | + } |
|
| 508 | + $tpl_component['ADMIN_ATTRIBUTE_FRONTEND_DISPLAY_CONTENT_CLASS'] = empty($product_attribute_frontend_display_config) ? ' class="wpshopHide" ' : ''; |
|
| 509 | + $tpl_component['ADMIN_PRODUCT_ATTRIBUTE_FRONTEND_DISPLAY_MAIN_CHOICE_CHECK'] = empty($product_attribute_frontend_display_config) ? ' checked="checked"' : ''; |
|
| 510 | + $tpl_component['ADMIN_ATTRIBUTE_FD_NAME'] = self::currentPageCode . '_attr_frontend_display'; |
|
| 517 | 511 | |
| 518 | - /** |
|
| 519 | - * Retrieve the attribute list used for sorting product into frontend listing |
|
| 520 | - * @return array The attribute list to use for listing sorting |
|
| 521 | - */ |
|
| 522 | - public static function get_sorting_criteria() |
|
| 523 | - { |
|
| 524 | - global $wpdb; |
|
| 512 | + $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>'; |
|
| 513 | + } |
|
| 525 | 514 | |
| 526 | - $data = array(array('code' => 'title', 'frontend_label' => __('Product name', 'wpshop')), array('code' => 'date', 'frontend_label' => __('Date added', 'wpshop')), array('code' => 'modified', 'frontend_label' => __('Date modified', 'wpshop')), array('code' => 'rand', 'frontend_label' => __('Random', 'wpshop'))); |
|
| 515 | + return $content; |
|
| 516 | + } |
|
| 527 | 517 | |
| 528 | - $query = $wpdb->prepare("SELECT code, frontend_label FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE is_used_for_sort_by = %s", 'yes'); |
|
| 529 | - $results = $wpdb->get_results($query, ARRAY_A); |
|
| 530 | - if (!empty($results)) { |
|
| 531 | - $data = array_merge($data, $results); |
|
| 532 | - } |
|
| 518 | + /** |
|
| 519 | + * Retrieve the attribute list used for sorting product into frontend listing |
|
| 520 | + * @return array The attribute list to use for listing sorting |
|
| 521 | + */ |
|
| 522 | + public static function get_sorting_criteria() |
|
| 523 | + { |
|
| 524 | + global $wpdb; |
|
| 533 | 525 | |
| 534 | - return $data; |
|
| 535 | - } |
|
| 526 | + $data = array(array('code' => 'title', 'frontend_label' => __('Product name', 'wpshop')), array('code' => 'date', 'frontend_label' => __('Date added', 'wpshop')), array('code' => 'modified', 'frontend_label' => __('Date modified', 'wpshop')), array('code' => 'rand', 'frontend_label' => __('Random', 'wpshop'))); |
|
| 527 | + |
|
| 528 | + $query = $wpdb->prepare("SELECT code, frontend_label FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE is_used_for_sort_by = %s", 'yes'); |
|
| 529 | + $results = $wpdb->get_results($query, ARRAY_A); |
|
| 530 | + if (!empty($results)) { |
|
| 531 | + $data = array_merge($data, $results); |
|
| 532 | + } |
|
| 533 | + |
|
| 534 | + return $data; |
|
| 535 | + } |
|
| 536 | 536 | |
| 537 | - public static function get_products_matching_attribute($attr_name, $attr_value) |
|
| 538 | - { |
|
| 539 | - global $wpdb; |
|
| 537 | + public static function get_products_matching_attribute($attr_name, $attr_value) |
|
| 538 | + { |
|
| 539 | + global $wpdb; |
|
| 540 | 540 | |
| 541 | - $products = array(); |
|
| 542 | - $query = "SELECT * FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE code=%s"; |
|
| 543 | - $data = (array) $wpdb->get_row($wpdb->prepare($query, $attr_name)); |
|
| 541 | + $products = array(); |
|
| 542 | + $query = "SELECT * FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE code=%s"; |
|
| 543 | + $data = (array) $wpdb->get_row($wpdb->prepare($query, $attr_name)); |
|
| 544 | 544 | |
| 545 | - if (!empty($data)) { |
|
| 546 | - if ($data['data_type_to_use'] == 'custom') { |
|
| 547 | - // Find which table to take |
|
| 548 | - 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;} |
|
| 545 | + if (!empty($data)) { |
|
| 546 | + if ($data['data_type_to_use'] == 'custom') { |
|
| 547 | + // Find which table to take |
|
| 548 | + 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;} |
|
| 549 | 549 | |
| 550 | - if (isset($table_name)) { |
|
| 551 | - // If the value is an id of a select, radio or checkbox |
|
| 552 | - if (in_array($data['backend_input'], array('select', 'multiple-select', 'radio', 'checkbox'))) { |
|
| 550 | + if (isset($table_name)) { |
|
| 551 | + // If the value is an id of a select, radio or checkbox |
|
| 552 | + if (in_array($data['backend_input'], array('select', 'multiple-select', 'radio', 'checkbox'))) { |
|
| 553 | 553 | |
| 554 | - $query = $wpdb->prepare(" |
|
| 554 | + $query = $wpdb->prepare(" |
|
| 555 | 555 | SELECT " . $table_name . ".entity_id FROM " . $table_name . " |
| 556 | 556 | INNER JOIN {$wpdb->posts} AS P ON ( ( P.ID = " . $table_name . ".entity_id ) AND ( P.post_status = 'publish' ) ) |
| 557 | 557 | LEFT JOIN " . WPSHOP_DBT_ATTRIBUTE . " AS ATT ON ATT.id = " . $table_name . ".attribute_id |
| 558 | 558 | LEFT JOIN " . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . " AS ATT_OPT ON " . $table_name . ".value = ATT_OPT.id |
| 559 | 559 | WHERE ATT.code=%s AND ( ATT_OPT.value=%s OR ATT_OPT.value=%s )", $attr_name, strtolower(__($attr_value, 'wpshop')), $attr_value |
| 560 | - ); |
|
| 561 | - $data = $wpdb->get_results($query); |
|
| 562 | - } else { |
|
| 560 | + ); |
|
| 561 | + $data = $wpdb->get_results($query); |
|
| 562 | + } else { |
|
| 563 | 563 | |
| 564 | - $query = $wpdb->prepare(" |
|
| 564 | + $query = $wpdb->prepare(" |
|
| 565 | 565 | SELECT " . $table_name . ".entity_id FROM " . $table_name . " |
| 566 | 566 | INNER JOIN {$wpdb->posts} AS P ON ( ( P.ID = " . $table_name . ".entity_id ) AND ( P.post_status = 'publish' ) ) |
| 567 | 567 | INNER JOIN " . WPSHOP_DBT_ATTRIBUTE . " AS ATT ON ATT.id = " . $table_name . ".attribute_id |
| 568 | 568 | INNER JOIN {$wpdb->posts} AS P ON ( ( P.ID = " . $table_name . ".entity_id ) AND ( P.post_status = 'publish' ) ) |
| 569 | 569 | WHERE ATT.code=%s AND " . $table_name . ".value=%s", $attr_name, sprintf('%.5f', $attr_value) // force useless zero like 48.58000 |
| 570 | - ); |
|
| 571 | - $data = $wpdb->get_results($query); |
|
| 572 | - |
|
| 573 | - } |
|
| 574 | - } else { |
|
| 575 | - return __('Incorrect shortcode', 'wpshop'); |
|
| 576 | - } |
|
| 577 | - |
|
| 578 | - } elseif ($data['data_type_to_use'] == 'internal') { |
|
| 579 | - /** Check the ID of manufacturer **/ |
|
| 580 | - $default_value = unserialize($data['default_value']); |
|
| 581 | - if (!empty($default_value) && !empty($default_value['default_value'])) { |
|
| 582 | - $query = get_post($attr_value); |
|
| 583 | - $pid = (!empty($query) && !empty($query->ID)) ? $query->ID : ''; |
|
| 584 | - if (!empty($pid)) { |
|
| 585 | - $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); |
|
| 586 | - $data = $wpdb->get_results($query); |
|
| 587 | - } |
|
| 588 | - } |
|
| 589 | - } else { |
|
| 590 | - return __('Incorrect shortcode', 'wpshop'); |
|
| 591 | - } |
|
| 592 | - |
|
| 593 | - } else { |
|
| 594 | - return __('Incorrect shortcode', 'wpshop'); |
|
| 595 | - } |
|
| 570 | + ); |
|
| 571 | + $data = $wpdb->get_results($query); |
|
| 596 | 572 | |
| 597 | - if (!empty($data)) { |
|
| 598 | - foreach ($data as $p) { |
|
| 599 | - if (!empty($p) && is_object($p) && !empty($p->entity_id)) { |
|
| 600 | - $products[] = $p->entity_id; |
|
| 601 | - } |
|
| 602 | - } |
|
| 603 | - } |
|
| 604 | - return $products; |
|
| 605 | - } |
|
| 573 | + } |
|
| 574 | + } else { |
|
| 575 | + return __('Incorrect shortcode', 'wpshop'); |
|
| 576 | + } |
|
| 606 | 577 | |
| 607 | - /** |
|
| 608 | - * Related product shortcode reader |
|
| 609 | - * |
|
| 610 | - * @param array $atts { |
|
| 611 | - * pid : Product idenfifier to get related element for |
|
| 612 | - * display_mode : The output mode if defined (grid || list) |
|
| 613 | - * } |
|
| 614 | - * |
|
| 615 | - * @return string |
|
| 616 | - * |
|
| 617 | - */ |
|
| 618 | - public static function wpshop_related_products_func($atts) |
|
| 619 | - { |
|
| 620 | - global $wp_query; |
|
| 578 | + } elseif ($data['data_type_to_use'] == 'internal') { |
|
| 579 | + /** Check the ID of manufacturer **/ |
|
| 580 | + $default_value = unserialize($data['default_value']); |
|
| 581 | + if (!empty($default_value) && !empty($default_value['default_value'])) { |
|
| 582 | + $query = get_post($attr_value); |
|
| 583 | + $pid = (!empty($query) && !empty($query->ID)) ? $query->ID : ''; |
|
| 584 | + if (!empty($pid)) { |
|
| 585 | + $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); |
|
| 586 | + $data = $wpdb->get_results($query); |
|
| 587 | + } |
|
| 588 | + } |
|
| 589 | + } else { |
|
| 590 | + return __('Incorrect shortcode', 'wpshop'); |
|
| 591 | + } |
|
| 621 | 592 | |
| 622 | - $atts['product_type'] = 'related'; |
|
| 623 | - if (empty($atts['pid'])) { |
|
| 624 | - $atts['pid'] = $wp_query->posts[0]->ID; |
|
| 625 | - } |
|
| 593 | + } else { |
|
| 594 | + return __('Incorrect shortcode', 'wpshop'); |
|
| 595 | + } |
|
| 626 | 596 | |
| 627 | - $related_product_output = self::wpshop_products_func($atts); |
|
| 597 | + if (!empty($data)) { |
|
| 598 | + foreach ($data as $p) { |
|
| 599 | + if (!empty($p) && is_object($p) && !empty($p->entity_id)) { |
|
| 600 | + $products[] = $p->entity_id; |
|
| 601 | + } |
|
| 602 | + } |
|
| 603 | + } |
|
| 604 | + return $products; |
|
| 605 | + } |
|
| 628 | 606 | |
| 629 | - $output = ''; |
|
| 630 | - if (!empty($related_product_output)) { |
|
| 631 | - ob_start(); |
|
| 632 | - require wpshop_tools::get_template_part(WPS_PRODUCT_DIR, WPS_PRODUCT_TEMPLATES_MAIN_DIR, 'frontend', 'related_product'); |
|
| 633 | - $output = ob_get_contents(); |
|
| 634 | - ob_end_clean(); |
|
| 635 | - } |
|
| 607 | + /** |
|
| 608 | + * Related product shortcode reader |
|
| 609 | + * |
|
| 610 | + * @param array $atts { |
|
| 611 | + * pid : Product idenfifier to get related element for |
|
| 612 | + * display_mode : The output mode if defined (grid || list) |
|
| 613 | + * } |
|
| 614 | + * |
|
| 615 | + * @return string |
|
| 616 | + * |
|
| 617 | + */ |
|
| 618 | + public static function wpshop_related_products_func($atts) |
|
| 619 | + { |
|
| 620 | + global $wp_query; |
|
| 636 | 621 | |
| 637 | - return $output; |
|
| 638 | - } |
|
| 622 | + $atts['product_type'] = 'related'; |
|
| 623 | + if (empty($atts['pid'])) { |
|
| 624 | + $atts['pid'] = $wp_query->posts[0]->ID; |
|
| 625 | + } |
|
| 639 | 626 | |
| 640 | - /** |
|
| 641 | - * Display a list of product from a shortcode |
|
| 642 | - * |
|
| 643 | - * @param array $atts { |
|
| 644 | - * limit : The number of element to display |
|
| 645 | - * order : The information to order list by |
|
| 646 | - * sorting : List order (ASC | DESC) |
|
| 647 | - * display : Display size (normal | mini) |
|
| 648 | - * type : Display tyep (grid | list) only work with display=normal |
|
| 649 | - * pagination : The number of element per page |
|
| 650 | - * display_pagination : Display the pagination or not |
|
| 651 | - * } |
|
| 652 | - * |
|
| 653 | - * @return string |
|
| 654 | - * |
|
| 655 | - **/ |
|
| 656 | - public static function wpshop_products_func($atts) |
|
| 657 | - { |
|
| 658 | - global $wpdb, $wp_query; |
|
| 659 | - |
|
| 660 | - $string = ''; |
|
| 661 | - $have_results = false; |
|
| 662 | - $output_results = true; |
|
| 663 | - $type = (empty($atts['type']) or !in_array($atts['type'], array('grid', 'list'))) ? WPSHOP_DISPLAY_LIST_TYPE : $atts['type']; |
|
| 664 | - $pagination = isset($atts['pagination']) ? intval($atts['pagination']) : WPSHOP_ELEMENT_NB_PER_PAGE; |
|
| 665 | - $cid = !empty($atts['cid']) ? $atts['cid'] : 0; |
|
| 666 | - $pid = !empty($atts['pid']) ? $atts['pid'] : 0; |
|
| 667 | - $order_by_sorting = (!empty($atts['sorting']) && ($atts['sorting'] == 'DESC')) ? 'DESC' : 'ASC'; |
|
| 668 | - $limit = isset($atts['limit']) ? intval($atts['limit']) : 0; |
|
| 669 | - $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; |
|
| 670 | - $display_pagination = (!empty($atts['display_pagination'])) ? (($atts['display_pagination'] === "yes") ? true : false) : true; |
|
| 671 | - $attr = ''; |
|
| 672 | - |
|
| 673 | - $sorting_criteria = self::get_sorting_criteria(); |
|
| 674 | - |
|
| 675 | - /** Get products which have att_name equal to att_value */ |
|
| 676 | - if (!empty($atts['att_name']) && !empty($atts['att_value'])) { |
|
| 677 | - $attr = $atts['att_name'] . ':' . $atts['att_value']; |
|
| 678 | - |
|
| 679 | - $products = self::get_products_matching_attribute($atts['att_name'], $atts['att_value']); |
|
| 680 | - |
|
| 681 | - // Foreach on the found products |
|
| 682 | - if (!empty($products)) { |
|
| 683 | - $pid = implode(',', $products); |
|
| 684 | - if (empty($pid)) { |
|
| 685 | - $output_results = false; |
|
| 686 | - } |
|
| 687 | - |
|
| 688 | - } else { |
|
| 689 | - $output_results = false; |
|
| 690 | - } |
|
| 627 | + $related_product_output = self::wpshop_products_func($atts); |
|
| 691 | 628 | |
| 692 | - } |
|
| 629 | + $output = ''; |
|
| 630 | + if (!empty($related_product_output)) { |
|
| 631 | + ob_start(); |
|
| 632 | + require wpshop_tools::get_template_part(WPS_PRODUCT_DIR, WPS_PRODUCT_TEMPLATES_MAIN_DIR, 'frontend', 'related_product'); |
|
| 633 | + $output = ob_get_contents(); |
|
| 634 | + ob_end_clean(); |
|
| 635 | + } |
|
| 693 | 636 | |
| 694 | - /** Get related products */ |
|
| 695 | - if (!empty($atts['product_type'])) { |
|
| 696 | - switch ($atts['product_type']) { |
|
| 697 | - case 'related': |
|
| 698 | - $product_id = !empty($atts['pid']) ? (int) $atts['pid'] : get_the_ID(); |
|
| 699 | - $type = !empty($atts['display_mode']) && in_array($atts['display_mode'], array('list', 'grid')) ? $atts['display_mode'] : WPSHOP_DISPLAY_LIST_TYPE; |
|
| 700 | - $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; |
|
| 701 | - |
|
| 702 | - $pids = get_post_meta((int) $product_id, WPSHOP_PRODUCT_RELATED_PRODUCTS, true); |
|
| 703 | - if (!empty($pids) && !empty($pids[0])) { |
|
| 704 | - $pid = implode(',', $pids); |
|
| 705 | - } |
|
| 706 | - if (empty($pid) || $pid == $product_id) { |
|
| 707 | - $output_results = false; |
|
| 708 | - } |
|
| 709 | - |
|
| 710 | - break; |
|
| 711 | - } |
|
| 712 | - } |
|
| 637 | + return $output; |
|
| 638 | + } |
|
| 639 | + |
|
| 640 | + /** |
|
| 641 | + * Display a list of product from a shortcode |
|
| 642 | + * |
|
| 643 | + * @param array $atts { |
|
| 644 | + * limit : The number of element to display |
|
| 645 | + * order : The information to order list by |
|
| 646 | + * sorting : List order (ASC | DESC) |
|
| 647 | + * display : Display size (normal | mini) |
|
| 648 | + * type : Display tyep (grid | list) only work with display=normal |
|
| 649 | + * pagination : The number of element per page |
|
| 650 | + * display_pagination : Display the pagination or not |
|
| 651 | + * } |
|
| 652 | + * |
|
| 653 | + * @return string |
|
| 654 | + * |
|
| 655 | + **/ |
|
| 656 | + public static function wpshop_products_func($atts) |
|
| 657 | + { |
|
| 658 | + global $wpdb, $wp_query; |
|
| 659 | + |
|
| 660 | + $string = ''; |
|
| 661 | + $have_results = false; |
|
| 662 | + $output_results = true; |
|
| 663 | + $type = (empty($atts['type']) or !in_array($atts['type'], array('grid', 'list'))) ? WPSHOP_DISPLAY_LIST_TYPE : $atts['type']; |
|
| 664 | + $pagination = isset($atts['pagination']) ? intval($atts['pagination']) : WPSHOP_ELEMENT_NB_PER_PAGE; |
|
| 665 | + $cid = !empty($atts['cid']) ? $atts['cid'] : 0; |
|
| 666 | + $pid = !empty($atts['pid']) ? $atts['pid'] : 0; |
|
| 667 | + $order_by_sorting = (!empty($atts['sorting']) && ($atts['sorting'] == 'DESC')) ? 'DESC' : 'ASC'; |
|
| 668 | + $limit = isset($atts['limit']) ? intval($atts['limit']) : 0; |
|
| 669 | + $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; |
|
| 670 | + $display_pagination = (!empty($atts['display_pagination'])) ? (($atts['display_pagination'] === "yes") ? true : false) : true; |
|
| 671 | + $attr = ''; |
|
| 672 | + |
|
| 673 | + $sorting_criteria = self::get_sorting_criteria(); |
|
| 674 | + |
|
| 675 | + /** Get products which have att_name equal to att_value */ |
|
| 676 | + if (!empty($atts['att_name']) && !empty($atts['att_value'])) { |
|
| 677 | + $attr = $atts['att_name'] . ':' . $atts['att_value']; |
|
| 678 | + |
|
| 679 | + $products = self::get_products_matching_attribute($atts['att_name'], $atts['att_value']); |
|
| 680 | + |
|
| 681 | + // Foreach on the found products |
|
| 682 | + if (!empty($products)) { |
|
| 683 | + $pid = implode(',', $products); |
|
| 684 | + if (empty($pid)) { |
|
| 685 | + $output_results = false; |
|
| 686 | + } |
|
| 713 | 687 | |
| 714 | - /** Output all the products */ |
|
| 715 | - if ($output_results) { |
|
| 716 | - $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); |
|
| 688 | + } else { |
|
| 689 | + $output_results = false; |
|
| 690 | + } |
|
| 717 | 691 | |
| 718 | - if ($data[0]) { |
|
| 719 | - $have_results = true; |
|
| 720 | - $string = $data[1]; |
|
| 721 | - } |
|
| 722 | - } |
|
| 692 | + } |
|
| 693 | + |
|
| 694 | + /** Get related products */ |
|
| 695 | + if (!empty($atts['product_type'])) { |
|
| 696 | + switch ($atts['product_type']) { |
|
| 697 | + case 'related': |
|
| 698 | + $product_id = !empty($atts['pid']) ? (int) $atts['pid'] : get_the_ID(); |
|
| 699 | + $type = !empty($atts['display_mode']) && in_array($atts['display_mode'], array('list', 'grid')) ? $atts['display_mode'] : WPSHOP_DISPLAY_LIST_TYPE; |
|
| 700 | + $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; |
|
| 701 | + |
|
| 702 | + $pids = get_post_meta((int) $product_id, WPSHOP_PRODUCT_RELATED_PRODUCTS, true); |
|
| 703 | + if (!empty($pids) && !empty($pids[0])) { |
|
| 704 | + $pid = implode(',', $pids); |
|
| 705 | + } |
|
| 706 | + if (empty($pid) || $pid == $product_id) { |
|
| 707 | + $output_results = false; |
|
| 708 | + } |
|
| 709 | + |
|
| 710 | + break; |
|
| 711 | + } |
|
| 712 | + } |
|
| 713 | + |
|
| 714 | + /** Output all the products */ |
|
| 715 | + if ($output_results) { |
|
| 716 | + $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); |
|
| 717 | + |
|
| 718 | + if ($data[0]) { |
|
| 719 | + $have_results = true; |
|
| 720 | + $string = $data[1]; |
|
| 721 | + } |
|
| 722 | + } |
|
| 723 | + |
|
| 724 | + /** If there are result to display */ |
|
| 725 | + if ($have_results) { |
|
| 726 | + $sorting = ''; |
|
| 727 | + if (!empty($pid)) { |
|
| 728 | + $product_list = explode(',', $pid); |
|
| 729 | + if (count($product_list) == 1) { |
|
| 730 | + $atts['sorting'] = 'no'; |
|
| 731 | + } |
|
| 732 | + } |
|
| 723 | 733 | |
| 724 | - /** If there are result to display */ |
|
| 725 | - if ($have_results) { |
|
| 726 | - $sorting = ''; |
|
| 727 | - if (!empty($pid)) { |
|
| 728 | - $product_list = explode(',', $pid); |
|
| 729 | - if (count($product_list) == 1) { |
|
| 730 | - $atts['sorting'] = 'no'; |
|
| 731 | - } |
|
| 732 | - } |
|
| 733 | - |
|
| 734 | - /* |
|
| 734 | + /* |
|
| 735 | 735 | * Template parameters |
| 736 | 736 | */ |
| 737 | - $template_part = 'product_listing_sorting'; |
|
| 738 | - $tpl_component = array(); |
|
| 737 | + $template_part = 'product_listing_sorting'; |
|
| 738 | + $tpl_component = array(); |
|
| 739 | 739 | |
| 740 | - /* |
|
| 740 | + /* |
|
| 741 | 741 | * Build template |
| 742 | 742 | */ |
| 743 | - $tpl_way_to_take = wpshop_display::check_way_for_template($template_part); |
|
| 744 | - if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) { |
|
| 745 | - /* Include the old way template part */ |
|
| 746 | - ob_start(); |
|
| 747 | - require wpshop_display::get_template_file($tpl_way_to_take[1]); |
|
| 748 | - $sorting = ob_get_contents(); |
|
| 749 | - ob_end_clean(); |
|
| 750 | - } else { |
|
| 751 | - /* |
|
| 743 | + $tpl_way_to_take = wpshop_display::check_way_for_template($template_part); |
|
| 744 | + if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) { |
|
| 745 | + /* Include the old way template part */ |
|
| 746 | + ob_start(); |
|
| 747 | + require wpshop_display::get_template_file($tpl_way_to_take[1]); |
|
| 748 | + $sorting = ob_get_contents(); |
|
| 749 | + ob_end_clean(); |
|
| 750 | + } else { |
|
| 751 | + /* |
|
| 752 | 752 | * Display hidden field every times |
| 753 | 753 | */ |
| 754 | - $sub_template_part = 'product_listing_sorting_hidden_field'; |
|
| 755 | - $sub_tpl_component = array(); |
|
| 756 | - $sub_tpl_component['DISPLAY_TYPE'] = $type; |
|
| 757 | - $sub_tpl_component['ORDER'] = $order_by_sorting; |
|
| 758 | - $sub_tpl_component['PRODUCT_NUMBER'] = $pagination; |
|
| 759 | - $sub_tpl_component['CURRENT_PAGE'] = 1; |
|
| 760 | - $sub_tpl_component['CATEGORY_ID'] = $cid; |
|
| 761 | - $sub_tpl_component['PRODUCT_ID'] = $pid; |
|
| 762 | - $sub_tpl_component['ATTR'] = $attr; |
|
| 763 | - $tpl_component['SORTING_HIDDEN_FIELDS'] = wpshop_display::display_template_element($sub_template_part, $sub_tpl_component, array(), 'admin'); |
|
| 764 | - unset($sub_tpl_component); |
|
| 765 | - |
|
| 766 | - if ((!empty($sorting_criteria) && is_array($sorting_criteria))) { |
|
| 767 | - $sub_template_part = 'product_listing_sorting_criteria'; |
|
| 768 | - $sub_tpl_component = array(); |
|
| 769 | - $criteria = ''; |
|
| 770 | - foreach ($sorting_criteria as $c): |
|
| 754 | + $sub_template_part = 'product_listing_sorting_hidden_field'; |
|
| 755 | + $sub_tpl_component = array(); |
|
| 756 | + $sub_tpl_component['DISPLAY_TYPE'] = $type; |
|
| 757 | + $sub_tpl_component['ORDER'] = $order_by_sorting; |
|
| 758 | + $sub_tpl_component['PRODUCT_NUMBER'] = $pagination; |
|
| 759 | + $sub_tpl_component['CURRENT_PAGE'] = 1; |
|
| 760 | + $sub_tpl_component['CATEGORY_ID'] = $cid; |
|
| 761 | + $sub_tpl_component['PRODUCT_ID'] = $pid; |
|
| 762 | + $sub_tpl_component['ATTR'] = $attr; |
|
| 763 | + $tpl_component['SORTING_HIDDEN_FIELDS'] = wpshop_display::display_template_element($sub_template_part, $sub_tpl_component, array(), 'admin'); |
|
| 764 | + unset($sub_tpl_component); |
|
| 765 | + |
|
| 766 | + if ((!empty($sorting_criteria) && is_array($sorting_criteria))) { |
|
| 767 | + $sub_template_part = 'product_listing_sorting_criteria'; |
|
| 768 | + $sub_tpl_component = array(); |
|
| 769 | + $criteria = ''; |
|
| 770 | + foreach ($sorting_criteria as $c): |
|
| 771 | 771 | $selected = isset( $atts['order'] ) ? $atts['order'] : null; |
| 772 | - $criteria .= '<option value="' . $c['code'] . '" ' . selected( $selected, $c['code'], false ) . '>' . __($c['frontend_label'], 'wpshop') . '</option>'; |
|
| 773 | - endforeach; |
|
| 774 | - $sub_tpl_component['SORTING_CRITERIA_LIST'] = $criteria; |
|
| 775 | - $tpl_component['SORTING_CRITERIA'] = wpshop_display::display_template_element($sub_template_part, $sub_tpl_component); |
|
| 776 | - unset($sub_tpl_component); |
|
| 777 | - } |
|
| 778 | - |
|
| 779 | - if (empty($atts['sorting']) || (!empty($atts['sorting']) && ($atts['sorting'] != 'no'))) { |
|
| 780 | - $tpl_component['DISPLAY_TYPE_STATE_GRID'] = $type == 'grid' ? ' active' : null; |
|
| 781 | - $tpl_component['DISPLAY_TYPE_STATE_LIST'] = $type == 'list' ? ' active' : null; |
|
| 782 | - $sorting = wpshop_display::display_template_element($template_part, $tpl_component); |
|
| 783 | - } else if (!empty($atts['sorting']) && ($atts['sorting'] == 'no')) { |
|
| 784 | - $sub_template_part = 'product_listing_sorting_criteria_hidden'; |
|
| 785 | - $sub_tpl_component = array(); |
|
| 786 | - $sub_tpl_component['CRITERIA_DEFAULT'] = !empty($sorting_criteria[0]['code']) ? $sorting_criteria[0]['code'] : 'title'; |
|
| 787 | - $tpl_component['SORTING_CRITERIA'] = wpshop_display::display_template_element($sub_template_part, $sub_tpl_component, array(), 'admin'); |
|
| 788 | - unset($sub_tpl_component); |
|
| 789 | - |
|
| 790 | - $template_part = 'product_listing_sorting_hidden'; |
|
| 791 | - $sorting = wpshop_display::display_template_element($template_part, $tpl_component, array(), 'admin'); |
|
| 792 | - } |
|
| 793 | - } |
|
| 794 | - unset($tpl_component); |
|
| 795 | - |
|
| 796 | - if (!empty($atts) && !empty($atts['container']) && $atts['container'] == 'no') { |
|
| 797 | - $string = $sorting . '<div data-nonce="' . wp_create_nonce('products_by_criteria') . '" class="wps-catalog-container wps-bloc-loader">' . $string . '</div>'; |
|
| 798 | - } else { |
|
| 799 | - $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>'; |
|
| 800 | - } |
|
| 801 | - } else if (empty($atts['no_result_message']) || ($atts['no_result_message'] != 'no')) { |
|
| 802 | - $string = __('There is nothing to output here', 'wpshop'); |
|
| 803 | - } |
|
| 772 | + $criteria .= '<option value="' . $c['code'] . '" ' . selected( $selected, $c['code'], false ) . '>' . __($c['frontend_label'], 'wpshop') . '</option>'; |
|
| 773 | + endforeach; |
|
| 774 | + $sub_tpl_component['SORTING_CRITERIA_LIST'] = $criteria; |
|
| 775 | + $tpl_component['SORTING_CRITERIA'] = wpshop_display::display_template_element($sub_template_part, $sub_tpl_component); |
|
| 776 | + unset($sub_tpl_component); |
|
| 777 | + } |
|
| 804 | 778 | |
| 805 | - return do_shortcode($string); |
|
| 806 | - } |
|
| 779 | + if (empty($atts['sorting']) || (!empty($atts['sorting']) && ($atts['sorting'] != 'no'))) { |
|
| 780 | + $tpl_component['DISPLAY_TYPE_STATE_GRID'] = $type == 'grid' ? ' active' : null; |
|
| 781 | + $tpl_component['DISPLAY_TYPE_STATE_LIST'] = $type == 'list' ? ' active' : null; |
|
| 782 | + $sorting = wpshop_display::display_template_element($template_part, $tpl_component); |
|
| 783 | + } else if (!empty($atts['sorting']) && ($atts['sorting'] == 'no')) { |
|
| 784 | + $sub_template_part = 'product_listing_sorting_criteria_hidden'; |
|
| 785 | + $sub_tpl_component = array(); |
|
| 786 | + $sub_tpl_component['CRITERIA_DEFAULT'] = !empty($sorting_criteria[0]['code']) ? $sorting_criteria[0]['code'] : 'title'; |
|
| 787 | + $tpl_component['SORTING_CRITERIA'] = wpshop_display::display_template_element($sub_template_part, $sub_tpl_component, array(), 'admin'); |
|
| 788 | + unset($sub_tpl_component); |
|
| 789 | + |
|
| 790 | + $template_part = 'product_listing_sorting_hidden'; |
|
| 791 | + $sorting = wpshop_display::display_template_element($template_part, $tpl_component, array(), 'admin'); |
|
| 792 | + } |
|
| 793 | + } |
|
| 794 | + unset($tpl_component); |
|
| 807 | 795 | |
| 808 | - 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) |
|
| 809 | - { |
|
| 810 | - global $wpdb; |
|
| 796 | + if (!empty($atts) && !empty($atts['container']) && $atts['container'] == 'no') { |
|
| 797 | + $string = $sorting . '<div data-nonce="' . wp_create_nonce('products_by_criteria') . '" class="wps-catalog-container wps-bloc-loader">' . $string . '</div>'; |
|
| 798 | + } else { |
|
| 799 | + $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>'; |
|
| 800 | + } |
|
| 801 | + } else if (empty($atts['no_result_message']) || ($atts['no_result_message'] != 'no')) { |
|
| 802 | + $string = __('There is nothing to output here', 'wpshop'); |
|
| 803 | + } |
|
| 811 | 804 | |
| 812 | - $string = '<span id="wpshop_loading"> </span>'; |
|
| 813 | - $have_results = false; |
|
| 814 | - $display_type = (!empty($display_type) && in_array($display_type, array('grid', 'list'))) ? $display_type : 'grid'; |
|
| 805 | + return do_shortcode($string); |
|
| 806 | + } |
|
| 815 | 807 | |
| 816 | - /** Check if Discount are activated */ |
|
| 817 | - $discount_option = get_option('wpshop_catalog_product_option'); |
|
| 808 | + 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) |
|
| 809 | + { |
|
| 810 | + global $wpdb; |
|
| 818 | 811 | |
| 819 | - if ($criteria == 'product_price' && !empty($discount_option) && !empty($discount_option['discount']) && $discount_option['discount'] == 'on') { |
|
| 820 | - $criteria = 'wpshop_displayed_price'; |
|
| 821 | - } |
|
| 812 | + $string = '<span id="wpshop_loading"> </span>'; |
|
| 813 | + $have_results = false; |
|
| 814 | + $display_type = (!empty($display_type) && in_array($display_type, array('grid', 'list'))) ? $display_type : 'grid'; |
|
| 822 | 815 | |
| 823 | - $query = array( |
|
| 824 | - 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, |
|
| 825 | - 'order' => $order, |
|
| 826 | - 'posts_per_page' => $products_per_page, |
|
| 827 | - 'paged' => $page_number, |
|
| 828 | - 'post_status' => 'publish', |
|
| 829 | - ); |
|
| 830 | - |
|
| 831 | - // If the limit is greater than zero, hide pagination and change posts_per_page var |
|
| 832 | - if ($nb_of_product_limit > 0) { |
|
| 833 | - $query['posts_per_page'] = $nb_of_product_limit; |
|
| 834 | - unset($query['paged']); |
|
| 835 | - } |
|
| 836 | - if (!empty($pid)) { |
|
| 837 | - if (!is_array($pid)) { |
|
| 838 | - $pid = explode(',', $pid); |
|
| 839 | - } |
|
| 816 | + /** Check if Discount are activated */ |
|
| 817 | + $discount_option = get_option('wpshop_catalog_product_option'); |
|
| 840 | 818 | |
| 841 | - $query['post__in'] = $pid; |
|
| 842 | - } |
|
| 843 | - if (!empty($cid)) { |
|
| 844 | - $cid = explode(',', $cid); |
|
| 845 | - $query['tax_query'] = array(array( |
|
| 846 | - 'taxonomy' => WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES, |
|
| 847 | - 'field' => 'id', |
|
| 848 | - 'terms' => $cid, |
|
| 849 | - 'operator' => 'IN', |
|
| 850 | - )); |
|
| 851 | - } |
|
| 852 | - if ($criteria != null) { |
|
| 853 | - switch ($criteria) { |
|
| 854 | - case 'creator': |
|
| 855 | - case 'author': |
|
| 856 | - $query['author'] = get_current_user_id(); |
|
| 857 | - break; |
|
| 858 | - case 'none': |
|
| 859 | - case 'ID': |
|
| 860 | - case 'title': |
|
| 861 | - case 'date': |
|
| 862 | - case 'modified': |
|
| 863 | - case 'relevance': |
|
| 864 | - case 'post__in': |
|
| 865 | - case 'rand': |
|
| 866 | - $query['orderby'] = $criteria; |
|
| 867 | - break; |
|
| 868 | - default: |
|
| 869 | - if (!empty($pid)) { |
|
| 870 | - $post_meta = get_post_meta($pid, '_' . $criteria, true); |
|
| 871 | - } else { |
|
| 872 | - $check_meta = $wpdb->prepare("SELECT COUNT(meta_id) as meta_criteria FROM " . $wpdb->postmeta . " WHERE meta_key = %s", '_' . $criteria); |
|
| 873 | - $post_meta = $wpdb->get_var($check_meta); |
|
| 874 | - } |
|
| 875 | - if (!empty($post_meta)) { |
|
| 876 | - if (in_array($criteria, array('wpshop_displayed_price', 'product_price'))) { |
|
| 877 | - $query['orderby'] = 'meta_value_num'; |
|
| 878 | - } else { |
|
| 879 | - $query['orderby'] = 'meta_value'; |
|
| 880 | - } |
|
| 881 | - $query['meta_key'] = '_' . $criteria; |
|
| 882 | - } |
|
| 883 | - break; |
|
| 884 | - } |
|
| 885 | - } else { |
|
| 886 | - $query['orderby'] = 'menu_order ID'; |
|
| 887 | - } |
|
| 888 | - $post_per_page = $query['posts_per_page']; |
|
| 889 | - $total_products = (!empty($query['post__in'])) ? $query['post__in'] : 0; |
|
| 890 | - if (!empty($pid) && !empty($query['post__in']) && count($query['post__in']) > $query['posts_per_page']) { |
|
| 891 | - $tmp_array = array(); |
|
| 892 | - |
|
| 893 | - if (empty($page_number) || $page_number == 1) { |
|
| 894 | - for ($i = 0; $i < $query['posts_per_page']; $i++) { |
|
| 895 | - $tmp_array[] = $query['post__in'][$i]; |
|
| 896 | - } |
|
| 897 | - } else { |
|
| 898 | - $begin_number = (($page_number - 1) * $query['posts_per_page']); |
|
| 899 | - for ($i = $begin_number; $i < $query['posts_per_page'] + $begin_number; $i++) { |
|
| 900 | - if (!empty($query['post__in'][$i])) { |
|
| 901 | - $tmp_array[] = $query['post__in'][$i]; |
|
| 902 | - } |
|
| 903 | - } |
|
| 904 | - } |
|
| 905 | - unset($query['post__in']); |
|
| 906 | - $query['post__in'] = $tmp_array; |
|
| 907 | - $query['posts_per_page'] = -1; |
|
| 908 | - } |
|
| 819 | + if ($criteria == 'product_price' && !empty($discount_option) && !empty($discount_option['discount']) && $discount_option['discount'] == 'on') { |
|
| 820 | + $criteria = 'wpshop_displayed_price'; |
|
| 821 | + } |
|
| 909 | 822 | |
| 910 | - $query['post_status'] = 'publish'; |
|
| 911 | - |
|
| 912 | - $custom_query = new WP_Query($query); |
|
| 913 | - |
|
| 914 | - if ($custom_query->have_posts()) { |
|
| 915 | - $have_results = true; |
|
| 916 | - |
|
| 917 | - // ---------------- // |
|
| 918 | - // Products listing // |
|
| 919 | - // ---------------- // |
|
| 920 | - $current_position = 1; |
|
| 921 | - $product_list = ''; |
|
| 922 | - while ($custom_query->have_posts()): $custom_query->the_post(); |
|
| 923 | - $cats = get_the_terms(get_the_ID(), WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES); |
|
| 924 | - $cats = !empty($cats) && is_array($cats) ? array_values($cats) : array(); |
|
| 925 | - $cat_id = empty($cats) ? 0 : $cats[0]->term_id; |
|
| 926 | - $product_list .= self::product_mini_output(get_the_ID(), $cat_id, $display_type, $current_position, $grid_element_nb_per_line); |
|
| 927 | - $current_position++; |
|
| 928 | - endwhile; |
|
| 929 | - $tpl_component = array(); |
|
| 930 | - $tpl_component['PRODUCT_CONTAINER_TYPE_CLASS'] = ($display_type == 'grid' ? ' ' . $display_type . '_' . $grid_element_nb_per_line : '') . ' ' . $display_type . '_mode'; |
|
| 931 | - $tpl_component['PRODUCT_LIST_DISPLAY_TYPE'] = $display_type; |
|
| 932 | - $tpl_component['PRODUCT_LIST_PER_LINE'] = $grid_element_nb_per_line; |
|
| 933 | - $tpl_component['PRODUCT_LIST'] = $product_list; |
|
| 934 | - $tpl_component['CROSSED_OUT_PRICE'] = ''; |
|
| 935 | - $tpl_component['LOW_STOCK_ALERT_MESSAGE'] = ''; |
|
| 936 | - $string = wpshop_display::display_template_element('product_list_container', $tpl_component); |
|
| 937 | - |
|
| 938 | - // --------------------- // |
|
| 939 | - // Pagination management // |
|
| 940 | - // --------------------- // |
|
| 941 | - if ( $display_pagination ) { |
|
| 942 | - if ($nb_of_product_limit == 0) { |
|
| 943 | - |
|
| 944 | - $paginate = paginate_links(array( |
|
| 945 | - 'base' => '%_%', |
|
| 946 | - 'format' => '/?page_product=%#%', |
|
| 947 | - 'current' => $page_number, |
|
| 948 | - 'total' => $custom_query->max_num_pages, |
|
| 949 | - 'type' => 'array', |
|
| 950 | - 'prev_next' => false, |
|
| 951 | - )); |
|
| 952 | - if (!empty($paginate)) { |
|
| 953 | - $string .= '<ul class="pagination wps-pagination">'; |
|
| 954 | - foreach ($paginate as $p) { |
|
| 955 | - $string .= '<li>' . $p . '</li>'; |
|
| 956 | - } |
|
| 957 | - $string .= '</ul>'; |
|
| 958 | - } |
|
| 959 | - } |
|
| 960 | - |
|
| 961 | - if (!empty($pid) && !empty($query['post__in']) && count($total_products) > $post_per_page) { |
|
| 962 | - $paginate = paginate_links(array( |
|
| 963 | - 'base' => '%_%', |
|
| 964 | - 'format' => '/?page_product=%#%', |
|
| 965 | - 'current' => $page_number, |
|
| 966 | - 'total' => ceil(count($total_products) / $post_per_page), |
|
| 967 | - 'type' => 'array', |
|
| 968 | - 'prev_next' => false, |
|
| 969 | - )); |
|
| 970 | - if (!empty($paginate)) { |
|
| 971 | - $string .= '<ul class="pagination wps-pagination">'; |
|
| 972 | - foreach ($paginate as $p) { |
|
| 973 | - $string .= '<li>' . $p . '</li>'; |
|
| 974 | - } |
|
| 975 | - $string .= '</ul>'; |
|
| 976 | - } |
|
| 977 | - } |
|
| 978 | - } |
|
| 823 | + $query = array( |
|
| 824 | + 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, |
|
| 825 | + 'order' => $order, |
|
| 826 | + 'posts_per_page' => $products_per_page, |
|
| 827 | + 'paged' => $page_number, |
|
| 828 | + 'post_status' => 'publish', |
|
| 829 | + ); |
|
| 830 | + |
|
| 831 | + // If the limit is greater than zero, hide pagination and change posts_per_page var |
|
| 832 | + if ($nb_of_product_limit > 0) { |
|
| 833 | + $query['posts_per_page'] = $nb_of_product_limit; |
|
| 834 | + unset($query['paged']); |
|
| 835 | + } |
|
| 836 | + if (!empty($pid)) { |
|
| 837 | + if (!is_array($pid)) { |
|
| 838 | + $pid = explode(',', $pid); |
|
| 839 | + } |
|
| 979 | 840 | |
| 980 | - } |
|
| 981 | - wp_reset_query(); // important |
|
| 841 | + $query['post__in'] = $pid; |
|
| 842 | + } |
|
| 843 | + if (!empty($cid)) { |
|
| 844 | + $cid = explode(',', $cid); |
|
| 845 | + $query['tax_query'] = array(array( |
|
| 846 | + 'taxonomy' => WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES, |
|
| 847 | + 'field' => 'id', |
|
| 848 | + 'terms' => $cid, |
|
| 849 | + 'operator' => 'IN', |
|
| 850 | + )); |
|
| 851 | + } |
|
| 852 | + if ($criteria != null) { |
|
| 853 | + switch ($criteria) { |
|
| 854 | + case 'creator': |
|
| 855 | + case 'author': |
|
| 856 | + $query['author'] = get_current_user_id(); |
|
| 857 | + break; |
|
| 858 | + case 'none': |
|
| 859 | + case 'ID': |
|
| 860 | + case 'title': |
|
| 861 | + case 'date': |
|
| 862 | + case 'modified': |
|
| 863 | + case 'relevance': |
|
| 864 | + case 'post__in': |
|
| 865 | + case 'rand': |
|
| 866 | + $query['orderby'] = $criteria; |
|
| 867 | + break; |
|
| 868 | + default: |
|
| 869 | + if (!empty($pid)) { |
|
| 870 | + $post_meta = get_post_meta($pid, '_' . $criteria, true); |
|
| 871 | + } else { |
|
| 872 | + $check_meta = $wpdb->prepare("SELECT COUNT(meta_id) as meta_criteria FROM " . $wpdb->postmeta . " WHERE meta_key = %s", '_' . $criteria); |
|
| 873 | + $post_meta = $wpdb->get_var($check_meta); |
|
| 874 | + } |
|
| 875 | + if (!empty($post_meta)) { |
|
| 876 | + if (in_array($criteria, array('wpshop_displayed_price', 'product_price'))) { |
|
| 877 | + $query['orderby'] = 'meta_value_num'; |
|
| 878 | + } else { |
|
| 879 | + $query['orderby'] = 'meta_value'; |
|
| 880 | + } |
|
| 881 | + $query['meta_key'] = '_' . $criteria; |
|
| 882 | + } |
|
| 883 | + break; |
|
| 884 | + } |
|
| 885 | + } else { |
|
| 886 | + $query['orderby'] = 'menu_order ID'; |
|
| 887 | + } |
|
| 888 | + $post_per_page = $query['posts_per_page']; |
|
| 889 | + $total_products = (!empty($query['post__in'])) ? $query['post__in'] : 0; |
|
| 890 | + if (!empty($pid) && !empty($query['post__in']) && count($query['post__in']) > $query['posts_per_page']) { |
|
| 891 | + $tmp_array = array(); |
|
| 892 | + |
|
| 893 | + if (empty($page_number) || $page_number == 1) { |
|
| 894 | + for ($i = 0; $i < $query['posts_per_page']; $i++) { |
|
| 895 | + $tmp_array[] = $query['post__in'][$i]; |
|
| 896 | + } |
|
| 897 | + } else { |
|
| 898 | + $begin_number = (($page_number - 1) * $query['posts_per_page']); |
|
| 899 | + for ($i = $begin_number; $i < $query['posts_per_page'] + $begin_number; $i++) { |
|
| 900 | + if (!empty($query['post__in'][$i])) { |
|
| 901 | + $tmp_array[] = $query['post__in'][$i]; |
|
| 902 | + } |
|
| 903 | + } |
|
| 904 | + } |
|
| 905 | + unset($query['post__in']); |
|
| 906 | + $query['post__in'] = $tmp_array; |
|
| 907 | + $query['posts_per_page'] = -1; |
|
| 908 | + } |
|
| 982 | 909 | |
| 983 | - return array($have_results, $string); |
|
| 984 | - } |
|
| 910 | + $query['post_status'] = 'publish'; |
|
| 911 | + |
|
| 912 | + $custom_query = new WP_Query($query); |
|
| 913 | + |
|
| 914 | + if ($custom_query->have_posts()) { |
|
| 915 | + $have_results = true; |
|
| 916 | + |
|
| 917 | + // ---------------- // |
|
| 918 | + // Products listing // |
|
| 919 | + // ---------------- // |
|
| 920 | + $current_position = 1; |
|
| 921 | + $product_list = ''; |
|
| 922 | + while ($custom_query->have_posts()): $custom_query->the_post(); |
|
| 923 | + $cats = get_the_terms(get_the_ID(), WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES); |
|
| 924 | + $cats = !empty($cats) && is_array($cats) ? array_values($cats) : array(); |
|
| 925 | + $cat_id = empty($cats) ? 0 : $cats[0]->term_id; |
|
| 926 | + $product_list .= self::product_mini_output(get_the_ID(), $cat_id, $display_type, $current_position, $grid_element_nb_per_line); |
|
| 927 | + $current_position++; |
|
| 928 | + endwhile; |
|
| 929 | + $tpl_component = array(); |
|
| 930 | + $tpl_component['PRODUCT_CONTAINER_TYPE_CLASS'] = ($display_type == 'grid' ? ' ' . $display_type . '_' . $grid_element_nb_per_line : '') . ' ' . $display_type . '_mode'; |
|
| 931 | + $tpl_component['PRODUCT_LIST_DISPLAY_TYPE'] = $display_type; |
|
| 932 | + $tpl_component['PRODUCT_LIST_PER_LINE'] = $grid_element_nb_per_line; |
|
| 933 | + $tpl_component['PRODUCT_LIST'] = $product_list; |
|
| 934 | + $tpl_component['CROSSED_OUT_PRICE'] = ''; |
|
| 935 | + $tpl_component['LOW_STOCK_ALERT_MESSAGE'] = ''; |
|
| 936 | + $string = wpshop_display::display_template_element('product_list_container', $tpl_component); |
|
| 937 | + |
|
| 938 | + // --------------------- // |
|
| 939 | + // Pagination management // |
|
| 940 | + // --------------------- // |
|
| 941 | + if ( $display_pagination ) { |
|
| 942 | + if ($nb_of_product_limit == 0) { |
|
| 943 | + |
|
| 944 | + $paginate = paginate_links(array( |
|
| 945 | + 'base' => '%_%', |
|
| 946 | + 'format' => '/?page_product=%#%', |
|
| 947 | + 'current' => $page_number, |
|
| 948 | + 'total' => $custom_query->max_num_pages, |
|
| 949 | + 'type' => 'array', |
|
| 950 | + 'prev_next' => false, |
|
| 951 | + )); |
|
| 952 | + if (!empty($paginate)) { |
|
| 953 | + $string .= '<ul class="pagination wps-pagination">'; |
|
| 954 | + foreach ($paginate as $p) { |
|
| 955 | + $string .= '<li>' . $p . '</li>'; |
|
| 956 | + } |
|
| 957 | + $string .= '</ul>'; |
|
| 958 | + } |
|
| 959 | + } |
|
| 960 | + |
|
| 961 | + if (!empty($pid) && !empty($query['post__in']) && count($total_products) > $post_per_page) { |
|
| 962 | + $paginate = paginate_links(array( |
|
| 963 | + 'base' => '%_%', |
|
| 964 | + 'format' => '/?page_product=%#%', |
|
| 965 | + 'current' => $page_number, |
|
| 966 | + 'total' => ceil(count($total_products) / $post_per_page), |
|
| 967 | + 'type' => 'array', |
|
| 968 | + 'prev_next' => false, |
|
| 969 | + )); |
|
| 970 | + if (!empty($paginate)) { |
|
| 971 | + $string .= '<ul class="pagination wps-pagination">'; |
|
| 972 | + foreach ($paginate as $p) { |
|
| 973 | + $string .= '<li>' . $p . '</li>'; |
|
| 974 | + } |
|
| 975 | + $string .= '</ul>'; |
|
| 976 | + } |
|
| 977 | + } |
|
| 978 | + } |
|
| 979 | + |
|
| 980 | + } |
|
| 981 | + wp_reset_query(); // important |
|
| 982 | + |
|
| 983 | + return array($have_results, $string); |
|
| 984 | + } |
|
| 985 | 985 | |
| 986 | 986 | /** |
| 987 | - * Update quantity for a product |
|
| 988 | - * @param integer $product_id The product we want to update quantity for |
|
| 989 | - * @param decimal $qty The new quantity |
|
| 990 | - */ |
|
| 987 | + * Update quantity for a product |
|
| 988 | + * @param integer $product_id The product we want to update quantity for |
|
| 989 | + * @param decimal $qty The new quantity |
|
| 990 | + */ |
|
| 991 | 991 | public static function reduce_product_stock_qty($product_id, $qty, $variation_id = '') { |
| 992 | 992 | global $wpdb; |
| 993 | 993 | |
@@ -1042,16 +1042,16 @@ discard block |
||
| 1042 | 1042 | } |
| 1043 | 1043 | } |
| 1044 | 1044 | |
| 1045 | - /** |
|
| 1046 | - * Retrieve an array with complete information about a given product |
|
| 1047 | - * @param integer $product_id |
|
| 1048 | - * @param boolean $for_cart_storage |
|
| 1049 | - * @return array Information about the product defined by first parameter |
|
| 1050 | - */ |
|
| 1051 | - public static function get_product_data($product_id, $for_cart_storage = false, $post_status = '"publish"') |
|
| 1052 | - { |
|
| 1053 | - global $wpdb; |
|
| 1054 | - $query = $wpdb->prepare(' |
|
| 1045 | + /** |
|
| 1046 | + * Retrieve an array with complete information about a given product |
|
| 1047 | + * @param integer $product_id |
|
| 1048 | + * @param boolean $for_cart_storage |
|
| 1049 | + * @return array Information about the product defined by first parameter |
|
| 1050 | + */ |
|
| 1051 | + public static function get_product_data($product_id, $for_cart_storage = false, $post_status = '"publish"') |
|
| 1052 | + { |
|
| 1053 | + global $wpdb; |
|
| 1054 | + $query = $wpdb->prepare(' |
|
| 1055 | 1055 | SELECT P.*, PM.meta_value AS attribute_set_id |
| 1056 | 1056 | FROM ' . $wpdb->posts . ' AS P |
| 1057 | 1057 | INNER JOIN ' . $wpdb->postmeta . ' AS PM ON (PM.post_id=P.ID) |
@@ -1063,398 +1063,398 @@ discard block |
||
| 1063 | 1063 | LIMIT 1 |
| 1064 | 1064 | ', $product_id); |
| 1065 | 1065 | |
| 1066 | - $product = $wpdb->get_row($query); |
|
| 1067 | - |
|
| 1068 | - $product_data = array(); |
|
| 1069 | - $product_meta = array(); |
|
| 1070 | - |
|
| 1071 | - if (!empty($product)) { |
|
| 1072 | - $product_data['product_id'] = (!empty($product->ID)) ? $product->ID : ''; |
|
| 1073 | - $product_data['post_name'] = (!empty($product->post_name)) ? $product->post_name : ''; |
|
| 1074 | - $product_data['product_name'] = (!empty($product->post_title)) ? $product->post_title : ''; |
|
| 1075 | - $product_data['post_title'] = (!empty($product->post_title)) ? $product->post_title : ''; |
|
| 1076 | - |
|
| 1077 | - $product_data['product_author_id'] = (!empty($product->post_author)) ? $product->post_author : ''; |
|
| 1078 | - $product_data['product_date'] = (!empty($product->post_date)) ? $product->post_date : ''; |
|
| 1079 | - $product_data['product_content'] = (!empty($product->post_content)) ? $product->post_content : ''; |
|
| 1080 | - $product_data['product_excerpt'] = (!empty($product->post_excerpt)) ? $product->post_excerpt : wp_trim_words($product_data['product_content'], apply_filters('excerpt_length', 50), '...'); |
|
| 1081 | - |
|
| 1082 | - $product_data['product_meta_attribute_set_id'] = (!empty($product->attribute_set_id)) ? $product->attribute_set_id : ''; |
|
| 1083 | - |
|
| 1084 | - $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); |
|
| 1085 | - if (!empty($data)) { |
|
| 1086 | - foreach ($data as $attribute) { |
|
| 1087 | - $data_type = 'attribute_value_' . $attribute->data_type; |
|
| 1088 | - $value = $attribute->$data_type; |
|
| 1089 | - if (in_array($attribute->backend_input, array('select', 'multiple-select', 'radio', 'checkbox'))) { |
|
| 1090 | - $value = wpshop_attributes::get_attribute_type_select_option_info($value, 'value'); |
|
| 1091 | - } |
|
| 1092 | - |
|
| 1093 | - /** Special traitment regarding attribute_code */ |
|
| 1094 | - switch ($attribute->attribute_code) { |
|
| 1095 | - case 'product_weight': |
|
| 1096 | - $default_weight_unity = get_option('wpshop_shop_default_weight_unity'); |
|
| 1097 | - if (!empty($default_weight_unity)) { |
|
| 1098 | - $query = $wpdb->prepare('SELECT unit FROM ' . WPSHOP_DBT_ATTRIBUTE_UNIT . ' WHERE id = %d', $default_weight_unity); |
|
| 1099 | - $unity = $wpdb->get_var($query); |
|
| 1100 | - if ($unity == 'kg') { |
|
| 1101 | - $value *= 1000; |
|
| 1102 | - } |
|
| 1103 | - |
|
| 1104 | - } |
|
| 1105 | - break; |
|
| 1106 | - default: |
|
| 1107 | - $value = !empty($value) ? $value : 0; |
|
| 1108 | - break; |
|
| 1109 | - } |
|
| 1110 | - $product_data[$attribute->attribute_code] = $value; |
|
| 1111 | - |
|
| 1112 | - if (!$for_cart_storage or $for_cart_storage && $attribute->is_recordable_in_cart_meta == 'yes') { |
|
| 1113 | - $meta = get_post_meta($product->ID, 'attribute_option_' . $attribute->attribute_code, true); |
|
| 1114 | - if (!empty($meta)) { |
|
| 1115 | - $product_meta[$attribute->attribute_code] = $meta; |
|
| 1116 | - } |
|
| 1117 | - } |
|
| 1118 | - |
|
| 1119 | - if (($attribute->is_visible_in_front == 'yes') && (!in_array($attribute->attribute_code, unserialize(WPSHOP_ATTRIBUTE_PRICES)))) { |
|
| 1120 | - $product_meta['attribute_visible'][$attribute->attribute_code] = $value; |
|
| 1121 | - } |
|
| 1122 | - if (($attribute->is_visible_in_front_listing == 'yes') && (!in_array($attribute->attribute_code, unserialize(WPSHOP_ATTRIBUTE_PRICES)))) { |
|
| 1123 | - $product_meta['attribute_visible_listing'][$attribute->attribute_code] = $value; |
|
| 1124 | - } |
|
| 1125 | - } |
|
| 1126 | - } else { |
|
| 1127 | - |
|
| 1128 | - } |
|
| 1129 | - |
|
| 1130 | - /** Get datas about product options */ |
|
| 1131 | - if ($product->post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) { |
|
| 1132 | - $variation_details = get_post_meta($product->ID, '_wpshop_variations_attribute_def', true); |
|
| 1133 | - |
|
| 1134 | - foreach ($variation_details as $attribute_code => $attribute_value) { |
|
| 1135 | - $variation_id = $attribute_value; |
|
| 1136 | - $attribute_definition = wpshop_attributes::getElement($attribute_code, "'valid'", 'code'); |
|
| 1137 | - |
|
| 1138 | - $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)); |
|
| 1139 | - $product_meta['variation_definition'][$attribute_code]['NAME'] = $attribute_definition->frontend_label; |
|
| 1140 | - switch ($attribute_definition->backend_input) { |
|
| 1141 | - case 'select': |
|
| 1142 | - case 'multiple-select': |
|
| 1143 | - case 'radio': |
|
| 1144 | - case 'checkbox': |
|
| 1145 | - $attribute_value = wpshop_attributes::get_attribute_type_select_option_info($attribute_value, 'label', $attribute_definition->data_type_to_use, true); |
|
| 1146 | - break; |
|
| 1147 | - } |
|
| 1148 | - $product_meta['variation_definition'][$attribute_code]['VALUE'] = $attribute_value; |
|
| 1149 | - $product_meta['variation_definition'][$attribute_code]['ID'] = $variation_id; |
|
| 1150 | - } |
|
| 1151 | - } |
|
| 1152 | - |
|
| 1153 | - $product_data['item_meta'] = !empty($product_meta) ? $product_meta : array(); |
|
| 1154 | - |
|
| 1155 | - /** Get the display definition for the current product for checking custom display */ |
|
| 1156 | - $product_data['custom_display'] = get_post_meta($product_id, WPSHOP_PRODUCT_FRONT_DISPLAY_CONF, true); |
|
| 1157 | - } |
|
| 1066 | + $product = $wpdb->get_row($query); |
|
| 1067 | + |
|
| 1068 | + $product_data = array(); |
|
| 1069 | + $product_meta = array(); |
|
| 1070 | + |
|
| 1071 | + if (!empty($product)) { |
|
| 1072 | + $product_data['product_id'] = (!empty($product->ID)) ? $product->ID : ''; |
|
| 1073 | + $product_data['post_name'] = (!empty($product->post_name)) ? $product->post_name : ''; |
|
| 1074 | + $product_data['product_name'] = (!empty($product->post_title)) ? $product->post_title : ''; |
|
| 1075 | + $product_data['post_title'] = (!empty($product->post_title)) ? $product->post_title : ''; |
|
| 1076 | + |
|
| 1077 | + $product_data['product_author_id'] = (!empty($product->post_author)) ? $product->post_author : ''; |
|
| 1078 | + $product_data['product_date'] = (!empty($product->post_date)) ? $product->post_date : ''; |
|
| 1079 | + $product_data['product_content'] = (!empty($product->post_content)) ? $product->post_content : ''; |
|
| 1080 | + $product_data['product_excerpt'] = (!empty($product->post_excerpt)) ? $product->post_excerpt : wp_trim_words($product_data['product_content'], apply_filters('excerpt_length', 50), '...'); |
|
| 1081 | + |
|
| 1082 | + $product_data['product_meta_attribute_set_id'] = (!empty($product->attribute_set_id)) ? $product->attribute_set_id : ''; |
|
| 1083 | + |
|
| 1084 | + $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); |
|
| 1085 | + if (!empty($data)) { |
|
| 1086 | + foreach ($data as $attribute) { |
|
| 1087 | + $data_type = 'attribute_value_' . $attribute->data_type; |
|
| 1088 | + $value = $attribute->$data_type; |
|
| 1089 | + if (in_array($attribute->backend_input, array('select', 'multiple-select', 'radio', 'checkbox'))) { |
|
| 1090 | + $value = wpshop_attributes::get_attribute_type_select_option_info($value, 'value'); |
|
| 1091 | + } |
|
| 1092 | + |
|
| 1093 | + /** Special traitment regarding attribute_code */ |
|
| 1094 | + switch ($attribute->attribute_code) { |
|
| 1095 | + case 'product_weight': |
|
| 1096 | + $default_weight_unity = get_option('wpshop_shop_default_weight_unity'); |
|
| 1097 | + if (!empty($default_weight_unity)) { |
|
| 1098 | + $query = $wpdb->prepare('SELECT unit FROM ' . WPSHOP_DBT_ATTRIBUTE_UNIT . ' WHERE id = %d', $default_weight_unity); |
|
| 1099 | + $unity = $wpdb->get_var($query); |
|
| 1100 | + if ($unity == 'kg') { |
|
| 1101 | + $value *= 1000; |
|
| 1102 | + } |
|
| 1103 | + |
|
| 1104 | + } |
|
| 1105 | + break; |
|
| 1106 | + default: |
|
| 1107 | + $value = !empty($value) ? $value : 0; |
|
| 1108 | + break; |
|
| 1109 | + } |
|
| 1110 | + $product_data[$attribute->attribute_code] = $value; |
|
| 1111 | + |
|
| 1112 | + if (!$for_cart_storage or $for_cart_storage && $attribute->is_recordable_in_cart_meta == 'yes') { |
|
| 1113 | + $meta = get_post_meta($product->ID, 'attribute_option_' . $attribute->attribute_code, true); |
|
| 1114 | + if (!empty($meta)) { |
|
| 1115 | + $product_meta[$attribute->attribute_code] = $meta; |
|
| 1116 | + } |
|
| 1117 | + } |
|
| 1118 | + |
|
| 1119 | + if (($attribute->is_visible_in_front == 'yes') && (!in_array($attribute->attribute_code, unserialize(WPSHOP_ATTRIBUTE_PRICES)))) { |
|
| 1120 | + $product_meta['attribute_visible'][$attribute->attribute_code] = $value; |
|
| 1121 | + } |
|
| 1122 | + if (($attribute->is_visible_in_front_listing == 'yes') && (!in_array($attribute->attribute_code, unserialize(WPSHOP_ATTRIBUTE_PRICES)))) { |
|
| 1123 | + $product_meta['attribute_visible_listing'][$attribute->attribute_code] = $value; |
|
| 1124 | + } |
|
| 1125 | + } |
|
| 1126 | + } else { |
|
| 1158 | 1127 | |
| 1159 | - return $product_data; |
|
| 1160 | - } |
|
| 1128 | + } |
|
| 1161 | 1129 | |
| 1162 | - /** |
|
| 1163 | - * Add a product into the db. This function is used for the EDI |
|
| 1164 | - * @param $name Name of the product |
|
| 1165 | - * @param $description Description of the product |
|
| 1166 | - * @param $attrs List of the attributes and values of the product |
|
| 1167 | - * @return boolean |
|
| 1168 | - */ |
|
| 1169 | - public function addProduct($name, $description, $attrs = array()) |
|
| 1170 | - { |
|
| 1171 | - $new_product = wpshop_entities::create_new_entity(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, $name, $description, $attrs); |
|
| 1172 | - return $new_product[0]; |
|
| 1173 | - } |
|
| 1130 | + /** Get datas about product options */ |
|
| 1131 | + if ($product->post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) { |
|
| 1132 | + $variation_details = get_post_meta($product->ID, '_wpshop_variations_attribute_def', true); |
|
| 1133 | + |
|
| 1134 | + foreach ($variation_details as $attribute_code => $attribute_value) { |
|
| 1135 | + $variation_id = $attribute_value; |
|
| 1136 | + $attribute_definition = wpshop_attributes::getElement($attribute_code, "'valid'", 'code'); |
|
| 1137 | + |
|
| 1138 | + $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)); |
|
| 1139 | + $product_meta['variation_definition'][$attribute_code]['NAME'] = $attribute_definition->frontend_label; |
|
| 1140 | + switch ($attribute_definition->backend_input) { |
|
| 1141 | + case 'select': |
|
| 1142 | + case 'multiple-select': |
|
| 1143 | + case 'radio': |
|
| 1144 | + case 'checkbox': |
|
| 1145 | + $attribute_value = wpshop_attributes::get_attribute_type_select_option_info($attribute_value, 'label', $attribute_definition->data_type_to_use, true); |
|
| 1146 | + break; |
|
| 1147 | + } |
|
| 1148 | + $product_meta['variation_definition'][$attribute_code]['VALUE'] = $attribute_value; |
|
| 1149 | + $product_meta['variation_definition'][$attribute_code]['ID'] = $variation_id; |
|
| 1150 | + } |
|
| 1151 | + } |
|
| 1174 | 1152 | |
| 1175 | - /** |
|
| 1176 | - * Retrieve a product listing |
|
| 1177 | - * @param boolean $formated If the output have to be formated or not |
|
| 1178 | - * @param string $product_search Optionnal Define a search term for request |
|
| 1179 | - * @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 |
|
| 1180 | - */ |
|
| 1181 | - public static function product_list($formated = false, $product_search = null) |
|
| 1182 | - { |
|
| 1183 | - global $wpdb; |
|
| 1184 | - |
|
| 1185 | - $query_extra_params = $query_extra_params_value = ''; |
|
| 1186 | - if (!empty($product_search)) { |
|
| 1187 | - $query_extra_params = " AND post_title LIKE '%%" . $product_search . "%%'"; |
|
| 1188 | - if (is_array($product_search)) { |
|
| 1189 | - $query_extra_params = " AND ID IN (%s)"; |
|
| 1190 | - $query_extra_params_value = implode(",", $product_search); |
|
| 1191 | - } |
|
| 1192 | - } |
|
| 1153 | + $product_data['item_meta'] = !empty($product_meta) ? $product_meta : array(); |
|
| 1154 | + |
|
| 1155 | + /** Get the display definition for the current product for checking custom display */ |
|
| 1156 | + $product_data['custom_display'] = get_post_meta($product_id, WPSHOP_PRODUCT_FRONT_DISPLAY_CONF, true); |
|
| 1157 | + } |
|
| 1158 | + |
|
| 1159 | + return $product_data; |
|
| 1160 | + } |
|
| 1161 | + |
|
| 1162 | + /** |
|
| 1163 | + * Add a product into the db. This function is used for the EDI |
|
| 1164 | + * @param $name Name of the product |
|
| 1165 | + * @param $description Description of the product |
|
| 1166 | + * @param $attrs List of the attributes and values of the product |
|
| 1167 | + * @return boolean |
|
| 1168 | + */ |
|
| 1169 | + public function addProduct($name, $description, $attrs = array()) |
|
| 1170 | + { |
|
| 1171 | + $new_product = wpshop_entities::create_new_entity(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, $name, $description, $attrs); |
|
| 1172 | + return $new_product[0]; |
|
| 1173 | + } |
|
| 1174 | + |
|
| 1175 | + /** |
|
| 1176 | + * Retrieve a product listing |
|
| 1177 | + * @param boolean $formated If the output have to be formated or not |
|
| 1178 | + * @param string $product_search Optionnal Define a search term for request |
|
| 1179 | + * @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 |
|
| 1180 | + */ |
|
| 1181 | + public static function product_list($formated = false, $product_search = null) |
|
| 1182 | + { |
|
| 1183 | + global $wpdb; |
|
| 1184 | + |
|
| 1185 | + $query_extra_params = $query_extra_params_value = ''; |
|
| 1186 | + if (!empty($product_search)) { |
|
| 1187 | + $query_extra_params = " AND post_title LIKE '%%" . $product_search . "%%'"; |
|
| 1188 | + if (is_array($product_search)) { |
|
| 1189 | + $query_extra_params = " AND ID IN (%s)"; |
|
| 1190 | + $query_extra_params_value = implode(",", $product_search); |
|
| 1191 | + } |
|
| 1192 | + } |
|
| 1193 | 1193 | |
| 1194 | - $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); |
|
| 1195 | - $data = $wpdb->get_results($query); |
|
| 1194 | + $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); |
|
| 1195 | + $data = $wpdb->get_results($query); |
|
| 1196 | 1196 | |
| 1197 | - /* |
|
| 1197 | + /* |
|
| 1198 | 1198 | * Make some arangement on output if parameter is given |
| 1199 | 1199 | */ |
| 1200 | - if ($formated) { |
|
| 1201 | - $product_string = ''; |
|
| 1202 | - foreach ($data as $d) { |
|
| 1203 | - $product_string .= ' |
|
| 1200 | + if ($formated) { |
|
| 1201 | + $product_string = ''; |
|
| 1202 | + foreach ($data as $d) { |
|
| 1203 | + $product_string .= ' |
|
| 1204 | 1204 | <li class="wpshop_shortcode_element_container wpshop_shortcode_element_container_product" > |
| 1205 | 1205 | <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> |
| 1206 | 1206 | </li>'; |
| 1207 | - } |
|
| 1208 | - } |
|
| 1207 | + } |
|
| 1208 | + } |
|
| 1209 | 1209 | |
| 1210 | - return $formated ? $product_string : $data; |
|
| 1211 | - } |
|
| 1210 | + return $formated ? $product_string : $data; |
|
| 1211 | + } |
|
| 1212 | 1212 | |
| 1213 | - /** |
|
| 1214 | - * Enregistrement des données pour le produit |
|
| 1215 | - */ |
|
| 1216 | - public function save_product_custom_informations($post_id, $data_to_save = array()) |
|
| 1217 | - { |
|
| 1218 | - global $wpdb; |
|
| 1219 | - |
|
| 1220 | - $data_to_save = (!empty($data_to_save)) ? $data_to_save : (array) $_REQUEST; |
|
| 1221 | - // Apply a filter to extra actions |
|
| 1222 | - $data_to_save = apply_filters('wps_save_product_extra_filter', $data_to_save); |
|
| 1223 | - |
|
| 1224 | - 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"))) { |
|
| 1225 | - if (!empty($data_to_save[wpshop_products::currentPageCode . '_attribute'])) { |
|
| 1226 | - /* Fill the product reference automatically if nothing is sent */ |
|
| 1227 | - if (empty($data_to_save[wpshop_products::currentPageCode . '_attribute']['varchar']['product_reference'])) { |
|
| 1228 | - $query = "SELECT MAX(ID) AS PDCT_ID FROM {$wpdb->posts}"; |
|
| 1229 | - $last_ref = $wpdb->get_var($query); |
|
| 1230 | - $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; |
|
| 1231 | - } else { |
|
| 1232 | - /* Check if the product reference existing in the database */ |
|
| 1233 | - $ref = $data_to_save[wpshop_products::currentPageCode . '_attribute']['varchar']['product_reference']; |
|
| 1234 | - $query = $wpdb->prepare( |
|
| 1235 | - "SELECT value_id |
|
| 1213 | + /** |
|
| 1214 | + * Enregistrement des données pour le produit |
|
| 1215 | + */ |
|
| 1216 | + public function save_product_custom_informations($post_id, $data_to_save = array()) |
|
| 1217 | + { |
|
| 1218 | + global $wpdb; |
|
| 1219 | + |
|
| 1220 | + $data_to_save = (!empty($data_to_save)) ? $data_to_save : (array) $_REQUEST; |
|
| 1221 | + // Apply a filter to extra actions |
|
| 1222 | + $data_to_save = apply_filters('wps_save_product_extra_filter', $data_to_save); |
|
| 1223 | + |
|
| 1224 | + 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"))) { |
|
| 1225 | + if (!empty($data_to_save[wpshop_products::currentPageCode . '_attribute'])) { |
|
| 1226 | + /* Fill the product reference automatically if nothing is sent */ |
|
| 1227 | + if (empty($data_to_save[wpshop_products::currentPageCode . '_attribute']['varchar']['product_reference'])) { |
|
| 1228 | + $query = "SELECT MAX(ID) AS PDCT_ID FROM {$wpdb->posts}"; |
|
| 1229 | + $last_ref = $wpdb->get_var($query); |
|
| 1230 | + $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; |
|
| 1231 | + } else { |
|
| 1232 | + /* Check if the product reference existing in the database */ |
|
| 1233 | + $ref = $data_to_save[wpshop_products::currentPageCode . '_attribute']['varchar']['product_reference']; |
|
| 1234 | + $query = $wpdb->prepare( |
|
| 1235 | + "SELECT value_id |
|
| 1236 | 1236 | FROM " . WPSHOP_DBT_ATTRIBUTE_VALUES_VARCHAR . " |
| 1237 | 1237 | INNER JOIN {$wpdb->posts} ON ( ID = entity_id ) |
| 1238 | 1238 | WHERE value = %s |
| 1239 | 1239 | AND entity_id != %d |
| 1240 | 1240 | AND entity_type_id = %d" |
| 1241 | - , $ref, $data_to_save['post_ID'], wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT)); |
|
| 1242 | - $existing_reference = $wpdb->get_var($query); |
|
| 1243 | - |
|
| 1244 | - /* If this product reference exist -> Create a new product reference */ |
|
| 1245 | - if ($wpdb->num_rows > 0) { |
|
| 1246 | - $query = "SELECT MAX(ID) AS PDCT_ID FROM " . $wpdb->posts; |
|
| 1247 | - $last_ref = $wpdb->get_var($query); |
|
| 1248 | - $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; |
|
| 1249 | - } |
|
| 1250 | - } |
|
| 1251 | - |
|
| 1252 | - /* Save the attributes values into wpshop eav database */ |
|
| 1253 | - $update_from = !empty($data_to_save[wpshop_products::currentPageCode . '_provenance']) ? $data_to_save[wpshop_products::currentPageCode . '_provenance'] : ''; |
|
| 1254 | - $lang = WPSHOP_CURRENT_LOCALE; |
|
| 1255 | - if (!empty($data_to_save['icl_post_language'])) { |
|
| 1256 | - $query = $wpdb->prepare("SELECT locale FROM " . $wpdb->prefix . "icl_locale_map WHERE code = %s", $data_to_save['icl_post_language']); |
|
| 1257 | - $lang = $wpdb->get_var($query); |
|
| 1258 | - } |
|
| 1259 | - 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); |
|
| 1260 | - |
|
| 1261 | - /* Update product price looking for shop parameters */ |
|
| 1262 | - wpshop_products::calculate_price($data_to_save['post_ID']); |
|
| 1263 | - |
|
| 1264 | - /* Save the attributes values into wordpress post metadata database in order to have a backup and to make frontend search working */ |
|
| 1265 | - $productMetaDatas = array(); |
|
| 1266 | - foreach ($data_to_save[wpshop_products::currentPageCode . '_attribute'] as $attributeType => $attributeValues) { |
|
| 1267 | - foreach ($attributeValues as $attributeCode => $attributeValue) { |
|
| 1268 | - if ($attributeCode == 'product_attribute_set_id') { |
|
| 1269 | - /* Update the attribute set id for the current product */ |
|
| 1270 | - update_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, $attributeValue); |
|
| 1271 | - } |
|
| 1272 | - if ($attributeType == 'decimal') { |
|
| 1273 | - $attributeValue = str_replace(',', '.', $attributeValue); |
|
| 1274 | - } |
|
| 1275 | - if (($attributeType == 'integer') && !is_array($attributeValue)) { |
|
| 1276 | - $attributeValue = (int) $attributeValue; |
|
| 1277 | - } |
|
| 1278 | - $productMetaDatas[$attributeCode] = $attributeValue; |
|
| 1279 | - } |
|
| 1280 | - } |
|
| 1281 | - update_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, $productMetaDatas); |
|
| 1282 | - } |
|
| 1283 | - |
|
| 1284 | - if (!empty($data_to_save[wpshop_products::currentPageCode . '_attr_frontend_display']) && empty($data_to_save[wpshop_products::currentPageCode . '_attr_frontend_display']['default_config'])) { |
|
| 1285 | - update_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_FRONT_DISPLAY_CONF, $data_to_save[wpshop_products::currentPageCode . '_attr_frontend_display']); |
|
| 1286 | - } else if ($data_to_save['action'] != 'autosave') { |
|
| 1287 | - delete_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_FRONT_DISPLAY_CONF); |
|
| 1288 | - } |
|
| 1289 | - |
|
| 1290 | - $product = wpshop_products::get_product_data($data_to_save['post_ID'], false, '"publish"'); |
|
| 1291 | - if (empty($product['product_id'])) { |
|
| 1292 | - $product['product_id'] = $data_to_save['post_ID']; |
|
| 1293 | - } |
|
| 1294 | - $price = wpshop_prices::get_product_price($product, 'just_price_infos', array('mini_output', 'grid')); |
|
| 1295 | - update_post_meta($data_to_save['post_ID'], '_wps_price_infos', $price); |
|
| 1296 | - |
|
| 1297 | - /** Save product variation */ |
|
| 1298 | - if (!empty($data_to_save[WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION])) { |
|
| 1299 | - foreach ($data_to_save[WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION] as $variation_id => $variation_definition) { |
|
| 1300 | - |
|
| 1301 | - foreach (unserialize(WPSHOP_ATTRIBUTE_PRICES) as $price_attribute_code) { |
|
| 1302 | - $price_attr_def = wpshop_attributes::getElement($price_attribute_code, "'valid'", 'code'); |
|
| 1303 | - 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])) { |
|
| 1304 | - $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; |
|
| 1305 | - } |
|
| 1306 | - } |
|
| 1307 | - $lang = WPSHOP_CURRENT_LOCALE; |
|
| 1308 | - if (!empty($data_to_save['icl_post_language'])) { |
|
| 1309 | - $query = $wpdb->prepare("SELECT locale FROM " . $wpdb->prefix . "icl_locale_map WHERE code = %s", $data_to_save['icl_post_language']); |
|
| 1310 | - $lang = $wpdb->get_var($query); |
|
| 1311 | - } |
|
| 1312 | - wpshop_attributes::saveAttributeForEntity($variation_definition['attribute'], wpshop_entities::get_entity_identifier_from_code(wpshop_products::currentPageCode), $variation_id, $lang); |
|
| 1313 | - |
|
| 1314 | - /** Save the attributes values into wordpress post metadata database in order to have a backup and to make frontend search working */ |
|
| 1315 | - $variation_metadata = get_post_meta($variation_id, '_wpshop_product_metadata', true); |
|
| 1316 | - if (!empty($variation_metadata)) { |
|
| 1317 | - $attributes_list = wpshop_attributes::get_attribute_list_for_item(wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION), $variation_id); |
|
| 1318 | - if (!empty($attributes_list)) { |
|
| 1319 | - foreach ($attributes_list as $attribute) { |
|
| 1320 | - $value_key = 'attribute_value_' . $attribute->data_type; |
|
| 1321 | - $attributeValue = $attribute->$value_key; |
|
| 1322 | - if ($attribute->data_type == 'decimal') { |
|
| 1323 | - $attributeValue = str_replace(',', '.', $attribute->$value_key); |
|
| 1324 | - } |
|
| 1325 | - if (($attribute->data_type == 'integer') && !is_array($attributeValue)) { |
|
| 1326 | - $attributeValue = (int) $attribute->$value_key; |
|
| 1327 | - } |
|
| 1328 | - $variation_metadata[$attribute->code] = $attribute->$value_key; |
|
| 1329 | - } |
|
| 1330 | - } |
|
| 1331 | - } |
|
| 1332 | - |
|
| 1333 | - foreach ($variation_definition['attribute'] as $attributeType => $attributeValues) { |
|
| 1334 | - foreach ($attributeValues as $attributeCode => $attributeValue) { |
|
| 1335 | - if ($attributeType == 'decimal') { |
|
| 1336 | - $attributeValue = str_replace(',', '.', $attributeValue); |
|
| 1337 | - } |
|
| 1338 | - if (($attributeType == 'integer') && !is_array($attributeValue)) { |
|
| 1339 | - $attributeValue = (int) $attributeValue; |
|
| 1340 | - } |
|
| 1341 | - $variation_metadata[$attributeCode] = $attributeValue; |
|
| 1342 | - } |
|
| 1343 | - } |
|
| 1344 | - update_post_meta($variation_id, WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, $variation_metadata); |
|
| 1345 | - |
|
| 1346 | - /** Save attached picture id **/ |
|
| 1347 | - $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']) : ''; |
|
| 1348 | - $selected_picture = update_post_meta($variation_id, '_wps_variation_attached_picture', $attached_picture_id); |
|
| 1349 | - |
|
| 1350 | - /* Update product price looking for shop parameters */ |
|
| 1351 | - wpshop_products::calculate_price($variation_id); |
|
| 1352 | - } |
|
| 1353 | - } |
|
| 1354 | - |
|
| 1355 | - /* Update the related products list*/ |
|
| 1356 | - if (!empty($data_to_save['related_products_list'])) { |
|
| 1357 | - update_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_RELATED_PRODUCTS, $data_to_save['related_products_list']); |
|
| 1358 | - } else if ($data_to_save['action'] != 'autosave') { |
|
| 1359 | - delete_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_RELATED_PRODUCTS); |
|
| 1360 | - } |
|
| 1361 | - /* Update the provider list*/ |
|
| 1362 | - if (!empty($data_to_save['provider_list'])) { |
|
| 1363 | - update_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_PROVIDER, $data_to_save['provider_list']); |
|
| 1364 | - } else if ($data_to_save['action'] != 'autosave') { |
|
| 1365 | - delete_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_PROVIDER); |
|
| 1366 | - } |
|
| 1367 | - |
|
| 1368 | - /* Update product options */ |
|
| 1369 | - if (!empty($data_to_save[WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT]['options'])) { |
|
| 1370 | - update_post_meta($data_to_save['post_ID'], '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_options', $data_to_save[WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT]['options']); |
|
| 1371 | - } else if ($data_to_save['action'] != 'autosave') { |
|
| 1372 | - delete_post_meta($data_to_save['post_ID'], '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_options'); |
|
| 1373 | - } |
|
| 1374 | - |
|
| 1375 | - /** Add flag on variations to check which type of variation **/ |
|
| 1376 | - $check_product_have_variations = self::get_variation($post_id); |
|
| 1377 | - if (!empty($check_product_have_variations)) { |
|
| 1378 | - $variation_flag = self::check_variation_type($post_id); |
|
| 1379 | - $variation_defining = get_post_meta($post_id, '_wpshop_variation_defining', true); |
|
| 1380 | - $variation_defining['variation_type'] = $variation_flag; |
|
| 1381 | - update_post_meta($post_id, '_wpshop_variation_defining', $variation_defining); |
|
| 1382 | - } |
|
| 1383 | - 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); |
|
| 1384 | - } |
|
| 1241 | + , $ref, $data_to_save['post_ID'], wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT)); |
|
| 1242 | + $existing_reference = $wpdb->get_var($query); |
|
| 1243 | + |
|
| 1244 | + /* If this product reference exist -> Create a new product reference */ |
|
| 1245 | + if ($wpdb->num_rows > 0) { |
|
| 1246 | + $query = "SELECT MAX(ID) AS PDCT_ID FROM " . $wpdb->posts; |
|
| 1247 | + $last_ref = $wpdb->get_var($query); |
|
| 1248 | + $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; |
|
| 1249 | + } |
|
| 1250 | + } |
|
| 1385 | 1251 | |
| 1386 | - flush_rewrite_rules(); |
|
| 1387 | - } |
|
| 1252 | + /* Save the attributes values into wpshop eav database */ |
|
| 1253 | + $update_from = !empty($data_to_save[wpshop_products::currentPageCode . '_provenance']) ? $data_to_save[wpshop_products::currentPageCode . '_provenance'] : ''; |
|
| 1254 | + $lang = WPSHOP_CURRENT_LOCALE; |
|
| 1255 | + if (!empty($data_to_save['icl_post_language'])) { |
|
| 1256 | + $query = $wpdb->prepare("SELECT locale FROM " . $wpdb->prefix . "icl_locale_map WHERE code = %s", $data_to_save['icl_post_language']); |
|
| 1257 | + $lang = $wpdb->get_var($query); |
|
| 1258 | + } |
|
| 1259 | + 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); |
|
| 1260 | + |
|
| 1261 | + /* Update product price looking for shop parameters */ |
|
| 1262 | + wpshop_products::calculate_price($data_to_save['post_ID']); |
|
| 1263 | + |
|
| 1264 | + /* Save the attributes values into wordpress post metadata database in order to have a backup and to make frontend search working */ |
|
| 1265 | + $productMetaDatas = array(); |
|
| 1266 | + foreach ($data_to_save[wpshop_products::currentPageCode . '_attribute'] as $attributeType => $attributeValues) { |
|
| 1267 | + foreach ($attributeValues as $attributeCode => $attributeValue) { |
|
| 1268 | + if ($attributeCode == 'product_attribute_set_id') { |
|
| 1269 | + /* Update the attribute set id for the current product */ |
|
| 1270 | + update_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, $attributeValue); |
|
| 1271 | + } |
|
| 1272 | + if ($attributeType == 'decimal') { |
|
| 1273 | + $attributeValue = str_replace(',', '.', $attributeValue); |
|
| 1274 | + } |
|
| 1275 | + if (($attributeType == 'integer') && !is_array($attributeValue)) { |
|
| 1276 | + $attributeValue = (int) $attributeValue; |
|
| 1277 | + } |
|
| 1278 | + $productMetaDatas[$attributeCode] = $attributeValue; |
|
| 1279 | + } |
|
| 1280 | + } |
|
| 1281 | + update_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, $productMetaDatas); |
|
| 1282 | + } |
|
| 1388 | 1283 | |
| 1389 | - /** |
|
| 1390 | - * Return the variation type |
|
| 1391 | - * @param integer $post_id |
|
| 1392 | - * @return string |
|
| 1393 | - */ |
|
| 1394 | - public function check_variation_type($post_id) |
|
| 1395 | - { |
|
| 1396 | - $variation_type = 'single'; |
|
| 1397 | - if (!empty($variation_type)) { |
|
| 1398 | - $variations = self::get_variation($post_id); |
|
| 1399 | - if (!empty($variations)) { |
|
| 1400 | - foreach ($variations as $variation_id => $variation_data) { |
|
| 1401 | - if (!empty($variation_data) && !empty($variation_data['variation_def']) && count($variation_data['variation_def']) == 1) { |
|
| 1402 | - return 'single'; |
|
| 1403 | - } elseif (!empty($variation_data) && !empty($variation_data['variation_def']) && count($variation_data['variation_def']) > 1) { |
|
| 1404 | - $variation_type = 'combined'; |
|
| 1405 | - } |
|
| 1406 | - } |
|
| 1407 | - } |
|
| 1408 | - } |
|
| 1409 | - return $variation_type; |
|
| 1410 | - } |
|
| 1284 | + if (!empty($data_to_save[wpshop_products::currentPageCode . '_attr_frontend_display']) && empty($data_to_save[wpshop_products::currentPageCode . '_attr_frontend_display']['default_config'])) { |
|
| 1285 | + update_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_FRONT_DISPLAY_CONF, $data_to_save[wpshop_products::currentPageCode . '_attr_frontend_display']); |
|
| 1286 | + } else if ($data_to_save['action'] != 'autosave') { |
|
| 1287 | + delete_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_FRONT_DISPLAY_CONF); |
|
| 1288 | + } |
|
| 1411 | 1289 | |
| 1412 | - /** |
|
| 1413 | - * Allows to define a specific permalink for each product by checking the parent categories |
|
| 1414 | - * |
|
| 1415 | - * @param mixed $permalink The actual permalink of the element |
|
| 1416 | - * @param object $post The post we want to set the permalink for |
|
| 1417 | - * @param void |
|
| 1418 | - * |
|
| 1419 | - * @return mixed The new permalink for the current element |
|
| 1420 | - */ |
|
| 1421 | - public static function set_product_permalink($permalink, $post, $unknown) |
|
| 1422 | - { |
|
| 1423 | - $options = get_option('wpshop_catalog_product_option', array()); |
|
| 1424 | - |
|
| 1425 | - if ($post->post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT/* && 'publish' == $post->post_status */) { |
|
| 1426 | - if (!isset($options['wpshop_catalog_product_slug_with_category']) || $options['wpshop_catalog_product_slug_with_category'] != 'yes') { |
|
| 1427 | - return $permalink; |
|
| 1428 | - } else { |
|
| 1429 | - $options_cats = get_option('wpshop_catalog_categories_option', array()); |
|
| 1430 | - $product_categories = wp_get_object_terms($post->ID, WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES); |
|
| 1431 | - if (empty($product_categories)) { |
|
| 1432 | - $product_category_slug = $options_cats['wpshop_catalog_no_category_slug']; |
|
| 1433 | - } else { |
|
| 1434 | - $product_category_slug = $product_categories[0]->slug; |
|
| 1435 | - } |
|
| 1436 | - $permalink = str_replace('%' . WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES . '%', $product_category_slug, $permalink); |
|
| 1437 | - } |
|
| 1438 | - } |
|
| 1290 | + $product = wpshop_products::get_product_data($data_to_save['post_ID'], false, '"publish"'); |
|
| 1291 | + if (empty($product['product_id'])) { |
|
| 1292 | + $product['product_id'] = $data_to_save['post_ID']; |
|
| 1293 | + } |
|
| 1294 | + $price = wpshop_prices::get_product_price($product, 'just_price_infos', array('mini_output', 'grid')); |
|
| 1295 | + update_post_meta($data_to_save['post_ID'], '_wps_price_infos', $price); |
|
| 1296 | + |
|
| 1297 | + /** Save product variation */ |
|
| 1298 | + if (!empty($data_to_save[WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION])) { |
|
| 1299 | + foreach ($data_to_save[WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION] as $variation_id => $variation_definition) { |
|
| 1300 | + |
|
| 1301 | + foreach (unserialize(WPSHOP_ATTRIBUTE_PRICES) as $price_attribute_code) { |
|
| 1302 | + $price_attr_def = wpshop_attributes::getElement($price_attribute_code, "'valid'", 'code'); |
|
| 1303 | + 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])) { |
|
| 1304 | + $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; |
|
| 1305 | + } |
|
| 1306 | + } |
|
| 1307 | + $lang = WPSHOP_CURRENT_LOCALE; |
|
| 1308 | + if (!empty($data_to_save['icl_post_language'])) { |
|
| 1309 | + $query = $wpdb->prepare("SELECT locale FROM " . $wpdb->prefix . "icl_locale_map WHERE code = %s", $data_to_save['icl_post_language']); |
|
| 1310 | + $lang = $wpdb->get_var($query); |
|
| 1311 | + } |
|
| 1312 | + wpshop_attributes::saveAttributeForEntity($variation_definition['attribute'], wpshop_entities::get_entity_identifier_from_code(wpshop_products::currentPageCode), $variation_id, $lang); |
|
| 1313 | + |
|
| 1314 | + /** Save the attributes values into wordpress post metadata database in order to have a backup and to make frontend search working */ |
|
| 1315 | + $variation_metadata = get_post_meta($variation_id, '_wpshop_product_metadata', true); |
|
| 1316 | + if (!empty($variation_metadata)) { |
|
| 1317 | + $attributes_list = wpshop_attributes::get_attribute_list_for_item(wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION), $variation_id); |
|
| 1318 | + if (!empty($attributes_list)) { |
|
| 1319 | + foreach ($attributes_list as $attribute) { |
|
| 1320 | + $value_key = 'attribute_value_' . $attribute->data_type; |
|
| 1321 | + $attributeValue = $attribute->$value_key; |
|
| 1322 | + if ($attribute->data_type == 'decimal') { |
|
| 1323 | + $attributeValue = str_replace(',', '.', $attribute->$value_key); |
|
| 1324 | + } |
|
| 1325 | + if (($attribute->data_type == 'integer') && !is_array($attributeValue)) { |
|
| 1326 | + $attributeValue = (int) $attribute->$value_key; |
|
| 1327 | + } |
|
| 1328 | + $variation_metadata[$attribute->code] = $attribute->$value_key; |
|
| 1329 | + } |
|
| 1330 | + } |
|
| 1331 | + } |
|
| 1332 | + |
|
| 1333 | + foreach ($variation_definition['attribute'] as $attributeType => $attributeValues) { |
|
| 1334 | + foreach ($attributeValues as $attributeCode => $attributeValue) { |
|
| 1335 | + if ($attributeType == 'decimal') { |
|
| 1336 | + $attributeValue = str_replace(',', '.', $attributeValue); |
|
| 1337 | + } |
|
| 1338 | + if (($attributeType == 'integer') && !is_array($attributeValue)) { |
|
| 1339 | + $attributeValue = (int) $attributeValue; |
|
| 1340 | + } |
|
| 1341 | + $variation_metadata[$attributeCode] = $attributeValue; |
|
| 1342 | + } |
|
| 1343 | + } |
|
| 1344 | + update_post_meta($variation_id, WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, $variation_metadata); |
|
| 1345 | + |
|
| 1346 | + /** Save attached picture id **/ |
|
| 1347 | + $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']) : ''; |
|
| 1348 | + $selected_picture = update_post_meta($variation_id, '_wps_variation_attached_picture', $attached_picture_id); |
|
| 1349 | + |
|
| 1350 | + /* Update product price looking for shop parameters */ |
|
| 1351 | + wpshop_products::calculate_price($variation_id); |
|
| 1352 | + } |
|
| 1353 | + } |
|
| 1354 | + |
|
| 1355 | + /* Update the related products list*/ |
|
| 1356 | + if (!empty($data_to_save['related_products_list'])) { |
|
| 1357 | + update_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_RELATED_PRODUCTS, $data_to_save['related_products_list']); |
|
| 1358 | + } else if ($data_to_save['action'] != 'autosave') { |
|
| 1359 | + delete_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_RELATED_PRODUCTS); |
|
| 1360 | + } |
|
| 1361 | + /* Update the provider list*/ |
|
| 1362 | + if (!empty($data_to_save['provider_list'])) { |
|
| 1363 | + update_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_PROVIDER, $data_to_save['provider_list']); |
|
| 1364 | + } else if ($data_to_save['action'] != 'autosave') { |
|
| 1365 | + delete_post_meta($data_to_save['post_ID'], WPSHOP_PRODUCT_PROVIDER); |
|
| 1366 | + } |
|
| 1367 | + |
|
| 1368 | + /* Update product options */ |
|
| 1369 | + if (!empty($data_to_save[WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT]['options'])) { |
|
| 1370 | + update_post_meta($data_to_save['post_ID'], '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_options', $data_to_save[WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT]['options']); |
|
| 1371 | + } else if ($data_to_save['action'] != 'autosave') { |
|
| 1372 | + delete_post_meta($data_to_save['post_ID'], '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_options'); |
|
| 1373 | + } |
|
| 1374 | + |
|
| 1375 | + /** Add flag on variations to check which type of variation **/ |
|
| 1376 | + $check_product_have_variations = self::get_variation($post_id); |
|
| 1377 | + if (!empty($check_product_have_variations)) { |
|
| 1378 | + $variation_flag = self::check_variation_type($post_id); |
|
| 1379 | + $variation_defining = get_post_meta($post_id, '_wpshop_variation_defining', true); |
|
| 1380 | + $variation_defining['variation_type'] = $variation_flag; |
|
| 1381 | + update_post_meta($post_id, '_wpshop_variation_defining', $variation_defining); |
|
| 1382 | + } |
|
| 1383 | + 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); |
|
| 1384 | + } |
|
| 1385 | + |
|
| 1386 | + flush_rewrite_rules(); |
|
| 1387 | + } |
|
| 1388 | + |
|
| 1389 | + /** |
|
| 1390 | + * Return the variation type |
|
| 1391 | + * @param integer $post_id |
|
| 1392 | + * @return string |
|
| 1393 | + */ |
|
| 1394 | + public function check_variation_type($post_id) |
|
| 1395 | + { |
|
| 1396 | + $variation_type = 'single'; |
|
| 1397 | + if (!empty($variation_type)) { |
|
| 1398 | + $variations = self::get_variation($post_id); |
|
| 1399 | + if (!empty($variations)) { |
|
| 1400 | + foreach ($variations as $variation_id => $variation_data) { |
|
| 1401 | + if (!empty($variation_data) && !empty($variation_data['variation_def']) && count($variation_data['variation_def']) == 1) { |
|
| 1402 | + return 'single'; |
|
| 1403 | + } elseif (!empty($variation_data) && !empty($variation_data['variation_def']) && count($variation_data['variation_def']) > 1) { |
|
| 1404 | + $variation_type = 'combined'; |
|
| 1405 | + } |
|
| 1406 | + } |
|
| 1407 | + } |
|
| 1408 | + } |
|
| 1409 | + return $variation_type; |
|
| 1410 | + } |
|
| 1411 | + |
|
| 1412 | + /** |
|
| 1413 | + * Allows to define a specific permalink for each product by checking the parent categories |
|
| 1414 | + * |
|
| 1415 | + * @param mixed $permalink The actual permalink of the element |
|
| 1416 | + * @param object $post The post we want to set the permalink for |
|
| 1417 | + * @param void |
|
| 1418 | + * |
|
| 1419 | + * @return mixed The new permalink for the current element |
|
| 1420 | + */ |
|
| 1421 | + public static function set_product_permalink($permalink, $post, $unknown) |
|
| 1422 | + { |
|
| 1423 | + $options = get_option('wpshop_catalog_product_option', array()); |
|
| 1424 | + |
|
| 1425 | + if ($post->post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT/* && 'publish' == $post->post_status */) { |
|
| 1426 | + if (!isset($options['wpshop_catalog_product_slug_with_category']) || $options['wpshop_catalog_product_slug_with_category'] != 'yes') { |
|
| 1427 | + return $permalink; |
|
| 1428 | + } else { |
|
| 1429 | + $options_cats = get_option('wpshop_catalog_categories_option', array()); |
|
| 1430 | + $product_categories = wp_get_object_terms($post->ID, WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES); |
|
| 1431 | + if (empty($product_categories)) { |
|
| 1432 | + $product_category_slug = $options_cats['wpshop_catalog_no_category_slug']; |
|
| 1433 | + } else { |
|
| 1434 | + $product_category_slug = $product_categories[0]->slug; |
|
| 1435 | + } |
|
| 1436 | + $permalink = str_replace('%' . WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES . '%', $product_category_slug, $permalink); |
|
| 1437 | + } |
|
| 1438 | + } |
|
| 1439 | 1439 | |
| 1440 | - return $permalink; |
|
| 1440 | + return $permalink; |
|
| 1441 | 1441 | |
| 1442 | - //echo '<pre>'; print_r($permalink); echo '</pre>'; exit(); |
|
| 1442 | + //echo '<pre>'; print_r($permalink); echo '</pre>'; exit(); |
|
| 1443 | 1443 | |
| 1444 | - //wpshop_catalog_categories_slug wpshop_catalog_no_category_slug |
|
| 1444 | + //wpshop_catalog_categories_slug wpshop_catalog_no_category_slug |
|
| 1445 | 1445 | |
| 1446 | - /*if(false) { |
|
| 1446 | + /*if(false) { |
|
| 1447 | 1447 | global $wp_query; |
| 1448 | 1448 | $product_categories = wp_get_object_terms( $post->ID, WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES ); |
| 1449 | 1449 | |
| 1450 | 1450 | if(count($product_categories) == 0){ /* Product has only one category we get the only available slug */ |
| 1451 | - /* $product_category_slug = WPSHOP_UNCATEGORIZED_PRODUCT_SLUG; |
|
| 1451 | + /* $product_category_slug = WPSHOP_UNCATEGORIZED_PRODUCT_SLUG; |
|
| 1452 | 1452 | } |
| 1453 | 1453 | elseif(count($product_categories) == 1){ /* Product has only one category we get the only available slug */ |
| 1454 | - /* $product_category_slug = $product_categories[0]->slug; |
|
| 1454 | + /* $product_category_slug = $product_categories[0]->slug; |
|
| 1455 | 1455 | } |
| 1456 | 1456 | else{ /* Product has several categories choose the slug of the we want */ |
| 1457 | - /* $product_category_slugs = array(); |
|
| 1457 | + /* $product_category_slugs = array(); |
|
| 1458 | 1458 | foreach($product_categories as $product_category){ |
| 1459 | 1459 | $product_category_slugs[] = $product_category->slug; |
| 1460 | 1460 | } |
@@ -1464,457 +1464,457 @@ discard block |
||
| 1464 | 1464 | $permalink = str_replace('%' . WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES . '%', $product_category_slug, $permalink); |
| 1465 | 1465 | return apply_filters('wpshop_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_permalink', $permalink, $post->ID ); |
| 1466 | 1466 | }*/ |
| 1467 | - } |
|
| 1467 | + } |
|
| 1468 | 1468 | |
| 1469 | - public static function set_product_request_by_name($query) |
|
| 1470 | - { |
|
| 1471 | - $options = get_option('wpshop_catalog_product_option', array()); |
|
| 1469 | + public static function set_product_request_by_name($query) |
|
| 1470 | + { |
|
| 1471 | + $options = get_option('wpshop_catalog_product_option', array()); |
|
| 1472 | 1472 | |
| 1473 | - if ($query->is_main_query() && (2 == count($query->query) || isset($query->query['page'])) && !empty($query->query['name']) && empty($options['wpshop_catalog_product_slug'])); |
|
| 1474 | - // $query->set( 'post_type', array( 'post', WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'page' ) ); |
|
| 1475 | - } |
|
| 1473 | + if ($query->is_main_query() && (2 == count($query->query) || isset($query->query['page'])) && !empty($query->query['name']) && empty($options['wpshop_catalog_product_slug'])); |
|
| 1474 | + // $query->set( 'post_type', array( 'post', WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'page' ) ); |
|
| 1475 | + } |
|
| 1476 | 1476 | |
| 1477 | - /** |
|
| 1478 | - * Define output for product |
|
| 1479 | - * |
|
| 1480 | - * @param mixed $initialContent The initial product content defined into wordpress basic admin interface |
|
| 1481 | - * @param integer $product_id The product identifier we want to get and output attribute for |
|
| 1482 | - * |
|
| 1483 | - * @return mixed $content The content to add or to modify the product output in frontend |
|
| 1484 | - */ |
|
| 1485 | - public static function product_complete_sheet_output($initialContent, $product_id) |
|
| 1486 | - { |
|
| 1487 | - $content = $attributeContentOutput = ''; |
|
| 1488 | - $wps_product_ctr = new wps_product_ctr(); |
|
| 1489 | - /** Log number of view for the current product */ |
|
| 1490 | - $product_view_number = get_post_meta($product_id, WPSHOP_PRODUCT_VIEW_NB, true); |
|
| 1491 | - $product_view_number++; |
|
| 1492 | - update_post_meta($product_id, WPSHOP_PRODUCT_VIEW_NB, $product_view_number); |
|
| 1493 | - |
|
| 1494 | - /** Get product definition */ |
|
| 1495 | - |
|
| 1496 | - $product = self::get_product_data($product_id); |
|
| 1497 | - wp_cache_set('wpshop_product_data_' . $product_id, $product); |
|
| 1498 | - |
|
| 1499 | - /** Get the product thumbnail */ |
|
| 1500 | - $productThumbnail = wpshop_display::display_template_element('product_thumbnail_default', array()); |
|
| 1501 | - if (has_post_thumbnail($product_id)) { |
|
| 1502 | - $thumbnail_url = wp_get_attachment_image_src(get_post_thumbnail_id(), 'full'); |
|
| 1503 | - $tpl_component = array(); |
|
| 1504 | - $tpl_component['PRODUCT_THUMBNAIL_URL'] = $thumbnail_url[0]; |
|
| 1505 | - $tpl_component['PRODUCT_THUMBNAIL'] = get_the_post_thumbnail($product_id, 'wpshop-product-galery'); |
|
| 1506 | - $tpl_component['PRODUCT_THUMBNAIL_FULL'] = get_the_post_thumbnail($product_id, 'full'); |
|
| 1507 | - $image_attributes = wp_get_attachment_metadata(get_post_thumbnail_id()); |
|
| 1508 | - if (!empty($image_attributes) && !empty($image_attributes['sizes']) && is_array($image_attributes['sizes'])) { |
|
| 1509 | - foreach ($image_attributes['sizes'] as $size_name => $size_def) { |
|
| 1510 | - $tpl_component['PRODUCT_THUMBNAIL_' . strtoupper($size_name)] = wp_get_attachment_image(get_post_thumbnail_id(), $size_name); |
|
| 1511 | - $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; |
|
| 1512 | - } |
|
| 1513 | - } |
|
| 1514 | - $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; |
|
| 1515 | - $productThumbnail = wpshop_display::display_template_element('product_thumbnail', $tpl_component); |
|
| 1516 | - unset($tpl_component); |
|
| 1517 | - } |
|
| 1477 | + /** |
|
| 1478 | + * Define output for product |
|
| 1479 | + * |
|
| 1480 | + * @param mixed $initialContent The initial product content defined into wordpress basic admin interface |
|
| 1481 | + * @param integer $product_id The product identifier we want to get and output attribute for |
|
| 1482 | + * |
|
| 1483 | + * @return mixed $content The content to add or to modify the product output in frontend |
|
| 1484 | + */ |
|
| 1485 | + public static function product_complete_sheet_output($initialContent, $product_id) |
|
| 1486 | + { |
|
| 1487 | + $content = $attributeContentOutput = ''; |
|
| 1488 | + $wps_product_ctr = new wps_product_ctr(); |
|
| 1489 | + /** Log number of view for the current product */ |
|
| 1490 | + $product_view_number = get_post_meta($product_id, WPSHOP_PRODUCT_VIEW_NB, true); |
|
| 1491 | + $product_view_number++; |
|
| 1492 | + update_post_meta($product_id, WPSHOP_PRODUCT_VIEW_NB, $product_view_number); |
|
| 1493 | + |
|
| 1494 | + /** Get product definition */ |
|
| 1495 | + |
|
| 1496 | + $product = self::get_product_data($product_id); |
|
| 1497 | + wp_cache_set('wpshop_product_data_' . $product_id, $product); |
|
| 1498 | + |
|
| 1499 | + /** Get the product thumbnail */ |
|
| 1500 | + $productThumbnail = wpshop_display::display_template_element('product_thumbnail_default', array()); |
|
| 1501 | + if (has_post_thumbnail($product_id)) { |
|
| 1502 | + $thumbnail_url = wp_get_attachment_image_src(get_post_thumbnail_id(), 'full'); |
|
| 1503 | + $tpl_component = array(); |
|
| 1504 | + $tpl_component['PRODUCT_THUMBNAIL_URL'] = $thumbnail_url[0]; |
|
| 1505 | + $tpl_component['PRODUCT_THUMBNAIL'] = get_the_post_thumbnail($product_id, 'wpshop-product-galery'); |
|
| 1506 | + $tpl_component['PRODUCT_THUMBNAIL_FULL'] = get_the_post_thumbnail($product_id, 'full'); |
|
| 1507 | + $image_attributes = wp_get_attachment_metadata(get_post_thumbnail_id()); |
|
| 1508 | + if (!empty($image_attributes) && !empty($image_attributes['sizes']) && is_array($image_attributes['sizes'])) { |
|
| 1509 | + foreach ($image_attributes['sizes'] as $size_name => $size_def) { |
|
| 1510 | + $tpl_component['PRODUCT_THUMBNAIL_' . strtoupper($size_name)] = wp_get_attachment_image(get_post_thumbnail_id(), $size_name); |
|
| 1511 | + $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; |
|
| 1512 | + } |
|
| 1513 | + } |
|
| 1514 | + $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; |
|
| 1515 | + $productThumbnail = wpshop_display::display_template_element('product_thumbnail', $tpl_component); |
|
| 1516 | + unset($tpl_component); |
|
| 1517 | + } |
|
| 1518 | 1518 | |
| 1519 | - $product_document_galery = wps_media_manager_frontend_ctr::get_product_complete_sheet_attachments($product_id); |
|
| 1520 | - |
|
| 1521 | - /** Retrieve product attributes for output */ |
|
| 1522 | - $attributeContentOutput = wpshop_attributes::attribute_of_entity_to_tab(wpshop_entities::get_entity_identifier_from_code(self::currentPageCode), $product_id, $product); |
|
| 1523 | - |
|
| 1524 | - /** Retrieve product price */ |
|
| 1525 | - $price_attribute = wpshop_attributes::getElement('product_price', "'valid'", 'code'); |
|
| 1526 | - $price_display = wpshop_attributes::check_attribute_display($price_attribute->is_visible_in_front, $product['custom_display'], 'attribute', 'product_price', 'complete_sheet'); |
|
| 1527 | - $catalog_options = get_option('wpshop_catalog_main_option', array()); |
|
| 1528 | - $productPrice = ''; |
|
| 1529 | - $wpshop_price_piloting_option = get_option('wpshop_shop_price_piloting'); |
|
| 1530 | - $check_product_price = wpshop_prices::check_product_price($product); |
|
| 1531 | - $result_price_piloting = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $check_product_price['et'] : $check_product_price['ati']; |
|
| 1532 | - 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)) { |
|
| 1533 | - $productPrice = wpshop_prices::get_product_price($product, 'price_display', 'complete_sheet'); |
|
| 1534 | - } |
|
| 1519 | + $product_document_galery = wps_media_manager_frontend_ctr::get_product_complete_sheet_attachments($product_id); |
|
| 1520 | + |
|
| 1521 | + /** Retrieve product attributes for output */ |
|
| 1522 | + $attributeContentOutput = wpshop_attributes::attribute_of_entity_to_tab(wpshop_entities::get_entity_identifier_from_code(self::currentPageCode), $product_id, $product); |
|
| 1523 | + |
|
| 1524 | + /** Retrieve product price */ |
|
| 1525 | + $price_attribute = wpshop_attributes::getElement('product_price', "'valid'", 'code'); |
|
| 1526 | + $price_display = wpshop_attributes::check_attribute_display($price_attribute->is_visible_in_front, $product['custom_display'], 'attribute', 'product_price', 'complete_sheet'); |
|
| 1527 | + $catalog_options = get_option('wpshop_catalog_main_option', array()); |
|
| 1528 | + $productPrice = ''; |
|
| 1529 | + $wpshop_price_piloting_option = get_option('wpshop_shop_price_piloting'); |
|
| 1530 | + $check_product_price = wpshop_prices::check_product_price($product); |
|
| 1531 | + $result_price_piloting = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $check_product_price['et'] : $check_product_price['ati']; |
|
| 1532 | + 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)) { |
|
| 1533 | + $productPrice = wpshop_prices::get_product_price($product, 'price_display', 'complete_sheet'); |
|
| 1534 | + } |
|
| 1535 | 1535 | |
| 1536 | - /** Check if there is at less 1 product in stock */ |
|
| 1537 | - $productStock = $wps_product_ctr->check_stock($product_id, 1); |
|
| 1538 | - $productStock = ($productStock === true) ? 1 : null; |
|
| 1536 | + /** Check if there is at less 1 product in stock */ |
|
| 1537 | + $productStock = $wps_product_ctr->check_stock($product_id, 1); |
|
| 1538 | + $productStock = ($productStock === true) ? 1 : null; |
|
| 1539 | 1539 | |
| 1540 | - /** if !product stock check product have variation with stock **/ |
|
| 1540 | + /** if !product stock check product have variation with stock **/ |
|
| 1541 | 1541 | // if ( empty($productStock) ) { |
| 1542 | - $product_variation_meta = get_post_meta($product_id, '_wpshop_variation_defining', true); |
|
| 1543 | - if (!empty($product_variation_meta) && !empty($product_variation_meta['options']) && !empty($product_variation_meta['options']['priority']) && in_array('combined', $product_variation_meta['options']['priority'])) { |
|
| 1544 | - $variations = wpshop_products::get_variation($product_id); |
|
| 1545 | - if (!empty($variations)) { |
|
| 1546 | - foreach ($variations as $variation) { |
|
| 1547 | - if (!empty($variation) && !empty($variation['variation_dif']) && array_key_exists('product_stock', $variation['variation_dif']) && round($variation['variation_dif']['product_stock']) > 0) { |
|
| 1548 | - $productStock = 1; |
|
| 1549 | - } |
|
| 1550 | - } |
|
| 1551 | - } |
|
| 1552 | - } |
|
| 1542 | + $product_variation_meta = get_post_meta($product_id, '_wpshop_variation_defining', true); |
|
| 1543 | + if (!empty($product_variation_meta) && !empty($product_variation_meta['options']) && !empty($product_variation_meta['options']['priority']) && in_array('combined', $product_variation_meta['options']['priority'])) { |
|
| 1544 | + $variations = wpshop_products::get_variation($product_id); |
|
| 1545 | + if (!empty($variations)) { |
|
| 1546 | + foreach ($variations as $variation) { |
|
| 1547 | + if (!empty($variation) && !empty($variation['variation_dif']) && array_key_exists('product_stock', $variation['variation_dif']) && round($variation['variation_dif']['product_stock']) > 0) { |
|
| 1548 | + $productStock = 1; |
|
| 1549 | + } |
|
| 1550 | + } |
|
| 1551 | + } |
|
| 1552 | + } |
|
| 1553 | 1553 | // } |
| 1554 | 1554 | |
| 1555 | - /** Define "Add to cart" button */ |
|
| 1556 | - $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'); |
|
| 1557 | - $display_price_state_when_price_is_empty = true; |
|
| 1558 | - if (empty($productPrice) && (!empty($catalog_options) || (!empty($catalog_options['wpshop_catalog_empty_price_behaviour']) && $catalog_options['wpshop_catalog_empty_price_behaviour'] == 'yes'))) { |
|
| 1559 | - $display_price_state_when_price_is_empty = false; |
|
| 1560 | - } else if (!empty($productPrice)) { |
|
| 1561 | - $display_price_state_when_price_is_empty = true; |
|
| 1562 | - } |
|
| 1563 | - $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') : ''; |
|
| 1564 | - $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)) : ''; |
|
| 1565 | - |
|
| 1566 | - /** Define "Ask a quotation" button */ |
|
| 1567 | - $quotation_button = self::display_quotation_button($product_id, (!empty($product['quotation_allowed']) ? $product['quotation_allowed'] : null), 'complete'); |
|
| 1568 | - |
|
| 1569 | - /** Template parameters */ |
|
| 1570 | - $template_part = 'product_complete_tpl'; |
|
| 1571 | - $tpl_component = array(); |
|
| 1572 | - |
|
| 1573 | - $tpl_component['PRODUCT_VARIATIONS'] = wpshop_products::wpshop_variation($product_id); |
|
| 1574 | - $tpl_component['PRODUCT_ID'] = $product_id; |
|
| 1575 | - $tpl_component['PRODUCT_TITLE'] = $product['post_title']; |
|
| 1576 | - $tpl_component['PRODUCT_THUMBNAIL'] = $productThumbnail; |
|
| 1577 | - $tpl_component['PRODUCT_GALERY_PICS'] = ''; |
|
| 1578 | - $tpl_component['PRODUCT_PRICE'] = $productPrice; |
|
| 1579 | - $modules_option = get_option('wpshop_modules'); |
|
| 1580 | - $tpl_component['LOW_STOCK_ALERT_MESSAGE'] = ''; |
|
| 1581 | - if (!empty($modules_option) && !empty($modules_option['wpshop_low_stock_alert']) && $modules_option['wpshop_low_stock_alert']['activated'] == 'on') { |
|
| 1582 | - $wps_marketing_tools = new wps_marketing_tools_ctr(); |
|
| 1583 | - $tpl_component['LOW_STOCK_ALERT_MESSAGE'] = $wps_marketing_tools->display_alert_stock_message(array('id' => $product_id)); |
|
| 1584 | - } |
|
| 1555 | + /** Define "Add to cart" button */ |
|
| 1556 | + $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'); |
|
| 1557 | + $display_price_state_when_price_is_empty = true; |
|
| 1558 | + if (empty($productPrice) && (!empty($catalog_options) || (!empty($catalog_options['wpshop_catalog_empty_price_behaviour']) && $catalog_options['wpshop_catalog_empty_price_behaviour'] == 'yes'))) { |
|
| 1559 | + $display_price_state_when_price_is_empty = false; |
|
| 1560 | + } else if (!empty($productPrice)) { |
|
| 1561 | + $display_price_state_when_price_is_empty = true; |
|
| 1562 | + } |
|
| 1563 | + $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') : ''; |
|
| 1564 | + $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)) : ''; |
|
| 1565 | + |
|
| 1566 | + /** Define "Ask a quotation" button */ |
|
| 1567 | + $quotation_button = self::display_quotation_button($product_id, (!empty($product['quotation_allowed']) ? $product['quotation_allowed'] : null), 'complete'); |
|
| 1568 | + |
|
| 1569 | + /** Template parameters */ |
|
| 1570 | + $template_part = 'product_complete_tpl'; |
|
| 1571 | + $tpl_component = array(); |
|
| 1572 | + |
|
| 1573 | + $tpl_component['PRODUCT_VARIATIONS'] = wpshop_products::wpshop_variation($product_id); |
|
| 1574 | + $tpl_component['PRODUCT_ID'] = $product_id; |
|
| 1575 | + $tpl_component['PRODUCT_TITLE'] = $product['post_title']; |
|
| 1576 | + $tpl_component['PRODUCT_THUMBNAIL'] = $productThumbnail; |
|
| 1577 | + $tpl_component['PRODUCT_GALERY_PICS'] = ''; |
|
| 1578 | + $tpl_component['PRODUCT_PRICE'] = $productPrice; |
|
| 1579 | + $modules_option = get_option('wpshop_modules'); |
|
| 1580 | + $tpl_component['LOW_STOCK_ALERT_MESSAGE'] = ''; |
|
| 1581 | + if (!empty($modules_option) && !empty($modules_option['wpshop_low_stock_alert']) && $modules_option['wpshop_low_stock_alert']['activated'] == 'on') { |
|
| 1582 | + $wps_marketing_tools = new wps_marketing_tools_ctr(); |
|
| 1583 | + $tpl_component['LOW_STOCK_ALERT_MESSAGE'] = $wps_marketing_tools->display_alert_stock_message(array('id' => $product_id)); |
|
| 1584 | + } |
|
| 1585 | 1585 | |
| 1586 | - /** Gallery **/ |
|
| 1587 | - $tpl_component['PRODUCT_COMPLETE_SHEET_GALLERY'] = wps_media_manager_frontend_ctr::get_product_complete_sheet_galery($product_id); |
|
| 1588 | - |
|
| 1589 | - $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'] : '')); |
|
| 1590 | - |
|
| 1591 | - $product_new = $product_new_def['output']; |
|
| 1592 | - $product_class = $product_new_def['class']; |
|
| 1593 | - |
|
| 1594 | - $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'] : '')); |
|
| 1595 | - $product_featured = $product_featured_def['output']; |
|
| 1596 | - $product_class .= $product_featured_def['class']; |
|
| 1597 | - |
|
| 1598 | - $tpl_component['PRODUCT_IS_NEW'] = $product_new; |
|
| 1599 | - $tpl_component['PRODUCT_IS_FEATURED'] = $product_featured; |
|
| 1600 | - $tpl_component['PRODUCT_EXTRA_STATE'] = $tpl_component['PRODUCT_IS_NEW'] . $tpl_component['PRODUCT_IS_FEATURED']; |
|
| 1601 | - |
|
| 1602 | - $tpl_component['PRODUCT_INITIAL_CONTENT'] = $initialContent; |
|
| 1603 | - $tpl_component['PRODUCT_BUTTON_ADD_TO_CART'] = $add_to_cart_button; |
|
| 1604 | - $tpl_component['PRODUCT_BUTTON_QUOTATION'] = $quotation_button; |
|
| 1605 | - $tpl_component['PRODUCT_QUANTITY_CHOOSER'] = $product_quantity_chooser_input; |
|
| 1606 | - $tpl_component['PRODUCT_BUTTONS'] = $tpl_component['PRODUCT_BUTTON_QUOTATION'] . $tpl_component['PRODUCT_BUTTON_ADD_TO_CART']; |
|
| 1607 | - $tpl_component['PRODUCT_GALERY_DOCS'] = $product_document_galery; |
|
| 1608 | - $tpl_component['PRODUCT_FEATURES'] = $attributeContentOutput; |
|
| 1609 | - $tpl_component = apply_filters('wps-filter-product-complete-sheet-output', $tpl_component, $product_id); |
|
| 1610 | - |
|
| 1611 | - /** Build template */ |
|
| 1612 | - $tpl_way_to_take = wpshop_display::check_way_for_template($template_part); |
|
| 1613 | - if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) { |
|
| 1614 | - /* Include the old way template part */ |
|
| 1615 | - ob_start(); |
|
| 1616 | - require wpshop_display::get_template_file($tpl_way_to_take[1]); |
|
| 1617 | - $content = ob_get_contents(); |
|
| 1618 | - ob_end_clean(); |
|
| 1619 | - } else { |
|
| 1620 | - $content = wpshop_display::display_template_element($template_part, $tpl_component); |
|
| 1621 | - } |
|
| 1622 | - unset($tpl_component); |
|
| 1623 | - return $content; |
|
| 1624 | - } |
|
| 1586 | + /** Gallery **/ |
|
| 1587 | + $tpl_component['PRODUCT_COMPLETE_SHEET_GALLERY'] = wps_media_manager_frontend_ctr::get_product_complete_sheet_galery($product_id); |
|
| 1588 | + |
|
| 1589 | + $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'] : '')); |
|
| 1590 | + |
|
| 1591 | + $product_new = $product_new_def['output']; |
|
| 1592 | + $product_class = $product_new_def['class']; |
|
| 1593 | + |
|
| 1594 | + $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'] : '')); |
|
| 1595 | + $product_featured = $product_featured_def['output']; |
|
| 1596 | + $product_class .= $product_featured_def['class']; |
|
| 1597 | + |
|
| 1598 | + $tpl_component['PRODUCT_IS_NEW'] = $product_new; |
|
| 1599 | + $tpl_component['PRODUCT_IS_FEATURED'] = $product_featured; |
|
| 1600 | + $tpl_component['PRODUCT_EXTRA_STATE'] = $tpl_component['PRODUCT_IS_NEW'] . $tpl_component['PRODUCT_IS_FEATURED']; |
|
| 1601 | + |
|
| 1602 | + $tpl_component['PRODUCT_INITIAL_CONTENT'] = $initialContent; |
|
| 1603 | + $tpl_component['PRODUCT_BUTTON_ADD_TO_CART'] = $add_to_cart_button; |
|
| 1604 | + $tpl_component['PRODUCT_BUTTON_QUOTATION'] = $quotation_button; |
|
| 1605 | + $tpl_component['PRODUCT_QUANTITY_CHOOSER'] = $product_quantity_chooser_input; |
|
| 1606 | + $tpl_component['PRODUCT_BUTTONS'] = $tpl_component['PRODUCT_BUTTON_QUOTATION'] . $tpl_component['PRODUCT_BUTTON_ADD_TO_CART']; |
|
| 1607 | + $tpl_component['PRODUCT_GALERY_DOCS'] = $product_document_galery; |
|
| 1608 | + $tpl_component['PRODUCT_FEATURES'] = $attributeContentOutput; |
|
| 1609 | + $tpl_component = apply_filters('wps-filter-product-complete-sheet-output', $tpl_component, $product_id); |
|
| 1610 | + |
|
| 1611 | + /** Build template */ |
|
| 1612 | + $tpl_way_to_take = wpshop_display::check_way_for_template($template_part); |
|
| 1613 | + if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) { |
|
| 1614 | + /* Include the old way template part */ |
|
| 1615 | + ob_start(); |
|
| 1616 | + require wpshop_display::get_template_file($tpl_way_to_take[1]); |
|
| 1617 | + $content = ob_get_contents(); |
|
| 1618 | + ob_end_clean(); |
|
| 1619 | + } else { |
|
| 1620 | + $content = wpshop_display::display_template_element($template_part, $tpl_component); |
|
| 1621 | + } |
|
| 1622 | + unset($tpl_component); |
|
| 1623 | + return $content; |
|
| 1624 | + } |
|
| 1625 | 1625 | |
| 1626 | - 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) |
|
| 1627 | - { |
|
| 1628 | - $content = ''; |
|
| 1629 | - $product_information = $product_class = ''; |
|
| 1626 | + 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) |
|
| 1627 | + { |
|
| 1628 | + $content = ''; |
|
| 1629 | + $product_information = $product_class = ''; |
|
| 1630 | 1630 | |
| 1631 | - /** Get the product thumbnail */ |
|
| 1632 | - $productThumbnail = wpshop_display::display_template_element('product_thumbnail_default', array()); |
|
| 1633 | - if (has_post_thumbnail($product_id)) { |
|
| 1634 | - $productThumbnail = get_the_post_thumbnail($product_id, 'thumbnail'); |
|
| 1635 | - } |
|
| 1631 | + /** Get the product thumbnail */ |
|
| 1632 | + $productThumbnail = wpshop_display::display_template_element('product_thumbnail_default', array()); |
|
| 1633 | + if (has_post_thumbnail($product_id)) { |
|
| 1634 | + $productThumbnail = get_the_post_thumbnail($product_id, 'thumbnail'); |
|
| 1635 | + } |
|
| 1636 | 1636 | |
| 1637 | - $product = self::get_product_data($product_id); |
|
| 1637 | + $product = self::get_product_data($product_id); |
|
| 1638 | 1638 | |
| 1639 | - /** Get the product information for output */ |
|
| 1640 | - if (!empty($product)) { |
|
| 1639 | + /** Get the product information for output */ |
|
| 1640 | + if (!empty($product)) { |
|
| 1641 | 1641 | |
| 1642 | - $product_title = $product['post_title']; |
|
| 1643 | - $product_name = $product['post_name']; |
|
| 1644 | - $product_link = get_permalink($product_id); |
|
| 1645 | - $product_more_informations = $product['product_content']; |
|
| 1646 | - $product_excerpt = $product['product_excerpt']; |
|
| 1642 | + $product_title = $product['post_title']; |
|
| 1643 | + $product_name = $product['post_name']; |
|
| 1644 | + $product_link = get_permalink($product_id); |
|
| 1645 | + $product_more_informations = $product['product_content']; |
|
| 1646 | + $product_excerpt = $product['product_excerpt']; |
|
| 1647 | 1647 | |
| 1648 | - if (strpos($product['product_content'], '<!--more-->')) { |
|
| 1649 | - $post_content = explode('<!--more-->', $product['product_content']); |
|
| 1650 | - $product_more_informations = $post_content[0]; |
|
| 1651 | - } |
|
| 1648 | + if (strpos($product['product_content'], '<!--more-->')) { |
|
| 1649 | + $post_content = explode('<!--more-->', $product['product_content']); |
|
| 1650 | + $product_more_informations = $post_content[0]; |
|
| 1651 | + } |
|
| 1652 | 1652 | |
| 1653 | - } else { |
|
| 1654 | - $productThumbnail = wpshop_display::display_template_element('product_thumbnail_default', array()); |
|
| 1655 | - $product_title = '<i>' . __('This product does not exist', 'wpshop') . '</i>'; |
|
| 1656 | - $product_link = ''; |
|
| 1657 | - $product_more_informations = ''; |
|
| 1658 | - $product_excerpt = ''; |
|
| 1659 | - } |
|
| 1653 | + } else { |
|
| 1654 | + $productThumbnail = wpshop_display::display_template_element('product_thumbnail_default', array()); |
|
| 1655 | + $product_title = '<i>' . __('This product does not exist', 'wpshop') . '</i>'; |
|
| 1656 | + $product_link = ''; |
|
| 1657 | + $product_more_informations = ''; |
|
| 1658 | + $product_excerpt = ''; |
|
| 1659 | + } |
|
| 1660 | 1660 | |
| 1661 | - /** Retrieve product price */ |
|
| 1662 | - $price_attribute = wpshop_attributes::getElement('product_price', "'valid'", 'code'); |
|
| 1663 | - $price_display = wpshop_attributes::check_attribute_display($price_attribute->is_visible_in_front_listing, $product['custom_display'], 'attribute', 'product_price', 'mini_output'); |
|
| 1664 | - $catalog_options = get_option('wpshop_catalog_main_option', array()); |
|
| 1665 | - $productPrice = ''; |
|
| 1666 | - $wpshop_price_piloting_option = get_option('wpshop_shop_price_piloting'); |
|
| 1667 | - $check_product_price = wpshop_prices::check_product_price($product); |
|
| 1668 | - $result_price_piloting = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $check_product_price['et'] : $check_product_price['ati']; |
|
| 1669 | - 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)) { |
|
| 1670 | - $product_price_infos = wpshop_prices::get_product_price($product, 'just_price_infos', 'mini_output'); |
|
| 1671 | - |
|
| 1672 | - if (!empty($product_price_infos)) { |
|
| 1673 | - $tpl_component_price = array(); |
|
| 1674 | - /** Price piloting **/ |
|
| 1661 | + /** Retrieve product price */ |
|
| 1662 | + $price_attribute = wpshop_attributes::getElement('product_price', "'valid'", 'code'); |
|
| 1663 | + $price_display = wpshop_attributes::check_attribute_display($price_attribute->is_visible_in_front_listing, $product['custom_display'], 'attribute', 'product_price', 'mini_output'); |
|
| 1664 | + $catalog_options = get_option('wpshop_catalog_main_option', array()); |
|
| 1665 | + $productPrice = ''; |
|
| 1666 | + $wpshop_price_piloting_option = get_option('wpshop_shop_price_piloting'); |
|
| 1667 | + $check_product_price = wpshop_prices::check_product_price($product); |
|
| 1668 | + $result_price_piloting = (!empty($wpshop_price_piloting_option) && $wpshop_price_piloting_option == 'HT') ? $check_product_price['et'] : $check_product_price['ati']; |
|
| 1669 | + 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)) { |
|
| 1670 | + $product_price_infos = wpshop_prices::get_product_price($product, 'just_price_infos', 'mini_output'); |
|
| 1671 | + |
|
| 1672 | + if (!empty($product_price_infos)) { |
|
| 1673 | + $tpl_component_price = array(); |
|
| 1674 | + /** Price piloting **/ |
|
| 1675 | 1675 | $price_display_option = get_option( 'wpshop_catalog_product_option' ); |
| 1676 | 1676 | $tpl_component['PRICE_FROM'] = (!empty($price_display_option) && !empty($price_display_option['price_display']) && !empty($price_display_option['price_display']['text_from']) ) ? 'on' : ''; |
| 1677 | - $price_ploting = get_option('wpshop_shop_price_piloting'); |
|
| 1678 | - $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'])) : ''; |
|
| 1679 | - $variations = wpshop_products::get_variation($product_id); |
|
| 1677 | + $price_ploting = get_option('wpshop_shop_price_piloting'); |
|
| 1678 | + $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'])) : ''; |
|
| 1679 | + $variations = wpshop_products::get_variation($product_id); |
|
| 1680 | 1680 | $tpl_component_price['PRODUCT_PRICE'] = $product_price_infos['PRODUCT_PRICE']; |
| 1681 | 1681 | if(empty($product_price_infos['CROSSED_OUT_PRICE']) && (!empty($variations) && (!empty($product_price_infos['PRICE_FROM']) || !empty( $tpl_component['PRICE_FROM'] ) ))) { |
| 1682 | 1682 | $tpl_component_price['PRODUCT_PRICE'] = __('Price from', 'wpshop') . ' ' . $tpl_component_price['PRODUCT_PRICE']; |
| 1683 | 1683 | } |
| 1684 | - $tpl_component_price['MESSAGE_SAVE_MONEY'] = $product_price_infos['MESSAGE_SAVE_MONEY']; |
|
| 1685 | - $tpl_component_price['TAX_PILOTING'] = (!empty($price_ploting) && $price_ploting == 'HT') ? __('ET', 'wpshop') : ''; |
|
| 1686 | - $product_price_infos['MESSAGE_SAVE_MONEY']; |
|
| 1687 | - $productPrice = wpshop_display::display_template_element('product_price_template_mini_output', $tpl_component_price); |
|
| 1688 | - } else { |
|
| 1689 | - $productPrice = wpshop_prices::get_product_price($product, 'price_display', array('mini_output', $output_type)); |
|
| 1690 | - } |
|
| 1691 | - } |
|
| 1684 | + $tpl_component_price['MESSAGE_SAVE_MONEY'] = $product_price_infos['MESSAGE_SAVE_MONEY']; |
|
| 1685 | + $tpl_component_price['TAX_PILOTING'] = (!empty($price_ploting) && $price_ploting == 'HT') ? __('ET', 'wpshop') : ''; |
|
| 1686 | + $product_price_infos['MESSAGE_SAVE_MONEY']; |
|
| 1687 | + $productPrice = wpshop_display::display_template_element('product_price_template_mini_output', $tpl_component_price); |
|
| 1688 | + } else { |
|
| 1689 | + $productPrice = wpshop_prices::get_product_price($product, 'price_display', array('mini_output', $output_type)); |
|
| 1690 | + } |
|
| 1691 | + } |
|
| 1692 | 1692 | |
| 1693 | - /** Check if there is at less 1 product in stock */ |
|
| 1694 | - $wps_product_ctr = new wps_product_ctr(); |
|
| 1695 | - $productStock = $wps_product_ctr->check_stock($product_id, 1); |
|
| 1696 | - $productStock = $productStock === true ? 1 : null; |
|
| 1697 | - |
|
| 1698 | - /** Define "Add to cart" button */ |
|
| 1699 | - $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'); |
|
| 1700 | - $display_price_state_when_price_is_empty = false; |
|
| 1701 | - if (empty($productPrice) && (!empty($catalog_options) || (!empty($catalog_options['wpshop_catalog_empty_price_behaviour']) && $catalog_options['wpshop_catalog_empty_price_behaviour'] == 'yes'))) { |
|
| 1702 | - $display_price_state_when_price_is_empty = false; |
|
| 1703 | - } else if (!empty($productPrice)) { |
|
| 1704 | - $display_price_state_when_price_is_empty = true; |
|
| 1705 | - } |
|
| 1706 | - $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') : ''; |
|
| 1707 | - $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)) : ''; |
|
| 1693 | + /** Check if there is at less 1 product in stock */ |
|
| 1694 | + $wps_product_ctr = new wps_product_ctr(); |
|
| 1695 | + $productStock = $wps_product_ctr->check_stock($product_id, 1); |
|
| 1696 | + $productStock = $productStock === true ? 1 : null; |
|
| 1697 | + |
|
| 1698 | + /** Define "Add to cart" button */ |
|
| 1699 | + $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'); |
|
| 1700 | + $display_price_state_when_price_is_empty = false; |
|
| 1701 | + if (empty($productPrice) && (!empty($catalog_options) || (!empty($catalog_options['wpshop_catalog_empty_price_behaviour']) && $catalog_options['wpshop_catalog_empty_price_behaviour'] == 'yes'))) { |
|
| 1702 | + $display_price_state_when_price_is_empty = false; |
|
| 1703 | + } else if (!empty($productPrice)) { |
|
| 1704 | + $display_price_state_when_price_is_empty = true; |
|
| 1705 | + } |
|
| 1706 | + $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') : ''; |
|
| 1707 | + $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)) : ''; |
|
| 1708 | 1708 | |
| 1709 | - /** Define "Ask a quotation" button */ |
|
| 1710 | - $quotation_button = self::display_quotation_button($product_id, (!empty($product['quotation_allowed']) ? $product['quotation_allowed'] : null)); |
|
| 1711 | - $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'] : '')); |
|
| 1709 | + /** Define "Ask a quotation" button */ |
|
| 1710 | + $quotation_button = self::display_quotation_button($product_id, (!empty($product['quotation_allowed']) ? $product['quotation_allowed'] : null)); |
|
| 1711 | + $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'] : '')); |
|
| 1712 | 1712 | |
| 1713 | - $product_new = $product_new_def['output']; |
|
| 1714 | - $product_class .= $product_new_def['class']; |
|
| 1713 | + $product_new = $product_new_def['output']; |
|
| 1714 | + $product_class .= $product_new_def['class']; |
|
| 1715 | 1715 | |
| 1716 | - $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'] : '')); |
|
| 1717 | - $product_featured = $product_featured_def['output']; |
|
| 1718 | - $product_class .= $product_featured_def['class']; |
|
| 1716 | + $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'] : '')); |
|
| 1717 | + $product_featured = $product_featured_def['output']; |
|
| 1718 | + $product_class .= $product_featured_def['class']; |
|
| 1719 | 1719 | |
| 1720 | - if (!($current_item_position % $grid_element_nb_per_line)) { |
|
| 1721 | - $product_class .= ' wpshop_last_product_of_line'; |
|
| 1722 | - } |
|
| 1720 | + if (!($current_item_position % $grid_element_nb_per_line)) { |
|
| 1721 | + $product_class .= ' wpshop_last_product_of_line'; |
|
| 1722 | + } |
|
| 1723 | 1723 | |
| 1724 | - if (!empty($product['product_id'])) { |
|
| 1725 | - /** Template parameters */ |
|
| 1726 | - $template_part = 'product_mini_' . $output_type; |
|
| 1727 | - $tpl_component = array(); |
|
| 1728 | - $tpl_component['PRODUCT_THUMBNAIL'] = wpshop_display::display_template_element('product_thumbnail_default', array()); |
|
| 1729 | - $tpl_component['PRODUCT_THUMBNAIL_WPSHOP-PRODUCT-GALERY'] = wpshop_display::display_template_element('product_thumbnail_default', array()); |
|
| 1730 | - $tpl_component['PRODUCT_ID'] = $product_id; |
|
| 1731 | - $tpl_component['PRODUCT_CLASS'] = $product_class; |
|
| 1732 | - $tpl_component['PRODUCT_BUTTON_ADD_TO_CART'] = $add_to_cart_button; |
|
| 1733 | - $tpl_component['PRODUCT_BUTTON_QUOTATION'] = $quotation_button; |
|
| 1734 | - $tpl_component['PRODUCT_QUANTITY_CHOOSER'] = $product_quantity_chooser_input; |
|
| 1735 | - $tpl_component['PRODUCT_BUTTONS'] = $tpl_component['PRODUCT_BUTTON_ADD_TO_CART'] . $tpl_component['PRODUCT_BUTTON_QUOTATION']; |
|
| 1736 | - $tpl_component['PRODUCT_PRICE'] = $productPrice; |
|
| 1737 | - $tpl_component['PRODUCT_PERMALINK'] = $product_link; |
|
| 1738 | - $tpl_component['PRODUCT_TITLE'] = (!empty($product_title)) ? $product_title : ''; |
|
| 1739 | - $tpl_component['PRODUCT_NAME'] = $product_name; |
|
| 1740 | - $tpl_component['PRODUCT_DESCRIPTION'] = $product_more_informations; |
|
| 1741 | - $tpl_component['PRODUCT_IS_NEW'] = $product_new; |
|
| 1742 | - $tpl_component['PRODUCT_IS_FEATURED'] = $product_featured; |
|
| 1743 | - $tpl_component['PRODUCT_EXTRA_STATE'] = $tpl_component['PRODUCT_IS_NEW'] . $tpl_component['PRODUCT_IS_FEATURED']; |
|
| 1744 | - $tpl_component['PRODUCT_THUMBNAIL'] = $productThumbnail; |
|
| 1745 | - |
|
| 1746 | - if (has_post_thumbnail($product_id)) { |
|
| 1747 | - $image_attributes = wp_get_attachment_metadata(get_post_thumbnail_id($product_id)); |
|
| 1748 | - if (!empty($image_attributes) && !empty($image_attributes['sizes']) && is_array($image_attributes['sizes'])) { |
|
| 1749 | - $existing_image_sizes = get_intermediate_image_sizes(); |
|
| 1750 | - foreach ($existing_image_sizes as $size_name) { |
|
| 1751 | - $tpl_component['PRODUCT_THUMBNAIL_' . strtoupper($size_name)] = wp_get_attachment_image(get_post_thumbnail_id($product_id), $size_name); |
|
| 1752 | - $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; |
|
| 1753 | - } |
|
| 1754 | - } |
|
| 1755 | - } |
|
| 1756 | - |
|
| 1757 | - $tpl_component['PRODUCT_EXCERPT'] = $product_excerpt; |
|
| 1758 | - $tpl_component['PRODUCT_OUTPUT_TYPE'] = $output_type; |
|
| 1759 | - $tpl_component = apply_filters('wps-filter-product-mini-output', $tpl_component, $product_id); |
|
| 1760 | - |
|
| 1761 | - /** Build template */ |
|
| 1762 | - $tpl_way_to_take = wpshop_display::check_way_for_template($template_part); |
|
| 1763 | - if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) { |
|
| 1764 | - /** Include the old way template part */ |
|
| 1765 | - ob_start(); |
|
| 1766 | - require wpshop_display::get_template_file($tpl_way_to_take[1]); |
|
| 1767 | - $content = ob_get_contents(); |
|
| 1768 | - ob_end_clean(); |
|
| 1769 | - } else { |
|
| 1770 | - $content = wpshop_display::display_template_element($template_part, $tpl_component); |
|
| 1771 | - } |
|
| 1772 | - unset($tpl_component); |
|
| 1724 | + if (!empty($product['product_id'])) { |
|
| 1725 | + /** Template parameters */ |
|
| 1726 | + $template_part = 'product_mini_' . $output_type; |
|
| 1727 | + $tpl_component = array(); |
|
| 1728 | + $tpl_component['PRODUCT_THUMBNAIL'] = wpshop_display::display_template_element('product_thumbnail_default', array()); |
|
| 1729 | + $tpl_component['PRODUCT_THUMBNAIL_WPSHOP-PRODUCT-GALERY'] = wpshop_display::display_template_element('product_thumbnail_default', array()); |
|
| 1730 | + $tpl_component['PRODUCT_ID'] = $product_id; |
|
| 1731 | + $tpl_component['PRODUCT_CLASS'] = $product_class; |
|
| 1732 | + $tpl_component['PRODUCT_BUTTON_ADD_TO_CART'] = $add_to_cart_button; |
|
| 1733 | + $tpl_component['PRODUCT_BUTTON_QUOTATION'] = $quotation_button; |
|
| 1734 | + $tpl_component['PRODUCT_QUANTITY_CHOOSER'] = $product_quantity_chooser_input; |
|
| 1735 | + $tpl_component['PRODUCT_BUTTONS'] = $tpl_component['PRODUCT_BUTTON_ADD_TO_CART'] . $tpl_component['PRODUCT_BUTTON_QUOTATION']; |
|
| 1736 | + $tpl_component['PRODUCT_PRICE'] = $productPrice; |
|
| 1737 | + $tpl_component['PRODUCT_PERMALINK'] = $product_link; |
|
| 1738 | + $tpl_component['PRODUCT_TITLE'] = (!empty($product_title)) ? $product_title : ''; |
|
| 1739 | + $tpl_component['PRODUCT_NAME'] = $product_name; |
|
| 1740 | + $tpl_component['PRODUCT_DESCRIPTION'] = $product_more_informations; |
|
| 1741 | + $tpl_component['PRODUCT_IS_NEW'] = $product_new; |
|
| 1742 | + $tpl_component['PRODUCT_IS_FEATURED'] = $product_featured; |
|
| 1743 | + $tpl_component['PRODUCT_EXTRA_STATE'] = $tpl_component['PRODUCT_IS_NEW'] . $tpl_component['PRODUCT_IS_FEATURED']; |
|
| 1744 | + $tpl_component['PRODUCT_THUMBNAIL'] = $productThumbnail; |
|
| 1745 | + |
|
| 1746 | + if (has_post_thumbnail($product_id)) { |
|
| 1747 | + $image_attributes = wp_get_attachment_metadata(get_post_thumbnail_id($product_id)); |
|
| 1748 | + if (!empty($image_attributes) && !empty($image_attributes['sizes']) && is_array($image_attributes['sizes'])) { |
|
| 1749 | + $existing_image_sizes = get_intermediate_image_sizes(); |
|
| 1750 | + foreach ($existing_image_sizes as $size_name) { |
|
| 1751 | + $tpl_component['PRODUCT_THUMBNAIL_' . strtoupper($size_name)] = wp_get_attachment_image(get_post_thumbnail_id($product_id), $size_name); |
|
| 1752 | + $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; |
|
| 1753 | + } |
|
| 1754 | + } |
|
| 1755 | + } |
|
| 1773 | 1756 | |
| 1774 | - } |
|
| 1757 | + $tpl_component['PRODUCT_EXCERPT'] = $product_excerpt; |
|
| 1758 | + $tpl_component['PRODUCT_OUTPUT_TYPE'] = $output_type; |
|
| 1759 | + $tpl_component = apply_filters('wps-filter-product-mini-output', $tpl_component, $product_id); |
|
| 1760 | + |
|
| 1761 | + /** Build template */ |
|
| 1762 | + $tpl_way_to_take = wpshop_display::check_way_for_template($template_part); |
|
| 1763 | + if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) { |
|
| 1764 | + /** Include the old way template part */ |
|
| 1765 | + ob_start(); |
|
| 1766 | + require wpshop_display::get_template_file($tpl_way_to_take[1]); |
|
| 1767 | + $content = ob_get_contents(); |
|
| 1768 | + ob_end_clean(); |
|
| 1769 | + } else { |
|
| 1770 | + $content = wpshop_display::display_template_element($template_part, $tpl_component); |
|
| 1771 | + } |
|
| 1772 | + unset($tpl_component); |
|
| 1775 | 1773 | |
| 1776 | - return $content; |
|
| 1777 | - } |
|
| 1774 | + } |
|
| 1778 | 1775 | |
| 1779 | - /** |
|
| 1780 | - * Get the products (post) of a given category |
|
| 1781 | - * |
|
| 1782 | - * @param string $category_slug The category slug we want to get the product list for |
|
| 1783 | - * |
|
| 1784 | - * @return mixed $widget_content The output for the product list |
|
| 1785 | - */ |
|
| 1786 | - public static function get_product_of_category($category_slug, $category_id) |
|
| 1787 | - { |
|
| 1788 | - global $top_categories; |
|
| 1789 | - $widget_content = ''; |
|
| 1790 | - $products = wp_cache_get('wpshop_products_category_' . $category_id); |
|
| 1791 | - if (false == $products) { |
|
| 1792 | - $args = array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES => $category_slug); |
|
| 1793 | - $products = get_posts($args); |
|
| 1794 | - wp_cache_set('wpshop_products_category_' . $category_id, $products); |
|
| 1795 | - } |
|
| 1796 | - if (is_array($products) && (count($products) > 0)) { |
|
| 1797 | - foreach ($products as $product) { |
|
| 1798 | - if ($product->post_status == "publish") { |
|
| 1799 | - ob_start(); |
|
| 1800 | - require wpshop_display::get_template_file('categories_products-widget.tpl.php'); |
|
| 1801 | - $widget_content .= ob_get_contents(); |
|
| 1802 | - ob_end_clean(); |
|
| 1803 | - } |
|
| 1804 | - } |
|
| 1805 | - } |
|
| 1776 | + return $content; |
|
| 1777 | + } |
|
| 1806 | 1778 | |
| 1807 | - echo $widget_content; |
|
| 1808 | - } |
|
| 1779 | + /** |
|
| 1780 | + * Get the products (post) of a given category |
|
| 1781 | + * |
|
| 1782 | + * @param string $category_slug The category slug we want to get the product list for |
|
| 1783 | + * |
|
| 1784 | + * @return mixed $widget_content The output for the product list |
|
| 1785 | + */ |
|
| 1786 | + public static function get_product_of_category($category_slug, $category_id) |
|
| 1787 | + { |
|
| 1788 | + global $top_categories; |
|
| 1789 | + $widget_content = ''; |
|
| 1790 | + $products = wp_cache_get('wpshop_products_category_' . $category_id); |
|
| 1791 | + if (false == $products) { |
|
| 1792 | + $args = array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES => $category_slug); |
|
| 1793 | + $products = get_posts($args); |
|
| 1794 | + wp_cache_set('wpshop_products_category_' . $category_id, $products); |
|
| 1795 | + } |
|
| 1796 | + if (is_array($products) && (count($products) > 0)) { |
|
| 1797 | + foreach ($products as $product) { |
|
| 1798 | + if ($product->post_status == "publish") { |
|
| 1799 | + ob_start(); |
|
| 1800 | + require wpshop_display::get_template_file('categories_products-widget.tpl.php'); |
|
| 1801 | + $widget_content .= ob_get_contents(); |
|
| 1802 | + ob_end_clean(); |
|
| 1803 | + } |
|
| 1804 | + } |
|
| 1805 | + } |
|
| 1809 | 1806 | |
| 1810 | - /** |
|
| 1811 | - * |
|
| 1812 | - * @param unknown_type $selected_product |
|
| 1813 | - * @return string |
|
| 1814 | - */ |
|
| 1815 | - public function custom_product_list($selected_product = array()) |
|
| 1816 | - { |
|
| 1817 | - global $wpdb; |
|
| 1818 | - |
|
| 1819 | - /* Start the table definition */ |
|
| 1820 | - $tableId = 'wpshop_product_list'; |
|
| 1821 | - $tableTitles = array(); |
|
| 1822 | - $tableTitles[] = ''; |
|
| 1823 | - $tableTitles[] = __('Id', 'wpshop'); |
|
| 1824 | - $tableTitles[] = __('Quantity', 'wpshop'); |
|
| 1825 | - $tableTitles[] = __('Reference', 'wpshop'); |
|
| 1826 | - $tableTitles[] = __('Product name', 'wpshop'); |
|
| 1827 | - $tableTitles[] = __('Actions', 'wpshop'); |
|
| 1828 | - $tableTitles[] = __('Price', 'wpshop'); |
|
| 1829 | - $tableClasses = array(); |
|
| 1830 | - $tableClasses[] = 'wpshop_product_selector_column'; |
|
| 1831 | - $tableClasses[] = 'wpshop_product_identifier_column'; |
|
| 1832 | - $tableClasses[] = 'wpshop_product_quantity_column'; |
|
| 1833 | - $tableClasses[] = 'wpshop_product_sku_column'; |
|
| 1834 | - $tableClasses[] = 'wpshop_product_name_column'; |
|
| 1835 | - $tableClasses[] = 'wpshop_product_link_column'; |
|
| 1836 | - $tableClasses[] = 'wpshop_product_price_column'; |
|
| 1837 | - |
|
| 1838 | - /* Get post list */ |
|
| 1839 | - $has_result = false; |
|
| 1840 | - $current_line_index = 0; |
|
| 1841 | - $posts = query_posts(array( |
|
| 1842 | - 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'posts_per_page' => -1, |
|
| 1843 | - )); |
|
| 1844 | - if (!empty($posts)) { |
|
| 1845 | - $has_result = true; |
|
| 1846 | - foreach ($posts as $post) { |
|
| 1847 | - $tableRowsId[$current_line_index] = 'product_' . $post->ID; |
|
| 1848 | - |
|
| 1849 | - $post_info = get_post_meta($post->ID, '_wpshop_product_metadata', true); |
|
| 1850 | - |
|
| 1851 | - unset($tableRowValue); |
|
| 1852 | - $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 . '" />'); |
|
| 1853 | - $tableRowValue[] = array('class' => 'wpshop_product_identifier_cell', 'value' => '<label for="wpshop_product_cb_dialog_' . $post->ID . '" >' . WPSHOP_IDENTIFIER_PRODUCT . $post->ID . '</label>'); |
|
| 1854 | - $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>'); |
|
| 1855 | - $tableRowValue[] = array('class' => 'wpshop_product_sku_cell', 'value' => (!empty($post_info['product_reference'])) ? $post_info['product_reference'] : ''); |
|
| 1856 | - $tableRowValue[] = array('class' => 'wpshop_product_name_cell', 'value' => $post->post_title); |
|
| 1857 | - $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/> |
|
| 1807 | + echo $widget_content; |
|
| 1808 | + } |
|
| 1809 | + |
|
| 1810 | + /** |
|
| 1811 | + * |
|
| 1812 | + * @param unknown_type $selected_product |
|
| 1813 | + * @return string |
|
| 1814 | + */ |
|
| 1815 | + public function custom_product_list($selected_product = array()) |
|
| 1816 | + { |
|
| 1817 | + global $wpdb; |
|
| 1818 | + |
|
| 1819 | + /* Start the table definition */ |
|
| 1820 | + $tableId = 'wpshop_product_list'; |
|
| 1821 | + $tableTitles = array(); |
|
| 1822 | + $tableTitles[] = ''; |
|
| 1823 | + $tableTitles[] = __('Id', 'wpshop'); |
|
| 1824 | + $tableTitles[] = __('Quantity', 'wpshop'); |
|
| 1825 | + $tableTitles[] = __('Reference', 'wpshop'); |
|
| 1826 | + $tableTitles[] = __('Product name', 'wpshop'); |
|
| 1827 | + $tableTitles[] = __('Actions', 'wpshop'); |
|
| 1828 | + $tableTitles[] = __('Price', 'wpshop'); |
|
| 1829 | + $tableClasses = array(); |
|
| 1830 | + $tableClasses[] = 'wpshop_product_selector_column'; |
|
| 1831 | + $tableClasses[] = 'wpshop_product_identifier_column'; |
|
| 1832 | + $tableClasses[] = 'wpshop_product_quantity_column'; |
|
| 1833 | + $tableClasses[] = 'wpshop_product_sku_column'; |
|
| 1834 | + $tableClasses[] = 'wpshop_product_name_column'; |
|
| 1835 | + $tableClasses[] = 'wpshop_product_link_column'; |
|
| 1836 | + $tableClasses[] = 'wpshop_product_price_column'; |
|
| 1837 | + |
|
| 1838 | + /* Get post list */ |
|
| 1839 | + $has_result = false; |
|
| 1840 | + $current_line_index = 0; |
|
| 1841 | + $posts = query_posts(array( |
|
| 1842 | + 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'posts_per_page' => -1, |
|
| 1843 | + )); |
|
| 1844 | + if (!empty($posts)) { |
|
| 1845 | + $has_result = true; |
|
| 1846 | + foreach ($posts as $post) { |
|
| 1847 | + $tableRowsId[$current_line_index] = 'product_' . $post->ID; |
|
| 1848 | + |
|
| 1849 | + $post_info = get_post_meta($post->ID, '_wpshop_product_metadata', true); |
|
| 1850 | + |
|
| 1851 | + unset($tableRowValue); |
|
| 1852 | + $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 . '" />'); |
|
| 1853 | + $tableRowValue[] = array('class' => 'wpshop_product_identifier_cell', 'value' => '<label for="wpshop_product_cb_dialog_' . $post->ID . '" >' . WPSHOP_IDENTIFIER_PRODUCT . $post->ID . '</label>'); |
|
| 1854 | + $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>'); |
|
| 1855 | + $tableRowValue[] = array('class' => 'wpshop_product_sku_cell', 'value' => (!empty($post_info['product_reference'])) ? $post_info['product_reference'] : ''); |
|
| 1856 | + $tableRowValue[] = array('class' => 'wpshop_product_name_cell', 'value' => $post->post_title); |
|
| 1857 | + $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/> |
|
| 1858 | 1858 | <a href="' . admin_url('post.php?post=' . $post->ID . '&action=edit') . '" target="wpshop_edit_product" >' . __('Edit product', 'wpshop') . '</a>'); |
| 1859 | - $tableRowValue[] = array('class' => 'wpshop_product_price_cell', 'value' => __('Price ET', 'wpshop') . ' : ' . ((!empty($post_info[WPSHOP_PRODUCT_PRICE_HT])) ? round($post_info[WPSHOP_PRODUCT_PRICE_HT], 2) . ' ' . wpshop_tools::wpshop_get_currency() : '') . '<br/>' . __('Price ATI', 'wpshop') . ' : ' . ((!empty($post_info[WPSHOP_PRODUCT_PRICE_TTC])) ? round($post_info[WPSHOP_PRODUCT_PRICE_TTC], 2) . ' ' . wpshop_tools::wpshop_get_currency() : '')); |
|
| 1860 | - $tableRows[] = $tableRowValue; |
|
| 1859 | + $tableRowValue[] = array('class' => 'wpshop_product_price_cell', 'value' => __('Price ET', 'wpshop') . ' : ' . ((!empty($post_info[WPSHOP_PRODUCT_PRICE_HT])) ? round($post_info[WPSHOP_PRODUCT_PRICE_HT], 2) . ' ' . wpshop_tools::wpshop_get_currency() : '') . '<br/>' . __('Price ATI', 'wpshop') . ' : ' . ((!empty($post_info[WPSHOP_PRODUCT_PRICE_TTC])) ? round($post_info[WPSHOP_PRODUCT_PRICE_TTC], 2) . ' ' . wpshop_tools::wpshop_get_currency() : '')); |
|
| 1860 | + $tableRows[] = $tableRowValue; |
|
| 1861 | 1861 | |
| 1862 | - $current_line_index++; |
|
| 1863 | - } |
|
| 1864 | - wp_reset_query(); |
|
| 1865 | - } |
|
| 1866 | - $posts = query_posts(array( |
|
| 1867 | - 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, 'posts_per_page' => -1, |
|
| 1868 | - )); |
|
| 1869 | - if (!empty($posts)) { |
|
| 1870 | - $has_result = true; |
|
| 1871 | - foreach ($posts as $post) { |
|
| 1872 | - $tableRowsId[$current_line_index] = 'product_' . $post->ID; |
|
| 1873 | - |
|
| 1874 | - $post_info = get_post_meta($post->ID, '_wpshop_product_metadata', true); |
|
| 1875 | - |
|
| 1876 | - unset($tableRowValue); |
|
| 1877 | - $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 . '" />'); |
|
| 1878 | - $tableRowValue[] = array('class' => 'wpshop_product_identifier_cell', 'value' => '<label for="wpshop_product_cb_dialog_' . $post->ID . '" >' . WPSHOP_IDENTIFIER_PRODUCT . $post->ID . '</label>'); |
|
| 1879 | - $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>'); |
|
| 1880 | - $tableRowValue[] = array('class' => 'wpshop_product_sku_cell', 'value' => (!empty($post_info['product_reference'])) ? $post_info['product_reference'] : ''); |
|
| 1881 | - $parent_product = wpshop_products::get_parent_variation($post->ID); |
|
| 1882 | - if (!empty($parent_product) && !empty($parent_product['parent_post'])) { |
|
| 1883 | - $product_variations_postmeta = get_post_meta($post->ID, '_wpshop_variations_attribute_def', true); |
|
| 1884 | - $query = $wpdb->prepare('SELECT frontend_label FROM ' . WPSHOP_DBT_ATTRIBUTE . ' WHERE code = %s', key($product_variations_postmeta)); |
|
| 1885 | - $option_name = $wpdb->get_var($query); |
|
| 1886 | - $query = $wpdb->prepare('SELECT label FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id = %d', $product_variations_postmeta[key($product_variations_postmeta)]); |
|
| 1887 | - $option_value = $wpdb->get_var($query); |
|
| 1888 | - $parent_post = $parent_product['parent_post']; |
|
| 1889 | - $tableRowValue[] = array('class' => 'wpshop_product_name_cell', 'value' => $parent_post->post_title . ' <br/>(' . $option_name . ' : ' . $option_value . ')'); |
|
| 1890 | - } else { |
|
| 1891 | - $tableRowValue[] = array('class' => 'wpshop_product_name_cell', 'value' => $post->post_title); |
|
| 1892 | - } |
|
| 1893 | - |
|
| 1894 | - $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/> |
|
| 1862 | + $current_line_index++; |
|
| 1863 | + } |
|
| 1864 | + wp_reset_query(); |
|
| 1865 | + } |
|
| 1866 | + $posts = query_posts(array( |
|
| 1867 | + 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, 'posts_per_page' => -1, |
|
| 1868 | + )); |
|
| 1869 | + if (!empty($posts)) { |
|
| 1870 | + $has_result = true; |
|
| 1871 | + foreach ($posts as $post) { |
|
| 1872 | + $tableRowsId[$current_line_index] = 'product_' . $post->ID; |
|
| 1873 | + |
|
| 1874 | + $post_info = get_post_meta($post->ID, '_wpshop_product_metadata', true); |
|
| 1875 | + |
|
| 1876 | + unset($tableRowValue); |
|
| 1877 | + $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 . '" />'); |
|
| 1878 | + $tableRowValue[] = array('class' => 'wpshop_product_identifier_cell', 'value' => '<label for="wpshop_product_cb_dialog_' . $post->ID . '" >' . WPSHOP_IDENTIFIER_PRODUCT . $post->ID . '</label>'); |
|
| 1879 | + $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>'); |
|
| 1880 | + $tableRowValue[] = array('class' => 'wpshop_product_sku_cell', 'value' => (!empty($post_info['product_reference'])) ? $post_info['product_reference'] : ''); |
|
| 1881 | + $parent_product = wpshop_products::get_parent_variation($post->ID); |
|
| 1882 | + if (!empty($parent_product) && !empty($parent_product['parent_post'])) { |
|
| 1883 | + $product_variations_postmeta = get_post_meta($post->ID, '_wpshop_variations_attribute_def', true); |
|
| 1884 | + $query = $wpdb->prepare('SELECT frontend_label FROM ' . WPSHOP_DBT_ATTRIBUTE . ' WHERE code = %s', key($product_variations_postmeta)); |
|
| 1885 | + $option_name = $wpdb->get_var($query); |
|
| 1886 | + $query = $wpdb->prepare('SELECT label FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id = %d', $product_variations_postmeta[key($product_variations_postmeta)]); |
|
| 1887 | + $option_value = $wpdb->get_var($query); |
|
| 1888 | + $parent_post = $parent_product['parent_post']; |
|
| 1889 | + $tableRowValue[] = array('class' => 'wpshop_product_name_cell', 'value' => $parent_post->post_title . ' <br/>(' . $option_name . ' : ' . $option_value . ')'); |
|
| 1890 | + } else { |
|
| 1891 | + $tableRowValue[] = array('class' => 'wpshop_product_name_cell', 'value' => $post->post_title); |
|
| 1892 | + } |
|
| 1893 | + |
|
| 1894 | + $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 | 1895 | <a href="' . admin_url('post.php?post=' . $post->ID . '&action=edit') . '" target="wpshop_edit_product" >' . __('Edit product', 'wpshop') . '</a>'); |
| 1896 | - $tableRowValue[] = array('class' => 'wpshop_product_price_cell', 'value' => __('Price ET', 'wpshop') . ' : ' . ((!empty($post_info[WPSHOP_PRODUCT_PRICE_HT])) ? round($post_info[WPSHOP_PRODUCT_PRICE_HT], 2) . ' ' . wpshop_tools::wpshop_get_currency() : '') . '<br/>' . __('Price ATI', 'wpshop') . ' : ' . ((!empty($post_info[WPSHOP_PRODUCT_PRICE_TTC])) ? round($post_info[WPSHOP_PRODUCT_PRICE_TTC], 2) . ' ' . wpshop_tools::wpshop_get_currency() : '')); |
|
| 1897 | - $tableRows[] = $tableRowValue; |
|
| 1896 | + $tableRowValue[] = array('class' => 'wpshop_product_price_cell', 'value' => __('Price ET', 'wpshop') . ' : ' . ((!empty($post_info[WPSHOP_PRODUCT_PRICE_HT])) ? round($post_info[WPSHOP_PRODUCT_PRICE_HT], 2) . ' ' . wpshop_tools::wpshop_get_currency() : '') . '<br/>' . __('Price ATI', 'wpshop') . ' : ' . ((!empty($post_info[WPSHOP_PRODUCT_PRICE_TTC])) ? round($post_info[WPSHOP_PRODUCT_PRICE_TTC], 2) . ' ' . wpshop_tools::wpshop_get_currency() : '')); |
|
| 1897 | + $tableRows[] = $tableRowValue; |
|
| 1898 | 1898 | |
| 1899 | - $current_line_index++; |
|
| 1900 | - } |
|
| 1901 | - wp_reset_query(); |
|
| 1902 | - } |
|
| 1899 | + $current_line_index++; |
|
| 1900 | + } |
|
| 1901 | + wp_reset_query(); |
|
| 1902 | + } |
|
| 1903 | 1903 | |
| 1904 | - if (!$has_result) { |
|
| 1905 | - $tableRowsId[] = 'no_product_found'; |
|
| 1906 | - unset($tableRowValue); |
|
| 1907 | - $tableRowValue[] = array('class' => 'wpshop_product_selector_cell', 'value' => ''); |
|
| 1908 | - $tableRowValue[] = array('class' => 'wpshop_product_identifier_cell', 'value' => ''); |
|
| 1909 | - $tableRowValue[] = array('class' => 'wpshop_product_quantity_cell', 'value' => ''); |
|
| 1910 | - $tableRowValue[] = array('class' => 'wpshop_product_sku_cell', 'value' => __('No element to ouput here', 'wpshop')); |
|
| 1911 | - $tableRowValue[] = array('class' => 'wpshop_product_name_cell', 'value' => ''); |
|
| 1912 | - $tableRowValue[] = array('class' => 'wpshop_product_link_cell', 'value' => ''); |
|
| 1913 | - $tableRowValue[] = array('class' => 'wpshop_product_price_cell', 'value' => ''); |
|
| 1914 | - $tableRows[] = $tableRowValue; |
|
| 1915 | - } |
|
| 1904 | + if (!$has_result) { |
|
| 1905 | + $tableRowsId[] = 'no_product_found'; |
|
| 1906 | + unset($tableRowValue); |
|
| 1907 | + $tableRowValue[] = array('class' => 'wpshop_product_selector_cell', 'value' => ''); |
|
| 1908 | + $tableRowValue[] = array('class' => 'wpshop_product_identifier_cell', 'value' => ''); |
|
| 1909 | + $tableRowValue[] = array('class' => 'wpshop_product_quantity_cell', 'value' => ''); |
|
| 1910 | + $tableRowValue[] = array('class' => 'wpshop_product_sku_cell', 'value' => __('No element to ouput here', 'wpshop')); |
|
| 1911 | + $tableRowValue[] = array('class' => 'wpshop_product_name_cell', 'value' => ''); |
|
| 1912 | + $tableRowValue[] = array('class' => 'wpshop_product_link_cell', 'value' => ''); |
|
| 1913 | + $tableRowValue[] = array('class' => 'wpshop_product_price_cell', 'value' => ''); |
|
| 1914 | + $tableRows[] = $tableRowValue; |
|
| 1915 | + } |
|
| 1916 | 1916 | |
| 1917 | - return wpshop_display::getTable($tableId, $tableTitles, $tableRows, $tableClasses, $tableRowsId, '', false) . ' |
|
| 1917 | + return wpshop_display::getTable($tableId, $tableTitles, $tableRows, $tableClasses, $tableRowsId, '', false) . ' |
|
| 1918 | 1918 | <script type="text/javascript" > |
| 1919 | 1919 | wpshop(document).ready(function(){ |
| 1920 | 1920 | jQuery("#' . $tableId . '").dataTable( { |
@@ -1923,1534 +1923,1534 @@ discard block |
||
| 1923 | 1923 | }); |
| 1924 | 1924 | }); |
| 1925 | 1925 | </script>'; |
| 1926 | - } |
|
| 1926 | + } |
|
| 1927 | 1927 | |
| 1928 | - /** |
|
| 1929 | - * Allows to manage output for special state for a product (New product/highlight product) |
|
| 1930 | - * |
|
| 1931 | - * @param string $special The type of special type we want to output |
|
| 1932 | - * @param string $output_type The current display type (used for product listing) |
|
| 1933 | - * @param string $special_state_def The value allowing to test if we have to display a special state for the product |
|
| 1934 | - * @param datetime $special_state_start The start date if applicable for the special state |
|
| 1935 | - * @param datetime $special_state_end The end date if applicable for the special state |
|
| 1936 | - * |
|
| 1937 | - * @return array $product_special_state The product special state |
|
| 1938 | - */ |
|
| 1939 | - public static function display_product_special_state($special, $output_type, $special_state_def, $special_state_start, $special_state_end) |
|
| 1940 | - { |
|
| 1941 | - $product_special_state = array(); |
|
| 1942 | - $product_special_state['output'] = $product_special_state['class'] = ''; |
|
| 1943 | - |
|
| 1944 | - /** Get product special state definition */ |
|
| 1945 | - $special_state_def = !empty($special_state_def) ? $special_state_def : 'No'; |
|
| 1946 | - $special_state_start = !empty($special_state_start) ? substr($special_state_start, 0, 10) : null; |
|
| 1947 | - $special_state_end = !empty($special_state_end) ? substr($special_state_end, 0, 10) : null; |
|
| 1948 | - |
|
| 1949 | - /** Get current time */ |
|
| 1950 | - $current_time = substr(current_time('mysql', 0), 0, 10); |
|
| 1951 | - |
|
| 1952 | - /** PRODUCT MARK AS NEW */ |
|
| 1953 | - $show_product_special_state = false; |
|
| 1954 | - if ((strtolower(__($special_state_def, 'wpshop')) === strtolower(__('Yes', 'wpshop'))) && |
|
| 1955 | - (empty($special_state_start) || ($special_state_start == '0000-00-00') || ($special_state_start >= $current_time)) && |
|
| 1956 | - (empty($special_state_end) || ($special_state_end == '0000-00-00') || ($special_state_end <= $current_time))) { |
|
| 1957 | - $show_product_special_state = true; |
|
| 1958 | - } |
|
| 1928 | + /** |
|
| 1929 | + * Allows to manage output for special state for a product (New product/highlight product) |
|
| 1930 | + * |
|
| 1931 | + * @param string $special The type of special type we want to output |
|
| 1932 | + * @param string $output_type The current display type (used for product listing) |
|
| 1933 | + * @param string $special_state_def The value allowing to test if we have to display a special state for the product |
|
| 1934 | + * @param datetime $special_state_start The start date if applicable for the special state |
|
| 1935 | + * @param datetime $special_state_end The end date if applicable for the special state |
|
| 1936 | + * |
|
| 1937 | + * @return array $product_special_state The product special state |
|
| 1938 | + */ |
|
| 1939 | + public static function display_product_special_state($special, $output_type, $special_state_def, $special_state_start, $special_state_end) |
|
| 1940 | + { |
|
| 1941 | + $product_special_state = array(); |
|
| 1942 | + $product_special_state['output'] = $product_special_state['class'] = ''; |
|
| 1943 | + |
|
| 1944 | + /** Get product special state definition */ |
|
| 1945 | + $special_state_def = !empty($special_state_def) ? $special_state_def : 'No'; |
|
| 1946 | + $special_state_start = !empty($special_state_start) ? substr($special_state_start, 0, 10) : null; |
|
| 1947 | + $special_state_end = !empty($special_state_end) ? substr($special_state_end, 0, 10) : null; |
|
| 1948 | + |
|
| 1949 | + /** Get current time */ |
|
| 1950 | + $current_time = substr(current_time('mysql', 0), 0, 10); |
|
| 1951 | + |
|
| 1952 | + /** PRODUCT MARK AS NEW */ |
|
| 1953 | + $show_product_special_state = false; |
|
| 1954 | + if ((strtolower(__($special_state_def, 'wpshop')) === strtolower(__('Yes', 'wpshop'))) && |
|
| 1955 | + (empty($special_state_start) || ($special_state_start == '0000-00-00') || ($special_state_start >= $current_time)) && |
|
| 1956 | + (empty($special_state_end) || ($special_state_end == '0000-00-00') || ($special_state_end <= $current_time))) { |
|
| 1957 | + $show_product_special_state = true; |
|
| 1958 | + } |
|
| 1959 | 1959 | |
| 1960 | - if ($show_product_special_state) { |
|
| 1961 | - /** Check the type of special output needed */ |
|
| 1962 | - switch ($special) { |
|
| 1963 | - case 'declare_new': |
|
| 1964 | - $product_special_state['class'] = ' wpshop_product_is_new_' . $output_type; |
|
| 1965 | - $template_part = 'product_is_new_sticker'; |
|
| 1966 | - break; |
|
| 1967 | - |
|
| 1968 | - case 'highlight_product': |
|
| 1969 | - $product_special_state['class'] = ' wpshop_product_featured_' . $output_type; |
|
| 1970 | - $template_part = 'product_is_featured_sticker'; |
|
| 1971 | - break; |
|
| 1972 | - } |
|
| 1973 | - |
|
| 1974 | - /** Template parameters */ |
|
| 1975 | - $tpl_component = array(); |
|
| 1976 | - |
|
| 1977 | - /** Build template */ |
|
| 1978 | - $tpl_way_to_take = wpshop_display::check_way_for_template($template_part); |
|
| 1979 | - if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) { |
|
| 1980 | - /** Include the old way template part */ |
|
| 1981 | - ob_start(); |
|
| 1982 | - require wpshop_display::get_template_file($tpl_way_to_take[1]); |
|
| 1983 | - $product_special_state['output'] = ob_get_contents(); |
|
| 1984 | - ob_end_clean(); |
|
| 1985 | - } else { |
|
| 1986 | - $product_special_state['output'] = wpshop_display::display_template_element($template_part, $tpl_component); |
|
| 1987 | - } |
|
| 1988 | - unset($tpl_component); |
|
| 1989 | - } |
|
| 1960 | + if ($show_product_special_state) { |
|
| 1961 | + /** Check the type of special output needed */ |
|
| 1962 | + switch ($special) { |
|
| 1963 | + case 'declare_new': |
|
| 1964 | + $product_special_state['class'] = ' wpshop_product_is_new_' . $output_type; |
|
| 1965 | + $template_part = 'product_is_new_sticker'; |
|
| 1966 | + break; |
|
| 1990 | 1967 | |
| 1991 | - return $product_special_state; |
|
| 1992 | - } |
|
| 1968 | + case 'highlight_product': |
|
| 1969 | + $product_special_state['class'] = ' wpshop_product_featured_' . $output_type; |
|
| 1970 | + $template_part = 'product_is_featured_sticker'; |
|
| 1971 | + break; |
|
| 1972 | + } |
|
| 1993 | 1973 | |
| 1994 | - /** |
|
| 1995 | - * Prepare product price for saving and easier read later |
|
| 1996 | - * |
|
| 1997 | - * @param integer $element_id Identifier of current product |
|
| 1998 | - */ |
|
| 1999 | - public static function calculate_price($element_id) |
|
| 2000 | - { |
|
| 2001 | - global $wpdb; |
|
| 2002 | - |
|
| 2003 | - /** |
|
| 2004 | - * Récupères les attributs suivants : product_price, price_ht et tva |
|
| 2005 | - * par rapport à $element_id / Get the next attributes : product_price, |
|
| 2006 | - * price_ht and tva |
|
| 2007 | - */ |
|
| 2008 | - $query = $wpdb->prepare( |
|
| 2009 | - "SELECT ATTR.code, ATTR_VAL.value_id AS id, ATTR_VAL.value, ATTR.id AS attribute_id |
|
| 1974 | + /** Template parameters */ |
|
| 1975 | + $tpl_component = array(); |
|
| 1976 | + |
|
| 1977 | + /** Build template */ |
|
| 1978 | + $tpl_way_to_take = wpshop_display::check_way_for_template($template_part); |
|
| 1979 | + if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) { |
|
| 1980 | + /** Include the old way template part */ |
|
| 1981 | + ob_start(); |
|
| 1982 | + require wpshop_display::get_template_file($tpl_way_to_take[1]); |
|
| 1983 | + $product_special_state['output'] = ob_get_contents(); |
|
| 1984 | + ob_end_clean(); |
|
| 1985 | + } else { |
|
| 1986 | + $product_special_state['output'] = wpshop_display::display_template_element($template_part, $tpl_component); |
|
| 1987 | + } |
|
| 1988 | + unset($tpl_component); |
|
| 1989 | + } |
|
| 1990 | + |
|
| 1991 | + return $product_special_state; |
|
| 1992 | + } |
|
| 1993 | + |
|
| 1994 | + /** |
|
| 1995 | + * Prepare product price for saving and easier read later |
|
| 1996 | + * |
|
| 1997 | + * @param integer $element_id Identifier of current product |
|
| 1998 | + */ |
|
| 1999 | + public static function calculate_price($element_id) |
|
| 2000 | + { |
|
| 2001 | + global $wpdb; |
|
| 2002 | + |
|
| 2003 | + /** |
|
| 2004 | + * Récupères les attributs suivants : product_price, price_ht et tva |
|
| 2005 | + * par rapport à $element_id / Get the next attributes : product_price, |
|
| 2006 | + * price_ht and tva |
|
| 2007 | + */ |
|
| 2008 | + $query = $wpdb->prepare( |
|
| 2009 | + "SELECT ATTR.code, ATTR_VAL.value_id AS id, ATTR_VAL.value, ATTR.id AS attribute_id |
|
| 2010 | 2010 | FROM " . WPSHOP_DBT_ATTRIBUTE . " AS ATTR |
| 2011 | 2011 | RIGHT JOIN " . WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL . " AS ATTR_VAL ON ((ATTR_VAL.attribute_id = ATTR.id) AND (ATTR_VAL.entity_id = %d)) |
| 2012 | 2012 | WHERE ATTR.code IN ('" . implode("', '", unserialize(WPSHOP_ATTRIBUTE_PRICES)) . "')", |
| 2013 | - $element_id |
|
| 2014 | - ); |
|
| 2015 | - $prices_attribute = $wpdb->get_results($query, OBJECT_K); |
|
| 2016 | - |
|
| 2017 | - /** Si aucun prix trouvé on stop la méthode / If not found price, stop the method */ |
|
| 2018 | - if (empty($prices_attribute)) { |
|
| 2019 | - return false; |
|
| 2020 | - } else { |
|
| 2021 | - /** |
|
| 2022 | - * Récupère le prix de base selon le pilotage de prix de la boutique / Get |
|
| 2023 | - * the base amount according on the shop price control |
|
| 2024 | - */ |
|
| 2025 | - $base_price = $prices_attribute[constant('WPSHOP_PRODUCT_PRICE_' . WPSHOP_PRODUCT_PRICE_PILOT)]->value; |
|
| 2026 | - $rate_vat = wpshop_prices::get_rate_vat($element_id); |
|
| 2027 | - $divider_price_ttc = 1 + ($rate_vat->value / 100); |
|
| 2028 | - |
|
| 2029 | - /** |
|
| 2030 | - * Informations nécessaire pour crée un attribut / Information needed to |
|
| 2031 | - * create an attribute |
|
| 2032 | - */ |
|
| 2033 | - $entity_type_id = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT); |
|
| 2034 | - $language = WPSHOP_CURRENT_LOCALE; |
|
| 2035 | - $icl_post_language = !empty($_REQUEST['icl_post_language']) ? sanitize_text_field($_REQUEST['icl_post_language']) : ''; |
|
| 2036 | - |
|
| 2037 | - if (!empty($icl_post_language)) { |
|
| 2038 | - $query = $wpdb->prepare("SELECT locale FROM " . $wpdb->prefix . "icl_locale_map WHERE code = %s", $icl_post_language); |
|
| 2039 | - $language = $wpdb->get_var($query); |
|
| 2040 | - } |
|
| 2041 | - |
|
| 2042 | - /** |
|
| 2043 | - * Vérifie la configuration pour savoir comment calculer les prix pour le produit / |
|
| 2044 | - * Check configuration to know how to make the calcul for the product |
|
| 2045 | - */ |
|
| 2046 | - if (WPSHOP_PRODUCT_PRICE_PILOT == 'HT') { |
|
| 2047 | - $price_with_vat = ($base_price * $divider_price_ttc); |
|
| 2048 | - $price_no_vat = $base_price; |
|
| 2049 | - } else if (WPSHOP_PRODUCT_PRICE_PILOT == 'TTC') { |
|
| 2050 | - $price_with_vat = $base_price; |
|
| 2051 | - $price_no_vat = ($price_with_vat / $divider_price_ttc); |
|
| 2052 | - } |
|
| 2053 | - |
|
| 2054 | - /** |
|
| 2055 | - * Le dernier paramètre permet de ne pas supprimer les attributs du même |
|
| 2056 | - * type que celui-ci / The last parameter allows not to delete the |
|
| 2057 | - * attributes of the same type as this one |
|
| 2058 | - */ |
|
| 2059 | - wpshop_attributes::saveAttributeForEntity(array('decimal' => array('product_price' => $price_with_vat)), $entity_type_id, $element_id, $language, 'wpshop_products'); |
|
| 2060 | - wpshop_attributes::saveAttributeForEntity(array('decimal' => array('price_ht' => $price_no_vat)), $entity_type_id, $element_id, $language, 'wpshop_product'); |
|
| 2061 | - |
|
| 2062 | - /** Ajout ou met à jour de l'attribut tva / Add or update the attribute vat */ |
|
| 2063 | - $vat_amount = $price_with_vat - $price_no_vat; |
|
| 2064 | - wpshop_attributes::saveAttributeForEntity(array('decimal' => array('tva' => $vat_amount)), $entity_type_id, $element_id, $language, 'wpshop_product'); |
|
| 2065 | - |
|
| 2066 | - /** Update the product meta information with the calculated prices */ |
|
| 2067 | - $product_postmeta = get_post_meta($element_id, WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, true); |
|
| 2068 | - $product_postmeta[WPSHOP_PRODUCT_PRICE_TTC] = number_format(round($price_with_vat, 5), 5, '.', ''); |
|
| 2069 | - $product_postmeta[WPSHOP_PRODUCT_PRICE_HT] = number_format(round($price_no_vat, 5), 5, '.', ''); |
|
| 2070 | - $product_postmeta[WPSHOP_PRODUCT_PRICE_TAX_AMOUNT] = number_format(round($vat_amount, 5), 5, '.', ''); |
|
| 2071 | - $product_postmeta[WPSHOP_PRODUCT_PRICE_TAX] = $rate_vat->id; |
|
| 2072 | - |
|
| 2073 | - update_post_meta($element_id, WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, $product_postmeta); |
|
| 2013 | + $element_id |
|
| 2014 | + ); |
|
| 2015 | + $prices_attribute = $wpdb->get_results($query, OBJECT_K); |
|
| 2016 | + |
|
| 2017 | + /** Si aucun prix trouvé on stop la méthode / If not found price, stop the method */ |
|
| 2018 | + if (empty($prices_attribute)) { |
|
| 2019 | + return false; |
|
| 2020 | + } else { |
|
| 2021 | + /** |
|
| 2022 | + * Récupère le prix de base selon le pilotage de prix de la boutique / Get |
|
| 2023 | + * the base amount according on the shop price control |
|
| 2024 | + */ |
|
| 2025 | + $base_price = $prices_attribute[constant('WPSHOP_PRODUCT_PRICE_' . WPSHOP_PRODUCT_PRICE_PILOT)]->value; |
|
| 2026 | + $rate_vat = wpshop_prices::get_rate_vat($element_id); |
|
| 2027 | + $divider_price_ttc = 1 + ($rate_vat->value / 100); |
|
| 2028 | + |
|
| 2029 | + /** |
|
| 2030 | + * Informations nécessaire pour crée un attribut / Information needed to |
|
| 2031 | + * create an attribute |
|
| 2032 | + */ |
|
| 2033 | + $entity_type_id = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT); |
|
| 2034 | + $language = WPSHOP_CURRENT_LOCALE; |
|
| 2035 | + $icl_post_language = !empty($_REQUEST['icl_post_language']) ? sanitize_text_field($_REQUEST['icl_post_language']) : ''; |
|
| 2036 | + |
|
| 2037 | + if (!empty($icl_post_language)) { |
|
| 2038 | + $query = $wpdb->prepare("SELECT locale FROM " . $wpdb->prefix . "icl_locale_map WHERE code = %s", $icl_post_language); |
|
| 2039 | + $language = $wpdb->get_var($query); |
|
| 2040 | + } |
|
| 2074 | 2041 | |
| 2075 | - /** Met à jour la meta _wps_price_infos */ |
|
| 2076 | - $p = wpshop_products::get_product_data($element_id); |
|
| 2077 | - $price = wpshop_prices::get_product_price($p, 'just_price_infos', array('mini_output', 'grid')); |
|
| 2078 | - update_post_meta($element_id, '_wps_price_infos', $price); |
|
| 2042 | + /** |
|
| 2043 | + * Vérifie la configuration pour savoir comment calculer les prix pour le produit / |
|
| 2044 | + * Check configuration to know how to make the calcul for the product |
|
| 2045 | + */ |
|
| 2046 | + if (WPSHOP_PRODUCT_PRICE_PILOT == 'HT') { |
|
| 2047 | + $price_with_vat = ($base_price * $divider_price_ttc); |
|
| 2048 | + $price_no_vat = $base_price; |
|
| 2049 | + } else if (WPSHOP_PRODUCT_PRICE_PILOT == 'TTC') { |
|
| 2050 | + $price_with_vat = $base_price; |
|
| 2051 | + $price_no_vat = ($price_with_vat / $divider_price_ttc); |
|
| 2052 | + } |
|
| 2079 | 2053 | |
| 2080 | - /** Met à jour la meta _wpshop_displayed_price */ |
|
| 2081 | - wps_filter_search::save_displayed_price_meta($element_id); |
|
| 2082 | - } |
|
| 2054 | + /** |
|
| 2055 | + * Le dernier paramètre permet de ne pas supprimer les attributs du même |
|
| 2056 | + * type que celui-ci / The last parameter allows not to delete the |
|
| 2057 | + * attributes of the same type as this one |
|
| 2058 | + */ |
|
| 2059 | + wpshop_attributes::saveAttributeForEntity(array('decimal' => array('product_price' => $price_with_vat)), $entity_type_id, $element_id, $language, 'wpshop_products'); |
|
| 2060 | + wpshop_attributes::saveAttributeForEntity(array('decimal' => array('price_ht' => $price_no_vat)), $entity_type_id, $element_id, $language, 'wpshop_product'); |
|
| 2061 | + |
|
| 2062 | + /** Ajout ou met à jour de l'attribut tva / Add or update the attribute vat */ |
|
| 2063 | + $vat_amount = $price_with_vat - $price_no_vat; |
|
| 2064 | + wpshop_attributes::saveAttributeForEntity(array('decimal' => array('tva' => $vat_amount)), $entity_type_id, $element_id, $language, 'wpshop_product'); |
|
| 2065 | + |
|
| 2066 | + /** Update the product meta information with the calculated prices */ |
|
| 2067 | + $product_postmeta = get_post_meta($element_id, WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, true); |
|
| 2068 | + $product_postmeta[WPSHOP_PRODUCT_PRICE_TTC] = number_format(round($price_with_vat, 5), 5, '.', ''); |
|
| 2069 | + $product_postmeta[WPSHOP_PRODUCT_PRICE_HT] = number_format(round($price_no_vat, 5), 5, '.', ''); |
|
| 2070 | + $product_postmeta[WPSHOP_PRODUCT_PRICE_TAX_AMOUNT] = number_format(round($vat_amount, 5), 5, '.', ''); |
|
| 2071 | + $product_postmeta[WPSHOP_PRODUCT_PRICE_TAX] = $rate_vat->id; |
|
| 2072 | + |
|
| 2073 | + update_post_meta($element_id, WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, $product_postmeta); |
|
| 2074 | + |
|
| 2075 | + /** Met à jour la meta _wps_price_infos */ |
|
| 2076 | + $p = wpshop_products::get_product_data($element_id); |
|
| 2077 | + $price = wpshop_prices::get_product_price($p, 'just_price_infos', array('mini_output', 'grid')); |
|
| 2078 | + update_post_meta($element_id, '_wps_price_infos', $price); |
|
| 2079 | + |
|
| 2080 | + /** Met à jour la meta _wpshop_displayed_price */ |
|
| 2081 | + wps_filter_search::save_displayed_price_meta($element_id); |
|
| 2082 | + } |
|
| 2083 | 2083 | |
| 2084 | - return true; |
|
| 2085 | - } |
|
| 2084 | + return true; |
|
| 2085 | + } |
|
| 2086 | 2086 | |
| 2087 | - /** |
|
| 2088 | - * Allows to get the good button for adding product to cart |
|
| 2089 | - * |
|
| 2090 | - * @param integer $product_id The product identifier |
|
| 2091 | - * @param boolean $productStock If there is the possibility to add the given product to the cart |
|
| 2092 | - * |
|
| 2093 | - * @return string $button The html output for the button |
|
| 2094 | - */ |
|
| 2095 | - public static function display_add_to_cart_button($product_id, $productStock, $output_type = 'mini') |
|
| 2096 | - { |
|
| 2097 | - $button = ''; |
|
| 2087 | + /** |
|
| 2088 | + * Allows to get the good button for adding product to cart |
|
| 2089 | + * |
|
| 2090 | + * @param integer $product_id The product identifier |
|
| 2091 | + * @param boolean $productStock If there is the possibility to add the given product to the cart |
|
| 2092 | + * |
|
| 2093 | + * @return string $button The html output for the button |
|
| 2094 | + */ |
|
| 2095 | + public static function display_add_to_cart_button($product_id, $productStock, $output_type = 'mini') |
|
| 2096 | + { |
|
| 2097 | + $button = ''; |
|
| 2098 | 2098 | // $attributes_frontend_display = get_post_meta( $product_id, '_wpshop_product_attributes_frontend_display', true ); |
| 2099 | 2099 | |
| 2100 | - 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') ) */) { |
|
| 2101 | - /* |
|
| 2100 | + 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') ) */) { |
|
| 2101 | + /* |
|
| 2102 | 2102 | * Check if current product has variation for button display |
| 2103 | 2103 | */ |
| 2104 | - $variations_exists = get_posts(array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, 'post_parent' => $product_id)); |
|
| 2105 | - $variations_list = (!empty($variations_exists) && is_array(wpshop_attributes::get_attribute_user_defined(array('entity_type_id' => self::currentPageCode)))) ? true : false; |
|
| 2104 | + $variations_exists = get_posts(array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, 'post_parent' => $product_id)); |
|
| 2105 | + $variations_list = (!empty($variations_exists) && is_array(wpshop_attributes::get_attribute_user_defined(array('entity_type_id' => self::currentPageCode)))) ? true : false; |
|
| 2106 | 2106 | |
| 2107 | - /* |
|
| 2107 | + /* |
|
| 2108 | 2108 | * Template parameters |
| 2109 | 2109 | */ |
| 2110 | 2110 | |
| 2111 | - if (get_post_type($product_id) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT) { |
|
| 2112 | - /** Check variation stock **/ |
|
| 2113 | - $variations = self::get_variation($product_id); |
|
| 2114 | - if (!empty($variations)) { |
|
| 2115 | - foreach ($variations as $variation) { |
|
| 2116 | - if (!empty($variation) && !empty($variation['variation_dif']) && !empty($variation['variation_dif']['product_stock'])) { |
|
| 2117 | - $productStock += $variation['variation_dif']['product_stock']; |
|
| 2118 | - } |
|
| 2119 | - } |
|
| 2120 | - } |
|
| 2121 | - } |
|
| 2122 | - |
|
| 2123 | - $template_part = ($variations_list && ($output_type == 'mini')) ? 'configure_product_button' : (!empty($productStock) ? 'add_to_cart_button' : 'unavailable_product_button'); |
|
| 2111 | + if (get_post_type($product_id) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT) { |
|
| 2112 | + /** Check variation stock **/ |
|
| 2113 | + $variations = self::get_variation($product_id); |
|
| 2114 | + if (!empty($variations)) { |
|
| 2115 | + foreach ($variations as $variation) { |
|
| 2116 | + if (!empty($variation) && !empty($variation['variation_dif']) && !empty($variation['variation_dif']['product_stock'])) { |
|
| 2117 | + $productStock += $variation['variation_dif']['product_stock']; |
|
| 2118 | + } |
|
| 2119 | + } |
|
| 2120 | + } |
|
| 2121 | + } |
|
| 2122 | + |
|
| 2123 | + $template_part = ($variations_list && ($output_type == 'mini')) ? 'configure_product_button' : (!empty($productStock) ? 'add_to_cart_button' : 'unavailable_product_button'); |
|
| 2124 | 2124 | $template_part = apply_filters( 'wps_custom_add_to_cart_button', $template_part, $product_id ); |
| 2125 | 2125 | |
| 2126 | - $tpl_component = array(); |
|
| 2127 | - $tpl_component['PRODUCT_ID'] = $product_id; |
|
| 2128 | - $tpl_component['PRODUCT_PERMALINK'] = get_permalink($product_id); |
|
| 2129 | - $tpl_component['PRODUCT_TITLE'] = get_the_title($product_id); |
|
| 2126 | + $tpl_component = array(); |
|
| 2127 | + $tpl_component['PRODUCT_ID'] = $product_id; |
|
| 2128 | + $tpl_component['PRODUCT_PERMALINK'] = get_permalink($product_id); |
|
| 2129 | + $tpl_component['PRODUCT_TITLE'] = get_the_title($product_id); |
|
| 2130 | 2130 | |
| 2131 | - /* |
|
| 2131 | + /* |
|
| 2132 | 2132 | * Build template |
| 2133 | 2133 | */ |
| 2134 | - $tpl_way_to_take = wpshop_display::check_way_for_template($template_part); |
|
| 2135 | - if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) { |
|
| 2136 | - /* Include the old way template part */ |
|
| 2137 | - ob_start(); |
|
| 2138 | - require wpshop_display::get_template_file($tpl_way_to_take[1]); |
|
| 2139 | - $button = ob_get_contents(); |
|
| 2140 | - ob_end_clean(); |
|
| 2141 | - } else { |
|
| 2142 | - $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)); |
|
| 2143 | - } |
|
| 2144 | - unset($tpl_component); |
|
| 2145 | - } |
|
| 2146 | - return $button; |
|
| 2147 | - } |
|
| 2134 | + $tpl_way_to_take = wpshop_display::check_way_for_template($template_part); |
|
| 2135 | + if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) { |
|
| 2136 | + /* Include the old way template part */ |
|
| 2137 | + ob_start(); |
|
| 2138 | + require wpshop_display::get_template_file($tpl_way_to_take[1]); |
|
| 2139 | + $button = ob_get_contents(); |
|
| 2140 | + ob_end_clean(); |
|
| 2141 | + } else { |
|
| 2142 | + $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)); |
|
| 2143 | + } |
|
| 2144 | + unset($tpl_component); |
|
| 2145 | + } |
|
| 2146 | + return $button; |
|
| 2147 | + } |
|
| 2148 | 2148 | |
| 2149 | - /** |
|
| 2150 | - * Allows to get the good button for adding product to a quotation |
|
| 2151 | - * |
|
| 2152 | - * @param integer $product_id The product identifier |
|
| 2153 | - * @param boolean $product_quotation_state The state of the quotation addons |
|
| 2154 | - * |
|
| 2155 | - * @return string $button The html output for the button |
|
| 2156 | - */ |
|
| 2157 | - public static function display_quotation_button($product_id, $product_quotation_state, $output_type = 'mini') |
|
| 2158 | - { |
|
| 2159 | - $quotation_button = ''; |
|
| 2160 | - |
|
| 2161 | - 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'))) { |
|
| 2162 | - $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(); |
|
| 2163 | - /** |
|
| 2164 | - * Template parameters |
|
| 2165 | - */ |
|
| 2166 | - $template_part = (!empty($variations_list) && ($output_type == 'mini')) ? 'configure_quotation_button' : 'ask_quotation_button'; |
|
| 2167 | - $tpl_component = array(); |
|
| 2168 | - $tpl_component['PRODUCT_ID'] = $product_id; |
|
| 2169 | - $tpl_component['PRODUCT_PERMALINK'] = get_permalink($product_id); |
|
| 2170 | - $tpl_component['PRODUCT_TITLE'] = get_the_title($product_id); |
|
| 2149 | + /** |
|
| 2150 | + * Allows to get the good button for adding product to a quotation |
|
| 2151 | + * |
|
| 2152 | + * @param integer $product_id The product identifier |
|
| 2153 | + * @param boolean $product_quotation_state The state of the quotation addons |
|
| 2154 | + * |
|
| 2155 | + * @return string $button The html output for the button |
|
| 2156 | + */ |
|
| 2157 | + public static function display_quotation_button($product_id, $product_quotation_state, $output_type = 'mini') |
|
| 2158 | + { |
|
| 2159 | + $quotation_button = ''; |
|
| 2160 | + |
|
| 2161 | + 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'))) { |
|
| 2162 | + $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(); |
|
| 2163 | + /** |
|
| 2164 | + * Template parameters |
|
| 2165 | + */ |
|
| 2166 | + $template_part = (!empty($variations_list) && ($output_type == 'mini')) ? 'configure_quotation_button' : 'ask_quotation_button'; |
|
| 2167 | + $tpl_component = array(); |
|
| 2168 | + $tpl_component['PRODUCT_ID'] = $product_id; |
|
| 2169 | + $tpl_component['PRODUCT_PERMALINK'] = get_permalink($product_id); |
|
| 2170 | + $tpl_component['PRODUCT_TITLE'] = get_the_title($product_id); |
|
| 2171 | + |
|
| 2172 | + /** |
|
| 2173 | + * Build template |
|
| 2174 | + */ |
|
| 2175 | + $tpl_way_to_take = wpshop_display::check_way_for_template($template_part); |
|
| 2176 | + if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) { |
|
| 2177 | + /* Include the old way template part */ |
|
| 2178 | + ob_start(); |
|
| 2179 | + require wpshop_display::get_template_file($tpl_way_to_take[1]); |
|
| 2180 | + $quotation_button = ob_get_contents(); |
|
| 2181 | + ob_end_clean(); |
|
| 2182 | + } else { |
|
| 2183 | + $quotation_button = wpshop_display::display_template_element($template_part, $tpl_component); |
|
| 2184 | + } |
|
| 2185 | + unset($tpl_component); |
|
| 2186 | + } |
|
| 2171 | 2187 | |
| 2172 | - /** |
|
| 2173 | - * Build template |
|
| 2174 | - */ |
|
| 2175 | - $tpl_way_to_take = wpshop_display::check_way_for_template($template_part); |
|
| 2176 | - if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) { |
|
| 2177 | - /* Include the old way template part */ |
|
| 2178 | - ob_start(); |
|
| 2179 | - require wpshop_display::get_template_file($tpl_way_to_take[1]); |
|
| 2180 | - $quotation_button = ob_get_contents(); |
|
| 2181 | - ob_end_clean(); |
|
| 2182 | - } else { |
|
| 2183 | - $quotation_button = wpshop_display::display_template_element($template_part, $tpl_component); |
|
| 2184 | - } |
|
| 2185 | - unset($tpl_component); |
|
| 2186 | - } |
|
| 2188 | + return $quotation_button; |
|
| 2189 | + } |
|
| 2187 | 2190 | |
| 2188 | - return $quotation_button; |
|
| 2189 | - } |
|
| 2191 | + /** |
|
| 2192 | + * Return the output for a product attachement gallery (picture or document) |
|
| 2193 | + * |
|
| 2194 | + * @param string $attachement_type The type of attachement to output. allows to define with type of template to take |
|
| 2195 | + * @param string $content The gallery content build previously |
|
| 2196 | + * |
|
| 2197 | + * @return string The attachement gallery output |
|
| 2198 | + */ |
|
| 2199 | + public static function display_attachment_gallery($attachement_type, $content) |
|
| 2200 | + { |
|
| 2201 | + $galery_output = ''; |
|
| 2190 | 2202 | |
| 2191 | - /** |
|
| 2192 | - * Return the output for a product attachement gallery (picture or document) |
|
| 2193 | - * |
|
| 2194 | - * @param string $attachement_type The type of attachement to output. allows to define with type of template to take |
|
| 2195 | - * @param string $content The gallery content build previously |
|
| 2196 | - * |
|
| 2197 | - * @return string The attachement gallery output |
|
| 2198 | - */ |
|
| 2199 | - public static function display_attachment_gallery($attachement_type, $content) |
|
| 2200 | - { |
|
| 2201 | - $galery_output = ''; |
|
| 2202 | - |
|
| 2203 | - /* |
|
| 2203 | + /* |
|
| 2204 | 2204 | * Get the template part for given galery type |
| 2205 | 2205 | */ |
| 2206 | - switch ($attachement_type) { |
|
| 2207 | - case 'picture': |
|
| 2208 | - $template_part = 'product_attachment_picture_galery'; |
|
| 2209 | - break; |
|
| 2210 | - case 'document': |
|
| 2211 | - $template_part = 'product_attachment_galery'; |
|
| 2212 | - break; |
|
| 2213 | - } |
|
| 2206 | + switch ($attachement_type) { |
|
| 2207 | + case 'picture': |
|
| 2208 | + $template_part = 'product_attachment_picture_galery'; |
|
| 2209 | + break; |
|
| 2210 | + case 'document': |
|
| 2211 | + $template_part = 'product_attachment_galery'; |
|
| 2212 | + break; |
|
| 2213 | + } |
|
| 2214 | 2214 | |
| 2215 | - /* |
|
| 2215 | + /* |
|
| 2216 | 2216 | * Template parameters |
| 2217 | 2217 | */ |
| 2218 | - $tpl_component = array(); |
|
| 2219 | - $tpl_component['PRODUCT_ATTACHMENT_OUTPUT_CONTENT'] = $content; |
|
| 2220 | - $tpl_component['ATTACHMENT_ITEM_TYPE'] = $attachement_type; |
|
| 2218 | + $tpl_component = array(); |
|
| 2219 | + $tpl_component['PRODUCT_ATTACHMENT_OUTPUT_CONTENT'] = $content; |
|
| 2220 | + $tpl_component['ATTACHMENT_ITEM_TYPE'] = $attachement_type; |
|
| 2221 | 2221 | |
| 2222 | - /* |
|
| 2222 | + /* |
|
| 2223 | 2223 | * Build template |
| 2224 | 2224 | */ |
| 2225 | - $tpl_way_to_take = wpshop_display::check_way_for_template($template_part); |
|
| 2226 | - if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) { |
|
| 2227 | - /* Include the old way template part */ |
|
| 2228 | - ob_start(); |
|
| 2229 | - require wpshop_display::get_template_file($tpl_way_to_take[1]); |
|
| 2230 | - $galery_output = ob_get_contents(); |
|
| 2231 | - ob_end_clean(); |
|
| 2232 | - } else { |
|
| 2233 | - $galery_output = wpshop_display::display_template_element($template_part, $tpl_component); |
|
| 2234 | - } |
|
| 2235 | - unset($tpl_component); |
|
| 2225 | + $tpl_way_to_take = wpshop_display::check_way_for_template($template_part); |
|
| 2226 | + if ($tpl_way_to_take[0] && !empty($tpl_way_to_take[1])) { |
|
| 2227 | + /* Include the old way template part */ |
|
| 2228 | + ob_start(); |
|
| 2229 | + require wpshop_display::get_template_file($tpl_way_to_take[1]); |
|
| 2230 | + $galery_output = ob_get_contents(); |
|
| 2231 | + ob_end_clean(); |
|
| 2232 | + } else { |
|
| 2233 | + $galery_output = wpshop_display::display_template_element($template_part, $tpl_component); |
|
| 2234 | + } |
|
| 2235 | + unset($tpl_component); |
|
| 2236 | 2236 | |
| 2237 | - return $galery_output; |
|
| 2238 | - } |
|
| 2237 | + return $galery_output; |
|
| 2238 | + } |
|
| 2239 | 2239 | |
| 2240 | - /** |
|
| 2241 | - * Define the metabox to display in product edition page in backend |
|
| 2242 | - * @param object $post The current element displayed for edition |
|
| 2243 | - */ |
|
| 2244 | - public static function meta_box_variations($post) |
|
| 2245 | - { |
|
| 2246 | - $output = ''; |
|
| 2247 | - /* Variations container */ |
|
| 2248 | - $tpl_component = array(); |
|
| 2249 | - $tpl_component['ADMIN_VARIATION_CONTAINER'] = self::display_variation_admin($post->ID); |
|
| 2250 | - $tpl_component['LINK_NEW_INTERFACE'] = wp_nonce_url(get_edit_post_link($post->ID) . '&wps_variation_interface=true', 'wps_remove_variation_interface'); |
|
| 2251 | - $output .= wpshop_display::display_template_element('wpshop_admin_variation_metabox', $tpl_component, array(), 'admin'); |
|
| 2252 | - echo '<span class="wpshop_loading_ wpshopHide" ><img src="' . admin_url('images/loading.gif') . '" alt="loading picture" /></span>' . $output . '<div class="wpshop_cls" ></div>'; |
|
| 2253 | - } |
|
| 2240 | + /** |
|
| 2241 | + * Define the metabox to display in product edition page in backend |
|
| 2242 | + * @param object $post The current element displayed for edition |
|
| 2243 | + */ |
|
| 2244 | + public static function meta_box_variations($post) |
|
| 2245 | + { |
|
| 2246 | + $output = ''; |
|
| 2247 | + /* Variations container */ |
|
| 2248 | + $tpl_component = array(); |
|
| 2249 | + $tpl_component['ADMIN_VARIATION_CONTAINER'] = self::display_variation_admin($post->ID); |
|
| 2250 | + $tpl_component['LINK_NEW_INTERFACE'] = wp_nonce_url(get_edit_post_link($post->ID) . '&wps_variation_interface=true', 'wps_remove_variation_interface'); |
|
| 2251 | + $output .= wpshop_display::display_template_element('wpshop_admin_variation_metabox', $tpl_component, array(), 'admin'); |
|
| 2252 | + echo '<span class="wpshop_loading_ wpshopHide" ><img src="' . admin_url('images/loading.gif') . '" alt="loading picture" /></span>' . $output . '<div class="wpshop_cls" ></div>'; |
|
| 2253 | + } |
|
| 2254 | 2254 | |
| 2255 | - /** |
|
| 2256 | - * Call variation creation function with a list of defined variation |
|
| 2257 | - * |
|
| 2258 | - * @param array $possible_variations A list of variation to create for the current element |
|
| 2259 | - * @param integer $element_id The product we want to create variation for |
|
| 2260 | - * |
|
| 2261 | - * @return mixed The last created variation identifier |
|
| 2262 | - */ |
|
| 2263 | - public static function creation_variation_callback($possible_variations, $element_id) |
|
| 2264 | - { |
|
| 2265 | - /** Get existing variation */ |
|
| 2266 | - $existing_variations_in_db = wpshop_products::get_variation($element_id); |
|
| 2267 | - $existing_variations = array(); |
|
| 2268 | - if (!empty($existing_variations_in_db)) { |
|
| 2269 | - foreach ($existing_variations_in_db as $variations_def) { |
|
| 2270 | - $existing_variations[] = $variations_def['variation_def']; |
|
| 2271 | - } |
|
| 2272 | - } |
|
| 2273 | - /** New variation definition */ |
|
| 2274 | - $attribute_defining_variation = get_post_meta($element_id, '_wpshop_variation_defining', true); |
|
| 2275 | - |
|
| 2276 | - /** Read possible values */ |
|
| 2277 | - foreach ($possible_variations as $variation_definition) { |
|
| 2278 | - if (in_array($variation_definition, $existing_variations)) { |
|
| 2279 | - continue; |
|
| 2280 | - } |
|
| 2281 | - |
|
| 2282 | - $attribute_to_set = array(); |
|
| 2283 | - foreach ($variation_definition as $attribute_code => $attribute_selected_value) { |
|
| 2284 | - $attribute = wpshop_attributes::getElement($attribute_code, "'valid'", 'code'); |
|
| 2285 | - $attribute_to_set[$attribute->data_type][$attribute_code] = $attribute_selected_value; |
|
| 2286 | - if (empty($attribute_defining_variation['attributes']) || (!in_array($attribute_code, $attribute_defining_variation['attributes']))) { |
|
| 2287 | - $attribute_defining_variation['attributes'][] = $attribute_code; |
|
| 2288 | - } |
|
| 2289 | - } |
|
| 2290 | - $variation_id = wpshop_products::create_variation($element_id, $attribute_to_set); |
|
| 2291 | - } |
|
| 2292 | - update_post_meta($element_id, '_wpshop_variation_defining', $attribute_defining_variation); |
|
| 2255 | + /** |
|
| 2256 | + * Call variation creation function with a list of defined variation |
|
| 2257 | + * |
|
| 2258 | + * @param array $possible_variations A list of variation to create for the current element |
|
| 2259 | + * @param integer $element_id The product we want to create variation for |
|
| 2260 | + * |
|
| 2261 | + * @return mixed The last created variation identifier |
|
| 2262 | + */ |
|
| 2263 | + public static function creation_variation_callback($possible_variations, $element_id) |
|
| 2264 | + { |
|
| 2265 | + /** Get existing variation */ |
|
| 2266 | + $existing_variations_in_db = wpshop_products::get_variation($element_id); |
|
| 2267 | + $existing_variations = array(); |
|
| 2268 | + if (!empty($existing_variations_in_db)) { |
|
| 2269 | + foreach ($existing_variations_in_db as $variations_def) { |
|
| 2270 | + $existing_variations[] = $variations_def['variation_def']; |
|
| 2271 | + } |
|
| 2272 | + } |
|
| 2273 | + /** New variation definition */ |
|
| 2274 | + $attribute_defining_variation = get_post_meta($element_id, '_wpshop_variation_defining', true); |
|
| 2293 | 2275 | |
| 2294 | - return !empty($variation_id) ? $variation_id : 0; |
|
| 2295 | - } |
|
| 2276 | + /** Read possible values */ |
|
| 2277 | + foreach ($possible_variations as $variation_definition) { |
|
| 2278 | + if (in_array($variation_definition, $existing_variations)) { |
|
| 2279 | + continue; |
|
| 2280 | + } |
|
| 2296 | 2281 | |
| 2297 | - /** |
|
| 2298 | - * Create a new variation for product |
|
| 2299 | - * |
|
| 2300 | - * @param integer $head_product The product identifier to create the new variation for |
|
| 2301 | - * @param array $variation_attributes Attribute list for the variation |
|
| 2302 | - * |
|
| 2303 | - * @return mixed <number, WP_Error> The variation identifier or an error in case the creation was not succesfull |
|
| 2304 | - */ |
|
| 2305 | - public static function create_variation($head_product, $variation_attributes) |
|
| 2306 | - { |
|
| 2307 | - /** Create custom title */ |
|
| 2308 | - $title_variation = ""; |
|
| 2309 | - if (!empty($variation_attributes)) { |
|
| 2310 | - foreach ($variation_attributes as $type => $array) { |
|
| 2311 | - if (!empty($array)) { |
|
| 2312 | - foreach ($array as $code => $value) { |
|
| 2313 | - $title_variation .= " " . $code . " " . $value; |
|
| 2314 | - } |
|
| 2315 | - } |
|
| 2316 | - } |
|
| 2317 | - } |
|
| 2282 | + $attribute_to_set = array(); |
|
| 2283 | + foreach ($variation_definition as $attribute_code => $attribute_selected_value) { |
|
| 2284 | + $attribute = wpshop_attributes::getElement($attribute_code, "'valid'", 'code'); |
|
| 2285 | + $attribute_to_set[$attribute->data_type][$attribute_code] = $attribute_selected_value; |
|
| 2286 | + if (empty($attribute_defining_variation['attributes']) || (!in_array($attribute_code, $attribute_defining_variation['attributes']))) { |
|
| 2287 | + $attribute_defining_variation['attributes'][] = $attribute_code; |
|
| 2288 | + } |
|
| 2289 | + } |
|
| 2290 | + $variation_id = wpshop_products::create_variation($element_id, $attribute_to_set); |
|
| 2291 | + } |
|
| 2292 | + update_post_meta($element_id, '_wpshop_variation_defining', $attribute_defining_variation); |
|
| 2318 | 2293 | |
| 2319 | - $variation = array( |
|
| 2320 | - 'post_title' => sprintf(__('Product %s variation %s', 'wpshop'), $head_product, get_the_title($head_product)) . $title_variation, |
|
| 2321 | - 'post_content' => '', |
|
| 2322 | - 'post_status' => 'publish', |
|
| 2323 | - 'post_author' => get_current_user_id(), |
|
| 2324 | - 'post_parent' => $head_product, |
|
| 2325 | - 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, |
|
| 2326 | - ); |
|
| 2327 | - $variation_id = wp_insert_post($variation); |
|
| 2328 | - |
|
| 2329 | - wpshop_attributes::saveAttributeForEntity($variation_attributes, wpshop_entities::get_entity_identifier_from_code(wpshop_products::currentPageCode), $variation_id, WPSHOP_CURRENT_LOCALE, ''); |
|
| 2330 | - |
|
| 2331 | - /* Update product price looking for shop parameters */ |
|
| 2332 | - wpshop_products::calculate_price($variation_id); |
|
| 2333 | - |
|
| 2334 | - /* Save the attributes values into wordpress post metadata database in order to have a backup and to make frontend search working */ |
|
| 2335 | - $productMetaDatas = array(); |
|
| 2336 | - foreach ($variation_attributes as $attributeType => $attributeValues) { |
|
| 2337 | - foreach ($attributeValues as $attributeCode => $attributeValue) { |
|
| 2338 | - if (!empty($attributeValue)) { |
|
| 2339 | - $productMetaDatas[$attributeCode] = $attributeValue; |
|
| 2340 | - } |
|
| 2341 | - } |
|
| 2342 | - } |
|
| 2343 | - update_post_meta($variation_id, '_wpshop_variations_attribute_def', $productMetaDatas); |
|
| 2344 | - update_post_meta($variation_id, WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, $productMetaDatas); |
|
| 2345 | - 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)); |
|
| 2294 | + return !empty($variation_id) ? $variation_id : 0; |
|
| 2295 | + } |
|
| 2346 | 2296 | |
| 2347 | - return $variation_id; |
|
| 2348 | - } |
|
| 2297 | + /** |
|
| 2298 | + * Create a new variation for product |
|
| 2299 | + * |
|
| 2300 | + * @param integer $head_product The product identifier to create the new variation for |
|
| 2301 | + * @param array $variation_attributes Attribute list for the variation |
|
| 2302 | + * |
|
| 2303 | + * @return mixed <number, WP_Error> The variation identifier or an error in case the creation was not succesfull |
|
| 2304 | + */ |
|
| 2305 | + public static function create_variation($head_product, $variation_attributes) |
|
| 2306 | + { |
|
| 2307 | + /** Create custom title */ |
|
| 2308 | + $title_variation = ""; |
|
| 2309 | + if (!empty($variation_attributes)) { |
|
| 2310 | + foreach ($variation_attributes as $type => $array) { |
|
| 2311 | + if (!empty($array)) { |
|
| 2312 | + foreach ($array as $code => $value) { |
|
| 2313 | + $title_variation .= " " . $code . " " . $value; |
|
| 2314 | + } |
|
| 2315 | + } |
|
| 2316 | + } |
|
| 2317 | + } |
|
| 2349 | 2318 | |
| 2350 | - /** |
|
| 2351 | - * Get variation list for a given product |
|
| 2352 | - * |
|
| 2353 | - * @param integer $head_product The product identifier to get the variation for |
|
| 2354 | - * @return object The variation list |
|
| 2355 | - */ |
|
| 2356 | - public static function get_variation($head_product, $type = 'any') |
|
| 2357 | - { |
|
| 2358 | - global $wpdb; |
|
| 2359 | - $variations_output = null; |
|
| 2360 | - $args = array( |
|
| 2361 | - 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, |
|
| 2362 | - 'post_parent' => $head_product, |
|
| 2363 | - 'orderby' => 'ID', |
|
| 2364 | - 'order' => 'ASC', |
|
| 2365 | - 'posts_per_page' => -1, |
|
| 2366 | - 'post_status' => $type, |
|
| 2367 | - ); |
|
| 2368 | - $variations = get_posts($args); |
|
| 2369 | - |
|
| 2370 | - if (!empty($variations)) { |
|
| 2371 | - $head_wpshop_variation_definition = get_post_meta($head_product, '_wpshop_variation_defining', true); |
|
| 2372 | - |
|
| 2373 | - foreach ($variations as $post_def) { |
|
| 2374 | - $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'"); |
|
| 2375 | - foreach ($data as $content) { |
|
| 2376 | - $attribute_value = 'attribute_value_' . $content->data_type; |
|
| 2377 | - if (!empty($content->$attribute_value)) { |
|
| 2378 | - if (!empty($head_wpshop_variation_definition['attributes']) && in_array($content->code, $head_wpshop_variation_definition['attributes'])) { |
|
| 2379 | - $variations_output[$post_def->ID]['variation_def'][$content->code] = $content->$attribute_value; |
|
| 2380 | - } else { |
|
| 2381 | - $variations_output[$post_def->ID]['variation_dif'][$content->code] = $content->$attribute_value; |
|
| 2382 | - } |
|
| 2383 | - } |
|
| 2384 | - } |
|
| 2385 | - $variations_output[$post_def->ID]['post'] = $post_def; |
|
| 2386 | - } |
|
| 2387 | - } |
|
| 2388 | - wp_reset_query(); |
|
| 2389 | - return $variations_output; |
|
| 2390 | - } |
|
| 2319 | + $variation = array( |
|
| 2320 | + 'post_title' => sprintf(__('Product %s variation %s', 'wpshop'), $head_product, get_the_title($head_product)) . $title_variation, |
|
| 2321 | + 'post_content' => '', |
|
| 2322 | + 'post_status' => 'publish', |
|
| 2323 | + 'post_author' => get_current_user_id(), |
|
| 2324 | + 'post_parent' => $head_product, |
|
| 2325 | + 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, |
|
| 2326 | + ); |
|
| 2327 | + $variation_id = wp_insert_post($variation); |
|
| 2328 | + |
|
| 2329 | + wpshop_attributes::saveAttributeForEntity($variation_attributes, wpshop_entities::get_entity_identifier_from_code(wpshop_products::currentPageCode), $variation_id, WPSHOP_CURRENT_LOCALE, ''); |
|
| 2330 | + |
|
| 2331 | + /* Update product price looking for shop parameters */ |
|
| 2332 | + wpshop_products::calculate_price($variation_id); |
|
| 2333 | + |
|
| 2334 | + /* Save the attributes values into wordpress post metadata database in order to have a backup and to make frontend search working */ |
|
| 2335 | + $productMetaDatas = array(); |
|
| 2336 | + foreach ($variation_attributes as $attributeType => $attributeValues) { |
|
| 2337 | + foreach ($attributeValues as $attributeCode => $attributeValue) { |
|
| 2338 | + if (!empty($attributeValue)) { |
|
| 2339 | + $productMetaDatas[$attributeCode] = $attributeValue; |
|
| 2340 | + } |
|
| 2341 | + } |
|
| 2342 | + } |
|
| 2343 | + update_post_meta($variation_id, '_wpshop_variations_attribute_def', $productMetaDatas); |
|
| 2344 | + update_post_meta($variation_id, WPSHOP_PRODUCT_ATTRIBUTE_META_KEY, $productMetaDatas); |
|
| 2345 | + 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)); |
|
| 2391 | 2346 | |
| 2392 | - /** |
|
| 2393 | - * Affichage des variations d'un produit dans l'administration |
|
| 2394 | - * |
|
| 2395 | - * @param integer $head_product L'identifiant du produit dont on veut afficher les variations |
|
| 2396 | - * @return string Le code html permettant l'affichage des variations dans l'interface d'édition du produit |
|
| 2397 | - */ |
|
| 2398 | - public static function display_variation_admin($head_product) |
|
| 2399 | - { |
|
| 2400 | - $output = ''; |
|
| 2401 | - $productCurrency = wpshop_tools::wpshop_get_currency(); |
|
| 2402 | - /* Récupération de la liste des variations pour le produit en cours d'édition */ |
|
| 2403 | - $variations = self::get_variation($head_product); |
|
| 2404 | - $price_piloting = get_option('wpshop_shop_price_piloting'); |
|
| 2405 | - |
|
| 2406 | - /* Affichage de la liste des variations pour le produit en cours d'édition */ |
|
| 2407 | - if (!empty($variations) && is_array($variations)) { |
|
| 2408 | - $existing_variation_list = wpshop_display::display_template_element('wpshop_admin_existing_variation_controller', array(), array(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT => $head_product), 'admin'); |
|
| 2409 | - |
|
| 2410 | - foreach ($variations as $variation) { |
|
| 2411 | - $tpl_component = array(); |
|
| 2412 | - |
|
| 2413 | - $tpl_component['ADMIN_EXISTING_VARIATIONS_CLASS'] = ' wpshop_variation_' . self::currentPageCode; |
|
| 2414 | - $tpl_component['VARIATION_IDENTIFIER'] = $variation['post']->ID; |
|
| 2415 | - $tpl_component['VARIATION_DETAIL'] = ' '; |
|
| 2416 | - $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; |
|
| 2417 | - $tpl_component['VARIATION_DETAIL_PRICE'] = number_format($p, 2, '.', '') . ' ' . $productCurrency . ' ' . ((!empty($price_piloting) && $price_piloting == 'HT') ? __('ET', 'wpshop') : __('ATI', 'wpshop')); |
|
| 2418 | - if (!empty($price_piloting) && $price_piloting == 'HT') { |
|
| 2419 | - |
|
| 2420 | - } else { |
|
| 2421 | - |
|
| 2422 | - } |
|
| 2423 | - $post_obj = $variation['post']; |
|
| 2424 | - |
|
| 2425 | - $parent_product_infos = wpshop_products::get_parent_variation($post_obj->ID); |
|
| 2426 | - if (!empty($parent_product_infos)) { |
|
| 2427 | - $parent_post = $parent_product_infos['parent_post']; |
|
| 2428 | - $product_option_postmeta = get_post_meta($parent_post->ID, '_wpshop_variation_defining', true); |
|
| 2429 | - if (!empty($product_option_postmeta['options']['price_behaviour']) && !empty($product_option_postmeta['options']['price_behaviour'][0]) && $product_option_postmeta['options']['price_behaviour'][0] == 'addition') { |
|
| 2430 | - if (!empty($price_piloting) && $price_piloting == 'HT') { |
|
| 2431 | - $product_price = ((!empty($variation['variation_dif']['price_ht'])) ? $variation['variation_dif']['price_ht'] : 0) + $parent_product_infos['parent_post_meta']['price_ht']; |
|
| 2432 | - } else { |
|
| 2433 | - $product_price = ((!empty($variation['variation_dif']['product_price'])) ? $variation['variation_dif']['product_price'] : 0) + $parent_product_infos['parent_post_meta']['product_price']; |
|
| 2434 | - } |
|
| 2435 | - $tpl_component['VARIATION_DETAIL_SALE_PRICE_INDICATION'] = __('Variation price combined with the parent product price', 'wpshop'); |
|
| 2436 | - } else { |
|
| 2437 | - if (!empty($price_piloting) && $price_piloting == 'HT') { |
|
| 2438 | - $product_price = (!empty($variation['variation_dif']['price_ht'])) ? $variation['variation_dif']['price_ht'] : 0; |
|
| 2439 | - } else { |
|
| 2440 | - $product_price = (!empty($variation['variation_dif']['product_price'])) ? $variation['variation_dif']['product_price'] : 0; |
|
| 2441 | - } |
|
| 2442 | - $tpl_component['VARIATION_DETAIL_SALE_PRICE_INDICATION'] = __('Only variation\'s price is used', 'wpshop'); |
|
| 2443 | - } |
|
| 2444 | - $product_price = number_format(str_replace(',', '.', $product_price), 2, '.', '') . ' ' . $productCurrency . ' ' . ((!empty($price_piloting) && $price_piloting == 'HT') ? __('ET', 'wpshop') : __('ATI', 'wpshop')); |
|
| 2445 | - $tpl_component['VARIATION_DETAIL_SALE_PRICE'] = $product_price; |
|
| 2446 | - } |
|
| 2447 | - |
|
| 2448 | - if (!empty($variation['variation_def'])) { |
|
| 2449 | - foreach ($variation['variation_def'] as $variation_key => $variation_value) { |
|
| 2450 | - if (!empty($variation_value)) { |
|
| 2451 | - $attribute_def_for_variation = wpshop_attributes::getElement($variation_key, "'valid'", 'code'); |
|
| 2452 | - $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'); |
|
| 2453 | - $tpl_component['VARIATION_IMAGE_CHOICE'] = ''; |
|
| 2454 | - |
|
| 2455 | - /** Define Link image to variation interface **/ |
|
| 2456 | - 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'))) { |
|
| 2457 | - $pictures = get_posts(array('post_type' => 'attachment', 'posts_per_page' => -1, 'post_status' => null, 'post_parent' => $head_product)); |
|
| 2458 | - |
|
| 2459 | - $media_id_data = get_post_meta($head_product, '_wps_product_media', true); |
|
| 2460 | - if (!empty($media_id_data)) { |
|
| 2461 | - $medias_ids = explode(',', $media_id_data); |
|
| 2462 | - |
|
| 2463 | - if (!empty($medias_ids)) { |
|
| 2464 | - foreach ($medias_ids as $media_id) { |
|
| 2465 | - if (!empty($media_id)) { |
|
| 2466 | - $pictures[] = get_post($media_id); |
|
| 2467 | - } |
|
| 2468 | - } |
|
| 2469 | - } |
|
| 2470 | - } |
|
| 2471 | - |
|
| 2472 | - $pictures_data = ''; |
|
| 2473 | - if (!empty($pictures)) { |
|
| 2474 | - $selected_picture = get_post_meta($variation['post']->ID, '_wps_variation_attached_picture', true); |
|
| 2475 | - |
|
| 2476 | - $done_picture = array(); |
|
| 2477 | - foreach ($pictures as $picture) { |
|
| 2478 | - if (!in_array($picture->ID, $done_picture)) { |
|
| 2479 | - if (wp_attachment_is_image($picture->ID)) { |
|
| 2480 | - $checked = ((!empty($selected_picture) && $selected_picture == $picture->ID) ? 'checked="checked"' : ''); |
|
| 2481 | - $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'); |
|
| 2482 | - |
|
| 2483 | - $done_picture[] = $picture->ID; |
|
| 2484 | - } |
|
| 2485 | - } |
|
| 2486 | - } |
|
| 2487 | - } |
|
| 2488 | - |
|
| 2489 | - $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'); |
|
| 2490 | - } |
|
| 2491 | - |
|
| 2492 | - } |
|
| 2493 | - } |
|
| 2494 | - } |
|
| 2495 | - |
|
| 2496 | - $tpl_component['VARIATION_DETAIL'] = substr($tpl_component['VARIATION_DETAIL'], 0, -2); |
|
| 2497 | - |
|
| 2498 | - $tpl_component['ADMIN_VARIATION_SPECIFIC_DEFINITION_CONTAINER_CLASS'] = ' wpshopHide'; |
|
| 2499 | - $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()))); |
|
| 2500 | - $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'); |
|
| 2501 | - |
|
| 2502 | - /* Add the variation definition to output */ |
|
| 2503 | - $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'); |
|
| 2504 | - } |
|
| 2505 | - |
|
| 2506 | - $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'); |
|
| 2507 | - /* Reset de la liste des résultats pour éviter les comportements indésirables */ |
|
| 2508 | - wp_reset_query(); |
|
| 2509 | - } else { |
|
| 2510 | - $output = __('No variation found for this product. Please use button above for create one', 'wpshop'); |
|
| 2511 | - } |
|
| 2347 | + return $variation_id; |
|
| 2348 | + } |
|
| 2512 | 2349 | |
| 2513 | - return $output; |
|
| 2514 | - } |
|
| 2350 | + /** |
|
| 2351 | + * Get variation list for a given product |
|
| 2352 | + * |
|
| 2353 | + * @param integer $head_product The product identifier to get the variation for |
|
| 2354 | + * @return object The variation list |
|
| 2355 | + */ |
|
| 2356 | + public static function get_variation($head_product, $type = 'any') |
|
| 2357 | + { |
|
| 2358 | + global $wpdb; |
|
| 2359 | + $variations_output = null; |
|
| 2360 | + $args = array( |
|
| 2361 | + 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION, |
|
| 2362 | + 'post_parent' => $head_product, |
|
| 2363 | + 'orderby' => 'ID', |
|
| 2364 | + 'order' => 'ASC', |
|
| 2365 | + 'posts_per_page' => -1, |
|
| 2366 | + 'post_status' => $type, |
|
| 2367 | + ); |
|
| 2368 | + $variations = get_posts($args); |
|
| 2369 | + |
|
| 2370 | + if (!empty($variations)) { |
|
| 2371 | + $head_wpshop_variation_definition = get_post_meta($head_product, '_wpshop_variation_defining', true); |
|
| 2372 | + |
|
| 2373 | + foreach ($variations as $post_def) { |
|
| 2374 | + $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'"); |
|
| 2375 | + foreach ($data as $content) { |
|
| 2376 | + $attribute_value = 'attribute_value_' . $content->data_type; |
|
| 2377 | + if (!empty($content->$attribute_value)) { |
|
| 2378 | + if (!empty($head_wpshop_variation_definition['attributes']) && in_array($content->code, $head_wpshop_variation_definition['attributes'])) { |
|
| 2379 | + $variations_output[$post_def->ID]['variation_def'][$content->code] = $content->$attribute_value; |
|
| 2380 | + } else { |
|
| 2381 | + $variations_output[$post_def->ID]['variation_dif'][$content->code] = $content->$attribute_value; |
|
| 2382 | + } |
|
| 2383 | + } |
|
| 2384 | + } |
|
| 2385 | + $variations_output[$post_def->ID]['post'] = $post_def; |
|
| 2386 | + } |
|
| 2387 | + } |
|
| 2388 | + wp_reset_query(); |
|
| 2389 | + return $variations_output; |
|
| 2390 | + } |
|
| 2515 | 2391 | |
| 2516 | - /** |
|
| 2517 | - * Retrieve and display the variation for a given product |
|
| 2518 | - * @param integer $product_id The product identifier to get variation for |
|
| 2519 | - */ |
|
| 2520 | - public static function wpshop_variation($post_id = '', $from_admin = false, $order_id = '', $qty = 1) |
|
| 2521 | - { |
|
| 2522 | - global $wp_query; |
|
| 2523 | - $output = ''; |
|
| 2524 | - |
|
| 2525 | - $product_id = empty($post_id) ? $wp_query->post->ID : $post_id; |
|
| 2526 | - $wpshop_product_attributes_frontend_display = get_post_meta($product_id, '_wpshop_product_attributes_frontend_display', true); |
|
| 2527 | - $head_wpshop_variation_definition = get_post_meta($product_id, '_wpshop_variation_defining', true); |
|
| 2528 | - |
|
| 2529 | - /** Get attribute order for current product */ |
|
| 2530 | - $product_attribute_order_detail = wpshop_attributes_set::getAttributeSetDetails(get_post_meta($product_id, WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, true)); |
|
| 2531 | - $output_order = array(); |
|
| 2532 | - if (count($product_attribute_order_detail) > 0) { |
|
| 2533 | - if (!empty($product_attribute_order_detail)) { |
|
| 2534 | - foreach ($product_attribute_order_detail as $product_attr_group_id => $product_attr_group_detail) { |
|
| 2535 | - foreach ($product_attr_group_detail['attribut'] as $position => $attribute_def) { |
|
| 2536 | - if (!empty($attribute_def->code)) { |
|
| 2537 | - $output_order[$attribute_def->code] = $position; |
|
| 2538 | - } |
|
| 2539 | - |
|
| 2540 | - } |
|
| 2541 | - } |
|
| 2542 | - } |
|
| 2543 | - } |
|
| 2392 | + /** |
|
| 2393 | + * Affichage des variations d'un produit dans l'administration |
|
| 2394 | + * |
|
| 2395 | + * @param integer $head_product L'identifiant du produit dont on veut afficher les variations |
|
| 2396 | + * @return string Le code html permettant l'affichage des variations dans l'interface d'édition du produit |
|
| 2397 | + */ |
|
| 2398 | + public static function display_variation_admin($head_product) |
|
| 2399 | + { |
|
| 2400 | + $output = ''; |
|
| 2401 | + $productCurrency = wpshop_tools::wpshop_get_currency(); |
|
| 2402 | + /* Récupération de la liste des variations pour le produit en cours d'édition */ |
|
| 2403 | + $variations = self::get_variation($head_product); |
|
| 2404 | + $price_piloting = get_option('wpshop_shop_price_piloting'); |
|
| 2405 | + |
|
| 2406 | + /* Affichage de la liste des variations pour le produit en cours d'édition */ |
|
| 2407 | + if (!empty($variations) && is_array($variations)) { |
|
| 2408 | + $existing_variation_list = wpshop_display::display_template_element('wpshop_admin_existing_variation_controller', array(), array(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT => $head_product), 'admin'); |
|
| 2409 | + |
|
| 2410 | + foreach ($variations as $variation) { |
|
| 2411 | + $tpl_component = array(); |
|
| 2412 | + |
|
| 2413 | + $tpl_component['ADMIN_EXISTING_VARIATIONS_CLASS'] = ' wpshop_variation_' . self::currentPageCode; |
|
| 2414 | + $tpl_component['VARIATION_IDENTIFIER'] = $variation['post']->ID; |
|
| 2415 | + $tpl_component['VARIATION_DETAIL'] = ' '; |
|
| 2416 | + $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; |
|
| 2417 | + $tpl_component['VARIATION_DETAIL_PRICE'] = number_format($p, 2, '.', '') . ' ' . $productCurrency . ' ' . ((!empty($price_piloting) && $price_piloting == 'HT') ? __('ET', 'wpshop') : __('ATI', 'wpshop')); |
|
| 2418 | + if (!empty($price_piloting) && $price_piloting == 'HT') { |
|
| 2419 | + |
|
| 2420 | + } else { |
|
| 2421 | + |
|
| 2422 | + } |
|
| 2423 | + $post_obj = $variation['post']; |
|
| 2424 | + |
|
| 2425 | + $parent_product_infos = wpshop_products::get_parent_variation($post_obj->ID); |
|
| 2426 | + if (!empty($parent_product_infos)) { |
|
| 2427 | + $parent_post = $parent_product_infos['parent_post']; |
|
| 2428 | + $product_option_postmeta = get_post_meta($parent_post->ID, '_wpshop_variation_defining', true); |
|
| 2429 | + if (!empty($product_option_postmeta['options']['price_behaviour']) && !empty($product_option_postmeta['options']['price_behaviour'][0]) && $product_option_postmeta['options']['price_behaviour'][0] == 'addition') { |
|
| 2430 | + if (!empty($price_piloting) && $price_piloting == 'HT') { |
|
| 2431 | + $product_price = ((!empty($variation['variation_dif']['price_ht'])) ? $variation['variation_dif']['price_ht'] : 0) + $parent_product_infos['parent_post_meta']['price_ht']; |
|
| 2432 | + } else { |
|
| 2433 | + $product_price = ((!empty($variation['variation_dif']['product_price'])) ? $variation['variation_dif']['product_price'] : 0) + $parent_product_infos['parent_post_meta']['product_price']; |
|
| 2434 | + } |
|
| 2435 | + $tpl_component['VARIATION_DETAIL_SALE_PRICE_INDICATION'] = __('Variation price combined with the parent product price', 'wpshop'); |
|
| 2436 | + } else { |
|
| 2437 | + if (!empty($price_piloting) && $price_piloting == 'HT') { |
|
| 2438 | + $product_price = (!empty($variation['variation_dif']['price_ht'])) ? $variation['variation_dif']['price_ht'] : 0; |
|
| 2439 | + } else { |
|
| 2440 | + $product_price = (!empty($variation['variation_dif']['product_price'])) ? $variation['variation_dif']['product_price'] : 0; |
|
| 2441 | + } |
|
| 2442 | + $tpl_component['VARIATION_DETAIL_SALE_PRICE_INDICATION'] = __('Only variation\'s price is used', 'wpshop'); |
|
| 2443 | + } |
|
| 2444 | + $product_price = number_format(str_replace(',', '.', $product_price), 2, '.', '') . ' ' . $productCurrency . ' ' . ((!empty($price_piloting) && $price_piloting == 'HT') ? __('ET', 'wpshop') : __('ATI', 'wpshop')); |
|
| 2445 | + $tpl_component['VARIATION_DETAIL_SALE_PRICE'] = $product_price; |
|
| 2446 | + } |
|
| 2544 | 2447 | |
| 2545 | - $variations_params = array(); |
|
| 2546 | - $variation_attribute = array(); |
|
| 2547 | - $variation_attribute_ordered = array(); |
|
| 2548 | - $possible_values = array(); |
|
| 2549 | - $possible_values_for_selection_calculation = array(); |
|
| 2550 | - |
|
| 2551 | - /* Vérification de l'existence de déclinaison pour le produit */ |
|
| 2552 | - $wpshop_variation_list = self::get_variation($product_id); |
|
| 2553 | - if (!empty($wpshop_variation_list)) { |
|
| 2554 | - foreach ($wpshop_variation_list as $variation) { |
|
| 2555 | - if (!empty($variation['variation_def'])) { |
|
| 2556 | - $display_option = get_post_meta($post_id, '_wpshop_product_attributes_frontend_display', true); |
|
| 2557 | - foreach ($variation['variation_def'] as $attribute_code => $attribute_value) { |
|
| 2558 | - if (empty($display_option) || (!empty($display_option['attribute']) && !empty($display_option['attribute'][$attribute_code]) && !empty($display_option['attribute'][$attribute_code]['complete_sheet']))) { |
|
| 2559 | - $tpl_component = array(); |
|
| 2560 | - |
|
| 2561 | - $attribute_db_definition = wpshop_attributes::getElement($attribute_code, "'valid'", 'code'); |
|
| 2562 | - $default_value_is_serial = false; |
|
| 2563 | - $attribute_list_first_element = $attribute_db_definition->default_value; |
|
| 2564 | - if (!empty($attribute_db_definition->default_value) && ($attribute_db_definition->default_value == serialize(false) || wpshop_tools::is_serialized($attribute_db_definition->default_value))) { |
|
| 2565 | - $default_value_is_serial = true; |
|
| 2566 | - $tmp_default_value = unserialize($attribute_db_definition->default_value); |
|
| 2567 | - $attribute_list_first_element = !empty($tmp_default_value['field_options']['label_for_first_item']) ? $tmp_default_value['field_options']['label_for_first_item'] : null; |
|
| 2568 | - } |
|
| 2569 | - |
|
| 2570 | - if ($default_value_is_serial && !empty($attribute_list_first_element) && ($attribute_list_first_element != 'none')) { |
|
| 2571 | - $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'); |
|
| 2572 | - } |
|
| 2573 | - |
|
| 2574 | - if (!empty($attribute_value) && ($attribute_db_definition->data_type_to_use == 'custom')) { |
|
| 2575 | - $tpl_component['VARIATION_VALUE'] = stripslashes(wpshop_attributes::get_attribute_type_select_option_info($attribute_value, 'label', 'custom')); |
|
| 2576 | - $position = wpshop_attributes::get_attribute_type_select_option_info($attribute_value, 'position', 'custom'); |
|
| 2577 | - } else if (!empty($attribute_value) && ($attribute_db_definition->data_type_to_use == 'internal')) { |
|
| 2578 | - $post_def = get_post($attribute_value); |
|
| 2579 | - $tpl_component['VARIATION_VALUE'] = stripslashes($post_def->post_title); |
|
| 2580 | - $position = $post_def->menu_order; |
|
| 2581 | - } |
|
| 2582 | - |
|
| 2583 | - if (!empty($variation['variation_dif'])) { |
|
| 2584 | - foreach ($variation['variation_dif'] as $attribute_dif_code => $attribute_dif_value) { |
|
| 2585 | - $wpshop_prices_attributes = unserialize(WPSHOP_ATTRIBUTE_PRICES); |
|
| 2586 | - $the_value = $attribute_dif_value; |
|
| 2587 | - if (in_array($attribute_dif_code, $wpshop_prices_attributes)) { |
|
| 2588 | - $the_value = wpshop_display::format_field_output('wpshop_product_price', $attribute_dif_value); |
|
| 2589 | - } |
|
| 2590 | - $tpl_component['VARIATION_DIF_' . strtoupper($attribute_dif_code)] = stripslashes($the_value); |
|
| 2591 | - } |
|
| 2592 | - } |
|
| 2593 | - if (!empty($attribute_value)) { |
|
| 2594 | - $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)); |
|
| 2595 | - $possible_values_for_selection_calculation[$attribute_code][$attribute_value] = $tpl_component['VARIATION_VALUE']; |
|
| 2596 | - } |
|
| 2597 | - unset($tpl_component); |
|
| 2598 | - } |
|
| 2599 | - } |
|
| 2600 | - } |
|
| 2601 | - } |
|
| 2602 | - |
|
| 2603 | - $variation_tpl = array(); |
|
| 2604 | - if (!empty($head_wpshop_variation_definition['attributes'])) { |
|
| 2605 | - foreach ($head_wpshop_variation_definition['attributes'] as $attribute_code) { |
|
| 2606 | - $attribute_db_definition = wpshop_attributes::getElement($attribute_code, "'valid'", 'code'); |
|
| 2607 | - |
|
| 2608 | - if (!empty($attribute_db_definition)) { |
|
| 2609 | - $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'); |
|
| 2610 | - |
|
| 2611 | - $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; |
|
| 2612 | - if (!$is_required && $attribute_db_definition->is_required == 'yes') { |
|
| 2613 | - $is_required = true; |
|
| 2614 | - } |
|
| 2615 | - |
|
| 2616 | - $input_def = array(); |
|
| 2617 | - $input_def['type'] = $attribute_db_definition->frontend_input; |
|
| 2618 | - $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); |
|
| 2619 | - if (in_array($attribute_db_definition->frontend_input, array('radio', 'checkbox'))) { |
|
| 2620 | - unset($possible_values[$attribute_code][0]); |
|
| 2621 | - $value = array($value); |
|
| 2622 | - } |
|
| 2623 | - $input_def['id'] = 'wpshop_variation_attr_' . $attribute_code; |
|
| 2624 | - $input_def['name'] = $attribute_code; |
|
| 2625 | - $real_possible_values = array(); |
|
| 2626 | - if (!empty($possible_values[$attribute_code])) { |
|
| 2627 | - ksort($possible_values[$attribute_code]); |
|
| 2628 | - foreach ($possible_values[$attribute_code] as $position => $def) { |
|
| 2629 | - foreach ($def as $attribute_value => $attribute_value_output) { |
|
| 2630 | - $real_possible_values[$attribute_value] = $attribute_value_output; |
|
| 2631 | - if (!empty($attribute_value)) { |
|
| 2632 | - global $wpdb; |
|
| 2633 | - $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); |
|
| 2634 | - if ('draft' == $wpdb->get_var($query)) { |
|
| 2635 | - unset($real_possible_values[$attribute_value]); |
|
| 2636 | - } |
|
| 2637 | - } |
|
| 2638 | - } |
|
| 2639 | - } |
|
| 2640 | - } |
|
| 2641 | - $input_def['possible_value'] = $real_possible_values; |
|
| 2642 | - $input_def['valueToPut'] = 'index'; |
|
| 2643 | - $input_def['value'] = $value; |
|
| 2644 | - |
|
| 2645 | - $input_def['options']['more_input'] = ''; |
|
| 2646 | - if (!empty($possible_values_for_selection_calculation[$attribute_code])) { |
|
| 2647 | - foreach ($possible_values_for_selection_calculation[$attribute_code] as $value_id => $value) { |
|
| 2648 | - $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 . '" />'; |
|
| 2649 | - } |
|
| 2650 | - } |
|
| 2651 | - |
|
| 2652 | - $input_def['options_label']['original'] = true; |
|
| 2653 | - $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) . '" '; |
|
| 2654 | - |
|
| 2655 | - if (!empty($real_possible_values)) { |
|
| 2656 | - $tpl_component = array(); |
|
| 2657 | - $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']; |
|
| 2658 | - $tpl_component['VARIATION_INPUT'] = wpshop_form::check_input_type($input_def, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) . $input_def['options']['more_input']; |
|
| 2659 | - $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)); |
|
| 2660 | - $tpl_component['VARIATION_CODE'] = $attribute_code; |
|
| 2661 | - $tpl_component['VARIATION_LABEL_HELPER'] = !empty($attribute_db_definition->frontend_help_message) ? ' title="' . $attribute_db_definition->frontend_help_message . '" ' : ''; |
|
| 2662 | - $tpl_component['VARIATION_LABEL_CLASS'] = !empty($attribute_db_definition->frontend_help_message) ? ' wpshop_att_variation_helper' : ''; |
|
| 2663 | - $tpl_component['VARIATION_IDENTIFIER'] = $input_def['id']; |
|
| 2664 | - $tpl_component['VARIATION_PARENT_ID'] = $product_id; |
|
| 2665 | - $tpl_component['VARIATION_PARENT_TYPE'] = WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT; |
|
| 2666 | - $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; |
|
| 2667 | - $tpl_component['VARIATION_REQUIRED_INDICATION'] = ($is_required) ? __('Required variation', 'wpshop') : ''; |
|
| 2668 | - $variation_tpl['VARIATION_COMPLETE_OUTPUT_' . strtoupper($attribute_code)] = wpshop_display::display_template_element('product_variation_item', $tpl_component); |
|
| 2669 | - $variation_attribute_ordered[$output_order[$attribute_code]] = $variation_tpl['VARIATION_COMPLETE_OUTPUT_' . strtoupper($attribute_code)]; |
|
| 2670 | - } |
|
| 2671 | - |
|
| 2672 | - $variation_attribute[] = $attribute_code; |
|
| 2673 | - } |
|
| 2674 | - } |
|
| 2675 | - } |
|
| 2448 | + if (!empty($variation['variation_def'])) { |
|
| 2449 | + foreach ($variation['variation_def'] as $variation_key => $variation_value) { |
|
| 2450 | + if (!empty($variation_value)) { |
|
| 2451 | + $attribute_def_for_variation = wpshop_attributes::getElement($variation_key, "'valid'", 'code'); |
|
| 2452 | + $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'); |
|
| 2453 | + $tpl_component['VARIATION_IMAGE_CHOICE'] = ''; |
|
| 2454 | + |
|
| 2455 | + /** Define Link image to variation interface **/ |
|
| 2456 | + 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'))) { |
|
| 2457 | + $pictures = get_posts(array('post_type' => 'attachment', 'posts_per_page' => -1, 'post_status' => null, 'post_parent' => $head_product)); |
|
| 2458 | + |
|
| 2459 | + $media_id_data = get_post_meta($head_product, '_wps_product_media', true); |
|
| 2460 | + if (!empty($media_id_data)) { |
|
| 2461 | + $medias_ids = explode(',', $media_id_data); |
|
| 2462 | + |
|
| 2463 | + if (!empty($medias_ids)) { |
|
| 2464 | + foreach ($medias_ids as $media_id) { |
|
| 2465 | + if (!empty($media_id)) { |
|
| 2466 | + $pictures[] = get_post($media_id); |
|
| 2467 | + } |
|
| 2468 | + } |
|
| 2469 | + } |
|
| 2470 | + } |
|
| 2471 | + |
|
| 2472 | + $pictures_data = ''; |
|
| 2473 | + if (!empty($pictures)) { |
|
| 2474 | + $selected_picture = get_post_meta($variation['post']->ID, '_wps_variation_attached_picture', true); |
|
| 2475 | + |
|
| 2476 | + $done_picture = array(); |
|
| 2477 | + foreach ($pictures as $picture) { |
|
| 2478 | + if (!in_array($picture->ID, $done_picture)) { |
|
| 2479 | + if (wp_attachment_is_image($picture->ID)) { |
|
| 2480 | + $checked = ((!empty($selected_picture) && $selected_picture == $picture->ID) ? 'checked="checked"' : ''); |
|
| 2481 | + $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'); |
|
| 2482 | + |
|
| 2483 | + $done_picture[] = $picture->ID; |
|
| 2484 | + } |
|
| 2485 | + } |
|
| 2486 | + } |
|
| 2487 | + } |
|
| 2488 | + |
|
| 2489 | + $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'); |
|
| 2490 | + } |
|
| 2491 | + |
|
| 2492 | + } |
|
| 2493 | + } |
|
| 2494 | + } |
|
| 2676 | 2495 | |
| 2677 | - } |
|
| 2678 | - $variation_tpl['VARIATION_FORM_ELEMENT_ID'] = $product_id; |
|
| 2679 | - wp_reset_query(); |
|
| 2680 | - |
|
| 2681 | - $attribute_defined_to_be_user_defined = wpshop_attributes::get_attribute_user_defined(array('entity_type_id' => self::currentPageCode)); |
|
| 2682 | - if (!empty($attribute_defined_to_be_user_defined)) { |
|
| 2683 | - foreach ($attribute_defined_to_be_user_defined as $attribute_not_in_variation_but_user_defined) { |
|
| 2684 | - $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; |
|
| 2685 | - |
|
| 2686 | - $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'); |
|
| 2687 | - 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')) { |
|
| 2688 | - $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] : '')); |
|
| 2689 | - |
|
| 2690 | - $tpl_component = array(); |
|
| 2691 | - $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) . '" '; |
|
| 2692 | - $tpl_component['VARIATION_INPUT'] = wpshop_form::check_input_type($attribute_output_def, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION . '[free]') . $attribute_output_def['options']; |
|
| 2693 | - $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)); |
|
| 2694 | - $tpl_component['VARIATION_CODE'] = $attribute_not_in_variation_but_user_defined->code; |
|
| 2695 | - $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 . '" ' : ''; |
|
| 2696 | - $tpl_component['VARIATION_LABEL_CLASS'] = !empty($attribute_not_in_variation_but_user_defined->frontend_help_message) ? ' wpshop_att_variation_helper' : ''; |
|
| 2697 | - $tpl_component['VARIATION_REQUIRED_INDICATION'] = ($is_required) ? __('Required variation', 'wpshop') : ''; |
|
| 2698 | - $tpl_component['VARIATION_IDENTIFIER'] = $attribute_output_def['id']; |
|
| 2699 | - $tpl_component['VARIATION_PARENT_ID'] = $product_id; |
|
| 2700 | - $tpl_component['VARIATION_PARENT_TYPE'] = WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT; |
|
| 2701 | - $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; |
|
| 2702 | - $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']; |
|
| 2703 | - $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)]; |
|
| 2704 | - } |
|
| 2705 | - } |
|
| 2706 | - } |
|
| 2707 | - $variation_tpl['VARIATION_FORM_VARIATION_LIST'] = ''; |
|
| 2708 | - if (!empty($variation_attribute_ordered) && is_array($variation_attribute_ordered)) { |
|
| 2709 | - ksort($variation_attribute_ordered); |
|
| 2710 | - foreach ($variation_attribute_ordered as $attribute_variation_to_output) { |
|
| 2711 | - $variation_tpl['VARIATION_FORM_VARIATION_LIST'] .= $attribute_variation_to_output; |
|
| 2712 | - } |
|
| 2713 | - } |
|
| 2714 | - $variation_tpl['FROM_ADMIN_INDICATOR'] = $variation_tpl['ORDER_ID_INDICATOR'] = ''; |
|
| 2715 | - $variation_tpl['PRODUCT_ADDED_TO_CART_QTY'] = (!empty($qty)) ? $qty : 1; |
|
| 2716 | - if ($from_admin && !empty($order_id)) { |
|
| 2717 | - $variation_tpl['FROM_ADMIN_INDICATOR'] = '<input type="hidden" name="wps_orders_from_admin" value="1" />'; |
|
| 2718 | - $variation_tpl['ORDER_ID_INDICATOR'] = '<input type="hidden" name="wps_orders_order_id" value="' . $order_id . '" />'; |
|
| 2719 | - } |
|
| 2720 | - $output = !empty($variation_tpl['VARIATION_FORM_VARIATION_LIST']) ? wpshop_display::display_template_element('product_variation_form', $variation_tpl) : ''; |
|
| 2496 | + $tpl_component['VARIATION_DETAIL'] = substr($tpl_component['VARIATION_DETAIL'], 0, -2); |
|
| 2721 | 2497 | |
| 2722 | - return $output; |
|
| 2723 | - } |
|
| 2498 | + $tpl_component['ADMIN_VARIATION_SPECIFIC_DEFINITION_CONTAINER_CLASS'] = ' wpshopHide'; |
|
| 2499 | + $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()))); |
|
| 2500 | + $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'); |
|
| 2724 | 2501 | |
| 2725 | - public static function get_parent_variation($variation_id) |
|
| 2726 | - { |
|
| 2727 | - $result = array(); |
|
| 2728 | - if (!empty($variation_id)) { |
|
| 2729 | - $variation_post = get_post($variation_id); |
|
| 2730 | - if (!empty($variation_post) && !empty($variation_post->post_parent)) { |
|
| 2731 | - $result['parent_post'] = get_post($variation_post->post_parent); |
|
| 2732 | - $result['parent_post_meta'] = get_post_meta($variation_post->post_parent, '_wpshop_product_metadata', true); |
|
| 2733 | - } |
|
| 2734 | - } |
|
| 2735 | - return $result; |
|
| 2736 | - } |
|
| 2502 | + /* Add the variation definition to output */ |
|
| 2503 | + $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'); |
|
| 2504 | + } |
|
| 2737 | 2505 | |
| 2738 | - /** |
|
| 2739 | - * Display the current configuration for a given product |
|
| 2740 | - * @param array $shortcode_attribute Some parameters given by the shortcode for display |
|
| 2741 | - */ |
|
| 2742 | - public function wpshop_product_variations_summary($shortcode_attribute) |
|
| 2743 | - { |
|
| 2744 | - $output = ''; |
|
| 2745 | - |
|
| 2746 | - $product_variations_selection_args = array( |
|
| 2747 | - 'CURRENCY_SELECTOR' => wpshop_attributes_unit::wpshop_shop_currency_list_field(), |
|
| 2748 | - 'PRODUCT_VARIATION_SELECTION_DISPLAY' => '', |
|
| 2749 | - ); |
|
| 2750 | - |
|
| 2751 | - $current_user_id = get_current_user_id(); |
|
| 2752 | - |
|
| 2753 | - if (!empty($_SESSION) && !empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_items'])) { |
|
| 2754 | - foreach ($_SESSION['cart']['order_items'] as $item_id => $item) { |
|
| 2755 | - if (!empty($item) && !empty($item['item_id'])) { |
|
| 2756 | - |
|
| 2757 | - $free_variations = array(); |
|
| 2758 | - if (!empty($item['item_meta']) && !empty($item['item_meta']['free_variation'])) { |
|
| 2759 | - foreach ($item['item_meta']['free_variation'] as $attribute_code => $attribute_value) { |
|
| 2760 | - $free_variations[] = $attribute_code . '-_variation_val_-' . $attribute_value; |
|
| 2761 | - } |
|
| 2762 | - } |
|
| 2763 | - |
|
| 2764 | - $variations = array(); |
|
| 2765 | - if (!empty($item['item_meta']) && !empty($item['item_meta']['variations'])) { |
|
| 2766 | - foreach ($item['item_meta']['variations'] as $variation_id => $variation_def) { |
|
| 2767 | - |
|
| 2768 | - if (!empty($variation_def['item_meta']) && !empty($variation_def['item_meta']['variation_definition'])) { |
|
| 2769 | - foreach ($variation_def['item_meta']['variation_definition'] as $attribute_code => $attribute_selected_data) { |
|
| 2770 | - $variations[] = $attribute_code . '-_variation_val_-' . $attribute_selected_data['ID']; |
|
| 2771 | - } |
|
| 2772 | - } |
|
| 2773 | - } |
|
| 2774 | - } |
|
| 2775 | - $product_variation_summary = self::wpshop_ajax_wpshop_variation_selection($item['item_id'], $variations, $free_variations, null, $item['item_qty']); |
|
| 2776 | - |
|
| 2777 | - $product_variations_selection_args['PRODUCT_VARIATION_SELECTION_DISPLAY'] .= $product_variation_summary[1]['product_output']; |
|
| 2778 | - } |
|
| 2779 | - } |
|
| 2780 | - } |
|
| 2506 | + $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'); |
|
| 2507 | + /* Reset de la liste des résultats pour éviter les comportements indésirables */ |
|
| 2508 | + wp_reset_query(); |
|
| 2509 | + } else { |
|
| 2510 | + $output = __('No variation found for this product. Please use button above for create one', 'wpshop'); |
|
| 2511 | + } |
|
| 2781 | 2512 | |
| 2782 | - $output .= wpshop_display::display_template_element('wpshop_product_configuration_summary', $product_variations_selection_args); |
|
| 2513 | + return $output; |
|
| 2514 | + } |
|
| 2783 | 2515 | |
| 2784 | - echo $output; |
|
| 2785 | - } |
|
| 2516 | + /** |
|
| 2517 | + * Retrieve and display the variation for a given product |
|
| 2518 | + * @param integer $product_id The product identifier to get variation for |
|
| 2519 | + */ |
|
| 2520 | + public static function wpshop_variation($post_id = '', $from_admin = false, $order_id = '', $qty = 1) |
|
| 2521 | + { |
|
| 2522 | + global $wp_query; |
|
| 2523 | + $output = ''; |
|
| 2524 | + |
|
| 2525 | + $product_id = empty($post_id) ? $wp_query->post->ID : $post_id; |
|
| 2526 | + $wpshop_product_attributes_frontend_display = get_post_meta($product_id, '_wpshop_product_attributes_frontend_display', true); |
|
| 2527 | + $head_wpshop_variation_definition = get_post_meta($product_id, '_wpshop_variation_defining', true); |
|
| 2528 | + |
|
| 2529 | + /** Get attribute order for current product */ |
|
| 2530 | + $product_attribute_order_detail = wpshop_attributes_set::getAttributeSetDetails(get_post_meta($product_id, WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, true)); |
|
| 2531 | + $output_order = array(); |
|
| 2532 | + if (count($product_attribute_order_detail) > 0) { |
|
| 2533 | + if (!empty($product_attribute_order_detail)) { |
|
| 2534 | + foreach ($product_attribute_order_detail as $product_attr_group_id => $product_attr_group_detail) { |
|
| 2535 | + foreach ($product_attr_group_detail['attribut'] as $position => $attribute_def) { |
|
| 2536 | + if (!empty($attribute_def->code)) { |
|
| 2537 | + $output_order[$attribute_def->code] = $position; |
|
| 2538 | + } |
|
| 2539 | + |
|
| 2540 | + } |
|
| 2541 | + } |
|
| 2542 | + } |
|
| 2543 | + } |
|
| 2544 | + |
|
| 2545 | + $variations_params = array(); |
|
| 2546 | + $variation_attribute = array(); |
|
| 2547 | + $variation_attribute_ordered = array(); |
|
| 2548 | + $possible_values = array(); |
|
| 2549 | + $possible_values_for_selection_calculation = array(); |
|
| 2550 | + |
|
| 2551 | + /* Vérification de l'existence de déclinaison pour le produit */ |
|
| 2552 | + $wpshop_variation_list = self::get_variation($product_id); |
|
| 2553 | + if (!empty($wpshop_variation_list)) { |
|
| 2554 | + foreach ($wpshop_variation_list as $variation) { |
|
| 2555 | + if (!empty($variation['variation_def'])) { |
|
| 2556 | + $display_option = get_post_meta($post_id, '_wpshop_product_attributes_frontend_display', true); |
|
| 2557 | + foreach ($variation['variation_def'] as $attribute_code => $attribute_value) { |
|
| 2558 | + if (empty($display_option) || (!empty($display_option['attribute']) && !empty($display_option['attribute'][$attribute_code]) && !empty($display_option['attribute'][$attribute_code]['complete_sheet']))) { |
|
| 2559 | + $tpl_component = array(); |
|
| 2560 | + |
|
| 2561 | + $attribute_db_definition = wpshop_attributes::getElement($attribute_code, "'valid'", 'code'); |
|
| 2562 | + $default_value_is_serial = false; |
|
| 2563 | + $attribute_list_first_element = $attribute_db_definition->default_value; |
|
| 2564 | + if (!empty($attribute_db_definition->default_value) && ($attribute_db_definition->default_value == serialize(false) || wpshop_tools::is_serialized($attribute_db_definition->default_value))) { |
|
| 2565 | + $default_value_is_serial = true; |
|
| 2566 | + $tmp_default_value = unserialize($attribute_db_definition->default_value); |
|
| 2567 | + $attribute_list_first_element = !empty($tmp_default_value['field_options']['label_for_first_item']) ? $tmp_default_value['field_options']['label_for_first_item'] : null; |
|
| 2568 | + } |
|
| 2569 | + |
|
| 2570 | + if ($default_value_is_serial && !empty($attribute_list_first_element) && ($attribute_list_first_element != 'none')) { |
|
| 2571 | + $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'); |
|
| 2572 | + } |
|
| 2573 | + |
|
| 2574 | + if (!empty($attribute_value) && ($attribute_db_definition->data_type_to_use == 'custom')) { |
|
| 2575 | + $tpl_component['VARIATION_VALUE'] = stripslashes(wpshop_attributes::get_attribute_type_select_option_info($attribute_value, 'label', 'custom')); |
|
| 2576 | + $position = wpshop_attributes::get_attribute_type_select_option_info($attribute_value, 'position', 'custom'); |
|
| 2577 | + } else if (!empty($attribute_value) && ($attribute_db_definition->data_type_to_use == 'internal')) { |
|
| 2578 | + $post_def = get_post($attribute_value); |
|
| 2579 | + $tpl_component['VARIATION_VALUE'] = stripslashes($post_def->post_title); |
|
| 2580 | + $position = $post_def->menu_order; |
|
| 2581 | + } |
|
| 2582 | + |
|
| 2583 | + if (!empty($variation['variation_dif'])) { |
|
| 2584 | + foreach ($variation['variation_dif'] as $attribute_dif_code => $attribute_dif_value) { |
|
| 2585 | + $wpshop_prices_attributes = unserialize(WPSHOP_ATTRIBUTE_PRICES); |
|
| 2586 | + $the_value = $attribute_dif_value; |
|
| 2587 | + if (in_array($attribute_dif_code, $wpshop_prices_attributes)) { |
|
| 2588 | + $the_value = wpshop_display::format_field_output('wpshop_product_price', $attribute_dif_value); |
|
| 2589 | + } |
|
| 2590 | + $tpl_component['VARIATION_DIF_' . strtoupper($attribute_dif_code)] = stripslashes($the_value); |
|
| 2591 | + } |
|
| 2592 | + } |
|
| 2593 | + if (!empty($attribute_value)) { |
|
| 2594 | + $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)); |
|
| 2595 | + $possible_values_for_selection_calculation[$attribute_code][$attribute_value] = $tpl_component['VARIATION_VALUE']; |
|
| 2596 | + } |
|
| 2597 | + unset($tpl_component); |
|
| 2598 | + } |
|
| 2599 | + } |
|
| 2600 | + } |
|
| 2601 | + } |
|
| 2602 | + |
|
| 2603 | + $variation_tpl = array(); |
|
| 2604 | + if (!empty($head_wpshop_variation_definition['attributes'])) { |
|
| 2605 | + foreach ($head_wpshop_variation_definition['attributes'] as $attribute_code) { |
|
| 2606 | + $attribute_db_definition = wpshop_attributes::getElement($attribute_code, "'valid'", 'code'); |
|
| 2607 | + |
|
| 2608 | + if (!empty($attribute_db_definition)) { |
|
| 2609 | + $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'); |
|
| 2610 | + |
|
| 2611 | + $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; |
|
| 2612 | + if (!$is_required && $attribute_db_definition->is_required == 'yes') { |
|
| 2613 | + $is_required = true; |
|
| 2614 | + } |
|
| 2615 | + |
|
| 2616 | + $input_def = array(); |
|
| 2617 | + $input_def['type'] = $attribute_db_definition->frontend_input; |
|
| 2618 | + $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); |
|
| 2619 | + if (in_array($attribute_db_definition->frontend_input, array('radio', 'checkbox'))) { |
|
| 2620 | + unset($possible_values[$attribute_code][0]); |
|
| 2621 | + $value = array($value); |
|
| 2622 | + } |
|
| 2623 | + $input_def['id'] = 'wpshop_variation_attr_' . $attribute_code; |
|
| 2624 | + $input_def['name'] = $attribute_code; |
|
| 2625 | + $real_possible_values = array(); |
|
| 2626 | + if (!empty($possible_values[$attribute_code])) { |
|
| 2627 | + ksort($possible_values[$attribute_code]); |
|
| 2628 | + foreach ($possible_values[$attribute_code] as $position => $def) { |
|
| 2629 | + foreach ($def as $attribute_value => $attribute_value_output) { |
|
| 2630 | + $real_possible_values[$attribute_value] = $attribute_value_output; |
|
| 2631 | + if (!empty($attribute_value)) { |
|
| 2632 | + global $wpdb; |
|
| 2633 | + $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); |
|
| 2634 | + if ('draft' == $wpdb->get_var($query)) { |
|
| 2635 | + unset($real_possible_values[$attribute_value]); |
|
| 2636 | + } |
|
| 2637 | + } |
|
| 2638 | + } |
|
| 2639 | + } |
|
| 2640 | + } |
|
| 2641 | + $input_def['possible_value'] = $real_possible_values; |
|
| 2642 | + $input_def['valueToPut'] = 'index'; |
|
| 2643 | + $input_def['value'] = $value; |
|
| 2644 | + |
|
| 2645 | + $input_def['options']['more_input'] = ''; |
|
| 2646 | + if (!empty($possible_values_for_selection_calculation[$attribute_code])) { |
|
| 2647 | + foreach ($possible_values_for_selection_calculation[$attribute_code] as $value_id => $value) { |
|
| 2648 | + $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 . '" />'; |
|
| 2649 | + } |
|
| 2650 | + } |
|
| 2651 | + |
|
| 2652 | + $input_def['options_label']['original'] = true; |
|
| 2653 | + $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) . '" '; |
|
| 2654 | + |
|
| 2655 | + if (!empty($real_possible_values)) { |
|
| 2656 | + $tpl_component = array(); |
|
| 2657 | + $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']; |
|
| 2658 | + $tpl_component['VARIATION_INPUT'] = wpshop_form::check_input_type($input_def, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) . $input_def['options']['more_input']; |
|
| 2659 | + $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)); |
|
| 2660 | + $tpl_component['VARIATION_CODE'] = $attribute_code; |
|
| 2661 | + $tpl_component['VARIATION_LABEL_HELPER'] = !empty($attribute_db_definition->frontend_help_message) ? ' title="' . $attribute_db_definition->frontend_help_message . '" ' : ''; |
|
| 2662 | + $tpl_component['VARIATION_LABEL_CLASS'] = !empty($attribute_db_definition->frontend_help_message) ? ' wpshop_att_variation_helper' : ''; |
|
| 2663 | + $tpl_component['VARIATION_IDENTIFIER'] = $input_def['id']; |
|
| 2664 | + $tpl_component['VARIATION_PARENT_ID'] = $product_id; |
|
| 2665 | + $tpl_component['VARIATION_PARENT_TYPE'] = WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT; |
|
| 2666 | + $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; |
|
| 2667 | + $tpl_component['VARIATION_REQUIRED_INDICATION'] = ($is_required) ? __('Required variation', 'wpshop') : ''; |
|
| 2668 | + $variation_tpl['VARIATION_COMPLETE_OUTPUT_' . strtoupper($attribute_code)] = wpshop_display::display_template_element('product_variation_item', $tpl_component); |
|
| 2669 | + $variation_attribute_ordered[$output_order[$attribute_code]] = $variation_tpl['VARIATION_COMPLETE_OUTPUT_' . strtoupper($attribute_code)]; |
|
| 2670 | + } |
|
| 2671 | + |
|
| 2672 | + $variation_attribute[] = $attribute_code; |
|
| 2673 | + } |
|
| 2674 | + } |
|
| 2675 | + } |
|
| 2786 | 2676 | |
| 2787 | - /** |
|
| 2788 | - * Affichage du résumé du produit sélectionné avec le prix par option / Display a summary of selected product with the price per option |
|
| 2789 | - * |
|
| 2790 | - * @param integer $product_id L'identifiant du produit qui est ajouté au panier / The product identifier added to cart |
|
| 2791 | - * @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 |
|
| 2792 | - * @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 |
|
| 2793 | - * @param string $wpshop_current_for_display Inconnu / Unknown |
|
| 2794 | - * @param integer $product_qty La quantité commandée par le client / Quantity ordered by the customer |
|
| 2795 | - * |
|
| 2796 | - * @return array Le résultat du calcul pour l'affichage / Output result |
|
| 2797 | - */ |
|
| 2798 | - public static function wpshop_ajax_wpshop_variation_selection($product_id, $wpshop_variation_selected, $wpshop_free_variation, $wpshop_current_for_display, $product_qty = 1) |
|
| 2799 | - { |
|
| 2800 | - global $wpdb; |
|
| 2801 | - |
|
| 2802 | - $wpshop_cart = new wps_cart(); |
|
| 2803 | - $wpshop_products = new wpshop_products(); |
|
| 2804 | - |
|
| 2805 | - $response = ''; |
|
| 2806 | - $response_status = $has_variation = false; |
|
| 2807 | - $tpl_component = array(); |
|
| 2808 | - |
|
| 2809 | - // Check if variations exists |
|
| 2810 | - if (!empty($wpshop_variation_selected) || !empty($wpshop_free_variation)) { |
|
| 2811 | - |
|
| 2812 | - //Recover all selected variations |
|
| 2813 | - $variations_selected = array(); |
|
| 2814 | - if (!empty($wpshop_variation_selected)) { |
|
| 2815 | - foreach ($wpshop_variation_selected as $selected_variation) { |
|
| 2816 | - $variation_definition = explode('-_variation_val_-', $selected_variation); |
|
| 2817 | - $variations_selected[$variation_definition[0]] = $variation_definition[1]; |
|
| 2818 | - } |
|
| 2819 | - } |
|
| 2820 | - |
|
| 2821 | - // Check variations priority |
|
| 2822 | - $product_with_variation = wpshop_products::get_variation_by_priority($variations_selected, $product_id); |
|
| 2823 | - |
|
| 2824 | - // Check if $product_with_variation have variations |
|
| 2825 | - if (!empty($product_with_variation[$product_id]['variations']) || !empty($wpshop_free_variation)) { |
|
| 2826 | - |
|
| 2827 | - $formatted_product = $wpshop_cart->prepare_product_to_add_to_cart($product_id, $product_qty, $variations_selected); |
|
| 2828 | - $product_to_add_to_cart = $formatted_product[0]; |
|
| 2829 | - foreach ($formatted_product[0] as $pid => $product_more_content) { |
|
| 2830 | - $order_items[$pid]['product_id'] = $product_more_content['id']; |
|
| 2831 | - |
|
| 2832 | - /** For product with variation */ |
|
| 2833 | - $order_items[$pid]['product_variation_type'] = !empty($product_more_content['variation_priority']) ? $product_more_content['variation_priority'] : ''; |
|
| 2834 | - $order_items[$pid]['free_variation'] = !empty($product_more_content['free_variation']) ? $product_more_content['free_variation'] : ''; |
|
| 2835 | - $order_items[$pid]['product_variation'] = ''; |
|
| 2836 | - if (!empty($product_more_content['variations'])) { |
|
| 2837 | - foreach ($product_more_content['variations'] as $variation_id) { |
|
| 2838 | - $order_items[$pid]['product_variation'][] = $variation_id; |
|
| 2839 | - } |
|
| 2840 | - } |
|
| 2841 | - } |
|
| 2842 | - |
|
| 2843 | - // If Product list is not empty, add products to order |
|
| 2844 | - if (!empty($order_items)) { |
|
| 2845 | - foreach ($order_items as $product_id => $d) { |
|
| 2846 | - $product_key = $product_id; |
|
| 2847 | - |
|
| 2848 | - // Formate datas |
|
| 2849 | - $product_id = $head_product_id = $d['product_id']; |
|
| 2850 | - $product_variation = !empty($d['product_variation']) ? $d['product_variation'] : null; |
|
| 2851 | - |
|
| 2852 | - // If product is a single variation product |
|
| 2853 | - if (!empty($product_variation) && (count($product_variation) == 1)) { |
|
| 2854 | - $product_id = $product_variation[0]; |
|
| 2855 | - } |
|
| 2856 | - |
|
| 2857 | - // Construct final product |
|
| 2858 | - $product = wpshop_products::get_product_data($d['product_id'], true); |
|
| 2859 | - $the_product = array_merge(array('product_id' => $d['product_id'], 'product_qty' => 1), $product); |
|
| 2677 | + } |
|
| 2678 | + $variation_tpl['VARIATION_FORM_ELEMENT_ID'] = $product_id; |
|
| 2679 | + wp_reset_query(); |
|
| 2680 | + |
|
| 2681 | + $attribute_defined_to_be_user_defined = wpshop_attributes::get_attribute_user_defined(array('entity_type_id' => self::currentPageCode)); |
|
| 2682 | + if (!empty($attribute_defined_to_be_user_defined)) { |
|
| 2683 | + foreach ($attribute_defined_to_be_user_defined as $attribute_not_in_variation_but_user_defined) { |
|
| 2684 | + $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; |
|
| 2685 | + |
|
| 2686 | + $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'); |
|
| 2687 | + 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')) { |
|
| 2688 | + $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] : '')); |
|
| 2689 | + |
|
| 2690 | + $tpl_component = array(); |
|
| 2691 | + $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) . '" '; |
|
| 2692 | + $tpl_component['VARIATION_INPUT'] = wpshop_form::check_input_type($attribute_output_def, WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION . '[free]') . $attribute_output_def['options']; |
|
| 2693 | + $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)); |
|
| 2694 | + $tpl_component['VARIATION_CODE'] = $attribute_not_in_variation_but_user_defined->code; |
|
| 2695 | + $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 . '" ' : ''; |
|
| 2696 | + $tpl_component['VARIATION_LABEL_CLASS'] = !empty($attribute_not_in_variation_but_user_defined->frontend_help_message) ? ' wpshop_att_variation_helper' : ''; |
|
| 2697 | + $tpl_component['VARIATION_REQUIRED_INDICATION'] = ($is_required) ? __('Required variation', 'wpshop') : ''; |
|
| 2698 | + $tpl_component['VARIATION_IDENTIFIER'] = $attribute_output_def['id']; |
|
| 2699 | + $tpl_component['VARIATION_PARENT_ID'] = $product_id; |
|
| 2700 | + $tpl_component['VARIATION_PARENT_TYPE'] = WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT; |
|
| 2701 | + $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; |
|
| 2702 | + $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']; |
|
| 2703 | + $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)]; |
|
| 2704 | + } |
|
| 2705 | + } |
|
| 2706 | + } |
|
| 2707 | + $variation_tpl['VARIATION_FORM_VARIATION_LIST'] = ''; |
|
| 2708 | + if (!empty($variation_attribute_ordered) && is_array($variation_attribute_ordered)) { |
|
| 2709 | + ksort($variation_attribute_ordered); |
|
| 2710 | + foreach ($variation_attribute_ordered as $attribute_variation_to_output) { |
|
| 2711 | + $variation_tpl['VARIATION_FORM_VARIATION_LIST'] .= $attribute_variation_to_output; |
|
| 2712 | + } |
|
| 2713 | + } |
|
| 2714 | + $variation_tpl['FROM_ADMIN_INDICATOR'] = $variation_tpl['ORDER_ID_INDICATOR'] = ''; |
|
| 2715 | + $variation_tpl['PRODUCT_ADDED_TO_CART_QTY'] = (!empty($qty)) ? $qty : 1; |
|
| 2716 | + if ($from_admin && !empty($order_id)) { |
|
| 2717 | + $variation_tpl['FROM_ADMIN_INDICATOR'] = '<input type="hidden" name="wps_orders_from_admin" value="1" />'; |
|
| 2718 | + $variation_tpl['ORDER_ID_INDICATOR'] = '<input type="hidden" name="wps_orders_order_id" value="' . $order_id . '" />'; |
|
| 2719 | + } |
|
| 2720 | + $output = !empty($variation_tpl['VARIATION_FORM_VARIATION_LIST']) ? wpshop_display::display_template_element('product_variation_form', $variation_tpl) : ''; |
|
| 2721 | + |
|
| 2722 | + return $output; |
|
| 2723 | + } |
|
| 2724 | + |
|
| 2725 | + public static function get_parent_variation($variation_id) |
|
| 2726 | + { |
|
| 2727 | + $result = array(); |
|
| 2728 | + if (!empty($variation_id)) { |
|
| 2729 | + $variation_post = get_post($variation_id); |
|
| 2730 | + if (!empty($variation_post) && !empty($variation_post->post_parent)) { |
|
| 2731 | + $result['parent_post'] = get_post($variation_post->post_parent); |
|
| 2732 | + $result['parent_post_meta'] = get_post_meta($variation_post->post_parent, '_wpshop_product_metadata', true); |
|
| 2733 | + } |
|
| 2734 | + } |
|
| 2735 | + return $result; |
|
| 2736 | + } |
|
| 2737 | + |
|
| 2738 | + /** |
|
| 2739 | + * Display the current configuration for a given product |
|
| 2740 | + * @param array $shortcode_attribute Some parameters given by the shortcode for display |
|
| 2741 | + */ |
|
| 2742 | + public function wpshop_product_variations_summary($shortcode_attribute) |
|
| 2743 | + { |
|
| 2744 | + $output = ''; |
|
| 2745 | + |
|
| 2746 | + $product_variations_selection_args = array( |
|
| 2747 | + 'CURRENCY_SELECTOR' => wpshop_attributes_unit::wpshop_shop_currency_list_field(), |
|
| 2748 | + 'PRODUCT_VARIATION_SELECTION_DISPLAY' => '', |
|
| 2749 | + ); |
|
| 2750 | + |
|
| 2751 | + $current_user_id = get_current_user_id(); |
|
| 2752 | + |
|
| 2753 | + if (!empty($_SESSION) && !empty($_SESSION['cart']) && !empty($_SESSION['cart']['order_items'])) { |
|
| 2754 | + foreach ($_SESSION['cart']['order_items'] as $item_id => $item) { |
|
| 2755 | + if (!empty($item) && !empty($item['item_id'])) { |
|
| 2756 | + |
|
| 2757 | + $free_variations = array(); |
|
| 2758 | + if (!empty($item['item_meta']) && !empty($item['item_meta']['free_variation'])) { |
|
| 2759 | + foreach ($item['item_meta']['free_variation'] as $attribute_code => $attribute_value) { |
|
| 2760 | + $free_variations[] = $attribute_code . '-_variation_val_-' . $attribute_value; |
|
| 2761 | + } |
|
| 2762 | + } |
|
| 2763 | + |
|
| 2764 | + $variations = array(); |
|
| 2765 | + if (!empty($item['item_meta']) && !empty($item['item_meta']['variations'])) { |
|
| 2766 | + foreach ($item['item_meta']['variations'] as $variation_id => $variation_def) { |
|
| 2767 | + |
|
| 2768 | + if (!empty($variation_def['item_meta']) && !empty($variation_def['item_meta']['variation_definition'])) { |
|
| 2769 | + foreach ($variation_def['item_meta']['variation_definition'] as $attribute_code => $attribute_selected_data) { |
|
| 2770 | + $variations[] = $attribute_code . '-_variation_val_-' . $attribute_selected_data['ID']; |
|
| 2771 | + } |
|
| 2772 | + } |
|
| 2773 | + } |
|
| 2774 | + } |
|
| 2775 | + $product_variation_summary = self::wpshop_ajax_wpshop_variation_selection($item['item_id'], $variations, $free_variations, null, $item['item_qty']); |
|
| 2776 | + |
|
| 2777 | + $product_variations_selection_args['PRODUCT_VARIATION_SELECTION_DISPLAY'] .= $product_variation_summary[1]['product_output']; |
|
| 2778 | + } |
|
| 2779 | + } |
|
| 2780 | + } |
|
| 2781 | + |
|
| 2782 | + $output .= wpshop_display::display_template_element('wpshop_product_configuration_summary', $product_variations_selection_args); |
|
| 2783 | + |
|
| 2784 | + echo $output; |
|
| 2785 | + } |
|
| 2786 | + |
|
| 2787 | + /** |
|
| 2788 | + * Affichage du résumé du produit sélectionné avec le prix par option / Display a summary of selected product with the price per option |
|
| 2789 | + * |
|
| 2790 | + * @param integer $product_id L'identifiant du produit qui est ajouté au panier / The product identifier added to cart |
|
| 2791 | + * @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 |
|
| 2792 | + * @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 |
|
| 2793 | + * @param string $wpshop_current_for_display Inconnu / Unknown |
|
| 2794 | + * @param integer $product_qty La quantité commandée par le client / Quantity ordered by the customer |
|
| 2795 | + * |
|
| 2796 | + * @return array Le résultat du calcul pour l'affichage / Output result |
|
| 2797 | + */ |
|
| 2798 | + public static function wpshop_ajax_wpshop_variation_selection($product_id, $wpshop_variation_selected, $wpshop_free_variation, $wpshop_current_for_display, $product_qty = 1) |
|
| 2799 | + { |
|
| 2800 | + global $wpdb; |
|
| 2801 | + |
|
| 2802 | + $wpshop_cart = new wps_cart(); |
|
| 2803 | + $wpshop_products = new wpshop_products(); |
|
| 2804 | + |
|
| 2805 | + $response = ''; |
|
| 2806 | + $response_status = $has_variation = false; |
|
| 2807 | + $tpl_component = array(); |
|
| 2808 | + |
|
| 2809 | + // Check if variations exists |
|
| 2810 | + if (!empty($wpshop_variation_selected) || !empty($wpshop_free_variation)) { |
|
| 2811 | + |
|
| 2812 | + //Recover all selected variations |
|
| 2813 | + $variations_selected = array(); |
|
| 2814 | + if (!empty($wpshop_variation_selected)) { |
|
| 2815 | + foreach ($wpshop_variation_selected as $selected_variation) { |
|
| 2816 | + $variation_definition = explode('-_variation_val_-', $selected_variation); |
|
| 2817 | + $variations_selected[$variation_definition[0]] = $variation_definition[1]; |
|
| 2818 | + } |
|
| 2819 | + } |
|
| 2820 | + |
|
| 2821 | + // Check variations priority |
|
| 2822 | + $product_with_variation = wpshop_products::get_variation_by_priority($variations_selected, $product_id); |
|
| 2823 | + |
|
| 2824 | + // Check if $product_with_variation have variations |
|
| 2825 | + if (!empty($product_with_variation[$product_id]['variations']) || !empty($wpshop_free_variation)) { |
|
| 2826 | + |
|
| 2827 | + $formatted_product = $wpshop_cart->prepare_product_to_add_to_cart($product_id, $product_qty, $variations_selected); |
|
| 2828 | + $product_to_add_to_cart = $formatted_product[0]; |
|
| 2829 | + foreach ($formatted_product[0] as $pid => $product_more_content) { |
|
| 2830 | + $order_items[$pid]['product_id'] = $product_more_content['id']; |
|
| 2831 | + |
|
| 2832 | + /** For product with variation */ |
|
| 2833 | + $order_items[$pid]['product_variation_type'] = !empty($product_more_content['variation_priority']) ? $product_more_content['variation_priority'] : ''; |
|
| 2834 | + $order_items[$pid]['free_variation'] = !empty($product_more_content['free_variation']) ? $product_more_content['free_variation'] : ''; |
|
| 2835 | + $order_items[$pid]['product_variation'] = ''; |
|
| 2836 | + if (!empty($product_more_content['variations'])) { |
|
| 2837 | + foreach ($product_more_content['variations'] as $variation_id) { |
|
| 2838 | + $order_items[$pid]['product_variation'][] = $variation_id; |
|
| 2839 | + } |
|
| 2840 | + } |
|
| 2841 | + } |
|
| 2842 | + |
|
| 2843 | + // If Product list is not empty, add products to order |
|
| 2844 | + if (!empty($order_items)) { |
|
| 2845 | + foreach ($order_items as $product_id => $d) { |
|
| 2846 | + $product_key = $product_id; |
|
| 2847 | + |
|
| 2848 | + // Formate datas |
|
| 2849 | + $product_id = $head_product_id = $d['product_id']; |
|
| 2850 | + $product_variation = !empty($d['product_variation']) ? $d['product_variation'] : null; |
|
| 2851 | + |
|
| 2852 | + // If product is a single variation product |
|
| 2853 | + if (!empty($product_variation) && (count($product_variation) == 1)) { |
|
| 2854 | + $product_id = $product_variation[0]; |
|
| 2855 | + } |
|
| 2856 | + |
|
| 2857 | + // Construct final product |
|
| 2858 | + $product = wpshop_products::get_product_data($d['product_id'], true); |
|
| 2859 | + $the_product = array_merge(array('product_id' => $d['product_id'], 'product_qty' => 1), $product); |
|
| 2860 | 2860 | $the_product['text_from'] = $product_with_variation['text_from']; |
| 2861 | 2861 | |
| 2862 | - // Add variation to product into cart for storage |
|
| 2863 | - if (!empty($product_variation)) { |
|
| 2864 | - $the_product = wpshop_products::get_variation_price_behaviour($the_product, $product_variation, $head_product_id, array('type' => $d['product_variation_type'])); |
|
| 2865 | - } |
|
| 2866 | - |
|
| 2867 | - // Free Variations Checking |
|
| 2868 | - if (!empty($d['free_variation'])) { |
|
| 2869 | - $the_product['item_meta']['free_variation'] = $d['free_variation']; |
|
| 2870 | - $head_product_id = $the_product['product_id']; |
|
| 2871 | - } |
|
| 2872 | - |
|
| 2873 | - // If product is a variation, we check parent product general |
|
| 2874 | - if (get_post_type($the_product['product_id']) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) { |
|
| 2875 | - $parent_def = wpshop_products::get_parent_variation($the_product['product_id']); |
|
| 2876 | - if (!empty($parent_def) && !empty($parent_def['parent_post'])) { |
|
| 2877 | - $variation_def = get_post_meta($parent_def['parent_post']->ID, '_wpshop_variation_defining', true); |
|
| 2878 | - $parent_meta = $parent_def['parent_post_meta']; |
|
| 2879 | - 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) { |
|
| 2880 | - $the_product['product_price'] += number_format(str_replace(',', '.', $parent_meta['product_price']), 2, '.', ''); |
|
| 2881 | - $the_product['price_ht'] += number_format(str_replace(',', '.', $parent_meta['price_ht']), 2, '.', ''); |
|
| 2882 | - $the_product['tva'] += number_format(str_replace(',', '.', $parent_meta['tva']), 2, '.', ''); |
|
| 2883 | - } |
|
| 2884 | - } |
|
| 2885 | - } |
|
| 2886 | - } |
|
| 2887 | - } |
|
| 2888 | - |
|
| 2889 | - if (!empty($the_product) && empty($the_product['price_ttc_before_discount']) && empty($the_product['price_ht_before_discount'])) { |
|
| 2890 | - $price_infos = wpshop_prices::check_product_price($the_product, true); |
|
| 2891 | - if (!empty($price_infos['discount']['discount_exist'])) { |
|
| 2892 | - $the_product['price_ttc_before_discount'] = $the_product['product_price']; |
|
| 2893 | - $the_product['price_ht_before_discount'] = $the_product['price_ht']; |
|
| 2894 | - } |
|
| 2895 | - $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']; |
|
| 2896 | - $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']; |
|
| 2897 | - $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']; |
|
| 2898 | - } |
|
| 2899 | - |
|
| 2900 | - $product = wpshop_products::get_product_data($product_id, true, '"publish", "draft"'); |
|
| 2901 | - // Add free variations to product |
|
| 2902 | - if (!empty($wpshop_free_variation)) { |
|
| 2903 | - $the_product['item_meta']['free_variation'] = $wpshop_free_variation; |
|
| 2904 | - } |
|
| 2905 | - // Change picture if have a selected variation |
|
| 2906 | - $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; |
|
| 2907 | - $response['wps_product_image'] = $wpshop_products->wps_selected_variation_picture($head_product_id, $the_selected_variation); |
|
| 2908 | - |
|
| 2909 | - // Price Display |
|
| 2910 | - $price_attribute = wpshop_attributes::getElement('product_price', "'valid'", 'code'); |
|
| 2911 | - $price_display = wpshop_attributes::check_attribute_display($price_attribute->is_visible_in_front, $product['custom_display'], 'attribute', 'product_price', 'complete_sheet'); |
|
| 2912 | - $productPrice = ''; |
|
| 2913 | - if ($price_display) { |
|
| 2914 | - $response['product_price_output'] = wpshop_prices::get_product_price($the_product, 'price_display', 'complete_sheet', false, true); |
|
| 2915 | - } |
|
| 2916 | - |
|
| 2917 | - //Get Summary cart |
|
| 2918 | - $response['product_output'] = $wpshop_products->wps_get_summary_variations_product($product_id, $the_product, (!empty($wpshop_variation_selected) || !empty($wpshop_free_variation) ? true : false)); |
|
| 2919 | - $response_status = true; |
|
| 2920 | - } else { |
|
| 2921 | - //Product without variations |
|
| 2922 | - $product_data = wpshop_products::get_product_data($product_id); |
|
| 2923 | - $response['product_price_output'] = wpshop_prices::get_product_price($product_data, 'price_display', 'complete_sheet'); |
|
| 2862 | + // Add variation to product into cart for storage |
|
| 2863 | + if (!empty($product_variation)) { |
|
| 2864 | + $the_product = wpshop_products::get_variation_price_behaviour($the_product, $product_variation, $head_product_id, array('type' => $d['product_variation_type'])); |
|
| 2865 | + } |
|
| 2866 | + |
|
| 2867 | + // Free Variations Checking |
|
| 2868 | + if (!empty($d['free_variation'])) { |
|
| 2869 | + $the_product['item_meta']['free_variation'] = $d['free_variation']; |
|
| 2870 | + $head_product_id = $the_product['product_id']; |
|
| 2871 | + } |
|
| 2872 | + |
|
| 2873 | + // If product is a variation, we check parent product general |
|
| 2874 | + if (get_post_type($the_product['product_id']) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) { |
|
| 2875 | + $parent_def = wpshop_products::get_parent_variation($the_product['product_id']); |
|
| 2876 | + if (!empty($parent_def) && !empty($parent_def['parent_post'])) { |
|
| 2877 | + $variation_def = get_post_meta($parent_def['parent_post']->ID, '_wpshop_variation_defining', true); |
|
| 2878 | + $parent_meta = $parent_def['parent_post_meta']; |
|
| 2879 | + 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) { |
|
| 2880 | + $the_product['product_price'] += number_format(str_replace(',', '.', $parent_meta['product_price']), 2, '.', ''); |
|
| 2881 | + $the_product['price_ht'] += number_format(str_replace(',', '.', $parent_meta['price_ht']), 2, '.', ''); |
|
| 2882 | + $the_product['tva'] += number_format(str_replace(',', '.', $parent_meta['tva']), 2, '.', ''); |
|
| 2883 | + } |
|
| 2884 | + } |
|
| 2885 | + } |
|
| 2886 | + } |
|
| 2887 | + } |
|
| 2888 | + |
|
| 2889 | + if (!empty($the_product) && empty($the_product['price_ttc_before_discount']) && empty($the_product['price_ht_before_discount'])) { |
|
| 2890 | + $price_infos = wpshop_prices::check_product_price($the_product, true); |
|
| 2891 | + if (!empty($price_infos['discount']['discount_exist'])) { |
|
| 2892 | + $the_product['price_ttc_before_discount'] = $the_product['product_price']; |
|
| 2893 | + $the_product['price_ht_before_discount'] = $the_product['price_ht']; |
|
| 2894 | + } |
|
| 2895 | + $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']; |
|
| 2896 | + $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']; |
|
| 2897 | + $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']; |
|
| 2898 | + } |
|
| 2899 | + |
|
| 2900 | + $product = wpshop_products::get_product_data($product_id, true, '"publish", "draft"'); |
|
| 2901 | + // Add free variations to product |
|
| 2902 | + if (!empty($wpshop_free_variation)) { |
|
| 2903 | + $the_product['item_meta']['free_variation'] = $wpshop_free_variation; |
|
| 2904 | + } |
|
| 2905 | + // Change picture if have a selected variation |
|
| 2906 | + $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; |
|
| 2907 | + $response['wps_product_image'] = $wpshop_products->wps_selected_variation_picture($head_product_id, $the_selected_variation); |
|
| 2908 | + |
|
| 2909 | + // Price Display |
|
| 2910 | + $price_attribute = wpshop_attributes::getElement('product_price', "'valid'", 'code'); |
|
| 2911 | + $price_display = wpshop_attributes::check_attribute_display($price_attribute->is_visible_in_front, $product['custom_display'], 'attribute', 'product_price', 'complete_sheet'); |
|
| 2912 | + $productPrice = ''; |
|
| 2913 | + if ($price_display) { |
|
| 2914 | + $response['product_price_output'] = wpshop_prices::get_product_price($the_product, 'price_display', 'complete_sheet', false, true); |
|
| 2915 | + } |
|
| 2916 | + |
|
| 2917 | + //Get Summary cart |
|
| 2918 | + $response['product_output'] = $wpshop_products->wps_get_summary_variations_product($product_id, $the_product, (!empty($wpshop_variation_selected) || !empty($wpshop_free_variation) ? true : false)); |
|
| 2924 | 2919 | $response_status = true; |
| 2925 | - } |
|
| 2926 | - } |
|
| 2920 | + } else { |
|
| 2921 | + //Product without variations |
|
| 2922 | + $product_data = wpshop_products::get_product_data($product_id); |
|
| 2923 | + $response['product_price_output'] = wpshop_prices::get_product_price($product_data, 'price_display', 'complete_sheet'); |
|
| 2924 | + $response_status = true; |
|
| 2925 | + } |
|
| 2926 | + } |
|
| 2927 | 2927 | |
| 2928 | - return array($response_status, $response); |
|
| 2929 | - } |
|
| 2928 | + return array($response_status, $response); |
|
| 2929 | + } |
|
| 2930 | 2930 | |
| 2931 | - /** |
|
| 2932 | - * Display information for a given value of an attribute defined as an entity, when attribute option for detail view is set as true |
|
| 2933 | - * |
|
| 2934 | - * @param array $shortcode_attribute Some parameters given by the shortcode for display |
|
| 2935 | - */ |
|
| 2936 | - public function wpshop_product_variation_value_detail($shortcode_attribute) |
|
| 2937 | - { |
|
| 2938 | - echo wpshop_display::display_template_element('wpshop_product_variation_value_detail_container', array()); |
|
| 2939 | - } |
|
| 2931 | + /** |
|
| 2932 | + * Display information for a given value of an attribute defined as an entity, when attribute option for detail view is set as true |
|
| 2933 | + * |
|
| 2934 | + * @param array $shortcode_attribute Some parameters given by the shortcode for display |
|
| 2935 | + */ |
|
| 2936 | + public function wpshop_product_variation_value_detail($shortcode_attribute) |
|
| 2937 | + { |
|
| 2938 | + echo wpshop_display::display_template_element('wpshop_product_variation_value_detail_container', array()); |
|
| 2939 | + } |
|
| 2940 | 2940 | |
| 2941 | - /** |
|
| 2942 | - * Build the product structure with variation for product choosed by the user into frontend sheet |
|
| 2943 | - * |
|
| 2944 | - * @param array $selected_variation THe list of variation choosed by the user in product frontend sheet |
|
| 2945 | - * @param integer $product_id The basic product choose by the user in frontend |
|
| 2946 | - * |
|
| 2947 | - * @return array The product list for adding to the cart build by variation priority |
|
| 2948 | - */ |
|
| 2949 | - public static function get_variation_by_priority($selected_variation, $product_id, $add_to_cart_action = false) |
|
| 2950 | - { |
|
| 2951 | - global $wpdb; |
|
| 2952 | - $all_required_variations_selected = $no_selected_variation = true; |
|
| 2953 | - $single_variations = $combined_variations = $product_to_add_to_cart = array(); |
|
| 2954 | - |
|
| 2955 | - // Check if all required variations are selected |
|
| 2956 | - $required_attributes_list = wpshop_prices::check_required_attributes($product_id); |
|
| 2957 | - foreach ($selected_variation as $k => $value) { |
|
| 2958 | - if ($value == 0 && in_array($k, $required_attributes_list)) { |
|
| 2959 | - $all_required_variations_selected = false; |
|
| 2960 | - } |
|
| 2961 | - if ($value != 0) { |
|
| 2962 | - $no_selected_variation = false; |
|
| 2963 | - } |
|
| 2964 | - } |
|
| 2965 | - if (!empty($selected_variation)) { |
|
| 2966 | - //Check variations configuration |
|
| 2967 | - $product_variation_configuration = get_post_meta($product_id, '_wpshop_variation_defining', true); |
|
| 2968 | - // Check variations type |
|
| 2969 | - $product_variation_type = (!empty($product_variation_configuration) && !empty($product_variation_configuration['variation_type'])) ? $product_variation_configuration['variation_type'] : 'single'; |
|
| 2970 | - $product_to_add_to_cart[$product_id]['variation_priority'] = $product_variation_type; |
|
| 2971 | - |
|
| 2972 | - //Check defined variation priority |
|
| 2973 | - $priority = (!empty($product_variation_configuration['options']) && !empty($product_variation_configuration['options']['priority'][0])) ? $product_variation_configuration['options']['priority'][0] : 'combined'; |
|
| 2974 | - $product_to_add_to_cart[$product_id]['defined_variation_priority'] = $priority; |
|
| 2975 | - |
|
| 2976 | - // Recover all product variations |
|
| 2977 | - $query_variation = $selected_variation; |
|
| 2978 | - // Delete free variations |
|
| 2979 | - unset($query_variation['free']); |
|
| 2980 | - |
|
| 2981 | - if ($product_variation_type == 'single') { |
|
| 2982 | - // Get single variations |
|
| 2983 | - $single_variations = array(); |
|
| 2984 | - foreach ($selected_variation as $attribute_code => $attribute_value) { |
|
| 2985 | - if (isset($attribute_value) && $attribute_code != 'free') { |
|
| 2986 | - $query = $wpdb->prepare("SELECT ID FROM " . $wpdb->postmeta . " AS P_META INNER JOIN " . $wpdb->posts . " as P ON ((P.ID = P_META.post_id) AND (P.post_parent = %d)) WHERE P_META.meta_value = '" . serialize(array($attribute_code => $attribute_value)) . "' OR P_META.meta_value = '" . serialize(array($attribute_code => (int) $attribute_value)) . "'", $product_id); |
|
| 2987 | - $single_variation_id = $wpdb->get_var($query); |
|
| 2988 | - if (!empty($single_variation_id)) { |
|
| 2989 | - $single_variations[] = $single_variation_id; |
|
| 2990 | - unset($query_variation[$attribute_code]); |
|
| 2991 | - } |
|
| 2992 | - } |
|
| 2993 | - } |
|
| 2994 | - } else { |
|
| 2995 | - // Get combined variations |
|
| 2996 | - $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); |
|
| 2997 | - $combined_variation_id = $wpdb->get_var($query); |
|
| 2998 | - if (!empty($combined_variation_id)) { |
|
| 2999 | - $combined_variations[] = $combined_variation_id; |
|
| 3000 | - } |
|
| 3001 | - |
|
| 3002 | - } |
|
| 3003 | - |
|
| 3004 | - //If all required variations are not selected |
|
| 3005 | - if (!$all_required_variations_selected || $no_selected_variation) { |
|
| 3006 | - $product_to_add_to_cart['text_from'] = 'on'; |
|
| 3007 | - // If we choose to display lower price variation combinaison |
|
| 3008 | - 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']))) { |
|
| 3009 | - //Get lower price variation combinaison |
|
| 3010 | - $lower_price_variations = wpshop_prices::check_product_lower_price($product_id); |
|
| 3011 | - if (!empty($lower_price_variations['variations']) && is_array($lower_price_variations['variations'])) { |
|
| 3012 | - foreach ($lower_price_variations['variations'] as $lower_price_variation) { |
|
| 3013 | - $product_to_add_to_cart[$product_id]['variations'][] = $lower_price_variation; |
|
| 3014 | - } |
|
| 3015 | - } |
|
| 3016 | - $product_to_add_to_cart['display_lower_price'] = true; |
|
| 3017 | - } else { |
|
| 3018 | - $product_to_add_to_cart[$product_id]['variations'] = array(); |
|
| 3019 | - } |
|
| 3020 | - } else { |
|
| 3021 | - $product_to_add_to_cart['text_from'] = ''; |
|
| 3022 | - $product_to_add_to_cart[$product_id]['variations'] = (!empty($product_variation_type) && $product_variation_type == 'single') ? $single_variations : $combined_variations; |
|
| 3023 | - } |
|
| 3024 | - } |
|
| 2941 | + /** |
|
| 2942 | + * Build the product structure with variation for product choosed by the user into frontend sheet |
|
| 2943 | + * |
|
| 2944 | + * @param array $selected_variation THe list of variation choosed by the user in product frontend sheet |
|
| 2945 | + * @param integer $product_id The basic product choose by the user in frontend |
|
| 2946 | + * |
|
| 2947 | + * @return array The product list for adding to the cart build by variation priority |
|
| 2948 | + */ |
|
| 2949 | + public static function get_variation_by_priority($selected_variation, $product_id, $add_to_cart_action = false) |
|
| 2950 | + { |
|
| 2951 | + global $wpdb; |
|
| 2952 | + $all_required_variations_selected = $no_selected_variation = true; |
|
| 2953 | + $single_variations = $combined_variations = $product_to_add_to_cart = array(); |
|
| 2954 | + |
|
| 2955 | + // Check if all required variations are selected |
|
| 2956 | + $required_attributes_list = wpshop_prices::check_required_attributes($product_id); |
|
| 2957 | + foreach ($selected_variation as $k => $value) { |
|
| 2958 | + if ($value == 0 && in_array($k, $required_attributes_list)) { |
|
| 2959 | + $all_required_variations_selected = false; |
|
| 2960 | + } |
|
| 2961 | + if ($value != 0) { |
|
| 2962 | + $no_selected_variation = false; |
|
| 2963 | + } |
|
| 2964 | + } |
|
| 2965 | + if (!empty($selected_variation)) { |
|
| 2966 | + //Check variations configuration |
|
| 2967 | + $product_variation_configuration = get_post_meta($product_id, '_wpshop_variation_defining', true); |
|
| 2968 | + // Check variations type |
|
| 2969 | + $product_variation_type = (!empty($product_variation_configuration) && !empty($product_variation_configuration['variation_type'])) ? $product_variation_configuration['variation_type'] : 'single'; |
|
| 2970 | + $product_to_add_to_cart[$product_id]['variation_priority'] = $product_variation_type; |
|
| 2971 | + |
|
| 2972 | + //Check defined variation priority |
|
| 2973 | + $priority = (!empty($product_variation_configuration['options']) && !empty($product_variation_configuration['options']['priority'][0])) ? $product_variation_configuration['options']['priority'][0] : 'combined'; |
|
| 2974 | + $product_to_add_to_cart[$product_id]['defined_variation_priority'] = $priority; |
|
| 2975 | + |
|
| 2976 | + // Recover all product variations |
|
| 2977 | + $query_variation = $selected_variation; |
|
| 2978 | + // Delete free variations |
|
| 2979 | + unset($query_variation['free']); |
|
| 2980 | + |
|
| 2981 | + if ($product_variation_type == 'single') { |
|
| 2982 | + // Get single variations |
|
| 2983 | + $single_variations = array(); |
|
| 2984 | + foreach ($selected_variation as $attribute_code => $attribute_value) { |
|
| 2985 | + if (isset($attribute_value) && $attribute_code != 'free') { |
|
| 2986 | + $query = $wpdb->prepare("SELECT ID FROM " . $wpdb->postmeta . " AS P_META INNER JOIN " . $wpdb->posts . " as P ON ((P.ID = P_META.post_id) AND (P.post_parent = %d)) WHERE P_META.meta_value = '" . serialize(array($attribute_code => $attribute_value)) . "' OR P_META.meta_value = '" . serialize(array($attribute_code => (int) $attribute_value)) . "'", $product_id); |
|
| 2987 | + $single_variation_id = $wpdb->get_var($query); |
|
| 2988 | + if (!empty($single_variation_id)) { |
|
| 2989 | + $single_variations[] = $single_variation_id; |
|
| 2990 | + unset($query_variation[$attribute_code]); |
|
| 2991 | + } |
|
| 2992 | + } |
|
| 2993 | + } |
|
| 2994 | + } else { |
|
| 2995 | + // Get combined variations |
|
| 2996 | + $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); |
|
| 2997 | + $combined_variation_id = $wpdb->get_var($query); |
|
| 2998 | + if (!empty($combined_variation_id)) { |
|
| 2999 | + $combined_variations[] = $combined_variation_id; |
|
| 3000 | + } |
|
| 3025 | 3001 | |
| 3026 | - return $product_to_add_to_cart; |
|
| 3027 | - } |
|
| 3002 | + } |
|
| 3028 | 3003 | |
| 3029 | - public static function get_variation_price_behaviour($product_into_cart, $product_variations, $head_product_id, $variations_options) |
|
| 3030 | - { |
|
| 3031 | - global $wpdb; |
|
| 3032 | - |
|
| 3033 | - if (!empty($product_variations)) { |
|
| 3034 | - // Initialize variations total price datas |
|
| 3035 | - $variations_total_price = array('price_et' => 0, 'vat_amount' => 0, 'price_ati' => 0); |
|
| 3036 | - $variations_discount_total_price = array('price_et' => 0, 'vat_amount' => 0, 'price_ati' => 0); |
|
| 3037 | - $vat_rate = 0; |
|
| 3038 | - $discount_amount = $discount_rate = $special_price = 0; |
|
| 3039 | - // Recover Head product metadata |
|
| 3040 | - $head_product_metadata = get_post_meta($head_product_id, '_wpshop_product_metadata', true); |
|
| 3041 | - $tva_rate_id = (!empty($head_product_metadata['tx_tva'])) ? $head_product_metadata['tx_tva'] : 0; |
|
| 3042 | - if (!empty($tva_rate_id)) { |
|
| 3043 | - // Recover VAT Rate of product |
|
| 3044 | - $query = $wpdb->prepare('SELECT value FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id = %d', $tva_rate_id); |
|
| 3045 | - $vat_rate = $wpdb->get_var($query); |
|
| 3046 | - } |
|
| 3047 | - $price_piloting = get_option('wpshop_shop_price_piloting'); |
|
| 3048 | - foreach ($product_variations as $product_variation) { |
|
| 3049 | - $variation_metadata['product_price'] = 0; |
|
| 3050 | - $variation_metadata = get_post_meta($product_variation, '_wpshop_product_metadata', true); |
|
| 3051 | - if (!empty($variation_metadata)) { |
|
| 3052 | - $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']); |
|
| 3053 | - $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)))); |
|
| 3054 | - |
|
| 3055 | - $variations_total_price['price_et'] += $p_et; |
|
| 3056 | - $variations_total_price['price_ati'] += $p_ati; |
|
| 3057 | - $variations_total_price['vat_amount'] += $p_ati - $p_et; |
|
| 3058 | - |
|
| 3059 | - $variation_metadata['tx_tva'] = $product_into_cart['tx_tva'] = $vat_rate; |
|
| 3060 | - |
|
| 3061 | - // Check discount |
|
| 3062 | - $discount_config = wpshop_prices::check_discount_for_product($product_variation); |
|
| 3063 | - if (!empty($discount_config) && !empty($discount_config['value'])) { |
|
| 3064 | - $variation_discount_prices = wpshop_prices::calcul_discounted_price($variation_metadata, $discount_config); |
|
| 3065 | - $variations_discount_total_price['price_et'] += $variation_discount_prices['price_ht']; |
|
| 3066 | - $variations_discount_total_price['price_ati'] += $variation_discount_prices['product_price']; |
|
| 3067 | - $variations_discount_total_price['vat_amount'] += $variation_discount_prices['tva']; |
|
| 3068 | - |
|
| 3069 | - if (!empty($discount_config['type']) && $discount_config['type'] == 'discount_amount') { |
|
| 3070 | - $product_into_cart['discount_amount'] = $discount_amount + $product_into_cart['discount_amount']; |
|
| 3071 | - } elseif (!empty($discount_config['type']) && $discount_config['type'] == 'discount_rate') { |
|
| 3072 | - $product_into_cart['discount_rate'] = $discount_rate + $discount_config['value']; |
|
| 3073 | - } elseif (!empty($discount_config['type']) && $discount_config['type'] == 'special_price') { |
|
| 3074 | - $product_into_cart['special_price'] = $special_price + $discount_config['value']; |
|
| 3075 | - } |
|
| 3076 | - } |
|
| 3077 | - |
|
| 3078 | - $product_variation_def = wpshop_products::get_product_data($product_variation, true, '"publish", "draft"'); |
|
| 3079 | - $product_into_cart['item_meta']['variations'][$product_variation] = $product_variation_def; |
|
| 3080 | - } |
|
| 3081 | - } |
|
| 3082 | - |
|
| 3083 | - // Check if add or replace variation price to head product |
|
| 3084 | - /** |
|
| 3085 | - * Since 1.4.3.7 |
|
| 3086 | - * L'option du produit remplace le prix du produit de tête. |
|
| 3087 | - */ |
|
| 3004 | + //If all required variations are not selected |
|
| 3005 | + if (!$all_required_variations_selected || $no_selected_variation) { |
|
| 3006 | + $product_to_add_to_cart['text_from'] = 'on'; |
|
| 3007 | + // If we choose to display lower price variation combinaison |
|
| 3008 | + 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']))) { |
|
| 3009 | + //Get lower price variation combinaison |
|
| 3010 | + $lower_price_variations = wpshop_prices::check_product_lower_price($product_id); |
|
| 3011 | + if (!empty($lower_price_variations['variations']) && is_array($lower_price_variations['variations'])) { |
|
| 3012 | + foreach ($lower_price_variations['variations'] as $lower_price_variation) { |
|
| 3013 | + $product_to_add_to_cart[$product_id]['variations'][] = $lower_price_variation; |
|
| 3014 | + } |
|
| 3015 | + } |
|
| 3016 | + $product_to_add_to_cart['display_lower_price'] = true; |
|
| 3017 | + } else { |
|
| 3018 | + $product_to_add_to_cart[$product_id]['variations'] = array(); |
|
| 3019 | + } |
|
| 3020 | + } else { |
|
| 3021 | + $product_to_add_to_cart['text_from'] = ''; |
|
| 3022 | + $product_to_add_to_cart[$product_id]['variations'] = (!empty($product_variation_type) && $product_variation_type == 'single') ? $single_variations : $combined_variations; |
|
| 3023 | + } |
|
| 3024 | + } |
|
| 3025 | + |
|
| 3026 | + return $product_to_add_to_cart; |
|
| 3027 | + } |
|
| 3028 | + |
|
| 3029 | + public static function get_variation_price_behaviour($product_into_cart, $product_variations, $head_product_id, $variations_options) |
|
| 3030 | + { |
|
| 3031 | + global $wpdb; |
|
| 3032 | + |
|
| 3033 | + if (!empty($product_variations)) { |
|
| 3034 | + // Initialize variations total price datas |
|
| 3035 | + $variations_total_price = array('price_et' => 0, 'vat_amount' => 0, 'price_ati' => 0); |
|
| 3036 | + $variations_discount_total_price = array('price_et' => 0, 'vat_amount' => 0, 'price_ati' => 0); |
|
| 3037 | + $vat_rate = 0; |
|
| 3038 | + $discount_amount = $discount_rate = $special_price = 0; |
|
| 3039 | + // Recover Head product metadata |
|
| 3040 | + $head_product_metadata = get_post_meta($head_product_id, '_wpshop_product_metadata', true); |
|
| 3041 | + $tva_rate_id = (!empty($head_product_metadata['tx_tva'])) ? $head_product_metadata['tx_tva'] : 0; |
|
| 3042 | + if (!empty($tva_rate_id)) { |
|
| 3043 | + // Recover VAT Rate of product |
|
| 3044 | + $query = $wpdb->prepare('SELECT value FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE id = %d', $tva_rate_id); |
|
| 3045 | + $vat_rate = $wpdb->get_var($query); |
|
| 3046 | + } |
|
| 3047 | + $price_piloting = get_option('wpshop_shop_price_piloting'); |
|
| 3048 | + foreach ($product_variations as $product_variation) { |
|
| 3049 | + $variation_metadata['product_price'] = 0; |
|
| 3050 | + $variation_metadata = get_post_meta($product_variation, '_wpshop_product_metadata', true); |
|
| 3051 | + if (!empty($variation_metadata)) { |
|
| 3052 | + $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']); |
|
| 3053 | + $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)))); |
|
| 3054 | + |
|
| 3055 | + $variations_total_price['price_et'] += $p_et; |
|
| 3056 | + $variations_total_price['price_ati'] += $p_ati; |
|
| 3057 | + $variations_total_price['vat_amount'] += $p_ati - $p_et; |
|
| 3058 | + |
|
| 3059 | + $variation_metadata['tx_tva'] = $product_into_cart['tx_tva'] = $vat_rate; |
|
| 3060 | + |
|
| 3061 | + // Check discount |
|
| 3062 | + $discount_config = wpshop_prices::check_discount_for_product($product_variation); |
|
| 3063 | + if (!empty($discount_config) && !empty($discount_config['value'])) { |
|
| 3064 | + $variation_discount_prices = wpshop_prices::calcul_discounted_price($variation_metadata, $discount_config); |
|
| 3065 | + $variations_discount_total_price['price_et'] += $variation_discount_prices['price_ht']; |
|
| 3066 | + $variations_discount_total_price['price_ati'] += $variation_discount_prices['product_price']; |
|
| 3067 | + $variations_discount_total_price['vat_amount'] += $variation_discount_prices['tva']; |
|
| 3068 | + |
|
| 3069 | + if (!empty($discount_config['type']) && $discount_config['type'] == 'discount_amount') { |
|
| 3070 | + $product_into_cart['discount_amount'] = $discount_amount + $product_into_cart['discount_amount']; |
|
| 3071 | + } elseif (!empty($discount_config['type']) && $discount_config['type'] == 'discount_rate') { |
|
| 3072 | + $product_into_cart['discount_rate'] = $discount_rate + $discount_config['value']; |
|
| 3073 | + } elseif (!empty($discount_config['type']) && $discount_config['type'] == 'special_price') { |
|
| 3074 | + $product_into_cart['special_price'] = $special_price + $discount_config['value']; |
|
| 3075 | + } |
|
| 3076 | + } |
|
| 3077 | + |
|
| 3078 | + $product_variation_def = wpshop_products::get_product_data($product_variation, true, '"publish", "draft"'); |
|
| 3079 | + $product_into_cart['item_meta']['variations'][$product_variation] = $product_variation_def; |
|
| 3080 | + } |
|
| 3081 | + } |
|
| 3082 | + |
|
| 3083 | + // Check if add or replace variation price to head product |
|
| 3084 | + /** |
|
| 3085 | + * Since 1.4.3.7 |
|
| 3086 | + * L'option du produit remplace le prix du produit de tête. |
|
| 3087 | + */ |
|
| 3088 | 3088 | if( true ) { |
| 3089 | - //Replace the product price |
|
| 3090 | - if (!empty($variations_discount_total_price) && !empty($variations_discount_total_price['price_ati'])) { |
|
| 3091 | - $product_into_cart['price_ttc_before_discount'] = $variations_total_price['price_ati']; |
|
| 3092 | - $product_into_cart['price_ht_before_discount'] = $variations_total_price['price_et']; |
|
| 3093 | - |
|
| 3094 | - $product_into_cart['product_price'] = $variations_discount_total_price['price_ati']; |
|
| 3095 | - $product_into_cart['price_ht'] = $variations_discount_total_price['price_et']; |
|
| 3096 | - $product_into_cart['tva'] = $variations_discount_total_price['vat_amount']; |
|
| 3097 | - } else { |
|
| 3098 | - $product_into_cart['product_price'] = $variations_total_price['price_ati']; |
|
| 3099 | - $product_into_cart['price_ht'] = $variations_total_price['price_et']; |
|
| 3100 | - $product_into_cart['tva'] = $variations_total_price['vat_amount']; |
|
| 3101 | - } |
|
| 3102 | - } else { |
|
| 3103 | - // Add variations price to product price |
|
| 3104 | - if (!empty($variations_discount_total_price) && !empty($variations_discount_total_price['price_ati'])) { |
|
| 3105 | - $product_into_cart['price_ttc_before_discount'] = ($product_into_cart['product_price'] + $variations_total_price['price_ati']); |
|
| 3106 | - $product_into_cart['price_ht_before_discount'] = ($product_into_cart['price_ht'] + $variations_total_price['price_et']); |
|
| 3107 | - |
|
| 3108 | - $product_into_cart['product_price'] += $variations_discount_total_price['price_ati']; |
|
| 3109 | - $product_into_cart['price_ht'] += $variations_discount_total_price['price_et']; |
|
| 3110 | - $product_into_cart['tva'] += $variations_discount_total_price['vat_amount']; |
|
| 3111 | - } else { |
|
| 3112 | - $product_into_cart['product_price'] += $variations_total_price['price_ati']; |
|
| 3113 | - $product_into_cart['price_ht'] += $variations_total_price['price_et']; |
|
| 3114 | - $product_into_cart['tva'] += $variations_total_price['vat_amount']; |
|
| 3115 | - } |
|
| 3116 | - // Check parent discount |
|
| 3117 | - $parent_discount_config = wpshop_prices::check_discount_for_product($head_product_id); |
|
| 3118 | - if (!empty($parent_discount_config)) { |
|
| 3119 | - $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']; |
|
| 3120 | - $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']; |
|
| 3121 | - $product_into_cart = wpshop_prices::calcul_discounted_price($product_into_cart, $parent_discount_config); |
|
| 3122 | - |
|
| 3123 | - if (!empty($parent_discount_config['type']) && $parent_discount_config['type'] == 'discount_amount') { |
|
| 3124 | - $product_into_cart['discount_amount'] = $discount_amount + $parent_discount_config['value']; |
|
| 3125 | - } elseif (!empty($parent_discount_config['type']) && $parent_discount_config['type'] == 'discount_rate') { |
|
| 3126 | - $product_into_cart['discount_rate'] = $discount_rate + $parent_discount_config['value']; |
|
| 3127 | - } elseif (!empty($parent_discount_config['type']) && $parent_discount_config['type'] == 'special_price') { |
|
| 3128 | - $product_into_cart['special_price'] = $special_price + $parent_discount_config['value']; |
|
| 3129 | - } |
|
| 3130 | - } |
|
| 3131 | - } |
|
| 3132 | - } else { |
|
| 3133 | - // If product have just Free variations |
|
| 3134 | - $discount_config = wpshop_prices::check_discount_for_product($head_product_id); |
|
| 3135 | - if (!empty($discount_config)) { |
|
| 3136 | - $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']; |
|
| 3137 | - $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']; |
|
| 3138 | - $product_into_cart = wpshop_prices::calcul_discounted_price($product_into_cart, $discount_config); |
|
| 3139 | - } |
|
| 3140 | - } |
|
| 3089 | + //Replace the product price |
|
| 3090 | + if (!empty($variations_discount_total_price) && !empty($variations_discount_total_price['price_ati'])) { |
|
| 3091 | + $product_into_cart['price_ttc_before_discount'] = $variations_total_price['price_ati']; |
|
| 3092 | + $product_into_cart['price_ht_before_discount'] = $variations_total_price['price_et']; |
|
| 3093 | + |
|
| 3094 | + $product_into_cart['product_price'] = $variations_discount_total_price['price_ati']; |
|
| 3095 | + $product_into_cart['price_ht'] = $variations_discount_total_price['price_et']; |
|
| 3096 | + $product_into_cart['tva'] = $variations_discount_total_price['vat_amount']; |
|
| 3097 | + } else { |
|
| 3098 | + $product_into_cart['product_price'] = $variations_total_price['price_ati']; |
|
| 3099 | + $product_into_cart['price_ht'] = $variations_total_price['price_et']; |
|
| 3100 | + $product_into_cart['tva'] = $variations_total_price['vat_amount']; |
|
| 3101 | + } |
|
| 3102 | + } else { |
|
| 3103 | + // Add variations price to product price |
|
| 3104 | + if (!empty($variations_discount_total_price) && !empty($variations_discount_total_price['price_ati'])) { |
|
| 3105 | + $product_into_cart['price_ttc_before_discount'] = ($product_into_cart['product_price'] + $variations_total_price['price_ati']); |
|
| 3106 | + $product_into_cart['price_ht_before_discount'] = ($product_into_cart['price_ht'] + $variations_total_price['price_et']); |
|
| 3107 | + |
|
| 3108 | + $product_into_cart['product_price'] += $variations_discount_total_price['price_ati']; |
|
| 3109 | + $product_into_cart['price_ht'] += $variations_discount_total_price['price_et']; |
|
| 3110 | + $product_into_cart['tva'] += $variations_discount_total_price['vat_amount']; |
|
| 3111 | + } else { |
|
| 3112 | + $product_into_cart['product_price'] += $variations_total_price['price_ati']; |
|
| 3113 | + $product_into_cart['price_ht'] += $variations_total_price['price_et']; |
|
| 3114 | + $product_into_cart['tva'] += $variations_total_price['vat_amount']; |
|
| 3115 | + } |
|
| 3116 | + // Check parent discount |
|
| 3117 | + $parent_discount_config = wpshop_prices::check_discount_for_product($head_product_id); |
|
| 3118 | + if (!empty($parent_discount_config)) { |
|
| 3119 | + $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']; |
|
| 3120 | + $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']; |
|
| 3121 | + $product_into_cart = wpshop_prices::calcul_discounted_price($product_into_cart, $parent_discount_config); |
|
| 3122 | + |
|
| 3123 | + if (!empty($parent_discount_config['type']) && $parent_discount_config['type'] == 'discount_amount') { |
|
| 3124 | + $product_into_cart['discount_amount'] = $discount_amount + $parent_discount_config['value']; |
|
| 3125 | + } elseif (!empty($parent_discount_config['type']) && $parent_discount_config['type'] == 'discount_rate') { |
|
| 3126 | + $product_into_cart['discount_rate'] = $discount_rate + $parent_discount_config['value']; |
|
| 3127 | + } elseif (!empty($parent_discount_config['type']) && $parent_discount_config['type'] == 'special_price') { |
|
| 3128 | + $product_into_cart['special_price'] = $special_price + $parent_discount_config['value']; |
|
| 3129 | + } |
|
| 3130 | + } |
|
| 3131 | + } |
|
| 3132 | + } else { |
|
| 3133 | + // If product have just Free variations |
|
| 3134 | + $discount_config = wpshop_prices::check_discount_for_product($head_product_id); |
|
| 3135 | + if (!empty($discount_config)) { |
|
| 3136 | + $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']; |
|
| 3137 | + $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']; |
|
| 3138 | + $product_into_cart = wpshop_prices::calcul_discounted_price($product_into_cart, $discount_config); |
|
| 3139 | + } |
|
| 3140 | + } |
|
| 3141 | 3141 | |
| 3142 | - // Text From indicator |
|
| 3143 | - if (!empty($variations_options) && !empty($variations_options['text_from'])) { |
|
| 3144 | - $product_into_cart['text_from'] = $variations_options['text_from']; |
|
| 3145 | - } |
|
| 3146 | - return $product_into_cart; |
|
| 3147 | - } |
|
| 3142 | + // Text From indicator |
|
| 3143 | + if (!empty($variations_options) && !empty($variations_options['text_from'])) { |
|
| 3144 | + $product_into_cart['text_from'] = $variations_options['text_from']; |
|
| 3145 | + } |
|
| 3146 | + return $product_into_cart; |
|
| 3147 | + } |
|
| 3148 | 3148 | |
| 3149 | - /** |
|
| 3150 | - * Read an array with product options chosen by the customer, order into an array regarding admin definition |
|
| 3151 | - * |
|
| 3152 | - * @param array $product_definition_value The array with the selected product option to ordered |
|
| 3153 | - * @param array $output_order The good order for attribute defined by administrator |
|
| 3154 | - * @param dtring $from_page A string allowing to take a specific template regarding the current page |
|
| 3155 | - * |
|
| 3156 | - * @return array The array containing all product options ordered as the admin configure it |
|
| 3157 | - */ |
|
| 3158 | - public static function get_selected_variation_display($product_definition_value, $output_order, $from_page = null, $template_part = 'wpshop', $output_type = null) |
|
| 3159 | - { |
|
| 3160 | - $variation_attribute_ordered = array(); |
|
| 3161 | - $variation_attribute_ordered['prices'] = array(); |
|
| 3162 | - $variation_attribute_ordered['attribute_list'] = array(); |
|
| 3163 | - |
|
| 3164 | - if (!empty($product_definition_value['variation_definition']) && is_array($product_definition_value['variation_definition'])) { |
|
| 3165 | - foreach ($product_definition_value['variation_definition'] as $variation_attribute_code => $variation_attribute_detail) { |
|
| 3166 | - $variation_tpl_component = array(); |
|
| 3167 | - foreach ($variation_attribute_detail as $info_name => $info_value) { |
|
| 3168 | - $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); |
|
| 3169 | - } |
|
| 3170 | - $variation_tpl_component['VARIATION_ID'] = $variation_attribute_code; |
|
| 3171 | - $variation_tpl_component['VARIATION_ATT_CODE'] = $variation_attribute_code; |
|
| 3172 | - if (!empty($output_order[$variation_attribute_code])) { |
|
| 3173 | - $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); |
|
| 3174 | - if (!in_array($display_data, $variation_attribute_ordered['attribute_list'])) { |
|
| 3175 | - $variation_attribute_ordered['attribute_list'][$output_order[$variation_attribute_code]] = $display_data; |
|
| 3176 | - } |
|
| 3177 | - } else { |
|
| 3178 | - $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); |
|
| 3179 | - if (!in_array($display_data, $variation_attribute_ordered['attribute_list'])) { |
|
| 3180 | - $variation_attribute_ordered['attribute_list'][] = $display_data; |
|
| 3181 | - } |
|
| 3182 | - } |
|
| 3183 | - unset($variation_tpl_component); |
|
| 3184 | - } |
|
| 3185 | - } |
|
| 3149 | + /** |
|
| 3150 | + * Read an array with product options chosen by the customer, order into an array regarding admin definition |
|
| 3151 | + * |
|
| 3152 | + * @param array $product_definition_value The array with the selected product option to ordered |
|
| 3153 | + * @param array $output_order The good order for attribute defined by administrator |
|
| 3154 | + * @param dtring $from_page A string allowing to take a specific template regarding the current page |
|
| 3155 | + * |
|
| 3156 | + * @return array The array containing all product options ordered as the admin configure it |
|
| 3157 | + */ |
|
| 3158 | + public static function get_selected_variation_display($product_definition_value, $output_order, $from_page = null, $template_part = 'wpshop', $output_type = null) |
|
| 3159 | + { |
|
| 3160 | + $variation_attribute_ordered = array(); |
|
| 3161 | + $variation_attribute_ordered['prices'] = array(); |
|
| 3162 | + $variation_attribute_ordered['attribute_list'] = array(); |
|
| 3163 | + |
|
| 3164 | + if (!empty($product_definition_value['variation_definition']) && is_array($product_definition_value['variation_definition'])) { |
|
| 3165 | + foreach ($product_definition_value['variation_definition'] as $variation_attribute_code => $variation_attribute_detail) { |
|
| 3166 | + $variation_tpl_component = array(); |
|
| 3167 | + foreach ($variation_attribute_detail as $info_name => $info_value) { |
|
| 3168 | + $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); |
|
| 3169 | + } |
|
| 3170 | + $variation_tpl_component['VARIATION_ID'] = $variation_attribute_code; |
|
| 3171 | + $variation_tpl_component['VARIATION_ATT_CODE'] = $variation_attribute_code; |
|
| 3172 | + if (!empty($output_order[$variation_attribute_code])) { |
|
| 3173 | + $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); |
|
| 3174 | + if (!in_array($display_data, $variation_attribute_ordered['attribute_list'])) { |
|
| 3175 | + $variation_attribute_ordered['attribute_list'][$output_order[$variation_attribute_code]] = $display_data; |
|
| 3176 | + } |
|
| 3177 | + } else { |
|
| 3178 | + $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); |
|
| 3179 | + if (!in_array($display_data, $variation_attribute_ordered['attribute_list'])) { |
|
| 3180 | + $variation_attribute_ordered['attribute_list'][] = $display_data; |
|
| 3181 | + } |
|
| 3182 | + } |
|
| 3183 | + unset($variation_tpl_component); |
|
| 3184 | + } |
|
| 3185 | + } |
|
| 3186 | 3186 | |
| 3187 | - if (!empty($product_definition_value['variations']) && is_array($product_definition_value['variations'])) { |
|
| 3188 | - foreach ($product_definition_value['variations'] as $variation_id => $variation_details) { |
|
| 3189 | - $variation_tpl_component = array(); |
|
| 3190 | - foreach ($variation_details as $info_name => $info_value) { |
|
| 3191 | - if ($info_name != 'item_meta') { |
|
| 3192 | - $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); |
|
| 3193 | - } |
|
| 3194 | - } |
|
| 3195 | - foreach ($variation_details['item_meta']['variation_definition'] as $variation_attribute_code => $variation_attribute_def) { |
|
| 3196 | - $variation_tpl_component['VARIATION_NAME'] = stripslashes($variation_attribute_def['NAME']); |
|
| 3197 | - $variation_tpl_component['VARIATION_VALUE'] = stripslashes($variation_attribute_def['VALUE']); |
|
| 3198 | - $variation_tpl_component['VARIATION_ID'] = $variation_id; |
|
| 3199 | - $variation_tpl_component['VARIATION_ATT_CODE'] = $variation_attribute_code; |
|
| 3200 | - |
|
| 3201 | - $variation_attribute_ordered['prices'][$variation_attribute_code] = $variation_tpl_component['VARIATION_DETAIL_PRODUCT_PRICE']; |
|
| 3202 | - } |
|
| 3203 | - if (!empty($output_order[$variation_attribute_code])) { |
|
| 3204 | - $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); |
|
| 3205 | - } |
|
| 3206 | - unset($variation_tpl_component); |
|
| 3207 | - } |
|
| 3208 | - } |
|
| 3187 | + if (!empty($product_definition_value['variations']) && is_array($product_definition_value['variations'])) { |
|
| 3188 | + foreach ($product_definition_value['variations'] as $variation_id => $variation_details) { |
|
| 3189 | + $variation_tpl_component = array(); |
|
| 3190 | + foreach ($variation_details as $info_name => $info_value) { |
|
| 3191 | + if ($info_name != 'item_meta') { |
|
| 3192 | + $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); |
|
| 3193 | + } |
|
| 3194 | + } |
|
| 3195 | + foreach ($variation_details['item_meta']['variation_definition'] as $variation_attribute_code => $variation_attribute_def) { |
|
| 3196 | + $variation_tpl_component['VARIATION_NAME'] = stripslashes($variation_attribute_def['NAME']); |
|
| 3197 | + $variation_tpl_component['VARIATION_VALUE'] = stripslashes($variation_attribute_def['VALUE']); |
|
| 3198 | + $variation_tpl_component['VARIATION_ID'] = $variation_id; |
|
| 3199 | + $variation_tpl_component['VARIATION_ATT_CODE'] = $variation_attribute_code; |
|
| 3209 | 3200 | |
| 3210 | - /** Free Variation part */ |
|
| 3211 | - if (!empty($product_definition_value['free_variation']) && is_array($product_definition_value['free_variation'])) { |
|
| 3212 | - foreach ($product_definition_value['free_variation'] as $build_variation_key => $build_variation) { |
|
| 3213 | - if (strpos($build_variation, '-_variation_val_-')) { |
|
| 3214 | - $variation_definition = explode('-_variation_val_-', $build_variation); |
|
| 3215 | - $attribute_code = $variation_definition[0]; |
|
| 3216 | - $attribute_selected_value = $variation_definition[1]; |
|
| 3217 | - } else { |
|
| 3218 | - $attribute_code = $build_variation_key; |
|
| 3219 | - $attribute_selected_value = $build_variation; |
|
| 3220 | - } |
|
| 3221 | - |
|
| 3222 | - $free_variation_attribute_def = wpshop_attributes::getElement($attribute_code, "'valid'", 'code'); |
|
| 3223 | - $variation_tpl_component['VARIATION_NAME'] = stripslashes($free_variation_attribute_def->frontend_label); |
|
| 3224 | - $value_to_outut = $attribute_selected_value; |
|
| 3225 | - switch ($free_variation_attribute_def->data_type) { |
|
| 3226 | - case 'datetime': |
|
| 3227 | - $value_to_outut = mysql2date(get_option('date_format'), $attribute_selected_value, true); |
|
| 3228 | - break; |
|
| 3229 | - } |
|
| 3230 | - |
|
| 3231 | - if (in_array($free_variation_attribute_def->backend_input, array('select', 'multiple-select'))) { |
|
| 3232 | - switch ($free_variation_attribute_def->data_type_to_use) { |
|
| 3233 | - case 'custom': |
|
| 3234 | - case 'internal': |
|
| 3235 | - $possible_values = wpshop_attributes::get_select_output($free_variation_attribute_def); |
|
| 3236 | - $value_to_outut = $possible_values['possible_value'][$attribute_selected_value]; |
|
| 3237 | - break; |
|
| 3238 | - } |
|
| 3239 | - } |
|
| 3240 | - $variation_tpl_component['VARIATION_VALUE'] = stripslashes($value_to_outut); |
|
| 3241 | - $variation_tpl_component['VARIATION_ID'] = $attribute_code; |
|
| 3242 | - $variation_tpl_component['VARIATION_ATT_CODE'] = $attribute_code; |
|
| 3243 | - if (!empty($value_to_outut) && !empty($output_order[$free_variation_attribute_def->code])) { |
|
| 3244 | - $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); |
|
| 3245 | - if (!in_array($display_data, $variation_attribute_ordered['attribute_list'])) { |
|
| 3246 | - $variation_attribute_ordered['attribute_list'][$output_order[$free_variation_attribute_def->code]] = $display_data; |
|
| 3247 | - } |
|
| 3248 | - } |
|
| 3249 | - unset($variation_tpl_component); |
|
| 3250 | - } |
|
| 3251 | - } |
|
| 3252 | - return $variation_attribute_ordered; |
|
| 3253 | - } |
|
| 3201 | + $variation_attribute_ordered['prices'][$variation_attribute_code] = $variation_tpl_component['VARIATION_DETAIL_PRODUCT_PRICE']; |
|
| 3202 | + } |
|
| 3203 | + if (!empty($output_order[$variation_attribute_code])) { |
|
| 3204 | + $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); |
|
| 3205 | + } |
|
| 3206 | + unset($variation_tpl_component); |
|
| 3207 | + } |
|
| 3208 | + } |
|
| 3254 | 3209 | |
| 3255 | - public function wps_selected_variation_picture($head_product_id, $variations) |
|
| 3256 | - { |
|
| 3257 | - $response = array(); |
|
| 3258 | - /** Selected Product image **/ |
|
| 3259 | - $post_thumbnail_id = get_post_thumbnail_id($head_product_id); |
|
| 3260 | - if (!empty($post_thumbnail_id)) { |
|
| 3261 | - $response['img_id'] = $post_thumbnail_id; |
|
| 3262 | - $response['img'] = wp_get_attachment_image($post_thumbnail_id, 'wpshop-product-galery'); |
|
| 3263 | - $response['img_url'] = wp_get_attachment_url($post_thumbnail_id); |
|
| 3264 | - } |
|
| 3210 | + /** Free Variation part */ |
|
| 3211 | + if (!empty($product_definition_value['free_variation']) && is_array($product_definition_value['free_variation'])) { |
|
| 3212 | + foreach ($product_definition_value['free_variation'] as $build_variation_key => $build_variation) { |
|
| 3213 | + if (strpos($build_variation, '-_variation_val_-')) { |
|
| 3214 | + $variation_definition = explode('-_variation_val_-', $build_variation); |
|
| 3215 | + $attribute_code = $variation_definition[0]; |
|
| 3216 | + $attribute_selected_value = $variation_definition[1]; |
|
| 3217 | + } else { |
|
| 3218 | + $attribute_code = $build_variation_key; |
|
| 3219 | + $attribute_selected_value = $build_variation; |
|
| 3220 | + } |
|
| 3265 | 3221 | |
| 3266 | - /** check if have one variation **/ |
|
| 3267 | - if (!empty($variations) && count($variations) == 1) { |
|
| 3268 | - $variation_attached_image_id = get_post_meta($variations[0], '_wps_variation_attached_picture', true); |
|
| 3269 | - if (!empty($variation_attached_image_id)) { |
|
| 3270 | - $response['img_id'] = $variation_attached_image_id; |
|
| 3271 | - $response['img'] = wp_get_attachment_image($variation_attached_image_id, 'wpshop-product-galery'); |
|
| 3272 | - $response['img_url'] = wp_get_attachment_url($variation_attached_image_id); |
|
| 3273 | - } |
|
| 3274 | - } |
|
| 3275 | - return $response; |
|
| 3276 | - } |
|
| 3222 | + $free_variation_attribute_def = wpshop_attributes::getElement($attribute_code, "'valid'", 'code'); |
|
| 3223 | + $variation_tpl_component['VARIATION_NAME'] = stripslashes($free_variation_attribute_def->frontend_label); |
|
| 3224 | + $value_to_outut = $attribute_selected_value; |
|
| 3225 | + switch ($free_variation_attribute_def->data_type) { |
|
| 3226 | + case 'datetime': |
|
| 3227 | + $value_to_outut = mysql2date(get_option('date_format'), $attribute_selected_value, true); |
|
| 3228 | + break; |
|
| 3229 | + } |
|
| 3277 | 3230 | |
| 3278 | - /** Add a meta box of product sales history in product administration panel **/ |
|
| 3279 | - public function meta_box_product_sale_informations() |
|
| 3280 | - { |
|
| 3281 | - global $post; |
|
| 3282 | - $product_id = $post->ID; |
|
| 3283 | - |
|
| 3284 | - $variations = self::get_variation($product_id); |
|
| 3285 | - |
|
| 3286 | - $sales_informations = array(); |
|
| 3287 | - /** Query **/ |
|
| 3288 | - $data_to_compare = '"item_id";s:' . strlen($product_id) . ':"' . $product_id . '";'; |
|
| 3289 | - $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'))); |
|
| 3290 | - $orders = new WP_Query($query_args); |
|
| 3291 | - if (!empty($orders) && !empty($orders->posts)) { |
|
| 3292 | - foreach ($orders->posts as $order) { |
|
| 3293 | - $order_meta = get_post_meta($order->ID, '_order_postmeta', true); |
|
| 3294 | - $order_info = get_post_meta($order->ID, '_order_info', true); |
|
| 3295 | - $sales_informations[] = array( |
|
| 3296 | - 'order_key' => (!empty($order_meta) && !empty($order_meta['order_key'])) ? $order_meta['order_key'] : '', |
|
| 3297 | - 'order_date' => (!empty($order_meta) && !empty($order_meta['order_date'])) ? $order_meta['order_date'] : '', |
|
| 3298 | - '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'] : '', |
|
| 3299 | - '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'] : '', |
|
| 3300 | - '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'] : '', |
|
| 3301 | - ); |
|
| 3302 | - } |
|
| 3303 | - } |
|
| 3231 | + if (in_array($free_variation_attribute_def->backend_input, array('select', 'multiple-select'))) { |
|
| 3232 | + switch ($free_variation_attribute_def->data_type_to_use) { |
|
| 3233 | + case 'custom': |
|
| 3234 | + case 'internal': |
|
| 3235 | + $possible_values = wpshop_attributes::get_select_output($free_variation_attribute_def); |
|
| 3236 | + $value_to_outut = $possible_values['possible_value'][$attribute_selected_value]; |
|
| 3237 | + break; |
|
| 3238 | + } |
|
| 3239 | + } |
|
| 3240 | + $variation_tpl_component['VARIATION_VALUE'] = stripslashes($value_to_outut); |
|
| 3241 | + $variation_tpl_component['VARIATION_ID'] = $attribute_code; |
|
| 3242 | + $variation_tpl_component['VARIATION_ATT_CODE'] = $attribute_code; |
|
| 3243 | + if (!empty($value_to_outut) && !empty($output_order[$free_variation_attribute_def->code])) { |
|
| 3244 | + $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); |
|
| 3245 | + if (!in_array($display_data, $variation_attribute_ordered['attribute_list'])) { |
|
| 3246 | + $variation_attribute_ordered['attribute_list'][$output_order[$free_variation_attribute_def->code]] = $display_data; |
|
| 3247 | + } |
|
| 3248 | + } |
|
| 3249 | + unset($variation_tpl_component); |
|
| 3250 | + } |
|
| 3251 | + } |
|
| 3252 | + return $variation_attribute_ordered; |
|
| 3253 | + } |
|
| 3304 | 3254 | |
| 3305 | - /** If product has been ordered **/ |
|
| 3306 | - $output = ''; |
|
| 3307 | - if (!empty($sales_informations)) { |
|
| 3308 | - $output .= '<p>' . __('This product has been ordered', 'wpshop') . ' :</p>'; |
|
| 3309 | - $output .= '<ul>'; |
|
| 3310 | - foreach ($sales_informations as $sales_information) { |
|
| 3311 | - $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>'; |
|
| 3312 | - } |
|
| 3313 | - $output .= '</ul>'; |
|
| 3314 | - } else { |
|
| 3315 | - $output .= __('This product has never been ordered', 'wpshop'); |
|
| 3316 | - } |
|
| 3255 | + public function wps_selected_variation_picture($head_product_id, $variations) |
|
| 3256 | + { |
|
| 3257 | + $response = array(); |
|
| 3258 | + /** Selected Product image **/ |
|
| 3259 | + $post_thumbnail_id = get_post_thumbnail_id($head_product_id); |
|
| 3260 | + if (!empty($post_thumbnail_id)) { |
|
| 3261 | + $response['img_id'] = $post_thumbnail_id; |
|
| 3262 | + $response['img'] = wp_get_attachment_image($post_thumbnail_id, 'wpshop-product-galery'); |
|
| 3263 | + $response['img_url'] = wp_get_attachment_url($post_thumbnail_id); |
|
| 3264 | + } |
|
| 3317 | 3265 | |
| 3318 | - echo $output; |
|
| 3319 | - } |
|
| 3266 | + /** check if have one variation **/ |
|
| 3267 | + if (!empty($variations) && count($variations) == 1) { |
|
| 3268 | + $variation_attached_image_id = get_post_meta($variations[0], '_wps_variation_attached_picture', true); |
|
| 3269 | + if (!empty($variation_attached_image_id)) { |
|
| 3270 | + $response['img_id'] = $variation_attached_image_id; |
|
| 3271 | + $response['img'] = wp_get_attachment_image($variation_attached_image_id, 'wpshop-product-galery'); |
|
| 3272 | + $response['img_url'] = wp_get_attachment_url($variation_attached_image_id); |
|
| 3273 | + } |
|
| 3274 | + } |
|
| 3275 | + return $response; |
|
| 3276 | + } |
|
| 3320 | 3277 | |
| 3321 | - public function wps_get_summary_variations_product($product_id, $the_product, $has_variation) |
|
| 3322 | - { |
|
| 3323 | - global $wpdb, $wpshop_payment; |
|
| 3324 | - $output = ''; |
|
| 3325 | - $tpl_component = array(); |
|
| 3326 | - /** Get attribute order for current product */ |
|
| 3327 | - $product_attribute_order_detail = wpshop_attributes_set::getAttributeSetDetails(get_post_meta($product_id, WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, true)); |
|
| 3328 | - $output_order = array(); |
|
| 3329 | - if (count($product_attribute_order_detail) > 0) { |
|
| 3330 | - foreach ($product_attribute_order_detail as $product_attr_group_id => $product_attr_group_detail) { |
|
| 3331 | - foreach ($product_attr_group_detail['attribut'] as $position => $attribute_def) { |
|
| 3332 | - if (!empty($attribute_def->code)) { |
|
| 3333 | - $output_order[$attribute_def->code] = $position; |
|
| 3334 | - } |
|
| 3335 | - |
|
| 3336 | - } |
|
| 3337 | - } |
|
| 3338 | - } |
|
| 3339 | - $variation_attribute_ordered = array(); |
|
| 3340 | - |
|
| 3341 | - /** Check if product is a variation and change his name **/ |
|
| 3342 | - $product_post_type = get_post_type($the_product['product_id']); |
|
| 3343 | - if (!empty($product_post_type) && $product_post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) { |
|
| 3344 | - $parent_infos = wpshop_products::get_parent_variation($the_product['product_id']); |
|
| 3345 | - $parent_post = (!empty($parent_infos) && !empty($parent_infos['parent_post'])) ? $parent_infos['parent_post'] : array(); |
|
| 3346 | - $the_product['product_name'] = $the_product['post_title'] = $parent_post->post_title; |
|
| 3347 | - } |
|
| 3278 | + /** Add a meta box of product sales history in product administration panel **/ |
|
| 3279 | + public function meta_box_product_sale_informations() |
|
| 3280 | + { |
|
| 3281 | + global $post; |
|
| 3282 | + $product_id = $post->ID; |
|
| 3283 | + |
|
| 3284 | + $variations = self::get_variation($product_id); |
|
| 3285 | + |
|
| 3286 | + $sales_informations = array(); |
|
| 3287 | + /** Query **/ |
|
| 3288 | + $data_to_compare = '"item_id";s:' . strlen($product_id) . ':"' . $product_id . '";'; |
|
| 3289 | + $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'))); |
|
| 3290 | + $orders = new WP_Query($query_args); |
|
| 3291 | + if (!empty($orders) && !empty($orders->posts)) { |
|
| 3292 | + foreach ($orders->posts as $order) { |
|
| 3293 | + $order_meta = get_post_meta($order->ID, '_order_postmeta', true); |
|
| 3294 | + $order_info = get_post_meta($order->ID, '_order_info', true); |
|
| 3295 | + $sales_informations[] = array( |
|
| 3296 | + 'order_key' => (!empty($order_meta) && !empty($order_meta['order_key'])) ? $order_meta['order_key'] : '', |
|
| 3297 | + 'order_date' => (!empty($order_meta) && !empty($order_meta['order_date'])) ? $order_meta['order_date'] : '', |
|
| 3298 | + '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'] : '', |
|
| 3299 | + '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'] : '', |
|
| 3300 | + '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'] : '', |
|
| 3301 | + ); |
|
| 3302 | + } |
|
| 3303 | + } |
|
| 3348 | 3304 | |
| 3349 | - foreach ($the_product as $product_definition_key => $product_definition_value) { |
|
| 3350 | - if ($product_definition_key != 'item_meta') { |
|
| 3351 | - $tpl_component['PRODUCT_MAIN_INFO_' . strtoupper($product_definition_key)] = $product_definition_value; |
|
| 3352 | - if (!empty($wpshop_current_for_display) && in_array($product_definition_key, unserialize(WPSHOP_ATTRIBUTE_PRICES))) { |
|
| 3353 | - $tpl_component['PRODUCT_MAIN_INFO_' . strtoupper($product_definition_key)] = $product_definition_value; |
|
| 3354 | - } |
|
| 3355 | - } else { |
|
| 3356 | - $variation_attribute_ordered = wpshop_products::get_selected_variation_display($product_definition_value, $output_order, 'selection_summary'); |
|
| 3357 | - } |
|
| 3358 | - } |
|
| 3305 | + /** If product has been ordered **/ |
|
| 3306 | + $output = ''; |
|
| 3307 | + if (!empty($sales_informations)) { |
|
| 3308 | + $output .= '<p>' . __('This product has been ordered', 'wpshop') . ' :</p>'; |
|
| 3309 | + $output .= '<ul>'; |
|
| 3310 | + foreach ($sales_informations as $sales_information) { |
|
| 3311 | + $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>'; |
|
| 3312 | + } |
|
| 3313 | + $output .= '</ul>'; |
|
| 3314 | + } else { |
|
| 3315 | + $output .= __('This product has never been ordered', 'wpshop'); |
|
| 3316 | + } |
|
| 3359 | 3317 | |
| 3360 | - ksort($variation_attribute_ordered['attribute_list']); |
|
| 3361 | - $tpl_component['PRODUCT_VARIATION_SUMMARY_DETAILS'] = ''; |
|
| 3362 | - foreach ($variation_attribute_ordered['attribute_list'] as $attribute_variation_to_output) { |
|
| 3363 | - $tpl_component['PRODUCT_VARIATION_SUMMARY_DETAILS'] .= $attribute_variation_to_output; |
|
| 3364 | - } |
|
| 3318 | + echo $output; |
|
| 3319 | + } |
|
| 3365 | 3320 | |
| 3366 | - /** For security get all attributes defined as user defined or used in variation in order to set default value to empty */ |
|
| 3367 | - $attribute_list = wpshop_attributes::getElement('yes', "'valid'", "is_used_for_variation", true); |
|
| 3368 | - if (!empty($attribute_list)) { |
|
| 3369 | - foreach ($attribute_list as $attribute_def) { |
|
| 3370 | - $tpl_component['VARIATION_SUMMARY_ATTRIBUTE_PER_PRICE_' . strtoupper($attribute_def->code)] = '-'; |
|
| 3371 | - } |
|
| 3372 | - } |
|
| 3321 | + public function wps_get_summary_variations_product($product_id, $the_product, $has_variation) |
|
| 3322 | + { |
|
| 3323 | + global $wpdb, $wpshop_payment; |
|
| 3324 | + $output = ''; |
|
| 3325 | + $tpl_component = array(); |
|
| 3326 | + /** Get attribute order for current product */ |
|
| 3327 | + $product_attribute_order_detail = wpshop_attributes_set::getAttributeSetDetails(get_post_meta($product_id, WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, true)); |
|
| 3328 | + $output_order = array(); |
|
| 3329 | + if (count($product_attribute_order_detail) > 0) { |
|
| 3330 | + foreach ($product_attribute_order_detail as $product_attr_group_id => $product_attr_group_detail) { |
|
| 3331 | + foreach ($product_attr_group_detail['attribut'] as $position => $attribute_def) { |
|
| 3332 | + if (!empty($attribute_def->code)) { |
|
| 3333 | + $output_order[$attribute_def->code] = $position; |
|
| 3334 | + } |
|
| 3373 | 3335 | |
| 3374 | - /** Fill the array with all prices for different variations */ |
|
| 3375 | - foreach ($variation_attribute_ordered['prices'] as $attribute => $prices) { |
|
| 3376 | - $tpl_component['VARIATION_SUMMARY_ATTRIBUTE_PER_PRICE_' . strtoupper($attribute)] = $prices; |
|
| 3377 | - } |
|
| 3336 | + } |
|
| 3337 | + } |
|
| 3338 | + } |
|
| 3339 | + $variation_attribute_ordered = array(); |
|
| 3340 | + |
|
| 3341 | + /** Check if product is a variation and change his name **/ |
|
| 3342 | + $product_post_type = get_post_type($the_product['product_id']); |
|
| 3343 | + if (!empty($product_post_type) && $product_post_type == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) { |
|
| 3344 | + $parent_infos = wpshop_products::get_parent_variation($the_product['product_id']); |
|
| 3345 | + $parent_post = (!empty($parent_infos) && !empty($parent_infos['parent_post'])) ? $parent_infos['parent_post'] : array(); |
|
| 3346 | + $the_product['product_name'] = $the_product['post_title'] = $parent_post->post_title; |
|
| 3347 | + } |
|
| 3378 | 3348 | |
| 3379 | - $tpl_component['PRODUCT_VARIATION_SUMMARY_MORE_CONTENT'] = ''; |
|
| 3380 | - $query = $wpdb->prepare("SELECT post_id, meta_value FROM " . $wpdb->postmeta . " WHERE meta_key = %s ", '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_options'); |
|
| 3381 | - $post_list_with_options = $wpdb->get_results($query); |
|
| 3382 | - if (!empty($post_list_with_options)) { |
|
| 3383 | - $additionnal_price = 0; |
|
| 3384 | - foreach ($post_list_with_options as $product_info) { |
|
| 3385 | - $product_meta = unserialize($product_info->meta_value); |
|
| 3386 | - if (!empty($product_meta['cart']) && !empty($product_meta['cart']['auto_add']) && ($product_meta['cart']['auto_add'] == 'yes')) { |
|
| 3387 | - $product = wpshop_products::get_product_data($product_info->post_id, true, '"publish", "draft"'); |
|
| 3388 | - |
|
| 3389 | - $the_product = array_merge(array( |
|
| 3390 | - 'product_id' => $product_info->post_id, |
|
| 3391 | - 'product_qty' => 1, |
|
| 3392 | - ), $product); |
|
| 3393 | - |
|
| 3394 | - $additionnal_price += (!$different_currency || ($change_rate == 1)) ? $the_product['product_price'] : ($the_product['product_price'] * $change_rate); |
|
| 3395 | - $tpl_component['AUTO_PRODUCT_NAME'] = $the_product['product_name']; |
|
| 3396 | - |
|
| 3397 | - $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)); |
|
| 3398 | - $tpl_component['PRODUCT_VARIATION_SUMMARY_MORE_CONTENT'] = wpshop_display::display_template_element('wpshop_product_configuration_summary_detail_auto_product', $tpl_component); |
|
| 3399 | - } |
|
| 3400 | - } |
|
| 3401 | - } |
|
| 3349 | + foreach ($the_product as $product_definition_key => $product_definition_value) { |
|
| 3350 | + if ($product_definition_key != 'item_meta') { |
|
| 3351 | + $tpl_component['PRODUCT_MAIN_INFO_' . strtoupper($product_definition_key)] = $product_definition_value; |
|
| 3352 | + if (!empty($wpshop_current_for_display) && in_array($product_definition_key, unserialize(WPSHOP_ATTRIBUTE_PRICES))) { |
|
| 3353 | + $tpl_component['PRODUCT_MAIN_INFO_' . strtoupper($product_definition_key)] = $product_definition_value; |
|
| 3354 | + } |
|
| 3355 | + } else { |
|
| 3356 | + $variation_attribute_ordered = wpshop_products::get_selected_variation_display($product_definition_value, $output_order, 'selection_summary'); |
|
| 3357 | + } |
|
| 3358 | + } |
|
| 3402 | 3359 | |
| 3403 | - $tpl_component['PRODUCT_VARIATION_SUMMARY_GRAND_TOTAL'] = ''; |
|
| 3404 | - $tpl_component['SUMMARY_FINAL_RESULT_PRICE_NO_FORMAT'] = ''; |
|
| 3405 | - if (!empty($additionnal_price)) { |
|
| 3406 | - $tpl_component['SUMMARY_FINAL_RESULT_PRICE'] = wpshop_display::format_field_output('wpshop_product_price', $tpl_component['PRODUCT_MAIN_INFO_PRODUCT_PRICE'] + $additionnal_price); |
|
| 3407 | - $tpl_component['SUMMARY_FINAL_RESULT_PRICE_NO_FORMAT'] = ($tpl_component['PRODUCT_MAIN_INFO_PRODUCT_PRICE'] + $additionnal_price); |
|
| 3408 | - $tpl_component['PRODUCT_VARIATION_SUMMARY_GRAND_TOTAL'] = wpshop_display::display_template_element('wpshop_product_configuration_summary_detail_final_result', $tpl_component); |
|
| 3409 | - } |
|
| 3360 | + ksort($variation_attribute_ordered['attribute_list']); |
|
| 3361 | + $tpl_component['PRODUCT_VARIATION_SUMMARY_DETAILS'] = ''; |
|
| 3362 | + foreach ($variation_attribute_ordered['attribute_list'] as $attribute_variation_to_output) { |
|
| 3363 | + $tpl_component['PRODUCT_VARIATION_SUMMARY_DETAILS'] .= $attribute_variation_to_output; |
|
| 3364 | + } |
|
| 3365 | + |
|
| 3366 | + /** For security get all attributes defined as user defined or used in variation in order to set default value to empty */ |
|
| 3367 | + $attribute_list = wpshop_attributes::getElement('yes', "'valid'", "is_used_for_variation", true); |
|
| 3368 | + if (!empty($attribute_list)) { |
|
| 3369 | + foreach ($attribute_list as $attribute_def) { |
|
| 3370 | + $tpl_component['VARIATION_SUMMARY_ATTRIBUTE_PER_PRICE_' . strtoupper($attribute_def->code)] = '-'; |
|
| 3371 | + } |
|
| 3372 | + } |
|
| 3410 | 3373 | |
| 3411 | - /** Call informtion for partial payment */ |
|
| 3412 | - $partial_payment = $wpshop_payment->partial_payment_calcul($tpl_component['SUMMARY_FINAL_RESULT_PRICE_NO_FORMAT']); |
|
| 3413 | - $tpl_component['PARTIAL_PAYMENT_INFO'] = !empty($partial_payment['amount_to_pay']) ? $partial_payment['display'] : ''; |
|
| 3374 | + /** Fill the array with all prices for different variations */ |
|
| 3375 | + foreach ($variation_attribute_ordered['prices'] as $attribute => $prices) { |
|
| 3376 | + $tpl_component['VARIATION_SUMMARY_ATTRIBUTE_PER_PRICE_' . strtoupper($attribute)] = $prices; |
|
| 3377 | + } |
|
| 3378 | + |
|
| 3379 | + $tpl_component['PRODUCT_VARIATION_SUMMARY_MORE_CONTENT'] = ''; |
|
| 3380 | + $query = $wpdb->prepare("SELECT post_id, meta_value FROM " . $wpdb->postmeta . " WHERE meta_key = %s ", '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_options'); |
|
| 3381 | + $post_list_with_options = $wpdb->get_results($query); |
|
| 3382 | + if (!empty($post_list_with_options)) { |
|
| 3383 | + $additionnal_price = 0; |
|
| 3384 | + foreach ($post_list_with_options as $product_info) { |
|
| 3385 | + $product_meta = unserialize($product_info->meta_value); |
|
| 3386 | + if (!empty($product_meta['cart']) && !empty($product_meta['cart']['auto_add']) && ($product_meta['cart']['auto_add'] == 'yes')) { |
|
| 3387 | + $product = wpshop_products::get_product_data($product_info->post_id, true, '"publish", "draft"'); |
|
| 3388 | + |
|
| 3389 | + $the_product = array_merge(array( |
|
| 3390 | + 'product_id' => $product_info->post_id, |
|
| 3391 | + 'product_qty' => 1, |
|
| 3392 | + ), $product); |
|
| 3393 | + |
|
| 3394 | + $additionnal_price += (!$different_currency || ($change_rate == 1)) ? $the_product['product_price'] : ($the_product['product_price'] * $change_rate); |
|
| 3395 | + $tpl_component['AUTO_PRODUCT_NAME'] = $the_product['product_name']; |
|
| 3396 | + |
|
| 3397 | + $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)); |
|
| 3398 | + $tpl_component['PRODUCT_VARIATION_SUMMARY_MORE_CONTENT'] = wpshop_display::display_template_element('wpshop_product_configuration_summary_detail_auto_product', $tpl_component); |
|
| 3399 | + } |
|
| 3400 | + } |
|
| 3401 | + } |
|
| 3414 | 3402 | |
| 3415 | - /** Define the current selected currency for the order summary */ |
|
| 3403 | + $tpl_component['PRODUCT_VARIATION_SUMMARY_GRAND_TOTAL'] = ''; |
|
| 3404 | + $tpl_component['SUMMARY_FINAL_RESULT_PRICE_NO_FORMAT'] = ''; |
|
| 3405 | + if (!empty($additionnal_price)) { |
|
| 3406 | + $tpl_component['SUMMARY_FINAL_RESULT_PRICE'] = wpshop_display::format_field_output('wpshop_product_price', $tpl_component['PRODUCT_MAIN_INFO_PRODUCT_PRICE'] + $additionnal_price); |
|
| 3407 | + $tpl_component['SUMMARY_FINAL_RESULT_PRICE_NO_FORMAT'] = ($tpl_component['PRODUCT_MAIN_INFO_PRODUCT_PRICE'] + $additionnal_price); |
|
| 3408 | + $tpl_component['PRODUCT_VARIATION_SUMMARY_GRAND_TOTAL'] = wpshop_display::display_template_element('wpshop_product_configuration_summary_detail_final_result', $tpl_component); |
|
| 3409 | + } |
|
| 3410 | + |
|
| 3411 | + /** Call informtion for partial payment */ |
|
| 3412 | + $partial_payment = $wpshop_payment->partial_payment_calcul($tpl_component['SUMMARY_FINAL_RESULT_PRICE_NO_FORMAT']); |
|
| 3413 | + $tpl_component['PARTIAL_PAYMENT_INFO'] = !empty($partial_payment['amount_to_pay']) ? $partial_payment['display'] : ''; |
|
| 3414 | + |
|
| 3415 | + /** Define the current selected currency for the order summary */ |
|
| 3416 | 3416 | // $response['product_output'] = $has_variation ? wpshop_display::display_template_element('wpshop_product_configuration_summary_detail', $tpl_component) : ''; |
| 3417 | - $output = $has_variation ? wpshop_display::display_template_element('wpshop_product_configuration_summary_detail', $tpl_component) : ''; |
|
| 3418 | - return $output; |
|
| 3419 | - } |
|
| 3417 | + $output = $has_variation ? wpshop_display::display_template_element('wpshop_product_configuration_summary_detail', $tpl_component) : ''; |
|
| 3418 | + return $output; |
|
| 3419 | + } |
|
| 3420 | 3420 | |
| 3421 | - /** |
|
| 3422 | - * Get product ID if ID = "id-parent__id-variation" or "id-variation" or "id-parent" |
|
| 3423 | - * @param string $ID ID product variations or not |
|
| 3424 | - * @return string Return ID |
|
| 3425 | - */ |
|
| 3426 | - public static function get_id_variation($ID) |
|
| 3427 | - { |
|
| 3428 | - $result = explode('__', $ID); |
|
| 3429 | - return end($result); |
|
| 3430 | - } |
|
| 3421 | + /** |
|
| 3422 | + * Get product ID if ID = "id-parent__id-variation" or "id-variation" or "id-parent" |
|
| 3423 | + * @param string $ID ID product variations or not |
|
| 3424 | + * @return string Return ID |
|
| 3425 | + */ |
|
| 3426 | + public static function get_id_variation($ID) |
|
| 3427 | + { |
|
| 3428 | + $result = explode('__', $ID); |
|
| 3429 | + return end($result); |
|
| 3430 | + } |
|
| 3431 | 3431 | |
| 3432 | - /** |
|
| 3433 | - * Update all variations definitions who not modified |
|
| 3434 | - * @param array $new_value |
|
| 3435 | - * @param array $old_value |
|
| 3436 | - * @return array $new_value |
|
| 3437 | - */ |
|
| 3438 | - public static function update_wpshop_catalog_product_option($new_value, $old_value) |
|
| 3439 | - { |
|
| 3440 | - global $wpdb; |
|
| 3441 | - $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') . '%'); |
|
| 3442 | - foreach ($wpdb->get_results($query) as $wpshop_variation_defining) { |
|
| 3443 | - $wpshop_variation_defining_value = unserialize($wpshop_variation_defining->meta_value); |
|
| 3444 | - $wpshop_variation_defining_value['options']['price_display'] = $new_value['price_display']; |
|
| 3445 | - update_post_meta($wpshop_variation_defining->post_id, '_wpshop_variation_defining', $wpshop_variation_defining_value); |
|
| 3446 | - } |
|
| 3447 | - return $new_value; |
|
| 3448 | - } |
|
| 3432 | + /** |
|
| 3433 | + * Update all variations definitions who not modified |
|
| 3434 | + * @param array $new_value |
|
| 3435 | + * @param array $old_value |
|
| 3436 | + * @return array $new_value |
|
| 3437 | + */ |
|
| 3438 | + public static function update_wpshop_catalog_product_option($new_value, $old_value) |
|
| 3439 | + { |
|
| 3440 | + global $wpdb; |
|
| 3441 | + $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') . '%'); |
|
| 3442 | + foreach ($wpdb->get_results($query) as $wpshop_variation_defining) { |
|
| 3443 | + $wpshop_variation_defining_value = unserialize($wpshop_variation_defining->meta_value); |
|
| 3444 | + $wpshop_variation_defining_value['options']['price_display'] = $new_value['price_display']; |
|
| 3445 | + update_post_meta($wpshop_variation_defining->post_id, '_wpshop_variation_defining', $wpshop_variation_defining_value); |
|
| 3446 | + } |
|
| 3447 | + return $new_value; |
|
| 3448 | + } |
|
| 3449 | 3449 | |
| 3450 | - public static function variation_parameters_save($current_post_id, $options) |
|
| 3451 | - { |
|
| 3450 | + public static function variation_parameters_save($current_post_id, $options) |
|
| 3451 | + { |
|
| 3452 | 3452 | $variation_post_meta = get_post_meta($current_post_id, '_wpshop_variation_defining', true); |
| 3453 | - $variation_post_meta['options'] = $options; |
|
| 3453 | + $variation_post_meta['options'] = $options; |
|
| 3454 | 3454 | $variation_post_meta['follow_general_config'] = true; |
| 3455 | 3455 | if( $variation_post_meta['follow_general_config'] ) { |
| 3456 | 3456 | $shop_option = get_option('wpshop_catalog_product_option', array()); |
@@ -3466,6 +3466,6 @@ discard block |
||
| 3466 | 3466 | } |
| 3467 | 3467 | } |
| 3468 | 3468 | } |
| 3469 | - update_post_meta($current_post_id, '_wpshop_variation_defining', $variation_post_meta); |
|
| 3470 | - } |
|
| 3469 | + update_post_meta($current_post_id, '_wpshop_variation_defining', $variation_post_meta); |
|
| 3470 | + } |
|
| 3471 | 3471 | } |
@@ -1,10 +1,10 @@ discard block |
||
| 1 | 1 | <?php if (!defined('ABSPATH')) { |
| 2 | - exit; |
|
| 2 | + exit; |
|
| 3 | 3 | } |
| 4 | 4 | |
| 5 | 5 | /* Check if file is include. No direct access possible with file url */ |
| 6 | 6 | if (!defined('WPSHOP_VERSION')) { |
| 7 | - die(__('Access is not allowed by this way', 'wpshop')); |
|
| 7 | + die(__('Access is not allowed by this way', 'wpshop')); |
|
| 8 | 8 | } |
| 9 | 9 | |
| 10 | 10 | /** |
@@ -25,1785 +25,1785 @@ discard block |
||
| 25 | 25 | class wpshop_install |
| 26 | 26 | { |
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * Define the action launch when plugin is activate |
|
| 30 | - * |
|
| 31 | - * @return void |
|
| 32 | - */ |
|
| 33 | - public static function install_on_activation() |
|
| 34 | - { |
|
| 35 | - /* Create the different option needed for the plugin work properly */ |
|
| 36 | - add_option('wpshop_db_options', array('db_version' => 0)); |
|
| 37 | - add_option('wpshop_shop_default_currency', WPSHOP_SHOP_DEFAULT_CURRENCY); |
|
| 38 | - add_option('wpshop_emails', array('noreply_email' => get_bloginfo('admin_email'), 'contact_email' => get_bloginfo('admin_email'))); |
|
| 39 | - add_option('wpshop_catalog_product_option', array('wpshop_catalog_product_slug' => WPSHOP_CATALOG_PRODUCT_SLUG)); |
|
| 40 | - add_option('wpshop_catalog_categories_option', array('wpshop_catalog_categories_slug' => WPSHOP_CATALOG_CATEGORIES_SLUG)); |
|
| 41 | - add_option('wpshop_display_option', array('wpshop_display_list_type' => 'grid', 'wpshop_display_grid_element_number' => '3', 'wpshop_display_cat_sheet_output' => array('category_description', 'category_subcategory', 'category_subproduct'))); |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * Create the default pages |
|
| 46 | - */ |
|
| 47 | - public static function wpshop_insert_default_pages($pages_type = '') |
|
| 48 | - { |
|
| 49 | - global $wpdb, $wp_rewrite; |
|
| 50 | - |
|
| 51 | - /** if we will create any new pages we need to flush page cache */ |
|
| 52 | - $page_creation = false; |
|
| 53 | - $created_pages = array(); |
|
| 54 | - |
|
| 55 | - /** Default data array for add page */ |
|
| 56 | - $page_default_args = array( |
|
| 57 | - 'post_type' => 'page', |
|
| 58 | - 'comment_status' => 'closed', |
|
| 59 | - 'ping_status' => 'closed', |
|
| 60 | - 'post_status' => 'publish', |
|
| 61 | - 'post_author' => get_current_user_id(), |
|
| 62 | - ); |
|
| 63 | - |
|
| 64 | - /** Get defined shop type */ |
|
| 65 | - $wpshop_shop_type = !empty($pages_type) ? $pages_type : get_option('wpshop_shop_type', WPSHOP_DEFAULT_SHOP_TYPE); |
|
| 66 | - |
|
| 67 | - /** Get the default datas for installation - Pages */ |
|
| 68 | - $xml_default_pages = file_get_contents(WP_PLUGIN_DIR . '/' . WPSHOP_PLUGIN_DIR . '/assets/datas/default_pages.xml'); |
|
| 69 | - $defined_default_pages = new SimpleXMLElement($xml_default_pages); |
|
| 70 | - foreach ($defined_default_pages->xpath('//pages/page') as $page) { |
|
| 71 | - if (($wpshop_shop_type == $page->attributes()->shop_type) || ('sale' == $wpshop_shop_type)) { |
|
| 72 | - $page_id = null; |
|
| 73 | - |
|
| 74 | - /** Do a specific check for cart page, for old wpshop installation */ |
|
| 75 | - if ('wpshop_cart_page_id' == (string) $page->attributes()->code) { |
|
| 76 | - $query = $wpdb->prepare("SELECT ID FROM " . $wpdb->posts . " WHERE post_content LIKE %s AND post_type != %s", '%[wpshop_basket]%', 'revision'); |
|
| 77 | - $page_id = $wpdb->get_var($query); |
|
| 78 | - |
|
| 79 | - wp_update_post(array( |
|
| 80 | - 'ID' => $page_id, |
|
| 81 | - 'post_content' => (string) $page->content, |
|
| 82 | - )); |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - /** Check if a page exists with the current content readed form xml file */ |
|
| 86 | - if (empty($page_id)) { |
|
| 87 | - $query = $wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_content LIKE %s AND post_type != %s", '%' . (string) $page->content . '%', 'revision'); |
|
| 88 | - $page_id = $wpdb->get_var($query); |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - /** If the page does not exists create it */ |
|
| 92 | - if (empty($page_id)) { |
|
| 93 | - $default_page_args = wp_parse_args(array( |
|
| 94 | - 'post_title' => __((string) $page->title, 'wpshop'), |
|
| 95 | - 'post_name' => __((string) $page->slug, 'wpshop'), |
|
| 96 | - 'post_content' => __((string) $page->content, 'wpshop'), |
|
| 97 | - 'menu_order' => (string) $page->attributes()->position, |
|
| 98 | - ), $page_default_args); |
|
| 99 | - |
|
| 100 | - $page_id = wp_insert_post($default_page_args); |
|
| 101 | - $created_pages[] = (string) $page->attributes()->code; |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - /** If the page is created or already exists associated the page to the good service */ |
|
| 105 | - if (!empty($page_id)) { |
|
| 106 | - add_option((string) $page->attributes()->code, $page_id); |
|
| 107 | - |
|
| 108 | - $page_creation = true; |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - } |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - /** Check if page have been created in order to do specific action */ |
|
| 115 | - if (!empty($created_pages)) { |
|
| 116 | - /** If cart page and checkout page have just been created, change cart page id into checkout page id */ |
|
| 117 | - if (in_array('wpshop_cart_page_id', $created_pages) && in_array('wpshop_checkout_page_id', $created_pages)) { |
|
| 118 | - update_option('wpshop_cart_page_id', get_option('wpshop_checkout_page_id')); |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - wp_cache_flush(); |
|
| 124 | - /** If new page => empty cache */ |
|
| 125 | - if ($page_creation) { |
|
| 126 | - wp_cache_delete('all_page_ids', 'pages'); |
|
| 127 | - // $wp_rewrite->flush_rules(); |
|
| 128 | - } |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - /** |
|
| 132 | - * Insert sample datas when installing wpshop the first time if the admin choose |
|
| 133 | - */ |
|
| 134 | - public static function import_sample_datas() |
|
| 135 | - { |
|
| 136 | - global $wpdb, $wp_rewrite; |
|
| 137 | - |
|
| 138 | - /** Default data array for add product */ |
|
| 139 | - $product_default_args = array( |
|
| 140 | - 'comment_status' => 'closed', |
|
| 141 | - 'ping_status' => 'closed', |
|
| 142 | - 'post_status' => 'publish', |
|
| 143 | - 'post_author' => get_current_user_id(), |
|
| 144 | - ); |
|
| 145 | - |
|
| 146 | - /** Get the default datas for installation - sample products */ |
|
| 147 | - $sample_datas = file_get_contents(WP_PLUGIN_DIR . '/' . WPSHOP_PLUGIN_DIR . '/assets/datas/sample_datas.xml'); |
|
| 148 | - $defined_sample_datas = new SimpleXMLElement($sample_datas, LIBXML_NOCDATA); |
|
| 149 | - |
|
| 150 | - $namespaces = $defined_sample_datas->getDocNamespaces(); |
|
| 151 | - if (!isset($namespaces['wp'])) { |
|
| 152 | - $namespaces['wp'] = 'http://wordpress.org/export/1.1/'; |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - if (!isset($namespaces['excerpt'])) { |
|
| 156 | - $namespaces['excerpt'] = 'http://wordpress.org/export/1.1/excerpt/'; |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - foreach ($defined_sample_datas->xpath('//wpshop_products/wpshop_product') as $product) { |
|
| 160 | - $dc = $product->children('http://purl.org/dc/elements/1.1/'); |
|
| 161 | - $content = $product->children('http://purl.org/rss/1.0/modules/content/'); |
|
| 162 | - $excerpt = $product->children($namespaces['excerpt']); |
|
| 163 | - $wp = $product->children($namespaces['wp']); |
|
| 164 | - |
|
| 165 | - $product_args = wp_parse_args(array( |
|
| 166 | - 'post_title' => (string) $product->title, |
|
| 167 | - 'post_name' => (string) $wp->post_name, |
|
| 168 | - 'post_content' => (string) $content->encoded, |
|
| 169 | - 'post_excerpt' => (string) $excerpt->encoded, |
|
| 170 | - 'post_type' => (string) $wp->post_type, |
|
| 171 | - ), $product_default_args); |
|
| 172 | - |
|
| 173 | - $product_id = wp_insert_post($product_args); |
|
| 174 | - |
|
| 175 | - foreach ($wp->postmeta as $meta) { |
|
| 176 | - update_post_meta($product_id, (string) $meta->meta_key, (string) $meta->meta_value); |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - foreach ($defined_sample_datas->xpath('//wps_pdt_variations/wps_pdt_variation/wp:post_parent[. ="' . $wp->post_id . '"]/parent::*') as $product_variation) { |
|
| 180 | - $wps_pdt_var_dc = $product_variation->children('http://purl.org/dc/elements/1.1/'); |
|
| 181 | - $wps_pdt_var_content = $product_variation->children('http://purl.org/rss/1.0/modules/content/'); |
|
| 182 | - $wps_pdt_var_excerpt = $product_variation->children($namespaces['excerpt']); |
|
| 183 | - $wps_pdt_var_wp = $product_variation->children($namespaces['wp']); |
|
| 184 | - |
|
| 185 | - $product_args = wp_parse_args(array( |
|
| 186 | - 'post_title' => (string) $product_variation->title, |
|
| 187 | - 'post_name' => (string) $wps_pdt_var_wp->post_name, |
|
| 188 | - 'post_content' => (string) $wps_pdt_var_content->encoded, |
|
| 189 | - 'post_excerpt' => (string) $wps_pdt_var_excerpt->encoded, |
|
| 190 | - 'post_type' => (string) $wps_pdt_var_wp->post_type, |
|
| 191 | - 'post_parent' => $product_id, |
|
| 192 | - ), $product_default_args); |
|
| 193 | - |
|
| 194 | - $product_variation_id = wp_insert_post($product_args); |
|
| 195 | - |
|
| 196 | - foreach ($wps_pdt_var_wp->postmeta as $meta) { |
|
| 197 | - update_post_meta($product_variation_id, (string) $meta->meta_key, (string) $meta->meta_value); |
|
| 198 | - } |
|
| 199 | - } |
|
| 200 | - } |
|
| 201 | - } |
|
| 202 | - |
|
| 203 | - /** |
|
| 204 | - * Method called when plugin is loaded for database update. This method allows to update the database structure, insert default content. |
|
| 205 | - */ |
|
| 206 | - public static function update_wpshop_dev() |
|
| 207 | - { |
|
| 208 | - global $wpdb, $wpshop_db_table, $wpshop_db_table_list, $wpshop_update_way, $wpshop_db_content_add, $wpshop_db_content_update, $wpshop_db_options_add, $wpshop_eav_content, $wpshop_eav_content_update, $wpshop_db_options_update; |
|
| 209 | - |
|
| 210 | - require_once ABSPATH . 'wp-admin/includes/upgrade.php'; |
|
| 211 | - |
|
| 212 | - self::execute_operation_on_db_for_update('dev'); |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - /** |
|
| 216 | - * Method called when plugin is loaded for database update. This method allows to update the database structure, insert default content. |
|
| 217 | - */ |
|
| 218 | - public static function update_wpshop() |
|
| 219 | - { |
|
| 220 | - global $wpdb, $wpshop_db_table, $wpshop_db_table_list, $wpshop_update_way, $wpshop_db_content_add, $wpshop_db_content_update, $wpshop_db_options_add, $wpshop_eav_content, $wpshop_eav_content_update, $wpshop_db_options_update; |
|
| 221 | - $do_changes = false; |
|
| 222 | - |
|
| 223 | - require_once ABSPATH . 'wp-admin/includes/upgrade.php'; |
|
| 224 | - |
|
| 225 | - $current_db_version = get_option('wpshop_db_options', 0); |
|
| 226 | - $current_db_version = $current_db_version['db_version']; |
|
| 227 | - |
|
| 228 | - $current_def_max_version = max(array_keys($wpshop_update_way)); |
|
| 229 | - $new_version = $current_def_max_version + 1; |
|
| 230 | - $version_nb_delta = $current_def_max_version - $current_db_version; |
|
| 231 | - |
|
| 232 | - /* Check if there are modification to do */ |
|
| 233 | - if ($current_def_max_version >= $current_db_version) { |
|
| 234 | - /* Check the lowest version of db to execute */ |
|
| 235 | - $lowest_version_to_execute = $current_def_max_version - $version_nb_delta; |
|
| 236 | - |
|
| 237 | - for ($i = $lowest_version_to_execute; $i <= $current_def_max_version; $i++) { |
|
| 238 | - $do_changes = self::execute_operation_on_db_for_update($i); |
|
| 239 | - } |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - /* Update the db version option value */ |
|
| 243 | - if ($do_changes) { |
|
| 244 | - $db_version = get_option('wpshop_db_options', 0); |
|
| 245 | - $db_version['db_version'] = $new_version; |
|
| 246 | - update_option('wpshop_db_options', $db_version); |
|
| 247 | - } |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - /** |
|
| 251 | - * Update db structure on each plugin update |
|
| 252 | - * |
|
| 253 | - * @param integer $i The current plugin db version |
|
| 254 | - * @return boolean If the changes are done correctly or not |
|
| 255 | - */ |
|
| 256 | - public static function alter_db_structure_on_update($i) |
|
| 257 | - { |
|
| 258 | - $do_changes = false; |
|
| 259 | - global $wpdb, $wpshop_db_table, $wpshop_db_table_list, $wpshop_update_way, $wpshop_db_request, $wpshop_db_delete; |
|
| 260 | - |
|
| 261 | - /* Check if there are modification to do */ |
|
| 262 | - if (isset($wpshop_update_way[$i])) { |
|
| 263 | - /* Check if there are modification to make on table */ |
|
| 264 | - if (isset($wpshop_db_table_list[$i])) { |
|
| 265 | - foreach ($wpshop_db_table_list[$i] as $table_name) { |
|
| 266 | - dbDelta($wpshop_db_table[$table_name]); |
|
| 267 | - } |
|
| 268 | - $do_changes = true; |
|
| 269 | - } |
|
| 270 | - |
|
| 271 | - /* Request maker */ |
|
| 272 | - if (isset($wpshop_db_request[$i]) && is_array($wpshop_db_request) && is_array($wpshop_db_request[$i]) && (count($wpshop_db_request[$i]) > 0)) { |
|
| 273 | - foreach ($wpshop_db_request[$i] as $request) { |
|
| 274 | - $wpdb->query($request); |
|
| 275 | - $do_changes = true; |
|
| 276 | - } |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - /* Delete datas */ |
|
| 280 | - if (isset($wpshop_db_delete[$i]) && is_array($wpshop_db_delete) && is_array($wpshop_db_delete[$i]) && (count($wpshop_db_delete[$i]) > 0)) { |
|
| 281 | - foreach ($wpshop_db_delete[$i] as $request) { |
|
| 282 | - $wpdb->query($request); |
|
| 283 | - } |
|
| 284 | - } |
|
| 285 | - } |
|
| 286 | - |
|
| 287 | - return $do_changes; |
|
| 288 | - } |
|
| 289 | - |
|
| 290 | - /** |
|
| 291 | - * Do changes on database for wpshop plugin for a given version |
|
| 292 | - * |
|
| 293 | - * @param integer $i The wpshop db version to execute operation for |
|
| 294 | - * |
|
| 295 | - * @return boolean |
|
| 296 | - */ |
|
| 297 | - public static function execute_operation_on_db_for_update($i) |
|
| 298 | - { |
|
| 299 | - global $wpdb, $wpshop_db_table, $wpshop_db_table_list, $wpshop_update_way, $wpshop_db_content_add, $wpshop_db_content_update, $wpshop_db_options_add, $wpshop_eav_content, $wpshop_eav_content_update, $wpshop_db_options_update, $wpshop_db_request, $wpshop_db_delete; |
|
| 300 | - $do_changes = false; |
|
| 301 | - |
|
| 302 | - /* Check if there are modification to do */ |
|
| 303 | - if (isset($wpshop_update_way[$i])) { |
|
| 304 | - $do_changes = self::alter_db_structure_on_update($i); |
|
| 305 | - |
|
| 306 | - /********************/ |
|
| 307 | - /* Insert data */ |
|
| 308 | - /********************/ |
|
| 309 | - /* Options content */ |
|
| 310 | - if (isset($wpshop_db_options_add[$i]) && is_array($wpshop_db_options_add) && is_array($wpshop_db_options_add[$i]) && (count($wpshop_db_options_add[$i]) > 0)) { |
|
| 311 | - foreach ($wpshop_db_options_add[$i] as $option_name => $option_content) { |
|
| 312 | - add_option($option_name, $option_content, '', 'yes'); |
|
| 313 | - } |
|
| 314 | - $do_changes = true; |
|
| 315 | - } |
|
| 316 | - if (isset($wpshop_db_options_update[$i]) && is_array($wpshop_db_options_update) && is_array($wpshop_db_options_update[$i]) && (count($wpshop_db_options_update[$i]) > 0)) { |
|
| 317 | - foreach ($wpshop_db_options_update[$i] as $option_name => $option_content) { |
|
| 318 | - $option_current_content = get_option($option_name); |
|
| 319 | - foreach ($option_content as $option_key => $option_value) { |
|
| 320 | - $option_current_content[$option_key] = $option_value; |
|
| 321 | - } |
|
| 322 | - update_option($option_name, $option_current_content); |
|
| 323 | - } |
|
| 324 | - $do_changes = true; |
|
| 325 | - } |
|
| 326 | - |
|
| 327 | - /* Eav content */ |
|
| 328 | - if (isset($wpshop_eav_content[$i]) && is_array($wpshop_eav_content) && is_array($wpshop_eav_content[$i]) && (count($wpshop_eav_content[$i]) > 0)) { |
|
| 329 | - $do_changes = self::add_content_to_eav($wpshop_eav_content[$i], $do_changes); |
|
| 330 | - } |
|
| 331 | - /* Eav content update */ |
|
| 332 | - if (isset($wpshop_eav_content_update[$i]) && is_array($wpshop_eav_content_update) && is_array($wpshop_eav_content_update[$i]) && (count($wpshop_eav_content_update[$i]) > 0)) { |
|
| 333 | - $do_changes = self::add_content_to_eav($wpshop_eav_content_update[$i], $do_changes); |
|
| 334 | - } |
|
| 335 | - |
|
| 336 | - /* Add datas */ |
|
| 337 | - if (isset($wpshop_db_content_add[$i]) && is_array($wpshop_db_content_add) && is_array($wpshop_db_content_add[$i]) && (count($wpshop_db_content_add[$i]) > 0)) { |
|
| 338 | - foreach ($wpshop_db_content_add[$i] as $table_name => $def) { |
|
| 339 | - foreach ($def as $information_index => $table_information) { |
|
| 340 | - $wpdb->insert($table_name, $table_information, '%s'); |
|
| 341 | - $do_changes = true; |
|
| 342 | - } |
|
| 343 | - } |
|
| 344 | - } |
|
| 345 | - |
|
| 346 | - /* Update datas */ |
|
| 347 | - if (isset($wpshop_db_content_update[$i]) && is_array($wpshop_db_content_update) && is_array($wpshop_db_content_update[$i]) && (count($wpshop_db_content_update[$i]) > 0)) { |
|
| 348 | - foreach ($wpshop_db_content_update[$i] as $table_name => $def) { |
|
| 349 | - foreach ($def as $information_index => $table_information) { |
|
| 350 | - $wpdb->update($table_name, $table_information['datas'], $table_information['where'], '%s', '%s'); |
|
| 351 | - $do_changes = true; |
|
| 352 | - } |
|
| 353 | - } |
|
| 354 | - } |
|
| 355 | - } |
|
| 356 | - |
|
| 357 | - $do_changes = self::make_specific_operation_on_update($i); |
|
| 358 | - |
|
| 359 | - return $do_changes; |
|
| 360 | - } |
|
| 361 | - |
|
| 362 | - /** |
|
| 363 | - * Create specific data in eav db model |
|
| 364 | - * |
|
| 365 | - * @param array $eav_content The complete array with all element to create into database |
|
| 366 | - * @param boolean $do_changes The current state of changes to do |
|
| 367 | - * |
|
| 368 | - * @return boolean If there are changes to do or not |
|
| 369 | - */ |
|
| 370 | - public static function add_content_to_eav($eav_content, $do_changes) |
|
| 371 | - { |
|
| 372 | - global $wpdb; |
|
| 373 | - /* Create entities if entites are set to be created for the current version */ |
|
| 374 | - if (isset($eav_content['entities']) && is_array($eav_content['entities']) && is_array($eav_content['entities']) && (count($eav_content['entities']) > 0)) { |
|
| 375 | - foreach ($eav_content['entities'] as $entity) { |
|
| 376 | - /* Creation de l'entité produit dans la table des posts */ |
|
| 377 | - wpshop_entities::create_cpt_from_csv_file($entity); |
|
| 378 | - } |
|
| 379 | - $do_changes = true; |
|
| 380 | - } |
|
| 381 | - |
|
| 382 | - /* Create attributes for a given entity if attributes are set to be created for current version */ |
|
| 383 | - if (!empty($eav_content['attributes']) && is_array($eav_content['attributes']) && is_array($eav_content['attributes']) && (count($eav_content['attributes']) > 0)) { |
|
| 384 | - foreach ($eav_content['attributes'] as $entity_code) { |
|
| 385 | - wpshop_entities::create_cpt_attributes_from_csv_file($entity_code); |
|
| 386 | - } |
|
| 387 | - $do_changes = true; |
|
| 388 | - } |
|
| 389 | - |
|
| 390 | - /* Create attribute groups for a given entity if attributes groups are set to be created for current version */ |
|
| 391 | - if (isset($eav_content['attribute_groups']) && is_array($eav_content['attribute_groups']) && (count($eav_content['attribute_groups']) > 0)) { |
|
| 392 | - foreach ($eav_content['attribute_groups'] as $entity_code => $attribute_set) { |
|
| 393 | - $entity_id = wpshop_entities::get_entity_identifier_from_code($entity_code); |
|
| 394 | - |
|
| 395 | - if ($entity_id > 0) { |
|
| 396 | - foreach ($attribute_set as $set_name => $set_groups) { |
|
| 397 | - $query = $wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE_SET . " WHERE entity_id = %d AND name = LOWER(%s)", $entity_id, wpshop_tools::slugify($set_name, array('noAccent', 'noSpaces', 'lowerCase'))); |
|
| 398 | - $attribute_set_id = $wpdb->get_var($query); |
|
| 399 | - if ($attribute_set_id <= 0) { |
|
| 400 | - $attribute_set_content = array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'entity_id' => $entity_id, 'name' => $set_name); |
|
| 401 | - if ($set_name == 'default') { |
|
| 402 | - $attribute_set_content['default_set'] = 'yes'; |
|
| 403 | - } |
|
| 404 | - $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_SET, $attribute_set_content); |
|
| 405 | - $attribute_set_id = $wpdb->insert_id; |
|
| 406 | - } |
|
| 28 | + /** |
|
| 29 | + * Define the action launch when plugin is activate |
|
| 30 | + * |
|
| 31 | + * @return void |
|
| 32 | + */ |
|
| 33 | + public static function install_on_activation() |
|
| 34 | + { |
|
| 35 | + /* Create the different option needed for the plugin work properly */ |
|
| 36 | + add_option('wpshop_db_options', array('db_version' => 0)); |
|
| 37 | + add_option('wpshop_shop_default_currency', WPSHOP_SHOP_DEFAULT_CURRENCY); |
|
| 38 | + add_option('wpshop_emails', array('noreply_email' => get_bloginfo('admin_email'), 'contact_email' => get_bloginfo('admin_email'))); |
|
| 39 | + add_option('wpshop_catalog_product_option', array('wpshop_catalog_product_slug' => WPSHOP_CATALOG_PRODUCT_SLUG)); |
|
| 40 | + add_option('wpshop_catalog_categories_option', array('wpshop_catalog_categories_slug' => WPSHOP_CATALOG_CATEGORIES_SLUG)); |
|
| 41 | + add_option('wpshop_display_option', array('wpshop_display_list_type' => 'grid', 'wpshop_display_grid_element_number' => '3', 'wpshop_display_cat_sheet_output' => array('category_description', 'category_subcategory', 'category_subproduct'))); |
|
| 42 | + } |
|
| 407 | 43 | |
| 408 | - if ($attribute_set_id > 0) { |
|
| 409 | - foreach ($set_groups as $set_group_infos) { |
|
| 410 | - $set_group_infos_details = $set_group_infos['details']; |
|
| 411 | - unset($set_group_infos['details']); |
|
| 412 | - /* Change an attribute set status if definition specify this param */ |
|
| 413 | - if (isset($set_group_infos['status'])) { |
|
| 414 | - $wpdb->update(WPSHOP_DBT_ATTRIBUTE_SET, array('last_update_date' => current_time('mysql', 0), 'status' => $set_group_infos['status']), array('id' => $attribute_set_id)); |
|
| 415 | - } |
|
| 416 | - $query = $wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE_GROUP . " WHERE attribute_set_id = %d AND code = LOWER(%s)", $attribute_set_id, $set_group_infos['code']); |
|
| 417 | - $attribute_set_section_id = $wpdb->get_var($query); |
|
| 418 | - if ($attribute_set_section_id <= 0) { |
|
| 419 | - $new_set_section_infos = $set_group_infos; |
|
| 420 | - $new_set_section_infos['status'] = (isset($new_set_section_infos['status']) ? $new_set_section_infos['status'] : 'valid'); |
|
| 421 | - $new_set_section_infos['creation_date'] = current_time('mysql', 0); |
|
| 422 | - $new_set_section_infos['attribute_set_id'] = $attribute_set_id; |
|
| 423 | - $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_GROUP, $new_set_section_infos); |
|
| 424 | - $attribute_set_section_id = $wpdb->insert_id; |
|
| 425 | - } |
|
| 426 | - |
|
| 427 | - if (($attribute_set_section_id > 0) && (isset($set_group_infos_details) && is_array($set_group_infos_details) && (count($set_group_infos_details) > 0))) { |
|
| 428 | - $query = $wpdb->prepare("SELECT MAX(position) AS position FROM " . WPSHOP_DBT_ATTRIBUTE_DETAILS . " WHERE entity_type_id = %d AND attribute_set_id = %d AND attribute_group_id = %d", $entity_id, $attribute_set_id, $attribute_set_section_id); |
|
| 429 | - $last_position = $wpdb->get_var($query); |
|
| 430 | - $position = (int) $last_position + 1; |
|
| 431 | - foreach ($set_group_infos_details as $attribute_code) { |
|
| 432 | - $query = $wpdb->prepare("SELECT * FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE code = %s AND entity_id = %d", $attribute_code, $entity_id); |
|
| 433 | - $attribute_id = $wpdb->get_row($query); |
|
| 434 | - |
|
| 435 | - if ($attribute_id->id > 0) { |
|
| 436 | - $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'entity_type_id' => $entity_id, 'attribute_set_id' => $attribute_set_id, 'attribute_group_id' => $attribute_set_section_id, 'attribute_id' => $attribute_id->id, 'position' => $position)); |
|
| 437 | - $position++; |
|
| 438 | - } |
|
| 439 | - } |
|
| 440 | - } |
|
| 44 | + /** |
|
| 45 | + * Create the default pages |
|
| 46 | + */ |
|
| 47 | + public static function wpshop_insert_default_pages($pages_type = '') |
|
| 48 | + { |
|
| 49 | + global $wpdb, $wp_rewrite; |
|
| 50 | + |
|
| 51 | + /** if we will create any new pages we need to flush page cache */ |
|
| 52 | + $page_creation = false; |
|
| 53 | + $created_pages = array(); |
|
| 54 | + |
|
| 55 | + /** Default data array for add page */ |
|
| 56 | + $page_default_args = array( |
|
| 57 | + 'post_type' => 'page', |
|
| 58 | + 'comment_status' => 'closed', |
|
| 59 | + 'ping_status' => 'closed', |
|
| 60 | + 'post_status' => 'publish', |
|
| 61 | + 'post_author' => get_current_user_id(), |
|
| 62 | + ); |
|
| 63 | + |
|
| 64 | + /** Get defined shop type */ |
|
| 65 | + $wpshop_shop_type = !empty($pages_type) ? $pages_type : get_option('wpshop_shop_type', WPSHOP_DEFAULT_SHOP_TYPE); |
|
| 66 | + |
|
| 67 | + /** Get the default datas for installation - Pages */ |
|
| 68 | + $xml_default_pages = file_get_contents(WP_PLUGIN_DIR . '/' . WPSHOP_PLUGIN_DIR . '/assets/datas/default_pages.xml'); |
|
| 69 | + $defined_default_pages = new SimpleXMLElement($xml_default_pages); |
|
| 70 | + foreach ($defined_default_pages->xpath('//pages/page') as $page) { |
|
| 71 | + if (($wpshop_shop_type == $page->attributes()->shop_type) || ('sale' == $wpshop_shop_type)) { |
|
| 72 | + $page_id = null; |
|
| 73 | + |
|
| 74 | + /** Do a specific check for cart page, for old wpshop installation */ |
|
| 75 | + if ('wpshop_cart_page_id' == (string) $page->attributes()->code) { |
|
| 76 | + $query = $wpdb->prepare("SELECT ID FROM " . $wpdb->posts . " WHERE post_content LIKE %s AND post_type != %s", '%[wpshop_basket]%', 'revision'); |
|
| 77 | + $page_id = $wpdb->get_var($query); |
|
| 78 | + |
|
| 79 | + wp_update_post(array( |
|
| 80 | + 'ID' => $page_id, |
|
| 81 | + 'post_content' => (string) $page->content, |
|
| 82 | + )); |
|
| 83 | + } |
|
| 441 | 84 | |
| 442 | - } |
|
| 443 | - } |
|
| 444 | - } |
|
| 445 | - } |
|
| 446 | - } |
|
| 447 | - $do_changes = true; |
|
| 448 | - } |
|
| 449 | - |
|
| 450 | - return $do_changes; |
|
| 451 | - } |
|
| 452 | - |
|
| 453 | - /** |
|
| 454 | - * Update specific data in eav db model |
|
| 455 | - * |
|
| 456 | - * @param array $eav_content The complete array with all element to create into database |
|
| 457 | - * @param boolean $do_changes The current state of changes to do |
|
| 458 | - * |
|
| 459 | - * @return boolean If there are changes to do or not |
|
| 460 | - */ |
|
| 461 | - public static function update_eav_content($eav_content, $do_changes) |
|
| 462 | - { |
|
| 463 | - /* Update attributes fo a given entity if attributes are set to be updated for current version */ |
|
| 464 | - if (isset($eav_content['attributes']) && is_array($eav_content['attributes']) && (count($eav_content['attributes']) > 0)) { |
|
| 465 | - foreach ($eav_content['attributes'] as $entity_code => $attribute_definition) { |
|
| 466 | - foreach ($attribute_definition as $attribute_def) { |
|
| 467 | - $option_list_for_attribute = ''; |
|
| 468 | - if (isset($attribute_def['backend_input_values'])) { |
|
| 469 | - $option_list_for_attribute = $attribute_def['backend_input_values']; |
|
| 470 | - unset($attribute_def['backend_input_values']); |
|
| 471 | - } |
|
| 85 | + /** Check if a page exists with the current content readed form xml file */ |
|
| 86 | + if (empty($page_id)) { |
|
| 87 | + $query = $wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_content LIKE %s AND post_type != %s", '%' . (string) $page->content . '%', 'revision'); |
|
| 88 | + $page_id = $wpdb->get_var($query); |
|
| 89 | + } |
|
| 472 | 90 | |
| 473 | - /* Get entity identifier from code */ |
|
| 474 | - $attribute_def['entity_id'] = wpshop_entities::get_entity_identifier_from_code($entity_code); |
|
| 475 | - $attribute_def['status'] = $attribute_def['attribute_status']; |
|
| 476 | - unset($attribute_def['attribute_status']); |
|
| 477 | - $attribute_def['last_update_date'] = current_time('mysql', 0); |
|
| 478 | - $wpdb->update(WPSHOP_DBT_ATTRIBUTE, $attribute_def, array('code' => $attribute_def['code'])); |
|
| 479 | - $attribute_id = $wpdb->get_var($wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE code = %s", $attribute_def['code'])); |
|
| 480 | - |
|
| 481 | - /* Insert option values if there are some to add for the current attribute */ |
|
| 482 | - if (($option_list_for_attribute != '') && (is_array($option_list_for_attribute))) { |
|
| 483 | - foreach ($option_list_for_attribute as $option_code => $option_value) { |
|
| 484 | - $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS, array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'attribute_id' => $attribute_id, 'label' => ((substr($option_code, 0, 2) != '__') ? $option_value : __(substr($option_code, 2), 'wpshop')), 'value' => $option_value)); |
|
| 485 | - if ($option_code == $attribute_def['default_value']) { |
|
| 486 | - $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('last_update_date' => current_time('mysql', 0), 'default_value' => $wpdb->insert_id), array('id' => $attribute_id, 'default_value' => $option_code)); |
|
| 487 | - } |
|
| 488 | - } |
|
| 489 | - } |
|
| 490 | - } |
|
| 491 | - } |
|
| 492 | - $do_changes = true; |
|
| 493 | - } |
|
| 494 | - |
|
| 495 | - /* Update attribute groups fo a given entity if attributes groups are set to be updated for current version */ |
|
| 496 | - if (is_array($eav_content['attribute_groups']) && is_array($eav_content['attribute_groups']) && (count($eav_content['attribute_groups']) > 0)) { |
|
| 497 | - foreach ($eav_content['attribute_groups'] as $entity_code => $attribute_set) { |
|
| 498 | - $entity_id = wpshop_entities::get_entity_identifier_from_code($entity_code); |
|
| 499 | - |
|
| 500 | - if ($entity_id > 0) { |
|
| 501 | - foreach ($attribute_set as $set_name => $set_groups) { |
|
| 502 | - $query = $wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE_SET . " WHERE entity_id = %d AND name = LOWER(%s)", $entity_id, wpshop_tools::slugify($set_name, array('noAccent', 'noSpaces', 'lowerCase'))); |
|
| 503 | - $attribute_set_id = $wpdb->get_var($query); |
|
| 504 | - if ($attribute_set_id <= 0) { |
|
| 505 | - $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_SET, array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'entity_id' => $entity_id, 'name' => $set_name)); |
|
| 506 | - $attribute_set_id = $wpdb->insert_id; |
|
| 507 | - } |
|
| 91 | + /** If the page does not exists create it */ |
|
| 92 | + if (empty($page_id)) { |
|
| 93 | + $default_page_args = wp_parse_args(array( |
|
| 94 | + 'post_title' => __((string) $page->title, 'wpshop'), |
|
| 95 | + 'post_name' => __((string) $page->slug, 'wpshop'), |
|
| 96 | + 'post_content' => __((string) $page->content, 'wpshop'), |
|
| 97 | + 'menu_order' => (string) $page->attributes()->position, |
|
| 98 | + ), $page_default_args); |
|
| 99 | + |
|
| 100 | + $page_id = wp_insert_post($default_page_args); |
|
| 101 | + $created_pages[] = (string) $page->attributes()->code; |
|
| 102 | + } |
|
| 508 | 103 | |
| 509 | - if ($attribute_set_id > 0) { |
|
| 510 | - foreach ($set_groups as $set_group_infos) { |
|
| 511 | - $set_group_infos_details = $set_group_infos['details']; |
|
| 512 | - unset($set_group_infos['details']); |
|
| 513 | - /* Change an attribute set status if definition specify this param */ |
|
| 514 | - if (isset($set_group_infos['status'])) { |
|
| 515 | - $wpdb->update(WPSHOP_DBT_ATTRIBUTE_SET, array('last_update_date' => current_time('mysql', 0), 'status' => $set_group_infos['status']), array('id' => $attribute_set_id)); |
|
| 516 | - } |
|
| 517 | - $query = $wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE_GROUP . " WHERE attribute_set_id = %d AND code = LOWER(%s)", $attribute_set_id, $set_group_infos['code']); |
|
| 518 | - $attribute_set_section_id = $wpdb->get_var($query); |
|
| 519 | - if ($attribute_set_section_id <= 0) { |
|
| 520 | - $new_set_section_infos = $set_group_infos; |
|
| 521 | - $new_set_section_infos['status'] = (isset($new_set_section_infos['status']) ? $new_set_section_infos['status'] : 'valid'); |
|
| 522 | - $new_set_section_infos['creation_date'] = current_time('mysql', 0); |
|
| 523 | - $new_set_section_infos['attribute_set_id'] = $attribute_set_id; |
|
| 524 | - $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_GROUP, $new_set_section_infos); |
|
| 525 | - $attribute_set_section_id = $wpdb->insert_id; |
|
| 526 | - } else { |
|
| 527 | - $new_set_section_infos = $set_group_infos; |
|
| 528 | - $new_set_section_infos['last_update_date'] = current_time('mysql', 0); |
|
| 529 | - $wpdb->update(WPSHOP_DBT_ATTRIBUTE_GROUP, $new_set_section_infos, array('id' => $attribute_set_section_id)); |
|
| 530 | - } |
|
| 531 | - |
|
| 532 | - if (($attribute_set_section_id > 0) && (isset($set_group_infos_details) && is_array($set_group_infos_details))) { |
|
| 533 | - if (count($set_group_infos_details) <= 0) { |
|
| 534 | - $wpdb->update(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('last_update_date' => current_time('mysql', 0), 'status' => 'deleted'), array('entity_type_id' => $entity_id, 'attribute_set_id' => $attribute_set_id, 'attribute_group_id' => $attribute_set_section_id)); |
|
| 535 | - } else { |
|
| 536 | - $query = $wpdb->prepare("SELECT MAX(position) AS position FROM " . WPSHOP_DBT_ATTRIBUTE_DETAILS . " WHERE entity_type_id = %d AND attribute_set_id = %d AND attribute_group_id = %d", $entity_id, $attribute_set_id, $attribute_set_section_id); |
|
| 537 | - $last_position = $wpdb->get_var($query); |
|
| 538 | - $position = (int) $last_position + 1; |
|
| 539 | - foreach ($set_group_infos_details as $attribute_code) { |
|
| 540 | - $query = $wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE code = %s AND entity_id = %d", $attribute_code, $entity_id); |
|
| 541 | - $attribute_id = $wpdb->get_var($query); |
|
| 542 | - if ($attribute_id > 0) { |
|
| 543 | - $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'entity_type_id' => $entity_id, 'attribute_set_id' => $attribute_set_id, 'attribute_group_id' => $attribute_set_section_id, 'attribute_id' => $attribute_id, 'position' => $position)); |
|
| 544 | - $position++; |
|
| 545 | - } |
|
| 546 | - } |
|
| 547 | - } |
|
| 548 | - } |
|
| 549 | - } |
|
| 550 | - } |
|
| 551 | - } |
|
| 552 | - } |
|
| 553 | - } |
|
| 554 | - $do_changes = true; |
|
| 555 | - } |
|
| 556 | - |
|
| 557 | - return $do_changes; |
|
| 558 | - } |
|
| 559 | - |
|
| 560 | - /** |
|
| 561 | - * Manage special operation on wpshop plugin update |
|
| 562 | - */ |
|
| 563 | - public static function make_specific_operation_on_update($version) |
|
| 564 | - { |
|
| 565 | - global $wpdb, $wp_rewrite; |
|
| 566 | - $wpshop_shop_type = get_option('wpshop_shop_type', WPSHOP_DEFAULT_SHOP_TYPE); |
|
| 567 | - |
|
| 568 | - switch ($version) { |
|
| 569 | - case 3: |
|
| 570 | - case 6: |
|
| 571 | - self::wpshop_insert_default_pages($wpshop_shop_type); |
|
| 572 | - wp_cache_flush(); |
|
| 573 | - return true; |
|
| 574 | - break; |
|
| 575 | - case 8: |
|
| 576 | - /** Change metaboxes order for product in case it already exists */ |
|
| 577 | - $query = $wpdb->prepare("SELECT umeta_id, meta_value FROM {$wpdb->usermeta} WHERE meta_key = %s", 'meta-box-order_wpshop_product'); |
|
| 578 | - $customer_metaboxes_order = $wpdb->get_results($query); |
|
| 579 | - if (!empty($customer_metaboxes_order)) { |
|
| 580 | - foreach ($customer_metaboxes_order as $customer_metabox_order) { |
|
| 581 | - $do_changes = false; |
|
| 582 | - $current_order = unserialize($customer_metabox_order->meta_value); |
|
| 583 | - if (array_key_exists('normal', $current_order) && (false !== strpos('wpshop_product_important_datas', $current_order['normal']))) { |
|
| 584 | - str_replace('wpshop_product_important_datas,', '', $current_order['normal']); |
|
| 585 | - $do_changes = true; |
|
| 586 | - } |
|
| 104 | + /** If the page is created or already exists associated the page to the good service */ |
|
| 105 | + if (!empty($page_id)) { |
|
| 106 | + add_option((string) $page->attributes()->code, $page_id); |
|
| 587 | 107 | |
| 588 | - if (array_key_exists('side', $current_order)) { |
|
| 589 | - str_replace('wpshop_product_important_datas,', '', $current_order['side']); |
|
| 590 | - str_replace('submitdiv,', 'submitdiv,wpshop_product_important_datas,', $current_order['side']); |
|
| 591 | - $do_changes = true; |
|
| 592 | - } |
|
| 108 | + $page_creation = true; |
|
| 109 | + } |
|
| 593 | 110 | |
| 594 | - if (true === $do_changes) { |
|
| 595 | - $wpdb->update($wpdb->usermeta, array('meta_value' => serialize($current_order)), array('umeta_id' => $customer_metabox_order->umeta_id)); |
|
| 596 | - } |
|
| 597 | - } |
|
| 598 | - } else { |
|
| 599 | - $users = get_users(array('role' => 'administrator')); |
|
| 600 | - if (!empty($users)) { |
|
| 601 | - foreach ($users as $user) { |
|
| 602 | - $user_meta = array( |
|
| 603 | - 'side' => 'submitdiv,formatdiv,wpshop_product_important_datas,wpshop_product_categorydiv,pageparentdiv,wps_barcode_product,wpshop_product_actions,wpshop_product_options,postimagediv', |
|
| 604 | - 'normal' => 'wpshop_product_fixed_tab,postexcerpt,trackbacksdiv,postcustom,commentstatusdiv,slugdiv,authordiv,wpshop_wpshop_variations,wps_media_manager,wpshop_product_order_historic', |
|
| 605 | - 'advanced' => '', |
|
| 606 | - ); |
|
| 607 | - update_user_meta($user->ID, 'meta-box-order_wpshop_product', $user_meta); |
|
| 608 | - } |
|
| 609 | - } |
|
| 610 | - } |
|
| 111 | + } |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + /** Check if page have been created in order to do specific action */ |
|
| 115 | + if (!empty($created_pages)) { |
|
| 116 | + /** If cart page and checkout page have just been created, change cart page id into checkout page id */ |
|
| 117 | + if (in_array('wpshop_cart_page_id', $created_pages) && in_array('wpshop_checkout_page_id', $created_pages)) { |
|
| 118 | + update_option('wpshop_cart_page_id', get_option('wpshop_checkout_page_id')); |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + wp_cache_flush(); |
|
| 124 | + /** If new page => empty cache */ |
|
| 125 | + if ($page_creation) { |
|
| 126 | + wp_cache_delete('all_page_ids', 'pages'); |
|
| 127 | + // $wp_rewrite->flush_rules(); |
|
| 128 | + } |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + /** |
|
| 132 | + * Insert sample datas when installing wpshop the first time if the admin choose |
|
| 133 | + */ |
|
| 134 | + public static function import_sample_datas() |
|
| 135 | + { |
|
| 136 | + global $wpdb, $wp_rewrite; |
|
| 137 | + |
|
| 138 | + /** Default data array for add product */ |
|
| 139 | + $product_default_args = array( |
|
| 140 | + 'comment_status' => 'closed', |
|
| 141 | + 'ping_status' => 'closed', |
|
| 142 | + 'post_status' => 'publish', |
|
| 143 | + 'post_author' => get_current_user_id(), |
|
| 144 | + ); |
|
| 145 | + |
|
| 146 | + /** Get the default datas for installation - sample products */ |
|
| 147 | + $sample_datas = file_get_contents(WP_PLUGIN_DIR . '/' . WPSHOP_PLUGIN_DIR . '/assets/datas/sample_datas.xml'); |
|
| 148 | + $defined_sample_datas = new SimpleXMLElement($sample_datas, LIBXML_NOCDATA); |
|
| 149 | + |
|
| 150 | + $namespaces = $defined_sample_datas->getDocNamespaces(); |
|
| 151 | + if (!isset($namespaces['wp'])) { |
|
| 152 | + $namespaces['wp'] = 'http://wordpress.org/export/1.1/'; |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + if (!isset($namespaces['excerpt'])) { |
|
| 156 | + $namespaces['excerpt'] = 'http://wordpress.org/export/1.1/excerpt/'; |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + foreach ($defined_sample_datas->xpath('//wpshop_products/wpshop_product') as $product) { |
|
| 160 | + $dc = $product->children('http://purl.org/dc/elements/1.1/'); |
|
| 161 | + $content = $product->children('http://purl.org/rss/1.0/modules/content/'); |
|
| 162 | + $excerpt = $product->children($namespaces['excerpt']); |
|
| 163 | + $wp = $product->children($namespaces['wp']); |
|
| 164 | + |
|
| 165 | + $product_args = wp_parse_args(array( |
|
| 166 | + 'post_title' => (string) $product->title, |
|
| 167 | + 'post_name' => (string) $wp->post_name, |
|
| 168 | + 'post_content' => (string) $content->encoded, |
|
| 169 | + 'post_excerpt' => (string) $excerpt->encoded, |
|
| 170 | + 'post_type' => (string) $wp->post_type, |
|
| 171 | + ), $product_default_args); |
|
| 172 | + |
|
| 173 | + $product_id = wp_insert_post($product_args); |
|
| 174 | + |
|
| 175 | + foreach ($wp->postmeta as $meta) { |
|
| 176 | + update_post_meta($product_id, (string) $meta->meta_key, (string) $meta->meta_value); |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + foreach ($defined_sample_datas->xpath('//wps_pdt_variations/wps_pdt_variation/wp:post_parent[. ="' . $wp->post_id . '"]/parent::*') as $product_variation) { |
|
| 180 | + $wps_pdt_var_dc = $product_variation->children('http://purl.org/dc/elements/1.1/'); |
|
| 181 | + $wps_pdt_var_content = $product_variation->children('http://purl.org/rss/1.0/modules/content/'); |
|
| 182 | + $wps_pdt_var_excerpt = $product_variation->children($namespaces['excerpt']); |
|
| 183 | + $wps_pdt_var_wp = $product_variation->children($namespaces['wp']); |
|
| 184 | + |
|
| 185 | + $product_args = wp_parse_args(array( |
|
| 186 | + 'post_title' => (string) $product_variation->title, |
|
| 187 | + 'post_name' => (string) $wps_pdt_var_wp->post_name, |
|
| 188 | + 'post_content' => (string) $wps_pdt_var_content->encoded, |
|
| 189 | + 'post_excerpt' => (string) $wps_pdt_var_excerpt->encoded, |
|
| 190 | + 'post_type' => (string) $wps_pdt_var_wp->post_type, |
|
| 191 | + 'post_parent' => $product_id, |
|
| 192 | + ), $product_default_args); |
|
| 193 | + |
|
| 194 | + $product_variation_id = wp_insert_post($product_args); |
|
| 195 | + |
|
| 196 | + foreach ($wps_pdt_var_wp->postmeta as $meta) { |
|
| 197 | + update_post_meta($product_variation_id, (string) $meta->meta_key, (string) $meta->meta_value); |
|
| 198 | + } |
|
| 199 | + } |
|
| 200 | + } |
|
| 201 | + } |
|
| 202 | + |
|
| 203 | + /** |
|
| 204 | + * Method called when plugin is loaded for database update. This method allows to update the database structure, insert default content. |
|
| 205 | + */ |
|
| 206 | + public static function update_wpshop_dev() |
|
| 207 | + { |
|
| 208 | + global $wpdb, $wpshop_db_table, $wpshop_db_table_list, $wpshop_update_way, $wpshop_db_content_add, $wpshop_db_content_update, $wpshop_db_options_add, $wpshop_eav_content, $wpshop_eav_content_update, $wpshop_db_options_update; |
|
| 209 | + |
|
| 210 | + require_once ABSPATH . 'wp-admin/includes/upgrade.php'; |
|
| 211 | + |
|
| 212 | + self::execute_operation_on_db_for_update('dev'); |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + /** |
|
| 216 | + * Method called when plugin is loaded for database update. This method allows to update the database structure, insert default content. |
|
| 217 | + */ |
|
| 218 | + public static function update_wpshop() |
|
| 219 | + { |
|
| 220 | + global $wpdb, $wpshop_db_table, $wpshop_db_table_list, $wpshop_update_way, $wpshop_db_content_add, $wpshop_db_content_update, $wpshop_db_options_add, $wpshop_eav_content, $wpshop_eav_content_update, $wpshop_db_options_update; |
|
| 221 | + $do_changes = false; |
|
| 222 | + |
|
| 223 | + require_once ABSPATH . 'wp-admin/includes/upgrade.php'; |
|
| 224 | + |
|
| 225 | + $current_db_version = get_option('wpshop_db_options', 0); |
|
| 226 | + $current_db_version = $current_db_version['db_version']; |
|
| 227 | + |
|
| 228 | + $current_def_max_version = max(array_keys($wpshop_update_way)); |
|
| 229 | + $new_version = $current_def_max_version + 1; |
|
| 230 | + $version_nb_delta = $current_def_max_version - $current_db_version; |
|
| 231 | + |
|
| 232 | + /* Check if there are modification to do */ |
|
| 233 | + if ($current_def_max_version >= $current_db_version) { |
|
| 234 | + /* Check the lowest version of db to execute */ |
|
| 235 | + $lowest_version_to_execute = $current_def_max_version - $version_nb_delta; |
|
| 236 | + |
|
| 237 | + for ($i = $lowest_version_to_execute; $i <= $current_def_max_version; $i++) { |
|
| 238 | + $do_changes = self::execute_operation_on_db_for_update($i); |
|
| 239 | + } |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + /* Update the db version option value */ |
|
| 243 | + if ($do_changes) { |
|
| 244 | + $db_version = get_option('wpshop_db_options', 0); |
|
| 245 | + $db_version['db_version'] = $new_version; |
|
| 246 | + update_option('wpshop_db_options', $db_version); |
|
| 247 | + } |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + /** |
|
| 251 | + * Update db structure on each plugin update |
|
| 252 | + * |
|
| 253 | + * @param integer $i The current plugin db version |
|
| 254 | + * @return boolean If the changes are done correctly or not |
|
| 255 | + */ |
|
| 256 | + public static function alter_db_structure_on_update($i) |
|
| 257 | + { |
|
| 258 | + $do_changes = false; |
|
| 259 | + global $wpdb, $wpshop_db_table, $wpshop_db_table_list, $wpshop_update_way, $wpshop_db_request, $wpshop_db_delete; |
|
| 260 | + |
|
| 261 | + /* Check if there are modification to do */ |
|
| 262 | + if (isset($wpshop_update_way[$i])) { |
|
| 263 | + /* Check if there are modification to make on table */ |
|
| 264 | + if (isset($wpshop_db_table_list[$i])) { |
|
| 265 | + foreach ($wpshop_db_table_list[$i] as $table_name) { |
|
| 266 | + dbDelta($wpshop_db_table[$table_name]); |
|
| 267 | + } |
|
| 268 | + $do_changes = true; |
|
| 269 | + } |
|
| 270 | + |
|
| 271 | + /* Request maker */ |
|
| 272 | + if (isset($wpshop_db_request[$i]) && is_array($wpshop_db_request) && is_array($wpshop_db_request[$i]) && (count($wpshop_db_request[$i]) > 0)) { |
|
| 273 | + foreach ($wpshop_db_request[$i] as $request) { |
|
| 274 | + $wpdb->query($request); |
|
| 275 | + $do_changes = true; |
|
| 276 | + } |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + /* Delete datas */ |
|
| 280 | + if (isset($wpshop_db_delete[$i]) && is_array($wpshop_db_delete) && is_array($wpshop_db_delete[$i]) && (count($wpshop_db_delete[$i]) > 0)) { |
|
| 281 | + foreach ($wpshop_db_delete[$i] as $request) { |
|
| 282 | + $wpdb->query($request); |
|
| 283 | + } |
|
| 284 | + } |
|
| 285 | + } |
|
| 286 | + |
|
| 287 | + return $do_changes; |
|
| 288 | + } |
|
| 289 | + |
|
| 290 | + /** |
|
| 291 | + * Do changes on database for wpshop plugin for a given version |
|
| 292 | + * |
|
| 293 | + * @param integer $i The wpshop db version to execute operation for |
|
| 294 | + * |
|
| 295 | + * @return boolean |
|
| 296 | + */ |
|
| 297 | + public static function execute_operation_on_db_for_update($i) |
|
| 298 | + { |
|
| 299 | + global $wpdb, $wpshop_db_table, $wpshop_db_table_list, $wpshop_update_way, $wpshop_db_content_add, $wpshop_db_content_update, $wpshop_db_options_add, $wpshop_eav_content, $wpshop_eav_content_update, $wpshop_db_options_update, $wpshop_db_request, $wpshop_db_delete; |
|
| 300 | + $do_changes = false; |
|
| 301 | + |
|
| 302 | + /* Check if there are modification to do */ |
|
| 303 | + if (isset($wpshop_update_way[$i])) { |
|
| 304 | + $do_changes = self::alter_db_structure_on_update($i); |
|
| 305 | + |
|
| 306 | + /********************/ |
|
| 307 | + /* Insert data */ |
|
| 308 | + /********************/ |
|
| 309 | + /* Options content */ |
|
| 310 | + if (isset($wpshop_db_options_add[$i]) && is_array($wpshop_db_options_add) && is_array($wpshop_db_options_add[$i]) && (count($wpshop_db_options_add[$i]) > 0)) { |
|
| 311 | + foreach ($wpshop_db_options_add[$i] as $option_name => $option_content) { |
|
| 312 | + add_option($option_name, $option_content, '', 'yes'); |
|
| 313 | + } |
|
| 314 | + $do_changes = true; |
|
| 315 | + } |
|
| 316 | + if (isset($wpshop_db_options_update[$i]) && is_array($wpshop_db_options_update) && is_array($wpshop_db_options_update[$i]) && (count($wpshop_db_options_update[$i]) > 0)) { |
|
| 317 | + foreach ($wpshop_db_options_update[$i] as $option_name => $option_content) { |
|
| 318 | + $option_current_content = get_option($option_name); |
|
| 319 | + foreach ($option_content as $option_key => $option_value) { |
|
| 320 | + $option_current_content[$option_key] = $option_value; |
|
| 321 | + } |
|
| 322 | + update_option($option_name, $option_current_content); |
|
| 323 | + } |
|
| 324 | + $do_changes = true; |
|
| 325 | + } |
|
| 326 | + |
|
| 327 | + /* Eav content */ |
|
| 328 | + if (isset($wpshop_eav_content[$i]) && is_array($wpshop_eav_content) && is_array($wpshop_eav_content[$i]) && (count($wpshop_eav_content[$i]) > 0)) { |
|
| 329 | + $do_changes = self::add_content_to_eav($wpshop_eav_content[$i], $do_changes); |
|
| 330 | + } |
|
| 331 | + /* Eav content update */ |
|
| 332 | + if (isset($wpshop_eav_content_update[$i]) && is_array($wpshop_eav_content_update) && is_array($wpshop_eav_content_update[$i]) && (count($wpshop_eav_content_update[$i]) > 0)) { |
|
| 333 | + $do_changes = self::add_content_to_eav($wpshop_eav_content_update[$i], $do_changes); |
|
| 334 | + } |
|
| 335 | + |
|
| 336 | + /* Add datas */ |
|
| 337 | + if (isset($wpshop_db_content_add[$i]) && is_array($wpshop_db_content_add) && is_array($wpshop_db_content_add[$i]) && (count($wpshop_db_content_add[$i]) > 0)) { |
|
| 338 | + foreach ($wpshop_db_content_add[$i] as $table_name => $def) { |
|
| 339 | + foreach ($def as $information_index => $table_information) { |
|
| 340 | + $wpdb->insert($table_name, $table_information, '%s'); |
|
| 341 | + $do_changes = true; |
|
| 342 | + } |
|
| 343 | + } |
|
| 344 | + } |
|
| 345 | + |
|
| 346 | + /* Update datas */ |
|
| 347 | + if (isset($wpshop_db_content_update[$i]) && is_array($wpshop_db_content_update) && is_array($wpshop_db_content_update[$i]) && (count($wpshop_db_content_update[$i]) > 0)) { |
|
| 348 | + foreach ($wpshop_db_content_update[$i] as $table_name => $def) { |
|
| 349 | + foreach ($def as $information_index => $table_information) { |
|
| 350 | + $wpdb->update($table_name, $table_information['datas'], $table_information['where'], '%s', '%s'); |
|
| 351 | + $do_changes = true; |
|
| 352 | + } |
|
| 353 | + } |
|
| 354 | + } |
|
| 355 | + } |
|
| 356 | + |
|
| 357 | + $do_changes = self::make_specific_operation_on_update($i); |
|
| 358 | + |
|
| 359 | + return $do_changes; |
|
| 360 | + } |
|
| 361 | + |
|
| 362 | + /** |
|
| 363 | + * Create specific data in eav db model |
|
| 364 | + * |
|
| 365 | + * @param array $eav_content The complete array with all element to create into database |
|
| 366 | + * @param boolean $do_changes The current state of changes to do |
|
| 367 | + * |
|
| 368 | + * @return boolean If there are changes to do or not |
|
| 369 | + */ |
|
| 370 | + public static function add_content_to_eav($eav_content, $do_changes) |
|
| 371 | + { |
|
| 372 | + global $wpdb; |
|
| 373 | + /* Create entities if entites are set to be created for the current version */ |
|
| 374 | + if (isset($eav_content['entities']) && is_array($eav_content['entities']) && is_array($eav_content['entities']) && (count($eav_content['entities']) > 0)) { |
|
| 375 | + foreach ($eav_content['entities'] as $entity) { |
|
| 376 | + /* Creation de l'entité produit dans la table des posts */ |
|
| 377 | + wpshop_entities::create_cpt_from_csv_file($entity); |
|
| 378 | + } |
|
| 379 | + $do_changes = true; |
|
| 380 | + } |
|
| 381 | + |
|
| 382 | + /* Create attributes for a given entity if attributes are set to be created for current version */ |
|
| 383 | + if (!empty($eav_content['attributes']) && is_array($eav_content['attributes']) && is_array($eav_content['attributes']) && (count($eav_content['attributes']) > 0)) { |
|
| 384 | + foreach ($eav_content['attributes'] as $entity_code) { |
|
| 385 | + wpshop_entities::create_cpt_attributes_from_csv_file($entity_code); |
|
| 386 | + } |
|
| 387 | + $do_changes = true; |
|
| 388 | + } |
|
| 389 | + |
|
| 390 | + /* Create attribute groups for a given entity if attributes groups are set to be created for current version */ |
|
| 391 | + if (isset($eav_content['attribute_groups']) && is_array($eav_content['attribute_groups']) && (count($eav_content['attribute_groups']) > 0)) { |
|
| 392 | + foreach ($eav_content['attribute_groups'] as $entity_code => $attribute_set) { |
|
| 393 | + $entity_id = wpshop_entities::get_entity_identifier_from_code($entity_code); |
|
| 394 | + |
|
| 395 | + if ($entity_id > 0) { |
|
| 396 | + foreach ($attribute_set as $set_name => $set_groups) { |
|
| 397 | + $query = $wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE_SET . " WHERE entity_id = %d AND name = LOWER(%s)", $entity_id, wpshop_tools::slugify($set_name, array('noAccent', 'noSpaces', 'lowerCase'))); |
|
| 398 | + $attribute_set_id = $wpdb->get_var($query); |
|
| 399 | + if ($attribute_set_id <= 0) { |
|
| 400 | + $attribute_set_content = array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'entity_id' => $entity_id, 'name' => $set_name); |
|
| 401 | + if ($set_name == 'default') { |
|
| 402 | + $attribute_set_content['default_set'] = 'yes'; |
|
| 403 | + } |
|
| 404 | + $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_SET, $attribute_set_content); |
|
| 405 | + $attribute_set_id = $wpdb->insert_id; |
|
| 406 | + } |
|
| 407 | + |
|
| 408 | + if ($attribute_set_id > 0) { |
|
| 409 | + foreach ($set_groups as $set_group_infos) { |
|
| 410 | + $set_group_infos_details = $set_group_infos['details']; |
|
| 411 | + unset($set_group_infos['details']); |
|
| 412 | + /* Change an attribute set status if definition specify this param */ |
|
| 413 | + if (isset($set_group_infos['status'])) { |
|
| 414 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE_SET, array('last_update_date' => current_time('mysql', 0), 'status' => $set_group_infos['status']), array('id' => $attribute_set_id)); |
|
| 415 | + } |
|
| 416 | + $query = $wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE_GROUP . " WHERE attribute_set_id = %d AND code = LOWER(%s)", $attribute_set_id, $set_group_infos['code']); |
|
| 417 | + $attribute_set_section_id = $wpdb->get_var($query); |
|
| 418 | + if ($attribute_set_section_id <= 0) { |
|
| 419 | + $new_set_section_infos = $set_group_infos; |
|
| 420 | + $new_set_section_infos['status'] = (isset($new_set_section_infos['status']) ? $new_set_section_infos['status'] : 'valid'); |
|
| 421 | + $new_set_section_infos['creation_date'] = current_time('mysql', 0); |
|
| 422 | + $new_set_section_infos['attribute_set_id'] = $attribute_set_id; |
|
| 423 | + $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_GROUP, $new_set_section_infos); |
|
| 424 | + $attribute_set_section_id = $wpdb->insert_id; |
|
| 425 | + } |
|
| 426 | + |
|
| 427 | + if (($attribute_set_section_id > 0) && (isset($set_group_infos_details) && is_array($set_group_infos_details) && (count($set_group_infos_details) > 0))) { |
|
| 428 | + $query = $wpdb->prepare("SELECT MAX(position) AS position FROM " . WPSHOP_DBT_ATTRIBUTE_DETAILS . " WHERE entity_type_id = %d AND attribute_set_id = %d AND attribute_group_id = %d", $entity_id, $attribute_set_id, $attribute_set_section_id); |
|
| 429 | + $last_position = $wpdb->get_var($query); |
|
| 430 | + $position = (int) $last_position + 1; |
|
| 431 | + foreach ($set_group_infos_details as $attribute_code) { |
|
| 432 | + $query = $wpdb->prepare("SELECT * FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE code = %s AND entity_id = %d", $attribute_code, $entity_id); |
|
| 433 | + $attribute_id = $wpdb->get_row($query); |
|
| 434 | + |
|
| 435 | + if ($attribute_id->id > 0) { |
|
| 436 | + $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'entity_type_id' => $entity_id, 'attribute_set_id' => $attribute_set_id, 'attribute_group_id' => $attribute_set_section_id, 'attribute_id' => $attribute_id->id, 'position' => $position)); |
|
| 437 | + $position++; |
|
| 438 | + } |
|
| 439 | + } |
|
| 440 | + } |
|
| 441 | + |
|
| 442 | + } |
|
| 443 | + } |
|
| 444 | + } |
|
| 445 | + } |
|
| 446 | + } |
|
| 447 | + $do_changes = true; |
|
| 448 | + } |
|
| 449 | + |
|
| 450 | + return $do_changes; |
|
| 451 | + } |
|
| 452 | + |
|
| 453 | + /** |
|
| 454 | + * Update specific data in eav db model |
|
| 455 | + * |
|
| 456 | + * @param array $eav_content The complete array with all element to create into database |
|
| 457 | + * @param boolean $do_changes The current state of changes to do |
|
| 458 | + * |
|
| 459 | + * @return boolean If there are changes to do or not |
|
| 460 | + */ |
|
| 461 | + public static function update_eav_content($eav_content, $do_changes) |
|
| 462 | + { |
|
| 463 | + /* Update attributes fo a given entity if attributes are set to be updated for current version */ |
|
| 464 | + if (isset($eav_content['attributes']) && is_array($eav_content['attributes']) && (count($eav_content['attributes']) > 0)) { |
|
| 465 | + foreach ($eav_content['attributes'] as $entity_code => $attribute_definition) { |
|
| 466 | + foreach ($attribute_definition as $attribute_def) { |
|
| 467 | + $option_list_for_attribute = ''; |
|
| 468 | + if (isset($attribute_def['backend_input_values'])) { |
|
| 469 | + $option_list_for_attribute = $attribute_def['backend_input_values']; |
|
| 470 | + unset($attribute_def['backend_input_values']); |
|
| 471 | + } |
|
| 472 | + |
|
| 473 | + /* Get entity identifier from code */ |
|
| 474 | + $attribute_def['entity_id'] = wpshop_entities::get_entity_identifier_from_code($entity_code); |
|
| 475 | + $attribute_def['status'] = $attribute_def['attribute_status']; |
|
| 476 | + unset($attribute_def['attribute_status']); |
|
| 477 | + $attribute_def['last_update_date'] = current_time('mysql', 0); |
|
| 478 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE, $attribute_def, array('code' => $attribute_def['code'])); |
|
| 479 | + $attribute_id = $wpdb->get_var($wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE code = %s", $attribute_def['code'])); |
|
| 480 | + |
|
| 481 | + /* Insert option values if there are some to add for the current attribute */ |
|
| 482 | + if (($option_list_for_attribute != '') && (is_array($option_list_for_attribute))) { |
|
| 483 | + foreach ($option_list_for_attribute as $option_code => $option_value) { |
|
| 484 | + $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS, array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'attribute_id' => $attribute_id, 'label' => ((substr($option_code, 0, 2) != '__') ? $option_value : __(substr($option_code, 2), 'wpshop')), 'value' => $option_value)); |
|
| 485 | + if ($option_code == $attribute_def['default_value']) { |
|
| 486 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('last_update_date' => current_time('mysql', 0), 'default_value' => $wpdb->insert_id), array('id' => $attribute_id, 'default_value' => $option_code)); |
|
| 487 | + } |
|
| 488 | + } |
|
| 489 | + } |
|
| 490 | + } |
|
| 491 | + } |
|
| 492 | + $do_changes = true; |
|
| 493 | + } |
|
| 494 | + |
|
| 495 | + /* Update attribute groups fo a given entity if attributes groups are set to be updated for current version */ |
|
| 496 | + if (is_array($eav_content['attribute_groups']) && is_array($eav_content['attribute_groups']) && (count($eav_content['attribute_groups']) > 0)) { |
|
| 497 | + foreach ($eav_content['attribute_groups'] as $entity_code => $attribute_set) { |
|
| 498 | + $entity_id = wpshop_entities::get_entity_identifier_from_code($entity_code); |
|
| 499 | + |
|
| 500 | + if ($entity_id > 0) { |
|
| 501 | + foreach ($attribute_set as $set_name => $set_groups) { |
|
| 502 | + $query = $wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE_SET . " WHERE entity_id = %d AND name = LOWER(%s)", $entity_id, wpshop_tools::slugify($set_name, array('noAccent', 'noSpaces', 'lowerCase'))); |
|
| 503 | + $attribute_set_id = $wpdb->get_var($query); |
|
| 504 | + if ($attribute_set_id <= 0) { |
|
| 505 | + $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_SET, array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'entity_id' => $entity_id, 'name' => $set_name)); |
|
| 506 | + $attribute_set_id = $wpdb->insert_id; |
|
| 507 | + } |
|
| 508 | + |
|
| 509 | + if ($attribute_set_id > 0) { |
|
| 510 | + foreach ($set_groups as $set_group_infos) { |
|
| 511 | + $set_group_infos_details = $set_group_infos['details']; |
|
| 512 | + unset($set_group_infos['details']); |
|
| 513 | + /* Change an attribute set status if definition specify this param */ |
|
| 514 | + if (isset($set_group_infos['status'])) { |
|
| 515 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE_SET, array('last_update_date' => current_time('mysql', 0), 'status' => $set_group_infos['status']), array('id' => $attribute_set_id)); |
|
| 516 | + } |
|
| 517 | + $query = $wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE_GROUP . " WHERE attribute_set_id = %d AND code = LOWER(%s)", $attribute_set_id, $set_group_infos['code']); |
|
| 518 | + $attribute_set_section_id = $wpdb->get_var($query); |
|
| 519 | + if ($attribute_set_section_id <= 0) { |
|
| 520 | + $new_set_section_infos = $set_group_infos; |
|
| 521 | + $new_set_section_infos['status'] = (isset($new_set_section_infos['status']) ? $new_set_section_infos['status'] : 'valid'); |
|
| 522 | + $new_set_section_infos['creation_date'] = current_time('mysql', 0); |
|
| 523 | + $new_set_section_infos['attribute_set_id'] = $attribute_set_id; |
|
| 524 | + $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_GROUP, $new_set_section_infos); |
|
| 525 | + $attribute_set_section_id = $wpdb->insert_id; |
|
| 526 | + } else { |
|
| 527 | + $new_set_section_infos = $set_group_infos; |
|
| 528 | + $new_set_section_infos['last_update_date'] = current_time('mysql', 0); |
|
| 529 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE_GROUP, $new_set_section_infos, array('id' => $attribute_set_section_id)); |
|
| 530 | + } |
|
| 531 | + |
|
| 532 | + if (($attribute_set_section_id > 0) && (isset($set_group_infos_details) && is_array($set_group_infos_details))) { |
|
| 533 | + if (count($set_group_infos_details) <= 0) { |
|
| 534 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('last_update_date' => current_time('mysql', 0), 'status' => 'deleted'), array('entity_type_id' => $entity_id, 'attribute_set_id' => $attribute_set_id, 'attribute_group_id' => $attribute_set_section_id)); |
|
| 535 | + } else { |
|
| 536 | + $query = $wpdb->prepare("SELECT MAX(position) AS position FROM " . WPSHOP_DBT_ATTRIBUTE_DETAILS . " WHERE entity_type_id = %d AND attribute_set_id = %d AND attribute_group_id = %d", $entity_id, $attribute_set_id, $attribute_set_section_id); |
|
| 537 | + $last_position = $wpdb->get_var($query); |
|
| 538 | + $position = (int) $last_position + 1; |
|
| 539 | + foreach ($set_group_infos_details as $attribute_code) { |
|
| 540 | + $query = $wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE code = %s AND entity_id = %d", $attribute_code, $entity_id); |
|
| 541 | + $attribute_id = $wpdb->get_var($query); |
|
| 542 | + if ($attribute_id > 0) { |
|
| 543 | + $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'entity_type_id' => $entity_id, 'attribute_set_id' => $attribute_set_id, 'attribute_group_id' => $attribute_set_section_id, 'attribute_id' => $attribute_id, 'position' => $position)); |
|
| 544 | + $position++; |
|
| 545 | + } |
|
| 546 | + } |
|
| 547 | + } |
|
| 548 | + } |
|
| 549 | + } |
|
| 550 | + } |
|
| 551 | + } |
|
| 552 | + } |
|
| 553 | + } |
|
| 554 | + $do_changes = true; |
|
| 555 | + } |
|
| 556 | + |
|
| 557 | + return $do_changes; |
|
| 558 | + } |
|
| 611 | 559 | |
| 612 | - /* Update the product prices into database */ |
|
| 613 | - $query = $wpdb->prepare(" |
|
| 560 | + /** |
|
| 561 | + * Manage special operation on wpshop plugin update |
|
| 562 | + */ |
|
| 563 | + public static function make_specific_operation_on_update($version) |
|
| 564 | + { |
|
| 565 | + global $wpdb, $wp_rewrite; |
|
| 566 | + $wpshop_shop_type = get_option('wpshop_shop_type', WPSHOP_DEFAULT_SHOP_TYPE); |
|
| 567 | + |
|
| 568 | + switch ($version) { |
|
| 569 | + case 3: |
|
| 570 | + case 6: |
|
| 571 | + self::wpshop_insert_default_pages($wpshop_shop_type); |
|
| 572 | + wp_cache_flush(); |
|
| 573 | + return true; |
|
| 574 | + break; |
|
| 575 | + case 8: |
|
| 576 | + /** Change metaboxes order for product in case it already exists */ |
|
| 577 | + $query = $wpdb->prepare("SELECT umeta_id, meta_value FROM {$wpdb->usermeta} WHERE meta_key = %s", 'meta-box-order_wpshop_product'); |
|
| 578 | + $customer_metaboxes_order = $wpdb->get_results($query); |
|
| 579 | + if (!empty($customer_metaboxes_order)) { |
|
| 580 | + foreach ($customer_metaboxes_order as $customer_metabox_order) { |
|
| 581 | + $do_changes = false; |
|
| 582 | + $current_order = unserialize($customer_metabox_order->meta_value); |
|
| 583 | + if (array_key_exists('normal', $current_order) && (false !== strpos('wpshop_product_important_datas', $current_order['normal']))) { |
|
| 584 | + str_replace('wpshop_product_important_datas,', '', $current_order['normal']); |
|
| 585 | + $do_changes = true; |
|
| 586 | + } |
|
| 587 | + |
|
| 588 | + if (array_key_exists('side', $current_order)) { |
|
| 589 | + str_replace('wpshop_product_important_datas,', '', $current_order['side']); |
|
| 590 | + str_replace('submitdiv,', 'submitdiv,wpshop_product_important_datas,', $current_order['side']); |
|
| 591 | + $do_changes = true; |
|
| 592 | + } |
|
| 593 | + |
|
| 594 | + if (true === $do_changes) { |
|
| 595 | + $wpdb->update($wpdb->usermeta, array('meta_value' => serialize($current_order)), array('umeta_id' => $customer_metabox_order->umeta_id)); |
|
| 596 | + } |
|
| 597 | + } |
|
| 598 | + } else { |
|
| 599 | + $users = get_users(array('role' => 'administrator')); |
|
| 600 | + if (!empty($users)) { |
|
| 601 | + foreach ($users as $user) { |
|
| 602 | + $user_meta = array( |
|
| 603 | + 'side' => 'submitdiv,formatdiv,wpshop_product_important_datas,wpshop_product_categorydiv,pageparentdiv,wps_barcode_product,wpshop_product_actions,wpshop_product_options,postimagediv', |
|
| 604 | + 'normal' => 'wpshop_product_fixed_tab,postexcerpt,trackbacksdiv,postcustom,commentstatusdiv,slugdiv,authordiv,wpshop_wpshop_variations,wps_media_manager,wpshop_product_order_historic', |
|
| 605 | + 'advanced' => '', |
|
| 606 | + ); |
|
| 607 | + update_user_meta($user->ID, 'meta-box-order_wpshop_product', $user_meta); |
|
| 608 | + } |
|
| 609 | + } |
|
| 610 | + } |
|
| 611 | + |
|
| 612 | + /* Update the product prices into database */ |
|
| 613 | + $query = $wpdb->prepare(" |
|
| 614 | 614 | SELECT |
| 615 | 615 | (SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE code = %s) AS product_price, |
| 616 | 616 | (SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE code = %s) AS price_ht, |
| 617 | 617 | (SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE code = %s) AS tx_tva, |
| 618 | 618 | (SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE code = %s) AS tva", 'product_price', 'price_ht', 'tx_tva', 'tva'); |
| 619 | - $product_prices = $wpdb->get_row($query); |
|
| 620 | - $tax_id = $wpdb->get_var($wpdb->prepare("SELECT ATT_OPT.id FROM " . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . " AS ATT_OPT WHERE attribute_id = %d AND value = '20'", $product_prices->tx_tva)); |
|
| 621 | - $query = $wpdb->prepare("SELECT * FROM " . WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL . " WHERE attribute_id = %d", $product_prices->product_price); |
|
| 622 | - $price_list = $wpdb->get_results($query); |
|
| 623 | - foreach ($price_list as $existing_ttc_price) { |
|
| 624 | - $tax_rate = 1.20; |
|
| 625 | - $price_ht = $existing_ttc_price->value / $tax_rate; |
|
| 626 | - $tax_amount = $existing_ttc_price->value - $price_ht; |
|
| 627 | - |
|
| 628 | - $wpdb->replace(WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('entity_type_id' => $existing_ttc_price->entity_type_id, 'attribute_id' => $product_prices->price_ht, 'entity_id' => $existing_ttc_price->entity_id, 'unit_id' => $existing_ttc_price->unit_id, 'user_id' => $existing_ttc_price->user_id, 'language' => $existing_ttc_price->language, 'value' => $price_ht, 'creation_date_value' => current_time('mysql', 0))); |
|
| 629 | - $wpdb->replace(WPSHOP_DBT_ATTRIBUTE_VALUES_INTEGER, array('entity_type_id' => $existing_ttc_price->entity_type_id, 'attribute_id' => $product_prices->tx_tva, 'entity_id' => $existing_ttc_price->entity_id, 'unit_id' => $existing_ttc_price->unit_id, 'user_id' => $existing_ttc_price->user_id, 'language' => $existing_ttc_price->language, 'value' => $tax_id, 'creation_date_value' => current_time('mysql', 0))); |
|
| 630 | - $wpdb->replace(WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('entity_type_id' => $existing_ttc_price->entity_type_id, 'attribute_id' => $product_prices->tva, 'entity_id' => $existing_ttc_price->entity_id, 'unit_id' => $existing_ttc_price->unit_id, 'user_id' => $existing_ttc_price->user_id, 'language' => $existing_ttc_price->language, 'value' => $tax_amount, 'creation_date_value' => current_time('mysql', 0))); |
|
| 631 | - } |
|
| 632 | - |
|
| 633 | - /* Update orders structure into database */ |
|
| 634 | - $orders_id = $wpdb->get_results('SELECT ID FROM ' . $wpdb->posts . ' WHERE post_type = "' . WPSHOP_NEWTYPE_IDENTIFIER_ORDER . '"'); |
|
| 635 | - foreach ($orders_id as $o) { |
|
| 636 | - $myorder = get_post_meta($o->ID, '_order_postmeta', true); |
|
| 637 | - $neworder = array(); |
|
| 638 | - $items = array(); |
|
| 639 | - |
|
| 640 | - if (!isset($myorder['order_tva'])) { |
|
| 641 | - $order_total_ht = 0; |
|
| 642 | - $order_total_ttc = 0; |
|
| 643 | - $order_tva = array('20' => 0); |
|
| 644 | - |
|
| 645 | - foreach ($myorder['order_items'] as $item) { |
|
| 646 | - /* item */ |
|
| 647 | - $pu_ht = $item['cost'] / 1.20; |
|
| 648 | - $pu_tva = $item['cost'] - $pu_ht; |
|
| 649 | - $total_ht = $pu_ht * $item['qty']; |
|
| 650 | - $tva_total_amount = $pu_tva * $item['qty']; |
|
| 651 | - $total_ttc = $item['cost'] * $item['qty']; |
|
| 652 | - /* item */ |
|
| 653 | - $order_total_ht += $total_ht; |
|
| 654 | - $order_total_ttc += $total_ttc; |
|
| 655 | - $order_tva['20'] += $tva_total_amount; |
|
| 656 | - |
|
| 657 | - $items[] = array( |
|
| 658 | - 'item_id' => $item['id'], |
|
| 659 | - 'item_ref' => 'Nc', |
|
| 660 | - 'item_name' => $item['name'], |
|
| 661 | - 'item_qty' => $item['qty'], |
|
| 662 | - |
|
| 663 | - 'item_pu_ht' => number_format($pu_ht, 2, '.', ''), |
|
| 664 | - 'item_pu_ttc' => number_format($item['cost'], 2, '.', ''), |
|
| 665 | - |
|
| 666 | - 'item_ecotaxe_ht' => number_format(0, 2, '.', ''), |
|
| 667 | - 'item_ecotaxe_tva' => 20, |
|
| 668 | - 'item_ecotaxe_ttc' => number_format(0, 2, '.', ''), |
|
| 669 | - |
|
| 670 | - 'item_discount_type' => 0, |
|
| 671 | - 'item_discount_value' => 0, |
|
| 672 | - 'item_discount_amount' => number_format(0, 2, '.', ''), |
|
| 673 | - |
|
| 674 | - 'item_tva_rate' => 20, |
|
| 675 | - 'item_tva_amount' => number_format($pu_tva, 2, '.', ''), |
|
| 676 | - |
|
| 677 | - 'item_total_ht' => number_format($total_ht, 2, '.', ''), |
|
| 678 | - 'item_tva_total_amount' => number_format($tva_total_amount, 2, '.', ''), |
|
| 679 | - 'item_total_ttc' => number_format($total_ttc, 2, '.', ''), |
|
| 680 | - /*'item_total_ttc_with_ecotaxe' => number_format($total_ttc, 2, '.', '')*/ |
|
| 681 | - ); |
|
| 682 | - } |
|
| 619 | + $product_prices = $wpdb->get_row($query); |
|
| 620 | + $tax_id = $wpdb->get_var($wpdb->prepare("SELECT ATT_OPT.id FROM " . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . " AS ATT_OPT WHERE attribute_id = %d AND value = '20'", $product_prices->tx_tva)); |
|
| 621 | + $query = $wpdb->prepare("SELECT * FROM " . WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL . " WHERE attribute_id = %d", $product_prices->product_price); |
|
| 622 | + $price_list = $wpdb->get_results($query); |
|
| 623 | + foreach ($price_list as $existing_ttc_price) { |
|
| 624 | + $tax_rate = 1.20; |
|
| 625 | + $price_ht = $existing_ttc_price->value / $tax_rate; |
|
| 626 | + $tax_amount = $existing_ttc_price->value - $price_ht; |
|
| 627 | + |
|
| 628 | + $wpdb->replace(WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('entity_type_id' => $existing_ttc_price->entity_type_id, 'attribute_id' => $product_prices->price_ht, 'entity_id' => $existing_ttc_price->entity_id, 'unit_id' => $existing_ttc_price->unit_id, 'user_id' => $existing_ttc_price->user_id, 'language' => $existing_ttc_price->language, 'value' => $price_ht, 'creation_date_value' => current_time('mysql', 0))); |
|
| 629 | + $wpdb->replace(WPSHOP_DBT_ATTRIBUTE_VALUES_INTEGER, array('entity_type_id' => $existing_ttc_price->entity_type_id, 'attribute_id' => $product_prices->tx_tva, 'entity_id' => $existing_ttc_price->entity_id, 'unit_id' => $existing_ttc_price->unit_id, 'user_id' => $existing_ttc_price->user_id, 'language' => $existing_ttc_price->language, 'value' => $tax_id, 'creation_date_value' => current_time('mysql', 0))); |
|
| 630 | + $wpdb->replace(WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('entity_type_id' => $existing_ttc_price->entity_type_id, 'attribute_id' => $product_prices->tva, 'entity_id' => $existing_ttc_price->entity_id, 'unit_id' => $existing_ttc_price->unit_id, 'user_id' => $existing_ttc_price->user_id, 'language' => $existing_ttc_price->language, 'value' => $tax_amount, 'creation_date_value' => current_time('mysql', 0))); |
|
| 631 | + } |
|
| 683 | 632 | |
| 684 | - $neworder = array( |
|
| 685 | - 'order_key' => $myorder['order_key'], |
|
| 686 | - 'customer_id' => $myorder['customer_id'], |
|
| 687 | - 'order_status' => $myorder['order_status'], |
|
| 688 | - 'order_date' => $myorder['order_date'], |
|
| 689 | - 'order_payment_date' => $myorder['order_payment_date'], |
|
| 690 | - 'order_shipping_date' => $myorder['order_shipping_date'], |
|
| 691 | - 'payment_method' => $myorder['payment_method'], |
|
| 692 | - 'order_invoice_ref' => '', |
|
| 693 | - 'order_currency' => $myorder['order_currency'], |
|
| 694 | - 'order_total_ht' => $order_total_ht, |
|
| 695 | - 'order_total_ttc' => $order_total_ttc, |
|
| 696 | - 'order_grand_total' => $order_total_ttc, |
|
| 697 | - 'order_shipping_cost' => number_format(0, 2, '.', ''), |
|
| 698 | - 'order_tva' => array_map(array('wpshop_tools', 'number_format_hack'), $order_tva), |
|
| 699 | - 'order_items' => $items, |
|
| 700 | - ); |
|
| 701 | - /* Update the order postmeta */ |
|
| 702 | - update_post_meta($o->ID, '_order_postmeta', $neworder); |
|
| 703 | - } |
|
| 704 | - } |
|
| 705 | - |
|
| 706 | - self::wpshop_insert_default_pages($wpshop_shop_type); |
|
| 707 | - wp_cache_flush(); |
|
| 708 | - return true; |
|
| 709 | - break; |
|
| 710 | - case 12: |
|
| 711 | - $query = "SELECT ID FROM " . $wpdb->users; |
|
| 712 | - $user_list = $wpdb->get_results($query); |
|
| 713 | - foreach ($user_list as $user) { |
|
| 714 | - $user_first_name = get_user_meta($user->ID, 'first_name', true); |
|
| 715 | - $user_last_name = get_user_meta($user->ID, 'last_name', true); |
|
| 716 | - $shipping_info = get_user_meta($user->ID, 'shipping_info', true); |
|
| 717 | - |
|
| 718 | - if (($user_first_name == '') && !empty($shipping_info['first_name'])) { |
|
| 719 | - update_user_meta($user->ID, 'first_name', $shipping_info['first_name']); |
|
| 720 | - } |
|
| 633 | + /* Update orders structure into database */ |
|
| 634 | + $orders_id = $wpdb->get_results('SELECT ID FROM ' . $wpdb->posts . ' WHERE post_type = "' . WPSHOP_NEWTYPE_IDENTIFIER_ORDER . '"'); |
|
| 635 | + foreach ($orders_id as $o) { |
|
| 636 | + $myorder = get_post_meta($o->ID, '_order_postmeta', true); |
|
| 637 | + $neworder = array(); |
|
| 638 | + $items = array(); |
|
| 639 | + |
|
| 640 | + if (!isset($myorder['order_tva'])) { |
|
| 641 | + $order_total_ht = 0; |
|
| 642 | + $order_total_ttc = 0; |
|
| 643 | + $order_tva = array('20' => 0); |
|
| 644 | + |
|
| 645 | + foreach ($myorder['order_items'] as $item) { |
|
| 646 | + /* item */ |
|
| 647 | + $pu_ht = $item['cost'] / 1.20; |
|
| 648 | + $pu_tva = $item['cost'] - $pu_ht; |
|
| 649 | + $total_ht = $pu_ht * $item['qty']; |
|
| 650 | + $tva_total_amount = $pu_tva * $item['qty']; |
|
| 651 | + $total_ttc = $item['cost'] * $item['qty']; |
|
| 652 | + /* item */ |
|
| 653 | + $order_total_ht += $total_ht; |
|
| 654 | + $order_total_ttc += $total_ttc; |
|
| 655 | + $order_tva['20'] += $tva_total_amount; |
|
| 656 | + |
|
| 657 | + $items[] = array( |
|
| 658 | + 'item_id' => $item['id'], |
|
| 659 | + 'item_ref' => 'Nc', |
|
| 660 | + 'item_name' => $item['name'], |
|
| 661 | + 'item_qty' => $item['qty'], |
|
| 662 | + |
|
| 663 | + 'item_pu_ht' => number_format($pu_ht, 2, '.', ''), |
|
| 664 | + 'item_pu_ttc' => number_format($item['cost'], 2, '.', ''), |
|
| 665 | + |
|
| 666 | + 'item_ecotaxe_ht' => number_format(0, 2, '.', ''), |
|
| 667 | + 'item_ecotaxe_tva' => 20, |
|
| 668 | + 'item_ecotaxe_ttc' => number_format(0, 2, '.', ''), |
|
| 669 | + |
|
| 670 | + 'item_discount_type' => 0, |
|
| 671 | + 'item_discount_value' => 0, |
|
| 672 | + 'item_discount_amount' => number_format(0, 2, '.', ''), |
|
| 673 | + |
|
| 674 | + 'item_tva_rate' => 20, |
|
| 675 | + 'item_tva_amount' => number_format($pu_tva, 2, '.', ''), |
|
| 676 | + |
|
| 677 | + 'item_total_ht' => number_format($total_ht, 2, '.', ''), |
|
| 678 | + 'item_tva_total_amount' => number_format($tva_total_amount, 2, '.', ''), |
|
| 679 | + 'item_total_ttc' => number_format($total_ttc, 2, '.', ''), |
|
| 680 | + /*'item_total_ttc_with_ecotaxe' => number_format($total_ttc, 2, '.', '')*/ |
|
| 681 | + ); |
|
| 682 | + } |
|
| 683 | + |
|
| 684 | + $neworder = array( |
|
| 685 | + 'order_key' => $myorder['order_key'], |
|
| 686 | + 'customer_id' => $myorder['customer_id'], |
|
| 687 | + 'order_status' => $myorder['order_status'], |
|
| 688 | + 'order_date' => $myorder['order_date'], |
|
| 689 | + 'order_payment_date' => $myorder['order_payment_date'], |
|
| 690 | + 'order_shipping_date' => $myorder['order_shipping_date'], |
|
| 691 | + 'payment_method' => $myorder['payment_method'], |
|
| 692 | + 'order_invoice_ref' => '', |
|
| 693 | + 'order_currency' => $myorder['order_currency'], |
|
| 694 | + 'order_total_ht' => $order_total_ht, |
|
| 695 | + 'order_total_ttc' => $order_total_ttc, |
|
| 696 | + 'order_grand_total' => $order_total_ttc, |
|
| 697 | + 'order_shipping_cost' => number_format(0, 2, '.', ''), |
|
| 698 | + 'order_tva' => array_map(array('wpshop_tools', 'number_format_hack'), $order_tva), |
|
| 699 | + 'order_items' => $items, |
|
| 700 | + ); |
|
| 701 | + /* Update the order postmeta */ |
|
| 702 | + update_post_meta($o->ID, '_order_postmeta', $neworder); |
|
| 703 | + } |
|
| 704 | + } |
|
| 721 | 705 | |
| 722 | - if (($user_last_name == '') && !empty($shipping_info['last_name'])) { |
|
| 723 | - update_user_meta($user->ID, 'last_name', $shipping_info['last_name']); |
|
| 724 | - } |
|
| 725 | - } |
|
| 726 | - |
|
| 727 | - /* Update orders structure into database */ |
|
| 728 | - $orders_id = $wpdb->get_results('SELECT ID FROM ' . $wpdb->posts . ' WHERE post_type = "' . WPSHOP_NEWTYPE_IDENTIFIER_ORDER . '"'); |
|
| 729 | - foreach ($orders_id as $o) { |
|
| 730 | - $myorder = get_post_meta($o->ID, '_order_postmeta', true); |
|
| 731 | - if (!empty($myorder)) { |
|
| 732 | - $new_items = array(); |
|
| 733 | - foreach ($myorder['order_items'] as $item) { |
|
| 734 | - $new_items = $item; |
|
| 735 | - $new_items['item_discount_type'] = !empty($item['item_discount_rate']) ? $item['item_discount_rate'] : 'amount'; |
|
| 736 | - // unset($new_items['item_discount_rate']); |
|
| 737 | - $new_items['item_discount_value'] = 0; |
|
| 738 | - } |
|
| 739 | - $myorder['order_items'] = $new_items; |
|
| 706 | + self::wpshop_insert_default_pages($wpshop_shop_type); |
|
| 707 | + wp_cache_flush(); |
|
| 708 | + return true; |
|
| 709 | + break; |
|
| 710 | + case 12: |
|
| 711 | + $query = "SELECT ID FROM " . $wpdb->users; |
|
| 712 | + $user_list = $wpdb->get_results($query); |
|
| 713 | + foreach ($user_list as $user) { |
|
| 714 | + $user_first_name = get_user_meta($user->ID, 'first_name', true); |
|
| 715 | + $user_last_name = get_user_meta($user->ID, 'last_name', true); |
|
| 716 | + $shipping_info = get_user_meta($user->ID, 'shipping_info', true); |
|
| 717 | + |
|
| 718 | + if (($user_first_name == '') && !empty($shipping_info['first_name'])) { |
|
| 719 | + update_user_meta($user->ID, 'first_name', $shipping_info['first_name']); |
|
| 720 | + } |
|
| 721 | + |
|
| 722 | + if (($user_last_name == '') && !empty($shipping_info['last_name'])) { |
|
| 723 | + update_user_meta($user->ID, 'last_name', $shipping_info['last_name']); |
|
| 724 | + } |
|
| 725 | + } |
|
| 740 | 726 | |
| 741 | - /* Update the order postmeta */ |
|
| 742 | - update_post_meta($o->ID, '_order_postmeta', $myorder); |
|
| 743 | - } |
|
| 744 | - } |
|
| 745 | - |
|
| 746 | - /* Delete useless database table */ |
|
| 747 | - $query = "DROP TABLE " . WPSHOP_DBT_CART; |
|
| 748 | - $wpdb->query($query); |
|
| 749 | - $query = "DROP TABLE " . WPSHOP_DBT_CART_CONTENTS; |
|
| 750 | - $wpdb->query($query); |
|
| 751 | - return true; |
|
| 752 | - break; |
|
| 753 | - case 13: |
|
| 754 | - $attribute_used_for_sort_by = wpshop_attributes::getElement('yes', "'valid', 'moderated', 'notused'", 'is_used_for_sort_by', true); |
|
| 755 | - foreach ($attribute_used_for_sort_by as $attribute) { |
|
| 756 | - $data = query_posts(array('posts_per_page' => -1, 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT)); |
|
| 757 | - foreach ($data as $post) { |
|
| 758 | - $postmeta = get_post_meta($post->ID, '_wpshop_product_metadata', true); |
|
| 759 | - if (!empty($postmeta[$attribute->code])) { |
|
| 760 | - update_post_meta($post->ID, '_' . $attribute->code, $postmeta[$attribute->code]); |
|
| 761 | - } |
|
| 762 | - } |
|
| 763 | - wp_reset_query(); |
|
| 764 | - } |
|
| 765 | - return true; |
|
| 766 | - break; |
|
| 767 | - case 17: |
|
| 768 | - $products = query_posts(array( |
|
| 769 | - 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT) |
|
| 770 | - ); |
|
| 771 | - $query = $wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE_SET . " WHERE default_set = %s", 'yes'); |
|
| 772 | - $default_attribute_set = $wpdb->get_var($query); |
|
| 773 | - foreach ($products as $product) { |
|
| 774 | - $p_att_set_id = get_post_meta($product->ID, WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, true); |
|
| 775 | - if (empty($p_att_set_id)) { |
|
| 776 | - /* Update the attribute set id for the current product */ |
|
| 777 | - update_post_meta($product->ID, WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, $default_attribute_set); |
|
| 778 | - } |
|
| 779 | - wp_reset_query(); |
|
| 780 | - } |
|
| 781 | - self::wpshop_insert_default_pages($wpshop_shop_type); |
|
| 782 | - wp_cache_flush(); |
|
| 783 | - return true; |
|
| 784 | - break; |
|
| 785 | - case 18: |
|
| 786 | - self::wpshop_insert_default_pages($wpshop_shop_type); |
|
| 787 | - wp_cache_flush(); |
|
| 788 | - return true; |
|
| 789 | - break; |
|
| 790 | - case 19: |
|
| 791 | - $wp_rewrite->flush_rules(); |
|
| 792 | - return true; |
|
| 793 | - break; |
|
| 794 | - |
|
| 795 | - case 21: |
|
| 796 | - /** |
|
| 797 | - * Correction des valeurs pour l'attributs "gestion du stock" qui n'�taient pas cr�es automatiquement |
|
| 798 | - */ |
|
| 799 | - $query = $wpdb->prepare("SELECT ATTR_OPT.id, ATTR_OPT.value, ATTR_OPT.label, ATTR_OPT.position, ATTR_OPT.attribute_id FROM " . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . " AS ATTR_OPT INNER JOIN " . WPSHOP_DBT_ATTRIBUTE . " AS ATTR ON (ATTR.id = ATTR_OPT.attribute_id) WHERE ATTR_OPT.status=%s AND ATTR.code=%s", 'valid', 'manage_stock'); |
|
| 800 | - $manage_stock_option = $wpdb->get_results($query); |
|
| 801 | - if (!empty($manage_stock_option)) { |
|
| 802 | - $no_is_present = false; |
|
| 803 | - $attribute_id = $manage_stock_option[0]->attribute_id; |
|
| 804 | - foreach ($manage_stock_option as $manage_definition) { |
|
| 805 | - if (strtolower(__($manage_definition->value, 'wpshop')) == strtolower(__('no', 'wpshop'))) { |
|
| 806 | - $no_is_present = true; |
|
| 807 | - } |
|
| 808 | - } |
|
| 809 | - if (!$no_is_present) { |
|
| 810 | - $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS, array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'last_update_date' => current_time('mysql', 0), 'attribute_id' => $attribute_id, 'value' => 'no', 'label' => __('No', 'wpshop'))); |
|
| 811 | - } |
|
| 812 | - } |
|
| 727 | + /* Update orders structure into database */ |
|
| 728 | + $orders_id = $wpdb->get_results('SELECT ID FROM ' . $wpdb->posts . ' WHERE post_type = "' . WPSHOP_NEWTYPE_IDENTIFIER_ORDER . '"'); |
|
| 729 | + foreach ($orders_id as $o) { |
|
| 730 | + $myorder = get_post_meta($o->ID, '_order_postmeta', true); |
|
| 731 | + if (!empty($myorder)) { |
|
| 732 | + $new_items = array(); |
|
| 733 | + foreach ($myorder['order_items'] as $item) { |
|
| 734 | + $new_items = $item; |
|
| 735 | + $new_items['item_discount_type'] = !empty($item['item_discount_rate']) ? $item['item_discount_rate'] : 'amount'; |
|
| 736 | + // unset($new_items['item_discount_rate']); |
|
| 737 | + $new_items['item_discount_value'] = 0; |
|
| 738 | + } |
|
| 739 | + $myorder['order_items'] = $new_items; |
|
| 740 | + |
|
| 741 | + /* Update the order postmeta */ |
|
| 742 | + update_post_meta($o->ID, '_order_postmeta', $myorder); |
|
| 743 | + } |
|
| 744 | + } |
|
| 813 | 745 | |
| 814 | - /** Change price attribute set section order for default set */ |
|
| 815 | - $price_tab = unserialize(WPSHOP_ATTRIBUTE_PRICES); |
|
| 816 | - unset($price_tab[array_search(WPSHOP_COST_OF_POSTAGE, $price_tab)]); |
|
| 817 | - $query = "SELECT GROUP_CONCAT(id) FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE code IN ('" . implode("','", $price_tab) . "')"; |
|
| 818 | - $attribute_ids = $wpdb->get_var($query); |
|
| 746 | + /* Delete useless database table */ |
|
| 747 | + $query = "DROP TABLE " . WPSHOP_DBT_CART; |
|
| 748 | + $wpdb->query($query); |
|
| 749 | + $query = "DROP TABLE " . WPSHOP_DBT_CART_CONTENTS; |
|
| 750 | + $wpdb->query($query); |
|
| 751 | + return true; |
|
| 752 | + break; |
|
| 753 | + case 13: |
|
| 754 | + $attribute_used_for_sort_by = wpshop_attributes::getElement('yes', "'valid', 'moderated', 'notused'", 'is_used_for_sort_by', true); |
|
| 755 | + foreach ($attribute_used_for_sort_by as $attribute) { |
|
| 756 | + $data = query_posts(array('posts_per_page' => -1, 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT)); |
|
| 757 | + foreach ($data as $post) { |
|
| 758 | + $postmeta = get_post_meta($post->ID, '_wpshop_product_metadata', true); |
|
| 759 | + if (!empty($postmeta[$attribute->code])) { |
|
| 760 | + update_post_meta($post->ID, '_' . $attribute->code, $postmeta[$attribute->code]); |
|
| 761 | + } |
|
| 762 | + } |
|
| 763 | + wp_reset_query(); |
|
| 764 | + } |
|
| 765 | + return true; |
|
| 766 | + break; |
|
| 767 | + case 17: |
|
| 768 | + $products = query_posts(array( |
|
| 769 | + 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT) |
|
| 770 | + ); |
|
| 771 | + $query = $wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE_SET . " WHERE default_set = %s", 'yes'); |
|
| 772 | + $default_attribute_set = $wpdb->get_var($query); |
|
| 773 | + foreach ($products as $product) { |
|
| 774 | + $p_att_set_id = get_post_meta($product->ID, WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, true); |
|
| 775 | + if (empty($p_att_set_id)) { |
|
| 776 | + /* Update the attribute set id for the current product */ |
|
| 777 | + update_post_meta($product->ID, WPSHOP_PRODUCT_ATTRIBUTE_SET_ID_META_KEY, $default_attribute_set); |
|
| 778 | + } |
|
| 779 | + wp_reset_query(); |
|
| 780 | + } |
|
| 781 | + self::wpshop_insert_default_pages($wpshop_shop_type); |
|
| 782 | + wp_cache_flush(); |
|
| 783 | + return true; |
|
| 784 | + break; |
|
| 785 | + case 18: |
|
| 786 | + self::wpshop_insert_default_pages($wpshop_shop_type); |
|
| 787 | + wp_cache_flush(); |
|
| 788 | + return true; |
|
| 789 | + break; |
|
| 790 | + case 19: |
|
| 791 | + $wp_rewrite->flush_rules(); |
|
| 792 | + return true; |
|
| 793 | + break; |
|
| 794 | + |
|
| 795 | + case 21: |
|
| 796 | + /** |
|
| 797 | + * Correction des valeurs pour l'attributs "gestion du stock" qui n'�taient pas cr�es automatiquement |
|
| 798 | + */ |
|
| 799 | + $query = $wpdb->prepare("SELECT ATTR_OPT.id, ATTR_OPT.value, ATTR_OPT.label, ATTR_OPT.position, ATTR_OPT.attribute_id FROM " . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . " AS ATTR_OPT INNER JOIN " . WPSHOP_DBT_ATTRIBUTE . " AS ATTR ON (ATTR.id = ATTR_OPT.attribute_id) WHERE ATTR_OPT.status=%s AND ATTR.code=%s", 'valid', 'manage_stock'); |
|
| 800 | + $manage_stock_option = $wpdb->get_results($query); |
|
| 801 | + if (!empty($manage_stock_option)) { |
|
| 802 | + $no_is_present = false; |
|
| 803 | + $attribute_id = $manage_stock_option[0]->attribute_id; |
|
| 804 | + foreach ($manage_stock_option as $manage_definition) { |
|
| 805 | + if (strtolower(__($manage_definition->value, 'wpshop')) == strtolower(__('no', 'wpshop'))) { |
|
| 806 | + $no_is_present = true; |
|
| 807 | + } |
|
| 808 | + } |
|
| 809 | + if (!$no_is_present) { |
|
| 810 | + $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS, array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'last_update_date' => current_time('mysql', 0), 'attribute_id' => $attribute_id, 'value' => 'no', 'label' => __('No', 'wpshop'))); |
|
| 811 | + } |
|
| 812 | + } |
|
| 819 | 813 | |
| 820 | - $query = $wpdb->prepare(" |
|
| 814 | + /** Change price attribute set section order for default set */ |
|
| 815 | + $price_tab = unserialize(WPSHOP_ATTRIBUTE_PRICES); |
|
| 816 | + unset($price_tab[array_search(WPSHOP_COST_OF_POSTAGE, $price_tab)]); |
|
| 817 | + $query = "SELECT GROUP_CONCAT(id) FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE code IN ('" . implode("','", $price_tab) . "')"; |
|
| 818 | + $attribute_ids = $wpdb->get_var($query); |
|
| 819 | + |
|
| 820 | + $query = $wpdb->prepare(" |
|
| 821 | 821 | SELECT ATTR_DET.attribute_group_id |
| 822 | 822 | FROM " . WPSHOP_DBT_ATTRIBUTE_DETAILS . " AS ATTR_DET |
| 823 | 823 | INNER JOIN " . WPSHOP_DBT_ATTRIBUTE_GROUP . " AS ATTR_GROUP ON ((ATTR_GROUP.id = ATTR_DET.attribute_group_id) AND (ATTR_GROUP.code = %s)) |
| 824 | 824 | INNER JOIN " . WPSHOP_DBT_ATTRIBUTE_SET . " AS ATTR_SET ON ((ATTR_SET.id = ATTR_GROUP.attribute_set_id) AND (ATTR_SET.name = %s)) |
| 825 | 825 | WHERE ATTR_DET.attribute_id IN (" . $attribute_ids . ")" |
| 826 | - , 'prices', __('default', 'wpshop')); |
|
| 827 | - $list = $wpdb->get_results($query); |
|
| 828 | - if (!empty($list)) { |
|
| 829 | - $change_order = true; |
|
| 830 | - $old_value = $list[0]->attribute_group_id; |
|
| 831 | - unset($list[0]); |
|
| 832 | - if (!empty($list)) { |
|
| 833 | - foreach ($list as $data) { |
|
| 834 | - if ($old_value != $data->attribute_group_id) { |
|
| 835 | - $change_order = false; |
|
| 836 | - } |
|
| 837 | - } |
|
| 838 | - if ($change_order) { |
|
| 839 | - foreach ($price_tab as $price_code) { |
|
| 840 | - $query = $wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE code = %s", $price_code); |
|
| 841 | - $attribute_id = $wpdb->get_var($query); |
|
| 842 | - switch ($price_code) { |
|
| 843 | - case WPSHOP_PRODUCT_PRICE_HT: |
|
| 844 | - $position = (WPSHOP_PRODUCT_PRICE_PILOT == 'HT') ? 1 : 3; |
|
| 845 | - break; |
|
| 846 | - case WPSHOP_PRODUCT_PRICE_TAX: |
|
| 847 | - $position = 2; |
|
| 848 | - break; |
|
| 849 | - case WPSHOP_PRODUCT_PRICE_TTC: |
|
| 850 | - $position = (WPSHOP_PRODUCT_PRICE_PILOT == 'HT') ? 3 : 1; |
|
| 851 | - break; |
|
| 852 | - case WPSHOP_PRODUCT_PRICE_TAX_AMOUNT: |
|
| 853 | - $position = 4; |
|
| 854 | - break; |
|
| 855 | - } |
|
| 856 | - $wpdb->update(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('status' => 'valid', 'last_update_date' => current_time('mysql', 0), 'position' => $position), array('attribute_group_id' => $old_value, 'attribute_id' => $attribute_id)); |
|
| 857 | - } |
|
| 858 | - } |
|
| 859 | - } |
|
| 860 | - } |
|
| 861 | - return true; |
|
| 862 | - break; |
|
| 863 | - case 22: |
|
| 864 | - $query = $wpdb->prepare("SELECT ID FROM " . $wpdb->posts . " WHERE post_name = %s", WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT); |
|
| 865 | - $product_entity_id = $wpdb->get_var($query); |
|
| 866 | - if (empty($product_entityd_id) || ($product_entity_id <= 0) || !$product_entity_id) { |
|
| 867 | - /* Create the product entity into post table */ |
|
| 868 | - $product_entity = array( |
|
| 869 | - 'post_title' => __('Products', 'wpshop'), |
|
| 870 | - 'post_name' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, |
|
| 871 | - 'post_content' => __('Define the entity allowing to manage product on your store. If you delete this entity you won\'t be able to manage your store', 'wpshop'), |
|
| 872 | - 'post_status' => 'publish', |
|
| 873 | - 'post_author' => 1, |
|
| 874 | - 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES, |
|
| 875 | - ); |
|
| 876 | - $product_entity_id = wp_insert_post($product_entity); |
|
| 877 | - } |
|
| 878 | - |
|
| 879 | - /* Update eav table with the new entity id for product */ |
|
| 880 | - $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('entity_id' => $product_entity_id), array('entity_id' => 1)); |
|
| 881 | - $wpdb->update(WPSHOP_DBT_ATTRIBUTE_SET, array('entity_id' => $product_entity_id), array('entity_id' => 1)); |
|
| 882 | - $wpdb->update(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('entity_type_id' => $product_entity_id), array('entity_type_id' => 1)); |
|
| 883 | - $wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_DATETIME, array('entity_type_id' => $product_entity_id), array('entity_type_id' => 1)); |
|
| 884 | - $wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('entity_type_id' => $product_entity_id), array('entity_type_id' => 1)); |
|
| 885 | - $wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_INTEGER, array('entity_type_id' => $product_entity_id), array('entity_type_id' => 1)); |
|
| 886 | - $wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_TEXT, array('entity_type_id' => $product_entity_id), array('entity_type_id' => 1)); |
|
| 887 | - $wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_VARCHAR, array('entity_type_id' => $product_entity_id), array('entity_type_id' => 1)); |
|
| 888 | - $wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_HISTO, array('entity_type_id' => $product_entity_id), array('entity_type_id' => 1)); |
|
| 889 | - |
|
| 890 | - /* Create an element of customer entity for each existing user */ |
|
| 891 | - $user_list = get_users(); |
|
| 892 | - foreach ($user_list as $user) { |
|
| 893 | - wps_customer_ctr::create_entity_customer_when_user_is_created($user->ID); |
|
| 894 | - } |
|
| 895 | - |
|
| 896 | - return true; |
|
| 897 | - break; |
|
| 898 | - case 23: |
|
| 899 | - /* Delete duplicate entities */ |
|
| 900 | - $query = ("SELECT ID FROM " . $wpdb->posts . " WHERE post_name LIKE '%" . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . "%' "); |
|
| 901 | - $product_entity_list = $wpdb->get_results($query); |
|
| 902 | - if (count($product_entity_list) > 1) { |
|
| 903 | - $i = 0; |
|
| 904 | - foreach ($product_entity_list as $product_entity) { |
|
| 905 | - if ($i > 0) { |
|
| 906 | - wp_delete_post($product_entity->ID); |
|
| 907 | - } |
|
| 908 | - } |
|
| 909 | - } |
|
| 910 | - return true; |
|
| 911 | - break; |
|
| 912 | - case 24: |
|
| 913 | - /* Update the link status for disabled attribute set */ |
|
| 914 | - $query = $wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE_GROUP . " WHERE status = %s", 'deleted'); |
|
| 915 | - $deleted_attribute_group = $wpdb->get_results($query); |
|
| 916 | - if (!empty($deleted_attribute_group)) { |
|
| 917 | - foreach ($deleted_attribute_group as $group) { |
|
| 918 | - $wpdb->update(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('status' => 'deleted', 'last_update_date' => current_time('mysql', 0)), array('attribute_group_id' => $group->id)); |
|
| 919 | - } |
|
| 920 | - } |
|
| 921 | - |
|
| 922 | - /* Update entities meta management */ |
|
| 923 | - $entities = query_posts(array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES)); |
|
| 924 | - if (!empty($entities)) { |
|
| 925 | - foreach ($entities as $entity) { |
|
| 926 | - $support = get_post_meta($entity->ID, '_wpshop_entity_support', true); |
|
| 927 | - $rewrite = get_post_meta($entity->ID, '_wpshop_entity_rewrite', true); |
|
| 928 | - update_post_meta($entity->ID, '_wpshop_entity_params', array('support' => $support, 'rewrite' => array('slug' => $rewrite))); |
|
| 929 | - } |
|
| 930 | - } |
|
| 931 | - wp_reset_query(); |
|
| 932 | - return true; |
|
| 933 | - break; |
|
| 934 | - case 25: |
|
| 935 | - /* Get the first entities of product and customer */ |
|
| 936 | - $query = $wpdb->prepare("SELECT ID FROM " . $wpdb->posts . " WHERE post_name=%s AND post_type=%s ORDER BY ID ASC LIMIT 1", WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES); |
|
| 937 | - $product_entity_id = $wpdb->get_var($query); |
|
| 938 | - |
|
| 939 | - /* Update attributes that are not linked with entities */ |
|
| 940 | - $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('entity_id' => $product_entity_id), array('entity_id' => 0)); |
|
| 941 | - |
|
| 942 | - /* Get entities that have been created a lot of time and delete them */ |
|
| 943 | - $query = $wpdb->prepare("SELECT ID FROM " . $wpdb->posts . " WHERE (post_name LIKE '%%" . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . "-%%' OR post_name LIKE '%%" . WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS . "-%%') AND post_type=%s", WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES); |
|
| 944 | - $entities_to_delete = $wpdb->get_results($query); |
|
| 945 | - if (!empty($entities_to_delete) && is_array($entities_to_delete)) { |
|
| 946 | - foreach ($entities_to_delete as $entity) { |
|
| 947 | - wp_delete_post($entity->ID, true); |
|
| 948 | - } |
|
| 949 | - } |
|
| 950 | - |
|
| 951 | - /* Get post list that are children of entities created a lot of time */ |
|
| 952 | - $query = $wpdb->prepare("SELECT ID FROM " . $wpdb->posts . " WHERE post_type LIKE %s", WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS . "-%"); |
|
| 953 | - $entities_to_update = $wpdb->get_results($query); |
|
| 954 | - if (!empty($entities_to_update) && is_array($entities_to_update)) { |
|
| 955 | - foreach ($entities_to_update as $entity) { |
|
| 956 | - wp_update_post(array('ID' => $entity->ID, 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS)); |
|
| 957 | - } |
|
| 958 | - } |
|
| 959 | - $query = $wpdb->prepare("SELECT ID FROM " . $wpdb->posts . " WHERE post_type LIKE %s", WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . "-%"); |
|
| 960 | - $entities_to_update = $wpdb->get_results($query); |
|
| 961 | - if (!empty($entities_to_update) && is_array($entities_to_update)) { |
|
| 962 | - foreach ($entities_to_update as $entity) { |
|
| 963 | - wp_update_post(array('ID' => $entity->ID, 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT)); |
|
| 964 | - } |
|
| 965 | - } |
|
| 966 | - |
|
| 967 | - /* Change addons managament */ |
|
| 968 | - $wpshop_addons_options = get_option('wpshop_addons_state', array()); |
|
| 969 | - if (!empty($wpshop_addons_options)) { |
|
| 970 | - foreach ($wpshop_addons_options as $addon_name => $addon_state) { |
|
| 971 | - $options_args = array(); |
|
| 972 | - $options_args[$addon_name]['activate'] = $addon_state; |
|
| 973 | - $options_args[$addon_name]['activation_date'] = current_time('mysql', 0); |
|
| 974 | - if (!$addon_state) { |
|
| 975 | - $options_args[$addon_name]['deactivation_date'] = current_time('mysql', 0); |
|
| 976 | - } |
|
| 826 | + , 'prices', __('default', 'wpshop')); |
|
| 827 | + $list = $wpdb->get_results($query); |
|
| 828 | + if (!empty($list)) { |
|
| 829 | + $change_order = true; |
|
| 830 | + $old_value = $list[0]->attribute_group_id; |
|
| 831 | + unset($list[0]); |
|
| 832 | + if (!empty($list)) { |
|
| 833 | + foreach ($list as $data) { |
|
| 834 | + if ($old_value != $data->attribute_group_id) { |
|
| 835 | + $change_order = false; |
|
| 836 | + } |
|
| 837 | + } |
|
| 838 | + if ($change_order) { |
|
| 839 | + foreach ($price_tab as $price_code) { |
|
| 840 | + $query = $wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE . " WHERE code = %s", $price_code); |
|
| 841 | + $attribute_id = $wpdb->get_var($query); |
|
| 842 | + switch ($price_code) { |
|
| 843 | + case WPSHOP_PRODUCT_PRICE_HT: |
|
| 844 | + $position = (WPSHOP_PRODUCT_PRICE_PILOT == 'HT') ? 1 : 3; |
|
| 845 | + break; |
|
| 846 | + case WPSHOP_PRODUCT_PRICE_TAX: |
|
| 847 | + $position = 2; |
|
| 848 | + break; |
|
| 849 | + case WPSHOP_PRODUCT_PRICE_TTC: |
|
| 850 | + $position = (WPSHOP_PRODUCT_PRICE_PILOT == 'HT') ? 3 : 1; |
|
| 851 | + break; |
|
| 852 | + case WPSHOP_PRODUCT_PRICE_TAX_AMOUNT: |
|
| 853 | + $position = 4; |
|
| 854 | + break; |
|
| 855 | + } |
|
| 856 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('status' => 'valid', 'last_update_date' => current_time('mysql', 0), 'position' => $position), array('attribute_group_id' => $old_value, 'attribute_id' => $attribute_id)); |
|
| 857 | + } |
|
| 858 | + } |
|
| 859 | + } |
|
| 860 | + } |
|
| 861 | + return true; |
|
| 862 | + break; |
|
| 863 | + case 22: |
|
| 864 | + $query = $wpdb->prepare("SELECT ID FROM " . $wpdb->posts . " WHERE post_name = %s", WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT); |
|
| 865 | + $product_entity_id = $wpdb->get_var($query); |
|
| 866 | + if (empty($product_entityd_id) || ($product_entity_id <= 0) || !$product_entity_id) { |
|
| 867 | + /* Create the product entity into post table */ |
|
| 868 | + $product_entity = array( |
|
| 869 | + 'post_title' => __('Products', 'wpshop'), |
|
| 870 | + 'post_name' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, |
|
| 871 | + 'post_content' => __('Define the entity allowing to manage product on your store. If you delete this entity you won\'t be able to manage your store', 'wpshop'), |
|
| 872 | + 'post_status' => 'publish', |
|
| 873 | + 'post_author' => 1, |
|
| 874 | + 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES, |
|
| 875 | + ); |
|
| 876 | + $product_entity_id = wp_insert_post($product_entity); |
|
| 877 | + } |
|
| 977 | 878 | |
| 978 | - add_option(WPSHOP_ADDONS_OPTION_NAME, $options_args); |
|
| 979 | - } |
|
| 980 | - delete_option('wpshop_addons_state'); |
|
| 981 | - } |
|
| 982 | - |
|
| 983 | - /* Update the different entities id into attribute set details table */ |
|
| 984 | - $query = "UPDATE " . WPSHOP_DBT_ATTRIBUTE_DETAILS . " AS ATT_DET INNER JOIN " . WPSHOP_DBT_ATTRIBUTE . " AS ATT ON (ATT.id = ATT_DET.attribute_id) SET ATT_DET.entity_type_id = ATT.entity_id"; |
|
| 985 | - $wpdb->query($query); |
|
| 986 | - |
|
| 987 | - return true; |
|
| 988 | - break; |
|
| 989 | - case 26: |
|
| 990 | - $query = "SELECT post_id, meta_value FROM " . $wpdb->postmeta . " WHERE meta_key = '_order_postmeta' "; |
|
| 991 | - $results = $wpdb->get_results($query); |
|
| 992 | - foreach ($results as $result) { |
|
| 993 | - $order_info = unserialize($result->meta_value); |
|
| 994 | - update_post_meta($result->post_id, '_wpshop_order_customer_id', $order_info['customer_id']); |
|
| 995 | - update_post_meta($result->post_id, '_wpshop_order_shipping_date', $order_info['order_shipping_date']); |
|
| 996 | - update_post_meta($result->post_id, '_wpshop_order_status', $order_info['order_status']); |
|
| 997 | - } |
|
| 998 | - |
|
| 999 | - /* Update the different entities id into attribute set details table */ |
|
| 1000 | - $query = "UPDATE " . WPSHOP_DBT_ATTRIBUTE_DETAILS . " AS ATT_DET INNER JOIN " . WPSHOP_DBT_ATTRIBUTE . " AS ATT ON (ATT.id = ATT_DET.attribute_id) SET ATT_DET.entity_type_id = ATT.entity_id"; |
|
| 1001 | - $wpdb->query($query); |
|
| 1002 | - |
|
| 1003 | - return true; |
|
| 1004 | - break; |
|
| 1005 | - |
|
| 1006 | - case 29: |
|
| 1007 | - $billing_title = __('Billing address', 'wpshop'); |
|
| 1008 | - $shipping_title = __('Shipping address', 'wpshop'); |
|
| 1009 | - |
|
| 1010 | - //UPDATE USERS ADDRESSES |
|
| 1011 | - $billing_address_set_id_query = 'SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE name = "' . $billing_title . '"'; |
|
| 1012 | - $shipping_address_set_id_query = 'SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE name = "' . $shipping_title . '"'; |
|
| 1013 | - |
|
| 1014 | - $billing_address_set_id = $wpdb->get_var($billing_address_set_id_query); |
|
| 1015 | - $shipping_address_set_id = $wpdb->get_var($shipping_address_set_id_query); |
|
| 1016 | - |
|
| 1017 | - //Add Address & Google Map API KEY options |
|
| 1018 | - add_option('wpshop_billing_address', array('choice' => $billing_address_set_id), '', 'yes'); |
|
| 1019 | - add_option('wpshop_shipping_address_choice', array('activate' => 'on', 'choice' => $shipping_address_set_id), '', 'yes'); |
|
| 1020 | - add_option('wpshop_google_map_api_key', '', '', 'yes'); |
|
| 1021 | - |
|
| 1022 | - $query = 'SELECT * FROM ' . $wpdb->users . ''; |
|
| 1023 | - $results = $wpdb->get_results($query); |
|
| 1024 | - foreach ($results as $result) { |
|
| 1025 | - $billing_infos = get_user_meta($result->ID, 'billing_info', true); |
|
| 1026 | - $shipping_infos = get_user_meta($result->ID, 'shipping_info', true); |
|
| 1027 | - if (!empty($billing_infos)) { |
|
| 1028 | - //Save Billing Infos |
|
| 1029 | - $billing_address = array(); |
|
| 1030 | - if (!empty($billing_infos['civility'])) { |
|
| 1031 | - switch ($billing_infos['civility']) { |
|
| 1032 | - case 1: |
|
| 1033 | - $civility = $mister_id; |
|
| 1034 | - break; |
|
| 1035 | - case 2: |
|
| 1036 | - $civility = $madam_id; |
|
| 1037 | - break; |
|
| 1038 | - case 3: |
|
| 1039 | - $civility = $miss_id; |
|
| 1040 | - break; |
|
| 1041 | - } |
|
| 1042 | - } else { |
|
| 1043 | - $civility = $mister_id; |
|
| 1044 | - } |
|
| 1045 | - $billing_address = array('address_title' => $billing_title, |
|
| 1046 | - 'address_last_name' => !empty($billing_infos['last_name']) ? $billing_infos['last_name'] : '', |
|
| 1047 | - 'address_first_name' => !empty($billing_infos['first_name']) ? $billing_infos['first_name'] : '', |
|
| 1048 | - 'company' => !empty($billing_infos['company']) ? $billing_infos['company'] : '', |
|
| 1049 | - 'address' => !empty($billing_infos['address']) ? $billing_infos['address'] : '', |
|
| 1050 | - 'postcode' => !empty($billing_infos['postcode']) ? $billing_infos['postcode'] : '', |
|
| 1051 | - 'city' => !empty($billing_infos['city']) ? $billing_infos['city'] : '', |
|
| 1052 | - 'state' => !empty($billing_infos['state']) ? $billing_infos['state'] : '', |
|
| 1053 | - 'country' => !empty($billing_infos['country']) ? $billing_infos['country'] : '', |
|
| 1054 | - 'address_user_email' => !empty($billing_infos['email']) ? $billing_infos['email'] : '', |
|
| 1055 | - 'phone' => !empty($billing_infos['phone']) ? $billing_infos['phone'] : '', |
|
| 1056 | - 'tva_intra' => !empty($billing_infos['company_tva_intra']) ? $billing_infos['company_tva_intra'] : '', |
|
| 1057 | - 'civility' => $civility, |
|
| 1058 | - ); |
|
| 1059 | - //Create the post and post_meta for the billing address |
|
| 1060 | - $post_address = array( |
|
| 1061 | - 'post_author' => $result->ID, |
|
| 1062 | - 'post_title' => $billing_title, |
|
| 1063 | - 'post_status' => 'publish', |
|
| 1064 | - 'post_name' => WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS, |
|
| 1065 | - 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS, |
|
| 1066 | - 'post_parent' => $result->ID, |
|
| 1067 | - ); |
|
| 1068 | - $post_address_id = wp_insert_post($post_address); |
|
| 1069 | - |
|
| 1070 | - //Create the post_meta with the address infos |
|
| 1071 | - update_post_meta($post_address_id, '_' . WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS . '_metadata', $billing_address); |
|
| 1072 | - update_post_meta($post_address_id, '_' . WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS . '_attribute_set_id', $billing_address_set_id); |
|
| 1073 | - } |
|
| 879 | + /* Update eav table with the new entity id for product */ |
|
| 880 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('entity_id' => $product_entity_id), array('entity_id' => 1)); |
|
| 881 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE_SET, array('entity_id' => $product_entity_id), array('entity_id' => 1)); |
|
| 882 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('entity_type_id' => $product_entity_id), array('entity_type_id' => 1)); |
|
| 883 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_DATETIME, array('entity_type_id' => $product_entity_id), array('entity_type_id' => 1)); |
|
| 884 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_DECIMAL, array('entity_type_id' => $product_entity_id), array('entity_type_id' => 1)); |
|
| 885 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_INTEGER, array('entity_type_id' => $product_entity_id), array('entity_type_id' => 1)); |
|
| 886 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_TEXT, array('entity_type_id' => $product_entity_id), array('entity_type_id' => 1)); |
|
| 887 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_VARCHAR, array('entity_type_id' => $product_entity_id), array('entity_type_id' => 1)); |
|
| 888 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE_VALUES_HISTO, array('entity_type_id' => $product_entity_id), array('entity_type_id' => 1)); |
|
| 889 | + |
|
| 890 | + /* Create an element of customer entity for each existing user */ |
|
| 891 | + $user_list = get_users(); |
|
| 892 | + foreach ($user_list as $user) { |
|
| 893 | + wps_customer_ctr::create_entity_customer_when_user_is_created($user->ID); |
|
| 894 | + } |
|
| 1074 | 895 | |
| 1075 | - if (!empty($shipping_infos)) { |
|
| 1076 | - //Save Shipping Infos |
|
| 1077 | - if (!empty($shipping_infos['civility'])) { |
|
| 1078 | - switch ($shipping_infos['civility']) { |
|
| 1079 | - case 1: |
|
| 1080 | - $civility = $mister_id; |
|
| 1081 | - break; |
|
| 1082 | - case 2: |
|
| 1083 | - $civility = $madam_id; |
|
| 1084 | - break; |
|
| 1085 | - case 3: |
|
| 1086 | - $civility = $miss_id; |
|
| 1087 | - break; |
|
| 1088 | - } |
|
| 1089 | - } else { |
|
| 1090 | - $civility = $mister_id; |
|
| 1091 | - } |
|
| 1092 | - $shipping_address = array(); |
|
| 1093 | - $shipping_address = array('address_title' => $shipping_title, |
|
| 1094 | - 'address_last_name' => !empty($shipping_infos['last_name']) ? $shipping_infos['last_name'] : '', |
|
| 1095 | - 'address_first_name' => !empty($shipping_infos['first_name']) ? $shipping_infos['first_name'] : '', |
|
| 1096 | - 'company' => !empty($shipping_infos['company']) ? $shipping_infos['company'] : '', |
|
| 1097 | - 'address' => !empty($shipping_infos['address']) ? $shipping_infos['address'] : '', |
|
| 1098 | - 'postcode' => !empty($shipping_infos['postcode']) ? $shipping_infos['postcode'] : '', |
|
| 1099 | - 'city' => !empty($shipping_infos['city']) ? $shipping_infos['city'] : '', |
|
| 1100 | - 'state' => !empty($shipping_infos['state']) ? $shipping_infos['state'] : '', |
|
| 1101 | - 'country' => !empty($shipping_infos['country']) ? $shipping_infos['country'] : '', |
|
| 1102 | - 'civility' => $civility, |
|
| 1103 | - ); |
|
| 1104 | - //Create the post and post_meta for the billing address |
|
| 1105 | - $post_address = array( |
|
| 1106 | - 'post_author' => $result->ID, |
|
| 1107 | - 'post_title' => $shipping_title, |
|
| 1108 | - 'post_status' => 'publish', |
|
| 1109 | - 'post_name' => WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS, |
|
| 1110 | - 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS, |
|
| 1111 | - 'post_parent' => $result->ID, |
|
| 1112 | - ); |
|
| 1113 | - $post_address_id = wp_insert_post($post_address); |
|
| 1114 | - //Create the post_meta with the address infos |
|
| 1115 | - update_post_meta($post_address_id, '_' . WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS . '_metadata', $shipping_address); |
|
| 1116 | - update_post_meta($post_address_id, '_' . WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS . '_attribute_set_id', $shipping_address_set_id); |
|
| 1117 | - } |
|
| 1118 | - } |
|
| 1119 | - |
|
| 1120 | - // FORMATE THE ORDER ADDRESSES INFOS |
|
| 1121 | - $results = query_posts(array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ORDER, 'posts_per_page' => -1)); |
|
| 1122 | - foreach ($results as $result) { |
|
| 1123 | - $address = get_post_meta($result->ID, '_order_info', true); |
|
| 1124 | - |
|
| 1125 | - $billing_address = array(); |
|
| 1126 | - if (!empty($address['billing'])) { |
|
| 1127 | - if (!empty($address['billing']['civility'])) { |
|
| 1128 | - switch ($address['billing']['civility']) { |
|
| 1129 | - case 1: |
|
| 1130 | - $civility = $mister_id; |
|
| 1131 | - break; |
|
| 1132 | - case 2: |
|
| 1133 | - $civility = $madam_id; |
|
| 1134 | - break; |
|
| 1135 | - case 3: |
|
| 1136 | - $civility = $miss_id; |
|
| 1137 | - break; |
|
| 1138 | - default: |
|
| 1139 | - $civility = $mister_id; |
|
| 1140 | - break; |
|
| 1141 | - } |
|
| 1142 | - } else { |
|
| 1143 | - $civility = $mister_id; |
|
| 1144 | - } |
|
| 1145 | - $billing_address = array('address_title' => $billing_title, |
|
| 1146 | - 'address_last_name' => !empty($address['billing']['last_name']) ? $address['billing']['last_name'] : '', |
|
| 1147 | - 'address_first_name' => !empty($address['billing']['first_name']) ? $address['billing']['first_name'] : '', |
|
| 1148 | - 'company' => !empty($address['billing']['company']) ? $address['billing']['company'] : '', |
|
| 1149 | - 'address' => !empty($address['billing']['address']) ? $address['billing']['address'] : '', |
|
| 1150 | - 'postcode' => !empty($address['billing']['postcode']) ? $address['billing']['postcode'] : '', |
|
| 1151 | - 'city' => !empty($address['billing']['city']) ? $address['billing']['city'] : '', |
|
| 1152 | - 'state' => !empty($address['billing']['state']) ? $address['billing']['state'] : '', |
|
| 1153 | - 'country' => !empty($address['billing']['country']) ? $address['billing']['country'] : '', |
|
| 1154 | - 'address_user_email' => !empty($address['billing']['email']) ? $address['billing']['email'] : '', |
|
| 1155 | - 'phone' => !empty($address['billing']['phone']) ? $address['billing']['phone'] : '', |
|
| 1156 | - 'tva_intra' => !empty($address['billing']['company_tva_intra']) ? $address['billing']['company_tva_intra'] : '', |
|
| 1157 | - 'civility' => $civility, |
|
| 1158 | - ); |
|
| 1159 | - } |
|
| 896 | + return true; |
|
| 897 | + break; |
|
| 898 | + case 23: |
|
| 899 | + /* Delete duplicate entities */ |
|
| 900 | + $query = ("SELECT ID FROM " . $wpdb->posts . " WHERE post_name LIKE '%" . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . "%' "); |
|
| 901 | + $product_entity_list = $wpdb->get_results($query); |
|
| 902 | + if (count($product_entity_list) > 1) { |
|
| 903 | + $i = 0; |
|
| 904 | + foreach ($product_entity_list as $product_entity) { |
|
| 905 | + if ($i > 0) { |
|
| 906 | + wp_delete_post($product_entity->ID); |
|
| 907 | + } |
|
| 908 | + } |
|
| 909 | + } |
|
| 910 | + return true; |
|
| 911 | + break; |
|
| 912 | + case 24: |
|
| 913 | + /* Update the link status for disabled attribute set */ |
|
| 914 | + $query = $wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE_GROUP . " WHERE status = %s", 'deleted'); |
|
| 915 | + $deleted_attribute_group = $wpdb->get_results($query); |
|
| 916 | + if (!empty($deleted_attribute_group)) { |
|
| 917 | + foreach ($deleted_attribute_group as $group) { |
|
| 918 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('status' => 'deleted', 'last_update_date' => current_time('mysql', 0)), array('attribute_group_id' => $group->id)); |
|
| 919 | + } |
|
| 920 | + } |
|
| 1160 | 921 | |
| 1161 | - $shipping_address = array(); |
|
| 1162 | - if (!empty($address['shipping'])) { |
|
| 1163 | - if (!empty($address['shipping']['civility'])) { |
|
| 1164 | - switch ($address['shipping']['civility']) { |
|
| 1165 | - case 1: |
|
| 1166 | - $civility = $mister_id; |
|
| 1167 | - break; |
|
| 1168 | - case 2: |
|
| 1169 | - $civility = $madam_id; |
|
| 1170 | - break; |
|
| 1171 | - case 3: |
|
| 1172 | - $civility = $miss_id; |
|
| 1173 | - break; |
|
| 1174 | - } |
|
| 1175 | - } else { |
|
| 1176 | - $civility = $mister_id; |
|
| 1177 | - } |
|
| 1178 | - $shipping_address = array('address_title' => $shipping_title, |
|
| 1179 | - 'address_last_name' => !empty($address['shipping']['last_name']) ? $address['shipping']['last_name'] : '', |
|
| 1180 | - 'address_first_name' => !empty($address['shipping']['first_name']) ? $address['shipping']['first_name'] : '', |
|
| 1181 | - 'company' => !empty($address['shipping']['company']) ? $address['shipping']['company'] : '', |
|
| 1182 | - 'address' => !empty($address['shipping']['address']) ? $address['shipping']['address'] : '', |
|
| 1183 | - 'postcode' => !empty($address['shipping']['postcode']) ? $address['shipping']['postcode'] : '', |
|
| 1184 | - 'city' => !empty($address['shipping']['city']) ? $address['shipping']['city'] : '', |
|
| 1185 | - 'state' => !empty($address['shipping']['state']) ? $address['shipping']['state'] : '', |
|
| 1186 | - 'country' => !empty($address['shipping']['country']) ? $address['shipping']['country'] : '', |
|
| 1187 | - 'civility' => $civility, |
|
| 1188 | - ); |
|
| 1189 | - } |
|
| 922 | + /* Update entities meta management */ |
|
| 923 | + $entities = query_posts(array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES)); |
|
| 924 | + if (!empty($entities)) { |
|
| 925 | + foreach ($entities as $entity) { |
|
| 926 | + $support = get_post_meta($entity->ID, '_wpshop_entity_support', true); |
|
| 927 | + $rewrite = get_post_meta($entity->ID, '_wpshop_entity_rewrite', true); |
|
| 928 | + update_post_meta($entity->ID, '_wpshop_entity_params', array('support' => $support, 'rewrite' => array('slug' => $rewrite))); |
|
| 929 | + } |
|
| 930 | + } |
|
| 931 | + wp_reset_query(); |
|
| 932 | + return true; |
|
| 933 | + break; |
|
| 934 | + case 25: |
|
| 935 | + /* Get the first entities of product and customer */ |
|
| 936 | + $query = $wpdb->prepare("SELECT ID FROM " . $wpdb->posts . " WHERE post_name=%s AND post_type=%s ORDER BY ID ASC LIMIT 1", WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES); |
|
| 937 | + $product_entity_id = $wpdb->get_var($query); |
|
| 938 | + |
|
| 939 | + /* Update attributes that are not linked with entities */ |
|
| 940 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('entity_id' => $product_entity_id), array('entity_id' => 0)); |
|
| 941 | + |
|
| 942 | + /* Get entities that have been created a lot of time and delete them */ |
|
| 943 | + $query = $wpdb->prepare("SELECT ID FROM " . $wpdb->posts . " WHERE (post_name LIKE '%%" . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . "-%%' OR post_name LIKE '%%" . WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS . "-%%') AND post_type=%s", WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES); |
|
| 944 | + $entities_to_delete = $wpdb->get_results($query); |
|
| 945 | + if (!empty($entities_to_delete) && is_array($entities_to_delete)) { |
|
| 946 | + foreach ($entities_to_delete as $entity) { |
|
| 947 | + wp_delete_post($entity->ID, true); |
|
| 948 | + } |
|
| 949 | + } |
|
| 1190 | 950 | |
| 1191 | - $billing_array_content = array('id' => $billing_address_set_id, 'address' => $billing_address); |
|
| 1192 | - $shipping_array_content = array('id' => $shipping_address_set_id, 'address' => $shipping_address); |
|
| 1193 | - $array_new_format = array('billing' => $billing_array_content, 'shipping' => $shipping_array_content); |
|
| 951 | + /* Get post list that are children of entities created a lot of time */ |
|
| 952 | + $query = $wpdb->prepare("SELECT ID FROM " . $wpdb->posts . " WHERE post_type LIKE %s", WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS . "-%"); |
|
| 953 | + $entities_to_update = $wpdb->get_results($query); |
|
| 954 | + if (!empty($entities_to_update) && is_array($entities_to_update)) { |
|
| 955 | + foreach ($entities_to_update as $entity) { |
|
| 956 | + wp_update_post(array('ID' => $entity->ID, 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS)); |
|
| 957 | + } |
|
| 958 | + } |
|
| 959 | + $query = $wpdb->prepare("SELECT ID FROM " . $wpdb->posts . " WHERE post_type LIKE %s", WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . "-%"); |
|
| 960 | + $entities_to_update = $wpdb->get_results($query); |
|
| 961 | + if (!empty($entities_to_update) && is_array($entities_to_update)) { |
|
| 962 | + foreach ($entities_to_update as $entity) { |
|
| 963 | + wp_update_post(array('ID' => $entity->ID, 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT)); |
|
| 964 | + } |
|
| 965 | + } |
|
| 1194 | 966 | |
| 1195 | - //Update the post meta |
|
| 1196 | - update_post_meta($result->ID, '_order_info', $array_new_format); |
|
| 1197 | - } |
|
| 967 | + /* Change addons managament */ |
|
| 968 | + $wpshop_addons_options = get_option('wpshop_addons_state', array()); |
|
| 969 | + if (!empty($wpshop_addons_options)) { |
|
| 970 | + foreach ($wpshop_addons_options as $addon_name => $addon_state) { |
|
| 971 | + $options_args = array(); |
|
| 972 | + $options_args[$addon_name]['activate'] = $addon_state; |
|
| 973 | + $options_args[$addon_name]['activation_date'] = current_time('mysql', 0); |
|
| 974 | + if (!$addon_state) { |
|
| 975 | + $options_args[$addon_name]['deactivation_date'] = current_time('mysql', 0); |
|
| 976 | + } |
|
| 977 | + |
|
| 978 | + add_option(WPSHOP_ADDONS_OPTION_NAME, $options_args); |
|
| 979 | + } |
|
| 980 | + delete_option('wpshop_addons_state'); |
|
| 981 | + } |
|
| 1198 | 982 | |
| 1199 | - /* Update entities meta management */ |
|
| 1200 | - $entities = query_posts(array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES, 'posts_per_page' => -1)); |
|
| 1201 | - if (!empty($entities)) { |
|
| 1202 | - foreach ($entities as $entity) { |
|
| 1203 | - $params = get_post_meta($entity->ID, '_wpshop_entity_params', true); |
|
| 1204 | - $support = (!empty($params['support'])) ? $params['support'] : ''; |
|
| 1205 | - $rewrite = (!empty($params['rewrite'])) ? $params['rewrite'] : ''; |
|
| 983 | + /* Update the different entities id into attribute set details table */ |
|
| 984 | + $query = "UPDATE " . WPSHOP_DBT_ATTRIBUTE_DETAILS . " AS ATT_DET INNER JOIN " . WPSHOP_DBT_ATTRIBUTE . " AS ATT ON (ATT.id = ATT_DET.attribute_id) SET ATT_DET.entity_type_id = ATT.entity_id"; |
|
| 985 | + $wpdb->query($query); |
|
| 1206 | 986 | |
| 1207 | - $display_admin_menu = 'on'; |
|
| 987 | + return true; |
|
| 988 | + break; |
|
| 989 | + case 26: |
|
| 990 | + $query = "SELECT post_id, meta_value FROM " . $wpdb->postmeta . " WHERE meta_key = '_order_postmeta' "; |
|
| 991 | + $results = $wpdb->get_results($query); |
|
| 992 | + foreach ($results as $result) { |
|
| 993 | + $order_info = unserialize($result->meta_value); |
|
| 994 | + update_post_meta($result->post_id, '_wpshop_order_customer_id', $order_info['customer_id']); |
|
| 995 | + update_post_meta($result->post_id, '_wpshop_order_shipping_date', $order_info['order_shipping_date']); |
|
| 996 | + update_post_meta($result->post_id, '_wpshop_order_status', $order_info['order_status']); |
|
| 997 | + } |
|
| 1208 | 998 | |
| 1209 | - update_post_meta($entity->ID, '_wpshop_entity_params', array('support' => $support, 'rewrite' => $rewrite, 'display_admin_menu' => $display_admin_menu)); |
|
| 1210 | - } |
|
| 1211 | - } |
|
| 1212 | - wp_reset_query(); |
|
| 1213 | - |
|
| 1214 | - // Default Weight unity and Currency Options |
|
| 1215 | - add_option('wpshop_shop_weight_group', 3, '', 'yes'); |
|
| 1216 | - add_option('wpshop_shop_default_weight_unity', 6, '', 'yes'); |
|
| 1217 | - add_option('wpshop_shop_currency_group', 4, '', 'yes'); |
|
| 1218 | - |
|
| 1219 | - $default_currency = get_option('wpshop_shop_default_currency'); |
|
| 1220 | - foreach (unserialize(WPSHOP_SHOP_CURRENCIES) as $k => $v) { |
|
| 1221 | - if ($default_currency == $k) { |
|
| 1222 | - $symbol = $v; |
|
| 1223 | - } |
|
| 1224 | - } |
|
| 1225 | - if (!empty($symbol)) { |
|
| 1226 | - $query = 'SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_UNIT . ' WHERE name = "' . html_entity_decode($symbol, ENT_QUOTES, 'UTF-8') . '"'; |
|
| 1227 | - $currency = $wpdb->get_row($query); |
|
| 1228 | - if (!empty($currency)) { |
|
| 1229 | - update_option('wpshop_shop_default_currency', $currency->id); |
|
| 1230 | - // Update the change rate of the default currency |
|
| 1231 | - $wpdb->update(WPSHOP_DBT_ATTRIBUTE_UNIT, array('change_rate' => 1), array('id' => $currency->id)); |
|
| 1232 | - } |
|
| 1233 | - } |
|
| 1234 | - |
|
| 1235 | - // Update the field for variation and user definition field |
|
| 1236 | - $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('is_used_for_variation' => 'yes'), array('is_user_defined' => 'yes')); |
|
| 1237 | - // Update field type for frontend output selection |
|
| 1238 | - $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('frontend_input' => 'text'), array()); |
|
| 1239 | - $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('frontend_input' => 'textarea'), array('backend_input' => 'textarea')); |
|
| 1240 | - $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('frontend_input' => 'select'), array('backend_input' => 'multiple-select')); |
|
| 1241 | - $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('frontend_input' => 'select'), array('backend_input' => 'select')); |
|
| 1242 | - |
|
| 1243 | - add_option('wpshop_cart_option', array('product_added_to_cart' => array('dialog_msg'), 'product_added_to_quotation' => array('cart_page'))); |
|
| 1244 | - |
|
| 1245 | - return true; |
|
| 1246 | - break; |
|
| 1247 | - |
|
| 1248 | - case '30': |
|
| 1249 | - /** Update the current price piloting field for using it into variation specific attributes */ |
|
| 1250 | - $price_piloting_attribute = constant('WPSHOP_PRODUCT_PRICE_' . WPSHOP_PRODUCT_PRICE_PILOT); |
|
| 1251 | - $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('is_used_in_variation' => 'yes', 'last_update_date' => current_time('mysql', 0)), array('code' => $price_piloting_attribute)); |
|
| 1252 | - |
|
| 1253 | - /** Update the product reference field for using it into variation specific attributes */ |
|
| 1254 | - $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('is_used_in_variation' => 'yes', 'last_update_date' => current_time('mysql', 0)), array('code' => 'product_reference')); |
|
| 1255 | - |
|
| 1256 | - /** Insert new message for admin when a customer make an order */ |
|
| 1257 | - $admin_new_order_message = get_option('WPSHOP_NEW_ORDER_ADMIN_MESSAGE'); |
|
| 1258 | - if (empty($admin_new_order_message)) { |
|
| 1259 | - wps_message_ctr::createMessage('WPSHOP_NEW_ORDER_ADMIN_MESSAGE'); |
|
| 1260 | - } |
|
| 1261 | - /** Update all amount for paypal orders */ |
|
| 1262 | - $query = $wpdb->prepare("SELECT post_id FROM " . $wpdb->postmeta . " WHERE meta_key = %s AND meta_value = %s ", '_wpshop_payment_method', 'paypal'); |
|
| 1263 | - $paypal_payment_list = $wpdb->get_results($query); |
|
| 1264 | - if (!empty($paypal_payment_list)) { |
|
| 1265 | - foreach ($paypal_payment_list as $post) { |
|
| 1266 | - $order_meta = get_post_meta($post->post_id, '_order_postmeta', true); |
|
| 1267 | - $order_payment_meta = get_post_meta($post->post_id, 'wpshop_payment_return_data', true); |
|
| 1268 | - if (!empty($order_meta['order_status']) && ($order_meta['order_status'] == 'incorrect_amount')) { |
|
| 1269 | - if (!empty($order_meta['order_grand_total']) && !empty($order_payment_meta['mc_gross'])) { |
|
| 1270 | - $order_amount_to_pay = number_format($order_meta['order_grand_total'], 5); |
|
| 1271 | - $order_amount_payed = number_format(floatval($order_payment_meta['mc_gross']), 5); |
|
| 1272 | - if ($order_amount_payed == $order_amount_to_pay) { |
|
| 1273 | - wpshop_payment::setOrderPaymentStatus($order_id, 'completed'); |
|
| 1274 | - } |
|
| 1275 | - } |
|
| 1276 | - } |
|
| 1277 | - } |
|
| 1278 | - } |
|
| 1279 | - |
|
| 1280 | - /** Save existing orders address information */ |
|
| 1281 | - $billing_title = __('Billing address', 'wpshop'); |
|
| 1282 | - $shipping_title = __('Shipping address', 'wpshop'); |
|
| 1283 | - $results = query_posts(array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ORDER, 'posts_per_page' => -1)); |
|
| 1284 | - foreach ($results as $result) { |
|
| 1285 | - $address = get_post_meta($result->ID, '_order_info', true); |
|
| 1286 | - $address_format = array(); |
|
| 1287 | - |
|
| 1288 | - $billing_address = array(); |
|
| 1289 | - if (!empty($address['billing']) && empty($address['billing']['id'])) { |
|
| 1290 | - if (!empty($address['billing']['civility'])) { |
|
| 1291 | - switch ($address['billing']['civility']) { |
|
| 1292 | - case 1: |
|
| 1293 | - $civility = $mister_id; |
|
| 1294 | - break; |
|
| 1295 | - case 2: |
|
| 1296 | - $civility = $madam_id; |
|
| 1297 | - break; |
|
| 1298 | - case 3: |
|
| 1299 | - $civility = $miss_id; |
|
| 1300 | - break; |
|
| 1301 | - default: |
|
| 1302 | - $civility = $mister_id; |
|
| 1303 | - break; |
|
| 1304 | - } |
|
| 1305 | - } else { |
|
| 1306 | - $civility = $mister_id; |
|
| 1307 | - } |
|
| 1308 | - $billing_address = array('address_title' => $billing_title, |
|
| 1309 | - 'address_last_name' => !empty($address['billing']['last_name']) ? $address['billing']['last_name'] : '', |
|
| 1310 | - 'address_first_name' => !empty($address['billing']['first_name']) ? $address['billing']['first_name'] : '', |
|
| 1311 | - 'company' => !empty($address['billing']['company']) ? $address['billing']['company'] : '', |
|
| 1312 | - 'address' => !empty($address['billing']['address']) ? $address['billing']['address'] : '', |
|
| 1313 | - 'postcode' => !empty($address['billing']['postcode']) ? $address['billing']['postcode'] : '', |
|
| 1314 | - 'city' => !empty($address['billing']['city']) ? $address['billing']['city'] : '', |
|
| 1315 | - 'state' => !empty($address['billing']['state']) ? $address['billing']['state'] : '', |
|
| 1316 | - 'country' => !empty($address['billing']['country']) ? $address['billing']['country'] : '', |
|
| 1317 | - 'address_user_email' => !empty($address['billing']['email']) ? $address['billing']['email'] : '', |
|
| 1318 | - 'phone' => !empty($address['billing']['phone']) ? $address['billing']['phone'] : '', |
|
| 1319 | - 'tva_intra' => !empty($address['billing']['company_tva_intra']) ? $address['billing']['company_tva_intra'] : '', |
|
| 1320 | - 'civility' => $civility, |
|
| 1321 | - ); |
|
| 1322 | - $billing_address_option = get_option('wpshop_billing_address'); |
|
| 1323 | - $address_format['billing']['id'] = $billing_address_option['choice']; |
|
| 1324 | - $address_format['billing']['address'] = $shipping_address; |
|
| 1325 | - } |
|
| 999 | + /* Update the different entities id into attribute set details table */ |
|
| 1000 | + $query = "UPDATE " . WPSHOP_DBT_ATTRIBUTE_DETAILS . " AS ATT_DET INNER JOIN " . WPSHOP_DBT_ATTRIBUTE . " AS ATT ON (ATT.id = ATT_DET.attribute_id) SET ATT_DET.entity_type_id = ATT.entity_id"; |
|
| 1001 | + $wpdb->query($query); |
|
| 1326 | 1002 | |
| 1327 | - $shipping_address = array(); |
|
| 1328 | - if (!empty($address['shipping']) && empty($address['shipping']['id'])) { |
|
| 1329 | - if (!empty($address['shipping']['civility'])) { |
|
| 1330 | - switch ($address['shipping']['civility']) { |
|
| 1331 | - case 1: |
|
| 1332 | - $civility = $mister_id; |
|
| 1333 | - break; |
|
| 1334 | - case 2: |
|
| 1335 | - $civility = $madam_id; |
|
| 1336 | - break; |
|
| 1337 | - case 3: |
|
| 1338 | - $civility = $miss_id; |
|
| 1339 | - break; |
|
| 1340 | - } |
|
| 1341 | - } else { |
|
| 1342 | - $civility = $mister_id; |
|
| 1343 | - } |
|
| 1344 | - $shipping_address = array('address_title' => $shipping_title, |
|
| 1345 | - 'address_last_name' => !empty($address['shipping']['last_name']) ? $address['shipping']['last_name'] : '', |
|
| 1346 | - 'address_first_name' => !empty($address['shipping']['first_name']) ? $address['shipping']['first_name'] : '', |
|
| 1347 | - 'company' => !empty($address['shipping']['company']) ? $address['shipping']['company'] : '', |
|
| 1348 | - 'address' => !empty($address['shipping']['address']) ? $address['shipping']['address'] : '', |
|
| 1349 | - 'postcode' => !empty($address['shipping']['postcode']) ? $address['shipping']['postcode'] : '', |
|
| 1350 | - 'city' => !empty($address['shipping']['city']) ? $address['shipping']['city'] : '', |
|
| 1351 | - 'state' => !empty($address['shipping']['state']) ? $address['shipping']['state'] : '', |
|
| 1352 | - 'country' => !empty($address['shipping']['country']) ? $address['shipping']['country'] : '', |
|
| 1353 | - 'civility' => $civility, |
|
| 1354 | - ); |
|
| 1355 | - $shipping_address_options = get_option('wpshop_shipping_address_choice'); |
|
| 1356 | - $address_format['shipping']['id'] = $shipping_address_options['choice']; |
|
| 1357 | - $address_format['shipping']['address'] = $shipping_address; |
|
| 1358 | - } |
|
| 1003 | + return true; |
|
| 1004 | + break; |
|
| 1005 | + |
|
| 1006 | + case 29: |
|
| 1007 | + $billing_title = __('Billing address', 'wpshop'); |
|
| 1008 | + $shipping_title = __('Shipping address', 'wpshop'); |
|
| 1009 | + |
|
| 1010 | + //UPDATE USERS ADDRESSES |
|
| 1011 | + $billing_address_set_id_query = 'SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE name = "' . $billing_title . '"'; |
|
| 1012 | + $shipping_address_set_id_query = 'SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE name = "' . $shipping_title . '"'; |
|
| 1013 | + |
|
| 1014 | + $billing_address_set_id = $wpdb->get_var($billing_address_set_id_query); |
|
| 1015 | + $shipping_address_set_id = $wpdb->get_var($shipping_address_set_id_query); |
|
| 1016 | + |
|
| 1017 | + //Add Address & Google Map API KEY options |
|
| 1018 | + add_option('wpshop_billing_address', array('choice' => $billing_address_set_id), '', 'yes'); |
|
| 1019 | + add_option('wpshop_shipping_address_choice', array('activate' => 'on', 'choice' => $shipping_address_set_id), '', 'yes'); |
|
| 1020 | + add_option('wpshop_google_map_api_key', '', '', 'yes'); |
|
| 1021 | + |
|
| 1022 | + $query = 'SELECT * FROM ' . $wpdb->users . ''; |
|
| 1023 | + $results = $wpdb->get_results($query); |
|
| 1024 | + foreach ($results as $result) { |
|
| 1025 | + $billing_infos = get_user_meta($result->ID, 'billing_info', true); |
|
| 1026 | + $shipping_infos = get_user_meta($result->ID, 'shipping_info', true); |
|
| 1027 | + if (!empty($billing_infos)) { |
|
| 1028 | + //Save Billing Infos |
|
| 1029 | + $billing_address = array(); |
|
| 1030 | + if (!empty($billing_infos['civility'])) { |
|
| 1031 | + switch ($billing_infos['civility']) { |
|
| 1032 | + case 1: |
|
| 1033 | + $civility = $mister_id; |
|
| 1034 | + break; |
|
| 1035 | + case 2: |
|
| 1036 | + $civility = $madam_id; |
|
| 1037 | + break; |
|
| 1038 | + case 3: |
|
| 1039 | + $civility = $miss_id; |
|
| 1040 | + break; |
|
| 1041 | + } |
|
| 1042 | + } else { |
|
| 1043 | + $civility = $mister_id; |
|
| 1044 | + } |
|
| 1045 | + $billing_address = array('address_title' => $billing_title, |
|
| 1046 | + 'address_last_name' => !empty($billing_infos['last_name']) ? $billing_infos['last_name'] : '', |
|
| 1047 | + 'address_first_name' => !empty($billing_infos['first_name']) ? $billing_infos['first_name'] : '', |
|
| 1048 | + 'company' => !empty($billing_infos['company']) ? $billing_infos['company'] : '', |
|
| 1049 | + 'address' => !empty($billing_infos['address']) ? $billing_infos['address'] : '', |
|
| 1050 | + 'postcode' => !empty($billing_infos['postcode']) ? $billing_infos['postcode'] : '', |
|
| 1051 | + 'city' => !empty($billing_infos['city']) ? $billing_infos['city'] : '', |
|
| 1052 | + 'state' => !empty($billing_infos['state']) ? $billing_infos['state'] : '', |
|
| 1053 | + 'country' => !empty($billing_infos['country']) ? $billing_infos['country'] : '', |
|
| 1054 | + 'address_user_email' => !empty($billing_infos['email']) ? $billing_infos['email'] : '', |
|
| 1055 | + 'phone' => !empty($billing_infos['phone']) ? $billing_infos['phone'] : '', |
|
| 1056 | + 'tva_intra' => !empty($billing_infos['company_tva_intra']) ? $billing_infos['company_tva_intra'] : '', |
|
| 1057 | + 'civility' => $civility, |
|
| 1058 | + ); |
|
| 1059 | + //Create the post and post_meta for the billing address |
|
| 1060 | + $post_address = array( |
|
| 1061 | + 'post_author' => $result->ID, |
|
| 1062 | + 'post_title' => $billing_title, |
|
| 1063 | + 'post_status' => 'publish', |
|
| 1064 | + 'post_name' => WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS, |
|
| 1065 | + 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS, |
|
| 1066 | + 'post_parent' => $result->ID, |
|
| 1067 | + ); |
|
| 1068 | + $post_address_id = wp_insert_post($post_address); |
|
| 1069 | + |
|
| 1070 | + //Create the post_meta with the address infos |
|
| 1071 | + update_post_meta($post_address_id, '_' . WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS . '_metadata', $billing_address); |
|
| 1072 | + update_post_meta($post_address_id, '_' . WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS . '_attribute_set_id', $billing_address_set_id); |
|
| 1073 | + } |
|
| 1074 | + |
|
| 1075 | + if (!empty($shipping_infos)) { |
|
| 1076 | + //Save Shipping Infos |
|
| 1077 | + if (!empty($shipping_infos['civility'])) { |
|
| 1078 | + switch ($shipping_infos['civility']) { |
|
| 1079 | + case 1: |
|
| 1080 | + $civility = $mister_id; |
|
| 1081 | + break; |
|
| 1082 | + case 2: |
|
| 1083 | + $civility = $madam_id; |
|
| 1084 | + break; |
|
| 1085 | + case 3: |
|
| 1086 | + $civility = $miss_id; |
|
| 1087 | + break; |
|
| 1088 | + } |
|
| 1089 | + } else { |
|
| 1090 | + $civility = $mister_id; |
|
| 1091 | + } |
|
| 1092 | + $shipping_address = array(); |
|
| 1093 | + $shipping_address = array('address_title' => $shipping_title, |
|
| 1094 | + 'address_last_name' => !empty($shipping_infos['last_name']) ? $shipping_infos['last_name'] : '', |
|
| 1095 | + 'address_first_name' => !empty($shipping_infos['first_name']) ? $shipping_infos['first_name'] : '', |
|
| 1096 | + 'company' => !empty($shipping_infos['company']) ? $shipping_infos['company'] : '', |
|
| 1097 | + 'address' => !empty($shipping_infos['address']) ? $shipping_infos['address'] : '', |
|
| 1098 | + 'postcode' => !empty($shipping_infos['postcode']) ? $shipping_infos['postcode'] : '', |
|
| 1099 | + 'city' => !empty($shipping_infos['city']) ? $shipping_infos['city'] : '', |
|
| 1100 | + 'state' => !empty($shipping_infos['state']) ? $shipping_infos['state'] : '', |
|
| 1101 | + 'country' => !empty($shipping_infos['country']) ? $shipping_infos['country'] : '', |
|
| 1102 | + 'civility' => $civility, |
|
| 1103 | + ); |
|
| 1104 | + //Create the post and post_meta for the billing address |
|
| 1105 | + $post_address = array( |
|
| 1106 | + 'post_author' => $result->ID, |
|
| 1107 | + 'post_title' => $shipping_title, |
|
| 1108 | + 'post_status' => 'publish', |
|
| 1109 | + 'post_name' => WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS, |
|
| 1110 | + 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS, |
|
| 1111 | + 'post_parent' => $result->ID, |
|
| 1112 | + ); |
|
| 1113 | + $post_address_id = wp_insert_post($post_address); |
|
| 1114 | + //Create the post_meta with the address infos |
|
| 1115 | + update_post_meta($post_address_id, '_' . WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS . '_metadata', $shipping_address); |
|
| 1116 | + update_post_meta($post_address_id, '_' . WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS . '_attribute_set_id', $shipping_address_set_id); |
|
| 1117 | + } |
|
| 1118 | + } |
|
| 1359 | 1119 | |
| 1360 | - if (!empty($address_format)) { |
|
| 1361 | - update_post_meta($result->ID, '_order_info', $address_format); |
|
| 1362 | - } |
|
| 1363 | - } |
|
| 1364 | - |
|
| 1365 | - /** Delete username from frontend form */ |
|
| 1366 | - $attribute_login = wpshop_attributes::getElement('user_login', "'valid'", 'code'); |
|
| 1367 | - if (!empty($attribute_login)) { |
|
| 1368 | - $wpdb->update(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('status' => 'deleted', 'last_update_date' => current_time('mysql', 0), 'position' => 0), array('attribute_id' => $attribute_login->id)); |
|
| 1369 | - } |
|
| 1370 | - |
|
| 1371 | - $wpdb->update(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('last_update_date' => current_time('mysql', 0), 'position' => 0), array('status' => 'deleted')); |
|
| 1372 | - |
|
| 1373 | - return true; |
|
| 1374 | - break; |
|
| 1375 | - |
|
| 1376 | - case '31': |
|
| 1377 | - /** Change order structure in order to support several payment */ |
|
| 1378 | - $existing_orders = query_posts(array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ORDER, 'posts_per_page' => -1, 'post_status' => array('draft', 'trash', 'publish'))); |
|
| 1379 | - if (!empty($existing_orders)) { |
|
| 1380 | - foreach ($existing_orders as $order_main_informations) { |
|
| 1381 | - /** Transfer payment return data form old meta to new */ |
|
| 1382 | - $order_payment_return_data = get_post_meta($order_main_informations->ID, 'wpshop_payment_return_data', true); |
|
| 1383 | - update_post_meta($order_main_informations->ID, '_wpshop_payment_return_data', $order_payment_return_data); |
|
| 1384 | - delete_post_meta($order_main_informations->ID, 'wpshop_payment_return_data'); |
|
| 1385 | - |
|
| 1386 | - /** Transfer old payment storage method to new storage method */ |
|
| 1387 | - $order_meta = get_post_meta($order_main_informations->ID, '_order_postmeta', true); |
|
| 1388 | - if (!empty($order_meta['order_status'])) { |
|
| 1389 | - $order_meta['order_payment']['customer_choice'] = array('method' => (!empty($order_meta['payment_method']) ? $order_meta['payment_method'] : (!empty($order_meta['order_payment']['customer_choice']) ? $order_meta['order_payment']['customer_choice'] : ''))); |
|
| 1390 | - unset($order_meta['payment_method']); |
|
| 1391 | - $order_meta['order_payment']['received'][0]['waited_amount'] = !empty($order_meta['order_grand_total']) ? $order_meta['order_grand_total'] : 0; |
|
| 1392 | - $order_meta['order_payment']['received'][0]['method'] = $order_meta['order_payment']['customer_choice']['method']; |
|
| 1393 | - $order_meta['order_payment']['received'][0]['date'] = $order_meta['order_date']; |
|
| 1394 | - $order_meta['order_payment']['received'][0]['status'] = 'waiting_payment'; |
|
| 1395 | - $order_meta['order_payment']['received'][0]['comment'] = ''; |
|
| 1396 | - $order_meta['order_payment']['received'][0]['author'] = $order_meta['order_payment']['customer_choice'] == 'check' ? 1 : $order_meta['customer_id']; |
|
| 1397 | - if (in_array($order_meta['order_status'], array('completed', 'shipped'))) { |
|
| 1398 | - $order_meta['order_payment']['received'][0]['received_amount'] = $order_meta['order_grand_total']; |
|
| 1399 | - $order_meta['order_payment']['received'][0]['payment_reference'] = wpshop_payment::get_payment_transaction_number_old_way($order_main_informations->ID); |
|
| 1400 | - $order_meta['order_payment']['received'][0]['date'] = $order_meta['order_payment_date']; |
|
| 1401 | - $order_meta['order_payment']['received'][0]['status'] = 'payment_received'; |
|
| 1402 | - $order_meta['order_payment']['received'][0]['comment'] = ''; |
|
| 1403 | - $order_meta['order_payment']['received'][0]['author'] = $order_meta['order_payment']['customer_choice'] == 'check' ? 1 : $order_meta['customer_id']; |
|
| 1404 | - $order_meta['order_payment']['received'][0]['invoice_ref'] = $order_meta['order_invoice_ref']; |
|
| 1405 | - } |
|
| 1406 | - update_post_meta($order_main_informations->ID, '_order_postmeta', $order_meta); |
|
| 1407 | - |
|
| 1408 | - if (!empty($order_meta['order_payment']['customer_choice'])) { |
|
| 1409 | - switch ($order_meta['order_payment']['customer_choice']) { |
|
| 1410 | - case 'check': |
|
| 1411 | - delete_post_meta($order_main_informations->ID, '_order_check_number', get_post_meta($order_main_informations->ID, '_order_check_number', true)); |
|
| 1412 | - break; |
|
| 1413 | - case 'paypal': |
|
| 1414 | - delete_post_meta($order_main_informations->ID, '_order_paypal_txn_id', get_post_meta($order_main_informations->ID, '_order_paypal_txn_id', true)); |
|
| 1415 | - break; |
|
| 1416 | - case 'cic': |
|
| 1417 | - delete_post_meta($order_main_informations->ID, '_order_cic_txn_id', get_post_meta($order_main_informations->ID, '_order_cic_txn_id', true)); |
|
| 1418 | - break; |
|
| 1419 | - } |
|
| 1420 | - } |
|
| 1421 | - } |
|
| 1422 | - } |
|
| 1423 | - } |
|
| 1424 | - $wps_messages = new wps_message_ctr(); |
|
| 1425 | - $wps_messages->wpshop_messages_historic_correction(); |
|
| 1426 | - wp_reset_query(); |
|
| 1427 | - |
|
| 1428 | - $default_currency = get_option('wpshop_shop_default_currency'); |
|
| 1429 | - foreach (unserialize(WPSHOP_SHOP_CURRENCIES) as $k => $v) { |
|
| 1430 | - if ($default_currency == $k) { |
|
| 1431 | - $symbol = $v; |
|
| 1432 | - } |
|
| 1433 | - } |
|
| 1434 | - if (!empty($symbol)) { |
|
| 1435 | - $query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_UNIT . ' WHERE name = "' . html_entity_decode($symbol, ENT_QUOTES, 'UTF-8') . '"', ''); |
|
| 1436 | - $currency = $wpdb->get_row($query); |
|
| 1437 | - if (!empty($currency)) { |
|
| 1438 | - update_option('wpshop_shop_default_currency', $currency->id); |
|
| 1439 | - // Update the change rate of the default currency |
|
| 1440 | - $wpdb->update(WPSHOP_DBT_ATTRIBUTE_UNIT, array('change_rate' => 1), array('id' => $currency->id)); |
|
| 1441 | - } |
|
| 1442 | - } |
|
| 1443 | - |
|
| 1444 | - $shipping_confirmation_message = get_option('WPSHOP_SHIPPING_CONFIRMATION_MESSAGE'); |
|
| 1445 | - if (!empty($shipping_confirmation_message)) { |
|
| 1446 | - $message = __('Hello [customer_first_name] [customer_last_name], this email confirms that your order ([order_key]) has just been shipped (order date : [order_date], tracking number : [order_trackingNumber]). Thank you for your loyalty. Have a good day.', 'wpshop'); |
|
| 1447 | - $post = array('ID' => $shipping_confirmation_message, 'post_content' => $message); |
|
| 1448 | - wp_update_post($post); |
|
| 1449 | - } |
|
| 1450 | - return true; |
|
| 1451 | - break; |
|
| 1452 | - case '32': |
|
| 1453 | - /** Update product set id that are null */ |
|
| 1454 | - $query = $wpdb->prepare("UPDATE " . $wpdb->postmeta . " SET meta_value = (SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE_SET . " WHERE default_set = 'yes' AND entity_id = '" . wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT) . "') WHERE meta_key = %s AND ((meta_value = '') OR (meta_value = null))", '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_attribute_set_id'); |
|
| 1455 | - $wpdb->query($query); |
|
| 1456 | - |
|
| 1457 | - $addons_options = get_option(WPSHOP_ADDONS_OPTION_NAME); |
|
| 1458 | - if (!empty($addons_options) && !empty($addons_options['WPSHOP_ADDONS_QUOTATION']) && !empty($addons_options['WPSHOP_ADDONS_QUOTATION']['activate']) && $addons_options['WPSHOP_ADDONS_QUOTATION']['activate']) { |
|
| 1459 | - $admin_new_quotation_message = get_option('WPSHOP_NEW_QUOTATION_ADMIN_MESSAGE'); |
|
| 1460 | - if (empty($admin_new_quotation_message)) { |
|
| 1461 | - wps_message_ctr::createMessage('WPSHOP_NEW_QUOTATION_ADMIN_MESSAGE'); |
|
| 1462 | - } |
|
| 1463 | - $admin_new_quotation_confirm_message = get_option('WPSHOP_QUOTATION_CONFIRMATION_MESSAGE'); |
|
| 1464 | - if (empty($admin_new_quotation_confirm_message)) { |
|
| 1465 | - wps_message_ctr::createMessage('WPSHOP_QUOTATION_CONFIRMATION_MESSAGE'); |
|
| 1466 | - } |
|
| 1467 | - } |
|
| 1468 | - |
|
| 1469 | - /** Allows the administrator to manage a little bit more the catalog rewrite parameters */ |
|
| 1470 | - $options = get_option('wpshop_catalog_product_option'); |
|
| 1471 | - $options['wpshop_catalog_product_slug_with_category'] = empty($options['wpshop_catalog_product_slug_with_category']) ? 'yes' : $options['wpshop_catalog_product_slug_with_category']; |
|
| 1472 | - update_option('wpshop_catalog_product_option', $options); |
|
| 1473 | - |
|
| 1474 | - /** Create a new page for unsuccessfull payment return */ |
|
| 1475 | - self::wpshop_insert_default_pages($wpshop_shop_type); |
|
| 1476 | - wp_cache_flush(); |
|
| 1477 | - |
|
| 1478 | - /** Update the iso code of currencies */ |
|
| 1479 | - $wpdb->update(WPSHOP_DBT_ATTRIBUTE_UNIT, array('code_iso' => 'EUR'), array('name' => 'euro')); |
|
| 1480 | - $wpdb->update(WPSHOP_DBT_ATTRIBUTE_UNIT, array('code_iso' => 'USD'), array('name' => 'dollar')); |
|
| 1481 | - |
|
| 1482 | - /** Update VAT Rate*/ |
|
| 1483 | - $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE . ' WHERE code = %s OR code = %s', 'tx_tva', 'eco_taxe_rate_tva'); |
|
| 1484 | - $attribute_ids = $wpdb->get_results($query); |
|
| 1485 | - foreach ($attribute_ids as $attribute_id) { |
|
| 1486 | - $query = $wpdb->prepare('UPDATE ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' SET value = replace(value, "-", ".") WHERE attribute_id = %d', $attribute_id->id); |
|
| 1487 | - $wpdb->query($query); |
|
| 1488 | - } |
|
| 1489 | - |
|
| 1490 | - return true; |
|
| 1491 | - break; |
|
| 1492 | - |
|
| 1493 | - case '33': |
|
| 1494 | - /** Update the user_mail for the new system of log in/register */ |
|
| 1495 | - $query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_used_in_quick_add_form = "yes" WHERE code = "user_email"'); |
|
| 1496 | - |
|
| 1497 | - /** Put discount attributes in price attribute set section*/ |
|
| 1498 | - $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_GROUP . ' WHERE code = %s', 'prices'); |
|
| 1499 | - $prices_section_id = $wpdb->get_var($query); |
|
| 1500 | - |
|
| 1501 | - $query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE . ' WHERE code = %s OR code = %s', 'discount_rate', 'discount_amount'); |
|
| 1502 | - $attributes = $wpdb->get_results($query); |
|
| 1503 | - if (!empty($attributes) && !empty($prices_section_id)) { |
|
| 1504 | - foreach ($attributes as $attribute) { |
|
| 1505 | - $query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE_DETAILS . ' SET attribute_group_id = ' . $prices_section_id . ' WHERE attribute_id = ' . $attribute->id); |
|
| 1506 | - } |
|
| 1507 | - } |
|
| 1508 | - return true; |
|
| 1509 | - break; |
|
| 1120 | + // FORMATE THE ORDER ADDRESSES INFOS |
|
| 1121 | + $results = query_posts(array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ORDER, 'posts_per_page' => -1)); |
|
| 1122 | + foreach ($results as $result) { |
|
| 1123 | + $address = get_post_meta($result->ID, '_order_info', true); |
|
| 1124 | + |
|
| 1125 | + $billing_address = array(); |
|
| 1126 | + if (!empty($address['billing'])) { |
|
| 1127 | + if (!empty($address['billing']['civility'])) { |
|
| 1128 | + switch ($address['billing']['civility']) { |
|
| 1129 | + case 1: |
|
| 1130 | + $civility = $mister_id; |
|
| 1131 | + break; |
|
| 1132 | + case 2: |
|
| 1133 | + $civility = $madam_id; |
|
| 1134 | + break; |
|
| 1135 | + case 3: |
|
| 1136 | + $civility = $miss_id; |
|
| 1137 | + break; |
|
| 1138 | + default: |
|
| 1139 | + $civility = $mister_id; |
|
| 1140 | + break; |
|
| 1141 | + } |
|
| 1142 | + } else { |
|
| 1143 | + $civility = $mister_id; |
|
| 1144 | + } |
|
| 1145 | + $billing_address = array('address_title' => $billing_title, |
|
| 1146 | + 'address_last_name' => !empty($address['billing']['last_name']) ? $address['billing']['last_name'] : '', |
|
| 1147 | + 'address_first_name' => !empty($address['billing']['first_name']) ? $address['billing']['first_name'] : '', |
|
| 1148 | + 'company' => !empty($address['billing']['company']) ? $address['billing']['company'] : '', |
|
| 1149 | + 'address' => !empty($address['billing']['address']) ? $address['billing']['address'] : '', |
|
| 1150 | + 'postcode' => !empty($address['billing']['postcode']) ? $address['billing']['postcode'] : '', |
|
| 1151 | + 'city' => !empty($address['billing']['city']) ? $address['billing']['city'] : '', |
|
| 1152 | + 'state' => !empty($address['billing']['state']) ? $address['billing']['state'] : '', |
|
| 1153 | + 'country' => !empty($address['billing']['country']) ? $address['billing']['country'] : '', |
|
| 1154 | + 'address_user_email' => !empty($address['billing']['email']) ? $address['billing']['email'] : '', |
|
| 1155 | + 'phone' => !empty($address['billing']['phone']) ? $address['billing']['phone'] : '', |
|
| 1156 | + 'tva_intra' => !empty($address['billing']['company_tva_intra']) ? $address['billing']['company_tva_intra'] : '', |
|
| 1157 | + 'civility' => $civility, |
|
| 1158 | + ); |
|
| 1159 | + } |
|
| 1160 | + |
|
| 1161 | + $shipping_address = array(); |
|
| 1162 | + if (!empty($address['shipping'])) { |
|
| 1163 | + if (!empty($address['shipping']['civility'])) { |
|
| 1164 | + switch ($address['shipping']['civility']) { |
|
| 1165 | + case 1: |
|
| 1166 | + $civility = $mister_id; |
|
| 1167 | + break; |
|
| 1168 | + case 2: |
|
| 1169 | + $civility = $madam_id; |
|
| 1170 | + break; |
|
| 1171 | + case 3: |
|
| 1172 | + $civility = $miss_id; |
|
| 1173 | + break; |
|
| 1174 | + } |
|
| 1175 | + } else { |
|
| 1176 | + $civility = $mister_id; |
|
| 1177 | + } |
|
| 1178 | + $shipping_address = array('address_title' => $shipping_title, |
|
| 1179 | + 'address_last_name' => !empty($address['shipping']['last_name']) ? $address['shipping']['last_name'] : '', |
|
| 1180 | + 'address_first_name' => !empty($address['shipping']['first_name']) ? $address['shipping']['first_name'] : '', |
|
| 1181 | + 'company' => !empty($address['shipping']['company']) ? $address['shipping']['company'] : '', |
|
| 1182 | + 'address' => !empty($address['shipping']['address']) ? $address['shipping']['address'] : '', |
|
| 1183 | + 'postcode' => !empty($address['shipping']['postcode']) ? $address['shipping']['postcode'] : '', |
|
| 1184 | + 'city' => !empty($address['shipping']['city']) ? $address['shipping']['city'] : '', |
|
| 1185 | + 'state' => !empty($address['shipping']['state']) ? $address['shipping']['state'] : '', |
|
| 1186 | + 'country' => !empty($address['shipping']['country']) ? $address['shipping']['country'] : '', |
|
| 1187 | + 'civility' => $civility, |
|
| 1188 | + ); |
|
| 1189 | + } |
|
| 1190 | + |
|
| 1191 | + $billing_array_content = array('id' => $billing_address_set_id, 'address' => $billing_address); |
|
| 1192 | + $shipping_array_content = array('id' => $shipping_address_set_id, 'address' => $shipping_address); |
|
| 1193 | + $array_new_format = array('billing' => $billing_array_content, 'shipping' => $shipping_array_content); |
|
| 1194 | + |
|
| 1195 | + //Update the post meta |
|
| 1196 | + update_post_meta($result->ID, '_order_info', $array_new_format); |
|
| 1197 | + } |
|
| 1510 | 1198 | |
| 1511 | - case '34': |
|
| 1512 | - $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_GROUP . ' WHERE code = %s', 'prices'); |
|
| 1513 | - $prices_section_id = $wpdb->get_var($query); |
|
| 1199 | + /* Update entities meta management */ |
|
| 1200 | + $entities = query_posts(array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ENTITIES, 'posts_per_page' => -1)); |
|
| 1201 | + if (!empty($entities)) { |
|
| 1202 | + foreach ($entities as $entity) { |
|
| 1203 | + $params = get_post_meta($entity->ID, '_wpshop_entity_params', true); |
|
| 1204 | + $support = (!empty($params['support'])) ? $params['support'] : ''; |
|
| 1205 | + $rewrite = (!empty($params['rewrite'])) ? $params['rewrite'] : ''; |
|
| 1514 | 1206 | |
| 1515 | - $query = $wpdb->prepare('SELECT MAX(position) AS max_position FROM ' . WPSHOP_DBT_ATTRIBUTE_DETAILS . ' WHERE attribute_group_id = %d', $prices_section_id); |
|
| 1516 | - $last_position_id = $wpdb->get_var($query); |
|
| 1207 | + $display_admin_menu = 'on'; |
|
| 1517 | 1208 | |
| 1518 | - $query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_DETAILS . ' WHERE attribute_group_id = %d AND position = %d', $prices_section_id, $last_position_id); |
|
| 1519 | - $attribute_example = $wpdb->get_row($query); |
|
| 1209 | + update_post_meta($entity->ID, '_wpshop_entity_params', array('support' => $support, 'rewrite' => $rewrite, 'display_admin_menu' => $display_admin_menu)); |
|
| 1210 | + } |
|
| 1211 | + } |
|
| 1212 | + wp_reset_query(); |
|
| 1213 | + |
|
| 1214 | + // Default Weight unity and Currency Options |
|
| 1215 | + add_option('wpshop_shop_weight_group', 3, '', 'yes'); |
|
| 1216 | + add_option('wpshop_shop_default_weight_unity', 6, '', 'yes'); |
|
| 1217 | + add_option('wpshop_shop_currency_group', 4, '', 'yes'); |
|
| 1218 | + |
|
| 1219 | + $default_currency = get_option('wpshop_shop_default_currency'); |
|
| 1220 | + foreach (unserialize(WPSHOP_SHOP_CURRENCIES) as $k => $v) { |
|
| 1221 | + if ($default_currency == $k) { |
|
| 1222 | + $symbol = $v; |
|
| 1223 | + } |
|
| 1224 | + } |
|
| 1225 | + if (!empty($symbol)) { |
|
| 1226 | + $query = 'SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_UNIT . ' WHERE name = "' . html_entity_decode($symbol, ENT_QUOTES, 'UTF-8') . '"'; |
|
| 1227 | + $currency = $wpdb->get_row($query); |
|
| 1228 | + if (!empty($currency)) { |
|
| 1229 | + update_option('wpshop_shop_default_currency', $currency->id); |
|
| 1230 | + // Update the change rate of the default currency |
|
| 1231 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE_UNIT, array('change_rate' => 1), array('id' => $currency->id)); |
|
| 1232 | + } |
|
| 1233 | + } |
|
| 1520 | 1234 | |
| 1521 | - $query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE . ' WHERE code = %s OR code = %s', 'special_from', 'special_to'); |
|
| 1522 | - $attributes = $wpdb->get_results($query); |
|
| 1523 | - $i = 1; |
|
| 1524 | - if (!empty($attributes) && !empty($prices_section_id)) { |
|
| 1235 | + // Update the field for variation and user definition field |
|
| 1236 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('is_used_for_variation' => 'yes'), array('is_user_defined' => 'yes')); |
|
| 1237 | + // Update field type for frontend output selection |
|
| 1238 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('frontend_input' => 'text'), array()); |
|
| 1239 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('frontend_input' => 'textarea'), array('backend_input' => 'textarea')); |
|
| 1240 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('frontend_input' => 'select'), array('backend_input' => 'multiple-select')); |
|
| 1241 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('frontend_input' => 'select'), array('backend_input' => 'select')); |
|
| 1525 | 1242 | |
| 1526 | - foreach ($attributes as $attribute) { |
|
| 1527 | - $wpdb->update(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('attribute_group_id' => $prices_section_id), array('attribute_id' => $attribute->id)); |
|
| 1528 | - $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'entity_type_id' => $attribute_example->entity_type_id, 'attribute_set_id' => $attribute_example->attribute_set_id, 'attribute_group_id' => $prices_section_id, 'attribute_id' => $attribute->id, 'position' => $last_position_id + $i)); |
|
| 1529 | - $i++; |
|
| 1530 | - } |
|
| 1531 | - } |
|
| 1532 | - $discount_options = get_option('wpshop_catalog_product_option'); |
|
| 1533 | - $status = (!empty($discount_options) && !empty($discount_options['discount'])) ? 'valid' : 'notused'; |
|
| 1534 | - $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('frontend_label' => __('Discount from', 'wpshop'), 'status' => $status), array('code' => 'special_from')); |
|
| 1535 | - $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('frontend_label' => __('Discount to', 'wpshop'), 'status' => $status), array('code' => 'special_to')); |
|
| 1536 | - return true; |
|
| 1537 | - break; |
|
| 1538 | - |
|
| 1539 | - case '35': |
|
| 1540 | - $wpdb->update($wpdb->posts, array('post_status' => 'draft'), array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS)); |
|
| 1541 | - return true; |
|
| 1542 | - break; |
|
| 1543 | - |
|
| 1544 | - case '36': |
|
| 1545 | - wpshop_entities::create_cpt_attributes_from_csv_file(WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS); |
|
| 1546 | - @set_time_limit(900); |
|
| 1547 | - /** Change the path for old categories pictures */ |
|
| 1548 | - @chmod(WPSHOP_UPLOAD_DIR . 'wpshop_product_category', 0755); |
|
| 1549 | - |
|
| 1550 | - $query = 'SELECT * FROM ' . $wpdb->terms; |
|
| 1551 | - $terms = $wpdb->get_results($query); |
|
| 1552 | - if (!empty($terms)) { |
|
| 1553 | - foreach ($terms as $term) { |
|
| 1554 | - @chmod(WPSHOP_UPLOAD_DIR . 'wpshop_product_category/' . $term->term_id, 0755); |
|
| 1555 | - /** Check if a picture exists **/ |
|
| 1556 | - $term_option = get_option(WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES . '_' . $term->term_id); |
|
| 1557 | - if (!empty($term_option) && !empty($term_option['wpshop_category_picture']) && is_file(WPSHOP_UPLOAD_DIR . $term_option['wpshop_category_picture'])) { |
|
| 1558 | - $wp_upload_dir = wp_upload_dir(); |
|
| 1559 | - $img_path = WPSHOP_UPLOAD_DIR . $term_option['wpshop_category_picture']; |
|
| 1560 | - $img_basename = basename($img_path); |
|
| 1561 | - $wp_filetype = wp_check_filetype($img_basename, null); |
|
| 1562 | - /** Check if there is an image with the same name, if yes we add a rand number to image's name **/ |
|
| 1563 | - $rand_name = (is_file($wp_upload_dir['path'] . '/' . $img_basename)) ? rand() : ''; |
|
| 1564 | - $img_basename = (!empty($rand_name)) ? $rand_name . '_' . $img_basename : $img_basename; |
|
| 1565 | - if (copy($img_path, $wp_upload_dir['path'] . '/' . $img_basename)) { |
|
| 1566 | - $attachment = array( |
|
| 1567 | - 'guid' => $wp_upload_dir['url'] . '/' . $img_basename, |
|
| 1568 | - 'post_mime_type' => $wp_filetype['type'], |
|
| 1569 | - 'post_title' => preg_replace('/\.[^.]+$/', '', $img_basename), |
|
| 1570 | - 'post_content' => '', |
|
| 1571 | - 'post_status' => 'inherit', |
|
| 1572 | - ); |
|
| 1573 | - $attach_id = wp_insert_attachment($attachment, $wp_upload_dir['path'] . '/' . $img_basename); |
|
| 1574 | - /** Generate differnts sizes for this image **/ |
|
| 1575 | - require_once ABSPATH . 'wp-admin/includes/image.php'; |
|
| 1576 | - $attach_data = wp_generate_attachment_metadata($attach_id, $wp_upload_dir['path'] . '/' . $img_basename); |
|
| 1577 | - wp_update_attachment_metadata($attach_id, $attach_data); |
|
| 1578 | - /** Update option picture **/ |
|
| 1579 | - $term_option['wpshop_category_picture'] = $attach_id; |
|
| 1580 | - update_option(WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES . '_' . $term->term_id, $term_option); |
|
| 1581 | - } |
|
| 1582 | - } |
|
| 1583 | - } |
|
| 1584 | - } |
|
| 1585 | - |
|
| 1586 | - /** Change metabox Hidden Nav Menu Definition to display WPShop categories' metabox **/ |
|
| 1587 | - $query = $wpdb->prepare('SELECT * FROM ' . $wpdb->usermeta . ' WHERE meta_key = %s', 'metaboxhidden_nav-menus'); |
|
| 1588 | - $meta_keys = $wpdb->get_results($query); |
|
| 1589 | - if (!empty($meta_keys) && is_array($meta_keys)) { |
|
| 1590 | - foreach ($meta_keys as $meta_key) { |
|
| 1591 | - $user_id = $meta_key->user_id; |
|
| 1592 | - $meta_value = unserialize($meta_key->meta_value); |
|
| 1593 | - if (!empty($meta_value) && is_array($meta_value)) { |
|
| 1594 | - $data_to_delete = array_search('add-wpshop_product_category', $meta_value); |
|
| 1595 | - if ($data_to_delete !== false) { |
|
| 1596 | - unset($meta_value[$data_to_delete]); |
|
| 1597 | - } |
|
| 1598 | - } |
|
| 1599 | - update_user_meta($user_id, 'metaboxhidden_nav-menus', $meta_value); |
|
| 1600 | - } |
|
| 1601 | - } |
|
| 1602 | - return true; |
|
| 1603 | - break; |
|
| 1604 | - |
|
| 1605 | - case '37': |
|
| 1606 | - @set_time_limit(900); |
|
| 1607 | - /** Change the path for old categories pictures */ |
|
| 1608 | - @chmod(WPSHOP_UPLOAD_DIR . 'wpshop/wpshop_product_category', 0755); |
|
| 1609 | - /** Read all categories folders **/ |
|
| 1610 | - $categories_main_dir = WPSHOP_UPLOAD_DIR . 'wpshop/wpshop_product_category'; |
|
| 1611 | - if (file_exists($categories_main_dir)) { |
|
| 1612 | - $main_folder_content = scandir($categories_main_dir); |
|
| 1613 | - /** For each category folder **/ |
|
| 1614 | - foreach ($main_folder_content as $category_folder) { |
|
| 1615 | - if ($category_folder && substr($category_folder, 0, 1) != '.') { |
|
| 1616 | - $category_id = $category_folder; |
|
| 1617 | - @chmod(WPSHOP_UPLOAD_DIR . 'wpshop/wpshop_product_category/' . $category_id, 0755); |
|
| 1618 | - $scan_category_folder = opendir($categories_main_dir . '/' . $category_folder); |
|
| 1619 | - /** For each Picture of category **/ |
|
| 1620 | - $file_time = 0; |
|
| 1621 | - $save_this_picture = false; |
|
| 1622 | - while (false !== ($fichier = readdir($scan_category_folder))) { |
|
| 1623 | - if ($fichier && substr($fichier, 0, 1) != '.') { |
|
| 1624 | - if ($file_time < filemtime($categories_main_dir . '/' . $category_id . '/' . $fichier)) { |
|
| 1625 | - $save_this_picture = true; |
|
| 1626 | - $file_time = filemtime($categories_main_dir . '/' . $category_id . '/' . $fichier); |
|
| 1627 | - } |
|
| 1628 | - /** Select category option **/ |
|
| 1629 | - $term_option = get_option(WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES . '_' . $category_id); |
|
| 1630 | - $wp_upload_dir = wp_upload_dir(); |
|
| 1631 | - $img_path = $categories_main_dir . '/' . $category_id . '/' . $fichier; |
|
| 1632 | - $img_basename = basename($img_path); |
|
| 1633 | - $wp_filetype = wp_check_filetype($img_basename, null); |
|
| 1634 | - /** Check if there is an image with the same name, if yes we add a rand number to image's name **/ |
|
| 1635 | - $rand_name = (is_file($wp_upload_dir['path'] . '/' . $img_basename)) ? rand() : ''; |
|
| 1636 | - $img_basename = (!empty($rand_name)) ? $rand_name . '_' . $img_basename : $img_basename; |
|
| 1637 | - |
|
| 1638 | - if (copy($img_path, $wp_upload_dir['path'] . '/' . $img_basename)) { |
|
| 1639 | - $attachment = array( |
|
| 1640 | - 'guid' => $wp_upload_dir['url'] . '/' . $img_basename, |
|
| 1641 | - 'post_mime_type' => $wp_filetype['type'], |
|
| 1642 | - 'post_title' => preg_replace('/\.[^.]+$/', '', $img_basename), |
|
| 1643 | - 'post_content' => '', |
|
| 1644 | - 'post_status' => 'inherit', |
|
| 1645 | - ); |
|
| 1646 | - $attach_id = wp_insert_attachment($attachment, $wp_upload_dir['path'] . '/' . $img_basename); |
|
| 1647 | - /** Generate differnts sizes for this image **/ |
|
| 1648 | - require_once ABSPATH . 'wp-admin/includes/image.php'; |
|
| 1649 | - $attach_data = wp_generate_attachment_metadata($attach_id, $wp_upload_dir['path'] . '/' . $img_basename); |
|
| 1650 | - wp_update_attachment_metadata($attach_id, $attach_data); |
|
| 1651 | - /** Update option picture **/ |
|
| 1652 | - $term_option['wpshop_category_picture'] = $attach_id; |
|
| 1653 | - if ($save_this_picture) { |
|
| 1654 | - update_option(WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES . '_' . $category_id, $term_option); |
|
| 1655 | - } |
|
| 1656 | - $save_this_picture = false; |
|
| 1657 | - } |
|
| 1658 | - } |
|
| 1659 | - } |
|
| 1660 | - } |
|
| 1661 | - } |
|
| 1662 | - } |
|
| 1663 | - return true; |
|
| 1664 | - break; |
|
| 1665 | - |
|
| 1666 | - case '38': |
|
| 1667 | - wps_message_ctr::createMessage('WPSHOP_QUOTATION_UPDATE_MESSAGE'); |
|
| 1668 | - return true; |
|
| 1669 | - break; |
|
| 1670 | - |
|
| 1671 | - case '39': |
|
| 1672 | - $attribute_def = wpshop_attributes::getElement('tx_tva', "'valid'", 'code'); |
|
| 1673 | - /** Check if the 7% VAT Rate is not already created **/ |
|
| 1674 | - $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE attribute_id = %d AND value = %s', $attribute_def->id, '7'); |
|
| 1675 | - $exist_vat_rate = $wpdb->get_results($query); |
|
| 1676 | - |
|
| 1677 | - if (empty($exist_vat_rate)) { |
|
| 1678 | - /** Get Max Position **/ |
|
| 1679 | - $query = $wpdb->prepare('SELECT MAX(position) as max_position FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE attribute_id = %d', $attribute_def->id); |
|
| 1680 | - $max_position = $wpdb->get_var($query); |
|
| 1681 | - |
|
| 1682 | - if (!empty($attribute_def) && !empty($attribute_def->id)) { |
|
| 1683 | - $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS, array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'attribute_id' => $attribute_def->id, 'position' => (int) $max_position + 1, 'value' => '7', 'label' => '7')); |
|
| 1684 | - } |
|
| 1685 | - } |
|
| 1686 | - |
|
| 1687 | - /** Filter Search optimization **/ |
|
| 1688 | - @set_time_limit(900); |
|
| 1689 | - $query = $wpdb->prepare('SELECT term_id FROM ' . $wpdb->term_taxonomy . ' WHERE taxonomy = %s ', WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES); |
|
| 1690 | - $categories = $wpdb->get_results($query); |
|
| 1691 | - $cats = array(); |
|
| 1692 | - if (!empty($categories)) { |
|
| 1693 | - foreach ($categories as $category) { |
|
| 1694 | - $cats[] = $category->term_id; |
|
| 1695 | - } |
|
| 1696 | - $wpshop_filter_search = new wps_filter_search(); |
|
| 1697 | - $wpshop_filter_search->stock_values_for_attribute($cats); |
|
| 1698 | - } |
|
| 1699 | - return true; |
|
| 1700 | - break; |
|
| 1701 | - |
|
| 1702 | - case '40': |
|
| 1703 | - /** Store watt in puissance unit group */ |
|
| 1704 | - $query = $wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE_UNIT_GROUP . " WHERE name = %s", __('puissance', 'wpshop')); |
|
| 1705 | - $puissance_unit_group_id = $wpdb->get_var($query); |
|
| 1706 | - $wpdb->update(WPSHOP_DBT_ATTRIBUTE_UNIT, array('group_id' => $puissance_unit_group_id), array('unit' => 'watt')); |
|
| 1707 | - |
|
| 1708 | - /** Store day/week/year in duration unit group */ |
|
| 1709 | - $query = $wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE_UNIT_GROUP . " WHERE name = %s", __('duration', 'wpshop')); |
|
| 1710 | - $duration_unit_group_id = $wpdb->get_var($query); |
|
| 1711 | - $wpdb->update(WPSHOP_DBT_ATTRIBUTE_UNIT, array('group_id' => $duration_unit_group_id), array('unit' => 'day')); |
|
| 1712 | - $wpdb->update(WPSHOP_DBT_ATTRIBUTE_UNIT, array('group_id' => $duration_unit_group_id), array('unit' => 'week')); |
|
| 1713 | - $wpdb->update(WPSHOP_DBT_ATTRIBUTE_UNIT, array('group_id' => $duration_unit_group_id), array('unit' => 'year')); |
|
| 1714 | - |
|
| 1715 | - /** Store day/week/year in duration unit group */ |
|
| 1716 | - $query = $wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE_UNIT_GROUP . " WHERE name = %s", __('length', 'wpshop')); |
|
| 1717 | - $length_unit_group_id = $wpdb->get_var($query); |
|
| 1718 | - $wpdb->update(WPSHOP_DBT_ATTRIBUTE_UNIT, array('group_id' => $length_unit_group_id), array('unit' => 'cm')); |
|
| 1719 | - return true; |
|
| 1720 | - break; |
|
| 1721 | - |
|
| 1722 | - case '41': |
|
| 1723 | - /** Get distinct attribute set and delete doublons */ |
|
| 1724 | - $query = "SELECT DISTINCT( name ) AS name, MIN( id ) as min_id FROM " . WPSHOP_DBT_ATTRIBUTE_SET . " GROUP BY name HAVING COUNT(id) > 1"; |
|
| 1725 | - $list_of_set = $wpdb->get_results($query); |
|
| 1726 | - foreach ($list_of_set as $set_infos) { |
|
| 1727 | - $query = $wpdb->prepare("DELETE FROM " . WPSHOP_DBT_ATTRIBUTE_SET . " WHERE name = %s AND id != %d", $set_infos->name, $set_infos->min_id); |
|
| 1728 | - $wpdb->query($query); |
|
| 1729 | - } |
|
| 1730 | - $wpdb->query("OPTIMIZE TABLE " . WPSHOP_DBT_ATTRIBUTE_SET); |
|
| 1731 | - |
|
| 1732 | - /** Get and delete attribute set section */ |
|
| 1733 | - $query = "DELETE FROM " . WPSHOP_DBT_ATTRIBUTE_GROUP . " WHERE attribute_set_id NOT IN ( SELECT DISTINCT(id) FROM " . WPSHOP_DBT_ATTRIBUTE_SET . " )"; |
|
| 1734 | - $wpdb->query($query); |
|
| 1735 | - $wpdb->query("OPTIMIZE TABLE " . WPSHOP_DBT_ATTRIBUTE_GROUP); |
|
| 1736 | - |
|
| 1737 | - /** Get and delete attribute set details */ |
|
| 1738 | - $query = "DELETE FROM " . WPSHOP_DBT_ATTRIBUTE_DETAILS . " WHERE attribute_set_id NOT IN ( SELECT DISTINCT(id) FROM " . WPSHOP_DBT_ATTRIBUTE_SET . " ) OR attribute_group_id NOT IN ( SELECT DISTINCT(id) FROM " . WPSHOP_DBT_ATTRIBUTE_GROUP . " )"; |
|
| 1739 | - $wpdb->query($query); |
|
| 1740 | - $wpdb->query("OPTIMIZE TABLE " . WPSHOP_DBT_ATTRIBUTE_DETAILS); |
|
| 1741 | - |
|
| 1742 | - $query = "SELECT attribute_set_id, attribute_group_id, attribute_id, MIN(id) as min_id FROM " . WPSHOP_DBT_ATTRIBUTE_DETAILS . " GROUP BY attribute_set_id, attribute_group_id, attribute_id HAVING COUNT(id) > 1"; |
|
| 1743 | - $affectation_list = $wpdb->get_results($query); |
|
| 1744 | - foreach ($affectation_list as $affectation_to_treat) { |
|
| 1745 | - $query = $wpdb->prepare("DELETE FROM " . WPSHOP_DBT_ATTRIBUTE_DETAILS . " WHERE attribute_set_id = %d AND attribute_group_id = %d AND attribute_id = %d AND id != %d", $affectation_to_treat->attribute_set_id, $affectation_to_treat->attribute_group_id, $affectation_to_treat->attribute_id, $affectation_to_treat->min_id); |
|
| 1746 | - $wpdb->query($query); |
|
| 1747 | - } |
|
| 1748 | - $wpdb->query("OPTIMIZE TABLE " . WPSHOP_DBT_ATTRIBUTE_DETAILS); |
|
| 1749 | - |
|
| 1750 | - /** Get and delete double unit */ |
|
| 1751 | - $query = "SELECT DISTINCT( unit ) AS unit, MIN( id ) as min_id FROM " . WPSHOP_DBT_ATTRIBUTE_UNIT . " GROUP BY unit HAVING COUNT(id) > 1"; |
|
| 1752 | - $list_of_set = $wpdb->get_results($query); |
|
| 1753 | - foreach ($list_of_set as $set_infos) { |
|
| 1754 | - $query = $wpdb->prepare("DELETE FROM " . WPSHOP_DBT_ATTRIBUTE_UNIT . " WHERE unit = %s AND id != %d", $set_infos->unit, $set_infos->min_id); |
|
| 1755 | - $wpdb->query($query); |
|
| 1756 | - } |
|
| 1757 | - $wpdb->query("OPTIMIZE TABLE " . WPSHOP_DBT_ATTRIBUTE_UNIT); |
|
| 1758 | - |
|
| 1759 | - $query = "SELECT DISTINCT( name ) AS name, MIN( id ) as min_id FROM " . WPSHOP_DBT_ATTRIBUTE_UNIT_GROUP . " GROUP BY name HAVING COUNT(id) > 1"; |
|
| 1760 | - $list_of_set = $wpdb->get_results($query); |
|
| 1761 | - foreach ($list_of_set as $set_infos) { |
|
| 1762 | - $query = $wpdb->prepare("DELETE FROM " . WPSHOP_DBT_ATTRIBUTE_UNIT_GROUP . " WHERE name = %s AND id != %d", $set_infos->name, $set_infos->min_id); |
|
| 1763 | - $wpdb->query($query); |
|
| 1764 | - } |
|
| 1765 | - $wpdb->query("OPTIMIZE TABLE " . WPSHOP_DBT_ATTRIBUTE_UNIT_GROUP); |
|
| 1766 | - |
|
| 1767 | - /** Get and delete attribute set details */ |
|
| 1768 | - $query = "DELETE FROM " . WPSHOP_DBT_ATTRIBUTE_DETAILS . " WHERE attribute_set_id NOT IN ( SELECT DISTINCT(id) FROM " . WPSHOP_DBT_ATTRIBUTE_SET . " ) OR attribute_group_id NOT IN ( SELECT DISTINCT(id) FROM " . WPSHOP_DBT_ATTRIBUTE_GROUP . " )"; |
|
| 1769 | - $wpdb->query($query); |
|
| 1770 | - $query = "SELECT GROUP_CONCAT( id ) AS list_id, MIN( id ) as min_id FROM " . WPSHOP_DBT_ATTRIBUTE_DETAILS . " GROUP BY attribute_set_id, attribute_group_id, attribute_id HAVING COUNT(id) > 1"; |
|
| 1771 | - $affectation_list = $wpdb->get_results($query); |
|
| 1772 | - foreach ($affectation_list as $list) { |
|
| 1773 | - $query = $wpdb->prepare("DELETE FROM " . WPSHOP_DBT_ATTRIBUTE_DETAILS . " WHERE id IN (" . (substr($list->list_id, -1) == ',' ? substr($list->list_id, 0, -1) : $list->list_id) . ") AND id != %d", $list->min_id, ''); |
|
| 1774 | - $wpdb->query($query); |
|
| 1775 | - } |
|
| 1776 | - $wpdb->query("OPTIMIZE TABLE " . WPSHOP_DBT_ATTRIBUTE_DETAILS); |
|
| 1777 | - |
|
| 1778 | - return true; |
|
| 1779 | - break; |
|
| 1780 | - |
|
| 1781 | - case '42': |
|
| 1782 | - $available_downloadable_product = get_option('WPSHOP_DOWNLOADABLE_FILE_IS_AVAILABLE'); |
|
| 1783 | - if (empty($available_downloadable_product)) { |
|
| 1784 | - wps_message_ctr::createMessage('WPSHOP_DOWNLOADABLE_FILE_IS_AVAILABLE'); |
|
| 1785 | - } |
|
| 1786 | - return true; |
|
| 1787 | - break; |
|
| 1788 | - |
|
| 1789 | - case '43': |
|
| 1790 | - $available_downloadable_product = get_option('WPSHOP_ORDER_IS_CANCELED'); |
|
| 1791 | - if (empty($available_downloadable_product)) { |
|
| 1792 | - wps_message_ctr::createMessage('WPSHOP_ORDER_IS_CANCELED'); |
|
| 1793 | - } |
|
| 1794 | - return true; |
|
| 1795 | - break; |
|
| 1796 | - |
|
| 1797 | - case '44': |
|
| 1798 | - $display_option = get_option('wpshop_display_option'); |
|
| 1799 | - if (!empty($display_option) && empty($display_option['latest_products_ordered'])) { |
|
| 1800 | - $display_option['latest_products_ordered'] = 3; |
|
| 1801 | - update_option('wpshop_display_option', $display_option); |
|
| 1802 | - } |
|
| 1803 | - |
|
| 1804 | - /** Check messages for customization **/ |
|
| 1805 | - // @since 1.4.3.7 Deleted messages constants |
|
| 1806 | - /*$messages = array('WPSHOP_SIGNUP_MESSAGE' => WPSHOP_SIGNUP_MESSAGE, 'WPSHOP_PAYPAL_PAYMENT_CONFIRMATION_MESSAGE' => WPSHOP_PAYPAL_PAYMENT_CONFIRMATION_MESSAGE, 'WPSHOP_OTHERS_PAYMENT_CONFIRMATION_MESSAGE' => WPSHOP_OTHERS_PAYMENT_CONFIRMATION_MESSAGE, 'WPSHOP_SHIPPING_CONFIRMATION_MESSAGE' => WPSHOP_SHIPPING_CONFIRMATION_MESSAGE, 'WPSHOP_ORDER_UPDATE_MESSAGE' => WPSHOP_ORDER_UPDATE_MESSAGE, 'WPSHOP_ORDER_UPDATE_PRIVATE_MESSAGE' => WPSHOP_ORDER_UPDATE_PRIVATE_MESSAGE, 'WPSHOP_NEW_ORDER_ADMIN_MESSAGE' => WPSHOP_NEW_ORDER_ADMIN_MESSAGE, 'WPSHOP_NEW_QUOTATION_ADMIN_MESSAGE' => WPSHOP_NEW_QUOTATION_ADMIN_MESSAGE, 'WPSHOP_QUOTATION_CONFIRMATION_MESSAGE' => WPSHOP_QUOTATION_CONFIRMATION_MESSAGE, 'WPSHOP_QUOTATION_UPDATE_MESSAGE' => WPSHOP_QUOTATION_UPDATE_MESSAGE, 'WPSHOP_DOWNLOADABLE_FILE_IS_AVAILABLE' => WPSHOP_DOWNLOADABLE_FILE_IS_AVAILABLE, 'WPSHOP_ORDER_IS_CANCELED' => WPSHOP_ORDER_IS_CANCELED); |
|
| 1243 | + add_option('wpshop_cart_option', array('product_added_to_cart' => array('dialog_msg'), 'product_added_to_quotation' => array('cart_page'))); |
|
| 1244 | + |
|
| 1245 | + return true; |
|
| 1246 | + break; |
|
| 1247 | + |
|
| 1248 | + case '30': |
|
| 1249 | + /** Update the current price piloting field for using it into variation specific attributes */ |
|
| 1250 | + $price_piloting_attribute = constant('WPSHOP_PRODUCT_PRICE_' . WPSHOP_PRODUCT_PRICE_PILOT); |
|
| 1251 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('is_used_in_variation' => 'yes', 'last_update_date' => current_time('mysql', 0)), array('code' => $price_piloting_attribute)); |
|
| 1252 | + |
|
| 1253 | + /** Update the product reference field for using it into variation specific attributes */ |
|
| 1254 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('is_used_in_variation' => 'yes', 'last_update_date' => current_time('mysql', 0)), array('code' => 'product_reference')); |
|
| 1255 | + |
|
| 1256 | + /** Insert new message for admin when a customer make an order */ |
|
| 1257 | + $admin_new_order_message = get_option('WPSHOP_NEW_ORDER_ADMIN_MESSAGE'); |
|
| 1258 | + if (empty($admin_new_order_message)) { |
|
| 1259 | + wps_message_ctr::createMessage('WPSHOP_NEW_ORDER_ADMIN_MESSAGE'); |
|
| 1260 | + } |
|
| 1261 | + /** Update all amount for paypal orders */ |
|
| 1262 | + $query = $wpdb->prepare("SELECT post_id FROM " . $wpdb->postmeta . " WHERE meta_key = %s AND meta_value = %s ", '_wpshop_payment_method', 'paypal'); |
|
| 1263 | + $paypal_payment_list = $wpdb->get_results($query); |
|
| 1264 | + if (!empty($paypal_payment_list)) { |
|
| 1265 | + foreach ($paypal_payment_list as $post) { |
|
| 1266 | + $order_meta = get_post_meta($post->post_id, '_order_postmeta', true); |
|
| 1267 | + $order_payment_meta = get_post_meta($post->post_id, 'wpshop_payment_return_data', true); |
|
| 1268 | + if (!empty($order_meta['order_status']) && ($order_meta['order_status'] == 'incorrect_amount')) { |
|
| 1269 | + if (!empty($order_meta['order_grand_total']) && !empty($order_payment_meta['mc_gross'])) { |
|
| 1270 | + $order_amount_to_pay = number_format($order_meta['order_grand_total'], 5); |
|
| 1271 | + $order_amount_payed = number_format(floatval($order_payment_meta['mc_gross']), 5); |
|
| 1272 | + if ($order_amount_payed == $order_amount_to_pay) { |
|
| 1273 | + wpshop_payment::setOrderPaymentStatus($order_id, 'completed'); |
|
| 1274 | + } |
|
| 1275 | + } |
|
| 1276 | + } |
|
| 1277 | + } |
|
| 1278 | + } |
|
| 1279 | + |
|
| 1280 | + /** Save existing orders address information */ |
|
| 1281 | + $billing_title = __('Billing address', 'wpshop'); |
|
| 1282 | + $shipping_title = __('Shipping address', 'wpshop'); |
|
| 1283 | + $results = query_posts(array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ORDER, 'posts_per_page' => -1)); |
|
| 1284 | + foreach ($results as $result) { |
|
| 1285 | + $address = get_post_meta($result->ID, '_order_info', true); |
|
| 1286 | + $address_format = array(); |
|
| 1287 | + |
|
| 1288 | + $billing_address = array(); |
|
| 1289 | + if (!empty($address['billing']) && empty($address['billing']['id'])) { |
|
| 1290 | + if (!empty($address['billing']['civility'])) { |
|
| 1291 | + switch ($address['billing']['civility']) { |
|
| 1292 | + case 1: |
|
| 1293 | + $civility = $mister_id; |
|
| 1294 | + break; |
|
| 1295 | + case 2: |
|
| 1296 | + $civility = $madam_id; |
|
| 1297 | + break; |
|
| 1298 | + case 3: |
|
| 1299 | + $civility = $miss_id; |
|
| 1300 | + break; |
|
| 1301 | + default: |
|
| 1302 | + $civility = $mister_id; |
|
| 1303 | + break; |
|
| 1304 | + } |
|
| 1305 | + } else { |
|
| 1306 | + $civility = $mister_id; |
|
| 1307 | + } |
|
| 1308 | + $billing_address = array('address_title' => $billing_title, |
|
| 1309 | + 'address_last_name' => !empty($address['billing']['last_name']) ? $address['billing']['last_name'] : '', |
|
| 1310 | + 'address_first_name' => !empty($address['billing']['first_name']) ? $address['billing']['first_name'] : '', |
|
| 1311 | + 'company' => !empty($address['billing']['company']) ? $address['billing']['company'] : '', |
|
| 1312 | + 'address' => !empty($address['billing']['address']) ? $address['billing']['address'] : '', |
|
| 1313 | + 'postcode' => !empty($address['billing']['postcode']) ? $address['billing']['postcode'] : '', |
|
| 1314 | + 'city' => !empty($address['billing']['city']) ? $address['billing']['city'] : '', |
|
| 1315 | + 'state' => !empty($address['billing']['state']) ? $address['billing']['state'] : '', |
|
| 1316 | + 'country' => !empty($address['billing']['country']) ? $address['billing']['country'] : '', |
|
| 1317 | + 'address_user_email' => !empty($address['billing']['email']) ? $address['billing']['email'] : '', |
|
| 1318 | + 'phone' => !empty($address['billing']['phone']) ? $address['billing']['phone'] : '', |
|
| 1319 | + 'tva_intra' => !empty($address['billing']['company_tva_intra']) ? $address['billing']['company_tva_intra'] : '', |
|
| 1320 | + 'civility' => $civility, |
|
| 1321 | + ); |
|
| 1322 | + $billing_address_option = get_option('wpshop_billing_address'); |
|
| 1323 | + $address_format['billing']['id'] = $billing_address_option['choice']; |
|
| 1324 | + $address_format['billing']['address'] = $shipping_address; |
|
| 1325 | + } |
|
| 1326 | + |
|
| 1327 | + $shipping_address = array(); |
|
| 1328 | + if (!empty($address['shipping']) && empty($address['shipping']['id'])) { |
|
| 1329 | + if (!empty($address['shipping']['civility'])) { |
|
| 1330 | + switch ($address['shipping']['civility']) { |
|
| 1331 | + case 1: |
|
| 1332 | + $civility = $mister_id; |
|
| 1333 | + break; |
|
| 1334 | + case 2: |
|
| 1335 | + $civility = $madam_id; |
|
| 1336 | + break; |
|
| 1337 | + case 3: |
|
| 1338 | + $civility = $miss_id; |
|
| 1339 | + break; |
|
| 1340 | + } |
|
| 1341 | + } else { |
|
| 1342 | + $civility = $mister_id; |
|
| 1343 | + } |
|
| 1344 | + $shipping_address = array('address_title' => $shipping_title, |
|
| 1345 | + 'address_last_name' => !empty($address['shipping']['last_name']) ? $address['shipping']['last_name'] : '', |
|
| 1346 | + 'address_first_name' => !empty($address['shipping']['first_name']) ? $address['shipping']['first_name'] : '', |
|
| 1347 | + 'company' => !empty($address['shipping']['company']) ? $address['shipping']['company'] : '', |
|
| 1348 | + 'address' => !empty($address['shipping']['address']) ? $address['shipping']['address'] : '', |
|
| 1349 | + 'postcode' => !empty($address['shipping']['postcode']) ? $address['shipping']['postcode'] : '', |
|
| 1350 | + 'city' => !empty($address['shipping']['city']) ? $address['shipping']['city'] : '', |
|
| 1351 | + 'state' => !empty($address['shipping']['state']) ? $address['shipping']['state'] : '', |
|
| 1352 | + 'country' => !empty($address['shipping']['country']) ? $address['shipping']['country'] : '', |
|
| 1353 | + 'civility' => $civility, |
|
| 1354 | + ); |
|
| 1355 | + $shipping_address_options = get_option('wpshop_shipping_address_choice'); |
|
| 1356 | + $address_format['shipping']['id'] = $shipping_address_options['choice']; |
|
| 1357 | + $address_format['shipping']['address'] = $shipping_address; |
|
| 1358 | + } |
|
| 1359 | + |
|
| 1360 | + if (!empty($address_format)) { |
|
| 1361 | + update_post_meta($result->ID, '_order_info', $address_format); |
|
| 1362 | + } |
|
| 1363 | + } |
|
| 1364 | + |
|
| 1365 | + /** Delete username from frontend form */ |
|
| 1366 | + $attribute_login = wpshop_attributes::getElement('user_login', "'valid'", 'code'); |
|
| 1367 | + if (!empty($attribute_login)) { |
|
| 1368 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('status' => 'deleted', 'last_update_date' => current_time('mysql', 0), 'position' => 0), array('attribute_id' => $attribute_login->id)); |
|
| 1369 | + } |
|
| 1370 | + |
|
| 1371 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('last_update_date' => current_time('mysql', 0), 'position' => 0), array('status' => 'deleted')); |
|
| 1372 | + |
|
| 1373 | + return true; |
|
| 1374 | + break; |
|
| 1375 | + |
|
| 1376 | + case '31': |
|
| 1377 | + /** Change order structure in order to support several payment */ |
|
| 1378 | + $existing_orders = query_posts(array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ORDER, 'posts_per_page' => -1, 'post_status' => array('draft', 'trash', 'publish'))); |
|
| 1379 | + if (!empty($existing_orders)) { |
|
| 1380 | + foreach ($existing_orders as $order_main_informations) { |
|
| 1381 | + /** Transfer payment return data form old meta to new */ |
|
| 1382 | + $order_payment_return_data = get_post_meta($order_main_informations->ID, 'wpshop_payment_return_data', true); |
|
| 1383 | + update_post_meta($order_main_informations->ID, '_wpshop_payment_return_data', $order_payment_return_data); |
|
| 1384 | + delete_post_meta($order_main_informations->ID, 'wpshop_payment_return_data'); |
|
| 1385 | + |
|
| 1386 | + /** Transfer old payment storage method to new storage method */ |
|
| 1387 | + $order_meta = get_post_meta($order_main_informations->ID, '_order_postmeta', true); |
|
| 1388 | + if (!empty($order_meta['order_status'])) { |
|
| 1389 | + $order_meta['order_payment']['customer_choice'] = array('method' => (!empty($order_meta['payment_method']) ? $order_meta['payment_method'] : (!empty($order_meta['order_payment']['customer_choice']) ? $order_meta['order_payment']['customer_choice'] : ''))); |
|
| 1390 | + unset($order_meta['payment_method']); |
|
| 1391 | + $order_meta['order_payment']['received'][0]['waited_amount'] = !empty($order_meta['order_grand_total']) ? $order_meta['order_grand_total'] : 0; |
|
| 1392 | + $order_meta['order_payment']['received'][0]['method'] = $order_meta['order_payment']['customer_choice']['method']; |
|
| 1393 | + $order_meta['order_payment']['received'][0]['date'] = $order_meta['order_date']; |
|
| 1394 | + $order_meta['order_payment']['received'][0]['status'] = 'waiting_payment'; |
|
| 1395 | + $order_meta['order_payment']['received'][0]['comment'] = ''; |
|
| 1396 | + $order_meta['order_payment']['received'][0]['author'] = $order_meta['order_payment']['customer_choice'] == 'check' ? 1 : $order_meta['customer_id']; |
|
| 1397 | + if (in_array($order_meta['order_status'], array('completed', 'shipped'))) { |
|
| 1398 | + $order_meta['order_payment']['received'][0]['received_amount'] = $order_meta['order_grand_total']; |
|
| 1399 | + $order_meta['order_payment']['received'][0]['payment_reference'] = wpshop_payment::get_payment_transaction_number_old_way($order_main_informations->ID); |
|
| 1400 | + $order_meta['order_payment']['received'][0]['date'] = $order_meta['order_payment_date']; |
|
| 1401 | + $order_meta['order_payment']['received'][0]['status'] = 'payment_received'; |
|
| 1402 | + $order_meta['order_payment']['received'][0]['comment'] = ''; |
|
| 1403 | + $order_meta['order_payment']['received'][0]['author'] = $order_meta['order_payment']['customer_choice'] == 'check' ? 1 : $order_meta['customer_id']; |
|
| 1404 | + $order_meta['order_payment']['received'][0]['invoice_ref'] = $order_meta['order_invoice_ref']; |
|
| 1405 | + } |
|
| 1406 | + update_post_meta($order_main_informations->ID, '_order_postmeta', $order_meta); |
|
| 1407 | + |
|
| 1408 | + if (!empty($order_meta['order_payment']['customer_choice'])) { |
|
| 1409 | + switch ($order_meta['order_payment']['customer_choice']) { |
|
| 1410 | + case 'check': |
|
| 1411 | + delete_post_meta($order_main_informations->ID, '_order_check_number', get_post_meta($order_main_informations->ID, '_order_check_number', true)); |
|
| 1412 | + break; |
|
| 1413 | + case 'paypal': |
|
| 1414 | + delete_post_meta($order_main_informations->ID, '_order_paypal_txn_id', get_post_meta($order_main_informations->ID, '_order_paypal_txn_id', true)); |
|
| 1415 | + break; |
|
| 1416 | + case 'cic': |
|
| 1417 | + delete_post_meta($order_main_informations->ID, '_order_cic_txn_id', get_post_meta($order_main_informations->ID, '_order_cic_txn_id', true)); |
|
| 1418 | + break; |
|
| 1419 | + } |
|
| 1420 | + } |
|
| 1421 | + } |
|
| 1422 | + } |
|
| 1423 | + } |
|
| 1424 | + $wps_messages = new wps_message_ctr(); |
|
| 1425 | + $wps_messages->wpshop_messages_historic_correction(); |
|
| 1426 | + wp_reset_query(); |
|
| 1427 | + |
|
| 1428 | + $default_currency = get_option('wpshop_shop_default_currency'); |
|
| 1429 | + foreach (unserialize(WPSHOP_SHOP_CURRENCIES) as $k => $v) { |
|
| 1430 | + if ($default_currency == $k) { |
|
| 1431 | + $symbol = $v; |
|
| 1432 | + } |
|
| 1433 | + } |
|
| 1434 | + if (!empty($symbol)) { |
|
| 1435 | + $query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_UNIT . ' WHERE name = "' . html_entity_decode($symbol, ENT_QUOTES, 'UTF-8') . '"', ''); |
|
| 1436 | + $currency = $wpdb->get_row($query); |
|
| 1437 | + if (!empty($currency)) { |
|
| 1438 | + update_option('wpshop_shop_default_currency', $currency->id); |
|
| 1439 | + // Update the change rate of the default currency |
|
| 1440 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE_UNIT, array('change_rate' => 1), array('id' => $currency->id)); |
|
| 1441 | + } |
|
| 1442 | + } |
|
| 1443 | + |
|
| 1444 | + $shipping_confirmation_message = get_option('WPSHOP_SHIPPING_CONFIRMATION_MESSAGE'); |
|
| 1445 | + if (!empty($shipping_confirmation_message)) { |
|
| 1446 | + $message = __('Hello [customer_first_name] [customer_last_name], this email confirms that your order ([order_key]) has just been shipped (order date : [order_date], tracking number : [order_trackingNumber]). Thank you for your loyalty. Have a good day.', 'wpshop'); |
|
| 1447 | + $post = array('ID' => $shipping_confirmation_message, 'post_content' => $message); |
|
| 1448 | + wp_update_post($post); |
|
| 1449 | + } |
|
| 1450 | + return true; |
|
| 1451 | + break; |
|
| 1452 | + case '32': |
|
| 1453 | + /** Update product set id that are null */ |
|
| 1454 | + $query = $wpdb->prepare("UPDATE " . $wpdb->postmeta . " SET meta_value = (SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE_SET . " WHERE default_set = 'yes' AND entity_id = '" . wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT) . "') WHERE meta_key = %s AND ((meta_value = '') OR (meta_value = null))", '_' . WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT . '_attribute_set_id'); |
|
| 1455 | + $wpdb->query($query); |
|
| 1456 | + |
|
| 1457 | + $addons_options = get_option(WPSHOP_ADDONS_OPTION_NAME); |
|
| 1458 | + if (!empty($addons_options) && !empty($addons_options['WPSHOP_ADDONS_QUOTATION']) && !empty($addons_options['WPSHOP_ADDONS_QUOTATION']['activate']) && $addons_options['WPSHOP_ADDONS_QUOTATION']['activate']) { |
|
| 1459 | + $admin_new_quotation_message = get_option('WPSHOP_NEW_QUOTATION_ADMIN_MESSAGE'); |
|
| 1460 | + if (empty($admin_new_quotation_message)) { |
|
| 1461 | + wps_message_ctr::createMessage('WPSHOP_NEW_QUOTATION_ADMIN_MESSAGE'); |
|
| 1462 | + } |
|
| 1463 | + $admin_new_quotation_confirm_message = get_option('WPSHOP_QUOTATION_CONFIRMATION_MESSAGE'); |
|
| 1464 | + if (empty($admin_new_quotation_confirm_message)) { |
|
| 1465 | + wps_message_ctr::createMessage('WPSHOP_QUOTATION_CONFIRMATION_MESSAGE'); |
|
| 1466 | + } |
|
| 1467 | + } |
|
| 1468 | + |
|
| 1469 | + /** Allows the administrator to manage a little bit more the catalog rewrite parameters */ |
|
| 1470 | + $options = get_option('wpshop_catalog_product_option'); |
|
| 1471 | + $options['wpshop_catalog_product_slug_with_category'] = empty($options['wpshop_catalog_product_slug_with_category']) ? 'yes' : $options['wpshop_catalog_product_slug_with_category']; |
|
| 1472 | + update_option('wpshop_catalog_product_option', $options); |
|
| 1473 | + |
|
| 1474 | + /** Create a new page for unsuccessfull payment return */ |
|
| 1475 | + self::wpshop_insert_default_pages($wpshop_shop_type); |
|
| 1476 | + wp_cache_flush(); |
|
| 1477 | + |
|
| 1478 | + /** Update the iso code of currencies */ |
|
| 1479 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE_UNIT, array('code_iso' => 'EUR'), array('name' => 'euro')); |
|
| 1480 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE_UNIT, array('code_iso' => 'USD'), array('name' => 'dollar')); |
|
| 1481 | + |
|
| 1482 | + /** Update VAT Rate*/ |
|
| 1483 | + $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE . ' WHERE code = %s OR code = %s', 'tx_tva', 'eco_taxe_rate_tva'); |
|
| 1484 | + $attribute_ids = $wpdb->get_results($query); |
|
| 1485 | + foreach ($attribute_ids as $attribute_id) { |
|
| 1486 | + $query = $wpdb->prepare('UPDATE ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' SET value = replace(value, "-", ".") WHERE attribute_id = %d', $attribute_id->id); |
|
| 1487 | + $wpdb->query($query); |
|
| 1488 | + } |
|
| 1489 | + |
|
| 1490 | + return true; |
|
| 1491 | + break; |
|
| 1492 | + |
|
| 1493 | + case '33': |
|
| 1494 | + /** Update the user_mail for the new system of log in/register */ |
|
| 1495 | + $query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_used_in_quick_add_form = "yes" WHERE code = "user_email"'); |
|
| 1496 | + |
|
| 1497 | + /** Put discount attributes in price attribute set section*/ |
|
| 1498 | + $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_GROUP . ' WHERE code = %s', 'prices'); |
|
| 1499 | + $prices_section_id = $wpdb->get_var($query); |
|
| 1500 | + |
|
| 1501 | + $query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE . ' WHERE code = %s OR code = %s', 'discount_rate', 'discount_amount'); |
|
| 1502 | + $attributes = $wpdb->get_results($query); |
|
| 1503 | + if (!empty($attributes) && !empty($prices_section_id)) { |
|
| 1504 | + foreach ($attributes as $attribute) { |
|
| 1505 | + $query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE_DETAILS . ' SET attribute_group_id = ' . $prices_section_id . ' WHERE attribute_id = ' . $attribute->id); |
|
| 1506 | + } |
|
| 1507 | + } |
|
| 1508 | + return true; |
|
| 1509 | + break; |
|
| 1510 | + |
|
| 1511 | + case '34': |
|
| 1512 | + $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_GROUP . ' WHERE code = %s', 'prices'); |
|
| 1513 | + $prices_section_id = $wpdb->get_var($query); |
|
| 1514 | + |
|
| 1515 | + $query = $wpdb->prepare('SELECT MAX(position) AS max_position FROM ' . WPSHOP_DBT_ATTRIBUTE_DETAILS . ' WHERE attribute_group_id = %d', $prices_section_id); |
|
| 1516 | + $last_position_id = $wpdb->get_var($query); |
|
| 1517 | + |
|
| 1518 | + $query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_DETAILS . ' WHERE attribute_group_id = %d AND position = %d', $prices_section_id, $last_position_id); |
|
| 1519 | + $attribute_example = $wpdb->get_row($query); |
|
| 1520 | + |
|
| 1521 | + $query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE . ' WHERE code = %s OR code = %s', 'special_from', 'special_to'); |
|
| 1522 | + $attributes = $wpdb->get_results($query); |
|
| 1523 | + $i = 1; |
|
| 1524 | + if (!empty($attributes) && !empty($prices_section_id)) { |
|
| 1525 | + |
|
| 1526 | + foreach ($attributes as $attribute) { |
|
| 1527 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('attribute_group_id' => $prices_section_id), array('attribute_id' => $attribute->id)); |
|
| 1528 | + $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'entity_type_id' => $attribute_example->entity_type_id, 'attribute_set_id' => $attribute_example->attribute_set_id, 'attribute_group_id' => $prices_section_id, 'attribute_id' => $attribute->id, 'position' => $last_position_id + $i)); |
|
| 1529 | + $i++; |
|
| 1530 | + } |
|
| 1531 | + } |
|
| 1532 | + $discount_options = get_option('wpshop_catalog_product_option'); |
|
| 1533 | + $status = (!empty($discount_options) && !empty($discount_options['discount'])) ? 'valid' : 'notused'; |
|
| 1534 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('frontend_label' => __('Discount from', 'wpshop'), 'status' => $status), array('code' => 'special_from')); |
|
| 1535 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('frontend_label' => __('Discount to', 'wpshop'), 'status' => $status), array('code' => 'special_to')); |
|
| 1536 | + return true; |
|
| 1537 | + break; |
|
| 1538 | + |
|
| 1539 | + case '35': |
|
| 1540 | + $wpdb->update($wpdb->posts, array('post_status' => 'draft'), array('post_type' => WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS)); |
|
| 1541 | + return true; |
|
| 1542 | + break; |
|
| 1543 | + |
|
| 1544 | + case '36': |
|
| 1545 | + wpshop_entities::create_cpt_attributes_from_csv_file(WPSHOP_NEWTYPE_IDENTIFIER_ADDRESS); |
|
| 1546 | + @set_time_limit(900); |
|
| 1547 | + /** Change the path for old categories pictures */ |
|
| 1548 | + @chmod(WPSHOP_UPLOAD_DIR . 'wpshop_product_category', 0755); |
|
| 1549 | + |
|
| 1550 | + $query = 'SELECT * FROM ' . $wpdb->terms; |
|
| 1551 | + $terms = $wpdb->get_results($query); |
|
| 1552 | + if (!empty($terms)) { |
|
| 1553 | + foreach ($terms as $term) { |
|
| 1554 | + @chmod(WPSHOP_UPLOAD_DIR . 'wpshop_product_category/' . $term->term_id, 0755); |
|
| 1555 | + /** Check if a picture exists **/ |
|
| 1556 | + $term_option = get_option(WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES . '_' . $term->term_id); |
|
| 1557 | + if (!empty($term_option) && !empty($term_option['wpshop_category_picture']) && is_file(WPSHOP_UPLOAD_DIR . $term_option['wpshop_category_picture'])) { |
|
| 1558 | + $wp_upload_dir = wp_upload_dir(); |
|
| 1559 | + $img_path = WPSHOP_UPLOAD_DIR . $term_option['wpshop_category_picture']; |
|
| 1560 | + $img_basename = basename($img_path); |
|
| 1561 | + $wp_filetype = wp_check_filetype($img_basename, null); |
|
| 1562 | + /** Check if there is an image with the same name, if yes we add a rand number to image's name **/ |
|
| 1563 | + $rand_name = (is_file($wp_upload_dir['path'] . '/' . $img_basename)) ? rand() : ''; |
|
| 1564 | + $img_basename = (!empty($rand_name)) ? $rand_name . '_' . $img_basename : $img_basename; |
|
| 1565 | + if (copy($img_path, $wp_upload_dir['path'] . '/' . $img_basename)) { |
|
| 1566 | + $attachment = array( |
|
| 1567 | + 'guid' => $wp_upload_dir['url'] . '/' . $img_basename, |
|
| 1568 | + 'post_mime_type' => $wp_filetype['type'], |
|
| 1569 | + 'post_title' => preg_replace('/\.[^.]+$/', '', $img_basename), |
|
| 1570 | + 'post_content' => '', |
|
| 1571 | + 'post_status' => 'inherit', |
|
| 1572 | + ); |
|
| 1573 | + $attach_id = wp_insert_attachment($attachment, $wp_upload_dir['path'] . '/' . $img_basename); |
|
| 1574 | + /** Generate differnts sizes for this image **/ |
|
| 1575 | + require_once ABSPATH . 'wp-admin/includes/image.php'; |
|
| 1576 | + $attach_data = wp_generate_attachment_metadata($attach_id, $wp_upload_dir['path'] . '/' . $img_basename); |
|
| 1577 | + wp_update_attachment_metadata($attach_id, $attach_data); |
|
| 1578 | + /** Update option picture **/ |
|
| 1579 | + $term_option['wpshop_category_picture'] = $attach_id; |
|
| 1580 | + update_option(WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES . '_' . $term->term_id, $term_option); |
|
| 1581 | + } |
|
| 1582 | + } |
|
| 1583 | + } |
|
| 1584 | + } |
|
| 1585 | + |
|
| 1586 | + /** Change metabox Hidden Nav Menu Definition to display WPShop categories' metabox **/ |
|
| 1587 | + $query = $wpdb->prepare('SELECT * FROM ' . $wpdb->usermeta . ' WHERE meta_key = %s', 'metaboxhidden_nav-menus'); |
|
| 1588 | + $meta_keys = $wpdb->get_results($query); |
|
| 1589 | + if (!empty($meta_keys) && is_array($meta_keys)) { |
|
| 1590 | + foreach ($meta_keys as $meta_key) { |
|
| 1591 | + $user_id = $meta_key->user_id; |
|
| 1592 | + $meta_value = unserialize($meta_key->meta_value); |
|
| 1593 | + if (!empty($meta_value) && is_array($meta_value)) { |
|
| 1594 | + $data_to_delete = array_search('add-wpshop_product_category', $meta_value); |
|
| 1595 | + if ($data_to_delete !== false) { |
|
| 1596 | + unset($meta_value[$data_to_delete]); |
|
| 1597 | + } |
|
| 1598 | + } |
|
| 1599 | + update_user_meta($user_id, 'metaboxhidden_nav-menus', $meta_value); |
|
| 1600 | + } |
|
| 1601 | + } |
|
| 1602 | + return true; |
|
| 1603 | + break; |
|
| 1604 | + |
|
| 1605 | + case '37': |
|
| 1606 | + @set_time_limit(900); |
|
| 1607 | + /** Change the path for old categories pictures */ |
|
| 1608 | + @chmod(WPSHOP_UPLOAD_DIR . 'wpshop/wpshop_product_category', 0755); |
|
| 1609 | + /** Read all categories folders **/ |
|
| 1610 | + $categories_main_dir = WPSHOP_UPLOAD_DIR . 'wpshop/wpshop_product_category'; |
|
| 1611 | + if (file_exists($categories_main_dir)) { |
|
| 1612 | + $main_folder_content = scandir($categories_main_dir); |
|
| 1613 | + /** For each category folder **/ |
|
| 1614 | + foreach ($main_folder_content as $category_folder) { |
|
| 1615 | + if ($category_folder && substr($category_folder, 0, 1) != '.') { |
|
| 1616 | + $category_id = $category_folder; |
|
| 1617 | + @chmod(WPSHOP_UPLOAD_DIR . 'wpshop/wpshop_product_category/' . $category_id, 0755); |
|
| 1618 | + $scan_category_folder = opendir($categories_main_dir . '/' . $category_folder); |
|
| 1619 | + /** For each Picture of category **/ |
|
| 1620 | + $file_time = 0; |
|
| 1621 | + $save_this_picture = false; |
|
| 1622 | + while (false !== ($fichier = readdir($scan_category_folder))) { |
|
| 1623 | + if ($fichier && substr($fichier, 0, 1) != '.') { |
|
| 1624 | + if ($file_time < filemtime($categories_main_dir . '/' . $category_id . '/' . $fichier)) { |
|
| 1625 | + $save_this_picture = true; |
|
| 1626 | + $file_time = filemtime($categories_main_dir . '/' . $category_id . '/' . $fichier); |
|
| 1627 | + } |
|
| 1628 | + /** Select category option **/ |
|
| 1629 | + $term_option = get_option(WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES . '_' . $category_id); |
|
| 1630 | + $wp_upload_dir = wp_upload_dir(); |
|
| 1631 | + $img_path = $categories_main_dir . '/' . $category_id . '/' . $fichier; |
|
| 1632 | + $img_basename = basename($img_path); |
|
| 1633 | + $wp_filetype = wp_check_filetype($img_basename, null); |
|
| 1634 | + /** Check if there is an image with the same name, if yes we add a rand number to image's name **/ |
|
| 1635 | + $rand_name = (is_file($wp_upload_dir['path'] . '/' . $img_basename)) ? rand() : ''; |
|
| 1636 | + $img_basename = (!empty($rand_name)) ? $rand_name . '_' . $img_basename : $img_basename; |
|
| 1637 | + |
|
| 1638 | + if (copy($img_path, $wp_upload_dir['path'] . '/' . $img_basename)) { |
|
| 1639 | + $attachment = array( |
|
| 1640 | + 'guid' => $wp_upload_dir['url'] . '/' . $img_basename, |
|
| 1641 | + 'post_mime_type' => $wp_filetype['type'], |
|
| 1642 | + 'post_title' => preg_replace('/\.[^.]+$/', '', $img_basename), |
|
| 1643 | + 'post_content' => '', |
|
| 1644 | + 'post_status' => 'inherit', |
|
| 1645 | + ); |
|
| 1646 | + $attach_id = wp_insert_attachment($attachment, $wp_upload_dir['path'] . '/' . $img_basename); |
|
| 1647 | + /** Generate differnts sizes for this image **/ |
|
| 1648 | + require_once ABSPATH . 'wp-admin/includes/image.php'; |
|
| 1649 | + $attach_data = wp_generate_attachment_metadata($attach_id, $wp_upload_dir['path'] . '/' . $img_basename); |
|
| 1650 | + wp_update_attachment_metadata($attach_id, $attach_data); |
|
| 1651 | + /** Update option picture **/ |
|
| 1652 | + $term_option['wpshop_category_picture'] = $attach_id; |
|
| 1653 | + if ($save_this_picture) { |
|
| 1654 | + update_option(WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES . '_' . $category_id, $term_option); |
|
| 1655 | + } |
|
| 1656 | + $save_this_picture = false; |
|
| 1657 | + } |
|
| 1658 | + } |
|
| 1659 | + } |
|
| 1660 | + } |
|
| 1661 | + } |
|
| 1662 | + } |
|
| 1663 | + return true; |
|
| 1664 | + break; |
|
| 1665 | + |
|
| 1666 | + case '38': |
|
| 1667 | + wps_message_ctr::createMessage('WPSHOP_QUOTATION_UPDATE_MESSAGE'); |
|
| 1668 | + return true; |
|
| 1669 | + break; |
|
| 1670 | + |
|
| 1671 | + case '39': |
|
| 1672 | + $attribute_def = wpshop_attributes::getElement('tx_tva', "'valid'", 'code'); |
|
| 1673 | + /** Check if the 7% VAT Rate is not already created **/ |
|
| 1674 | + $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE attribute_id = %d AND value = %s', $attribute_def->id, '7'); |
|
| 1675 | + $exist_vat_rate = $wpdb->get_results($query); |
|
| 1676 | + |
|
| 1677 | + if (empty($exist_vat_rate)) { |
|
| 1678 | + /** Get Max Position **/ |
|
| 1679 | + $query = $wpdb->prepare('SELECT MAX(position) as max_position FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE attribute_id = %d', $attribute_def->id); |
|
| 1680 | + $max_position = $wpdb->get_var($query); |
|
| 1681 | + |
|
| 1682 | + if (!empty($attribute_def) && !empty($attribute_def->id)) { |
|
| 1683 | + $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS, array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'attribute_id' => $attribute_def->id, 'position' => (int) $max_position + 1, 'value' => '7', 'label' => '7')); |
|
| 1684 | + } |
|
| 1685 | + } |
|
| 1686 | + |
|
| 1687 | + /** Filter Search optimization **/ |
|
| 1688 | + @set_time_limit(900); |
|
| 1689 | + $query = $wpdb->prepare('SELECT term_id FROM ' . $wpdb->term_taxonomy . ' WHERE taxonomy = %s ', WPSHOP_NEWTYPE_IDENTIFIER_CATEGORIES); |
|
| 1690 | + $categories = $wpdb->get_results($query); |
|
| 1691 | + $cats = array(); |
|
| 1692 | + if (!empty($categories)) { |
|
| 1693 | + foreach ($categories as $category) { |
|
| 1694 | + $cats[] = $category->term_id; |
|
| 1695 | + } |
|
| 1696 | + $wpshop_filter_search = new wps_filter_search(); |
|
| 1697 | + $wpshop_filter_search->stock_values_for_attribute($cats); |
|
| 1698 | + } |
|
| 1699 | + return true; |
|
| 1700 | + break; |
|
| 1701 | + |
|
| 1702 | + case '40': |
|
| 1703 | + /** Store watt in puissance unit group */ |
|
| 1704 | + $query = $wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE_UNIT_GROUP . " WHERE name = %s", __('puissance', 'wpshop')); |
|
| 1705 | + $puissance_unit_group_id = $wpdb->get_var($query); |
|
| 1706 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE_UNIT, array('group_id' => $puissance_unit_group_id), array('unit' => 'watt')); |
|
| 1707 | + |
|
| 1708 | + /** Store day/week/year in duration unit group */ |
|
| 1709 | + $query = $wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE_UNIT_GROUP . " WHERE name = %s", __('duration', 'wpshop')); |
|
| 1710 | + $duration_unit_group_id = $wpdb->get_var($query); |
|
| 1711 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE_UNIT, array('group_id' => $duration_unit_group_id), array('unit' => 'day')); |
|
| 1712 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE_UNIT, array('group_id' => $duration_unit_group_id), array('unit' => 'week')); |
|
| 1713 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE_UNIT, array('group_id' => $duration_unit_group_id), array('unit' => 'year')); |
|
| 1714 | + |
|
| 1715 | + /** Store day/week/year in duration unit group */ |
|
| 1716 | + $query = $wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE_UNIT_GROUP . " WHERE name = %s", __('length', 'wpshop')); |
|
| 1717 | + $length_unit_group_id = $wpdb->get_var($query); |
|
| 1718 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE_UNIT, array('group_id' => $length_unit_group_id), array('unit' => 'cm')); |
|
| 1719 | + return true; |
|
| 1720 | + break; |
|
| 1721 | + |
|
| 1722 | + case '41': |
|
| 1723 | + /** Get distinct attribute set and delete doublons */ |
|
| 1724 | + $query = "SELECT DISTINCT( name ) AS name, MIN( id ) as min_id FROM " . WPSHOP_DBT_ATTRIBUTE_SET . " GROUP BY name HAVING COUNT(id) > 1"; |
|
| 1725 | + $list_of_set = $wpdb->get_results($query); |
|
| 1726 | + foreach ($list_of_set as $set_infos) { |
|
| 1727 | + $query = $wpdb->prepare("DELETE FROM " . WPSHOP_DBT_ATTRIBUTE_SET . " WHERE name = %s AND id != %d", $set_infos->name, $set_infos->min_id); |
|
| 1728 | + $wpdb->query($query); |
|
| 1729 | + } |
|
| 1730 | + $wpdb->query("OPTIMIZE TABLE " . WPSHOP_DBT_ATTRIBUTE_SET); |
|
| 1731 | + |
|
| 1732 | + /** Get and delete attribute set section */ |
|
| 1733 | + $query = "DELETE FROM " . WPSHOP_DBT_ATTRIBUTE_GROUP . " WHERE attribute_set_id NOT IN ( SELECT DISTINCT(id) FROM " . WPSHOP_DBT_ATTRIBUTE_SET . " )"; |
|
| 1734 | + $wpdb->query($query); |
|
| 1735 | + $wpdb->query("OPTIMIZE TABLE " . WPSHOP_DBT_ATTRIBUTE_GROUP); |
|
| 1736 | + |
|
| 1737 | + /** Get and delete attribute set details */ |
|
| 1738 | + $query = "DELETE FROM " . WPSHOP_DBT_ATTRIBUTE_DETAILS . " WHERE attribute_set_id NOT IN ( SELECT DISTINCT(id) FROM " . WPSHOP_DBT_ATTRIBUTE_SET . " ) OR attribute_group_id NOT IN ( SELECT DISTINCT(id) FROM " . WPSHOP_DBT_ATTRIBUTE_GROUP . " )"; |
|
| 1739 | + $wpdb->query($query); |
|
| 1740 | + $wpdb->query("OPTIMIZE TABLE " . WPSHOP_DBT_ATTRIBUTE_DETAILS); |
|
| 1741 | + |
|
| 1742 | + $query = "SELECT attribute_set_id, attribute_group_id, attribute_id, MIN(id) as min_id FROM " . WPSHOP_DBT_ATTRIBUTE_DETAILS . " GROUP BY attribute_set_id, attribute_group_id, attribute_id HAVING COUNT(id) > 1"; |
|
| 1743 | + $affectation_list = $wpdb->get_results($query); |
|
| 1744 | + foreach ($affectation_list as $affectation_to_treat) { |
|
| 1745 | + $query = $wpdb->prepare("DELETE FROM " . WPSHOP_DBT_ATTRIBUTE_DETAILS . " WHERE attribute_set_id = %d AND attribute_group_id = %d AND attribute_id = %d AND id != %d", $affectation_to_treat->attribute_set_id, $affectation_to_treat->attribute_group_id, $affectation_to_treat->attribute_id, $affectation_to_treat->min_id); |
|
| 1746 | + $wpdb->query($query); |
|
| 1747 | + } |
|
| 1748 | + $wpdb->query("OPTIMIZE TABLE " . WPSHOP_DBT_ATTRIBUTE_DETAILS); |
|
| 1749 | + |
|
| 1750 | + /** Get and delete double unit */ |
|
| 1751 | + $query = "SELECT DISTINCT( unit ) AS unit, MIN( id ) as min_id FROM " . WPSHOP_DBT_ATTRIBUTE_UNIT . " GROUP BY unit HAVING COUNT(id) > 1"; |
|
| 1752 | + $list_of_set = $wpdb->get_results($query); |
|
| 1753 | + foreach ($list_of_set as $set_infos) { |
|
| 1754 | + $query = $wpdb->prepare("DELETE FROM " . WPSHOP_DBT_ATTRIBUTE_UNIT . " WHERE unit = %s AND id != %d", $set_infos->unit, $set_infos->min_id); |
|
| 1755 | + $wpdb->query($query); |
|
| 1756 | + } |
|
| 1757 | + $wpdb->query("OPTIMIZE TABLE " . WPSHOP_DBT_ATTRIBUTE_UNIT); |
|
| 1758 | + |
|
| 1759 | + $query = "SELECT DISTINCT( name ) AS name, MIN( id ) as min_id FROM " . WPSHOP_DBT_ATTRIBUTE_UNIT_GROUP . " GROUP BY name HAVING COUNT(id) > 1"; |
|
| 1760 | + $list_of_set = $wpdb->get_results($query); |
|
| 1761 | + foreach ($list_of_set as $set_infos) { |
|
| 1762 | + $query = $wpdb->prepare("DELETE FROM " . WPSHOP_DBT_ATTRIBUTE_UNIT_GROUP . " WHERE name = %s AND id != %d", $set_infos->name, $set_infos->min_id); |
|
| 1763 | + $wpdb->query($query); |
|
| 1764 | + } |
|
| 1765 | + $wpdb->query("OPTIMIZE TABLE " . WPSHOP_DBT_ATTRIBUTE_UNIT_GROUP); |
|
| 1766 | + |
|
| 1767 | + /** Get and delete attribute set details */ |
|
| 1768 | + $query = "DELETE FROM " . WPSHOP_DBT_ATTRIBUTE_DETAILS . " WHERE attribute_set_id NOT IN ( SELECT DISTINCT(id) FROM " . WPSHOP_DBT_ATTRIBUTE_SET . " ) OR attribute_group_id NOT IN ( SELECT DISTINCT(id) FROM " . WPSHOP_DBT_ATTRIBUTE_GROUP . " )"; |
|
| 1769 | + $wpdb->query($query); |
|
| 1770 | + $query = "SELECT GROUP_CONCAT( id ) AS list_id, MIN( id ) as min_id FROM " . WPSHOP_DBT_ATTRIBUTE_DETAILS . " GROUP BY attribute_set_id, attribute_group_id, attribute_id HAVING COUNT(id) > 1"; |
|
| 1771 | + $affectation_list = $wpdb->get_results($query); |
|
| 1772 | + foreach ($affectation_list as $list) { |
|
| 1773 | + $query = $wpdb->prepare("DELETE FROM " . WPSHOP_DBT_ATTRIBUTE_DETAILS . " WHERE id IN (" . (substr($list->list_id, -1) == ',' ? substr($list->list_id, 0, -1) : $list->list_id) . ") AND id != %d", $list->min_id, ''); |
|
| 1774 | + $wpdb->query($query); |
|
| 1775 | + } |
|
| 1776 | + $wpdb->query("OPTIMIZE TABLE " . WPSHOP_DBT_ATTRIBUTE_DETAILS); |
|
| 1777 | + |
|
| 1778 | + return true; |
|
| 1779 | + break; |
|
| 1780 | + |
|
| 1781 | + case '42': |
|
| 1782 | + $available_downloadable_product = get_option('WPSHOP_DOWNLOADABLE_FILE_IS_AVAILABLE'); |
|
| 1783 | + if (empty($available_downloadable_product)) { |
|
| 1784 | + wps_message_ctr::createMessage('WPSHOP_DOWNLOADABLE_FILE_IS_AVAILABLE'); |
|
| 1785 | + } |
|
| 1786 | + return true; |
|
| 1787 | + break; |
|
| 1788 | + |
|
| 1789 | + case '43': |
|
| 1790 | + $available_downloadable_product = get_option('WPSHOP_ORDER_IS_CANCELED'); |
|
| 1791 | + if (empty($available_downloadable_product)) { |
|
| 1792 | + wps_message_ctr::createMessage('WPSHOP_ORDER_IS_CANCELED'); |
|
| 1793 | + } |
|
| 1794 | + return true; |
|
| 1795 | + break; |
|
| 1796 | + |
|
| 1797 | + case '44': |
|
| 1798 | + $display_option = get_option('wpshop_display_option'); |
|
| 1799 | + if (!empty($display_option) && empty($display_option['latest_products_ordered'])) { |
|
| 1800 | + $display_option['latest_products_ordered'] = 3; |
|
| 1801 | + update_option('wpshop_display_option', $display_option); |
|
| 1802 | + } |
|
| 1803 | + |
|
| 1804 | + /** Check messages for customization **/ |
|
| 1805 | + // @since 1.4.3.7 Deleted messages constants |
|
| 1806 | + /*$messages = array('WPSHOP_SIGNUP_MESSAGE' => WPSHOP_SIGNUP_MESSAGE, 'WPSHOP_PAYPAL_PAYMENT_CONFIRMATION_MESSAGE' => WPSHOP_PAYPAL_PAYMENT_CONFIRMATION_MESSAGE, 'WPSHOP_OTHERS_PAYMENT_CONFIRMATION_MESSAGE' => WPSHOP_OTHERS_PAYMENT_CONFIRMATION_MESSAGE, 'WPSHOP_SHIPPING_CONFIRMATION_MESSAGE' => WPSHOP_SHIPPING_CONFIRMATION_MESSAGE, 'WPSHOP_ORDER_UPDATE_MESSAGE' => WPSHOP_ORDER_UPDATE_MESSAGE, 'WPSHOP_ORDER_UPDATE_PRIVATE_MESSAGE' => WPSHOP_ORDER_UPDATE_PRIVATE_MESSAGE, 'WPSHOP_NEW_ORDER_ADMIN_MESSAGE' => WPSHOP_NEW_ORDER_ADMIN_MESSAGE, 'WPSHOP_NEW_QUOTATION_ADMIN_MESSAGE' => WPSHOP_NEW_QUOTATION_ADMIN_MESSAGE, 'WPSHOP_QUOTATION_CONFIRMATION_MESSAGE' => WPSHOP_QUOTATION_CONFIRMATION_MESSAGE, 'WPSHOP_QUOTATION_UPDATE_MESSAGE' => WPSHOP_QUOTATION_UPDATE_MESSAGE, 'WPSHOP_DOWNLOADABLE_FILE_IS_AVAILABLE' => WPSHOP_DOWNLOADABLE_FILE_IS_AVAILABLE, 'WPSHOP_ORDER_IS_CANCELED' => WPSHOP_ORDER_IS_CANCELED); |
|
| 1807 | 1807 | if (!empty($messages)) { |
| 1808 | 1808 | foreach ($messages as $key => $message) { |
| 1809 | 1809 | $message_option = get_option($key); |
@@ -1818,572 +1818,572 @@ discard block |
||
| 1818 | 1818 | } |
| 1819 | 1819 | }*/ |
| 1820 | 1820 | |
| 1821 | - return true; |
|
| 1822 | - break; |
|
| 1823 | - |
|
| 1824 | - case '45': |
|
| 1825 | - $shipping_mode_ctr = new wps_shipping_mode_ctr(); |
|
| 1826 | - $shipping_mode_ctr->migrate_default_shipping_mode(); |
|
| 1827 | - return true; |
|
| 1828 | - break; |
|
| 1829 | - |
|
| 1830 | - case '46': |
|
| 1831 | - wps_message_ctr::createMessage('WPSHOP_FORGOT_PASSWORD_MESSAGE'); |
|
| 1832 | - wps_message_ctr::customize_message(WPSHOP_FORGOT_PASSWORD_MESSAGE); |
|
| 1833 | - return true; |
|
| 1834 | - break; |
|
| 1835 | - |
|
| 1836 | - case '47': |
|
| 1837 | - wps_payment_mode::migrate_payment_modes(); |
|
| 1838 | - return true; |
|
| 1839 | - break; |
|
| 1840 | - |
|
| 1841 | - case '48': |
|
| 1842 | - @ini_set('max_execution_time', '500'); |
|
| 1843 | - |
|
| 1844 | - $count_products = wp_count_posts(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT); |
|
| 1845 | - $output_type_option = get_option('wpshop_display_option'); |
|
| 1846 | - $output_type = $output_type_option['wpshop_display_list_type']; |
|
| 1847 | - |
|
| 1848 | - for ($i = 0; $i <= $count_products->publish; $i += 20) { |
|
| 1849 | - $query = $wpdb->prepare('SELECT * FROM ' . $wpdb->posts . ' WHERE post_type = %s AND post_status = %s ORDER BY ID DESC LIMIT ' . $i . ', 20', WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'publish'); |
|
| 1850 | - $products = $wpdb->get_results($query); |
|
| 1851 | - if (!empty($products)) { |
|
| 1852 | - foreach ($products as $product) { |
|
| 1853 | - $p = wpshop_products::get_product_data($product->ID); |
|
| 1854 | - $price = wpshop_prices::get_product_price($p, 'just_price_infos', array('mini_output', $output_type)); |
|
| 1855 | - update_post_meta($product->ID, '_wps_price_infos', $price); |
|
| 1856 | - } |
|
| 1857 | - } |
|
| 1858 | - } |
|
| 1859 | - |
|
| 1860 | - return true; |
|
| 1861 | - break; |
|
| 1862 | - |
|
| 1863 | - case '49': |
|
| 1864 | - update_option('wpshop_send_invoice', true); |
|
| 1865 | - return true; |
|
| 1866 | - break; |
|
| 1867 | - |
|
| 1868 | - case '50': |
|
| 1869 | - $price_display_option = get_option('wpshop_catalog_product_option'); |
|
| 1870 | - $price_display_option['price_display']['text_from'] = 'on'; |
|
| 1871 | - $price_display_option['price_display']['lower_price'] = 'on'; |
|
| 1872 | - update_option('wpshop_catalog_product_option', $price_display_option); |
|
| 1873 | - |
|
| 1874 | - self::wpshop_insert_default_pages(); |
|
| 1875 | - |
|
| 1876 | - return true; |
|
| 1877 | - break; |
|
| 1878 | - |
|
| 1879 | - case '51': |
|
| 1880 | - /** Insert new message for direct payment link */ |
|
| 1881 | - $direct_payment_link_message = get_option('WPSHOP_DIRECT_PAYMENT_LINK_MESSAGE'); |
|
| 1882 | - if (empty($direct_payment_link_message)) { |
|
| 1883 | - wps_message_ctr::createMessage('WPSHOP_DIRECT_PAYMENT_LINK_MESSAGE'); |
|
| 1884 | - } |
|
| 1885 | - return true; |
|
| 1886 | - break; |
|
| 1887 | - |
|
| 1888 | - case '52': |
|
| 1889 | - $account_page_option = get_option('wpshop_myaccount_page_id'); |
|
| 1890 | - if (!empty($account_page_option)) { |
|
| 1891 | - $page_account = get_post($account_page_option); |
|
| 1892 | - $page_content = (!empty($page_account) && !empty($page_account->post_content)) ? str_replace('[wpshop_myaccount]', '[wps_account_dashboard]', $page_account->post_content) : '[wps_account_dashboard]'; |
|
| 1893 | - wp_update_post(array('ID' => $account_page_option, 'post_content' => $page_content)); |
|
| 1894 | - } |
|
| 1895 | - return true; |
|
| 1896 | - break; |
|
| 1897 | - |
|
| 1898 | - case '53': |
|
| 1899 | - $payment_modes_option = get_option('wps_payment_mode'); |
|
| 1900 | - if (!empty($payment_modes_option) && !empty($payment_modes_option['mode'])) { |
|
| 1901 | - $payment_modes_option['mode']['cash_on_delivery'] = array( |
|
| 1902 | - 'name' => __('Cash on delivery', 'wpshop'), |
|
| 1903 | - 'logo' => WPSHOP_TEMPLATES_URL . 'wpshop/cheque.png', |
|
| 1904 | - 'description' => __('Pay your order on delivery', 'wpshop')); |
|
| 1905 | - |
|
| 1906 | - update_option('wps_payment_mode', $payment_modes_option); |
|
| 1907 | - } |
|
| 1908 | - |
|
| 1909 | - // Mass action on products to add a flag on variation definition |
|
| 1910 | - $products = get_posts(array('posts_per_page' => -1, 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT)); |
|
| 1911 | - if (!empty($products)) { |
|
| 1912 | - foreach ($products as $p) { |
|
| 1913 | - $post_id = $p->ID; |
|
| 1914 | - $check_product_have_variations = wpshop_products::get_variation($post_id); |
|
| 1915 | - if (!empty($check_product_have_variations)) { |
|
| 1916 | - $variation_flag = wpshop_products::check_variation_type($post_id); |
|
| 1917 | - $variation_defining = get_post_meta($post_id, '_wpshop_variation_defining', true); |
|
| 1918 | - $variation_defining['variation_type'] = $variation_flag; |
|
| 1919 | - update_post_meta($post_id, '_wpshop_variation_defining', $variation_defining); |
|
| 1920 | - } |
|
| 1921 | - } |
|
| 1922 | - } |
|
| 1923 | - return true; |
|
| 1924 | - break; |
|
| 1925 | - |
|
| 1926 | - case '54': |
|
| 1927 | - // Change shortcode of sign up page |
|
| 1928 | - $signup_page_id = get_option('wpshop_signup_page_id'); |
|
| 1929 | - if (!empty($signup_page_id)) { |
|
| 1930 | - $signup_page = get_post($signup_page_id); |
|
| 1931 | - $signup_page_content = (!empty($signup_page) && !empty($signup_page->post_content)) ? str_replace('[wpshop_signup]', '[wps_account_dashboard]', $signup_page->post_content) : '[wps_account_dashboard]'; |
|
| 1932 | - wp_update_post(array('ID' => $signup_page_id, 'post_content' => $signup_page_content)); |
|
| 1933 | - } |
|
| 1934 | - |
|
| 1935 | - // Change Terms of sale default content |
|
| 1936 | - $terms_page_id = get_option('wpshop_terms_of_sale_page_id'); |
|
| 1937 | - if (!empty($terms_page_id)) { |
|
| 1938 | - $terms_sale_page = get_post($terms_page_id); |
|
| 1939 | - if (!empty($terms_sale_page) && !empty($terms_sale_page->post_content) && $terms_sale_page->post_content == '[wpshop_terms_of_sale]') { |
|
| 1940 | - $data = '<h1>' . __('Your terms of sale', 'wpshop') . '</h1>'; |
|
| 1941 | - $data .= '<h3>' . __('Rule', 'wpshop') . ' 1</h3>'; |
|
| 1942 | - $data .= '<p>Ut enim quisque sibi plurimum confidit et ut quisque maxime virtute et sapientia sic munitus est, ut nullo egeat suaque omnia in se ipso posita iudicet, ita in amicitiis expetendis colendisque maxime excellit.</p>'; |
|
| 1943 | - $data .= '<h3>' . __('Rule', 'wpshop') . ' 2</h3>'; |
|
| 1944 | - $data .= '<p>Ut enim quisque sibi plurimum confidit et ut quisque maxime virtute et sapientia sic munitus est, ut nullo egeat suaque omnia in se ipso posita iudicet, ita in amicitiis expetendis colendisque maxime excellit.</p>'; |
|
| 1945 | - $data .= '<h3>' . __('Rule', 'wpshop') . ' 3</h3>'; |
|
| 1946 | - $data .= '<p>Ut enim quisque sibi plurimum confidit et ut quisque maxime virtute et sapientia sic munitus est, ut nullo egeat suaque omnia in se ipso posita iudicet, ita in amicitiis expetendis colendisque maxime excellit.</p>'; |
|
| 1947 | - $data .= '<h3>' . __('Credits', 'wpshop') . '</h3>'; |
|
| 1948 | - $data .= sprintf(__('%s uses <a href="http://www.wpshop.fr/" target="_blank" title="%s uses WPShop e-commerce plug-in for Wordpress">WPShop e-commerce for Wordpress</a>', 'wpshop'), get_bloginfo('name'), get_bloginfo('name')); |
|
| 1949 | - wp_update_post(array('ID' => $terms_page_id, 'post_content' => $data)); |
|
| 1950 | - } |
|
| 1951 | - } |
|
| 1952 | - |
|
| 1953 | - return true; |
|
| 1954 | - break; |
|
| 1955 | - |
|
| 1956 | - case '55': |
|
| 1957 | - $checkout_page_id = get_option('wpshop_checkout_page_id'); |
|
| 1958 | - $checkout_page = get_post($checkout_page_id); |
|
| 1959 | - $checkout_page_content = (!empty($checkout_page) && !empty($checkout_page->post_content)) ? str_replace('[wpshop_checkout]', '[wps_checkout]', $checkout_page->post_content) : '[wps_checkout]'; |
|
| 1960 | - wp_update_post(array('ID' => $checkout_page_id, 'post_content' => $checkout_page_content)); |
|
| 1961 | - |
|
| 1962 | - // Update cart page id |
|
| 1963 | - update_option('wpshop_cart_page_id', $checkout_page_id); |
|
| 1964 | - return true; |
|
| 1965 | - break; |
|
| 1966 | - |
|
| 1967 | - case '56': |
|
| 1968 | - $wps_entities = new wpshop_entities(); |
|
| 1969 | - $customer_entity_id = $wps_entities->get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS); |
|
| 1970 | - $query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE entity_id = %d ORDER BY id LIMIT 1', $customer_entity_id); |
|
| 1971 | - $set = $wpdb->get_row($query); |
|
| 1972 | - if (!empty($set)) { |
|
| 1973 | - $wpdb->update(WPSHOP_DBT_ATTRIBUTE_SET, |
|
| 1974 | - array('default_set' => 'yes'), |
|
| 1975 | - array('id' => $set->id)); |
|
| 1976 | - } |
|
| 1977 | - // Update Opinions activation option |
|
| 1978 | - update_option('wps_opinion', array('active' => 'on')); |
|
| 1979 | - return true; |
|
| 1980 | - break; |
|
| 1981 | - |
|
| 1982 | - case '57': |
|
| 1983 | - $wpshop_cart_option = get_option('wpshop_cart_option'); |
|
| 1984 | - $wpshop_cart_option['display_newsletter']['site_subscription'][] = 'yes'; |
|
| 1985 | - $wpshop_cart_option['display_newsletter']['partner_subscription'][] = 'yes'; |
|
| 1986 | - |
|
| 1987 | - update_option('wpshop_cart_option', $wpshop_cart_option); |
|
| 1988 | - return true; |
|
| 1989 | - break; |
|
| 1990 | - |
|
| 1991 | - case '58': |
|
| 1992 | - /** Turn customers publish into draft **/ |
|
| 1993 | - $query = $wpdb->prepare("UPDATE {$wpdb->posts} SET post_status = %s WHERE post_type = %s", "draft", WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS); |
|
| 1994 | - $wpdb->query($query); |
|
| 1995 | - |
|
| 1996 | - $attribute_def = wpshop_attributes::getElement('tx_tva', "'valid'", 'code'); |
|
| 1997 | - /** Check if the 0% VAT Rate is not already created **/ |
|
| 1998 | - $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE attribute_id = %d AND value = %s', $attribute_def->id, '0'); |
|
| 1999 | - $exist_vat_rate = $wpdb->get_results($query); |
|
| 2000 | - |
|
| 2001 | - if (empty($exist_vat_rate)) { |
|
| 2002 | - /** Get Max Position **/ |
|
| 2003 | - $query = $wpdb->prepare('SELECT MAX(position) as max_position FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE attribute_id = %d', $attribute_def->id); |
|
| 2004 | - $max_position = $wpdb->get_var($query); |
|
| 2005 | - |
|
| 2006 | - if (!empty($attribute_def) && !empty($attribute_def->id)) { |
|
| 2007 | - $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS, array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'attribute_id' => $attribute_def->id, 'position' => (int) $max_position + 1, 'value' => '0', 'label' => '0')); |
|
| 2008 | - } |
|
| 2009 | - } |
|
| 2010 | - return true; |
|
| 2011 | - break; |
|
| 2012 | - |
|
| 2013 | - case '59': |
|
| 2014 | - /** Move old images gallery to the new gallery, and remove old links **/ |
|
| 2015 | - $allowed = get_allowed_mime_types(); |
|
| 2016 | - $args = array( |
|
| 2017 | - 'posts_per_page' => -1, |
|
| 2018 | - 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, |
|
| 2019 | - 'post_status' => array('publish', 'draft', 'trash'), |
|
| 2020 | - ); |
|
| 2021 | - $posts = get_posts($args); |
|
| 2022 | - $result = array(); |
|
| 2023 | - foreach ($posts as $post) { |
|
| 2024 | - $array = array(); |
|
| 2025 | - $array['Post'] = $post; |
|
| 2026 | - $array['PrincipalThumbnailID'] = get_post_meta($post->ID, '_thumbnail_id', true); |
|
| 2027 | - $array['Attachments'] = get_attached_media($allowed, $post->ID); |
|
| 2028 | - $array['TrueAttachmentsString'] = get_post_meta($post->ID, '_wps_product_media', true); |
|
| 2029 | - if (!empty($array['TrueAttachmentsString'])) { |
|
| 2030 | - $TrueAttachments_id = explode(',', $array['TrueAttachmentsString']); |
|
| 2031 | - } |
|
| 2032 | - $array['OldAttachmentsString'] = ''; |
|
| 2033 | - foreach ($array['Attachments'] as $attachment) { |
|
| 2034 | - $filename = basename(get_attached_file($attachment->ID)); |
|
| 2035 | - $pos_ext = strrpos($filename, '.'); |
|
| 2036 | - $filename_no_ext = substr($filename, 0, $pos_ext); |
|
| 2037 | - if ((empty($TrueAttachments_id) || !in_array($attachment->ID, $TrueAttachments_id)) && !(preg_match('#' . $filename_no_ext . '#', $post->post_content)) && ((empty($array['PrincipalThumbnailID']) || $attachment->ID != $array['PrincipalThumbnailID']))) { |
|
| 2038 | - $array['OldAttachmentsString'] .= $attachment->ID . ','; |
|
| 2039 | - } |
|
| 2040 | - } |
|
| 2041 | - unset($TrueAttachments_id); |
|
| 2042 | - $result[$post->ID] = $array['TrueAttachmentsString'] . $array['OldAttachmentsString']; |
|
| 2043 | - update_post_meta($post->ID, '_wps_product_media', $result[$post->ID]); |
|
| 2044 | - } |
|
| 2045 | - return true; |
|
| 2046 | - break; |
|
| 2047 | - |
|
| 2048 | - case '60': |
|
| 2049 | - /* Create default emails */ |
|
| 2050 | - wps_message_ctr::create_default_message(); |
|
| 2051 | - |
|
| 2052 | - /** Update entries for quick add */ |
|
| 2053 | - $query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_required = "yes", is_used_in_quick_add_form = "yes" WHERE code = "barcode"'); |
|
| 2054 | - $query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_used_in_quick_add_form = "yes" WHERE code = "product_stock"'); |
|
| 2055 | - $query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_used_in_quick_add_form = "yes" WHERE code = "manage_stock"'); |
|
| 2056 | - switch (WPSHOP_PRODUCT_PRICE_PILOT) { |
|
| 2057 | - case 'HT': |
|
| 2058 | - $query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_used_in_quick_add_form = "yes", is_used_in_variation = "yes" WHERE code = "price_ht"'); |
|
| 2059 | - $query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_used_in_quick_add_form = "no" WHERE code = "tx_tva"'); |
|
| 2060 | - $query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_used_in_quick_add_form = "no", is_used_in_variation = "no" WHERE code = "product_price"'); |
|
| 2061 | - break; |
|
| 2062 | - default: |
|
| 2063 | - $query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_used_in_quick_add_form = "yes", is_used_in_variation = "yes" WHERE code = "product_price"'); |
|
| 2064 | - $query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_used_in_quick_add_form = "yes" WHERE code = "tx_tva"'); |
|
| 2065 | - $query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_used_in_quick_add_form = "no", is_used_in_variation = "no" WHERE code = "price_ht"'); |
|
| 2066 | - break; |
|
| 2067 | - } |
|
| 2068 | - |
|
| 2069 | - /* Default country with WP language */ |
|
| 2070 | - $wpshop_country_default_choice_option = get_option('wpshop_country_default_choice'); |
|
| 2071 | - if (empty($wpshop_country_default_choice_option)) { |
|
| 2072 | - update_option('wpshop_country_default_choice', substr(get_bloginfo('language'), 3)); |
|
| 2073 | - } |
|
| 2074 | - return true; |
|
| 2075 | - break; |
|
| 2076 | - |
|
| 2077 | - case '61': |
|
| 2078 | - /** Import the xml for guided tour */ |
|
| 2079 | - wpsBubble_ctr::import_xml(); |
|
| 2080 | - |
|
| 2081 | - /* Hide admin bar */ |
|
| 2082 | - $wpshop_display_option = get_option('wpshop_display_option'); |
|
| 2083 | - if (!empty($wpshop_display_option) && empty($wpshop_display_option['wpshop_hide_admin_bar'])) { |
|
| 2084 | - $wpshop_display_option['wpshop_hide_admin_bar'] = 'on'; |
|
| 2085 | - update_option('wpshop_display_option', $wpshop_display_option); |
|
| 2086 | - } |
|
| 2087 | - |
|
| 2088 | - return true; |
|
| 2089 | - break; |
|
| 2090 | - |
|
| 2091 | - case '62': |
|
| 2092 | - /** Install user default for POS */ |
|
| 2093 | - wps_pos_addon::action_to_do_on_activation(); |
|
| 2094 | - |
|
| 2095 | - return true; |
|
| 2096 | - break; |
|
| 2097 | - |
|
| 2098 | - case '63': |
|
| 2099 | - $data = get_option('wps_shipping_mode'); |
|
| 2100 | - if (empty($data['modes']['default_shipping_mode_for_pos'])) { |
|
| 2101 | - $data['modes']['default_shipping_mode_for_pos']['name'] = __('No Delivery', 'wpshop'); |
|
| 2102 | - $data['modes']['default_shipping_mode_for_pos']['explanation'] = __('Delivery method for point of sale.', 'wpshop'); |
|
| 2103 | - update_option('wps_shipping_mode', $data); |
|
| 2104 | - } |
|
| 2105 | - return true; |
|
| 2106 | - break; |
|
| 2107 | - |
|
| 2108 | - case '64': |
|
| 2109 | - $options = get_option('wpshop_catalog_product_option'); |
|
| 2110 | - if (!empty($options['wpshop_catalog_product_slug_with_category'])) { |
|
| 2111 | - unset($options['wpshop_catalog_product_slug_with_category']); |
|
| 2112 | - update_option('wpshop_catalog_product_option', $options); |
|
| 2113 | - } |
|
| 2114 | - return true; |
|
| 2115 | - break; |
|
| 2116 | - |
|
| 2117 | - case '65': |
|
| 2118 | - $entity_id = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS); |
|
| 2119 | - $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE . ' WHERE code = %s AND entity_id = %d', 'company_customer', $entity_id); |
|
| 2120 | - $company_id = $wpdb->get_var($query); |
|
| 2121 | - if (!isset($company_id)) { |
|
| 2122 | - $wpdb->insert(WPSHOP_DBT_ATTRIBUTE, array( |
|
| 2123 | - 'is_visible_in_front' => 'no', |
|
| 2124 | - 'is_visible_in_front_listing' => 'yes', |
|
| 2125 | - 'is_global' => 'no', |
|
| 2126 | - 'is_user_defined' => 'no', |
|
| 2127 | - 'is_required' => 'no', |
|
| 2128 | - 'is_visible_in_advanced_search' => 'no', |
|
| 2129 | - 'is_searchable' => 'no', |
|
| 2130 | - 'is_filterable' => 'no', |
|
| 2131 | - 'is_comparable' => 'no', |
|
| 2132 | - 'is_html_allowed_on_front' => 'no', |
|
| 2133 | - 'is_unique' => 'no', |
|
| 2134 | - 'is_filterable_in_search' => 'no', |
|
| 2135 | - 'is_used_for_sort_by' => 'no', |
|
| 2136 | - 'is_configurable' => 'no', |
|
| 2137 | - 'is_requiring_unit' => 'no', |
|
| 2138 | - 'is_recordable_in_cart_meta' => 'no', |
|
| 2139 | - 'is_used_in_admin_listing_column' => 'no', |
|
| 2140 | - 'is_used_in_quick_add_form' => 'no', |
|
| 2141 | - 'is_used_for_variation' => 'no', |
|
| 2142 | - 'is_used_in_variation' => 'no', |
|
| 2143 | - '_display_informations_about_value' => 'no', |
|
| 2144 | - '_need_verification' => 'no', |
|
| 2145 | - '_unit_group_id' => null, |
|
| 2146 | - '_default_unit' => null, |
|
| 2147 | - 'is_historisable' => 'yes', |
|
| 2148 | - 'is_intrinsic' => 'no', |
|
| 2149 | - 'data_type_to_use' => 'custom', |
|
| 2150 | - 'use_ajax_for_filling_field' => 'no', |
|
| 2151 | - 'data_type' => 'varchar', |
|
| 2152 | - 'backend_table' => null, |
|
| 2153 | - 'backend_label' => 'Company', |
|
| 2154 | - 'backend_input' => 'text', |
|
| 2155 | - 'frontend_label' => 'Company', |
|
| 2156 | - 'frontend_input' => 'text', |
|
| 2157 | - 'frontend_verification' => null, |
|
| 2158 | - 'code' => 'company_customer', |
|
| 2159 | - 'note' => '', |
|
| 2160 | - 'default_value' => '', |
|
| 2161 | - 'frontend_css_class' => 'company_customer', |
|
| 2162 | - 'backend_css_class' => null, |
|
| 2163 | - 'frontend_help_message' => null, |
|
| 2164 | - 'entity_id' => $entity_id, |
|
| 2165 | - )); |
|
| 2166 | - $company_id = $wpdb->insert_id; |
|
| 2167 | - } |
|
| 2168 | - |
|
| 2169 | - $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE . ' WHERE code = %s AND entity_id = %d', 'is_provider', $entity_id); |
|
| 2170 | - $is_provider_id = $wpdb->get_var($query); |
|
| 2171 | - if (!isset($is_provider_id)) { |
|
| 2172 | - $wpdb->insert(WPSHOP_DBT_ATTRIBUTE, array( |
|
| 2173 | - 'is_visible_in_front' => 'no', |
|
| 2174 | - 'is_visible_in_front_listing' => 'yes', |
|
| 2175 | - 'is_global' => 'no', |
|
| 2176 | - 'is_user_defined' => 'no', |
|
| 2177 | - 'is_required' => 'yes', |
|
| 2178 | - 'is_visible_in_advanced_search' => 'no', |
|
| 2179 | - 'is_searchable' => 'no', |
|
| 2180 | - 'is_filterable' => 'no', |
|
| 2181 | - 'is_comparable' => 'no', |
|
| 2182 | - 'is_html_allowed_on_front' => 'no', |
|
| 2183 | - 'is_unique' => 'no', |
|
| 2184 | - 'is_filterable_in_search' => 'no', |
|
| 2185 | - 'is_used_for_sort_by' => 'no', |
|
| 2186 | - 'is_configurable' => 'no', |
|
| 2187 | - 'is_requiring_unit' => 'no', |
|
| 2188 | - 'is_recordable_in_cart_meta' => 'no', |
|
| 2189 | - 'is_used_in_admin_listing_column' => 'no', |
|
| 2190 | - 'is_used_in_quick_add_form' => 'no', |
|
| 2191 | - 'is_used_for_variation' => 'no', |
|
| 2192 | - 'is_used_in_variation' => 'no', |
|
| 2193 | - '_display_informations_about_value' => 'no', |
|
| 2194 | - '_need_verification' => 'no', |
|
| 2195 | - '_unit_group_id' => null, |
|
| 2196 | - '_default_unit' => null, |
|
| 2197 | - 'is_historisable' => 'yes', |
|
| 2198 | - 'is_intrinsic' => 'no', |
|
| 2199 | - 'data_type_to_use' => 'custom', |
|
| 2200 | - 'use_ajax_for_filling_field' => 'no', |
|
| 2201 | - 'data_type' => 'integer', |
|
| 2202 | - 'backend_table' => null, |
|
| 2203 | - 'backend_label' => 'Provider', |
|
| 2204 | - 'backend_input' => 'select', |
|
| 2205 | - 'frontend_label' => 'Provider', |
|
| 2206 | - 'frontend_input' => 'select', |
|
| 2207 | - 'frontend_verification' => null, |
|
| 2208 | - 'code' => 'is_provider', |
|
| 2209 | - 'note' => '', |
|
| 2210 | - 'default_value' => 'no', |
|
| 2211 | - 'frontend_css_class' => 'is_provider', |
|
| 2212 | - 'backend_css_class' => null, |
|
| 2213 | - 'frontend_help_message' => null, |
|
| 2214 | - 'entity_id' => $entity_id, |
|
| 2215 | - )); |
|
| 2216 | - $is_provider_id = $wpdb->insert_id; |
|
| 2217 | - $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS, array( |
|
| 2218 | - 'status' => 'valid', |
|
| 2219 | - 'attribute_id' => $is_provider_id, |
|
| 2220 | - 'creation_date_value' => current_time('mysql'), |
|
| 2221 | - 'value' => 'yes', |
|
| 2222 | - 'label' => 'Yes', |
|
| 2223 | - )); |
|
| 2224 | - $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS, array( |
|
| 2225 | - 'status' => 'valid', |
|
| 2226 | - 'attribute_id' => $is_provider_id, |
|
| 2227 | - 'creation_date_value' => current_time('mysql'), |
|
| 2228 | - 'value' => 'no', |
|
| 2229 | - 'label' => 'No', |
|
| 2230 | - )); |
|
| 2231 | - $default_value = $wpdb->insert_id; |
|
| 2232 | - $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('default_value' => $default_value), array('id' => $is_provider_id)); |
|
| 2233 | - } |
|
| 2234 | - |
|
| 2235 | - $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_DETAILS . ' WHERE attribute_id = %s', $company_id); |
|
| 2236 | - $company_section_detail_id = $wpdb->get_var($query); |
|
| 2237 | - |
|
| 2238 | - $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_DETAILS . ' WHERE attribute_id = %s', $is_provider_id); |
|
| 2239 | - $is_provider_section_detail_id = $wpdb->get_var($query); |
|
| 2240 | - |
|
| 2241 | - if (!isset($is_provider_section_detail_id) || !isset($company_section_detail_id)) { |
|
| 2242 | - $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE entity_id = %d', $entity_id); |
|
| 2243 | - $attribute_set_id = $wpdb->get_var($query); |
|
| 2244 | - |
|
| 2245 | - $query = $wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE_GROUP . " WHERE attribute_set_id = %d AND code = LOWER(%s)", $attribute_set_id, 'account'); |
|
| 2246 | - $attribute_set_section_id = $wpdb->get_var($query); |
|
| 2247 | - |
|
| 2248 | - $query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_DETAILS . ' WHERE entity_type_id = %d AND attribute_set_id = %d AND attribute_group_id = %d', $entity_id, $attribute_set_id, $attribute_set_section_id); |
|
| 2249 | - $attributes_set_details = $wpdb->get_results($query); |
|
| 2250 | - $set_details_id_postion_order = array(); |
|
| 2251 | - foreach ($attributes_set_details as $attribute_set_detail) { |
|
| 2252 | - $query = $wpdb->prepare('SELECT code FROM ' . WPSHOP_DBT_ATTRIBUTE . ' WHERE id = %d', $attribute_set_detail->attribute_id); |
|
| 2253 | - $attribute_set_detail_code = $wpdb->get_var($query); |
|
| 2254 | - if ($attribute_set_detail_code == 'last_name') { |
|
| 2255 | - $set_details_id_postion_order[1] = $attribute_set_detail->attribute_id; |
|
| 2256 | - } |
|
| 2257 | - if ($attribute_set_detail_code == 'first_name') { |
|
| 2258 | - $set_details_id_postion_order[2] = $attribute_set_detail->attribute_id; |
|
| 2259 | - } |
|
| 2260 | - if ($attribute_set_detail_code == 'user_email') { |
|
| 2261 | - $set_details_id_postion_order[3] = $attribute_set_detail->attribute_id; |
|
| 2262 | - } |
|
| 2263 | - if ($attribute_set_detail_code == 'user_pass') { |
|
| 2264 | - $set_details_id_postion_order[4] = $attribute_set_detail->attribute_id; |
|
| 2265 | - } |
|
| 2266 | - } |
|
| 2267 | - $max_position = count($set_details_id_postion_order); |
|
| 1821 | + return true; |
|
| 1822 | + break; |
|
| 2268 | 1823 | |
| 2269 | - if (!isset($company_section_detail_id)) { |
|
| 2270 | - $max_position = $max_position + 1; |
|
| 2271 | - $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'entity_type_id' => $entity_id, 'attribute_set_id' => $attribute_set_id, 'attribute_group_id' => $attribute_set_section_id, 'attribute_id' => $company_id, 'position' => (int) $max_position)); |
|
| 2272 | - $set_details_id_postion_order[$max_position] = $company_id; |
|
| 2273 | - $company_section_detail_id = $wpdb->insert_id; |
|
| 2274 | - } |
|
| 1824 | + case '45': |
|
| 1825 | + $shipping_mode_ctr = new wps_shipping_mode_ctr(); |
|
| 1826 | + $shipping_mode_ctr->migrate_default_shipping_mode(); |
|
| 1827 | + return true; |
|
| 1828 | + break; |
|
| 2275 | 1829 | |
| 2276 | - if (!isset($is_provider_section_detail_id)) { |
|
| 2277 | - $max_position = $max_position + 1; |
|
| 2278 | - $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'entity_type_id' => $entity_id, 'attribute_set_id' => $attribute_set_id, 'attribute_group_id' => $attribute_set_section_id, 'attribute_id' => $is_provider_id, 'position' => (int) $max_position)); |
|
| 2279 | - $set_details_id_postion_order[$max_position] = $is_provider_id; |
|
| 2280 | - $is_provider_section_detail_id = $wpdb->insert_id; |
|
| 2281 | - } |
|
| 1830 | + case '46': |
|
| 1831 | + wps_message_ctr::createMessage('WPSHOP_FORGOT_PASSWORD_MESSAGE'); |
|
| 1832 | + wps_message_ctr::customize_message(WPSHOP_FORGOT_PASSWORD_MESSAGE); |
|
| 1833 | + return true; |
|
| 1834 | + break; |
|
| 2282 | 1835 | |
| 2283 | - foreach ($set_details_id_postion_order as $pos => $attr_id) { |
|
| 2284 | - $wpdb->update(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('position' => $pos), array('attribute_id' => $attr_id, 'attribute_set_id' => $attribute_set_id, 'entity_type_id' => $entity_id, 'attribute_group_id' => $attribute_set_section_id), array('%d'), array('%d', '%d', '%d', '%d')); |
|
| 2285 | - } |
|
| 2286 | - } |
|
| 2287 | - |
|
| 2288 | - $wpdb->update(WPSHOP_DBT_ATTRIBUTE_SET, array('name' => __('Free product', 'wpshop'), 'slug' => 'free_product'), array('name' => 'free_product'), array('%s', '%s'), array('%s')); |
|
| 2289 | - |
|
| 2290 | - return true; |
|
| 2291 | - break; |
|
| 2292 | - |
|
| 2293 | - case 66: |
|
| 2294 | - $price_behaviour_entity_id = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT); |
|
| 2295 | - $wpdb->insert(WPSHOP_DBT_ATTRIBUTE, array( |
|
| 2296 | - 'is_visible_in_front' => 'no', |
|
| 2297 | - 'is_visible_in_front_listing' => 'yes', |
|
| 2298 | - 'is_global' => 'no', |
|
| 2299 | - 'is_user_defined' => 'no', |
|
| 2300 | - 'is_required' => 'no', |
|
| 2301 | - 'is_visible_in_advanced_search' => 'no', |
|
| 2302 | - 'is_searchable' => 'no', |
|
| 2303 | - 'is_filterable' => 'no', |
|
| 2304 | - 'is_comparable' => 'no', |
|
| 2305 | - 'is_html_allowed_on_front' => 'no', |
|
| 2306 | - 'is_unique' => 'no', |
|
| 2307 | - 'is_filterable_in_search' => 'no', |
|
| 2308 | - 'is_used_for_sort_by' => 'no', |
|
| 2309 | - 'is_configurable' => 'no', |
|
| 2310 | - 'is_requiring_unit' => 'no', |
|
| 2311 | - 'is_recordable_in_cart_meta' => 'no', |
|
| 2312 | - 'is_used_in_admin_listing_column' => 'no', |
|
| 2313 | - 'is_used_in_quick_add_form' => 'no', |
|
| 2314 | - 'is_used_for_variation' => 'no', |
|
| 2315 | - 'is_used_in_variation' => 'yes', |
|
| 2316 | - '_display_informations_about_value' => 'no', |
|
| 2317 | - '_need_verification' => 'no', |
|
| 2318 | - '_unit_group_id' => null, |
|
| 2319 | - '_default_unit' => null, |
|
| 2320 | - 'is_historisable' => 'yes', |
|
| 2321 | - 'is_intrinsic' => 'no', |
|
| 2322 | - 'data_type_to_use' => 'custom', |
|
| 2323 | - 'use_ajax_for_filling_field' => 'no', |
|
| 2324 | - 'data_type' => 'integer', |
|
| 2325 | - 'backend_table' => null, |
|
| 2326 | - 'backend_label' => null, |
|
| 2327 | - 'backend_input' => 'select', |
|
| 2328 | - 'frontend_label' => 'price_behaviour', |
|
| 2329 | - 'frontend_input' => 'select', |
|
| 2330 | - 'frontend_verification' => null, |
|
| 2331 | - 'code' => 'price_behaviour', |
|
| 2332 | - 'note' => '', |
|
| 2333 | - 'default_value' => '', |
|
| 2334 | - 'frontend_css_class' => 'price_behaviour', |
|
| 2335 | - 'backend_css_class' => null, |
|
| 2336 | - 'frontend_help_message' => null, |
|
| 2337 | - 'entity_id' => $price_behaviour_entity_id, |
|
| 2338 | - )); |
|
| 2339 | - $price_behaviour = $wpdb->insert_id; |
|
| 2340 | - $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS, array( |
|
| 2341 | - 'status' => 'valid', |
|
| 2342 | - 'attribute_id' => $price_behaviour, |
|
| 2343 | - 'creation_date' => current_time('mysql'), |
|
| 2344 | - 'value' => '+', |
|
| 2345 | - 'label' => '+', |
|
| 2346 | - )); |
|
| 2347 | - $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS, array( |
|
| 2348 | - 'status' => 'valid', |
|
| 2349 | - 'attribute_id' => $price_behaviour, |
|
| 2350 | - 'creation_date' => current_time('mysql'), |
|
| 2351 | - 'value' => '=', |
|
| 2352 | - 'label' => '=', |
|
| 2353 | - )); |
|
| 2354 | - $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE entity_id = %d AND ( name = %s OR slug = %s )', $price_behaviour_entity_id, 'default', 'default'); |
|
| 2355 | - $price_behaviour_section_id = $wpdb->get_var($query); |
|
| 2356 | - $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_GROUP . ' WHERE attribute_set_id = %d AND code = %s', $price_behaviour_section_id, 'prices'); |
|
| 2357 | - $price_behaviour_section_detail_id = $wpdb->get_var($query); |
|
| 2358 | - $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_DETAILS, array( |
|
| 2359 | - 'status' => 'deleted', |
|
| 2360 | - 'creation_date' => current_time('mysql', 0), |
|
| 2361 | - 'entity_type_id' => $price_behaviour_entity_id, |
|
| 2362 | - 'attribute_set_id' => $price_behaviour_section_id, |
|
| 2363 | - 'attribute_group_id' => $price_behaviour_section_detail_id, |
|
| 2364 | - 'attribute_id' => $price_behaviour, |
|
| 2365 | - 'position' => 0, |
|
| 2366 | - )); |
|
| 2367 | - $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('is_used_in_variation' => 'yes', 'last_update_date' => current_time('mysql', 0)), array('code' => 'is_downloadable_')); |
|
| 2368 | - $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('is_used_in_variation' => 'yes', 'last_update_date' => current_time('mysql', 0)), array('code' => 'tva')); |
|
| 2369 | - $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('is_used_in_variation' => 'yes', 'last_update_date' => current_time('mysql', 0)), array('code' => 'price_ht')); |
|
| 2370 | - $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('is_used_in_variation' => 'yes', 'last_update_date' => current_time('mysql', 0)), array('code' => 'product_stock')); |
|
| 2371 | - $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('is_used_in_variation' => 'yes', 'last_update_date' => current_time('mysql', 0)), array('code' => 'product_weight')); |
|
| 2372 | - return true; |
|
| 2373 | - break; |
|
| 2374 | - |
|
| 2375 | - case 67: |
|
| 2376 | - $admin_new_version_message = get_option('WPSHOP_NEW_VERSION_ADMIN_MESSAGE'); |
|
| 2377 | - if (empty($admin_new_version_message)) { |
|
| 2378 | - wps_message_ctr::createMessage('WPSHOP_NEW_VERSION_ADMIN_MESSAGE'); |
|
| 2379 | - } |
|
| 2380 | - $wpshop_cart_option = get_option('wpshop_cart_option'); |
|
| 2381 | - if (!empty($wpshop_cart_option) && !empty($wpshop_cart_option['total_nb_of_item_allowed'])) { |
|
| 2382 | - $wpshop_cart_option['total_nb_of_item_allowed'][0] = (int) filter_var($wpshop_cart_option['total_nb_of_item_allowed'][0], FILTER_VALIDATE_BOOLEAN); |
|
| 2383 | - } |
|
| 2384 | - update_option('wpshop_cart_option', $wpshop_cart_option); |
|
| 2385 | - return true; |
|
| 2386 | - break; |
|
| 1836 | + case '47': |
|
| 1837 | + wps_payment_mode::migrate_payment_modes(); |
|
| 1838 | + return true; |
|
| 1839 | + break; |
|
| 1840 | + |
|
| 1841 | + case '48': |
|
| 1842 | + @ini_set('max_execution_time', '500'); |
|
| 1843 | + |
|
| 1844 | + $count_products = wp_count_posts(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT); |
|
| 1845 | + $output_type_option = get_option('wpshop_display_option'); |
|
| 1846 | + $output_type = $output_type_option['wpshop_display_list_type']; |
|
| 1847 | + |
|
| 1848 | + for ($i = 0; $i <= $count_products->publish; $i += 20) { |
|
| 1849 | + $query = $wpdb->prepare('SELECT * FROM ' . $wpdb->posts . ' WHERE post_type = %s AND post_status = %s ORDER BY ID DESC LIMIT ' . $i . ', 20', WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, 'publish'); |
|
| 1850 | + $products = $wpdb->get_results($query); |
|
| 1851 | + if (!empty($products)) { |
|
| 1852 | + foreach ($products as $product) { |
|
| 1853 | + $p = wpshop_products::get_product_data($product->ID); |
|
| 1854 | + $price = wpshop_prices::get_product_price($p, 'just_price_infos', array('mini_output', $output_type)); |
|
| 1855 | + update_post_meta($product->ID, '_wps_price_infos', $price); |
|
| 1856 | + } |
|
| 1857 | + } |
|
| 1858 | + } |
|
| 1859 | + |
|
| 1860 | + return true; |
|
| 1861 | + break; |
|
| 1862 | + |
|
| 1863 | + case '49': |
|
| 1864 | + update_option('wpshop_send_invoice', true); |
|
| 1865 | + return true; |
|
| 1866 | + break; |
|
| 1867 | + |
|
| 1868 | + case '50': |
|
| 1869 | + $price_display_option = get_option('wpshop_catalog_product_option'); |
|
| 1870 | + $price_display_option['price_display']['text_from'] = 'on'; |
|
| 1871 | + $price_display_option['price_display']['lower_price'] = 'on'; |
|
| 1872 | + update_option('wpshop_catalog_product_option', $price_display_option); |
|
| 1873 | + |
|
| 1874 | + self::wpshop_insert_default_pages(); |
|
| 1875 | + |
|
| 1876 | + return true; |
|
| 1877 | + break; |
|
| 1878 | + |
|
| 1879 | + case '51': |
|
| 1880 | + /** Insert new message for direct payment link */ |
|
| 1881 | + $direct_payment_link_message = get_option('WPSHOP_DIRECT_PAYMENT_LINK_MESSAGE'); |
|
| 1882 | + if (empty($direct_payment_link_message)) { |
|
| 1883 | + wps_message_ctr::createMessage('WPSHOP_DIRECT_PAYMENT_LINK_MESSAGE'); |
|
| 1884 | + } |
|
| 1885 | + return true; |
|
| 1886 | + break; |
|
| 1887 | + |
|
| 1888 | + case '52': |
|
| 1889 | + $account_page_option = get_option('wpshop_myaccount_page_id'); |
|
| 1890 | + if (!empty($account_page_option)) { |
|
| 1891 | + $page_account = get_post($account_page_option); |
|
| 1892 | + $page_content = (!empty($page_account) && !empty($page_account->post_content)) ? str_replace('[wpshop_myaccount]', '[wps_account_dashboard]', $page_account->post_content) : '[wps_account_dashboard]'; |
|
| 1893 | + wp_update_post(array('ID' => $account_page_option, 'post_content' => $page_content)); |
|
| 1894 | + } |
|
| 1895 | + return true; |
|
| 1896 | + break; |
|
| 1897 | + |
|
| 1898 | + case '53': |
|
| 1899 | + $payment_modes_option = get_option('wps_payment_mode'); |
|
| 1900 | + if (!empty($payment_modes_option) && !empty($payment_modes_option['mode'])) { |
|
| 1901 | + $payment_modes_option['mode']['cash_on_delivery'] = array( |
|
| 1902 | + 'name' => __('Cash on delivery', 'wpshop'), |
|
| 1903 | + 'logo' => WPSHOP_TEMPLATES_URL . 'wpshop/cheque.png', |
|
| 1904 | + 'description' => __('Pay your order on delivery', 'wpshop')); |
|
| 1905 | + |
|
| 1906 | + update_option('wps_payment_mode', $payment_modes_option); |
|
| 1907 | + } |
|
| 1908 | + |
|
| 1909 | + // Mass action on products to add a flag on variation definition |
|
| 1910 | + $products = get_posts(array('posts_per_page' => -1, 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT)); |
|
| 1911 | + if (!empty($products)) { |
|
| 1912 | + foreach ($products as $p) { |
|
| 1913 | + $post_id = $p->ID; |
|
| 1914 | + $check_product_have_variations = wpshop_products::get_variation($post_id); |
|
| 1915 | + if (!empty($check_product_have_variations)) { |
|
| 1916 | + $variation_flag = wpshop_products::check_variation_type($post_id); |
|
| 1917 | + $variation_defining = get_post_meta($post_id, '_wpshop_variation_defining', true); |
|
| 1918 | + $variation_defining['variation_type'] = $variation_flag; |
|
| 1919 | + update_post_meta($post_id, '_wpshop_variation_defining', $variation_defining); |
|
| 1920 | + } |
|
| 1921 | + } |
|
| 1922 | + } |
|
| 1923 | + return true; |
|
| 1924 | + break; |
|
| 1925 | + |
|
| 1926 | + case '54': |
|
| 1927 | + // Change shortcode of sign up page |
|
| 1928 | + $signup_page_id = get_option('wpshop_signup_page_id'); |
|
| 1929 | + if (!empty($signup_page_id)) { |
|
| 1930 | + $signup_page = get_post($signup_page_id); |
|
| 1931 | + $signup_page_content = (!empty($signup_page) && !empty($signup_page->post_content)) ? str_replace('[wpshop_signup]', '[wps_account_dashboard]', $signup_page->post_content) : '[wps_account_dashboard]'; |
|
| 1932 | + wp_update_post(array('ID' => $signup_page_id, 'post_content' => $signup_page_content)); |
|
| 1933 | + } |
|
| 1934 | + |
|
| 1935 | + // Change Terms of sale default content |
|
| 1936 | + $terms_page_id = get_option('wpshop_terms_of_sale_page_id'); |
|
| 1937 | + if (!empty($terms_page_id)) { |
|
| 1938 | + $terms_sale_page = get_post($terms_page_id); |
|
| 1939 | + if (!empty($terms_sale_page) && !empty($terms_sale_page->post_content) && $terms_sale_page->post_content == '[wpshop_terms_of_sale]') { |
|
| 1940 | + $data = '<h1>' . __('Your terms of sale', 'wpshop') . '</h1>'; |
|
| 1941 | + $data .= '<h3>' . __('Rule', 'wpshop') . ' 1</h3>'; |
|
| 1942 | + $data .= '<p>Ut enim quisque sibi plurimum confidit et ut quisque maxime virtute et sapientia sic munitus est, ut nullo egeat suaque omnia in se ipso posita iudicet, ita in amicitiis expetendis colendisque maxime excellit.</p>'; |
|
| 1943 | + $data .= '<h3>' . __('Rule', 'wpshop') . ' 2</h3>'; |
|
| 1944 | + $data .= '<p>Ut enim quisque sibi plurimum confidit et ut quisque maxime virtute et sapientia sic munitus est, ut nullo egeat suaque omnia in se ipso posita iudicet, ita in amicitiis expetendis colendisque maxime excellit.</p>'; |
|
| 1945 | + $data .= '<h3>' . __('Rule', 'wpshop') . ' 3</h3>'; |
|
| 1946 | + $data .= '<p>Ut enim quisque sibi plurimum confidit et ut quisque maxime virtute et sapientia sic munitus est, ut nullo egeat suaque omnia in se ipso posita iudicet, ita in amicitiis expetendis colendisque maxime excellit.</p>'; |
|
| 1947 | + $data .= '<h3>' . __('Credits', 'wpshop') . '</h3>'; |
|
| 1948 | + $data .= sprintf(__('%s uses <a href="http://www.wpshop.fr/" target="_blank" title="%s uses WPShop e-commerce plug-in for Wordpress">WPShop e-commerce for Wordpress</a>', 'wpshop'), get_bloginfo('name'), get_bloginfo('name')); |
|
| 1949 | + wp_update_post(array('ID' => $terms_page_id, 'post_content' => $data)); |
|
| 1950 | + } |
|
| 1951 | + } |
|
| 1952 | + |
|
| 1953 | + return true; |
|
| 1954 | + break; |
|
| 1955 | + |
|
| 1956 | + case '55': |
|
| 1957 | + $checkout_page_id = get_option('wpshop_checkout_page_id'); |
|
| 1958 | + $checkout_page = get_post($checkout_page_id); |
|
| 1959 | + $checkout_page_content = (!empty($checkout_page) && !empty($checkout_page->post_content)) ? str_replace('[wpshop_checkout]', '[wps_checkout]', $checkout_page->post_content) : '[wps_checkout]'; |
|
| 1960 | + wp_update_post(array('ID' => $checkout_page_id, 'post_content' => $checkout_page_content)); |
|
| 1961 | + |
|
| 1962 | + // Update cart page id |
|
| 1963 | + update_option('wpshop_cart_page_id', $checkout_page_id); |
|
| 1964 | + return true; |
|
| 1965 | + break; |
|
| 1966 | + |
|
| 1967 | + case '56': |
|
| 1968 | + $wps_entities = new wpshop_entities(); |
|
| 1969 | + $customer_entity_id = $wps_entities->get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS); |
|
| 1970 | + $query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE entity_id = %d ORDER BY id LIMIT 1', $customer_entity_id); |
|
| 1971 | + $set = $wpdb->get_row($query); |
|
| 1972 | + if (!empty($set)) { |
|
| 1973 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE_SET, |
|
| 1974 | + array('default_set' => 'yes'), |
|
| 1975 | + array('id' => $set->id)); |
|
| 1976 | + } |
|
| 1977 | + // Update Opinions activation option |
|
| 1978 | + update_option('wps_opinion', array('active' => 'on')); |
|
| 1979 | + return true; |
|
| 1980 | + break; |
|
| 1981 | + |
|
| 1982 | + case '57': |
|
| 1983 | + $wpshop_cart_option = get_option('wpshop_cart_option'); |
|
| 1984 | + $wpshop_cart_option['display_newsletter']['site_subscription'][] = 'yes'; |
|
| 1985 | + $wpshop_cart_option['display_newsletter']['partner_subscription'][] = 'yes'; |
|
| 1986 | + |
|
| 1987 | + update_option('wpshop_cart_option', $wpshop_cart_option); |
|
| 1988 | + return true; |
|
| 1989 | + break; |
|
| 1990 | + |
|
| 1991 | + case '58': |
|
| 1992 | + /** Turn customers publish into draft **/ |
|
| 1993 | + $query = $wpdb->prepare("UPDATE {$wpdb->posts} SET post_status = %s WHERE post_type = %s", "draft", WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS); |
|
| 1994 | + $wpdb->query($query); |
|
| 1995 | + |
|
| 1996 | + $attribute_def = wpshop_attributes::getElement('tx_tva', "'valid'", 'code'); |
|
| 1997 | + /** Check if the 0% VAT Rate is not already created **/ |
|
| 1998 | + $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE attribute_id = %d AND value = %s', $attribute_def->id, '0'); |
|
| 1999 | + $exist_vat_rate = $wpdb->get_results($query); |
|
| 2000 | + |
|
| 2001 | + if (empty($exist_vat_rate)) { |
|
| 2002 | + /** Get Max Position **/ |
|
| 2003 | + $query = $wpdb->prepare('SELECT MAX(position) as max_position FROM ' . WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS . ' WHERE attribute_id = %d', $attribute_def->id); |
|
| 2004 | + $max_position = $wpdb->get_var($query); |
|
| 2005 | + |
|
| 2006 | + if (!empty($attribute_def) && !empty($attribute_def->id)) { |
|
| 2007 | + $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS, array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'attribute_id' => $attribute_def->id, 'position' => (int) $max_position + 1, 'value' => '0', 'label' => '0')); |
|
| 2008 | + } |
|
| 2009 | + } |
|
| 2010 | + return true; |
|
| 2011 | + break; |
|
| 2012 | + |
|
| 2013 | + case '59': |
|
| 2014 | + /** Move old images gallery to the new gallery, and remove old links **/ |
|
| 2015 | + $allowed = get_allowed_mime_types(); |
|
| 2016 | + $args = array( |
|
| 2017 | + 'posts_per_page' => -1, |
|
| 2018 | + 'post_type' => WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT, |
|
| 2019 | + 'post_status' => array('publish', 'draft', 'trash'), |
|
| 2020 | + ); |
|
| 2021 | + $posts = get_posts($args); |
|
| 2022 | + $result = array(); |
|
| 2023 | + foreach ($posts as $post) { |
|
| 2024 | + $array = array(); |
|
| 2025 | + $array['Post'] = $post; |
|
| 2026 | + $array['PrincipalThumbnailID'] = get_post_meta($post->ID, '_thumbnail_id', true); |
|
| 2027 | + $array['Attachments'] = get_attached_media($allowed, $post->ID); |
|
| 2028 | + $array['TrueAttachmentsString'] = get_post_meta($post->ID, '_wps_product_media', true); |
|
| 2029 | + if (!empty($array['TrueAttachmentsString'])) { |
|
| 2030 | + $TrueAttachments_id = explode(',', $array['TrueAttachmentsString']); |
|
| 2031 | + } |
|
| 2032 | + $array['OldAttachmentsString'] = ''; |
|
| 2033 | + foreach ($array['Attachments'] as $attachment) { |
|
| 2034 | + $filename = basename(get_attached_file($attachment->ID)); |
|
| 2035 | + $pos_ext = strrpos($filename, '.'); |
|
| 2036 | + $filename_no_ext = substr($filename, 0, $pos_ext); |
|
| 2037 | + if ((empty($TrueAttachments_id) || !in_array($attachment->ID, $TrueAttachments_id)) && !(preg_match('#' . $filename_no_ext . '#', $post->post_content)) && ((empty($array['PrincipalThumbnailID']) || $attachment->ID != $array['PrincipalThumbnailID']))) { |
|
| 2038 | + $array['OldAttachmentsString'] .= $attachment->ID . ','; |
|
| 2039 | + } |
|
| 2040 | + } |
|
| 2041 | + unset($TrueAttachments_id); |
|
| 2042 | + $result[$post->ID] = $array['TrueAttachmentsString'] . $array['OldAttachmentsString']; |
|
| 2043 | + update_post_meta($post->ID, '_wps_product_media', $result[$post->ID]); |
|
| 2044 | + } |
|
| 2045 | + return true; |
|
| 2046 | + break; |
|
| 2047 | + |
|
| 2048 | + case '60': |
|
| 2049 | + /* Create default emails */ |
|
| 2050 | + wps_message_ctr::create_default_message(); |
|
| 2051 | + |
|
| 2052 | + /** Update entries for quick add */ |
|
| 2053 | + $query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_required = "yes", is_used_in_quick_add_form = "yes" WHERE code = "barcode"'); |
|
| 2054 | + $query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_used_in_quick_add_form = "yes" WHERE code = "product_stock"'); |
|
| 2055 | + $query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_used_in_quick_add_form = "yes" WHERE code = "manage_stock"'); |
|
| 2056 | + switch (WPSHOP_PRODUCT_PRICE_PILOT) { |
|
| 2057 | + case 'HT': |
|
| 2058 | + $query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_used_in_quick_add_form = "yes", is_used_in_variation = "yes" WHERE code = "price_ht"'); |
|
| 2059 | + $query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_used_in_quick_add_form = "no" WHERE code = "tx_tva"'); |
|
| 2060 | + $query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_used_in_quick_add_form = "no", is_used_in_variation = "no" WHERE code = "product_price"'); |
|
| 2061 | + break; |
|
| 2062 | + default: |
|
| 2063 | + $query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_used_in_quick_add_form = "yes", is_used_in_variation = "yes" WHERE code = "product_price"'); |
|
| 2064 | + $query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_used_in_quick_add_form = "yes" WHERE code = "tx_tva"'); |
|
| 2065 | + $query = $wpdb->query('UPDATE ' . WPSHOP_DBT_ATTRIBUTE . ' SET is_used_in_quick_add_form = "no", is_used_in_variation = "no" WHERE code = "price_ht"'); |
|
| 2066 | + break; |
|
| 2067 | + } |
|
| 2068 | + |
|
| 2069 | + /* Default country with WP language */ |
|
| 2070 | + $wpshop_country_default_choice_option = get_option('wpshop_country_default_choice'); |
|
| 2071 | + if (empty($wpshop_country_default_choice_option)) { |
|
| 2072 | + update_option('wpshop_country_default_choice', substr(get_bloginfo('language'), 3)); |
|
| 2073 | + } |
|
| 2074 | + return true; |
|
| 2075 | + break; |
|
| 2076 | + |
|
| 2077 | + case '61': |
|
| 2078 | + /** Import the xml for guided tour */ |
|
| 2079 | + wpsBubble_ctr::import_xml(); |
|
| 2080 | + |
|
| 2081 | + /* Hide admin bar */ |
|
| 2082 | + $wpshop_display_option = get_option('wpshop_display_option'); |
|
| 2083 | + if (!empty($wpshop_display_option) && empty($wpshop_display_option['wpshop_hide_admin_bar'])) { |
|
| 2084 | + $wpshop_display_option['wpshop_hide_admin_bar'] = 'on'; |
|
| 2085 | + update_option('wpshop_display_option', $wpshop_display_option); |
|
| 2086 | + } |
|
| 2087 | + |
|
| 2088 | + return true; |
|
| 2089 | + break; |
|
| 2090 | + |
|
| 2091 | + case '62': |
|
| 2092 | + /** Install user default for POS */ |
|
| 2093 | + wps_pos_addon::action_to_do_on_activation(); |
|
| 2094 | + |
|
| 2095 | + return true; |
|
| 2096 | + break; |
|
| 2097 | + |
|
| 2098 | + case '63': |
|
| 2099 | + $data = get_option('wps_shipping_mode'); |
|
| 2100 | + if (empty($data['modes']['default_shipping_mode_for_pos'])) { |
|
| 2101 | + $data['modes']['default_shipping_mode_for_pos']['name'] = __('No Delivery', 'wpshop'); |
|
| 2102 | + $data['modes']['default_shipping_mode_for_pos']['explanation'] = __('Delivery method for point of sale.', 'wpshop'); |
|
| 2103 | + update_option('wps_shipping_mode', $data); |
|
| 2104 | + } |
|
| 2105 | + return true; |
|
| 2106 | + break; |
|
| 2107 | + |
|
| 2108 | + case '64': |
|
| 2109 | + $options = get_option('wpshop_catalog_product_option'); |
|
| 2110 | + if (!empty($options['wpshop_catalog_product_slug_with_category'])) { |
|
| 2111 | + unset($options['wpshop_catalog_product_slug_with_category']); |
|
| 2112 | + update_option('wpshop_catalog_product_option', $options); |
|
| 2113 | + } |
|
| 2114 | + return true; |
|
| 2115 | + break; |
|
| 2116 | + |
|
| 2117 | + case '65': |
|
| 2118 | + $entity_id = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_CUSTOMERS); |
|
| 2119 | + $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE . ' WHERE code = %s AND entity_id = %d', 'company_customer', $entity_id); |
|
| 2120 | + $company_id = $wpdb->get_var($query); |
|
| 2121 | + if (!isset($company_id)) { |
|
| 2122 | + $wpdb->insert(WPSHOP_DBT_ATTRIBUTE, array( |
|
| 2123 | + 'is_visible_in_front' => 'no', |
|
| 2124 | + 'is_visible_in_front_listing' => 'yes', |
|
| 2125 | + 'is_global' => 'no', |
|
| 2126 | + 'is_user_defined' => 'no', |
|
| 2127 | + 'is_required' => 'no', |
|
| 2128 | + 'is_visible_in_advanced_search' => 'no', |
|
| 2129 | + 'is_searchable' => 'no', |
|
| 2130 | + 'is_filterable' => 'no', |
|
| 2131 | + 'is_comparable' => 'no', |
|
| 2132 | + 'is_html_allowed_on_front' => 'no', |
|
| 2133 | + 'is_unique' => 'no', |
|
| 2134 | + 'is_filterable_in_search' => 'no', |
|
| 2135 | + 'is_used_for_sort_by' => 'no', |
|
| 2136 | + 'is_configurable' => 'no', |
|
| 2137 | + 'is_requiring_unit' => 'no', |
|
| 2138 | + 'is_recordable_in_cart_meta' => 'no', |
|
| 2139 | + 'is_used_in_admin_listing_column' => 'no', |
|
| 2140 | + 'is_used_in_quick_add_form' => 'no', |
|
| 2141 | + 'is_used_for_variation' => 'no', |
|
| 2142 | + 'is_used_in_variation' => 'no', |
|
| 2143 | + '_display_informations_about_value' => 'no', |
|
| 2144 | + '_need_verification' => 'no', |
|
| 2145 | + '_unit_group_id' => null, |
|
| 2146 | + '_default_unit' => null, |
|
| 2147 | + 'is_historisable' => 'yes', |
|
| 2148 | + 'is_intrinsic' => 'no', |
|
| 2149 | + 'data_type_to_use' => 'custom', |
|
| 2150 | + 'use_ajax_for_filling_field' => 'no', |
|
| 2151 | + 'data_type' => 'varchar', |
|
| 2152 | + 'backend_table' => null, |
|
| 2153 | + 'backend_label' => 'Company', |
|
| 2154 | + 'backend_input' => 'text', |
|
| 2155 | + 'frontend_label' => 'Company', |
|
| 2156 | + 'frontend_input' => 'text', |
|
| 2157 | + 'frontend_verification' => null, |
|
| 2158 | + 'code' => 'company_customer', |
|
| 2159 | + 'note' => '', |
|
| 2160 | + 'default_value' => '', |
|
| 2161 | + 'frontend_css_class' => 'company_customer', |
|
| 2162 | + 'backend_css_class' => null, |
|
| 2163 | + 'frontend_help_message' => null, |
|
| 2164 | + 'entity_id' => $entity_id, |
|
| 2165 | + )); |
|
| 2166 | + $company_id = $wpdb->insert_id; |
|
| 2167 | + } |
|
| 2168 | + |
|
| 2169 | + $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE . ' WHERE code = %s AND entity_id = %d', 'is_provider', $entity_id); |
|
| 2170 | + $is_provider_id = $wpdb->get_var($query); |
|
| 2171 | + if (!isset($is_provider_id)) { |
|
| 2172 | + $wpdb->insert(WPSHOP_DBT_ATTRIBUTE, array( |
|
| 2173 | + 'is_visible_in_front' => 'no', |
|
| 2174 | + 'is_visible_in_front_listing' => 'yes', |
|
| 2175 | + 'is_global' => 'no', |
|
| 2176 | + 'is_user_defined' => 'no', |
|
| 2177 | + 'is_required' => 'yes', |
|
| 2178 | + 'is_visible_in_advanced_search' => 'no', |
|
| 2179 | + 'is_searchable' => 'no', |
|
| 2180 | + 'is_filterable' => 'no', |
|
| 2181 | + 'is_comparable' => 'no', |
|
| 2182 | + 'is_html_allowed_on_front' => 'no', |
|
| 2183 | + 'is_unique' => 'no', |
|
| 2184 | + 'is_filterable_in_search' => 'no', |
|
| 2185 | + 'is_used_for_sort_by' => 'no', |
|
| 2186 | + 'is_configurable' => 'no', |
|
| 2187 | + 'is_requiring_unit' => 'no', |
|
| 2188 | + 'is_recordable_in_cart_meta' => 'no', |
|
| 2189 | + 'is_used_in_admin_listing_column' => 'no', |
|
| 2190 | + 'is_used_in_quick_add_form' => 'no', |
|
| 2191 | + 'is_used_for_variation' => 'no', |
|
| 2192 | + 'is_used_in_variation' => 'no', |
|
| 2193 | + '_display_informations_about_value' => 'no', |
|
| 2194 | + '_need_verification' => 'no', |
|
| 2195 | + '_unit_group_id' => null, |
|
| 2196 | + '_default_unit' => null, |
|
| 2197 | + 'is_historisable' => 'yes', |
|
| 2198 | + 'is_intrinsic' => 'no', |
|
| 2199 | + 'data_type_to_use' => 'custom', |
|
| 2200 | + 'use_ajax_for_filling_field' => 'no', |
|
| 2201 | + 'data_type' => 'integer', |
|
| 2202 | + 'backend_table' => null, |
|
| 2203 | + 'backend_label' => 'Provider', |
|
| 2204 | + 'backend_input' => 'select', |
|
| 2205 | + 'frontend_label' => 'Provider', |
|
| 2206 | + 'frontend_input' => 'select', |
|
| 2207 | + 'frontend_verification' => null, |
|
| 2208 | + 'code' => 'is_provider', |
|
| 2209 | + 'note' => '', |
|
| 2210 | + 'default_value' => 'no', |
|
| 2211 | + 'frontend_css_class' => 'is_provider', |
|
| 2212 | + 'backend_css_class' => null, |
|
| 2213 | + 'frontend_help_message' => null, |
|
| 2214 | + 'entity_id' => $entity_id, |
|
| 2215 | + )); |
|
| 2216 | + $is_provider_id = $wpdb->insert_id; |
|
| 2217 | + $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS, array( |
|
| 2218 | + 'status' => 'valid', |
|
| 2219 | + 'attribute_id' => $is_provider_id, |
|
| 2220 | + 'creation_date_value' => current_time('mysql'), |
|
| 2221 | + 'value' => 'yes', |
|
| 2222 | + 'label' => 'Yes', |
|
| 2223 | + )); |
|
| 2224 | + $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS, array( |
|
| 2225 | + 'status' => 'valid', |
|
| 2226 | + 'attribute_id' => $is_provider_id, |
|
| 2227 | + 'creation_date_value' => current_time('mysql'), |
|
| 2228 | + 'value' => 'no', |
|
| 2229 | + 'label' => 'No', |
|
| 2230 | + )); |
|
| 2231 | + $default_value = $wpdb->insert_id; |
|
| 2232 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('default_value' => $default_value), array('id' => $is_provider_id)); |
|
| 2233 | + } |
|
| 2234 | + |
|
| 2235 | + $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_DETAILS . ' WHERE attribute_id = %s', $company_id); |
|
| 2236 | + $company_section_detail_id = $wpdb->get_var($query); |
|
| 2237 | + |
|
| 2238 | + $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_DETAILS . ' WHERE attribute_id = %s', $is_provider_id); |
|
| 2239 | + $is_provider_section_detail_id = $wpdb->get_var($query); |
|
| 2240 | + |
|
| 2241 | + if (!isset($is_provider_section_detail_id) || !isset($company_section_detail_id)) { |
|
| 2242 | + $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE entity_id = %d', $entity_id); |
|
| 2243 | + $attribute_set_id = $wpdb->get_var($query); |
|
| 2244 | + |
|
| 2245 | + $query = $wpdb->prepare("SELECT id FROM " . WPSHOP_DBT_ATTRIBUTE_GROUP . " WHERE attribute_set_id = %d AND code = LOWER(%s)", $attribute_set_id, 'account'); |
|
| 2246 | + $attribute_set_section_id = $wpdb->get_var($query); |
|
| 2247 | + |
|
| 2248 | + $query = $wpdb->prepare('SELECT * FROM ' . WPSHOP_DBT_ATTRIBUTE_DETAILS . ' WHERE entity_type_id = %d AND attribute_set_id = %d AND attribute_group_id = %d', $entity_id, $attribute_set_id, $attribute_set_section_id); |
|
| 2249 | + $attributes_set_details = $wpdb->get_results($query); |
|
| 2250 | + $set_details_id_postion_order = array(); |
|
| 2251 | + foreach ($attributes_set_details as $attribute_set_detail) { |
|
| 2252 | + $query = $wpdb->prepare('SELECT code FROM ' . WPSHOP_DBT_ATTRIBUTE . ' WHERE id = %d', $attribute_set_detail->attribute_id); |
|
| 2253 | + $attribute_set_detail_code = $wpdb->get_var($query); |
|
| 2254 | + if ($attribute_set_detail_code == 'last_name') { |
|
| 2255 | + $set_details_id_postion_order[1] = $attribute_set_detail->attribute_id; |
|
| 2256 | + } |
|
| 2257 | + if ($attribute_set_detail_code == 'first_name') { |
|
| 2258 | + $set_details_id_postion_order[2] = $attribute_set_detail->attribute_id; |
|
| 2259 | + } |
|
| 2260 | + if ($attribute_set_detail_code == 'user_email') { |
|
| 2261 | + $set_details_id_postion_order[3] = $attribute_set_detail->attribute_id; |
|
| 2262 | + } |
|
| 2263 | + if ($attribute_set_detail_code == 'user_pass') { |
|
| 2264 | + $set_details_id_postion_order[4] = $attribute_set_detail->attribute_id; |
|
| 2265 | + } |
|
| 2266 | + } |
|
| 2267 | + $max_position = count($set_details_id_postion_order); |
|
| 2268 | + |
|
| 2269 | + if (!isset($company_section_detail_id)) { |
|
| 2270 | + $max_position = $max_position + 1; |
|
| 2271 | + $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'entity_type_id' => $entity_id, 'attribute_set_id' => $attribute_set_id, 'attribute_group_id' => $attribute_set_section_id, 'attribute_id' => $company_id, 'position' => (int) $max_position)); |
|
| 2272 | + $set_details_id_postion_order[$max_position] = $company_id; |
|
| 2273 | + $company_section_detail_id = $wpdb->insert_id; |
|
| 2274 | + } |
|
| 2275 | + |
|
| 2276 | + if (!isset($is_provider_section_detail_id)) { |
|
| 2277 | + $max_position = $max_position + 1; |
|
| 2278 | + $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('status' => 'valid', 'creation_date' => current_time('mysql', 0), 'entity_type_id' => $entity_id, 'attribute_set_id' => $attribute_set_id, 'attribute_group_id' => $attribute_set_section_id, 'attribute_id' => $is_provider_id, 'position' => (int) $max_position)); |
|
| 2279 | + $set_details_id_postion_order[$max_position] = $is_provider_id; |
|
| 2280 | + $is_provider_section_detail_id = $wpdb->insert_id; |
|
| 2281 | + } |
|
| 2282 | + |
|
| 2283 | + foreach ($set_details_id_postion_order as $pos => $attr_id) { |
|
| 2284 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE_DETAILS, array('position' => $pos), array('attribute_id' => $attr_id, 'attribute_set_id' => $attribute_set_id, 'entity_type_id' => $entity_id, 'attribute_group_id' => $attribute_set_section_id), array('%d'), array('%d', '%d', '%d', '%d')); |
|
| 2285 | + } |
|
| 2286 | + } |
|
| 2287 | + |
|
| 2288 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE_SET, array('name' => __('Free product', 'wpshop'), 'slug' => 'free_product'), array('name' => 'free_product'), array('%s', '%s'), array('%s')); |
|
| 2289 | + |
|
| 2290 | + return true; |
|
| 2291 | + break; |
|
| 2292 | + |
|
| 2293 | + case 66: |
|
| 2294 | + $price_behaviour_entity_id = wpshop_entities::get_entity_identifier_from_code(WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT); |
|
| 2295 | + $wpdb->insert(WPSHOP_DBT_ATTRIBUTE, array( |
|
| 2296 | + 'is_visible_in_front' => 'no', |
|
| 2297 | + 'is_visible_in_front_listing' => 'yes', |
|
| 2298 | + 'is_global' => 'no', |
|
| 2299 | + 'is_user_defined' => 'no', |
|
| 2300 | + 'is_required' => 'no', |
|
| 2301 | + 'is_visible_in_advanced_search' => 'no', |
|
| 2302 | + 'is_searchable' => 'no', |
|
| 2303 | + 'is_filterable' => 'no', |
|
| 2304 | + 'is_comparable' => 'no', |
|
| 2305 | + 'is_html_allowed_on_front' => 'no', |
|
| 2306 | + 'is_unique' => 'no', |
|
| 2307 | + 'is_filterable_in_search' => 'no', |
|
| 2308 | + 'is_used_for_sort_by' => 'no', |
|
| 2309 | + 'is_configurable' => 'no', |
|
| 2310 | + 'is_requiring_unit' => 'no', |
|
| 2311 | + 'is_recordable_in_cart_meta' => 'no', |
|
| 2312 | + 'is_used_in_admin_listing_column' => 'no', |
|
| 2313 | + 'is_used_in_quick_add_form' => 'no', |
|
| 2314 | + 'is_used_for_variation' => 'no', |
|
| 2315 | + 'is_used_in_variation' => 'yes', |
|
| 2316 | + '_display_informations_about_value' => 'no', |
|
| 2317 | + '_need_verification' => 'no', |
|
| 2318 | + '_unit_group_id' => null, |
|
| 2319 | + '_default_unit' => null, |
|
| 2320 | + 'is_historisable' => 'yes', |
|
| 2321 | + 'is_intrinsic' => 'no', |
|
| 2322 | + 'data_type_to_use' => 'custom', |
|
| 2323 | + 'use_ajax_for_filling_field' => 'no', |
|
| 2324 | + 'data_type' => 'integer', |
|
| 2325 | + 'backend_table' => null, |
|
| 2326 | + 'backend_label' => null, |
|
| 2327 | + 'backend_input' => 'select', |
|
| 2328 | + 'frontend_label' => 'price_behaviour', |
|
| 2329 | + 'frontend_input' => 'select', |
|
| 2330 | + 'frontend_verification' => null, |
|
| 2331 | + 'code' => 'price_behaviour', |
|
| 2332 | + 'note' => '', |
|
| 2333 | + 'default_value' => '', |
|
| 2334 | + 'frontend_css_class' => 'price_behaviour', |
|
| 2335 | + 'backend_css_class' => null, |
|
| 2336 | + 'frontend_help_message' => null, |
|
| 2337 | + 'entity_id' => $price_behaviour_entity_id, |
|
| 2338 | + )); |
|
| 2339 | + $price_behaviour = $wpdb->insert_id; |
|
| 2340 | + $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS, array( |
|
| 2341 | + 'status' => 'valid', |
|
| 2342 | + 'attribute_id' => $price_behaviour, |
|
| 2343 | + 'creation_date' => current_time('mysql'), |
|
| 2344 | + 'value' => '+', |
|
| 2345 | + 'label' => '+', |
|
| 2346 | + )); |
|
| 2347 | + $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_VALUES_OPTIONS, array( |
|
| 2348 | + 'status' => 'valid', |
|
| 2349 | + 'attribute_id' => $price_behaviour, |
|
| 2350 | + 'creation_date' => current_time('mysql'), |
|
| 2351 | + 'value' => '=', |
|
| 2352 | + 'label' => '=', |
|
| 2353 | + )); |
|
| 2354 | + $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_SET . ' WHERE entity_id = %d AND ( name = %s OR slug = %s )', $price_behaviour_entity_id, 'default', 'default'); |
|
| 2355 | + $price_behaviour_section_id = $wpdb->get_var($query); |
|
| 2356 | + $query = $wpdb->prepare('SELECT id FROM ' . WPSHOP_DBT_ATTRIBUTE_GROUP . ' WHERE attribute_set_id = %d AND code = %s', $price_behaviour_section_id, 'prices'); |
|
| 2357 | + $price_behaviour_section_detail_id = $wpdb->get_var($query); |
|
| 2358 | + $wpdb->insert(WPSHOP_DBT_ATTRIBUTE_DETAILS, array( |
|
| 2359 | + 'status' => 'deleted', |
|
| 2360 | + 'creation_date' => current_time('mysql', 0), |
|
| 2361 | + 'entity_type_id' => $price_behaviour_entity_id, |
|
| 2362 | + 'attribute_set_id' => $price_behaviour_section_id, |
|
| 2363 | + 'attribute_group_id' => $price_behaviour_section_detail_id, |
|
| 2364 | + 'attribute_id' => $price_behaviour, |
|
| 2365 | + 'position' => 0, |
|
| 2366 | + )); |
|
| 2367 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('is_used_in_variation' => 'yes', 'last_update_date' => current_time('mysql', 0)), array('code' => 'is_downloadable_')); |
|
| 2368 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('is_used_in_variation' => 'yes', 'last_update_date' => current_time('mysql', 0)), array('code' => 'tva')); |
|
| 2369 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('is_used_in_variation' => 'yes', 'last_update_date' => current_time('mysql', 0)), array('code' => 'price_ht')); |
|
| 2370 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('is_used_in_variation' => 'yes', 'last_update_date' => current_time('mysql', 0)), array('code' => 'product_stock')); |
|
| 2371 | + $wpdb->update(WPSHOP_DBT_ATTRIBUTE, array('is_used_in_variation' => 'yes', 'last_update_date' => current_time('mysql', 0)), array('code' => 'product_weight')); |
|
| 2372 | + return true; |
|
| 2373 | + break; |
|
| 2374 | + |
|
| 2375 | + case 67: |
|
| 2376 | + $admin_new_version_message = get_option('WPSHOP_NEW_VERSION_ADMIN_MESSAGE'); |
|
| 2377 | + if (empty($admin_new_version_message)) { |
|
| 2378 | + wps_message_ctr::createMessage('WPSHOP_NEW_VERSION_ADMIN_MESSAGE'); |
|
| 2379 | + } |
|
| 2380 | + $wpshop_cart_option = get_option('wpshop_cart_option'); |
|
| 2381 | + if (!empty($wpshop_cart_option) && !empty($wpshop_cart_option['total_nb_of_item_allowed'])) { |
|
| 2382 | + $wpshop_cart_option['total_nb_of_item_allowed'][0] = (int) filter_var($wpshop_cart_option['total_nb_of_item_allowed'][0], FILTER_VALIDATE_BOOLEAN); |
|
| 2383 | + } |
|
| 2384 | + update_option('wpshop_cart_option', $wpshop_cart_option); |
|
| 2385 | + return true; |
|
| 2386 | + break; |
|
| 2387 | 2387 | |
| 2388 | 2388 | case 68: |
| 2389 | 2389 | wps_message_ctr::create_default_message(); |