public function displayEditPage() { // init model $profilesModel = new ProfilesModel(); // get item if ($this->requestAction() == 'add_new_profile') { $item = $profilesModel->newItem(); } else { $item = $profilesModel->getItem($_REQUEST['profile']); } // set account id $account_id = $item['account_id']; $site_id = isset($item['site_id']) ? $item['site_id'] : false; if (!$account_id) { $account_id = get_option('wplister_default_account_id'); } if (!$site_id) { $site_id = WPLE()->accounts[$account_id]->site_id; } // get ebay data $payment_options = EbayPaymentModel::getAll($site_id); $loc_flat_shipping_options = EbayShippingModel::getAllLocal($site_id, 'flat'); $int_flat_shipping_options = EbayShippingModel::getAllInternational($site_id, 'flat'); $shipping_locations = EbayShippingModel::getShippingLocations($site_id); $exclude_locations = EbayShippingModel::getExcludeShippingLocations($site_id); $countries = EbayShippingModel::getEbayCountries($site_id); $template_files = $this->getTemplatesList(); $store_categories = $this->getStoreCategories($account_id); $loc_calc_shipping_options = EbayShippingModel::getAllLocal($site_id, 'calculated'); $int_calc_shipping_options = EbayShippingModel::getAllInternational($site_id, 'calculated'); $available_attributes = ProductWrapper::getAttributeTaxonomies(); // add attribute for SKU // $attrib = new stdClass(); // $attrib->name = '_sku'; // $attrib->label = 'SKU'; // $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; } } // $available_dispatch_times = self::getOption('DispatchTimeMaxDetails'); // $available_shipping_packages = self::getOption('ShippingPackageDetails'); // $ReturnsWithinOptions = get_option('wplister_ReturnsWithinOptions') $available_dispatch_times = WPLE_eBaySite::getSiteObj($site_id)->getDispatchTimeMaxDetails(); $available_shipping_packages = WPLE_eBaySite::getSiteObj($site_id)->getShippingPackageDetails(); $ReturnsWithinOptions = WPLE_eBaySite::getSiteObj($site_id)->getReturnsWithinOptions(); $ShippingCostPaidByOptions = WPLE_eBaySite::getSiteObj($site_id)->getShippingCostPaidByOptions(); $prepared_listings = WPLE_ListingQueryHelper::countItemsUsingProfile($item['profile_id'], 'prepared'); $verified_listings = WPLE_ListingQueryHelper::countItemsUsingProfile($item['profile_id'], 'verified'); $published_listings = WPLE_ListingQueryHelper::countItemsUsingProfile($item['profile_id'], 'published'); $ended_listings = WPLE_ListingQueryHelper::countItemsUsingProfile($item['profile_id'], 'ended'); $locked_listings = WPLE_ListingQueryHelper::countItemsUsingProfile($item['profile_id'], 'locked'); // this turned out to be to ressource intensive with 10k listings: // $prepared_listings = WPLE_ListingQueryHelper::getAllPreparedWithProfile( $item['profile_id'] ); // $verified_listings = WPLE_ListingQueryHelper::getAllVerifiedWithProfile( $item['profile_id'] ); // $published_listings = WPLE_ListingQueryHelper::getAllPublishedWithProfile( $item['profile_id'] ); // $ended_listings = WPLE_ListingQueryHelper::getAllEndedWithProfile( $item['profile_id'] ); // $locked_listings = WPLE_ListingQueryHelper::getAllLockedWithProfile( $item['profile_id'] ); // do we have a primary category? $details = $item['details']; if (intval($details['ebay_category_1_id']) != 0) { $primary_category_id = $details['ebay_category_1_id']; } else { // if not use default category $primary_category_id = self::getOption('default_ebay_category_id'); } // fetch updated item specifics for category $specifics = EbayCategoriesModel::getItemSpecificsForCategory($primary_category_id, $site_id, $account_id); // fetch updated available conditions array // $item['conditions'] = $this->fetchItemConditions( $primary_category_id, $item['profile_id'], $item['account_id'] ); $available_conditions = EbayCategoriesModel::getConditionsForCategory($primary_category_id, false, $account_id); // // build available conditions array // $available_conditions = false; // if ( isset( $item['conditions'][ $primary_category_id ] ) ) { // $available_conditions = $item['conditions'][ $primary_category_id ]; // } // // echo "<pre>";print_r($available_conditions);echo"</pre>"; // check if COD is available on the selected site $cod_available = false; foreach ($payment_options as $po) { if ('COD' == $po['payment_name']) { $cod_available = true; } } // fetch available shipping discount profiles $shipping_flat_profiles = array(); $shipping_calc_profiles = array(); $ShippingDiscountProfiles = self::getOption('ShippingDiscountProfiles', array()); if (isset($ShippingDiscountProfiles['FlatShippingDiscount'])) { $shipping_flat_profiles = $ShippingDiscountProfiles['FlatShippingDiscount']; } if (isset($ShippingDiscountProfiles['CalculatedShippingDiscount'])) { $shipping_calc_profiles = $ShippingDiscountProfiles['CalculatedShippingDiscount']; } // echo "<pre>";print_r($shipping_flat_profiles);echo"</pre>"; // get available seller profiles $seller_profiles_enabled = get_option('wplister_ebay_seller_profiles_enabled'); $seller_shipping_profiles = get_option('wplister_ebay_seller_shipping_profiles'); $seller_payment_profiles = get_option('wplister_ebay_seller_payment_profiles'); $seller_return_profiles = get_option('wplister_ebay_seller_return_profiles'); if (isset(WPLE()->accounts[$account_id])) { $account = WPLE()->accounts[$account_id]; $seller_profiles_enabled = $account->seller_profiles; $seller_shipping_profiles = maybe_unserialize($account->shipping_profiles); $seller_payment_profiles = maybe_unserialize($account->payment_profiles); $seller_return_profiles = maybe_unserialize($account->return_profiles); } $aData = array('plugin_url' => self::$PLUGIN_URL, 'message' => $this->message, 'item' => $item, 'site_id' => $site_id, 'account_id' => $account_id, 'payment_options' => $payment_options, 'loc_flat_shipping_options' => $loc_flat_shipping_options, 'int_flat_shipping_options' => $int_flat_shipping_options, 'loc_calc_shipping_options' => $loc_calc_shipping_options, 'int_calc_shipping_options' => $int_calc_shipping_options, 'available_attributes' => $available_attributes, 'custom_attributes' => $wpl_custom_attributes, 'calc_shipping_enabled' => in_array(self::getOption('ebay_site_id'), array(0, 2, 15, 100)), 'default_ebay_category_id' => self::getOption('default_ebay_category_id'), 'shipping_locations' => $shipping_locations, 'exclude_locations' => $exclude_locations, 'countries' => $countries, 'template_files' => $template_files, 'store_categories' => $store_categories, 'prepared_listings_count' => $prepared_listings, 'verified_listings_count' => $verified_listings, 'published_listings_count' => $published_listings, 'ended_listings_count' => $ended_listings, 'locked_listings_count' => $locked_listings, 'total_listings_count' => $prepared_listings + $verified_listings + $published_listings, 'available_dispatch_times' => $available_dispatch_times, 'specifics' => $specifics, 'available_conditions' => $available_conditions, 'available_shipping_packages' => $available_shipping_packages, 'shipping_flat_profiles' => $shipping_flat_profiles, 'shipping_calc_profiles' => $shipping_calc_profiles, 'cod_available' => $cod_available, 'ReturnsWithinOptions' => $ReturnsWithinOptions, 'ShippingCostPaidByOptions' => $ShippingCostPaidByOptions, 'seller_profiles_enabled' => $seller_profiles_enabled, 'seller_shipping_profiles' => $seller_shipping_profiles, 'seller_payment_profiles' => $seller_payment_profiles, 'seller_return_profiles' => $seller_return_profiles, 'form_action' => 'admin.php?page=' . self::ParentMenuId . '-profiles'); $this->display('profiles_edit_page', array_merge($aData, $item)); }
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>'; }