Changeset 2578509
- Timestamp:
- 08/05/2021 05:58:59 AM (5 years ago)
- Location:
- bonus-plus-wp/trunk
- Files:
-
- 4 edited
-
bonus-plus-wp.php (modified) (3 diffs)
-
inc/ClientProfile.php (modified) (1 diff)
-
inc/WooProductCatExport.php (modified) (6 diffs)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
bonus-plus-wp/trunk/bonus-plus-wp.php
r2577633 r2578509 1 1 <?php 2 3 2 /** 4 3 * Plugin Name: Bonus-Plus-wp … … 16 15 * WP requires at least: 5.0 17 16 * Tested up to: 5.8 18 * Version: 1. 617 * Version: 1.7 19 18 */ 20 19 namespace BPWP; … … 29 28 public static function init() 30 29 { 31 define('BPWP_PLUGIN_VERSION', '1. 6');30 define('BPWP_PLUGIN_VERSION', '1.7'); 32 31 33 32 require_once __DIR__ . '/functions.php'; -
bonus-plus-wp/trunk/inc/ClientProfile.php
r2576578 r2578509 164 164 'GET' 165 165 ); 166 update_user_meta($user_id, 'bonus-plus', $res );166 update_user_meta($user_id, 'bonus-plus', $res['request']); 167 167 } 168 168 } -
bonus-plus-wp/trunk/inc/WooProductCatExport.php
r2577633 r2578509 56 56 add_settings_field( 57 57 $id = 'bpwp_wrong_products_action', 58 $title = __('Действие при импорте с товаром у которого больше 1 категории:', 'bonus-plus-wp'),58 $title = __('Действие при экспорте с товаром у которого больше 1 категории:', 'bonus-plus-wp'), 59 59 $callback = array(__CLASS__, 'display_wrong_products_action'), 60 60 $page = 'bpwp-settings', … … 84 84 '<option value="%s" %s>%s</option>', 85 85 'empty', 86 selected(' default', $wrong_products_action, false),86 selected('empty', $wrong_products_action, false), 87 87 __( 'Импортировать товар, без категории', 'bonus-plus-wp') 88 88 ); … … 191 191 foreach ($products as $product) { 192 192 $productId = $product->get_id(); 193 // получим все категории продукта 194 $pCatIds = $product->get_category_ids(); 195 $categoriesCount = count($pCatIds); 196 197 if ($categoriesCount == 1) { 198 $pCatId = $pCatIds[0]; 199 $product = [ 193 $productName = $product->get_name(); 194 $productCategory = self::bpwp_get_product_child_category($productId); 195 196 if (count($productCategory) !== 1) { 197 // У товара больше 1 дочерней категории или нет, действуем по опции 198 $wrong_products_action = get_option('bpwp_wrong_products_action'); 199 switch ($wrong_products_action) { 200 case 'hide': 201 do_action( 202 'bpwp_logger_error', 203 $type = __CLASS__, 204 $title = __('Экспорт товаров в Бонус+, товар пропущен', 'bonus-plus-wp'), 205 $desc = sprintf(__('У товара [%s] %s более 1 дочерней категории', 'bonus-plus-wp'), $productId, $productName), 206 ); 207 break; 208 case 'empty': 209 $exportProduct = [ 210 'id' => $productId, 211 'pid' => 0, 212 'n' => $productName, 213 'g' => false, 214 ]; 215 $productList[] = $exportProduct; 216 break; 217 } 218 $wrongProducts[$productId] = $productName; 219 } else { 220 foreach ($productCategory as $productCat){ 221 $CatId = $productCat->term_id; 222 } 223 $productExport = [ 200 224 'id' => $productId, 201 'pid' => $ pCatId,202 'n' => $product ->get_name(),225 'pid' => $CatId, 226 'n' => $productName, 203 227 'g' => false, 204 228 ]; 205 $productList[] = $product; 206 } else { 207 // пробуем определить родительскую категорию товара 208 $productParentCat = self::bpwp_export_get_parent_cat($productId, $pCatIds); 209 if (!$productParentCat){ 210 // в зависимости от опции 211 $wrong_products_action = get_option('bpwp_wrong_products_action'); 212 switch ($wrong_products_action) { 213 case 'hide': 214 do_action( 215 'bpwp_logger_error', 216 $type = __CLASS__, 217 $title = __('Экспорт товаров в Бонус+, товар пропущен', 'bonus-plus-wp'), 218 $desc = sprintf(__('У товара с ID %s %s более 1 категории', 'bonus-plus-wp'), $productId, $product->name), 219 ); 220 break; 221 case 'empty': 222 $product = [ 223 'id' => $productId, 224 'pid' => 0, 225 'n' => $product->get_name(), 226 'g' => false, 227 ]; 228 $productList[] = $product; 229 break; 230 } 231 $wrongProducts[$productId] = $product->name; 232 } 229 $productList[] = $productExport; 233 230 } 234 231 } … … 314 311 $class = self::$lastExport['class']; 315 312 $lastExportDate = !empty(get_option(self::$lastExportOption)) ? get_option(self::$lastExportOption) : ''; 316 317 //$class = 'updated notice is-dismissible'; 313 $wrong_products_action = get_option('bpwp_wrong_products_action'); 314 switch ($wrong_products_action) { 315 case 'hide': 316 $action = __('Пропущено товаров', 'bonus-plus-wp'); 317 break; 318 case 'empty': 319 $action = __('Импортировано товаров, без категории', 'bonus-plus-wp'); 320 break; 321 } 322 318 323 $strings[] = sprintf('<strong>Результат последнего экспорта %s :</strong> %s', $lastExportDate, self::$lastExport['message']); 319 324 $strings[] = sprintf('<strong>%s: %d</strong>', esc_html(__('Найдено категорий', 'bonus-plus-wp')), self::$lastExport['cat_count']); … … 322 327 $strings[] = sprintf('<strong>%s: %d</strong>', esc_html(__('Найдено товаров', 'bonus-plus-wp')), self::$lastExport['pcount']); 323 328 $strings[] = sprintf('<strong>%s: %d</strong>', esc_html(__('Экспортировано товаров', 'bonus-plus-wp')), self::$lastExport['pexport']); 324 $strings[] = sprintf('<strong>%s: %d</strong>', esc_html( __('Пропущено товаров', 'bonus-plus-wp')), self::$lastExport['phide']);329 $strings[] = sprintf('<strong>%s: %d</strong>', esc_html($action), self::$lastExport['phide']); 325 330 326 331 … … 347 352 348 353 /** 349 * Return parent cat by product id350 * 354 * Return child category for product id https://wordpress.stackexchange.com/a/55921 355 * 351 356 * @param $productId int ИД товара 352 * @param $pCatIds array Массид ИД категорий товара 353 * 354 * @return void 355 */ 356 public static function bpwp_export_get_parent_cat($productId, $pCatIds){ 357 if (empty($productId) || empty($pCatIds) || empty(self::$productTopCat)) 358 return false; 359 360 $other_cats = array_diff($pCatIds, self::$productTopCat); 361 $parentCats = []; 362 foreach ($other_cats as $cat){ 363 $termChildren = get_term_children($cat, 'product_cat'); 364 if (empty($termChildren)){ 365 $parentCats[] = $cat; 366 } 367 } 368 369 if (count($parentCats) != 1){ 370 return false; 371 } else { 372 return $parentCats[0]; 373 } 374 375 357 * 358 * @return array Array of child product categories 359 */ 360 public static function bpwp_get_product_child_category($productId){ 361 //Get all terms associated with post in woocommerce's taxonomy 'product_cat' 362 $terms = get_the_terms($productId, 'product_cat'); 363 364 //Get an array of their IDs 365 $term_ids = wp_list_pluck($terms, 'term_id'); 366 367 //Get array of parents - 0 is not a parent 368 $parents = array_filter(wp_list_pluck($terms, 'parent')); 369 370 //Get array of IDs of terms which are not parents. 371 $term_ids_not_parents = array_diff($term_ids, $parents); 372 373 //Get corresponding term objects. 374 $terms_not_parents = array_intersect_key($terms, $term_ids_not_parents); 375 376 return $terms_not_parents; 376 377 } 377 378 } -
bonus-plus-wp/trunk/readme.txt
r2577633 r2578509 5 5 Requires at least: 4.0 6 6 Tested up to: 5.8 7 Stable tag: 1. 67 Stable tag: 1.7 8 8 Requires PHP: 7.1 9 9 License: GPLv2 or later … … 93 93 == Changelog == 94 94 95 = 1.7 = 96 - Исправлены функция определения родительской категории у товара, добавлена документация https://github.com/evgrezanov/bonus-plus-wp/wiki/Export-products-and-product-cat/ 97 95 98 = 1.6 = 96 - Исправлены ошибки при выводе сообщения о завершении экспорта товаров и категорий99 - Исправлены ошибки при выводе сообщения о завершении экспорта товаров и категорий 97 100 98 101 = 1.5 =
Note: See TracChangeset
for help on using the changeset viewer.