function mapItemDetailToDB($Detail, $always_process_foreign_transactions = false) { //#type $Detail TransactionType // echo "<pre>";print_r($Detail);echo"</pre>";#die(); $data['item_id'] = $Detail->Item->ItemID; $data['transaction_id'] = $Detail->TransactionID; $data['date_created'] = self::convertEbayDateToSql($Detail->CreatedDate); $data['price'] = $Detail->TransactionPrice->value; $data['quantity'] = $Detail->QuantityPurchased; $data['buyer_userid'] = @$Detail->Buyer->UserID; $data['buyer_name'] = @$Detail->Buyer->RegistrationAddress->Name; $data['buyer_email'] = @$Detail->Buyer->Email; $data['eBayPaymentStatus'] = $Detail->Status->eBayPaymentStatus; $data['CheckoutStatus'] = $Detail->Status->CheckoutStatus; $data['ShippingService'] = @$Detail->ShippingServiceSelected->ShippingService; //$data['ShippingAddress_Country'] = $Detail->Buyer->BuyerInfo->ShippingAddress->Country; //$data['ShippingAddress_Zip'] = $Detail->Buyer->BuyerInfo->ShippingAddress->PostalCode; $data['ShippingAddress_City'] = @$Detail->Buyer->BuyerInfo->ShippingAddress->CityName; $data['PaymentMethod'] = $Detail->Status->PaymentMethodUsed; $data['CompleteStatus'] = $Detail->Status->CompleteStatus; $data['LastTimeModified'] = self::convertEbayDateToSql($Detail->Status->LastTimeModified); $data['OrderLineItemID'] = $Detail->OrderLineItemID; $data['site_id'] = $this->site_id; $data['account_id'] = $this->account_id; $auction_item = ListingsModel::getItemByEbayID($Detail->Item->ItemID); // skip items not found in listings if ($listingItem) { $data['post_id'] = $listingItem->post_id; $data['item_title'] = $listingItem->auction_title; WPLE()->logger->info("process transaction #" . $Detail->TransactionID . " for item '" . $data['item_title'] . "' - #" . $Detail->Item->ItemID); WPLE()->logger->info("post_id: " . $data['post_id']); } else { $data['post_id'] = false; $data['item_title'] = $Detail->Item->Title; // only skip if foreign_transactions option is disabled if (get_option('wplister_foreign_transactions') != 1 && !$always_process_foreign_transactions) { WPLE()->logger->info("skipped transaction #" . $Detail->TransactionID . " for foreign item #" . $Detail->Item->ItemID); $this->addToReport('skipped', $data); return false; } else { WPLE()->logger->info("IMPORTED transaction #" . $Detail->TransactionID . " for foreign item #" . $Detail->Item->ItemID); } } // avoid empty transaction id if (intval($data['transaction_id']) == 0) { // use negative OrderLineItemID to separate from real TransactionIDs $data['transaction_id'] = 0 - str_replace('-', '', $data['OrderLineItemID']); } // use buyer name from shipping address if registration address is empty if ($data['buyer_name'] == '') { $data['buyer_name'] = @$Detail->Buyer->BuyerInfo->ShippingAddress->Name; } // save GetSellerTransactions reponse in details $data['details'] = self::encodeObject($Detail); return $data; }
function wpla_inventory_status_changed($post_id) { // re-apply profile to update ebay_auctions table $lm = new ListingsModel(); $listing_id = $lm->markItemAsModified($post_id); // $this->wplister_revise_inventory_status( $post_id ); do_action('wplister_revise_inventory_status', $post_id); }
public function showSiteDetails($id) { // init model $sitesModel = new SitesModel(); // get transaction record $transaction = $sitesModel->getItem($id); // get auction item record $auction_item = ListingsModel::getItemByEbayID($transaction['item_id']); $aData = array('transaction' => $transaction, 'auction_item' => $auction_item); $this->display('transaction_details', $aData); }
private function saveProfile() { global $wpdb; $details = $this->getPreprocessedPostDetails(); $profile_id = $this->getValueFromPost('profile_id'); $account_id = $this->getValueFromPost('account_id'); if (!$account_id) { $account_id = get_option('wplister_default_account_id'); } // fix entered prices $details = self::fixProfilePrices($details); // process item specifics $item_specifics = array(); $itmSpecs_name = @$_POST['itmSpecs_name']; $itmSpecs_value = @$_POST['itmSpecs_value']; $itmSpecs_attrib = @$_POST['itmSpecs_attrib']; if (is_array($itmSpecs_name)) { foreach ($itmSpecs_name as $key => $name) { #$name = str_replace('\\\\', '', $name ); $name = stripslashes($name); $value = trim($itmSpecs_value[$key]); $attribute = trim($itmSpecs_attrib[$key]); if ($value != '' || $attribute != '') { $spec = new stdClass(); $spec->name = $name; $spec->value = $value; $spec->attribute = $attribute; $item_specifics[] = $spec; } } } $details['item_specifics'] = $item_specifics; // add category names $details['ebay_category_1_name'] = EbayCategoriesModel::getCategoryName($details['ebay_category_1_id']); $details['ebay_category_2_name'] = EbayCategoriesModel::getCategoryName($details['ebay_category_2_id']); $details['store_category_1_name'] = EbayCategoriesModel::getStoreCategoryName($details['store_category_1_id']); $details['store_category_2_name'] = EbayCategoriesModel::getStoreCategoryName($details['store_category_2_id']); // fix prices - already done in fixProfilePrices() // $details['start_price'] = str_replace(',', '.', $details['start_price'] ); // $details['fixed_price'] = str_replace(',', '.', $details['fixed_price'] ); // if the user enters only fixed price but no start price, move fixed price to start price if ($details['start_price'] == '' && $details['fixed_price'] != '') { $details['start_price'] = $details['fixed_price']; $details['fixed_price'] = ''; } // fix quantities if (!$details['custom_quantity_enabled']) { $details['quantity'] = ''; $details['max_quantity'] = ''; } // do we have a primary category? 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'); } // // do we have ConditionDetails for primary category? // // $conditions = $this->fetchItemConditions( $primary_category_id, $profile_id, $account_id ); // $conditions = EbayCategoriesModel::getConditionsForCategory( $primary_category_id, false, $account_id ); // // do we have item specifics for primary category? // if ( intval($profile_id) != 0 ) { // // $saved_specifics = $wpdb->get_var('SELECT category_specifics FROM '.$wpdb->prefix.'ebay_profiles WHERE profile_id = '.$profile_id); // $saved_specifics = $wpdb->get_var( $wpdb->prepare( "SELECT category_specifics FROM {$wpdb->prefix}ebay_profiles WHERE profile_id = %d", $profile_id ) ); // $saved_specifics = unserialize($saved_specifics); // } // // fetch required item specifics for primary category // if ( ( isset( $saved_specifics[ $primary_category_id ] ) ) && ( $saved_specifics[ $primary_category_id ] != 'none' ) ) { // $specifics = $saved_specifics; // } elseif ( (int)$primary_category_id != 0 ) { // $this->initEC( $account_id ); // $specifics = $this->EC->getCategorySpecifics( $primary_category_id ); // $this->EC->closeEbay(); // } else { // $specifics = array(); // } // // do we have item specifics for primary category? // (improved version of the above, using ebay_categories as cache) // $specifics = EbayCategoriesModel::getItemSpecificsForCategory( $primary_category_id, false, $account_id ); // // $specifics = array( $primary_category_id => $specifics ); if (WPLISTER_LIGHT) { $specifics = array(); } // sql columns $item = array(); $item['profile_id'] = $profile_id; $item['profile_name'] = $this->getValueFromPost('profile_name'); $item['profile_description'] = $this->getValueFromPost('profile_description'); $item['listing_duration'] = $this->getValueFromPost('listing_duration'); $item['type'] = $this->getValueFromPost('auction_type'); $item['sort_order'] = intval($this->getValueFromPost('sort_order')); $item['details'] = json_encode($details); // $item['conditions'] = serialize( $conditions ); // deprecated // $item['category_specifics'] = serialize( $specifics ); // deprecated $item['conditions'] = ''; $item['category_specifics'] = ''; $item['account_id'] = $account_id; $item['site_id'] = WPLE()->accounts[$item['account_id']]->site_id; // insert or update if ($item['profile_id'] == 0) { // insert new profile unset($item['profile_id']); $result = $wpdb->insert($wpdb->prefix . 'ebay_profiles', $item); } else { // update profile $result = $wpdb->update($wpdb->prefix . 'ebay_profiles', $item, array('profile_id' => $item['profile_id'])); } // proper error handling if ($result === false) { $this->showMessage("There was a problem saving your profile.<br>SQL:<pre>" . $wpdb->last_query . '</pre>' . $wpdb->last_error, true); } else { $this->showMessage(__('Profile saved.', 'wplister')); // if we were updating this template as part of setup, move to next step if ('4' == self::getOption('setup_next_step')) { self::updateOption('setup_next_step', 5); } } // if this is a new profile, skip further processing if (!$profile_id) { return; } // handle delayed update option if (isset($_POST['wple_delay_profile_application'])) { update_option('wple_job_reapply_profile_id', $profile_id); return; } // prepare for updating items $listingsModel = new ListingsModel(); $profilesModel = new ProfilesModel(); $profile = $profilesModel->getItem($this->getValueFromPost('profile_id')); // re-apply profile to all prepared if ($this->getValueFromPost('apply_changes_to_all_prepared') == 'yes') { $items = WPLE_ListingQueryHelper::getAllPreparedWithProfile($item['profile_id']); $listingsModel->applyProfileToItems($profile, $items); $this->showMessage(sprintf(__('%s prepared items updated.', 'wplister'), count($items))); } // re-apply profile to all verified if ($this->getValueFromPost('apply_changes_to_all_verified') == 'yes') { $items = WPLE_ListingQueryHelper::getAllVerifiedWithProfile($item['profile_id']); $listingsModel->applyProfileToItems($profile, $items); $this->showMessage(sprintf(__('%s verified items updated.', 'wplister'), count($items))); } // re-apply profile to all published if ($this->getValueFromPost('apply_changes_to_all_published') == 'yes') { $items = WPLE_ListingQueryHelper::getAllPublishedWithProfile($item['profile_id']); $listingsModel->applyProfileToItems($profile, $items); $this->showMessage(sprintf(__('%s published items changed.', 'wplister'), count($items))); } // re-apply profile to all ended if ($this->getValueFromPost('apply_changes_to_all_ended') == 'yes') { $items = WPLE_ListingQueryHelper::getAllEndedWithProfile($item['profile_id']); $listingsModel->applyProfileToItems($profile, $items); $this->showMessage(sprintf(__('%s ended items updated.', 'wplister'), count($items))); // update ended listings - required for autorelist to be applied // $listingsModel->updateEndedListings(); $this->initEC($account_id); $this->EC->updateListings(); $this->EC->closeEbay(); } }
static function getItemsForGallery($type = 'new', $related_to_id, $limit = 12) { global $wpdb; $table = $wpdb->prefix . self::TABLENAME; // get listing item $listing = ListingsModel::getItem($related_to_id); switch ($type) { case 'ending': $wpdb->query("SET time_zone='+0:00'"); // tell SQL to use GMT $where_sql = "WHERE status = 'published' AND end_date < NOW()"; $order_sql = "ORDER BY end_date DESC"; break; case 'featured': $where_sql = "\tJOIN {$wpdb->prefix}postmeta pm ON ( li.post_id = pm.post_id )\n\t\t\t\t\t\t\t\tWHERE status = 'published' \n\t\t\t\t\t\t\t\t AND pm.meta_key = '_featured'\n\t\t\t\t\t\t\t\t AND pm.meta_value = 'yes'\n\t\t\t\t\t\t\t"; $order_sql = "ORDER BY date_published, end_date DESC"; break; case 'related': // combines upsell and crossell $upsell_ids = get_post_meta($listing['post_id'], '_upsell_ids', true); $crosssell_ids = get_post_meta($listing['post_id'], '_crosssell_ids', true); $inner_where_sql = '1 = 0'; if (is_array($upsell_ids)) { foreach ($upsell_ids as $post_id) { $post_id = esc_sql($post_id); $inner_where_sql .= ' OR post_id = "' . $post_id . '" '; } } if (is_array($crosssell_ids)) { foreach ($crosssell_ids as $post_id) { $post_id = esc_sql($post_id); $inner_where_sql .= ' OR post_id = "' . $post_id . '" '; } } $where_sql = "\tWHERE status = 'published' \n\t\t\t\t\t\t\t\t AND ( {$inner_where_sql} )\n\t\t\t\t\t\t\t"; $order_sql = "ORDER BY date_published, end_date DESC"; break; case 'new': default: $where_sql = "WHERE status = 'published' "; $order_sql = "ORDER BY date_published DESC"; break; } // make sure returned items use same account as reference listing if ($listing) { $where_sql .= ' AND li.account_id = ' . $listing['account_id']; } $limit = esc_sql($limit); $items = $wpdb->get_results("\n\t\t\tSELECT DISTINCT li.*\n\t\t\tFROM {$table} li\n\t\t\t{$where_sql}\n\t\t\t{$order_sql}\n\t\t\tLIMIT {$limit}\n\t\t", ARRAY_A); // echo "<pre>";print_r($wpdb->last_query);echo"</pre>";#die(); if ($type == 'ending') { $wpdb->query("SET time_zone='SYSTEM'"); } // revert back to original return $items; }
function processListingItem($order_id, $ebay_id, $quantity_purchased, $data, $VariationSpecifics, $Transaction) { global $wpdb; $has_been_replenished = false; // check if this listing exists in WP-Lister $listing_id = $wpdb->get_var($wpdb->prepare("SELECT id FROM {$wpdb->prefix}ebay_auctions WHERE ebay_id = %s", $ebay_id)); if (!$listing_id) { $history_message = "Skipped foreign item #{$ebay_id}"; $history_details = array('ebay_id' => $ebay_id); $this->addHistory($order_id, 'skipped_item', $history_message, $history_details); return; } // get current values from db // $quantity_purchased = $data['quantity']; $quantity_total = $wpdb->get_var($wpdb->prepare("SELECT quantity FROM {$wpdb->prefix}ebay_auctions WHERE ebay_id = %s", $ebay_id)); $quantity_sold = $wpdb->get_var($wpdb->prepare("SELECT quantity_sold FROM {$wpdb->prefix}ebay_auctions WHERE ebay_id = %s", $ebay_id)); // increase 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' => $ebay_id)); // add history record $history_message = "Sold quantity increased by {$quantity_purchased} for listing #{$ebay_id} - sold {$quantity_sold}"; $history_details = array('ebay_id' => $ebay_id, 'quantity_sold' => $quantity_sold, 'quantity_total' => $quantity_total); $this->addHistory($order_id, 'reduce_stock', $history_message, $history_details); // mark listing as sold when last item is sold - unless Out Of Stock Control (oosc) is enabled if (!ListingsModel::thisAccountUsesOutOfStockControl($data['account_id'])) { if ($quantity_sold == $quantity_total && !$has_been_replenished) { // make sure this product is out of stock before we mark listing as sold - free version excluded $listing_item = ListingsModel::getItem($listing_id); if (WPLISTER_LIGHT || ListingsModel::checkStockLevel($listing_item) == false) { $wpdb->update($wpdb->prefix . 'ebay_auctions', array('status' => 'sold', 'date_finished' => $data['date_created']), array('ebay_id' => $ebay_id)); WPLE()->logger->info('marked item #' . $ebay_id . ' as SOLD '); } } } }
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; }
function wplister_product_handle_submitbox_actions($post_id, $post) { if (isset($_POST['wpl_ebay_revise_on_update'])) { // call markItemAsModified() to re-apply the listing profile $lm = new ListingsModel(); $lm->markItemAsModified($post_id); WPLE()->logger->info('revising listing ' . $_POST['wpl_ebay_listing_id']); // call EbayController WPLE()->initEC(); $results = WPLE()->EC->reviseItems($_POST['wpl_ebay_listing_id']); WPLE()->EC->closeEbay(); WPLE()->logger->info('revised listing ' . $_POST['wpl_ebay_listing_id']); // $message = __('Selected items were revised on eBay.', 'wplister'); // $message .= ' ID: '.$_POST['wpl_ebay_listing_id']; // $class = (false) ? 'error' : 'updated'; // echo '<div id="message" class="'.$class.'" style="display:block !important"><p>'.$message.'</p></div>'; } if (isset($_POST['wpl_ebay_relist_on_update'])) { // call markItemAsModified() to re-apply the listing profile $lm = new ListingsModel(); $lm->markItemAsModified($post_id); WPLE()->logger->info('relisting listing ' . $_POST['wpl_ebay_listing_id']); // call EbayController WPLE()->initEC(); $results = WPLE()->EC->relistItems($_POST['wpl_ebay_listing_id']); WPLE()->EC->closeEbay(); WPLE()->logger->info('relisted listing ' . $_POST['wpl_ebay_listing_id']); // $message = __('Selected items were revised on eBay.', 'wplister'); // $message .= ' ID: '.$_POST['wpl_ebay_listing_id']; // $class = (false) ? 'error' : 'updated'; // echo '<div id="message" class="'.$class.'" style="display:block !important"><p>'.$message.'</p></div>'; } }
private function saveTemplate() { // set templates root folder $upload_dir = wp_upload_dir(); $templates_dir = $upload_dir['basedir'] . '/wp-lister/templates/'; // handle add_new_template // if ( $this->getValueFromPost('add_new_template') == 1 ) { if (isset($_REQUEST['wpl_add_new_template'])) { // check folder name $dirname = strtolower(sanitize_file_name($this->getValueFromPost('template_name'))); if ($dirname == '') { $this->showMessage("Could not create template. No template name was provided.", 1); return false; } // tpl_dir is the full path to the template $tpl_dir = $templates_dir . $dirname; // if folder exists, append '-1', '-2', .. '-99' if (is_dir($tpl_dir)) { for ($i = 1; $i < 100; $i++) { $new_tpl_dir = $tpl_dir . '-' . $i; if (!is_dir($new_tpl_dir)) { $tpl_dir = $new_tpl_dir; break; } } } // make new folder $result = @mkdir($tpl_dir); // handle errors if ($result === false) { $this->showMessage("Could not create template folder: " . $tpl_dir, 1); return false; } else { $this->showMessage(__('New template created in folder:', 'wplister') . ' ' . basename($tpl_dir)); } // init default template to handle setting $templatesModel = new TemplatesModel(); $templatesModel->folderpath = WPLISTER_PATH . '/templates/default/'; $templatesModel->initTemplate(); // save existing template } else { $dirname = $this->getValueFromPost('template_id'); $tpl_dir = $templates_dir . $dirname; $changed = 0; // re-apply profile to all published $listingsModel = new ListingsModel(); $items = WPLE_ListingQueryHelper::getAllPublishedWithTemplate($dirname); if (!empty($items)) { foreach ($items as $item) { // don't mark locked items as changed if (!$item['locked']) { // ListingsModel::updateListing( $item['id'], array('status' => 'changed') ); // for some reason, this was messing up quantities $listingsModel->reapplyProfileToItem($item['id']); $changed++; } } $this->showMessage(sprintf(__('%s published items marked as changed.', 'wplister'), $changed)); } // init template to handle setting $templatesModel = new TemplatesModel($dirname); $templatesModel->initTemplate(); } // destination files $file_html = $tpl_dir . '/template.html'; $file_css = $tpl_dir . '/style.css'; $file_header = $tpl_dir . '/header.php'; $file_footer = $tpl_dir . '/footer.php'; $file_functions = $tpl_dir . '/functions.php'; $file_settings = $tpl_dir . '/config.json'; $tpl_html = stripslashes($this->getValueFromPost('tpl_html')); $tpl_css = stripslashes($this->getValueFromPost('tpl_css')); $tpl_header = stripslashes($this->getValueFromPost('tpl_header')); $tpl_footer = stripslashes($this->getValueFromPost('tpl_footer')); $tpl_functions = stripslashes($this->getValueFromPost('tpl_functions')); $template_name = stripslashes($this->getValueFromPost('template_name')); $template_description = stripslashes($this->getValueFromPost('template_description')); $template_version = stripslashes($this->getValueFromPost('template_version')); // strip CDATA tags $tpl_html = $this->stripCDATA($tpl_html); $tpl_header = $this->stripCDATA($tpl_header); $tpl_footer = $this->stripCDATA($tpl_footer); // handle custom fields settings $settings = array(); if (is_array($templatesModel->fields)) { foreach ($templatesModel->fields as $field_id => $field) { $value = $this->getValueFromPost('tpl_field_' . $field_id); if ($value) { $settings[$field_id] = stripslashes($value); } } } // add template header $header_css = "/* \n"; $header_css .= "Template: {$template_name}\n"; $header_css .= "Description: {$template_description}\n"; $header_css .= "Version: {$template_version}\n"; $header_css .= "*/\n"; $tpl_css = $header_css . $tpl_css; // update template files $result = file_put_contents($file_css, $tpl_css); $result = file_put_contents($file_functions, $tpl_functions); $result = file_put_contents($file_footer, $tpl_footer); $result = file_put_contents($file_header, $tpl_header); $result = file_put_contents($file_html, $tpl_html); $result = file_put_contents($file_settings, json_encode($settings)); // catch any errors about permissions, safe mode, etc. global $php_errormsg; ini_set('track_errors', 1); if (!touch($file_css)) { $this->showMessage($php_errormsg, true); } // proper error handling if ($result === false) { $this->showMessage("WP-Lister failed to save your template because it could not write to the file <pre>{$file_css}</pre> Please check the file and folder permissions and make sure that PHP safe_mode is disabled.", true); } else { // hide double success message when adding new template if (!isset($_REQUEST['wpl_add_new_template'])) { $this->showMessage(__('Template saved.', 'wplister')); } // if we were updating this template as part of setup, move to next step if ('3' == self::getOption('setup_next_step')) { self::updateOption('setup_next_step', 4); } } }
public function checkProductStock($step = 0) { $batch_size = get_option('wplister_inventory_check_batch_size', 200); $limit = $batch_size; $offset = $batch_size * $step; // get listings - or return false $listings = WPLE_ListingQueryHelper::getAllPublished($limit, $offset); if (empty($listings)) { return false; } // restore previous data $tmp_result = get_option('wple_inventory_check_queue_data', false); if ($tmp_result) { $out_of_stock_products = $tmp_result['out_of_stock_products']; } else { $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; } // store result so far $tmp_result = array('out_of_stock_products' => $out_of_stock_products); update_option('wple_inventory_check_queue_data', $tmp_result, 'no'); // true means we processed more items return true; }
public function checkProductImages() { // get all listings $listings = WPLE_ListingQueryHelper::getAll(); $found_images = array(); $found_products = array(); // allow WP to upscale images if (isset($_REQUEST['resize_images'])) { add_filter('image_resize_dimensions', array($this, 'filter_image_resize_dimensions'), 10, 6); } // process published listings foreach ($listings as $item) { // get featured image id $post_id = $item['post_id']; $attachment_id = get_post_thumbnail_id($post_id); if (!$attachment_id) { continue; } // $image_attributes = wp_get_attachment_image_src( $attachment_id, 'full' ); // $img_width = $image_attributes[1]; // $img_height = $image_attributes[2]; // get attachment meta data $meta = wp_get_attachment_metadata($attachment_id); if (empty($meta)) { continue; } // echo "<pre>";print_r($meta);echo"</pre>";#die(); // check if at least one side is 500px or longer if ($meta['width'] >= 500 || $meta['height'] >= 500) { continue; } // echo "<pre>";print_r($attachment_id);echo"</pre>";#die(); // resize image if (isset($_REQUEST['resize_images'])) { $size = $this->upscaleImage($meta['file']); if ($size) { // update attachment meta sizes // echo "<pre>new size: ";print_r($size);echo"</pre>";#die(); $meta['width'] = $size['width']; $meta['height'] = $size['height']; // echo wp_update_attachment_metadata( $post_id, $meta ); update_post_meta($attachment_id, '_wp_attachment_metadata', $meta); // clear EPS cache for listing item ListingsModel::updateListing($item['id'], array('eps' => NULL)); $this->showMessage(sprintf('Resized image <code>%s</code> to %s x %s.', $meta['file'], $meta['width'], $meta['height'])); continue; } } // get image url $image_attributes = wp_get_attachment_image_src($attachment_id, 'full'); $meta['url'] = $image_attributes[0]; $meta['post_id'] = $post_id; $meta['ebay_id'] = $item['ebay_id']; $meta['ViewItemURL'] = $item['ViewItemURL']; // add to list of found images $found_images[$attachment_id] = $meta; } // echo "<pre>";print_r($found_images);echo"</pre>"; // return if empty if (empty($found_images)) { $this->showMessage('All images are okay.'); return; } $msg = '<p>'; $msg .= 'Warning: Some product images do not meet the requirements.'; $msg .= '</p>'; // table header $msg .= '<table style="width:100%">'; $msg .= "<tr>"; $msg .= "<th style='text-align:left'>Width</th>"; $msg .= "<th style='text-align:left'>Height</th>"; $msg .= "<th style='text-align:left'>File</th>"; $msg .= "<th style='text-align:left'>Product</th>"; $msg .= "<th style='text-align:left'>eBay ID</th>"; $msg .= "<th style='text-align:left'>ID</th>"; $msg .= "</tr>"; // table rows foreach ($found_images as $attachment_id => $item) { // get column data $post_id = $item['post_id']; $ebay_id = $item['ebay_id']; $width = $item['width']; $height = $item['height']; $file = $item['file']; $url = $item['url']; $title = get_the_title($item['post_id']); // 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>'; $file_link = '<a href="' . $url . '" target="_blank">' . $file . '</a>'; // build table row $msg .= "<tr>"; $msg .= "<td>{$width}</td>"; $msg .= "<td>{$height}</td>"; $msg .= "<td>{$file_link}</td>"; $msg .= "<td>{$edit_link} (ID {$post_id})</td>"; $msg .= "<td>{$ebay_link}</td>"; $msg .= "<td>{$attachment_id}</td>"; $msg .= "</tr>"; } $msg .= '</table>'; $msg .= '<p>'; $url = 'admin.php?page=wplister-tools&action=check_ebay_image_requirements&resize_images=yes&_wpnonce=' . wp_create_nonce('e2e_tools_page'); $msg .= '<a href="' . $url . '" class="button">' . __('Resize all', 'wplister') . '</a> '; $msg .= 'Click this button to upscale all found images to 500px.'; $msg .= '</p>'; $this->showMessage($msg, 1); }
public function getPreviewHTML($template_id, $id = false) { // get item data if ($id) { $item = ListingsModel::getItem($id); } else { $item = WPLE_ListingQueryHelper::getItemForPreview(); } if (!$item) { return '<div style="text-align:center; margin-top:5em;">You need to prepare at least one listing in order to preview a listing template.</div>'; } // use latest post_content from product - moved to TemplatesModel // $post = get_post( $item['post_id'] ); // if ( ! empty($post->post_content) ) $item['post_content'] = $post->post_content; // load template if (!$template_id) { $template_id = $item['template']; } $template = new TemplatesModel($template_id); $html = $template->processItem($item, false, true); // return html return $html; }
function updateItemDetails($ebay_id) { WPLE()->initEC(); $lm = new ListingsModel(); $details = $lm->getLatestDetails($ebay_id, WPLE()->EC->session); return $details; }
public function ajax_wpl_gallery() { $default_limit = get_option('wplister_gallery_items_limit', 12); $type = isset($_REQUEST['type']) ? $_REQUEST['type'] : 'new'; $limit = isset($_REQUEST['limit']) ? $_REQUEST['limit'] : $default_limit; $id = isset($_REQUEST['id']) ? $_REQUEST['id'] : false; $format = isset($_REQUEST['format']) ? $_REQUEST['format'] : 'html'; $items = WPLE_ListingQueryHelper::getItemsForGallery($type, $id, $limit); // echo "<pre>";print_r($items);echo"</pre>";die(); if ($format == 'json') { $json_data = array(); foreach ($items as $item) { $json_item = new stdClass(); $json_item->ebay_id = $item['ebay_id']; $json_item->post_id = $item['post_id']; $json_item->listing_id = $item['id']; $json_item->title = $item['auction_title']; $json_item->type = $item['auction_type']; $json_item->price = $item['price']; $json_item->quantity = $item['quantity']; $json_item->quantity_sold = $item['quantity_sold']; $json_item->main_image_url = $item['GalleryURL']; $json_item->ebay_url = $item['ViewItemURL']; $json_item->site_id = $item['site_id']; $json_item->status = $item['status']; $json_data[] = $json_item; } // check if callback parameter is set (JSONP support) if (isset($_REQUEST['callback'])) { header('content-type: application/javascript; charset=utf-8'); echo $_REQUEST['callback'] . '(' . json_encode($json_data) . ')'; // JSONP } else { header('content-type: application/json; charset=utf-8'); echo json_encode($json_data); // plain JSON } exit; } // get from_item and template path $view = WPLISTER_PATH . '/views/template/gallery.php'; $from_item = $id ? ListingsModel::getItem($id) : false; if ($from_item) { // if gallery.php exists in listing template, use it $gallery_tpl_file = WPLISTER_PATH . '/../../' . $from_item['template'] . '/gallery.php'; if (file_exists($gallery_tpl_file)) { $view = $gallery_tpl_file; } // the above might fail if wp-content has been moved - better use wp_upload_dir() to get actual template path: $upload_dir = wp_upload_dir(); $gallery_tpl_file = $upload_dir['basedir'] . '/wp-lister/templates/' . basename($from_item['template']) . '/gallery.php'; if (file_exists($gallery_tpl_file)) { $view = $gallery_tpl_file; } } // load gallery template if (file_exists($view)) { header('X-Frame-Options: GOFORIT'); include $view; } else { echo "file not found: " . $view; } exit; }
public function displayEditPage() { // get item $item = ListingsModel::getItem($_REQUEST['auction']); // unserialize details $this->initEC($item['account_id']); // $item['details'] = maybe_unserialize( $item['details'] ); // echo "<pre>";print_r($item);echo"</pre>";die(); // get ebay data $countries = EbayShippingModel::getEbayCountries(); // $template_files = $this->getTemplatesList(); $templatesModel = new TemplatesModel(); $templates = $templatesModel->getAll(); $aData = array('plugin_url' => self::$PLUGIN_URL, 'message' => $this->message, 'item' => $item, 'countries' => $countries, 'template_files' => $templates, 'form_action' => 'admin.php?page=' . self::ParentMenuId . (isset($_REQUEST['paged']) ? '&paged=' . $_REQUEST['paged'] : '')); $this->display('listings_edit_page', array_merge($aData, $item)); }
function column_end_date($item) { $profile_data = $this->getProfileData($item); if ($item['date_finished'] && in_array($item['status'], array('ended', 'sold', 'archived'))) { $date = $item['date_finished']; $value = mysql2date(get_option('date_format'), $date); $html = '<span style="color:darkgreen">' . $value . '</span>'; } elseif (is_array($profile_data['details']) && 'GTC' == @$profile_data['details']['listing_duration']) { $value = 'GTC'; $html = '<span style="color:silver">' . $value . '</span>'; } else { $date = $item['end_date']; $value = mysql2date(get_option('date_format'), $date); $html = '<span>' . $value . '</span>'; } // indicate if OOSC is enabled if (ListingsModel::thisListingUsesOutOfStockControl($item)) { $tip_msg = 'The <i>Out Of Stock Control</i> option is enabled.<br><br>This listing will not be ended when it is out of stock.'; $img_url = WPLISTER_URL . '/img/info.png'; $html .= ' <img src="' . $img_url . '" style="height:11px; padding:0;" class="tips" data-tip="' . $tip_msg . '"/> '; } return $html; }
public function updateItemsFromEbay($id) { $sm = new ListingsModel(); if (is_array($id)) { foreach ($id as $single_id) { $this->lastResults[] = $sm->updateItemDetails($single_id, $this->session); } $this->processLastResults(); } else { $this->lastResults[] = $sm->updateItemDetails($id, $this->session); $this->processLastResults(); return $this->lastResults; } }