Esempio n. 1
0
 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;
 }
Esempio n. 2
0
 public function handleActions()
 {
     // handle save listing
     if ($this->requestAction() == 'save_listing') {
         $this->saveListing();
     }
     // set account_id
     $account_id = isset($_REQUEST['auction']) ? WPLE_ListingQueryHelper::getAccountID($_REQUEST['auction']) : false;
     // handle verify action
     if ($this->requestAction() == 'verify') {
         $this->initEC($account_id);
         $this->EC->verifyItems($_REQUEST['auction']);
         $this->EC->closeEbay();
         if ($this->EC->isSuccess) {
             $this->showMessage(__('Selected items were verified with eBay.', 'wplister'));
         } else {
             $this->showMessage(__('There were some problems verifying your items.', 'wplister'), 1);
         }
     }
     // handle revise action
     if ($this->requestAction() == 'revise') {
         $this->initEC($account_id);
         $this->EC->reviseItems($_REQUEST['auction']);
         $this->EC->closeEbay();
         if ($this->EC->isSuccess) {
             $this->showMessage(__('Selected items were revised on eBay.', 'wplister'));
         } else {
             $this->showMessage(__('There were some problems revising your items.', 'wplister'), 1);
         }
     }
     // handle publish to eBay action
     if ($this->requestAction() == 'publish2e') {
         $this->initEC($account_id);
         $this->EC->sendItemsToEbay($_REQUEST['auction']);
         $this->EC->closeEbay();
         if ($this->EC->isSuccess) {
             $this->showMessage(__('Selected items were published on eBay.', 'wplister'));
         } else {
             $this->showMessage(__('Some items could not be published.', 'wplister'), 1);
         }
     }
     // handle relist action
     if ($this->requestAction() == 'relist') {
         $this->initEC($account_id);
         $this->EC->relistItems($_REQUEST['auction']);
         $this->EC->closeEbay();
         if ($this->EC->isSuccess) {
             $this->showMessage(__('Selected items were re-listed on eBay.', 'wplister'));
         } else {
             $this->showMessage(__('There were some problems relisting your items.', 'wplister'), 1);
         }
     }
     // handle end_item action
     if ($this->requestAction() == 'end_item') {
         $this->initEC($account_id);
         $this->EC->endItemsOnEbay($_REQUEST['auction']);
         $this->EC->closeEbay();
         $this->showMessage(__('Selected listings were ended.', 'wplister'));
     }
     // handle update from eBay action
     if ($this->requestAction() == 'update') {
         $this->initEC($account_id);
         $this->EC->updateItemsFromEbay($_REQUEST['auction']);
         $this->EC->closeEbay();
         $this->showMessage(__('Selected items were updated from eBay.', 'wplister'));
     }
     // handle delete action
     if (isset($_REQUEST['auction']) && $this->requestAction() == 'delete_listing') {
         $id = $_REQUEST['auction'];
         if (is_array($id)) {
             foreach ($id as $single_id) {
                 WPLE_ListingQueryHelper::deleteItem($single_id);
             }
         } else {
             WPLE_ListingQueryHelper::deleteItem($id);
         }
         $this->showMessage(__('Selected items were removed.', 'wplister'));
     }
     // handle archive action
     if ($this->requestAction() == 'archive') {
         $id = $_REQUEST['auction'];
         $data = array('status' => 'archived');
         if (is_array($id)) {
             foreach ($id as $single_id) {
                 ListingsModel::updateListing($single_id, $data);
             }
         } else {
             ListingsModel::updateListing($id, $data);
         }
         $this->showMessage(__('Selected items were archived.', 'wplister'));
     }
     // handle wple_reset_status action
     if ($this->requestAction() == 'wple_reset_status') {
         $lm = new ListingsModel();
         $id = $_REQUEST['auction'];
         $data = array('status' => 'prepared', 'ebay_id' => NULL, 'end_date' => NULL, 'date_published' => NULL, 'last_errors' => '');
         if (is_array($id)) {
             foreach ($id as $single_id) {
                 $status = WPLE_ListingQueryHelper::getStatus($single_id);
                 if (!in_array($status, array('ended', 'sold', 'archived'))) {
                     wple_show_message("Item with status <i>{$status}</i> was skipped. Only ended and sold items can have their status reset to <i>prepared</i>.", 'warn');
                     continue;
                 }
                 ListingsModel::updateListing($single_id, $data);
                 $lm->reapplyProfileToItem($single_id);
             }
             wple_show_message(__('Selected items had their status reset to prepared.', 'wplister'));
         }
     }
     // handle wple_clear_eps_data action
     if ($this->requestAction() == 'wple_clear_eps_data') {
         $id = $_REQUEST['auction'];
         if (is_array($id)) {
             foreach ($id as $single_id) {
                 ListingsModel::updateWhere(array('id' => $single_id), array('eps' => ''));
             }
             wple_show_message(__('EPS cache was cleared for selected items.', 'wplister'));
         }
     }
     // handle lock action
     if ($this->requestAction() == 'lock') {
         $id = $_REQUEST['auction'];
         $data = array('locked' => true);
         if (is_array($id)) {
             foreach ($id as $single_id) {
                 ListingsModel::updateListing($single_id, $data);
             }
         } else {
             ListingsModel::updateListing($id, $data);
         }
         $this->showMessage(__('Selected items were locked.', 'wplister'));
     }
     // handle unlock action
     if ($this->requestAction() == 'unlock') {
         $id = $_REQUEST['auction'];
         $data = array('locked' => false);
         if (is_array($id)) {
             foreach ($id as $single_id) {
                 ListingsModel::updateListing($single_id, $data);
             }
         } else {
             ListingsModel::updateListing($id, $data);
         }
         $this->showMessage(__('Selected items were unlocked.', 'wplister'));
     }
     // handle cancel_schedule action
     if ($this->requestAction() == 'cancel_schedule') {
         $id = $_REQUEST['auction'];
         $data = array('relist_date' => null);
         if (is_array($id)) {
             foreach ($id as $single_id) {
                 ListingsModel::updateListing($single_id, $data);
             }
         } else {
             ListingsModel::updateListing($id, $data);
         }
         $this->showMessage(__('Selected items were unscheduled from auto relist.', 'wplister'));
     }
     // clean listing archive
     if ($this->requestAction() == 'wpl_clean_listing_archive') {
         WPLE_ListingQueryHelper::cleanArchive();
         $this->showMessage(__('Archive was cleared.', 'wplister'));
     }
     // handle toolbar action - prepare listing from product
     if ($this->requestAction() == 'wpl_prepare_single_listing') {
         // get profile
         $profilesModel = new ProfilesModel();
         $profile = isset($_REQUEST['profile_id']) ? $profilesModel->getItem($_REQUEST['profile_id']) : false;
         if ($profile) {
             // prepare product
             $listingsModel = new ListingsModel();
             $listing_id = $listingsModel->prepareProductForListing($_REQUEST['product_id'], $profile['profile_id']);
             if ($listing_id) {
                 $listingsModel->applyProfileToNewListings($profile);
                 $this->showMessage(__('New listing was prepared from product.', 'wplister'));
             } else {
                 $msg = __('Could not create a new listing from this product.', 'wplister');
                 if ($listingsModel->errors) {
                     $msg .= '<br>' . join('<br>', $listingsModel->errors);
                 }
                 if ($listingsModel->warnings) {
                     $msg .= '<br>' . join('<br>', $listingsModel->warnings);
                 }
                 $this->showMessage($msg, 2);
             }
         } elseif (isset($_REQUEST['product_id'])) {
             // prepare product
             $listingsModel = new ListingsModel();
             $listingsModel->prepareProductForListing($_REQUEST['product_id']);
         }
     }
     // handle reapply profile action
     if ($this->requestAction() == 'reapply') {
         $listingsModel = new ListingsModel();
         $listingsModel->reapplyProfileToItems($_REQUEST['auction']);
         $this->showMessage(__('Profiles were re-applied to selected items.', 'wplister'));
     }
     // cancel (re-)selecting profile process
     if ($this->requestAction() == 'cancel_profile_selection') {
         ListingsModel::cancelSelectingListings();
     }
 }
Esempio n. 3
0
 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> &nbsp; ';
     $msg .= 'Click this button to upscale all found images to 500px.';
     $msg .= '</p>';
     $this->showMessage($msg, 1);
 }