Beispiel #1
0
 public function onWpAdminInit()
 {
     // handle save template
     if ($this->requestAction() == 'save_template') {
         $this->saveTemplate();
         if (@$_POST['return_to'] == 'listings') {
             $return_url = get_admin_url() . 'admin.php?page=wplister';
             if (isset($_REQUEST['listing_status'])) {
                 $return_url = add_query_arg('listing_status', $_REQUEST['listing_status'], $return_url);
             }
             if (isset($_REQUEST['s'])) {
                 $return_url = add_query_arg('s', $_REQUEST['s'], $return_url);
             }
             wp_redirect($return_url);
         }
     }
     // handle preview action
     if ($this->requestAction() == 'preview_template') {
         // handle parameters to select custom listing item
         $listing_id = isset($_REQUEST['listing_id']) ? $_REQUEST['listing_id'] : false;
         if (!$listing_id && isset($_REQUEST['post_id'])) {
             $listing_id = WPLE_ListingQueryHelper::getListingIDFromPostID($_REQUEST['post_id']);
         }
         $this->previewTemplate($_REQUEST['template'], $listing_id);
         exit;
     }
 }
Beispiel #2
0
 function wplister_relist_item($post_id)
 {
     // call markItemAsModified() to re-apply the listing profile
     $lm = new ListingsModel();
     $lm->markItemAsModified($post_id);
     $listing_id = WPLE_ListingQueryHelper::getListingIDFromPostID($post_id);
     WPLE()->logger->info('relisting item ' . $listing_id);
     // call EbayController
     $this->initEC();
     $results = $this->EC->relistItems($listing_id);
     $this->EC->closeEbay();
     WPLE()->logger->info('relisted item ' . $listing_id);
     return isset($this->EC->lastResults) ? $this->EC->lastResults : false;
 }
Beispiel #3
0
 public function processAllTextShortcodes($post_id, $tpl_html, $max_length = false, $ItemObj = false)
 {
     // get item object
     $listing_id = WPLE_ListingQueryHelper::getListingIDFromPostID($post_id);
     $item = ListingsModel::getItem($listing_id);
     // main content - [[product_content]] (unless updating title when saving product...)
     if (!isset($_REQUEST['action']) || $_REQUEST['action'] != 'editpost' || isset($_REQUEST['wpl_ebay_revise_on_update']) || isset($_REQUEST['wpl_ebay_relist_on_update'])) {
         $tpl_html = $this->processMainContentShortcode($post_id, $tpl_html, $item);
     }
     // product excerpt
     $product_id = $item['parent_id'] ? $item['parent_id'] : $item['post_id'];
     // maybe use parent post_id (for split variations)
     $tpl_html = str_replace('[[product_excerpt]]', WPLE_ListingQueryHelper::getRawPostExcerpt($product_id), $tpl_html);
     $tpl_html = str_replace('[[product_excerpt_nl2br]]', nl2br(WPLE_ListingQueryHelper::getRawPostExcerpt($product_id)), $tpl_html);
     $tpl_html = str_replace('[[product_additional_content]]', wpautop(WPLE_ListingQueryHelper::getRawPostExcerpt($product_id)), $tpl_html);
     $tpl_html = str_replace('[[product_additional_content_nl2br]]', nl2br(WPLE_ListingQueryHelper::getRawPostExcerpt($product_id)), $tpl_html);
     // product price
     $item_price = $item['price'];
     if ($ItemObj && $ItemObj->StartPrice) {
         $item_price = $ItemObj->StartPrice->value;
     }
     if ($ItemObj && $ItemObj->Variations) {
         $item_price = $ItemObj->Variations->Variation[0]->StartPrice;
     }
     $tpl_html = str_replace('[[product_price]]', number_format_i18n(floatval($item_price), 2), $tpl_html);
     $tpl_html = str_replace('[[product_price_raw]]', $item_price, $tpl_html);
     // product_category
     $tpl_html = str_replace('[[product_category]]', ProductWrapper::getProductCategoryName($post_id), $tpl_html);
     // SKU
     $tpl_html = str_replace('[[product_sku]]', ProductWrapper::getSKU($post_id), $tpl_html);
     // weight
     $tpl_html = str_replace('[[product_weight]]', ProductWrapper::getWeight($post_id, true), $tpl_html);
     // dimensions
     $dimensions = ProductWrapper::getDimensions($post_id);
     $width = @$dimensions['width'] . ' ' . @$dimensions['width_unit'];
     $height = @$dimensions['height'] . ' ' . @$dimensions['height_unit'];
     $length = @$dimensions['length'] . ' ' . @$dimensions['length_unit'];
     $tpl_html = str_replace('[[product_width]]', $width, $tpl_html);
     $tpl_html = str_replace('[[product_height]]', $height, $tpl_html);
     $tpl_html = str_replace('[[product_length]]', $length, $tpl_html);
     // attributes
     $tpl_html = $this->processAttributeShortcodes($post_id, $tpl_html, $max_length);
     // custom meta
     $tpl_html = $this->processCustomMetaShortcodes($post_id, $tpl_html, $max_length);
     return $tpl_html;
 }
Beispiel #4
0
 public function markItemAsModified($post_id)
 {
     global $wpdb;
     // get single listing for post_id
     $listing_id = WPLE_ListingQueryHelper::getListingIDFromPostID($post_id);
     $this->reapplyProfileToItem($listing_id);
     // process all listings for post_id
     $listings = WPLE_ListingQueryHelper::getAllListingsFromPostID($post_id);
     if (is_array($listings) && sizeof($listings) > 1) {
         foreach ($listings as $listing_item) {
             $this->reapplyProfileToItem($listing_item->id);
         }
     }
     // process split variations - fetched by parent_id
     $listings = WPLE_ListingQueryHelper::getAllListingsFromParentID($post_id);
     if (is_array($listings)) {
         foreach ($listings as $listing_item) {
             $this->reapplyProfileToItem($listing_item->id);
             WPLE()->logger->info('reapplied profile to SPLIT variation for post_id ' . $post_id . ' - listing_id: ' . $listing_item->id);
         }
     }
     return $listing_id;
     // set published items to changed
     // $wpdb->update( $this->tablename, array( 'status' => 'changed' ), array( 'status' => 'published', 'post_id' => $post_id ) );
     // set verified items to prepared
     // $wpdb->update( $this->tablename, array( 'status' => 'prepared' ), array( 'status' => 'verified', 'post_id' => $post_id ) );
 }
 function wple_product_admin_notices()
 {
     global $post, $post_ID;
     if (!$post) {
         return;
     }
     if (!$post_ID) {
         return;
     }
     $errors_msg = '';
     // warn about missing details
     // $this->checkForMissingData( $post );
     $this->checkForInvalidData($post);
     // get listing item
     $listing_id = WPLE_ListingQueryHelper::getListingIDFromPostID($post_ID);
     $listing = ListingsModel::getItem($listing_id);
     if (!$listing) {
         return;
     }
     // parse history
     $history = maybe_unserialize($listing['last_errors']);
     if (empty($history)) {
         return;
     }
     // echo "<pre>";print_r($history);echo"</pre>";#die();
     // process errors and warnings
     $tips_errors = array();
     $tips_warnings = array();
     if (is_array($history)) {
         foreach ($history['errors'] as $result) {
             $tips_errors[] = '<b>' . $result->SeverityCode . ':</b> ' . $result->ShortMessage . ' (' . $result->ErrorCode . ')<br>' . $result->LongMessage;
         }
         foreach ($history['warnings'] as $result) {
             $tips_warnings[] = '<b>' . $result->SeverityCode . ':</b> ' . $result->ShortMessage . ' (' . $result->ErrorCode . ')<br>' . $result->LongMessage;
         }
     }
     if (!empty($tips_errors)) {
         $errors_msg .= 'eBay returned the following error(s):' . '<br>';
         $errors_msg .= '<small style="color:darkred">' . join('<br>', $tips_errors) . '</small>';
     }
     if ($errors_msg) {
         self::showMessage($errors_msg, 1, 1);
     }
 }
Beispiel #6
0
 public function reviseInventoryForProducts($product_ids)
 {
     if (!is_array($product_ids) && !is_numeric($product_ids)) {
         return;
     }
     if (!is_array($product_ids)) {
         $product_ids = array($product_ids);
     }
     $lm = new ListingsModel();
     foreach ($product_ids as $post_id) {
         $listing_id = WPLE_ListingQueryHelper::getListingIDFromPostID($post_id);
         // if no listing found, check parent_id for variations
         if (!$listing_id) {
             $_product = get_product($post_id);
             if (!$_product) {
                 continue;
             }
             if ($_product->product_type == 'variation') {
                 $listing_id = WPLE_ListingQueryHelper::getListingIDFromPostID($_product->parent->id);
             }
         }
         // check if API is allowed to relist ended items
         if (get_option('wplister_api_enable_auto_relist')) {
             // check listing status - only ended and sold items can be relisted
             $allowed_statuses = array('ended', 'sold');
             if ($lm->itemHasAllowedStatus($listing_id, $allowed_statuses)) {
                 // ok, we have an ended item - check if it's in stock
                 $listing_item = ListingsModel::getItem($listing_id);
                 if (ListingsModel::checkStockLevel($listing_item)) {
                     // let's relist
                     $this->lastResults[] = $lm->relistItem($listing_id, $this->session);
                     continue;
                 }
                 // is in stock
             }
             // is ended
         }
         // if API relist enabled
         // revise inventory status (default)
         $this->lastResults[] = $lm->reviseInventoryStatus($listing_id, $this->session, false);
     }
     //
     $this->processLastResults();
 }