/**
* Output breadcrumbs if configured
* @return None - outputs breadcrumb HTML
*/
function wpsc_output_breadcrumbs($options = null)
{
    // Defaults
    $options = apply_filters('wpsc_output_breadcrumbs_options', $options);
    $options = wp_parse_args((array) $options, array('before-breadcrumbs' => '<div class="wpsc-breadcrumbs">', 'after-breadcrumbs' => '</div>', 'before-crumb' => '', 'after-crumb' => '', 'crumb-separator' => ' &raquo; ', 'show_home_page' => true, 'show_products_page' => true, 'echo' => true));
    $output = '';
    $products_page_id = wpsc_get_the_post_id_by_shortcode('[productspage]');
    $products_page = get_post($products_page_id);
    if (!wpsc_has_breadcrumbs()) {
        return;
    }
    $filtered_products_page = array('url' => get_option('product_list_url'), 'name' => apply_filters('the_title', $products_page->post_title));
    $filtered_products_page = apply_filters('wpsc_change_pp_breadcrumb', $filtered_products_page);
    // Home Page Crumb
    // If home if the same as products page only show the products-page link and not the home link
    if (get_option('page_on_front') != $products_page_id && $options['show_home_page']) {
        $output .= $options['before-crumb'];
        $output .= '<a class="wpsc-crumb" id="wpsc-crumb-home" href="' . get_option('home') . '">' . get_option('blogname') . '</a>';
        $output .= $options['after-crumb'];
    }
    // Products Page Crumb
    if ($options['show_products_page']) {
        if (!empty($output)) {
            $output .= $options['crumb-separator'];
        }
        $output .= $options['before-crumb'];
        $output .= '<a class="wpsc-crumb" id="wpsc-crumb-' . $products_page_id . '" href="' . $filtered_products_page['url'] . '">' . $filtered_products_page['name'] . '</a>';
        $output .= $options['after-crumb'];
    }
    // Remaining Crumbs
    while (wpsc_have_breadcrumbs()) {
        wpsc_the_breadcrumb();
        if (!empty($output)) {
            $output .= $options['crumb-separator'];
        }
        $output .= $options['before-crumb'];
        if (wpsc_breadcrumb_url()) {
            $output .= '<a class="wpsc-crumb" id="wpsc-crumb-' . wpsc_breadcrumb_slug() . '" href="' . wpsc_breadcrumb_url() . '">' . wpsc_breadcrumb_name() . '</a>';
        } else {
            $output .= '<span class="wpsc-crumb" id="wpsc-crumb-' . wpsc_breadcrumb_slug() . '">' . wpsc_breadcrumb_name() . '</span>';
        }
        $output .= $options['after-crumb'];
    }
    $output = $options['before-breadcrumbs'] . apply_filters('wpsc_output_breadcrumbs', $output, $options) . $options['after-breadcrumbs'];
    if ($options['echo']) {
        echo $output;
    } else {
        return $output;
    }
}
/**
 * wpsc display products function
 * Used to determine whether to display products on the page
 * @return boolean - true for yes, false for no
 */
function wpsc_display_products()
{
    $post = get_queried_object();
    $product_page_id = wpsc_get_the_post_id_by_shortcode('[productspage]');
    //we have to display something, if we are not displaying categories, then we must display products
    $output = true;
    if (wpsc_display_categories() && isset($post->ID)) {
        if (get_option('wpsc_default_category') == 'list' && $post->ID == $product_page_id) {
            $output = false;
        }
        if (isset($_GET['range']) || isset($_GET['category'])) {
            $output = true;
        }
    }
    return $output;
}
Example #3
0
/**
 * wpsc_is_product function.
 *
 * @since 3.8
 * @access public
 * @return boolean
 */
function wpsc_is_checkout()
{
    global $wp_query;
    $is_checkout = false;
    $checkout_shortcode = wpsc_get_the_post_id_by_shortcode('[shoppingcart]');
    $old_checkout_shortcode = wpsc_get_the_post_id_by_shortcode('[checkout]');
    if (isset($wp_query->is_checkout)) {
        $is_checkout = $wp_query->is_checkout;
    } else {
        if (!is_null($old_checkout_shortcode)) {
            $is_checkout = is_page($old_checkout_shortcode);
        } else {
            if (!is_null($checkout_shortcode)) {
                $is_checkout = is_page($checkout_shortcode);
            }
        }
    }
    return $is_checkout;
}
/**
 * wpsc_generate_product_query function.
 *
 * @access public
 * @param mixed $query
 * @return void
 */
function wpsc_generate_product_query($query)
{
    global $wp_query;
    $prod_page = wpsc_get_the_post_id_by_shortcode('[productspage]');
    $prod_page = get_post($prod_page);
    remove_filter('pre_get_posts', 'wpsc_generate_product_query', 11);
    $query->query_vars['taxonomy'] = null;
    $query->query_vars['term'] = null;
    // default product selection
    if ($query->query_vars['pagename'] != '') {
        $query->query_vars['post_type'] = 'wpsc-product';
        $query->query_vars['pagename'] = '';
        $query->is_page = false;
        $query->is_tax = false;
        $query->is_archive = true;
        $query->is_singular = false;
        $query->is_single = false;
    }
    // If wpsc_item is not null, we are looking for a product or a product category, check for category
    if (isset($query->query_vars['wpsc_item']) && $query->query_vars['wpsc_item'] != '') {
        $test_term = get_term_by('slug', $query->query_vars['wpsc_item'], 'wpsc_product_category');
        if ($test_term->slug == $query->query_vars['wpsc_item']) {
            // if category exists (slug matches slug), set products to value of wpsc_item
            $query->query_vars['products'] = $query->query_vars['wpsc_item'];
        } else {
            // otherwise set name to value of wpsc_item
            $query->query_vars['name'] = $query->query_vars['wpsc_item'];
        }
    }
    if (isset($query->query_vars['products']) && $query->query_vars['products'] != null && $query->query_vars['name'] != null) {
        unset($query->query_vars['taxonomy']);
        unset($query->query_vars['term']);
        $query->query_vars['post_type'] = 'wpsc-product';
        $query->is_tax = false;
        $query->is_archive = true;
        $query->is_singular = false;
        $query->is_single = false;
    }
    if (isset($wp_query->query_vars['wpsc_product_category']) && !isset($wp_query->query_vars['wpsc-product'])) {
        $query->query_vars['wpsc_product_category'] = $wp_query->query_vars['wpsc_product_category'];
        $query->query_vars['taxonomy'] = $wp_query->query_vars['taxonomy'];
        $query->query_vars['term'] = $wp_query->query_vars['term'];
    } elseif ('' != ($default_category = get_option('wpsc_default_category')) && !isset($wp_query->query_vars['wpsc-product'])) {
        $default_term = get_term($default_category, 'wpsc_product_category');
        if (!empty($default_term) && empty($wp_query->query_vars['category_name'])) {
            $query->query_vars['taxonomy'] = 'wpsc_product_category';
            $query->query_vars['term'] = $default_term->slug;
            $query->is_tax = true;
        } elseif (isset($wp_query->query_vars['name']) && $wp_query->is_404 && $wp_query->query_vars['category_name'] != $prod_page->post_name) {
            unset($query->query_vars['taxonomy']);
            unset($query->query_vars['term']);
            $query->query_vars['wpsc-product'] = $wp_query->query_vars['name'];
            $query->query_vars['name'] = $wp_query->query_vars['name'];
        } else {
            $query->is_tax = true;
            $term = get_term_by('slug', $wp_query->query_vars['name'], 'wpsc_product_category');
            if (!empty($term)) {
                $query->query_vars['taxonomy'] = 'wpsc_product_category';
                $query->query_vars['wpsc_product_category__in'] = array($term->term_taxonomy_id);
                $query->query_vars['wpsc_product_category'] = $wp_query->query_vars['name'];
                $query->query_vars['term'] = $wp_query->query_vars['name'];
            } elseif (is_numeric($default_category)) {
                $query->query_vars['taxonomy'] = 'wpsc_product_category';
            } else {
                $query->is_tax = false;
            }
        }
    }
    //If Product Tag Taxonomy
    if (isset($wp_query->query_vars['product_tag']) && $wp_query->query_vars['product_tag']) {
        $query->query_vars['product_tag'] = $wp_query->query_vars['product_tag'];
        $query->query_vars['term'] = $wp_query->query_vars['term'];
        $query->query_vars['taxonomy'] = 'product_tag';
        $query->is_tax = true;
    }
    if (1 == get_option('use_pagination')) {
        $query->query_vars['posts_per_page'] = get_option('wpsc_products_per_page');
        if (isset($_GET['items_per_page'])) {
            if (is_numeric($_GET['items_per_page'])) {
                $query->query_vars['posts_per_page'] = (int) $_GET['items_per_page'];
            } elseif ($_GET['items_per_page'] == 'all') {
                $query->query_vars['posts_per_page'] = -1;
                $query->query_vars['nopaging'] = 1;
            }
        }
    } else {
        $query->query_vars['posts_per_page'] = -1;
        $query->query_vars['nopaging'] = 1;
    }
    if ($query->is_tax == true) {
        new wpsc_products_by_category($query);
    }
    return $query;
}
function wpec_get_the_post_id_by_shortcode($shortcode)
{
    _wpsc_deprecated_function(__FUNCTION__, '3.8.9', 'wpsc_get_the_post_id_by_shortcode');
    return wpsc_get_the_post_id_by_shortcode($shortcode);
}
function is_products_page()
{
    global $post;
    if (empty($post) || !is_object($post) || empty($post->ID)) {
        return false;
    }
    $product_page_id = wpsc_get_the_post_id_by_shortcode('[productspage]');
    return $post->ID == $product_page_id;
}
Example #7
0
/**
* Output breadcrumbs if configured
* @return None - outputs breadcrumb HTML
*/
function wpsc_output_breadcrumbs($options = null)
{
    /**
     * Filter the arguments passed to wpsc_output_breadcrumbs.
     *
     * @since 3.9.0
     * @param array $options {
     *     associative array of options for outputting the breadcrumbs to this page.
     *
     *     'before-breadcrumbs' string  HTML output to start the breadcrumb.
     *     'after-breadcrumbs'  string  HTML output at the end of the breadcrumb eg closing tag.
     *     'before-crumb'       string  output before each step in path, typically decorative.
     *     'after-crumb'        string  output after each step in path.
     *     'crumb-separator'    string  demarks space between steps in path.
     *     'show_home_page'     bool    Whether to include home page as step at start of path.
     *     'show_products_page' bool    Whether to include products-page as second step in path.
     *     'echo'               bool    if true, outputs constructed string; if false, returns constructed string.
     *     'products_page_id'   int     Override the page id used for products_page
     *     }
     *
     */
    // Defaults
    $options = apply_filters('wpsc_output_breadcrumbs_options', $options);
    $options = wp_parse_args((array) $options, array('before-breadcrumbs' => '<div class="wpsc-breadcrumbs">', 'after-breadcrumbs' => '</div>', 'before-crumb' => '', 'after-crumb' => '', 'crumb-separator' => ' &raquo; ', 'show_home_page' => true, 'show_products_page' => true, 'echo' => true, 'products_page_id' => wpsc_get_the_post_id_by_shortcode('[productspage]')));
    $output = '';
    $products_page_id = absint($options['products_page_id']);
    $products_page = get_post($products_page_id);
    if (!wpsc_has_breadcrumbs()) {
        return;
    }
    $filtered_products_page = array('url' => get_option('product_list_url'), 'name' => apply_filters('the_title', $products_page->post_title, $products_page_id));
    /**
     * Filter the values used to create the products-page step.
     *
     * Overrides the url and text show for the products-page step in breadcrumb.
     *
     * @since 3.9.0
     * @param array $filtered_products_page {
     *     associative array of options for outputting the breadcrumbs to this page.
     *
     *     'url'   string  Fully-qualified url to products-page.
     *     'name'  string  The name that will appear for the products-page in breadcrumb.
     *     }
     *
     */
    $filtered_products_page = apply_filters('wpsc_change_pp_breadcrumb', $filtered_products_page);
    // Home Page Crumb
    // If home if the same as products page only show the products-page link and not the home link
    if (get_option('page_on_front') != $products_page_id && $options['show_home_page']) {
        $output .= $options['before-crumb'];
        $output .= '<a class="wpsc-crumb" id="wpsc-crumb-home" href="' . get_option('home') . '">' . get_option('blogname') . '</a>';
        $output .= $options['after-crumb'];
    }
    // Products Page Crumb
    if ($options['show_products_page']) {
        if (!empty($output)) {
            $output .= $options['crumb-separator'];
        }
        $output .= $options['before-crumb'];
        $output .= '<a class="wpsc-crumb" id="wpsc-crumb-' . $products_page_id . '" href="' . $filtered_products_page['url'] . '">' . $filtered_products_page['name'] . '</a>';
        $output .= $options['after-crumb'];
    }
    // Remaining Crumbs
    while (wpsc_have_breadcrumbs()) {
        wpsc_the_breadcrumb();
        if (!empty($output)) {
            $output .= $options['crumb-separator'];
        }
        $output .= $options['before-crumb'];
        if (wpsc_breadcrumb_url()) {
            $output .= '<a class="wpsc-crumb" id="wpsc-crumb-' . wpsc_breadcrumb_slug() . '" href="' . wpsc_breadcrumb_url() . '">' . wpsc_breadcrumb_name() . '</a>';
        } else {
            $output .= '<span class="wpsc-crumb" id="wpsc-crumb-' . wpsc_breadcrumb_slug() . '">' . wpsc_breadcrumb_name() . '</span>';
        }
        $output .= $options['after-crumb'];
    }
    /**
     * Filter the assembled breadcrumb.
     *
     * @since 3.9.0
     * @param string $output The constructed breadcrumb string.
     * @param array $options {@see 'wpsc_output_breadcrumbs_options'}
     *
     */
    $output = $options['before-breadcrumbs'] . apply_filters('wpsc_output_breadcrumbs', $output, $options) . $options['after-breadcrumbs'];
    if ($options['echo']) {
        echo $output;
    } else {
        return $output;
    }
}
/**
 * Live Search
 */
function wpsc_live_search()
{
    if ((double) WPSC_VERSION < 3.8) {
        $autocomplete = 'onkeyup="autocomplete(event)"';
    } else {
        $autocomplete = '';
    }
    //get the url to submit the search to
    $product_page_id = wpsc_get_the_post_id_by_shortcode('[productspage]');
    $pp_url = get_permalink($product_page_id);
    // the js below listens for the enter keypress and redirects to the product page with a get var of the search term
    ?>
  <div class="live_search_form">
		<input name="product_search" id="wpsc_search_autocomplete" <?php 
    echo $autocomplete;
    ?>
 class="wpsc_live_search" autocomplete="off" />
    <script type='text/javascript' > /* <![CDATA[ */
      jQuery('#wpsc_search_autocomplete').keypress( function(e){
        if ( e.keyCode == 13 ) {
          var url = '<?php 
    echo $pp_url;
    ?>
'+'?product_search='+jQuery(this).val();
          url = encodeURI(url);
          jQuery(window.location).attr('href', url);
        }
      });
	   /* ]]> */
    </script>
    <div class="blind_down" style="display:none;"></div>
  </div>
  <?php 
}
function is_products_page()
{
    global $post;
    $product_page_id = wpsc_get_the_post_id_by_shortcode('[productspage]');
    return $post->ID == $product_page_id;
}
Example #10
0
/**
 * Start Search Query
 */
function wpsc_gc_start_search_query()
{
    global $wp_query, $wpsc_query;
    $product_page_id = wpsc_get_the_post_id_by_shortcode('[productspage]');
    $post = get_post($product_page_id);
    $wp_query = new WP_Query(array('pagename' => $post->post_name));
    add_action('pre_get_posts', 'wpsc_gc_live_search_pre_get_posts');
    wpsc_start_the_query();
    remove_action('pre_get_posts', 'wpsc_gc_live_search_pre_get_posts');
    list($wp_query, $wpsc_query) = array($wpsc_query, $wp_query);
    // swap the wpsc_query object
    $GLOBALS['nzshpcrt_activateshpcrt'] = true;
}