Example #1
0
 /**
  * Parse the query request and initialize Shopp content
  *
  * @author Jonathan Davis
  * @since 1.2
  *
  * @param object $wp_query The WP_Query object (passed via parse_query action)
  * @return void
  **/
 public function query(WP_Query $wp_query)
 {
     if (!$this->request($wp_query)) {
         return;
     }
     $page = $wp_query->get(ShoppPages::QUERYVAR);
     $posttype = $wp_query->get('post_type');
     $product = $wp_query->get(ShoppProduct::$posttype);
     $collection = $wp_query->get('shopp_collection');
     $searching = $wp_query->get('s_cs');
     $search = $wp_query->get('s');
     // Shopp requests are never automatic on the home page
     $wp_query->is_home = false;
     $catalog = ShoppPages()->baseslug();
     // Detect catalog page requests
     if (is_archive() && $posttype == ShoppProduct::$posttype && '' == $product . $collection . $page . $search) {
         $page = $catalog;
         $wp_query->set(ShoppPages::QUERYVAR, $page);
     }
     // Shopp request, remove noindex
     remove_action('wp_head', 'noindex', 1);
     $wp_query->set('suppress_filters', false);
     // Override default WP_Query request
     // Restore paged query var for Shopp's alpha-pagination support
     if (isset($wp_query->query['paged']) && false != preg_match('/([A-Z]|0\\-9)/i', $wp_query->query['paged'])) {
         $wp_query->query_vars['paged'] = strtoupper($wp_query->query['paged']);
     }
     // Handle Taxonomies
     if (is_archive()) {
         $taxonomies = get_object_taxonomies(ShoppProduct::$posttype, 'object');
         foreach ($taxonomies as $t) {
             if ('' == $wp_query->get($t->query_var)) {
                 continue;
             }
             $taxonomy = $wp_query->get($t->query_var);
             if ($t->hierarchical) {
                 ShoppCollection(new ProductCategory($taxonomy, 'slug', $t->name));
             } else {
                 ShoppCollection(new ProductTag($taxonomy, 'slug', $t->name));
             }
             $page = false;
         }
     }
     $options = array();
     if ($searching) {
         // Catalog search
         $collection = 'search-results';
         $options = array('search' => $search);
     }
     // Handle Shopp Smart Collections
     if (!empty($collection)) {
         // Overrides to enforce archive behavior
         $page = $catalog;
         // Promo Collection routing
         $promos = shopp_setting('active_catalog_promos');
         if (isset($promos[$collection])) {
             $options['id'] = $promos[$collection][0];
             $collection = 'promo';
         }
         ShoppCollection(ShoppCatalog::load_collection($collection, $options));
         if (!is_feed()) {
             ShoppCollection()->load(array('load' => array('coverimages')));
         }
         // Provide a stub to the queried object for smart collections since WP has no parallel
         $post_archive = new stdClass();
         $post_archive->labels = new stdClass();
         $post_archive->labels->name = ShoppCollection()->name;
         $post_archive->post_title = ShoppCollection()->name;
         // Added so single_post_title will return the title properly
         $wp_query->queried_object = $post_archive;
         $wp_query->queried_object_id = 0;
     }
     $Collection = ShoppCollection();
     if (!empty($Collection)) {
         $this->Requested = $Collection;
         add_action('wp_head', array($this, 'metadata'));
         remove_action('wp_head', 'feed_links', 2);
         add_action('wp_head', array($this, 'feedlinks'), 2);
     }
     if (!empty($page)) {
         // Overrides to enforce page behavior
         $wp_query->set(ShoppPages::QUERYVAR, $page);
         $wp_query->is_page = true;
         $wp_query->is_singular = true;
         $wp_query->post_count = true;
         $wp_query->shopp_page = true;
         $wp_query->is_archive = false;
     }
 }
Example #2
0
 public function category_children()
 {
     check_admin_referer('wp_ajax_shopp_category_children');
     if (empty($_GET['parent'])) {
         die('0');
     }
     $parent = $_GET['parent'];
     $columns = array('id', 'parent', 'priority', 'name', 'uri', 'slug');
     $filters['columns'] = 'cat.' . join(',cat.', $columns);
     $filters['parent'] = $parent;
     $Catalog = new ShoppCatalog();
     $Catalog->outofstock = true;
     $Catalog->load_categories($filters);
     $columns[] = 'depth';
     foreach ($Catalog->categories as &$Category) {
         $properties = get_object_vars($Category);
         foreach ($properties as $property => $value) {
             if (!in_array($property, $columns)) {
                 unset($Category->{$property});
             }
         }
     }
     die(json_encode($Catalog->categories));
 }
Example #3
0
 /**
  * Provides markup for displaying one or more products in an aside widget
  *
  * @api `shopp('storefront.side-product')`
  * @since 1.0
  *
  * @param string          $result  The output
  * @param array           $options The options
  * - **source**: `product` (product,category) The source of the products to display
  * - **product**: The product custom post-type database ID or list of IDs (comma-separated)
  * - **category**: The taxonomy term ID or list of IDs (comma-separated)
  * - **load**: (on) When set, this option will load the first product (or category) into the working product or category context
  * @param ShoppStorefront $O       The working object
  * @return string The widget markup
  **/
 public static function side_product($result, $options, $O)
 {
     $Shopp = Shopp::object();
     $content = false;
     $source = isset($options['source']) ? $options['source'] : 'product';
     if ($source == 'product' && isset($options['product'])) {
         // Save original requested product
         if ($Shopp->Product) {
             $Requested = $Shopp->Product;
         }
         $products = explode(',', $options['product']);
         if (!is_array($products)) {
             $products = array($products);
         }
         foreach ($products as $product) {
             $product = trim($product);
             if (empty($product)) {
                 continue;
             }
             if (preg_match('/^\\d+$/', $product)) {
                 $Shopp->Product = new ShoppProduct($product);
             } else {
                 $Shopp->Product = new ShoppProduct($product, 'slug');
             }
             if (empty($Shopp->Product->id)) {
                 continue;
             }
             if (isset($options['load'])) {
                 return true;
             }
             ob_start();
             locate_shopp_template(array('sideproduct-' . $Shopp->Product->id . '.php', 'sideproduct.php'), true);
             $content .= ob_get_clean();
         }
         // Restore original requested Product
         if (!empty($Requested)) {
             $Shopp->Product = $Requested;
         } else {
             $Shopp->Product = false;
         }
     }
     if ($source == 'category' && isset($options['category'])) {
         // Save original requested category
         if ($Shopp->Category) {
             $Requested = $Shopp->Category;
         }
         if ($Shopp->Product) {
             $RequestedProduct = $Shopp->Product;
         }
         if (empty($options['category'])) {
             return false;
         }
         if (in_array($options['category'], array_keys($Shopp->Collections))) {
             $Category = ShoppCatalog::load_collection($options['category'], $options);
             ShoppCollection($Category);
         } elseif (intval($options['category']) > 0) {
             // By ID
             ShoppCollection(new ProductCategory($options['category']));
         } else {
             ShoppCollection(new ProductCategory($options['category'], 'slug'));
         }
         if (isset($options['load'])) {
             return true;
         }
         $options['load'] = array('coverimages');
         ShoppCollection()->load($options);
         $template = locate_shopp_template(array('sideproduct-' . $Shopp->Category->slug . '.php', 'sideproduct.php'));
         ob_start();
         foreach (ShoppCollection()->products as &$product) {
             ShoppProduct($product);
             load_template($template, false);
         }
         $content = ob_get_clean();
         // Restore original requested category
         if (!empty($Requested)) {
             $Shopp->Category = $Requested;
         } else {
             $Shopp->Category = false;
         }
         if (!empty($RequestedProduct)) {
             $Shopp->Product = $RequestedProduct;
         } else {
             $Shopp->Product = false;
         }
     }
     return $content;
 }
Example #4
0
 /**
  * Set
  *
  * @author Jonathan Davis
  * @since 1.1
  *
  * @return void
  **/
 public function init_positions()
 {
     // Load the entire catalog structure and update the category positions
     $Catalog = new ShoppCatalog();
     $Catalog->outofstock = true;
     $filters['columns'] = "cat.id,cat.parent,cat.priority";
     $Catalog->load_categories($filters);
     foreach ($Catalog->categories as $Category) {
         if (!isset($Category->_priority) || isset($Category->_priority) && $Category->_priority != $Category->priority) {
             sDB::query("UPDATE {$Category->_table} SET priority={$Category->priority} WHERE id={$Category->id}");
         }
     }
 }