Ejemplo n.º 1
0
 function wplister_product_has_changed($post_id)
 {
     $lm = new ListingsModel();
     $listing_id = $lm->markItemAsModified($post_id);
     // handle locked items
     $listing = ListingsModel::getItem($listing_id);
     if ($listing['locked']) {
         do_action('wplister_revise_inventory_status', $post_id);
     }
 }
Ejemplo n.º 2
0
 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;
 }
Ejemplo n.º 3
0
 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;
 }
Ejemplo n.º 4
0
 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 ');
             }
         }
     }
 }
Ejemplo n.º 5
0
 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));
 }
Ejemplo n.º 6
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;
 }
Ejemplo n.º 7
0
 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;
 }
Ejemplo n.º 8
0
 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);
     }
 }
Ejemplo n.º 9
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();
 }