public function buildCategories($id, $item, $post_id, $profile_details) { // handle primary category $ebay_category_1_id = get_post_meta($post_id, '_ebay_category_1_id', true); if (intval($ebay_category_1_id) > 0) { $item->PrimaryCategory = new CategoryType(); $item->PrimaryCategory->CategoryID = $ebay_category_1_id; } elseif (intval($profile_details['ebay_category_1_id']) > 0) { $item->PrimaryCategory = new CategoryType(); $item->PrimaryCategory->CategoryID = $profile_details['ebay_category_1_id']; } else { // get ebay categories map $categories_map_ebay = get_option('wplister_categories_map_ebay'); // fetch products local category terms $terms = wp_get_post_terms($post_id, ProductWrapper::getTaxonomy()); // WPLE()->logger->info('terms: '.print_r($terms,1)); $ebay_category_id = false; $primary_category_id = false; $secondary_category_id = false; foreach ($terms as $term) { // look up ebay category if (isset($categories_map_ebay[$term->term_id])) { $ebay_category_id = @$categories_map_ebay[$term->term_id]; $ebay_category_id = apply_filters('wplister_apply_ebay_category_map', $ebay_category_id, $post_id); } // check ebay category if (intval($ebay_category_id) > 0) { if (!$primary_category_id) { $primary_category_id = $ebay_category_id; } else { $secondary_category_id = $ebay_category_id; } } } WPLE()->logger->info('mapped primary_category_id: ' . $primary_category_id); WPLE()->logger->info('mapped secondary_category_id: ' . $secondary_category_id); if (intval($primary_category_id) > 0) { $item->PrimaryCategory = new CategoryType(); $item->PrimaryCategory->CategoryID = $primary_category_id; } if (intval($secondary_category_id) > 0 && $secondary_category_id != $primary_category_id) { $item->SecondaryCategory = new CategoryType(); $item->SecondaryCategory->CategoryID = $secondary_category_id; } } // optional secondary category $ebay_category_2_id = get_post_meta($post_id, '_ebay_category_2_id', true); if (intval($ebay_category_2_id) > 0) { $item->SecondaryCategory = new CategoryType(); $item->SecondaryCategory->CategoryID = $ebay_category_2_id; } elseif (intval($profile_details['ebay_category_2_id']) > 0) { $item->SecondaryCategory = new CategoryType(); $item->SecondaryCategory->CategoryID = $profile_details['ebay_category_2_id']; } // if no secondary category, set to zero if (!$item->SecondaryCategory->CategoryID) { $item->SecondaryCategory = new CategoryType(); $item->SecondaryCategory->CategoryID = 0; } // handle optional store category $store_category_1_id = get_post_meta($post_id, '_ebay_store_category_1_id', true); if (intval($store_category_1_id) > 0) { $item->Storefront = new StorefrontType(); $item->Storefront->StoreCategoryID = $store_category_1_id; } elseif (intval($profile_details['store_category_1_id']) > 0) { $item->Storefront = new StorefrontType(); $item->Storefront->StoreCategoryID = $profile_details['store_category_1_id']; } else { // get store categories map $categories_map_store = get_option('wplister_categories_map_store'); // fetch products local category terms $terms = wp_get_post_terms($post_id, ProductWrapper::getTaxonomy()); // WPLE()->logger->info('terms: '.print_r($terms,1)); $store_category_id = false; $primary_store_category_id = false; $secondary_store_category_id = false; foreach ($terms as $term) { // look up store category if (isset($categories_map_store[$term->term_id])) { $store_category_id = @$categories_map_store[$term->term_id]; } // check store category if (intval($store_category_id) > 0) { if (!$primary_store_category_id) { $primary_store_category_id = $store_category_id; } else { $secondary_store_category_id = $store_category_id; } } } WPLE()->logger->info('mapped primary_store_category_id: ' . $primary_store_category_id); WPLE()->logger->info('mapped secondary_store_category_id: ' . $secondary_store_category_id); if (intval($primary_store_category_id) > 0) { $item->Storefront = new StorefrontType(); $item->Storefront->StoreCategoryID = $primary_store_category_id; } if (intval($secondary_store_category_id) > 0) { $item->Storefront->StoreCategory2ID = $secondary_store_category_id; } } // optional secondary store category - from profile if (intval($profile_details['store_category_2_id']) > 0) { $item->Storefront->StoreCategory2ID = $profile_details['store_category_2_id']; } // optional secondary store category - from product $store_category_2_id = get_post_meta($post_id, '_ebay_store_category_2_id', true); if (intval($store_category_2_id) > 0) { $item->Storefront->StoreCategory2ID = $store_category_2_id; } // adjust Site if required - eBay Motors (beta) if ($item->Site == 'US') { // if primary category's site_id is 100, set Site to eBayMotors $primary_category = EbayCategoriesModel::getItem($item->PrimaryCategory->CategoryID); if ($primary_category['site_id'] == 100) { $item->setSite('eBayMotors'); } } return $item; }