/**
  * Wraps mark-up in a #shopp container, if needed
  *
  * @author Jonathan Davis
  * @since 1.1
  *
  * @param string $string The content markup to be wrapped
  * @param array $classes CSS classes to add to the container
  * @return string The wrapped markup
  **/
 static function wrapper($string)
 {
     $classes = array('shoppage', 'shopp_page');
     $views = array('list', 'grid');
     $view = shopp_setting('default_catalog_view');
     if (empty($view)) {
         $view = 'grid';
     }
     // Handle catalog view style cookie preference
     if (isset($_COOKIE['shopp_catalog_view'])) {
         $view = $_COOKIE['shopp_catalog_view'];
     }
     if (in_array($view, $views)) {
         $classes[] = $view;
     }
     $boxes = shopp_setting('row_products');
     if (empty($boxes)) {
         $boxes = 3;
     }
     $classes[] = 'shopp_grid-' . abs($boxes);
     // Add collection slug
     $Collection = ShoppCollection();
     if (!empty($Collection)) {
         if ($category = shopp('collection.get-slug')) {
             $classes[] = $category;
         }
     }
     // Add product id & slug classes
     $Product = ShoppProduct();
     if (!empty($Product)) {
         if ($productid = shopp('product.get-id')) {
             $classes[] = 'product-' . $productid;
         }
         if ($product = shopp('product.get-slug')) {
             $classes[] = $product;
         }
     }
     $classes = apply_filters('shopp_content_container_classes', $classes);
     $classes = esc_attr(join(' ', $classes));
     $id = false === strpos($string, 'id="shopp"') ? ' id="shopp" ' : '';
     return '<div' . $id . (!empty($classes) ? ' class="' . $classes . '"' : '') . '>' . $string . '</div>';
 }
Exemple #2
0
 public function smart(array $options = array())
 {
     $this->loading['order'] = 'random';
     if (isset($options['order']) && 'chaos' == strtolower($options['order'])) {
         $this->loading['order'] = 'chaos';
     }
     if (isset($options['exclude'])) {
         $where = array();
         $excludes = explode(",", $options['exclude']);
         if (in_array('current-product', $excludes) && isset(ShoppProduct()->id)) {
             $where[] = '(p.id != ' . ShoppProduct()->id . ')';
         }
         if (in_array('featured', $excludes)) {
             $where[] = "(p.featured='off')";
         }
         if (in_array('onsale', $excludes)) {
             $where[] = "(pd.sale='off' OR pr.discount=0)";
         }
         $this->loading['where'] = $where;
     }
     if (isset($options['columns'])) {
         $this->loading['columns'] = $options['columns'];
     }
 }
Exemple #3
0
    /**
     * Handles rendering the [product-buynow] shortcode
     *
     * @author Jonathan Davis
     * @since 1.1
     *
     * @param array $attrs The parsed shortcode attributes
     * @return string The processed content
     **/
    static function buynow(array $atts = array())
    {
        $properties = array('name', 'slug', 'id');
        foreach ($properties as $prop) {
            if (!isset($atts[$prop])) {
                continue;
            }
            $Product = new ShoppProduct($atts[$prop], $prop);
        }
        if (!empty($Product->id)) {
            ShoppProduct($Product);
        } elseif (!isset(ShoppProduct()->id)) {
            return "";
        }
        ob_start();
        ?>
		<form action="<?php 
        shopp('cart.url');
        ?>
" method="post" class="shopp product">
			<input type="hidden" name="redirect" value="checkout" />
			<?php 
        if (isset($atts['variations'])) {
            ?>
				<?php 
            if (shopp('product.has-variations')) {
                ?>
				<ul class="variations">
					<?php 
                shopp('product.variations', 'mode=multiple&label=true&defaults=' . __('Select an option', 'Shopp') . '&before_menu=<li>&after_menu=</li>');
                ?>
				</ul>
				<?php 
            }
            ?>
			<?php 
        }
        ?>
			<?php 
        if (isset($atts['addons'])) {
            ?>
				<?php 
            if (shopp('product.has-addons')) {
                ?>
					<ul class="addons">
						<?php 
                shopp('product.addons', 'mode=menu&label=true&defaults=' . __('Select an add-on', 'Shopp') . '&before_menu=<li>&after_menu=</li>');
                ?>
					</ul>
				<?php 
            }
            ?>
			<?php 
        }
        ?>
			<p><?php 
        if (isset($atts['quantity'])) {
            $quantity = empty($atts['quantity']) ? 'class=selectall&input=menu' : html_entity_decode($atts['quantity']);
            ?>
				<?php 
            shopp('product.quantity', $quantity);
            ?>
			<?php 
        }
        ?>
			<?php 
        $button = 'label=' . (isset($atts['label']) ? $atts['label'] : __('Buy Now', 'Shopp'));
        $button .= isset($atts['ajax']) && Shopp::str_true($atts['ajax']) ? '&ajax=on' : '';
        if (isset($atts['button'])) {
            $button = html_entity_decode($atts['button']);
        }
        ?>
			<?php 
        shopp('product.addtocart', $button);
        ?>
</p>
		</form>
		<?php 
        $markup = ob_get_contents();
        ob_end_clean();
        ShoppStorefront()->shortcoded[] = get_the_ID();
        return apply_filters('shopp_buynow_shortcode', $markup);
    }
 /**
  * Returns the proper global context object used in a shopp('collection') call
  *
  * @internal
  * @since 1.2
  *
  * @param ShoppProduct $Object The ShoppOrder object to set as the working context
  * @param string       $context The context being worked on by the Theme API
  * @return ShoppProduct The active object context
  **/
 public static function _setobject($Object, $object)
 {
     if (is_object($Object) && is_a($Object, 'ShoppProduct')) {
         return $Object;
     }
     if (strtolower($object) != 'product') {
         return $Object;
     } else {
         return ShoppProduct();
     }
 }
Exemple #5
0
 public function load()
 {
     $id = $this->request('id');
     $Product = new ShoppProduct($id);
     ShoppProduct($Product);
     return ShoppProduct();
 }
Exemple #6
0
 /**
  * Iterates over the products in the collection
  *
  * @api `shopp('collection.products')`
  * @since 1.0
  *
  * @param string           $result  The output
  * @param array            $options The options
  * @param ShoppCollection $O       The working object
  * @return bool True if the next product exists, false otherwise
  **/
 public static function products($result, $options, $O)
 {
     if (isset($options['looping'])) {
         return isset($O->_product_loop);
     }
     $null = null;
     if (!isset($O->_product_loop)) {
         reset($O->products);
         ShoppProduct(current($O->products));
         $O->_pindex = 0;
         $O->_rindex = false;
         $O->_product_loop = true;
     } else {
         if ($Product = next($O->products)) {
             ShoppProduct($Product);
         }
         $O->_pindex++;
     }
     if (current($O->products) !== false) {
         return true;
     } else {
         unset($O->_product_loop);
         ShoppProduct($null);
         if (is_a(ShoppStorefront()->Requested, 'ShoppProduct')) {
             ShoppProduct(ShoppStorefront()->Requested);
         }
         $O->_pindex = 0;
         return false;
     }
 }
Exemple #7
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;
 }
Exemple #8
0
        ?>
">
			<?php 
        if ($editing) {
            $data = array('${lineid}' => (int) $_GET['editline'], '${itemname}' => $itemname, '${quantity}' => $Item->quantity, '${unitprice}' => money($Item->unitprice), '${totalprice}' => money($Item->total));
            echo ShoppUI::template($itemeditor, $data);
        } else {
            foreach ($columns as $column => $column_title) {
                $classes = array($column, "column-{$column}");
                if (in_array($column, $hidden)) {
                    $classes[] = 'hidden';
                }
                ob_start();
                switch ($column) {
                    case 'items':
                        ShoppProduct(new ShoppProduct($Item->product));
                        // @todo Find a way to make this more efficient by loading product slugs with load_purchased()?
                        $viewurl = shopp('product.get-url');
                        $editurl = $this->url(array('id' => $Purchase->id, 'editline' => $id));
                        $rmvurl = $this->url(array('id' => $Purchase->id, 'rmvline' => $id));
                        $producturl = $this->url(array('id' => $Item->product));
                        ?>
									<td class="<?php 
                        echo esc_attr(join(' ', $classes));
                        ?>
">
										<a href="<?php 
                        echo $producturl;
                        ?>
">
                                            <?php