public function getShortProductVariations($post_id) { // update cache if required if (!array_key_exists($post_id, $this->short_variations)) { $this->short_variations[$post_id] = ProductWrapper::getVariations($post_id, true); } return $this->short_variations[$post_id]; }
function column_weight($item) { return ProductWrapper::getWeight($item['post_id']); }
public function ajax_wple_show_product_matches() { // TODO: check nonce if (isset($_REQUEST['id'])) { // $market = WPLA_AmazonMarket::getMarket( $_REQUEST['market_id'] ); $product = get_product($_REQUEST['id']); // echo "<pre>";print_r($product);echo"</pre>"; if ($product) { $product_attributes = ProductWrapper::getAttributes($product->id, true); $wpl_default_matcher_selection = get_option('wple_default_matcher_selection', 'title'); switch ($wpl_default_matcher_selection) { case 'title': # product title $query = $product->post->post_title; break; case 'sku': # product sku $query = $product->sku; break; default: # else check for attributes foreach ($product_attributes as $attribute_label => $attribute_value) { if ($attribute_label == $wpl_default_matcher_selection) { $query = $attribute_value; } } break; } // echo '<h2>'.$query.'</h2>'; // fall back to title when query is empty if (empty($query)) { $query = $product->post->post_title; } // handle custom query if (isset($_REQUEST['query'])) { $query = trim($_REQUEST['query']); } // get product attributes - if possible from cache $transient_key = 'wple_product_match_results_' . sanitize_key($query); $products = get_transient($transient_key); if (empty($products)) { // call API $this->initEC(); $products = $this->EC->callFindProducts($query); $this->EC->closeEbay(); if (is_array($products)) { // save cache set_transient($transient_key, $products, 300); } // echo "<pre>";print_r($transient_key);echo"</pre>";#die(); } // echo "<pre>products: ";print_r($products);echo"</pre>";#die(); // get market / site domain - for "view" links // $market = new WPLA_AmazonMarket( $account->market_id ); if (is_array($products)) { // load template $tpldata = array('plugin_url' => self::$PLUGIN_URL, 'message' => $this->message, 'query' => $query, 'query_product' => $product, 'query_product_attributes' => $product_attributes, 'products' => $products, 'post_id' => $_REQUEST['id'], 'query_select' => isset($_REQUEST['query_select']) ? $_REQUEST['query_select'] : false, 'form_action' => 'admin.php?page=' . self::ParentMenuId); WPLE()->pages['listings']->display('match_product', $tpldata); // } elseif ( $product->Error->Message ) { // $errors = sprintf( __('There was a problem fetching product details for %s.','wpla'), $product->post->post_title ) .'<br>Error: '. $reports->Error->Message; } else { $errors = sprintf(__('There were no products found for query %s.', 'wpla'), $query); echo $errors; } exit; } else { echo "invalid product"; } } }
function collect_updated_products($post_id, $post) { WPLE()->logger->info("CSV: collect_updated_products( {$post_id} )"); if (!$_POST) { return $post_id; } // if ( is_int( wp_is_post_revision( $post_id ) ) ) return; // if( is_int( wp_is_post_autosave( $post_id ) ) ) return; // if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) return $post_id; if (!current_user_can('edit_post', $post_id)) { return $post_id; } if (!in_array($post->post_type, array('product', 'product_variation'))) { return $post_id; } // if this is a single variation use parent_id // if ( $parent_id = ProductWrapper::getVariationParent( $post_id ) ) { if ($post->post_type == 'product_variation') { $parent_id = ProductWrapper::getVariationParent($post_id); // WPLE()->logger->info("single variation found - use parent $parent_id for $post_id"); $post_id = $parent_id; } // get queue $collected_products = get_option('wplister_updated_products_queue', array()); if (!is_array($collected_products)) { $collected_products = array(); } // add product_id to queue - if it doesn't exist if (!in_array($post_id, $collected_products)) { $collected_products[] = $post_id; } // WPLE()->logger->info("collected products: ".print_r($collected_products,1)); // update queue update_option('wplister_updated_products_queue', $collected_products); }
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; }
public function revertTransaction($id) { global $wpdb; // get transaction record $transaction = $this->getItem($id); if (!$transaction) { return false; } // restore listing's quantity_sold // get current values from db $quantity_purchased = $transaction['quantity']; $quantity_sold = $wpdb->get_var($wpdb->prepare("SELECT quantity_sold FROM {$wpdb->prefix}ebay_auctions WHERE ebay_id = %s", $transaction['item_id'])); // decrease the listing's quantity_sold $quantity_sold = $quantity_sold - $quantity_purchased; $wpdb->update($wpdb->prefix . 'ebay_auctions', array('quantity_sold' => $quantity_sold), array('ebay_id' => $transaction['item_id'])); // check if we need to restore product stock list($reduced_product_id, $new_stock_value) = $this->checkIfStockWasReducedForItemID($transaction); if ($reduced_product_id) { // echo "<pre>stock was reduced to ";print_r($new_stock_value);echo"</pre>";#die(); // restore product stock $newstock = ProductWrapper::increaseStockBy($reduced_product_id, $transaction['quantity']); $this->addHistory($transaction['transaction_id'], 'restored_stock', 'Product stock was restored', array('product_id' => $reduced_product_id, 'newstock' => $newstock)); } // update status $this->updateById($id, array('status' => 'reverted')); $this->addHistory($transaction['transaction_id'], 'revert_transaction', 'Transaction was reverted'); return true; }
function getVariationsHTML($item) { $profile_data = ListingsModel::decodeObject($item['profile_data'], true); $variations = ProductWrapper::getVariations($item['post_id']); $variations_html = '<div class="variations_list" style="margin:10px 0;">'; $variations_html .= '<table style="margin-bottom: 8px;">'; //table header if (true) { // first column: quantity $variations_html .= '<tr>'; $first_variation = reset($variations); if (is_array($first_variation['variation_attributes'])) { foreach ($first_variation['variation_attributes'] as $name => $value) { $variations_html .= '<th>'; $variations_html .= $name; $variations_html .= '</th>'; } } // last column: price $variations_html .= '<th align="right">'; $variations_html .= __('Price', 'wplister'); $variations_html .= '</th></tr>'; } //table body foreach ($variations as $var) { // first column: quantity // $variations_html .= '<tr><td align="right">'; // $variations_html .= intval( $var['stock'] ) . ' x'; // $variations_html .= '</td><td>'; $variations_html .= '<tr>'; foreach ($var['variation_attributes'] as $name => $value) { // $variations_html .= $name.': '.$value ; $variations_html .= '<td>'; $variations_html .= $value; $variations_html .= '</td>'; } // $variations_html .= '('.$var['sku'].') '; // $variations_html .= '('.$var['image'].') '; // last column: price $variations_html .= '<td align="right">'; $price = ListingsModel::applyProfilePrice($var['price'], $profile_data['details']['start_price']); $variations_html .= number_format_i18n(floatval($price), 2); $variations_html .= '</td></tr>'; } $variations_html .= '</table>'; $variations_html .= '</div>'; // return html return $variations_html; }
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)); }
public function checkSoldStock() { // get all sold listings $listings = WPLE_ListingQueryHelper::getAllWithStatus('sold'); $out_of_stock_products = array(); // process published listings foreach ($listings as $item) { // get wc product $_product = ProductWrapper::getProduct($item['post_id']); // check stock level // $stock = ProductWrapper::getStock( $item['post_id'] ); $stock = $_product ? $_product->get_total_stock() : 0; if ($stock == 0) { continue; } // mark listing as changed // if ( isset( $_REQUEST['mark_as_changed'] ) && $_REQUEST['mark_as_changed'] == 'yes' ) { // ListingsModel::updateListing( $item['id'], array( 'status' => 'changed' ) ); // $item['status'] = 'changed'; // } // add to list of out of stock products $item['stock'] = $stock; $item['exists'] = $_product ? true : false; $out_of_stock_products[] = $item; } // return if empty if (empty($out_of_stock_products)) { $this->showMessage('No sold products have stock in WooCommerce.', 0, 1); return; } $msg = '<p>'; $msg .= 'Warning: Some sold listings are still in stock in WooCommerce.'; $msg .= '</p>'; // table header $msg .= '<table style="width:100%">'; $msg .= "<tr>"; $msg .= "<th style='text-align:left'>Stock</th>"; $msg .= "<th style='text-align:left'>SKU</th>"; $msg .= "<th style='text-align:left'>Product</th>"; $msg .= "<th style='text-align:left'>Qty</th>"; $msg .= "<th style='text-align:left'>eBay ID</th>"; $msg .= "<th style='text-align:left'>Ended at</th>"; $msg .= "<th style='text-align:left'>Status</th>"; $msg .= "</tr>"; // table rows foreach ($out_of_stock_products as $item) { // get column data $qty = $item['quantity'] - $item['quantity_sold']; $sku = get_post_meta($item['post_id'], '_sku', true); $stock = $item['stock'] . ' x '; $title = $item['auction_title']; $post_id = $item['post_id']; $ebay_id = $item['ebay_id']; $status = $item['status']; $exists = $item['exists']; $date_ended = $item['date_finished'] ? $item['date_finished'] : $item['end_date']; // build links $ebay_url = $item['ViewItemURL'] ? $item['ViewItemURL'] : ($ebay_url = 'http://www.ebay.com/itm/' . $ebay_id); $ebay_link = '<a href="' . $ebay_url . '" target="_blank">' . $ebay_id . '</a>'; $edit_link = '<a href="post.php?action=edit&post=' . $post_id . '" target="_blank">' . $title . '</a>'; // mark non existent products if (!$exists) { $stock = 'N/A'; $post_id .= ' missing!'; } // build table row $msg .= "<tr>"; $msg .= "<td>{$stock}</td>"; $msg .= "<td>{$sku}</td>"; $msg .= "<td>{$edit_link} (ID {$post_id})</td>"; $msg .= "<td>{$qty} x </td>"; $msg .= "<td>{$ebay_link}</td>"; $msg .= "<td>{$date_ended}</td>"; $msg .= "<td>{$status}</td>"; $msg .= "</tr>"; } $msg .= '</table>'; // show 'check again' button $msg .= '<p>'; $url = 'admin.php?page=wplister-tools&action=check_wc_sold_stock&_wpnonce=' . wp_create_nonce('e2e_tools_page'); $msg .= '<a href="' . $url . '" class="button">' . __('Check again', 'wplister') . '</a> '; $msg .= '</p>'; // $msg .= '<p>'; // $url = 'admin.php?page=wplister-tools&action=check_wc_out_of_stock&mark_as_changed=yes&_wpnonce='.wp_create_nonce('e2e_tools_page'); // $msg .= '<a href="'.$url.'" class="button">'.__('Mark all as changed','wplister').'</a> '; // $msg .= 'Click this button to mark all found listings as changed in WP-Lister, then revise all changed listings.'; // $msg .= '</p>'; $this->showMessage($msg, 1, 1); }
public function applyProfileToItem($profile, $item, $update_title = true) { global $wpdb; // get item data $id = $item['id']; $post_id = $item['post_id']; $status = WPLE_ListingQueryHelper::getStatus($id); $ebay_id = self::getEbayIDFromID($id); $post_title = get_the_title($item['post_id']); WPLE()->logger->info("applyProfileToItem() - listing_id: {$id} / post_id: {$post_id}"); // WPLE()->logger->callStack( debug_backtrace() ); // skip ended auctions - or not, if you want to relist them... // if ( $status == 'ended' ) return; // use parent title for single (split) variation if (ProductWrapper::isSingleVariation($post_id)) { $parent_id = ProductWrapper::getVariationParent($post_id); $post_title = get_the_title($parent_id); // check if parent product has a custom eBay title set if (get_post_meta($parent_id, '_ebay_title', true)) { $post_title = trim(get_post_meta($parent_id, '_ebay_title', true)); } // get variations $variations = ProductWrapper::getVariations($parent_id); // find this variation in all variations of this parent foreach ($variations as $var) { if ($var['post_id'] == $post_id) { // append attribute values to title $post_title = self::processSingleVariationTitle($post_title, $var['variation_attributes']); } } } // gather profile data $data = array(); $data['profile_id'] = $profile['profile_id']; $data['account_id'] = $profile['account_id']; $data['site_id'] = $profile['site_id']; $data['auction_type'] = $profile['type']; $data['listing_duration'] = $profile['listing_duration']; $data['template'] = $profile['details']['template']; $data['quantity'] = $profile['details']['quantity']; $data['date_created'] = date('Y-m-d H:i:s'); $data['profile_data'] = self::encodeObject($profile); // echo "<pre>";print_r($data);echo"</pre>";die(); // add prefix and suffix to product title if ($update_title) { // append space to prefix, prepend space to suffix // TODO: make this an option $title_prefix = trim($profile['details']['title_prefix']) . ' '; $title_suffix = ' ' . trim($profile['details']['title_suffix']); // custom post meta fields override profile values if (get_post_meta($post_id, 'ebay_title_prefix', true)) { $title_prefix = trim(get_post_meta($post_id, 'ebay_title_prefix', true)) . ' '; } if (get_post_meta($post_id, 'ebay_title_suffix', true)) { $title_prefix = trim(get_post_meta($post_id, 'ebay_title_suffix', true)) . ' '; } $data['auction_title'] = trim($title_prefix . $post_title . $title_suffix); // custom post meta title override if (get_post_meta($post_id, '_ebay_title', true)) { $data['auction_title'] = trim(get_post_meta($post_id, '_ebay_title', true)); } elseif (get_post_meta($post_id, 'ebay_title', true)) { $data['auction_title'] = trim(get_post_meta($post_id, 'ebay_title', true)); } // process attribute shortcodes in title - like [[attribute_Brand]] if (strpos($data['auction_title'], ']]') > 0) { $templatesModel = new TemplatesModel(); WPLE()->logger->info('auction_title before processing: ' . $data['auction_title'] . ''); $data['auction_title'] = $templatesModel->processAllTextShortcodes($item['post_id'], $data['auction_title'], 80); } WPLE()->logger->info('auction_title after processing : ' . $data['auction_title'] . ''); // trim title to 255 characters - longer titles will break $wpdb->update() if (strlen($data['auction_title']) > 255) { $data['auction_title'] = self::mb_substr($data['auction_title'], 0, 80); // eBay titles can not be longer than 80 characters } } // apply profile price $data['price'] = ProductWrapper::getPrice($post_id); $data['price'] = self::applyProfilePrice($data['price'], $profile['details']['start_price']); // fetch product stock if no quantity set in profile - and apply max_quantity limit if (intval($data['quantity']) == 0) { $max = isset($profile['details']['max_quantity']) && intval($profile['details']['max_quantity']) > 0 ? $profile['details']['max_quantity'] : PHP_INT_MAX; $data['quantity'] = min($max, intval(ProductWrapper::getStock($post_id))); // update listing quantity properly - using setListingQuantity() which regards current quantity_sold self::setListingQuantity($post_id, $data['quantity']); unset($data['quantity']); } // default new status is 'prepared' $data['status'] = 'prepared'; // except for already published items where it is 'changed' if (intval($ebay_id) > 0) { $data['status'] = 'changed'; } // ended items stay 'ended' and sold items stay sold if ($status == 'ended') { $data['status'] = 'ended'; } if ($status == 'sold') { $data['status'] = 'sold'; } if ($status == 'archived') { $data['status'] = 'archived'; } // locked items simply keep their status if (@$item['locked']) { $data['status'] = $status; } // but if apply_changes_to_all_locked checkbox is ticked, even locked published items will be marked as 'changed' if (@$item['locked'] && $status == 'published' && isset($_POST['wpl_e2e_apply_changes_to_all_locked'])) { $data['status'] = 'changed'; } // except for selected items which shouldn't be locked in the first place if ($status == 'selected') { $data['status'] = 'prepared'; } // and reselected items which have already been 'ended' if ($status == 'reselected') { $data['status'] = 'ended'; } // and items which have already been 'changed' and now had a new profile applied if ($status == 'changed_profile') { $data['status'] = 'changed'; } // debug if ($status != $data['status']) { WPLE()->logger->info('applyProfileToItem(' . $id . ') old status: ' . $status); WPLE()->logger->info('applyProfileToItem(' . $id . ') new status: ' . $data['status']); } // update auctions table $wpdb->update($this->tablename, $data, array('id' => $id)); // WPLE()->logger->info('updating listing ID '.$id); // WPLE()->logger->info('data: '.print_r($data,1)); // WPLE()->logger->info('sql: '.$wpdb->last_query); // WPLE()->logger->info('error: '.$wpdb->last_error); }
public function getProductImagesURL($id) { global $wpdb; $results = $wpdb->get_results($wpdb->prepare(" \n\t\t\tSELECT id, guid \n\t\t\tFROM {$wpdb->prefix}posts\n\t\t\tWHERE post_type = 'attachment' \n\t\t\t AND post_parent = %s\n\t\t\tORDER BY menu_order\n\t\t", $id)); WPLE()->logger->debug("getProductImagesURL( {$id} ) : " . print_r($results, 1)); #echo "<pre>";print_r($results);echo"</pre>";#die(); // fetch images using default size $size = get_option('wplister_default_image_size', 'full'); $images = array(); foreach ($results as $row) { // $url = wp_get_attachment_url( $row->id, $size ); $url = $row->guid ? $row->guid : wp_get_attachment_url($row->id, $size); $images[] = $url; } // support for WooCommerce 2.0 Product Gallery if (get_option('wplister_wc2_gallery_fallback', 'none') == 'none') { $images = array(); } // discard images if fallback is disabled $product_image_gallery = get_post_meta($id, '_product_image_gallery', true); // use parent product for single (split) variation if (ProductWrapper::isSingleVariation($id)) { $parent_id = ProductWrapper::getVariationParent($id); $product_image_gallery = get_post_meta($parent_id, '_product_image_gallery', true); } if ($product_image_gallery) { // build clean array with main image as first item $images = array(); $images[] = $this->getProductMainImageURL($id); $image_ids = explode(',', $product_image_gallery); foreach ($image_ids as $image_id) { $url = wp_get_attachment_url($image_id, $size); if ($url && !in_array($url, $images)) { $images[] = $url; } } WPLE()->logger->info("found WC2 product gallery images for product #{$id} " . print_r($images, 1)); } $product_images = array(); foreach ($images as $imageurl) { $product_images[] = $this->removeHttpsFromUrl($imageurl); } // call wplister_product_images filter // hook into this from your WP theme's functions.php - this won't work in listing templates! $product_images = apply_filters('wplister_product_images', $product_images, $id); return $product_images; }
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>'; }
<?php foreach ($items as $item) { ?> <a href="<?php echo $item['ViewItemURL']; ?> " title="<?php echo $item['auction_title']; ?> " target="_top"> <div class="thumb"> <!-- <img src="<?php echo ProductWrapper::getImageURL($item['post_id']); ?> " alt="<?php echo $item['auction_title']; ?> " /> --> <img src="<?php echo $item['GalleryURL']; ?> " alt="<?php echo $item['auction_title']; ?> " /> </div> <div class="title"><?php