if(!empty($itemDetails['Item']['Storefront']['StoreCategoryID'])){
$category = $itemDetails['Item']['Storefront']['StoreCategoryID'];
$renderDataOnGlobalSettings = ! empty( get_option( 'ced_ebay_global_settings', false ) ) ? get_option('ced_ebay_global_settings', false ) : false;
if ( false != $renderDataOnGlobalSettings ) {
$import_categories = $renderDataOnGlobalSettings[ $user_id ]['ced_ebay_import_ebay_categories'];
if ( ! empty( $import_categories ) && 'Enabled' == $import_categories ) {
if ( ! empty( $category ) ) {
if(file_exists(CED_EBAY_DIRPATH . 'admin/ebay/lib/ebayAuthorization.php')){
require_once CED_EBAY_DIRPATH . 'admin/ebay/lib/ebayAuthorization.php';
$cedAuthorization = new Ebayauthorization();
$cedAuhorizationInstance = $cedAuthorization->get_instance();
$shopDetails = $cedAuhorizationInstance->getStoreData( $siteID );
if(!empty($shopDetails) && $shopDetails['Ack'] == 'Success'){
$store_categories = $shopDetails['Store']['CustomCategories']['CustomCategory'];
$store_cateogry_name = $this->ced_ebay_recursive_array_search($category, $store_categories);
if(!empty($store_cateogry_name)){
if(!term_exists($store_cateogry_name)){
$mainTerm = wp_insert_term(
$store_cateogry_name,
'product_cat',
array(
'',
'slug' => str_replace(' ', '-', trim($store_cateogry_name))
)
);
$newParentID = $mainTerm['term_id'];
$tem_slug = $mainTerm['slug'];
} else {
$get_term = get_term_by('name', $store_cateogry_name, 'product_cat');
$mainTerm = array(
'term_id'=> $get_term->term_id,
'term_taxonomy_id' => $get_term->term_taxonomy_id,
'slug' => $get_term->slug,
);
$newParentID = $mainTerm['term_id'];
$term_slug = $mainTerm['slug'];
}
wp_set_object_terms( $product_id, $newParentID, 'product_cat' );
}
}
}
}
}
}
}
public function ced_ebay_recursive_array_search($needle, $haystack) {
foreach($haystack as $key=>$value) {
if (is_array($value['ChildCategory'])) {
$nextKey = $this->ced_ebay_recursive_array_search($needle,$value['ChildCategory']);
if ($nextKey) {
return $nextKey;
}
}
else if($value['CategoryID']==$needle) {
return $value['Name'];
}
}
return false;
}
Last active
April 17, 2022 17:07
-
-
Save ali-cedcoss/4bfaeff42df116be9cbe5d5c6ee8eef8 to your computer and use it in GitHub Desktop.
assigning imported products to store their eBay store categories
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment