Пример #1
0
/**
 * Registers a smart collection of products
 *
 * @api
 * @since 1.2
 *
 * @param string $name Class name of the smart collection
 * @return void
 **/
function shopp_register_collection($name = '')
{
    if (empty($name)) {
        shopp_debug(__FUNCTION__ . " failed: Collection name required.");
        return false;
    }
    $Shopp = Shopp::object();
    $namespace = apply_filters('shopp_smart_collections_slug', SmartCollection::$namespace);
    $permastruct = SmartCollection::$taxon;
    $slugs = SmartCollection::slugs($name);
    $slug = $slugs[0];
    $Shopp->Collections[$slug] = $name;
    do_action('shopp_register_collection', $name, $slug);
    $slugs = SmartCollection::slugs($name);
    add_rewrite_tag("%{$permastruct}%", "([^/]+)");
    add_permastruct($permastruct, ShoppPages()->baseslug() . "/{$namespace}/%shopp_collection%", false);
    add_filter($permastruct . '_rewrite_rules', array('ProductCollection', 'pagerewrites'));
    $apicall = create_function('$result, $options, $O', 'ShoppCollection( new ' . $name . '($options) );
		return ShoppStorefrontThemeAPI::category($result, $options, $O);');
    foreach ((array) $slugs as $collection) {
        $collection = str_replace(array('-', '_'), '', $collection);
        // Sanitize slugs
        add_filter('shopp_themeapi_storefront_' . $collection . 'products', $apicall, 10, 3);
        // @deprecated
        add_filter('shopp_themeapi_storefront_' . $collection . 'collection', $apicall, 10, 3);
    }
    // Add special default permalink handling for collection URLs (only add it once)
    global $wp_rewrite;
    if (!$wp_rewrite->using_permalinks() && false === has_filter('term_link', array('SmartCollection', 'defaultlinks'))) {
        add_filter('term_link', array('SmartCollection', 'defaultlinks'), 10, 3);
    }
}
Пример #2
0
/**
 * Determines if the current request is for a registered dynamic Shopp collection
 *
 * NOTE: This function will not identify PHP loaded collections, it only
 * compares the page request, meaning using is_shopp_collection on the catalog landing
 * page, even when the landing page (catalog.php) template loads the CatalogProducts collection
 * will return false, because CatalogProducts is loaded in the template and not directly
 * from the request.
 *
 * @api
 * @since 1.2
 *
 * @param WP_Query $wp_query (optional) will use the global wp_query by default if false, or the WP_Query object to evaluation
 * @return boolean
 **/
function is_shopp_smart_collection($wp_query = false)
{
    if (false === $wp_query) {
        global $wp_the_query;
        $wp_query =& $wp_the_query;
    }
    $slug = $wp_query->get('shopp_collection');
    if (empty($slug)) {
        return false;
    }
    $Shopp = Shopp::object();
    foreach ((array) $Shopp->Collections as $Collection) {
        $slugs = SmartCollection::slugs($Collection);
        if (in_array($slug, $slugs)) {
            return true;
        }
    }
    return false;
}
Пример #3
0
 /**
  * Handles rendering the [catalog-collection] shortcode
  *
  * @author Jonathan Davis
  * @since 1.1
  *
  * @param array $attrs The parsed shortcode attributes
  * @return string The processed content
  **/
 static function collection(array $atts = array())
 {
     $Shopp = Shopp::object();
     $tag = 'category';
     if (isset($atts['name'])) {
         $Collection = new ProductCategory($atts['name'], 'name');
         unset($atts['name']);
     } elseif (isset($atts['slug'])) {
         foreach ($Shopp->Collections as $SmartCollection) {
             $slugs = SmartCollection::slugs($SmartCollection);
             if (in_array($atts['slug'], $slugs)) {
                 $tag = $slugs[0] . "-collection";
                 unset($atts['slug']);
                 break;
             }
         }
     } elseif (isset($atts['id'])) {
         $Collection = new ProductCategory($atts['id']);
         unset($atts['id']);
     } else {
         return '';
     }
     ShoppCollection($Collection);
     $markup = shopp("catalog.get-{$tag}", $atts);
     ShoppStorefront()->shortcoded[] = get_the_ID();
     // @deprecated in favor of the shopp_collection_shortcode
     $markup = apply_filters('shopp_category_shortcode', $markup);
     return apply_filters('shopp_collection_shortcode', $markup);
 }
Пример #4
0
 public function pagelink($page)
 {
     $link = parent::pagelink($page);
     return add_query_arg(array('s' => urlencode($this->search), 's_cs' => 1), $link);
 }
Пример #5
0
 /**
  * Load a any category from the catalog including smart categories
  *
  * @author Jonathan Davis
  * @since 1.0
  * @version 1.1
  *
  * @param string|int $category The identifying element of a category (by id/slug or uri)
  * @param array $options (optional) Any shopp() tag-compatible options to pass on to smart categories
  * @return object The loaded Category object
  **/
 static function load_collection($slug, array $options = array())
 {
     $Shopp = Shopp::object();
     foreach ((array) $Shopp->Collections as $Collection) {
         $slugs = SmartCollection::slugs($Collection);
         if (in_array($slug, $slugs)) {
             return new $Collection($options);
         }
     }
     $key = 'id';
     if (!preg_match('/^\\d+$/', $slug)) {
         $key = 'slug';
     }
     return new ProductCategory($slug, $key);
 }