Esempio n. 1
0
 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;
 }
Esempio n. 2
0
 protected function loadProductCategories()
 {
     $flatlist = array();
     $tree = get_terms(ProductWrapper::getTaxonomy(), 'orderby=count&hide_empty=0');
     if (!is_wp_error($tree)) {
         $result = $this->parseTree($tree);
         $flatlist = $this->printTree($result);
         // echo "<pre>";print_r($flatlist);echo "</pre>";
     }
     return $flatlist;
 }
Esempio n. 3
0
 function showItemSpecifics()
 {
     global $post;
     // get data
     $wpl_available_attributes = ProductWrapper::getAttributeTaxonomies();
     $wpl_default_ebay_category_id = get_post_meta($post->ID, '_ebay_category_1_id', true);
     // $specifics contains all available item specifics for the selected category
     // $item_specifics contains values set for this particular product / profile
     // $specifics                 = get_post_meta( $post->ID, '_ebay_category_specifics', true );
     $specifics = array();
     $item_specifics = get_post_meta($post->ID, '_ebay_item_specifics', true);
     // 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');
     // $profile_id  = $listing && $listing->profile_id ? $listing->profile_id : false;
     $post_id = $post->ID;
     // // if primary category is set on product level, update stored category specifics if required
     // // (fixes empty item specifics box on imported products)
     // if ( $wpl_default_ebay_category_id && ! $specifics ) {
     // 	$specifics = $this->get_updated_item_specifics_for_product_and_category( $post_id, $wpl_default_ebay_category_id, $wpl_account_id );
     // }
     // if no primary category selected on product level, check profile for primary category
     $profile = $this->get_current_listing_profile();
     if (!$wpl_default_ebay_category_id) {
         if ($profile && $profile['details']['ebay_category_1_id']) {
             $wpl_default_ebay_category_id = $profile['details']['ebay_category_1_id'];
             // $specifics = maybe_unserialize( $profile['category_specifics'] );
         }
     }
     // if there is still no primary eBay category, look up the product's category in the category map
     if (!$wpl_default_ebay_category_id) {
         // get ebay categories map
         $categories_map_ebay = get_option('wplister_categories_map_ebay');
         if (isset(WPLE()->accounts[$wpl_account_id])) {
             $account = WPLE()->accounts[$wpl_account_id];
             $categories_map_ebay = maybe_unserialize($account->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));
         // echo "<pre>";print_r($terms);echo"</pre>";#die();
         // echo "<pre>";print_r($categories_map_ebay);echo"</pre>";#die();
         $ebay_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) {
                 $wpl_default_ebay_category_id = $ebay_category_id;
                 // $specifics = $this->get_updated_item_specifics_for_product_and_category( $post_id, $ebay_category_id, $wpl_account_id );
                 break;
             }
         }
         // each term
     }
     // if still no ebay category
     // load specifics if we have a category
     if ($wpl_default_ebay_category_id) {
         $specifics = EbayCategoriesModel::getItemSpecificsForCategory($wpl_default_ebay_category_id, false, $wpl_account_id);
         // $specifics = array( $wpl_default_ebay_category_id => $specifics );
     }
     // echo "<pre>";print_r($wpl_default_ebay_category_id);echo"</pre>";#die();
     // echo "<pre>";print_r($profile);echo"</pre>";#die();
     // echo "<pre>";print_r($specifics);echo"</pre>";#die();
     // echo "<pre>";print_r($item_specifics);echo"</pre>";#die();
     // add attribute for SKU
     // $attrib = new stdClass();
     // $attrib->name = '_sku';
     // $attrib->label = 'SKU';
     // $wpl_available_attributes[] = $attrib;
     // process custom attributes
     $wpl_custom_attributes = array();
     $custom_attributes = apply_filters('wplister_custom_attributes', array());
     if (is_array($custom_attributes)) {
         foreach ($custom_attributes as $attrib) {
             $new_attribute = new stdClass();
             $new_attribute->name = $attrib['id'];
             $new_attribute->label = $attrib['label'];
             $wpl_custom_attributes[] = $new_attribute;
         }
     }
     echo '<div class="ebay_item_specifics_wrapper">';
     echo '<h2>' . __('Item Specifics', 'wplister') . '</h2>';
     include WPLISTER_PATH . '/views/profile/edit_item_specifics.php';
     // let the user know which category the available item specifics are based on
     if ($profile && $profile['details']['ebay_category_1_id']) {
         $profile_link = '<a href="admin.php?page=wplister-profiles&action=edit&profile=' . $profile['profile_id'] . '" target="_blank">' . $profile['profile_name'] . '</a>';
         echo '<small>These options are based on the selected profile <b>' . $profile_link . '</b> and its primary eBay category <b>' . $profile['details']['ebay_category_1_name'] . '</b>.</small>';
     } elseif ($wpl_default_ebay_category_id && isset($categories_map_ebay)) {
         $category_path = EbayCategoriesModel::getFullEbayCategoryName($wpl_default_ebay_category_id, $wpl_site_id);
         echo '<small>Item specifics are based on the eBay category <b>' . $category_path . '</b> according to your category settings.</small>';
     }
     echo '</div>';
 }