function printTree($tree, $depth = 0, $result = array()) { $categories_map_ebay = self::getOption('categories_map_ebay'); $categories_map_store = self::getOption('categories_map_store'); if ($this->account_id) { $categories_map_ebay = maybe_unserialize(WPLE()->accounts[$this->account_id]->categories_map_ebay); $categories_map_store = maybe_unserialize(WPLE()->accounts[$this->account_id]->categories_map_store); } if ($tree != 0 && count($tree) > 0) { foreach ($tree as $node) { // indent category name accourding to depth $node->name = str_repeat('– ', $depth) . $node->name; // echo $node->name; // get ebay category and (full) name $ebay_category_id = @$categories_map_ebay[$node->term_id]; $store_category_id = @$categories_map_store[$node->term_id]; // add item to results - excluding children $tmpnode = array('term_id' => $node->term_id, 'parent' => $node->parent, 'category' => $node->name, 'ebay_category_id' => $ebay_category_id, 'ebay_category_name' => EbayCategoriesModel::getFullEbayCategoryName($ebay_category_id, $this->site_id), 'store_category_id' => $store_category_id, 'store_category_name' => EbayCategoriesModel::getFullStoreCategoryName($store_category_id, $this->account_id), 'description' => $node->description); $result[] = $tmpnode; $result = $this->printTree($node->children, $depth + 1, $result); } } return $result; }
</tr> <?php if ($wpl_item->Storefront->StoreCategoryID) { ?> <tr> <th class="vi-is1-lbl"> Store Category: </th> <td colspan="3" class="vi-is1-clr"> <?php if ($wpl_item->Storefront->StoreCategoryID) { echo EbayCategoriesModel::getFullStoreCategoryName($wpl_item->Storefront->StoreCategoryID); } if ($wpl_item->Storefront->StoreCategory2ID) { echo '<br>' . EbayCategoriesModel::getFullStoreCategoryName($wpl_item->Storefront->StoreCategory2ID); } ?> </td> </tr> <tr> <td colspan="4" height="10"></td> </tr> <?php } ?> </tbody> </table>
padding-top: 3px; text-decoration: none; } a.link_remove_category { padding-left: 3px; text-decoration: none; } </style> <?php // fetch full category names $item_details['ebay_category_1_name'] = EbayCategoriesModel::getFullEbayCategoryName($item_details['ebay_category_1_id'], $wpl_site_id); $item_details['ebay_category_2_name'] = EbayCategoriesModel::getFullEbayCategoryName($item_details['ebay_category_2_id'], $wpl_site_id); $item_details['store_category_1_name'] = EbayCategoriesModel::getFullStoreCategoryName($item_details['store_category_1_id'], $wpl_account_id); $item_details['store_category_2_name'] = EbayCategoriesModel::getFullStoreCategoryName($item_details['store_category_2_id'], $wpl_account_id); ?> <div class="postbox" id="EbayCategorySelectionBox"> <h3><span><?php echo __('eBay categories', 'wplister'); ?> </span></h3> <div class="inside"> <div style="position:relative; margin: 0 5px;"> <label for="wpl-text-ebay_category_1_name" class="text_label"> <?php echo __('Primary eBay category', 'wplister'); ?> <?php
function showCategoryOptions() { global $post; // get listing object $listing = $this->get_current_ebay_item(); $wpl_account_id = $listing && $listing->account_id ? $listing->account_id : get_option('wplister_default_account_id'); $wpl_site_id = $listing ? $listing->site_id : get_option('wplister_ebay_site_id'); $default_text = '<span style="color:silver"><i>— ' . __('will be assigned automatically', 'wplister') . ' —</i></span>'; // primary ebay category $ebay_category_1_id = get_post_meta($post->ID, '_ebay_category_1_id', true); $ebay_category_1_name = $ebay_category_1_id ? EbayCategoriesModel::getFullEbayCategoryName($ebay_category_1_id, $wpl_site_id) : $default_text; // secondary ebay category $ebay_category_2_id = get_post_meta($post->ID, '_ebay_category_2_id', true); $ebay_category_2_name = $ebay_category_2_id ? EbayCategoriesModel::getFullEbayCategoryName($ebay_category_2_id, $wpl_site_id) : $default_text; // primary store category $store_category_1_id = get_post_meta($post->ID, '_ebay_store_category_1_id', true); $store_category_1_name = $store_category_1_id ? EbayCategoriesModel::getFullStoreCategoryName($store_category_1_id, $wpl_account_id) : $default_text; // secondary store category $store_category_2_id = get_post_meta($post->ID, '_ebay_store_category_2_id', true); $store_category_2_name = $store_category_2_id ? EbayCategoriesModel::getFullStoreCategoryName($store_category_2_id, $wpl_account_id) : $default_text; // if no eBay category selected on product level, check profile $profile = $this->get_current_listing_profile(); if ($profile && (empty($ebay_category_1_id) || empty($ebay_category_2_id))) { if (!$ebay_category_1_id && $profile['details']['ebay_category_1_id']) { $ebay_category_1_name = EbayCategoriesModel::getFullEbayCategoryName($profile['details']['ebay_category_1_id'], $wpl_site_id); $ebay_category_1_name = '<span style="color:silver">Profile category: ' . $ebay_category_1_name . ' </span>'; } if (!$ebay_category_2_id && $profile['details']['ebay_category_2_id']) { $ebay_category_2_name = EbayCategoriesModel::getFullEbayCategoryName($profile['details']['ebay_category_2_id'], $wpl_site_id); $ebay_category_2_name = '<span style="color:silver">Profile category: ' . $ebay_category_2_name . ' </span>'; } } // if no Store category selected on product level, check profile if ($profile && (empty($store_category_1_id) || empty($store_category_2_id))) { if (!$store_category_1_id && $profile['details']['store_category_1_id']) { $store_category_1_name = EbayCategoriesModel::getFullStoreCategoryName($profile['details']['store_category_1_id'], $wpl_account_id); $store_category_1_name = '<span style="color:silver">Profile category: ' . $store_category_1_name . ' </span>'; } if (!$store_category_2_id && $profile['details']['store_category_2_id']) { $store_category_2_name = EbayCategoriesModel::getFullStoreCategoryName($profile['details']['store_category_2_id'], $wpl_account_id); $store_category_2_name = '<span style="color:silver">Profile category: ' . $store_category_2_name . ' </span>'; } } $store_categories_message = 'Note: eBay <i>Store</i> categories are selected automatically based on the product categories assigned and your '; $store_categories_message .= '<a href="admin.php?page=wplister-settings&tab=categories" target="_blank">category settings</a>.'; // if ( $profile && ( $profile['details']['store_category_1_id'] || $profile['details']['store_category_2_id'] ) ) { // // $store_categories_message .= ' - unless you set specific store categories in your listing profile or on this page. '; // } else { // // $store_categories_message .= '. Your listing profile <b>'.$profile['profile_name'].'</b> does not use any store categories.'; // // $store_categories_message .= '.'; // } ?> <h4><?php echo __('eBay categories', 'wplister'); ?> </h4> <div style="position:relative; margin: 0 5px;"> <label for="wpl-text-ebay_category_1_name" class="text_label"><?php echo __('Primary eBay category', 'wplister'); ?> </label> <input type="hidden" name="wpl_ebay_category_1_id" id="ebay_category_id_1" value="<?php echo $ebay_category_1_id; ?> " class="" /> <span id="ebay_category_name_1" class="text_input" style="width:45%;float:left;line-height:2em;"><?php echo $ebay_category_1_name; ?> </span> <div class="category_row_actions"> <input type="button" value="<?php echo __('select', 'wplister'); ?> " class="button btn_select_ebay_category" onclick=""> <input type="button" value="<?php echo __('remove', 'wplister'); ?> " class="button btn_remove_ebay_category" onclick=""> </div> </div> <br style="clear:both" /> <div style="position:relative; margin: 0 5px;"> <label for="wpl-text-ebay_category_2_name" class="text_label"><?php echo __('Secondary eBay category', 'wplister'); ?> </label> <input type="hidden" name="wpl_ebay_category_2_id" id="ebay_category_id_2" value="<?php echo $ebay_category_2_id; ?> " class="" /> <span id="ebay_category_name_2" class="text_input" style="width:45%;float:left;line-height:2em;"><?php echo $ebay_category_2_name; ?> </span> <div class="category_row_actions"> <input type="button" value="<?php echo __('select', 'wplister'); ?> " class="button btn_select_ebay_category" onclick=""> <input type="button" value="<?php echo __('remove', 'wplister'); ?> " class="button btn_remove_ebay_category" onclick=""> </div> </div> <br style="clear:both" /> <h4><?php echo __('Store categories', 'wplister'); ?> </h4> <div style="position:relative; margin: 0 5px;"> <label for="wpl-text-store_category_1_name" class="text_label"> <?php echo __('Store category', 'wplister'); ?> 1 <?php wplister_tooltip('<b>Store category</b><br>A custom category that the seller created in their eBay Store.<br><br> eBay Stores sellers can create up to three levels of custom categories for their stores. Items can only be listed in root categories, or categories that have no child categories (subcategories).'); ?> </label> <input type="hidden" name="wpl_ebay_store_category_1_id" id="store_category_id_1" value="<?php echo $store_category_1_id; ?> " class="" /> <span id="store_category_name_1" class="text_input" style="width:45%;float:left;line-height:2em;"><?php echo $store_category_1_name; ?> </span> <div class="category_row_actions"> <input type="button" value="<?php echo __('select', 'wplister'); ?> " class="button btn_select_store_category" onclick=""> <input type="button" value="<?php echo __('remove', 'wplister'); ?> " class="button btn_remove_store_category" onclick=""> </div> </div> <div style="position:relative; margin: 0 5px; clear:both"> <label for="wpl-text-store_category_2_name" class="text_label"> <?php echo __('Store category', 'wplister'); ?> 2 <?php wplister_tooltip('<b>Store category</b><br>A custom category that the seller created in their eBay Store.<br><br> eBay Stores sellers can create up to three levels of custom categories for their stores. Items can only be listed in root categories, or categories that have no child categories (subcategories).'); ?> </label> <input type="hidden" name="wpl_ebay_store_category_2_id" id="store_category_id_2" value="<?php echo $store_category_2_id; ?> " class="" /> <span id="store_category_name_2" class="text_input" style="width:45%;float:left;line-height:2em;"><?php echo $store_category_2_name; ?> </span> <div class="category_row_actions"> <input type="button" value="<?php echo __('select', 'wplister'); ?> " class="button btn_select_store_category" onclick=""> <input type="button" value="<?php echo __('remove', 'wplister'); ?> " class="button btn_remove_store_category" onclick=""> </div> </div> <br style="clear:both" /> <p> <small><?php echo $store_categories_message; ?> </small> </p> <!-- hidden ajax categories tree --> <div id="ebay_categories_tree_wrapper"> <div id="ebay_categories_tree_container"></div> </div> <!-- hidden ajax categories tree --> <div id="store_categories_tree_wrapper"> <div id="store_categories_tree_container"></div> </div> <style type="text/css"> #ebay_categories_tree_wrapper, #store_categories_tree_wrapper { /*max-height: 320px;*/ /*margin-left: 35%;*/ overflow: auto; width: 65%; display: none; } #wplister-ebay-categories .category_row_actions { position: absolute; top: 0; right: 0; } #wplister-ebay-categories .category_row_actions input { width: auto; } a.link_select_category { float: right; padding-top: 3px; text-decoration: none; } a.link_remove_category { padding-left: 3px; text-decoration: none; } </style> <script type="text/javascript"> var wpl_site_id = '<?php echo $wpl_site_id; ?> '; var wpl_account_id = '<?php echo $wpl_account_id; ?> '; /* recusive function to gather the full category path names */ function wpl_getCategoryPathName( pathArray, depth ) { var pathname = ''; if (typeof depth == 'undefined' ) depth = 0; // get name if ( depth == 0 ) { var cat_name = jQuery('[rel=' + pathArray.join('\\\/') + ']').html(); } else { var cat_name = jQuery('[rel=' + pathArray.join('\\\/') +'\\\/'+ ']').html(); } // console.log('path...: ', pathArray.join('\\\/') ); // console.log('catname: ', cat_name); // console.log('pathArray: ', pathArray); // strip last (current) item popped = pathArray.pop(); // console.log('popped: ',popped); // call self with parent path if ( pathArray.length > 2 ) { pathname = wpl_getCategoryPathName( pathArray, depth + 1 ) + ' » ' + cat_name; } else if ( pathArray.length > 1 ) { pathname = cat_name; } return pathname; } jQuery( document ).ready( function () { // select ebay category button jQuery('input.btn_select_ebay_category').click( function(event) { // var cat_id = jQuery(this).parent()[0].id.split('sel_ebay_cat_id_')[1]; e2e_selecting_cat = ('ebay_category_name_1' == jQuery(this).parent().parent().first().find('.text_input')[0].id) ? 1 : 2; var tbHeight = tb_getPageSize()[1] - 120; var tbURL = "#TB_inline?height="+tbHeight+"&width=753&inlineId=ebay_categories_tree_wrapper"; tb_show("Select a category", tbURL); }); // remove ebay category button jQuery('input.btn_remove_ebay_category').click( function(event) { var cat_id = ('ebay_category_name_1' == jQuery(this).parent().parent().first().find('.text_input')[0].id) ? 1 : 2; jQuery('#ebay_category_id_'+cat_id).attr('value',''); jQuery('#ebay_category_name_'+cat_id).html(''); }); // select store category button jQuery('input.btn_select_store_category').click( function(event) { // var cat_id = jQuery(this).parent()[0].id.split('sel_store_cat_id_')[1]; e2e_selecting_cat = ('store_category_name_1' == jQuery(this).parent().parent().first().find('.text_input')[0].id) ? 1 : 2; var tbHeight = tb_getPageSize()[1] - 120; var tbURL = "#TB_inline?height="+tbHeight+"&width=753&inlineId=store_categories_tree_wrapper"; tb_show("Select a category", tbURL); }); // remove store category button jQuery('input.btn_remove_store_category').click( function(event) { var cat_id = ('store_category_name_1' == jQuery(this).parent().parent().first().find('.text_input')[0].id) ? 1 : 2; jQuery('#store_category_id_'+cat_id).attr('value',''); jQuery('#store_category_name_'+cat_id).html(''); }); // jqueryFileTree 1 - ebay categories jQuery('#ebay_categories_tree_container').fileTree({ root: '/0/', script: ajaxurl+'?action=e2e_get_ebay_categories_tree&site_id='+wpl_site_id, expandSpeed: 400, collapseSpeed: 400, loadMessage: 'loading eBay categories...', multiFolder: false }, function(catpath) { // get cat id from full path var cat_id = catpath.split('/').pop(); // get last item - like php basename() // get name of selected category var cat_name = ''; var pathname = wpl_getCategoryPathName( catpath.split('/') ); // console.log('pathname: ',pathname); // update fields jQuery('#ebay_category_id_'+e2e_selecting_cat).attr( 'value', cat_id ); jQuery('#ebay_category_name_'+e2e_selecting_cat).html( pathname ); // close thickbox tb_remove(); if ( e2e_selecting_cat == 1 ) { updateItemSpecifics(); // updateItemConditions(); } }); // jqueryFileTree 2 - store categories jQuery('#store_categories_tree_container').fileTree({ root: '/0/', script: ajaxurl+'?action=e2e_get_store_categories_tree&account_id='+wpl_account_id, expandSpeed: 400, collapseSpeed: 400, loadMessage: 'loading store categories...', multiFolder: false }, function(catpath) { // get cat id from full path var cat_id = catpath.split('/').pop(); // get last item - like php basename() // get name of selected category var cat_name = ''; var pathname = wpl_getCategoryPathName( catpath.split('/') ); // console.log('pathname: ',pathname); if ( pathname.indexOf('[use this category]') > -1 ) { catpath = catpath + '/'; pathname = wpl_getCategoryPathName( catpath.split('/') ); } // update fields jQuery('#store_category_id_'+e2e_selecting_cat).attr( 'value', cat_id ); jQuery('#store_category_name_'+e2e_selecting_cat).html( pathname ); // close thickbox tb_remove(); }); } ); </script> <?php }