Esempio n. 1
0
 function get_display_price($item)
 {
     // if item has variations check each price...
     if (ProductWrapper::hasVariations($item['post_id'])) {
         // handle StartPrice on product level
         if ($product_start_price = get_post_meta($item['post_id'], '_ebay_start_price', true)) {
             return $this->number_format($product_start_price, 2);
         }
         $variations = $this->getProductVariations($item['post_id']);
         if (!is_array($variations) || !sizeof($variations)) {
             return '';
         }
         $price_min = 1000000;
         // one million should be a high enough ceiling
         $price_max = 0;
         foreach ($variations as $var) {
             $price = $var['price'];
             if ($price > $price_max) {
                 $price_max = $price;
             }
             if ($price < $price_min) {
                 $price_min = $price;
             }
         }
         // apply price modifiers
         $profile_data = $this->getProfileData($item);
         $price_min = ListingsModel::applyProfilePrice($price_min, @$profile_data['details']['start_price']);
         $price_max = ListingsModel::applyProfilePrice($price_max, @$profile_data['details']['start_price']);
         // use lowest price for flattened variations
         if (isset($profile_data['details']['variations_mode']) && $profile_data['details']['variations_mode'] == 'flat') {
             return $this->number_format($price_min, 2);
         }
         if ($price_min == $price_max) {
             return $this->number_format($price_min, 2);
         } else {
             return $this->number_format($price_min, 2) . ' - ' . $this->number_format($price_max, 2);
         }
     }
     // use price from ebay_auctions by default
     $start_price = $item['price'];
     // handle StartPrice on product level
     if ($product_start_price = get_post_meta($item['post_id'], '_ebay_start_price', true)) {
         $start_price = $product_start_price;
     }
     return $this->number_format($start_price, 2);
 }
Esempio n. 2
0
 static function checkStockLevel($listing_item)
 {
     if (!is_array($listing_item)) {
         $listing_item = (array) $listing_item;
     }
     $post_id = $listing_item['post_id'];
     $profile_details = $listing_item['profile_data']['details'];
     $locked = $listing_item['locked'];
     if (ProductWrapper::hasVariations($post_id)) {
         $variations = ProductWrapper::getVariations($post_id);
         $stock = 0;
         foreach ($variations as $var) {
             $stock += intval($var['stock']);
         }
     } else {
         $stock = ProductWrapper::getStock($post_id);
     }
     // fixed profile quantity will always be in stock - except for locked items
     if (!$locked && intval($profile_details['quantity']) > 0) {
         $stock = $profile_details['quantity'];
     }
     WPLE()->logger->info("checkStockLevel() result: " . $stock);
     return intval($stock) > 0 ? $stock : false;
 }
Esempio n. 3
0
 public function processMainContentShortcode($post_id, $tpl_html, $item)
 {
     // use latest post_content from product
     $post = get_post($item['post_id']);
     $item['post_content'] = $post->post_content;
     // handle variations
     $variations_html = '';
     if (ProductWrapper::hasVariations($item['post_id'])) {
         // generate variations table
         $variations_html = $this->getVariationsHTML($item);
         // add variations table to item description
         if (isset($item['profile_data']['details']['add_variations_table']) && $item['profile_data']['details']['add_variations_table']) {
             $item['post_content'] .= $variations_html;
         }
     }
     // replace shortcodes
     $tpl_html = str_replace('[[product_variations]]', $variations_html, $tpl_html);
     // handle split variations - get description from parent post_id
     if (ProductWrapper::isSingleVariation($post_id)) {
         $post = get_post($item['parent_id']);
         $item['post_content'] = $post->post_content;
     }
     // handle addons
     // generate addons table
     $addons_html = $this->getAddonsHTML($item);
     // add addons table to item description
     if (isset($item['profile_data']['details']['add_variations_table']) && $item['profile_data']['details']['add_variations_table']) {
         $item['post_content'] .= $addons_html;
     }
     // replace shortcodes
     $tpl_html = str_replace('[[product_addons]]', $addons_html, $tpl_html);
     // remove ALL links from post content by default
     if ('default' == get_option('wplister_remove_links', 'default')) {
         /* $item['post_content'] = preg_replace('#<a.*?>([^<]*)</a>#i', '$1', $item['post_content'] ); */
         // regex improved to work in cases like <a ...><b>text</b></a>
         /* $item['post_content'] = preg_replace('#<a.*?>(.*)</a>#iU', '$1', $item['post_content'] ); */
         // improved for multiple links per line case
         $item['post_content'] = preg_replace('#<a.*?>(.*?)</a>#i', ' $1 ', $item['post_content']);
     }
     // fixed whitespace pasted from ms word
     // details: http://stackoverflow.com/questions/1431034/can-anyone-tell-me-what-this-ascii-character-is
     $whitespace = chr(194) . chr(160);
     $item['post_content'] = str_replace($whitespace, ' ', $item['post_content']);
     // process and insert main content
     if ('off' == get_option('wplister_process_shortcodes', 'content')) {
         // off - do nothing, except wpautop() for proper paragraphs
         $tpl_html = str_replace('[[product_content]]', wpautop($item['post_content']), $tpl_html);
     } elseif ('remove' == get_option('wplister_process_shortcodes', 'content')) {
         // remove - remove all shortcodes from product description
         $post_content = $item['post_content'];
         // find and remove all placeholders
         if (preg_match_all('/\\[([^\\]]+)\\]/', $post_content, $matches)) {
             foreach ($matches[0] as $placeholder) {
                 $post_content = str_replace($placeholder, '', $post_content);
             }
         }
         // insert content into template html
         $tpl_html = str_replace('[[product_content]]', wpautop($post_content), $tpl_html);
     } else {
         // make sure, WooCommerce template functions are loaded (WC2.2)
         if (!function_exists('woocommerce_product_loop_start') && version_compare(WC_VERSION, '2.2', '>=')) {
             // WC()->include_template_functions(); // won't work unless is_admin() == true
             include_once dirname(WC_PLUGIN_FILE) . '/includes/wc-template-functions.php';
         }
         // default - apply the_content filter to make description look the same as in WP
         $tpl_html = str_replace('[[product_content]]', apply_filters('the_content', $item['post_content']), $tpl_html);
     }
     return $tpl_html;
 }
Esempio n. 4
0
 public function getVariationImages($post_id)
 {
     // check if product has variations
     if (!ProductWrapper::hasVariations($post_id)) {
         return array();
     }
     // get variations
     $variations = ProductWrapper::getVariations($post_id);
     $variation_images = array();
     foreach ($variations as $var) {
         if (!in_array($var['image'], $variation_images)) {
             $variation_images[] = $this->removeHttpsFromUrl($var['image']);
         }
     }
     WPLE()->logger->info("variation images: " . print_r($variation_images, 1));
     return $variation_images;
 }