function category_shortcode($atts)
 {
     global $Shopp;
     $tag = 'category';
     if (isset($atts['name'])) {
         $Shopp->Category = new Category($atts['name'], 'name');
         unset($atts['name']);
     } elseif (isset($atts['slug'])) {
         switch ($atts['slug']) {
             case SearchResults::$_slug:
                 $tag = 'search-products';
                 unset($atts['slug']);
                 break;
             case TagProducts::$_slug:
                 $tag = 'tag-products';
                 unset($atts['slug']);
                 break;
             case BestsellerProducts::$_slug:
                 $tag = 'bestseller-products';
                 unset($atts['slug']);
                 break;
             case CatalogProducts::$_slug:
                 $tag = 'catalog-products';
                 unset($atts['slug']);
                 break;
             case NewProducts::$_slug:
                 $tag = 'new-products';
                 unset($atts['slug']);
                 break;
             case FeaturedProducts::$_slug:
                 $tag = 'featured-products';
                 unset($atts['slug']);
                 break;
             case OnSaleProducts::$_slug:
                 $tag = 'onsale-products';
                 unset($atts['slug']);
                 break;
             case RandomProducts::$_slug:
                 $tag = 'random-products';
                 unset($atts['slug']);
                 break;
         }
     } elseif (isset($atts['id'])) {
         $Shopp->Category = new Category($atts['id']);
         unset($atts['id']);
     } else {
         return "";
     }
     if (isset($atts['nowrap']) && value_is_true($atts['nowrap'])) {
         return $Shopp->Catalog->tag($tag, $atts);
     } else {
         return '<div id="shopp">' . $Shopp->Catalog->tag($tag, $atts) . '<div class="clear"></div></div>';
     }
 }
Example #2
0
	function smart ($options=array()) {
		$this->slug = self::$_slug;

		global $Ecart;
		$Cart = $Ecart->Order->Cart;
		$tagtable = DatabaseObject::tablename(Tag::$table);
		$catalogtable = DatabaseObject::tablename(Catalog::$table);

		// Use the current product if available
		if (!empty($Ecart->Product->id))
			$this->product = $Ecart->Product;

		// Or load a product specified
		if (isset($options['product'])) {
			if ($options['product'] == "recent-cartitem") 			// Use most recently added item in the cart
				$this->product = new Product($Cart->Added->product);
			elseif (preg_match('/^[\d+]$/',$options['product']) !== false) 	// Load by specified id
				$this->product = new Product($options['product']);
			else
				$this->product = new Product($options['product'],'slug'); // Load by specified slug
		}

		if (empty($this->product->id)) return false;

		// Load the product's tags if they are not available
		if (empty($this->product->tags))
			$this->product->load_data(array('tags'));

		if (empty($this->product->tags)) return false;

		$tagscope = "";
		if (isset($options['tagged'])) {
			$tagged = new Tag($options['tagged'],'name');

			if (!empty($tagged->id)) {
				$tagscope .= (empty($tagscope)?"":" OR ")."catalog.parent=$tagged->id";
			}

		}

		foreach ($this->product->tags as $tag)
			if (!empty($tag->id))
				$tagscope .= (empty($tagscope)?"":" OR ")."catalog.parent=$tag->id";

		if (!empty($tagscope)) $tagscope = "($tagscope) AND catalog.type='tag'";

		$this->tag = "product-".$this->product->id;
		$this->name = __("Products related to","Ecart")." &quot;".stripslashes($this->product->name)."&quot;";
		$this->uri = urlencode($this->tag);
		$this->controls = false;

		$exclude = "";
		if (!empty($this->product->id)) $exclude = " AND p.id != {$this->product->id}";

		$this->loading = array(
			'columns'=>'count(DISTINCT catalog.id)+SUM(IF('.$tagscope.',100,0)) AS score',
			'joins'=>"LEFT JOIN $catalogtable AS catalog ON catalog.product=p.id LEFT JOIN $tagtable AS t ON t.id=catalog.parent AND catalog.product=p.id",
			'where'=>"($tagscope) $exclude",
			'orderby'=>'score DESC'
			);
		if (isset($options['order'])) $this->loading['order'] = $options['order'];
		if (isset($options['controls']) && value_is_true($options['controls']))
			unset($this->controls);
	}
Example #3
0
	function tag ($property,$options=array()) {
		global $Ecart;

		$select_attrs = array('title','required','class','disabled','required','size','tabindex','accesskey');
		$submit_attrs = array('title','class','value','disabled','tabindex','accesskey');

		switch ($property) {
			case "link":
			case "url":
				return ecarturl(ECART_PRETTYURLS?$this->slug:array('ecart_pid'=>$this->id));
				break;
			case "found":
				if (empty($this->id)) return false;
				$load = array('prices','images','specs','tags','categories');
				if (isset($options['load'])) $load = explode(",",$options['load']);
				$this->load_data($load);
				return true;
				break;
			case "relevance": return (string)$this->score; break;
			case "id": return $this->id; break;
			case "name": return apply_filters('ecart_product_name',$this->name); break;
			case "slug": return $this->slug; break;
			case "summary": return apply_filters('ecart_product_summary',$this->summary); break;
			case "description":
				return apply_filters('ecart_product_description',$this->description);
			case "isfeatured":
			case "is-featured":
				return ($this->featured == "on"); break;
			case "price":
			case "saleprice":
				if (empty($this->prices)) $this->load_data(array('prices'));
				$defaults = array(
					'taxes' => null,
					'starting' => ''
				);
				$options = array_merge($defaults,$options);
				extract($options);

				if (!is_null($taxes)) $taxes = value_is_true($taxes);

				$min = $this->min[$property];
				$mintax = $this->min[$property.'_tax'];

				$max = $this->max[$property];
				$maxtax = $this->max[$property.'_tax'];

				$taxrate = ecart_taxrate($taxes,$this->prices[0]->tax,$this);

				if ("saleprice" == $property) $pricetag = $this->prices[0]->promoprice;
				else $pricetag = $this->prices[0]->price;

				if (count($this->options) > 0) {
					$taxrate = ecart_taxrate($taxes,true,$this);
					$mintax = $mintax?$min*$taxrate:0;
					$maxtax = $maxtax?$max*$taxrate:0;

					if ($min == $max) return money($min+$mintax);
					else {
						if (!empty($starting)) return "$starting ".money($min+$mintax);
						return money($min+$mintax)." &mdash; ".money($max+$maxtax);
					}
				} else return money($pricetag+($pricetag*$taxrate));

				break;
			case "taxrate":
				return ecart_taxrate(null,true,$this);
				break;
			case "weight":
				if(empty($this->prices)) $this->load_data(array('prices'));
				$defaults = array(
					'unit' => $Ecart->Settings->get('weight_unit'),
					'min' => $this->min['weight'],
					'max' => $this->max['weight'],
					'units' => true,
					'convert' => false
				);
				$options = array_merge($defaults,$options);
				extract($options);

				if(!isset($this->min['weight'])) return false;

				if ($convert !== false) {
					$min = convert_unit($min,$convert);
					$max = convert_unit($max,$convert);
					if (is_null($units)) $units = true;
					$unit = $convert;
				}

				$range = false;
				if ($min != $max) {
					$range = array($min,$max);
					sort($range);
				}

				$string = ($min == $max)?round($min,3):round($range[0],3)." - ".round($range[1],3);
				$string .= value_is_true($units) ? " $unit" : "";
				return $string;
				break;
			case "onsale":
				if (empty($this->prices)) $this->load_data(array('prices'));
				if (empty($this->prices)) return false;
				return $this->onsale;
				break;
			case "has-savings": return ($this->onsale && $this->min['saved'] > 0); break;
			case "savings":
				if (empty($this->prices)) $this->load_data(array('prices'));
				if (!isset($options['taxes'])) $options['taxes'] = null;

				$taxrate = ecart_taxrate($options['taxes']);
				$range = false;

				if (!isset($options['show'])) $options['show'] = '';
				if ($options['show'] == "%" || $options['show'] == "percent") {
					if ($this->options > 1) {
						if (round($this->min['savings']) != round($this->max['savings'])) {
							$range = array($this->min['savings'],$this->max['savings']);
							sort($range);
						}
						if (!$range) return percentage($this->min['savings'],array('precision' => 0)); // No price range
						else return percentage($range[0],array('precision' => 0))." &mdash; ".percentage($range[1],array('precision' => 0));
					} else return percentage($this->max['savings'],array('precision' => 0));
				} else {
					if ($this->options > 1) {
						if (round($this->min['saved']) != round($this->max['saved'])) {
							$range = array($this->min['saved'],$this->max['saved']);
							sort($range);
						}
						if (!$range) return money($this->min['saved']+($this->min['saved']*$taxrate)); // No price range
						else return money($range[0]+($range[0]*$taxrate))." &mdash; ".money($range[1]+($range[1]*$taxrate));
					} else return money($this->max['saved']+($this->max['saved']*$taxrate));
				}
				break;
			case "freeshipping":
				if (empty($this->prices)) $this->load_data(array('prices'));
				return $this->freeshipping;
			case "hasimages":
			case "has-images":
				if (empty($this->images)) $this->load_data(array('images'));
				return (!empty($this->images));
				break;
			case "images":
				if (!$this->images) return false;
				if (!isset($this->_images_loop)) {
					reset($this->images);
					$this->_images_loop = true;
				} else next($this->images);

				if (current($this->images) !== false) return true;
				else {
					unset($this->_images_loop);
					return false;
				}
				break;
			case "coverimage":
				// Force select the first loaded image
				unset($options['id']);
				$options['index'] = 0;
			case "thumbnail": // deprecated
			case "image":
				if (empty($this->images)) $this->load_data(array('images'));
				if (!(count($this->images) > 0)) return "";

				// Compatibility defaults
				$_size = 96;
				$_width = $Ecart->Settings->get('gallery_thumbnail_width');
				$_height = $Ecart->Settings->get('gallery_thumbnail_height');
				if (!$_width) $_width = $_size;
				if (!$_height) $_height = $_size;

				$defaults = array(
					'img' => false,
					'id' => false,
					'index' => false,
					'class' => '',
					'width' => false,
					'height' => false,
					'size' => false,
					'fit' => false,
					'sharpen' => false,
					'quality' => false,
					'bg' => false,
					'alt' => '',
					'title' => '',
					'zoom' => '',
					'zoomfx' => 'ecart-zoom',
					'property' => false
				);
				$options = array_merge($defaults,$options);
				extract($options);

				// Select image by database id
				if ($id !== false) {
					for ($i = 0; $i < count($this->images); $i++) {
						if ($img->id == $id) {
							$img = $this->images[$i]; break;
						}
					}
					if (!$img) return "";
				}

				// Select image by index position in the list
				if ($index !== false && isset($this->images[$index]))
					$img = $this->images[$index];

				// Use the current image pointer by default
				if (!$img) $img = current($this->images);

				if ($size !== false) $width = $height = $size;
				if (!$width) $width = $_width;
				if (!$height) $height = $_height;

				$scale = $fit?array_search($fit,$img->_scaling):false;
				$sharpen = $sharpen?min($sharpen,$img->_sharpen):false;
				$quality = $quality?min($quality,$img->_quality):false;
				$fill = $bg?hexdec(ltrim($bg,'#')):false;

				list($width_a,$height_a) = array_values($img->scaled($width,$height,$scale));
				if ($size == "original") {
					$width_a = $img->width;
					$height_a = $img->height;
				}
				if ($width_a === false) $width_a = $width;
				if ($height_a === false) $height_a = $height;

				$alt = esc_attr(empty($alt)?(empty($img->alt)?$img->name:$img->alt):$alt);
				$title = empty($title)?$img->title:$title;
				$titleattr = empty($title)?'':' title="'.esc_attr($title).'"';
				$classes = empty($class)?'':' class="'.esc_attr($class).'"';

				$src = ecarturl($img->id,'images');
				if (ECART_PERMALINKS) $src = trailingslashit($src).$img->filename;

				if ($size != "original")
					$src = add_query_string($img->resizing($width,$height,$scale,$sharpen,$quality,$fill),$src);

				switch (strtolower($property)) {
					case "id": return $img->id; break;
					case "url":
					case "src": return $src; break;
					case "title": return $title; break;
					case "alt": return $alt; break;
					case "width": return $width_a; break;
					case "height": return $height_a; break;
					case "class": return $class; break;
				}

				$imgtag = '<img src="'.$src.'"'.$titleattr.' alt="'.$alt.'" width="'.$width_a.'" height="'.$height_a.'" '.$classes.' />';

				if (value_is_true($zoom))
					return '<a href="'.ecarturl($img->id,'images').'/'.$img->filename.'" class="'.$zoomfx.'" rel="product-'.$this->id.'">'.$imgtag.'</a>';

				return $imgtag;
				break;
			case "gallery":
				if (empty($this->images)) $this->load_data(array('images'));
				if (empty($this->images)) return false;
				$styles = '';
				$_size = 240;
				$_width = $Ecart->Settings->get('gallery_small_width');
				$_height = $Ecart->Settings->get('gallery_small_height');

				if (!$_width) $_width = $_size;
				if (!$_height) $_height = $_size;

				$defaults = array(

					// Layout settings
					'margins' => 20,
					'rowthumbs' => false,
					// 'thumbpos' => 'after',

					// Preview image settings
					'p.size' => false,
					'p.width' => false,
					'p.height' => false,
					'p.fit' => false,
					'p.sharpen' => false,
					'p.quality' => false,
					'p.bg' => false,
					'p.link' => true,
					'rel' => '',

					// Thumbnail image settings
					'thumbsize' => false,
					'thumbwidth' => false,
					'thumbheight' => false,
					'thumbfit' => false,
					'thumbsharpen' => false,
					'thumbquality' => false,
					'thumbbg' => false,

					// Effects settings
					'zoomfx' => 'ecart-zoom',
					'preview' => 'click',
					'colorbox' => '{}'


				);
				$optionset = array_merge($defaults,$options);

				// Translate dot names
				$options = array();
				$keys = array_keys($optionset);
				foreach ($keys as $key)
					$options[str_replace('.','_',$key)] = $optionset[$key];
				extract($options);

				if ($p_size > 0)
					$_width = $_height = $p_size;

				$width = $p_width > 0?$p_width:$_width;
				$height = $p_height > 0?$p_height:$_height;

				$preview_width = $width;

				$previews = '<ul class="previews">';
				$firstPreview = true;

				// Find the max dimensions to use for the preview spacing image
				$maxwidth = $maxheight = 0;
				foreach ($this->images as $img) {
					$scale = $p_fit?false:array_search($p_fit,$img->_scaling);
					$scaled = $img->scaled($width,$height,$scale);
					$maxwidth = max($maxwidth,$scaled['width']);
					$maxheight = max($maxheight,$scaled['height']);
				}

				if ($maxwidth == 0) $maxwidth = $width;
				if ($maxheight == 0) $maxheight = $height;

				$p_link = value_is_true($p_link);

				foreach ($this->images as $img) {

					$scale = $p_fit?array_search($p_fit,$img->_scaling):false;
					$sharpen = $p_sharpen?min($p_sharpen,$img->_sharpen):false;
					$quality = $p_quality?min($p_quality,$img->_quality):false;
					$fill = $p_bg?hexdec(ltrim($p_bg,'#')):false;
					$scaled = $img->scaled($width,$height,$scale);

					if ($firstPreview) { // Adds "filler" image to reserve the dimensions in the DOM
						$href = ecarturl(ECART_PERMALINKS?trailingslashit('000'):'000','images');
						$previews .= '<li id="preview-fill"'.(($firstPreview)?' class="fill"':'').'>';
						$previews .= '<img src="'.add_query_string("$maxwidth,$maxheight",$href).'" alt=" " width="'.$maxwidth.'" height="'.$maxheight.'" />';
						$previews .= '</li>';
					}
					$title = !empty($img->title)?' title="'.esc_attr($img->title).'"':'';
					$alt = esc_attr(!empty($img->alt)?$img->alt:$img->filename);

					$previews .= '<li id="preview-'.$img->id.'"'.(($firstPreview)?' class="active"':'').'>';

					$href = ecarturl(ECART_PERMALINKS?trailingslashit($img->id).$img->filename:$img->id,'images');
					if ($p_link) $previews .= '<a href="'.$href.'" class="gallery product_'.$this->id.' '.$options['zoomfx'].'"'.(!empty($rel)?' rel="'.$rel.'"':'').'>';
					// else $previews .= '<a name="preview-'.$img->id.'">'; // If links are turned off, leave the <a> so we don't break layout
					$previews .= '<img src="'.add_query_string($img->resizing($width,$height,$scale,$sharpen,$quality,$fill),ecarturl($img->id,'images')).'"'.$title.' alt="'.$alt.'" width="'.$scaled['width'].'" height="'.$scaled['height'].'" />';
					if ($p_link) $previews .= '</a>';
					$previews .= '</li>';
					$firstPreview = false;
				}
				$previews .= '</ul>';

				$thumbs = "";
				$twidth = $preview_width+$margins;

				if (count($this->images) > 1) {
					$default_size = 64;
					$_thumbwidth = $Ecart->Settings->get('gallery_thumbnail_width');
					$_thumbheight = $Ecart->Settings->get('gallery_thumbnail_height');
					if (!$_thumbwidth) $_thumbwidth = $default_size;
					if (!$_thumbheight) $_thumbheight = $default_size;

					if ($thumbsize > 0) $thumbwidth = $thumbheight = $thumbsize;

					$width = $thumbwidth > 0?$thumbwidth:$_thumbwidth;
					$height = $thumbheight > 0?$thumbheight:$_thumbheight;

					$firstThumb = true;
					$thumbs = '<ul class="thumbnails">';
					foreach ($this->images as $img) {
						$scale = $thumbfit?array_search($thumbfit,$img->_scaling):false;
						$sharpen = $thumbsharpen?min($thumbsharpen,$img->_sharpen):false;
						$quality = $thumbquality?min($thumbquality,$img->_quality):false;
						$fill = $thumbbg?hexdec(ltrim($thumbbg,'#')):false;
						$scaled = $img->scaled($width,$height,$scale);

						$title = !empty($img->title)?' title="'.esc_attr($img->title).'"':'';
						$alt = esc_attr(!empty($img->alt)?$img->alt:$img->name);

						$thumbs .= '<li id="thumbnail-'.$img->id.'" class="preview-'.$img->id.(($firstThumb)?' first':'').'">';
						$thumbs .= '<img src="'.add_query_string($img->resizing($width,$height,$scale,$sharpen,$quality,$fill),ecarturl($img->id,'images')).'"'.$title.' alt="'.$alt.'" width="'.$scaled['width'].'" height="'.$scaled['height'].'" />';
						$thumbs .= '</li>'."\n";
						$firstThumb = false;
					}
					$thumbs .= '</ul>';

				}
				if ($rowthumbs > 0) $twidth = ($width+$margins+2)*(int)$rowthumbs;

				$result = '<div id="gallery-'.$this->id.'" class="gallery">'.$previews.$thumbs.'</div>';
				$script = "\t".'EcartGallery("#gallery-'.$this->id.'","'.$preview.'"'.($twidth?",$twidth":"").');';
				add_storefrontjs($script);

				return $result;

				break;
			case "has-categories":
				if (empty($this->categories)) $this->load_data(array('categories'));
				if (count($this->categories) > 0) return true; else return false; break;
			case "categories":
				if (!isset($this->_categories_loop)) {
					reset($this->categories);
					$this->_categories_loop = true;
				} else next($this->categories);

				if (current($this->categories) !== false) return true;
				else {
					unset($this->_categories_loop);
					return false;
				}
				break;
			case "in-category":
				if (empty($this->categories)) $this->load_data(array('categories'));
				if (isset($options['id'])) $field = "id";
				if (isset($options['name'])) $field = "name";
				if (isset($options['slug'])) $field = "slug";
				foreach ($this->categories as $category)
					if ($category->{$field} == $options[$field]) return true;
				return false;
			case "category":
				$category = current($this->categories);
				if (isset($options['show'])) {
					if ($options['show'] == "id") return $category->id;
					if ($options['show'] == "slug") return $category->slug;
				}
				return $category->name;
				break;
			case "hastags":
			case "has-tags":
				if (empty($this->tags)) $this->load_data(array('tags'));
				if (count($this->tags) > 0) return true; else return false; break;
			case "tags":
				if (!isset($this->_tags_loop)) {
					reset($this->tags);
					$this->_tags_loop = true;
				} else next($this->tags);

				if (current($this->tags) !== false) return true;
				else {
					unset($this->_tags_loop);
					return false;
				}
				break;
			case "tagged":
				if (empty($this->tags)) $this->load_data(array('tags'));
				if (isset($options['id'])) $field = "id";
				if (isset($options['name'])) $field = "name";
				foreach ($this->tags as $tag)
					if ($tag->{$field} == $options[$field]) return true;
				return false;
			case "tag":
				$tag = current($this->tags);
				if (isset($options['show'])) {
					if ($options['show'] == "id") return $tag->id;
				}
				return $tag->name;
				break;
			case "hasspecs":
			case "has-specs":
				if (empty($this->specs)) $this->load_data(array('specs'));
				if (count($this->specs) > 0) {
					$this->merge_specs();
					return true;
				} else return false; break;
			case "specs":
				if (!isset($this->_specs_loop)) {
					reset($this->specs);
					$this->_specs_loop = true;
				} else next($this->specs);

				if (current($this->specs) !== false) return true;
				else {
					unset($this->_specs_loop);
					return false;
				}
				break;
			case "spec":
				$string = "";
				$separator = ": ";
				$delimiter = ", ";
				if (isset($options['separator'])) $separator = $options['separator'];
				if (isset($options['delimiter'])) $separator = $options['delimiter'];

				$spec = current($this->specs);
				if (is_array($spec->value)) $spec->value = join($delimiter,$spec->value);

				if (isset($options['name'])
					&& !empty($options['name'])
					&& isset($this->specskey[$options['name']])) {
						$spec = $this->specskey[$options['name']];
						if (is_array($spec)) {
							if (isset($options['index'])) {
								foreach ($spec as $index => $entry)
									if ($index+1 == $options['index'])
										$content = $entry->value;
							} else {
								foreach ($spec as $entry) $contents[] = $entry->value;
								$content = join($delimiter,$contents);
							}
						} else $content = $spec->value;
					$string = apply_filters('ecart_product_spec',$content);
					return $string;
				}

				if (isset($options['name']) && isset($options['content']))
					$string = "{$spec->name}{$separator}".apply_filters('ecart_product_spec',$spec->value);
				elseif (isset($options['name'])) $string = $spec->name;
				elseif (isset($options['content'])) $string = apply_filters('ecart_product_spec',$spec->value);
				else $string = "{$spec->name}{$separator}".apply_filters('ecart_product_spec',$spec->value);
				return $string;
				break;
			case "has-variations":
				return ($this->variations == "on" && (!empty($this->options['v']) || !empty($this->options))); break;
			case "variations":

				$string = "";

				if (!isset($options['mode'])) {
					if (!isset($this->_prices_loop)) {
						reset($this->prices);
						$this->_prices_loop = true;
					} else next($this->prices);
					$price = current($this->prices);

					if ($price && ($price->type == 'N/A' || $price->context != 'variation'))
						next($this->prices);

					if (current($this->prices) !== false) return true;
					else {
						unset($this->_prices_loop);
						return false;
					}
					return true;
				}

				if ($this->outofstock) return false; // Completely out of stock, hide menus
				if (!isset($options['taxes'])) $options['taxes'] = null;

				$defaults = array(
					'defaults' => '',
					'disabled' => 'show',
					'pricetags' => 'show',
					'before_menu' => '',
					'after_menu' => '',
					'label' => 'on',
					'required' => __('You must select the options for this item before you can add it to your shopping cart.','Ecart')
					);
				$options = array_merge($defaults,$options);

				if ($options['mode'] == "single") {
					if (!empty($options['before_menu'])) $string .= $options['before_menu']."\n";
					if (value_is_true($options['label'])) $string .= '<label for="product-options'.$this->id.'">'. __('Options').': </label> '."\n";

					$string .= '<select name="products['.$this->id.'][price]" id="product-options'.$this->id.'">';
					if (!empty($options['defaults'])) $string .= '<option value="">'.$options['defaults'].'</option>'."\n";

					foreach ($this->prices as $pricetag) {
						if ($pricetag->context != "variation") continue;

						if (!isset($options['taxes']))
							$taxrate = ecart_taxrate(null,$pricetag->tax);
						else $taxrate = ecart_taxrate(value_is_true($options['taxes']),$pricetag->tax);
						$currently = ($pricetag->sale == "on")?$pricetag->promoprice:$pricetag->price;
						$disabled = ($pricetag->inventory == "on" && $pricetag->stock == 0)?' disabled="disabled"':'';

						$price = '  ('.money($currently).')';
						if ($pricetag->type != "N/A")
							$string .= '<option value="'.$pricetag->id.'"'.$disabled.'>'.$pricetag->label.$price.'</option>'."\n";
					}
					$string .= '</select>';
					if (!empty($options['after_menu'])) $string .= $options['after_menu']."\n";

				} else {
					if (!isset($this->options)) return;

					$menuoptions = $this->options;
					if (!empty($this->options['v'])) $menuoptions = $this->options['v'];

					$baseop = $Ecart->Settings->get('base_operations');
					$precision = $baseop['currency']['format']['precision'];

					if (!isset($options['taxes']))
						$taxrate = ecart_taxrate(null,true,$this);
					else $taxrate = ecart_taxrate(value_is_true($options['taxes']),true,$this);

					$pricekeys = array();
					foreach ($this->pricekey as $key => $pricing) {
						$filter = array('');
						$_ = new StdClass();
						if ($pricing->type != "Donation")
							$_->p = ((isset($pricing->onsale)
										&& $pricing->onsale == "on")?
											(float)$pricing->promoprice:
											(float)$pricing->price);
						$_->i = ($pricing->inventory == "on");
						$_->s = ($pricing->inventory == "on")?$pricing->stock:false;
						$_->tax = ($pricing->tax == "on");
						$_->t = $pricing->type;
						$pricekeys[$key] = $_;
					}

					ob_start();
?><?php if (!empty($options['defaults'])): ?>
	sjss.opdef = true;
<?php endif; ?>
<?php if (!empty($options['required'])): ?>
	sjss.opreq = "<?php echo $options['required']; ?>";
<?php endif; ?>
	pricetags[<?php echo $this->id; ?>] = <?php echo json_encode($pricekeys); ?>;
	new ProductOptionsMenus('select<?php if (!empty($Ecart->Category->slug)) echo ".category-".$Ecart->Category->slug; ?>.product<?php echo $this->id; ?>.options',{<?php if ($options['disabled'] == "hide") echo "disabled:false,"; ?><?php if ($options['pricetags'] == "hide") echo "pricetags:false,"; ?><?php if (!empty($taxrate)) echo "taxrate:$taxrate,"?>prices:pricetags[<?php echo $this->id; ?>]});
<?php
					$script = ob_get_contents();
					ob_end_clean();

					add_storefrontjs($script);

					foreach ($menuoptions as $id => $menu) {
						if (!empty($options['before_menu'])) $string .= $options['before_menu']."\n";
						if (value_is_true($options['label'])) $string .= '<label for="options-'.$menu['id'].'">'.$menu['name'].'</label> '."\n";
						$category_class = isset($Ecart->Category->slug)?'category-'.$Ecart->Category->slug:'';
						$string .= '<select name="products['.$this->id.'][options][]" class="'.$category_class.' product'.$this->id.' options" id="options-'.$menu['id'].'">';
						if (!empty($options['defaults'])) $string .= '<option value="">'.$options['defaults'].'</option>'."\n";
						foreach ($menu['options'] as $key => $option)
							$string .= '<option value="'.$option['id'].'">'.$option['name'].'</option>'."\n";

						$string .= '</select>';
					}
					if (!empty($options['after_menu'])) $string .= $options['after_menu']."\n";
				}

				return $string;
				break;
			case "variation":
				$variation = current($this->prices);

				if (!isset($options['taxes'])) $options['taxes'] = null;
				else $options['taxes'] = value_is_true($options['taxes']);
				$taxrate = ecart_taxrate($options['taxes'],$variation->tax,$this);

				$weightunit = (isset($options['units']) && !value_is_true($options['units']) ) ? false : $Ecart->Settings->get('weight_unit');

				$string = '';
				if (array_key_exists('id',$options)) $string .= $variation->id;
				if (array_key_exists('label',$options)) $string .= $variation->label;
				if (array_key_exists('type',$options)) $string .= $variation->type;
				if (array_key_exists('sku',$options)) $string .= $variation->sku;
				if (array_key_exists('price',$options)) $string .= money($variation->price+($variation->price*$taxrate));
				if (array_key_exists('saleprice',$options)) {
					if (isset($options['promos']) && !value_is_true($options['promos'])) {
						$string .= money($variation->saleprice+($variation->saleprice*$taxrate));
					} else $string .= money($variation->promoprice+($variation->promoprice*$taxrate));
				}
				if (array_key_exists('stock',$options)) $string .= $variation->stock;
				if (array_key_exists('weight',$options)) $string .= round($variation->weight, 3) . ($weightunit ? " $weightunit" : false);
				if (array_key_exists('shipfee',$options)) $string .= money(floatvalue($variation->shipfee));
				if (array_key_exists('sale',$options)) return ($variation->sale == "on");
				if (array_key_exists('shipping',$options)) return ($variation->shipping == "on");
				if (array_key_exists('tax',$options)) return ($variation->tax == "on");
				if (array_key_exists('inventory',$options)) return ($variation->inventory == "on");
				return $string;
				break;
			case "has-addons":
				return ($this->addons == "on" && !empty($this->options['a'])); break;
				break;
			case "addons":

				$string = "";

				if (!isset($options['mode'])) {
					if (!$this->priceloop) {
						reset($this->prices);
						$this->priceloop = true;
					} else next($this->prices);
					$thisprice = current($this->prices);

					if ($thisprice && $thisprice->type == "N/A")
						next($this->prices);

					if ($thisprice && $thisprice->context != "addon")
						next($this->prices);

					if (current($this->prices) !== false) return true;
					else {
						$this->priceloop = false;
						return false;
					}
					return true;
				}

				if ($this->outofstock) return false; // Completely out of stock, hide menus
				if (!isset($options['taxes'])) $options['taxes'] = null;

				$defaults = array(
					'defaults' => '',
					'disabled' => 'show',
					'before_menu' => '',
					'after_menu' => ''
					);

				$options = array_merge($defaults,$options);

				if (!isset($options['label'])) $options['label'] = "on";
				if (!isset($options['required'])) $options['required'] = __('You must select the options for this item before you can add it to your shopping cart.','Ecart');
				if ($options['mode'] == "single") {
					if (!empty($options['before_menu'])) $string .= $options['before_menu']."\n";
					if (value_is_true($options['label'])) $string .= '<label for="product-options'.$this->id.'">'. __('Options').': </label> '."\n";

					$string .= '<select name="products['.$this->id.'][price]" id="product-options'.$this->id.'">';
					if (!empty($options['defaults'])) $string .= '<option value="">'.$options['defaults'].'</option>'."\n";

					foreach ($this->prices as $pricetag) {
						if ($pricetag->context != "addon") continue;

						if (isset($options['taxes']))
							$taxrate = ecart_taxrate(value_is_true($options['taxes']),$pricetag->tax,$this);
						else $taxrate = ecart_taxrate(null,$pricetag->tax,$this);
						$currently = ($pricetag->sale == "on")?$pricetag->promoprice:$pricetag->price;
						$disabled = ($pricetag->inventory == "on" && $pricetag->stock == 0)?' disabled="disabled"':'';

						$price = '  ('.money($currently).')';
						if ($pricetag->type != "N/A")
							$string .= '<option value="'.$pricetag->id.'"'.$disabled.'>'.$pricetag->label.$price.'</option>'."\n";
					}

					$string .= '</select>';
					if (!empty($options['after_menu'])) $string .= $options['after_menu']."\n";

				} else {
					if (!isset($this->options['a'])) return;

					$taxrate = ecart_taxrate($options['taxes'],true,$this);

					// Index addon prices by option
					$pricing = array();
					foreach ($this->prices as $pricetag) {
						if ($pricetag->context != "addon") continue;
						$pricing[$pricetag->options] = $pricetag;
					}

					foreach ($this->options['a'] as $id => $menu) {
						if (!empty($options['before_menu'])) $string .= $options['before_menu']."\n";
						if (value_is_true($options['label'])) $string .= '<label for="options-'.$menu['id'].'">'.$menu['name'].'</label> '."\n";
						$category_class = isset($Ecart->Category->slug)?'category-'.$Ecart->Category->slug:'';
						$string .= '<select name="products['.$this->id.'][addons][]" class="'.$category_class.' product'.$this->id.' addons" id="addons-'.$menu['id'].'">';
						if (!empty($options['defaults'])) $string .= '<option value="">'.$options['defaults'].'</option>'."\n";
						foreach ($menu['options'] as $key => $option) {

							$pricetag = $pricing[$option['id']];

							if (isset($options['taxes']))
								$taxrate = ecart_taxrate(value_is_true($options['taxes']),$pricetag->tax,$this);
							else $taxrate = ecart_taxrate(null,$pricetag->tax,$this);

							$currently = ($pricetag->sale == "on")?$pricetag->promoprice:$pricetag->price;
							if ($taxrate > 0) $currently = $currently+($currently*$taxrate);
							$string .= '<option value="'.$option['id'].'">'.$option['name'].' (+'.money($currently).')</option>'."\n";
						}

						$string .= '</select>';
					}
					if (!empty($options['after_menu'])) $string .= $options['after_menu']."\n";

				}

				return $string;
				break;

			case "donation":
			case "amount":
			case "quantity":
				if ($this->outofstock) return false;

				$inputs = array('text','menu');
				$defaults = array(
					'value' => 1,
					'input' => 'text', // accepts text,menu
					'labelpos' => 'before',
					'label' => '',
					'options' => '1-15,20,25,30,40,50,75,100',
					'size' => 3
				);
				$options = array_merge($defaults,$options);
				$_options = $options;
				extract($options);

				unset($_options['label']); // Interferes with the text input value when passed to inputattrs()
				$labeling = '<label for="quantity-'.$this->id.'">'.$label.'</label>';

				if (!isset($this->_prices_loop)) reset($this->prices);
				$variation = current($this->prices);
				$_ = array();

				if ("before" == $labelpos) $_[] = $labeling;
				if ("menu" == $input) {
					if ($this->inventory && $this->max['stock'] == 0) return "";

					if (strpos($options,",") !== false) $options = explode(",",$options);
					else $options = array($options);

					$qtys = array();
					foreach ((array)$options as $v) {
						if (strpos($v,"-") !== false) {
							$v = explode("-",$v);
							if ($v[0] >= $v[1]) $qtys[] = $v[0];
							else for ($i = $v[0]; $i < $v[1]+1; $i++) $qtys[] = $i;
						} else $qtys[] = $v;
					}
					$_[] = '<select name="products['.$this->id.'][quantity]" id="quantity-'.$this->id.'">';
					foreach ($qtys as $qty) {
						$amount = $qty;
						$selection = (isset($this->quantity))?$this->quantity:1;
						if ($variation->type == "Donation" && $variation->donation['var'] == "on") {
							if ($variation->donation['min'] == "on" && $amount < $variation->price) continue;
							$amount = money($amount);
							$selection = $variation->price;
						} else {
							if ($this->inventory && $amount > $this->max['stock']) continue;
						}
						$selected = ($qty==$selection)?' selected="selected"':'';
						$_[] = '<option'.$selected.' value="'.$qty.'">'.$amount.'</option>';
					}
					$_[] = '</select>';
				} elseif (valid_input($input)) {
					if ($variation->type == "Donation" && $variation->donation['var'] == "on") {
						if ($variation->donation['min']) $_options['value'] = $variation->price;
						$_options['class'] .= " currency";
					}
					$_[] = '<input type="'.$input.'" name="products['.$this->id.'][quantity]" id="quantity-'.$this->id.'"'.inputattrs($_options).' />';
				}

				if ("after" == $labelpos) $_[] = $labeling;
				return join("\n",$_);
				break;
			case "input":
				if (!isset($options['type']) ||
					($options['type'] != "menu" && $options['type'] != "textarea" && !valid_input($options['type']))) $options['type'] = "text";
				if (!isset($options['name'])) return "";
				if ($options['type'] == "menu") {
					$result = '<select name="products['.$this->id.'][data]['.$options['name'].']" id="data-'.$options['name'].'-'.$this->id.'"'.inputattrs($options,$select_attrs).'>';
					if (isset($options['options']))
						$menuoptions = preg_split('/,(?=(?:[^\"]*\"[^\"]*\")*(?![^\"]*\"))/',$options['options']);
					if (is_array($menuoptions)) {
						foreach($menuoptions as $option) {
							$selected = "";
							$option = trim($option,'"');
							if (isset($options['default']) && $options['default'] == $option)
								$selected = ' selected="selected"';
							$result .= '<option value="'.$option.'"'.$selected.'>'.$option.'</option>';
						}
					}
					$result .= '</select>';
				} elseif ($options['type'] == "textarea") {
					if (isset($options['cols'])) $cols = ' cols="'.$options['cols'].'"';
					if (isset($options['rows'])) $rows = ' rows="'.$options['rows'].'"';
					$result .= '<textarea name="products['.$this->id.'][data]['.$options['name'].']" id="data-'.$options['name'].'-'.$this->id.'"'.$cols.$rows.inputattrs($options).'>'.$options['value'].'</textarea>';
				} else {
					$result = '<input type="'.$options['type'].'" name="products['.$this->id.'][data]['.$options['name'].']" id="data-'.$options['name'].'-'.$this->id.'"'.inputattrs($options).' />';
				}

				return $result;
				break;
			case "outofstock":
				if ($this->outofstock) {
					$label = isset($options['label'])?$options['label']:$Ecart->Settings->get('outofstock_text');
					$string = '<span class="outofstock">'.$label.'</span>';
					return $string;
				} else return false;
				break;
			case "buynow":
				if (!isset($options['value'])) $options['value'] = __("Buy Now","Ecart");
			case "addtocart":

				if (!isset($options['class'])) $options['class'] = "addtocart";
				else $options['class'] .= " addtocart";
				if (!isset($options['value'])) $options['value'] = __("Add to Cart","Ecart");
				$string = "";

				if ($this->outofstock) {
					$string .= '<span class="outofstock">'.$Ecart->Settings->get('outofstock_text').'</span>';
					return $string;
				}
				if (isset($options['redirect']) && !isset($options['ajax']))
					$string .= '<input type="hidden" name="redirect" value="'.$options['redirect'].'" />';

				$string .= '<input type="hidden" name="products['.$this->id.'][product]" value="'.$this->id.'" />';

				if (!empty($this->prices[0]) && $this->prices[0]->type != "N/A")
					$string .= '<input type="hidden" name="products['.$this->id.'][price]" value="'.$this->prices[0]->id.'" />';

				if (!empty($Ecart->Category)) {
					if (ECART_PRETTYURLS)
						$string .= '<input type="hidden" name="products['.$this->id.'][category]" value="'.$Ecart->Category->uri.'" />';
					else
						$string .= '<input type="hidden" name="products['.$this->id.'][category]" value="'.((!empty($Ecart->Category->id))?$Ecart->Category->id:$Ecart->Category->slug).'" />';
				}

				$string .= '<input type="hidden" name="cart" value="add" />';
				if (isset($options['ajax'])) {
					if ($options['ajax'] == "html") $options['class'] .= ' ajax-html';
					else $options['class'] .= " ajax";
					$string .= '<input type="hidden" name="ajax" value="true" />';
					$string .= '<input type="button" name="addtocart" '.inputattrs($options).' />';
				} else {
					$string .= '<input type="submit" name="addtocart" '.inputattrs($options).' />';
				}

				return $string;
		}


	}
Example #4
0
	/**
	 * Provides ecart('cart') template api functionality
	 *	 
	 * @since 1.0
	 *
	 * @return mixed
	 **/
	function tag ($property,$options=array()) {
		global $Ecart;
		$submit_attrs = array('title','value','disabled','tabindex','accesskey','class');

		// Return strings with no options
		switch ($property) {
			case "url": return ecarturl(false,'cart'); break;
			case "referrer":
			case "referer":
				$referrer = $Ecart->Shopping->data->referrer;
				if (!$referrer) $referrer = ecart('catalog','url','return=1');
				return $referrer;
				break;
			case "hasitems":
			case "has-items": return (count($this->contents) > 0); break;
			case "totalitems":
			case "total-items": return $this->Totals->quantity; break;
			case "items":
				if (!isset($this->_item_loop)) {
					reset($this->contents);
					$this->_item_loop = true;
				} else next($this->contents);

				if (current($this->contents)) return true;
				else {
					unset($this->_item_loop);
					reset($this->contents);
					return false;
				}
				break;
			case "hasshipped":
			case "has-shipped": return $this->shipped(); break;
			case "shippeditems":
			case "shipped-items":
				if (!isset($this->_shipped_loop)) {
					reset($this->shipped);
					$this->_shipped_loop = true;
				} else next($this->shipped);

				if (current($this->shipped)) return true;
				else {
					unset($this->_shipped_loop);
					reset($this->shipped);
					return false;
				}
				break;
			case "hasdownloads":
			case "has-downloads": return $this->downloads(); break;
			case "downloaditems":
			case "download-items":
				if (!isset($this->_downloads_loop)) {
					reset($this->downloads);
					$this->_downloads_loop = true;
				} else next($this->downloads);

				if (current($this->downloads)) return true;
				else {
					unset($this->_downloads_loop);
					reset($this->downloads);
					return false;
				}
				break;
			case "lastitem":
			case "last-item": return $this->contents[$this->added]; break;
			case "totalpromos":
			case "total-promos": return count($this->discounts); break;
			case "haspromos":
			case "has-promos": return (count($this->discounts) > 0); break;
			case "discounts":
			case "promos":
				if (!isset($this->_promo_looping)) {
					reset($this->discounts);
					$this->_promo_looping = true;
				} else next($this->discounts);

				$discount = current($this->discounts);
				while ($discount && empty($discount->applied) && !$discount->freeshipping)
					$discount = next($this->discounts);

				if (current($this->discounts)) return true;
				else {
					unset($this->_promo_looping);
					reset($this->discounts);
					return false;
				}
			case "promoname":
			case "promo-name":
				$discount = current($this->discounts);
				if ($discount->applied == 0 && empty($discount->items) && !isset($this->freeshipping)) return false;
				return $discount->name;
				break;
			case "promodiscount":
			case "promo-discount":
				$discount = current($this->discounts);
				if ($discount->applied == 0 && empty($discount->items) && !isset($this->freeshipping)) return false;
				if (!isset($options['label'])) $options['label'] = ' '.__('Off!','Ecart');
				else $options['label'] = ' '.$options['label'];
				$string = false;
				if (!empty($options['before'])) $string = $options['before'];

				switch($discount->type) {
					case "Free Shipping": $string .= money($discount->freeshipping).$options['label']; break;
					case "Percentage Off": $string .= percentage($discount->discount,array('precision' => 0)).$options['label']; break;
					case "Amount Off": $string .= money($discount->discount).$options['label']; break;
					case "Buy X Get Y Free": return sprintf(__('Buy %s get %s free','Ecart'),$discount->buyqty,$discount->getqty); break;
				}
				if (!empty($options['after'])) $string .= $options['after'];

				return $string;
				break;
			case "function":
				$result = '<div class="hidden"><input type="hidden" id="cart-action" name="cart" value="true" /></div><input type="submit" name="update" id="hidden-update" />';

				$Errors = &EcartErrors();
				if (!$Errors->exist(ECART_STOCK_ERR)) return $result;

				ob_start();
				include(ECART_TEMPLATES."/errors.php");
				$errors = ob_get_contents();
				ob_end_clean();
				return $result.$errors;
				break;
			case "emptybutton":
			case "empty-button":
				if (!isset($options['value'])) $options['value'] = __('Empty Cart','Ecart');
				return '<input type="submit" name="empty" id="empty-button" '.inputattrs($options,$submit_attrs).' />';
				break;
			case "updatebutton":
			case "update-button":
				if (!isset($options['value'])) $options['value'] = __('Update Subtotal','Ecart');
				if (isset($options['class'])) $options['class'] .= " update-button";
				else $options['class'] = "update-button";
				return '<input type="submit" name="update"'.inputattrs($options,$submit_attrs).' />';
				break;
			case "sidecart":
				ob_start();
				include(ECART_TEMPLATES."/sidecart.php");
				$content = ob_get_contents();
				ob_end_clean();
				return $content;
				break;
			case "hasdiscount":
			case "has-discount": return ($this->Totals->discount > 0); break;
			case "discount": return money($this->Totals->discount); break;
		}

		$result = "";
		switch ($property) {
			case "promos-available":
				if (!$Ecart->Promotions->available()) return false;
				// Skip if the promo limit has been reached
				if ($Ecart->Settings->get('promo_limit') > 0 &&
					count($this->discounts) >= $Ecart->Settings->get('promo_limit')) return false;
				return true;
				break;
			case "promo-code":
				// Skip if no promotions exist
				if (!$Ecart->Promotions->available()) return false;
				// Skip if the promo limit has been reached
				if ($Ecart->Settings->get('promo_limit') > 0 &&
					count($this->discounts) >= $Ecart->Settings->get('promo_limit')) return false;
				if (!isset($options['value'])) $options['value'] = __("Apply Promo Code","Ecart");
				$result = '<ul><li>';

				if ($Ecart->Errors->exist()) {
					$result .= '<p class="error">';
					$errors = $Ecart->Errors->source('CartDiscounts');
					foreach ((array)$errors as $error) if (!empty($error)) $result .= $error->message(true,false);
					$result .= '</p>';
				}

				$result .= '<span><input type="text" id="promocode" name="promocode" value="" size="10" /></span>';
				$result .= '<span><input type="submit" id="apply-code" name="update" '.inputattrs($options,$submit_attrs).' /></span>';
				$result .= '</li></ul>';
				return $result;
			case "has-shipping-methods":
				return apply_filters(
							'ecart_shipping_hasestimates',
							(!empty($this->shipping) && !$this->noshipping),
							$this->shipping
						); break;
			case "needs-shipped": return (!empty($this->shipped)); break;
			case "hasshipcosts":
			case "has-shipcosts":
			case "hasship-costs":
			case "has-ship-costs": return ($this->Totals->shipping > 0); break;
			case "needs-shipping-estimates":
				$markets = $Ecart->Settings->get('target_markets');
				return (!empty($this->shipped) && !$this->noshipping && ($this->showpostcode || count($markets) > 1));
				break;
			case "shipping-estimates":
				if (empty($this->shipped)) return "";
				$base = $Ecart->Settings->get('base_operations');
				$markets = $Ecart->Settings->get('target_markets');
				$Shipping = &$Ecart->Order->Shipping;
				if (empty($markets)) return "";
				foreach ($markets as $iso => $country) $countries[$iso] = $country;
				if (!empty($Shipping->country)) $selected = $Shipping->country;
				else $selected = $base['country'];
				$result .= '<ul><li>';
				if ((isset($options['postcode']) && value_is_true($options['postcode'])) || $this->showpostcode) {
					$result .= '<span>';
					$result .= '<input type="text" name="shipping[postcode]" id="shipping-postcode" size="6" value="'.$Shipping->postcode.'" />&nbsp;';
					$result .= '</span>';
				}
				if (count($countries) > 1) {
					$result .= '<span>';
					$result .= '<select name="shipping[country]" id="shipping-country">';
					$result .= menuoptions($countries,$selected,true);
					$result .= '</select>';
					$result .= '</span>';
				} else $result .= '<input type="hidden" name="shipping[country]" id="shipping-country" value="'.key($markets).'" />';
				$result .= '<br class="clear" /></li></ul>';
				return $result;
				break;
		}

		$result = "";
		switch ($property) {
			case "subtotal": $result = $this->Totals->subtotal; break;
			case "shipping":
				if (empty($this->shipped)) return "";
				if (isset($options['label'])) {
					$options['currency'] = "false";
					if ($this->freeshipping) {
						$result = $Ecart->Settings->get('free_shipping_text');
						if (empty($result)) $result = __('Free Shipping!','Ecart');
					}

					else $result = $options['label'];
				} else {
					if ($this->Totals->shipping === null)
						return __("Enter Postal Code","Ecart");
					elseif ($this->Totals->shipping === false)
						return __("Not Available","Ecart");
					else $result = $this->Totals->shipping;
				}
				break;
			case "hastaxes":
			case "has-taxes":
				return ($this->Totals->tax > 0); break;
			case "tax":
				if ($this->Totals->tax > 0) {
					if (isset($options['label'])) {
						$options['currency'] = "false";
						$result = $options['label'];
					} else $result = $this->Totals->tax;
				} else $options['currency'] = "false";
				break;
			case "total":
				$result = $this->Totals->total;
				break;
		}

		if (isset($options['currency']) && !value_is_true($options['currency'])) return $result;
		if (is_numeric($result)) return '<span class="ecart_cart_'.$property.'">'.money($result).'</span>';

		return false;
	}
 function tag($id, $property, $options = array())
 {
     global $Shopp;
     // Return strings with no options
     switch ($property) {
         case "id":
             return $id;
         case "name":
             return $this->name;
         case "link":
         case "url":
             return SHOPP_PERMALINKS ? $Shopp->shopuri . $this->slug : add_query_arg('shopp_pid', $this->product, $Shopp->shopuri);
         case "sku":
             return $this->sku;
     }
     $taxes = false;
     if (isset($options['taxes'])) {
         $taxes = $options['taxes'];
     }
     if ($property == "unitprice" || $property == "total" || $property == "options") {
         $taxrate = shopp_taxrate($taxes, $this->taxable);
     }
     // Handle currency values
     $result = "";
     switch ($property) {
         case "unitprice":
             $result = (double) $this->unitprice + $this->unitprice * $taxrate;
             break;
         case "total":
             $result = (double) $this->total + $this->total * $taxrate;
             break;
         case "tax":
             $result = (double) $this->tax;
             break;
     }
     if (is_float($result)) {
         if (isset($options['currency']) && !value_is_true($options['currency'])) {
             return $result;
         } else {
             return money($result);
         }
     }
     // Handle values with complex options
     switch ($property) {
         case "quantity":
             $result = $this->quantity;
             if ($this->type == "Donation" && $this->donation['var'] == "on") {
                 return $result;
             }
             if (isset($options['input']) && $options['input'] == "menu") {
                 if (!isset($options['value'])) {
                     $options['value'] = $this->quantity;
                 }
                 if (!isset($options['options'])) {
                     $values = "1-15,20,25,30,35,40,45,50,60,70,80,90,100";
                 } else {
                     $values = $options['options'];
                 }
                 if (strpos($values, ",") !== false) {
                     $values = explode(",", $values);
                 } else {
                     $values = array($values);
                 }
                 $qtys = array();
                 foreach ($values as $value) {
                     if (strpos($value, "-") !== false) {
                         $value = explode("-", $value);
                         if ($value[0] >= $value[1]) {
                             $qtys[] = $value[0];
                         } else {
                             for ($i = $value[0]; $i < $value[1] + 1; $i++) {
                                 $qtys[] = $i;
                             }
                         }
                     } else {
                         $qtys[] = $value;
                     }
                 }
                 $result = '<select name="items[' . $id . '][' . $property . ']">';
                 foreach ($qtys as $qty) {
                     $result .= '<option' . ($qty == $this->quantity ? ' selected="selected"' : '') . ' value="' . $qty . '">' . $qty . '</option>';
                 }
                 $result .= '</select>';
             } elseif (isset($options['input']) && valid_input($options['input'])) {
                 if (!isset($options['size'])) {
                     $options['size'] = 5;
                 }
                 if (!isset($options['value'])) {
                     $options['value'] = $this->quantity;
                 }
                 $result = '<input type="' . $options['input'] . '" name="items[' . $id . '][' . $property . ']" id="items-' . $id . '-' . $property . '" ' . inputattrs($options) . '/>';
             } else {
                 $result = $this->quantity;
             }
             break;
         case "remove":
             $label = __("Remove");
             if (isset($options['label'])) {
                 $label = $options['label'];
             }
             if (isset($options['class'])) {
                 $class = ' class="' . $options['class'] . '"';
             } else {
                 $class = ' class="remove"';
             }
             if (isset($options['input'])) {
                 switch ($options['input']) {
                     case "button":
                         $result = '<button type="submit" name="remove[' . $id . ']" value="' . $id . '"' . $class . ' tabindex="">' . $label . '</button>';
                         break;
                     case "checkbox":
                         $result = '<input type="checkbox" name="remove[' . $id . ']" value="' . $id . '"' . $class . ' tabindex="" title="' . $label . '"/>';
                         break;
                 }
             } else {
                 $result = '<a href="' . add_query_arg(array('cart' => 'update', 'item' => $id, 'quantity' => 0), $Shopp->link('cart')) . '"' . $class . '>' . $label . '</a>';
             }
             break;
         case "optionlabel":
             $result = $this->optionlabel;
             break;
         case "options":
             $class = "";
             if (isset($options['show']) && strtolower($options['show']) == "selected") {
                 return !empty($this->optionlabel) ? $options['before'] . $this->optionlabel . $options['after'] : '';
             }
             if (isset($options['class'])) {
                 $class = ' class="' . $options['class'] . '" ';
             }
             if (count($this->options) > 1) {
                 $result .= $options['before'];
                 $result .= '<input type="hidden" name="items[' . $id . '][product]" value="' . $this->product . '"/>';
                 $result .= ' <select name="items[' . $id . '][price]" id="items-' . $id . '-price"' . $class . '>';
                 $result .= $this->options($this->price, $taxrate);
                 $result .= '</select>';
                 $result .= $options['after'];
             }
             break;
         case "hasinputs":
         case "has-inputs":
             return count($this->data) > 0;
             break;
         case "inputs":
             if (!$this->dataloop) {
                 reset($this->data);
                 $this->dataloop = true;
             } else {
                 next($this->data);
             }
             if (current($this->data)) {
                 return true;
             } else {
                 $this->dataloop = false;
                 return false;
             }
             break;
         case "input":
             $data = current($this->data);
             $name = key($this->data);
             if (isset($options['name'])) {
                 return $name;
             }
             return $data;
             break;
         case "inputs-list":
         case "inputslist":
             if (empty($this->data)) {
                 return false;
             }
             $before = "";
             $after = "";
             $classes = "";
             $excludes = array();
             if (!empty($options['class'])) {
                 $classes = ' class="' . $options['class'] . '"';
             }
             if (!empty($options['exclude'])) {
                 $excludes = explode(",", $options['exclude']);
             }
             if (!empty($options['before'])) {
                 $before = $options['before'];
             }
             if (!empty($options['after'])) {
                 $after = $options['after'];
             }
             $result .= $before . '<ul' . $classes . '>';
             foreach ($this->data as $name => $data) {
                 if (in_array($name, $excludes)) {
                     continue;
                 }
                 $result .= '<li><strong>' . $name . '</strong>: ' . $data . '</li>';
             }
             $result .= '</ul>' . $after;
             return $result;
             break;
         case "thumbnail":
             if (!empty($options['class'])) {
                 $options['class'] = ' class="' . $options['class'] . '"';
             }
             if (isset($this->thumbnail)) {
                 $img = $this->thumbnail;
                 $width = isset($options['width']) ? $options['width'] : $img->properties['height'];
                 $height = isset($options['height']) ? $options['height'] : $img->properties['height'];
                 return '<img src="' . $Shopp->imguri . $img->id . '" alt="' . $this->name . ' ' . $img->datatype . '" width="' . $width . '" height="' . $height . '" ' . $options['class'] . ' />';
                 break;
             }
     }
     if (!empty($result)) {
         return $result;
     }
     return false;
 }
Example #6
0
	/**
	 * Renders a checkbox input
	 *
	 * @since 1.1
	 *
	 * @param int $column The table column to add the element to
	 * @param array $attributes Element attributes; use 'checked' to set whether the element is toggled on or not
	 *
	 * @return void
	 **/
	function checkbox ($column=0,$attributes=array()) {
		$attributes['type'] = "checkbox";
		$attributes['normal'] = "off";
		$attributes['value'] = "on";

		$attributes['checked'] = (value_is_true($attributes['checked'])?true:false);

		$attrs = json_encode($attributes);
		echo "$this->module.newInput($column,$attrs);\n";
	}
 function RelatedProducts($options = array())
 {
     global $Shopp;
     $tagtable = DatabaseObject::tablename(Tag::$table);
     $catalogtable = DatabaseObject::tablename(Catalog::$table);
     // Use the current product if available
     if (!empty($Shopp->Product->id)) {
         $this->product = $Shopp->Product;
     }
     // Or load a product specified
     if (isset($options['product'])) {
         if ($options['product'] == "recent-cartitem") {
             // Use most recently added item in the cart
             $this->product = new Product($Shopp->Cart->contents[$Shopp->Cart->data->added]->product);
         } elseif (preg_match('/^[\\d+]$/', $options['product'])) {
             // Load by specified id
             $this->product = new Product($options['product']);
         } else {
             $this->product = new Product($options['product'], 'slug');
         }
         // Load by specified slug
     }
     if (empty($this->product->id)) {
         return false;
     }
     // Load the product's tags if they are not available
     if (empty($this->product->tags)) {
         $this->product->load_data(array('tags'));
     }
     if (empty($this->product->tags)) {
         return false;
     }
     $tagscope = "";
     if (isset($options['tagged'])) {
         $tagged = new Tag($options['tagged'], 'name');
         if (!empty($tagged->id)) {
             $tagscope .= (empty($tagscope) ? "" : " OR ") . "catalog.tag={$tagged->id}";
         }
     }
     foreach ($this->product->tags as $tag) {
         if (!empty($tag->id)) {
             $tagscope .= (empty($tagscope) ? "" : " OR ") . "catalog.tag={$tag->id}";
         }
     }
     $this->tag = "product-" . $this->product->id;
     $this->name = __("Products related to", "Shopp") . " &quot;" . stripslashes($this->product->name) . "&quot;";
     $this->slug = self::$_slug;
     $this->uri = urlencode($this->tag);
     $this->smart = true;
     $this->controls = false;
     $exclude = "";
     if (!empty($this->product->id)) {
         $exclude = " AND p.id != {$this->product->id}";
     }
     $this->loading = array('columns' => 'count(DISTINCT catalog.id)+SUM(IF(' . $tagscope . ',100,0)) AS score', 'joins' => "LEFT JOIN {$catalogtable} AS catalog ON catalog.product=p.id LEFT JOIN {$tagtable} AS t ON t.id=catalog.tag AND catalog.product=p.id", 'where' => "({$tagscope}) {$exclude}", 'orderby' => 'score DESC');
     if (isset($options['show'])) {
         $this->loading['limit'] = $options['show'];
     }
     if (isset($options['pagination'])) {
         $this->loading['pagination'] = $options['pagination'];
     }
     if (isset($options['order'])) {
         $this->loading['order'] = $options['order'];
     }
     if (isset($options['controls']) && value_is_true($options['controls'])) {
         unset($this->controls);
     }
 }
function shopp_taxrate($override = null, $taxprice = true)
{
    global $Shopp;
    $rated = false;
    $taxrate = 0;
    $base = $Shopp->Settings->get('base_operations');
    if ($base['vat']) {
        $rated = true;
    }
    if (!is_null($override)) {
        $rated = value_is_true($override);
    }
    if (!value_is_true($taxprice)) {
        $rated = false;
    }
    if ($rated) {
        $taxrate = $Shopp->Cart->taxrate();
    }
    return $taxrate;
}
Example #9
0
	function tag ($property,$options=array()) {
		global $Ecart;

		$taxes = isset($options['taxes'])?$options['taxes']:false;
		$taxrate = 0;
		if ($property == "item-unitprice" || $property == "item-total")
			$taxrate = ecart_taxrate($taxes);

		// Return strings with no options
		switch ($property) {
			case "receipt":
				// Skip the receipt processing when sending order notifications in admin without the receipt
				if (defined('WP_ADMIN') && isset($_POST['receipt']) && $_POST['receipt'] == "no") return;
				if (isset($options['template']) && is_readable(ECART_TEMPLATES."/".$options['template']))
					return $this->receipt($template);
				else return $this->receipt();
				break;
			case "url": return ecarturl(false,'account'); break;
			case "id": return $this->id; break;
			case "customer": return $this->customer; break;
			case "date":
				if (empty($options['format'])) $options['format'] = get_option('date_format').' '.get_option('time_format');
				return _d($options['format'],((is_int($this->created))?$this->created:mktimestamp($this->created)));
				break;
			case "card": return (!empty($this->card))?sprintf("%'X16d",$this->card):''; break;
			case "cardtype": return $this->cardtype; break;
			case "txnid":
			case "transactionid": return $this->txnid; break;
			case "firstname": return esc_html($this->firstname); break;
			case "lastname": return esc_html($this->lastname); break;
			case "company": return esc_html($this->company); break;
			case "email": return esc_html($this->email); break;
			case "phone": return esc_html($this->phone); break;
			case "address": return esc_html($this->address); break;
			case "xaddress": return esc_html($this->xaddress); break;
			case "city": return esc_html($this->city); break;
			case "state":
				if (strlen($this->state > 2)) return esc_html($this->state);
				$regions = Lookup::country_zones();
				$states = $regions[$this->country];
				return $states[$this->state];
				break;
			case "postcode": return esc_html($this->postcode); break;
			case "country":
				$countries = $Ecart->Settings->get('target_markets');
				return $countries[$this->country]; break;
			case "shipaddress": return esc_html($this->shipaddress); break;
			case "shipxaddress": return esc_html($this->shipxaddress); break;
			case "shipcity": return esc_html($this->shipcity); break;
			case "shipstate":
				if (strlen($this->shipstate > 2)) return esc_html($this->shipstate);
				$regions = Lookup::country_zones();
				$states = $regions[$this->country];
				return $states[$this->shipstate];
				break;
			case "shippostcode": return esc_html($this->shippostcode); break;
			case "shipcountry":
				$countries = $Ecart->Settings->get('target_markets');
				return $countries[$this->shipcountry]; break;
			case "shipmethod": return esc_html($this->shipmethod); break;
			case "totalitems": return count($this->purchased); break;
			case "has-items":
			case "hasitems":
				if (empty($this->purchased)) $this->load_purchased();
				return (count($this->purchased) > 0);
				break;
			case "items":
				if (!isset($this->_items_loop)) {
					reset($this->purchased);
					$this->_items_loop = true;
				} else next($this->purchased);

				if (current($this->purchased) !== false) return true;
				else {
					unset($this->_items_loop);
					return false;
				}
			case "item-id":
				$item = current($this->purchased);
				return $item->id; break;
			case "item-product":
				$item = current($this->purchased);
				return $item->product; break;
			case "item-price":
				$item = current($this->purchased);
				return $item->price; break;
			case "item-name":
				$item = current($this->purchased);
				return $item->name; break;
			case "item-description":
				$item = current($this->purchased);
				return $item->description; break;
			case "item-options":
				if (!isset($options['after'])) $options['after'] = "";
				$item = current($this->purchased);
				return (!empty($item->optionlabel))?$options['before'].$item->optionlabel.$options['after']:''; break;
			case "item-sku":
				$item = current($this->purchased);
				return $item->sku; break;
			case "item-download":
				$item = current($this->purchased);
				if (empty($item->download)) return "";
				if (!isset($options['label'])) $options['label'] = __('Download','Ecart');
				$classes = "";
				if (isset($options['class'])) $classes = ' class="'.$options['class'].'"';
				$request = ECART_PRETTYURLS?
					"download/$item->dkey":
					array('src'=>'download','ecart_download'=>$item->dkey);
				$url = ecarturl($request,'catalog');
				return '<a href="'.$url.'"'.$classes.'>'.$options['label'].'</a>'; break;
			case "item-quantity":
				$item = current($this->purchased);
				return $item->quantity; break;
			case "item-unitprice":
				$item = current($this->purchased);
				$amount = $item->unitprice+($this->taxing == 'inclusive'?$item->unittax:0);
				return money($amount); break;
			case "item-total":
				$item = current($this->purchased);
				$amount = $item->total+($this->taxing == 'inclusive'?$item->unittax*$item->quantity:0);
				return money($amount); break;
			case "item-has-inputs":
			case "item-hasinputs":
				$item = current($this->purchased);
				return (count($item->data) > 0); break;
			case "item-inputs":
				$item = current($this->purchased);
				if (!isset($this->_iteminputs_loop)) {
					reset($item->data);
					$this->_iteminputs_loop = true;
				} else next($item->data);

				if (current($item->data) !== false) return true;
				else {
					unset($this->_iteminputs_loop);
					return false;
				}
				break;
			case "item-input":
				$item = current($this->purchased);
				$data = current($item->data);
				$name = key($item->data);
				if (isset($options['name'])) return esc_html($name);
				return esc_html($data);
				break;
			case "item-inputs-list":
			case "item-inputslist":
			case "item-inputs-list":
			case "iteminputslist":
				$item = current($this->purchased);
				if (empty($item->data)) return false;
				$before = ""; $after = ""; $classes = ""; $excludes = array();
				if (!empty($options['class'])) $classes = ' class="'.$options['class'].'"';
				if (!empty($options['exclude'])) $excludes = explode(",",$options['exclude']);
				if (!empty($options['before'])) $before = $options['before'];
				if (!empty($options['after'])) $after = $options['after'];

				$result .= $before.'<ul'.$classes.'>';
				foreach ($item->data as $name => $data) {
					if (in_array($name,$excludes)) continue;
					$result .= '<li><strong>'.esc_html($name).'</strong>: '.esc_html($data).'</li>';
				}
				$result .= '</ul>'.$after;
				return $result;
				break;
			case "item-has-addons":
			case "item-hasaddons":
				$item = current($this->purchased);
				return (count($item->addons) > 0); break;
			case "item-addons":
				$item = current($this->purchased);
				if (!isset($this->_itemaddons_loop)) {
					reset($item->addons->meta);
					$this->_itemaddons_loop = true;
				} else next($item->addons->meta);

				if (current($item->addons->meta) !== false) return true;
				else {
					unset($this->_itemaddons_loop);
					return false;
				}
				break;
			case "item-addons":
				$item = current($this->purchased);
				$addon = current($item->addons->meta);
				if (isset($options['id'])) return esc_html($addon->id);
				if (isset($options['name'])) return esc_html($addon->name);
				if (isset($options['label'])) return esc_html($addon->name);
				if (isset($options['type'])) return esc_html($addon->value->type);
				if (isset($options['onsale'])) return $addon->value->onsale;
				if (isset($options['inventory'])) return $addon->value->inventory;
				if (isset($options['sku'])) return esc_html($addon->value->sku);
				if (isset($options['unitprice'])) return money($addon->value->unitprice);
				return money($addon->value->unitprice);
				break;
			case "item-addons-list":
			case "item-addonslist":
			case "item-addons-list":
			case "itemaddonslist":
				$item = current($this->purchased);
				if (empty($item->addons)) return false;
				$defaults = array(
					'prices' => "on",
					'download' => __('Download','Ecart'),
					'before' => '',
					'after' => '',
					'classes' => '',
					'excludes' => ''
				);
				$options = array_merge($defaults,$options);
				extract($options);

				$class = !empty($classes)?' class="'.join(' ',explode(',',$classes)).'"':'';
				$taxrate = 0;
				if ($item->unitprice > 0)
					$taxrate = round($item->unittax/$item->unitprice,4);

				$result = $before.'<ul'.$class.'>';
				foreach ($item->addons->meta as $id => $addon) {
					if (in_array($addon->name,$excludes)) continue;
					if ($this->taxing == "inclusive")
						$price = $addon->value->unitprice+($addon->value->unitprice*$taxrate);
					else $price = $addon->value->unitprice;

					$link = false;
					if (isset($addon->value->download) && isset($addon->value->dkey)) {
						$dkey = $addon->value->dkey;
						$request = ECART_PRETTYURLS?"download/$dkey":array('ecart_download'=>$dkey);
						$url = ecarturl($request,'catalog');
						$link = '<br /><a href="'.$url.'">'.$download.'</a>';
					}

					$pricing = value_is_true($prices)?" (".money($price).")":"";
					$result .= '<li>'.esc_html($addon->name.$pricing).$link.'</li>';
				}
				$result .= '</ul>'.$after;
				return $result;
				break;
			case "has-data":
			case "hasdata": return (is_array($this->data) && count($this->data) > 0); break;
			case "orderdata":
				if (!isset($this->_data_loop)) {
					reset($this->data);
					$this->_data_loop = true;
				} else next($this->data);

				if (current($this->data) !== false) return true;
				else {
					unset($this->_data_loop);
					return false;
				}
				break;
			case "data":
				if (!is_array($this->data)) return false;
				$data = current($this->data);
				$name = key($this->data);
				if (isset($options['name'])) return esc_html($name);
				return esc_html($data);
				break;
			case "promolist":
			case "promo-list":
				$output = "";
				if (!empty($this->promos)) {
					$output .= '<ul>';
					foreach ($this->promos as $promo)
						$output .= '<li>'.$promo.'</li>';
					$output .= '</ul>';
				}
				return $output;
			case "has-promo":
			case "haspromo":
				if (empty($options['name'])) return false;
				return (in_array($options['name'],$this->promos));
				break;
			case "subtotal": return money($this->subtotal); break;
			case "hasfreight": return (!empty($this->shipmethod) || $this->freight > 0);
			case "freight": return money($this->freight); break;
			case "hasdownloads": return ($this->downloads);
			case "hasdiscount": return ($this->discount > 0);
			case "discount": return money($this->discount); break;
			case "hastax": return ($this->tax > 0)?true:false;
			case "tax": return money($this->tax); break;
			case "total": return money($this->total); break;
			case "status":
				$labels = $Ecart->Settings->get('order_status');
				if (empty($labels)) $labels = array('');
				return $labels[$this->status];
				break;
			case "paid": return ($this->txnstatus == "CHARGED"); break;
			case "notpaid": return ($this->txnstatus != "CHARGED"); break;
			case "payment":
				$labels = Lookup::payment_status_labels();
				return isset($labels[$this->txnstatus])?$labels[$this->txnstatus]:$this->txnstatus; break;
		}
	}
/**
 * shopp()
 * Provides the Shopp 'tag' support to allow for complete 
 * customization of customer interfaces
 *
 * @param $object The object to get the tag property from
 * @param $property The property of the object to get/output
 * @param $options Custom options for the property result in query form 
 *                   (option1=value&option2=value&...) or alternatively as an associative array
 */
function shopp()
{
    global $Shopp;
    $args = func_get_args();
    $object = strtolower($args[0]);
    $property = strtolower($args[1]);
    $options = array();
    if (isset($args[2])) {
        if (is_array($args[2]) && !empty($args[2])) {
            // handle associative array for options
            foreach (array_keys($args[2]) as $key) {
                $options[strtolower($key)] = $args[2][$key];
            }
        } else {
            // regular url-compatible arguments
            $paramsets = explode("&", $args[2]);
            foreach ((array) $paramsets as $paramset) {
                if (empty($paramset)) {
                    continue;
                }
                $key = $paramset;
                $value = "";
                if (strpos($paramset, "=") !== false) {
                    list($key, $value) = explode("=", $paramset);
                }
                $options[strtolower($key)] = $value;
            }
        }
    }
    $Object = false;
    $result = false;
    switch (strtolower($object)) {
        case "cart":
            if (isset($Shopp->Cart)) {
                $Object =& $Shopp->Cart;
            }
            break;
        case "cartitem":
            if (isset($Shopp->Cart)) {
                $Object =& $Shopp->Cart;
            }
            break;
        case "shipping":
            if (isset($Shopp->Cart)) {
                $Object =& $Shopp->Cart;
            }
            break;
        case "checkout":
            if (isset($Shopp->Cart)) {
                $Object =& $Shopp->Cart;
            }
            break;
        case "category":
            if (isset($Shopp->Category)) {
                $Object =& $Shopp->Category;
            }
            break;
        case "subcategory":
            if (isset($Shopp->Category->child)) {
                $Object =& $Shopp->Category->child;
            }
            break;
        case "catalog":
            if (isset($Shopp->Catalog)) {
                $Object =& $Shopp->Catalog;
            }
            break;
        case "product":
            if (isset($Shopp->Product)) {
                $Object =& $Shopp->Product;
            }
            break;
        case "purchase":
            if (isset($Shopp->Cart->data->Purchase)) {
                $Object =& $Shopp->Cart->data->Purchase;
            }
            break;
        case "customer":
            if (isset($Shopp->Cart->data->Order->Customer)) {
                $Object =& $Shopp->Cart->data->Order->Customer;
            }
            break;
        case "error":
            if (isset($Shopp->Cart->data->Errors)) {
                $Object =& $Shopp->Cart->data->Errors;
            }
            break;
        default:
            $Object = false;
    }
    if (!$Object) {
        new ShoppError("The shopp('{$object}') tag cannot be used in this context because the object responsible for handling it doesn't exist.", 'shopp_tag_error', SHOPP_ADMIN_ERR);
    } else {
        switch (strtolower($object)) {
            case "cartitem":
                $result = $Object->itemtag($property, $options);
                break;
            case "shipping":
                $result = $Object->shippingtag($property, $options);
                break;
            case "checkout":
                $result = $Object->checkouttag($property, $options);
                break;
            default:
                $result = $Object->tag($property, $options);
                break;
        }
    }
    // Force boolean result
    if (isset($options['is'])) {
        if (value_is_true($options['is'])) {
            if ($result) {
                return true;
            }
        } else {
            if ($result == false) {
                return true;
            }
        }
        return false;
    }
    // Always return a boolean if the result is boolean
    if (is_bool($result)) {
        return $result;
    }
    // Return the result instead of outputting it
    if (isset($options['return']) && value_is_true($options['return']) || isset($options['echo']) && !value_is_true($options['echo'])) {
        return $result;
    }
    // Output the result
    echo $result;
    return true;
}
Example #11
0
	function tag ($property,$options=array()) {
		global $Ecart;

		$Order =& $Ecart->Order;
		$checkout = false;
		if (isset($Ecart->Flow->Controller->checkout))
			$checkout = $Ecart->Flow->Controller->checkout;

		// Return strings with no options
		switch ($property) {
			case "url":
				return ecarturl(array('acct'=>null),'account',$Ecart->Gateways->secure); break;
			case "action":
				$action = null;
				if (isset($this->pages[$_GET['acct']])) $action = $_GET['acct'];
				return ecarturl(array('acct'=>$action),'account');
				break;

			case "accounturl": return ecarturl(false,'account'); break;
			case "recover-url": return add_query_arg('acct','recover',ecarturl(false,'account'));
			case "registration-form":
				$regions = Lookup::country_zones();
				add_storefrontjs("var regions = ".json_encode($regions).";",true);
				return $_SERVER['REQUEST_URI'];
				break;
			case "registration-errors":
				$Errors =& EcartErrors();
				if (!$Errors->exist(ECART_ERR)) return false;
				ob_start();
				include(ECART_TEMPLATES.'/errors.php');
				$markup = ob_get_contents();
				ob_end_clean();
				return $markup;
				break;
			case "register":
				return '<input type="submit" name="ecart_registration" value="Register" />';
				break;
			case "process":
				if (!empty($_GET['acct']) && isset($this->pages[$_GET['acct']])) return $_GET['acct'];
				return false;

			case "loggedin": return $Ecart->Order->Customer->login; break;
			case "notloggedin": return (!$Ecart->Order->Customer->login && $Ecart->Settings->get('account_system') != "none"); break;
			case "login-label":
				$accounts = $Ecart->Settings->get('account_system');
				$label = __('Email Address','Ecart');
				if ($accounts == "wordpress") $label = __('Login Name','Ecart');
				if (isset($options['label'])) $label = $options['label'];
				return $label;
				break;
			case "email-login":
			case "loginname-login":
			case "account-login":
				$id = "account-login".($checkout?"-checkout":'');
				if (!empty($_POST['account-login']))
					$options['value'] = $_POST['account-login'];
				if (!isset($options['autocomplete'])) $options['autocomplete'] = "off";
				return '<input type="text" name="account-login" id="'.$id.'"'.inputattrs($options).' />';
				break;
			case "password-login":
				if (!isset($options['autocomplete'])) $options['autocomplete'] = "off";
				$id = "password-login".($checkout?"-checkout":'');

				if (!empty($_POST['password-login']))
					$options['value'] = $_POST['password-login'];
				return '<input type="password" name="password-login" id="'.$id.'"'.inputattrs($options).' />';
				break;
			case "recover-button":
				if (!isset($options['value'])) $options['value'] = __('Get New Password','Ecart');
 					return '<input type="submit" name="recover-login" id="recover-button"'.inputattrs($options).' />';
				break;
			case "submit-login": // Deprecating
			case "login-button":
				if (!isset($options['value'])) $options['value'] = __('Login','Ecart');
				$string = "";
				$id = "submit-login";

				$request = $_GET;
				if (isset($request['acct']) && $request['acct'] == "logout") unset($request['acct']);

				if ($checkout) {
					$id .= "-checkout";
					$string .= '<input type="hidden" name="process-login" id="process-login" value="false" />';
					$string .= '<input type="hidden" name="redirect" value="checkout" />';
				} else $string .= '<input type="hidden" name="process-login" value="true" /><input type="hidden" name="redirect" value="'.ecarturl($request,'account',$Order->security()).'" />';
				$string .= '<input type="submit" name="submit-login" id="'.$id.'"'.inputattrs($options).' />';
				return $string;
				break;
			case "profile-saved":
				$saved = (isset($this->_saved) && $this->_saved);
				unset($this->_saved);
				return $saved;
			case "password-changed":
				$change = (isset($this->_password_change) && $this->_password_change);
				unset($this->_password_change);
				return $change;
			case "errors-exist": return true;
				$Errors = &EcartErrors();
				return ($Errors->exist(ECART_AUTH_ERR));
				break;
			case "login-errors": // @deprecated
			case "errors":
				if (!apply_filters('ecart_show_account_errors',true)) return false;
				$Errors = &EcartErrors();
				if (!$Errors->exist(ECART_AUTH_ERR)) return false;

				ob_start();
				include(ECART_TEMPLATES."/errors.php");
				$errors = ob_get_contents();
				ob_end_clean();
				return $errors;
				break;

			case "menu":
				if (!isset($this->_menu_looping)) {
					reset($this->menus);
					$this->_menu_looping = true;
				} else next($this->menus);

				if (current($this->menus) !== false) return true;
				else {
					unset($this->_menu_looping);
					reset($this->menus);
					return false;
				}
				break;
			case "management":
				$page = current($this->menus);
				if (array_key_exists('url',$options)) return ecarturl(array('acct'=>$page->request),'account');
				if (array_key_exists('action',$options)) return $page->request;
				return $page->label;
			case "accounts": return $Ecart->Settings->get('account_system'); break;
			case "hasaccount":
				$system = $Ecart->Settings->get('account_system');
				if ($system == "wordpress") return ($this->wpuser != 0);
				elseif ($system == "ecart") return (!empty($this->password));
				else return false;
			case "wpuser-created": return $this->newuser;
			case "order-lookup":
				$auth = $Ecart->Settings->get('account_system');
				if ($auth != "none") return true;

				if (!empty($_POST['vieworder']) && !empty($_POST['purchaseid'])) {
					require_once("Purchase.php");
					$Purchase = new Purchase($_POST['purchaseid']);
					if ($Purchase->email == $_POST['email']) {
						$Ecart->Purchase = $Purchase;
						$Purchase->load_purchased();
						ob_start();
						include(ECART_TEMPLATES."/receipt.php");
						$content = ob_get_contents();
						ob_end_clean();
						return apply_filters('ecart_order_lookup',$content);
					}
				}

				ob_start();
				include(ECART_ADMIN_PATH."/orders/account.php");
				$content = ob_get_contents();
				ob_end_clean();
				return apply_filters('ecart_order_lookup',$content);
				break;

			case "firstname":
				if (isset($options['mode']) && $options['mode'] == "value") return $this->firstname;
				if (!empty($this->firstname))
					$options['value'] = $this->firstname;
				return '<input type="text" name="firstname" id="firstname"'.inputattrs($options).' />';
				break;
			case "lastname":
				if (isset($options['mode']) && $options['mode'] == "value") return $this->lastname;
				if (!empty($this->lastname))
					$options['value'] = $this->lastname;
				return '<input type="text" name="lastname" id="lastname"'.inputattrs($options).' />';
				break;
			case "company":
				if (isset($options['mode']) && $options['mode'] == "value") return $this->company;
				if (!empty($this->company))
					$options['value'] = $this->company;
				return '<input type="text" name="company" id="company"'.inputattrs($options).' />';
				break;
			case "email":
				if (isset($options['mode']) && $options['mode'] == "value") return $this->email;
				if (!empty($this->email))
					$options['value'] = $this->email;
				return '<input type="text" name="email" id="email"'.inputattrs($options).' />';
				break;
			case "loginname":
				if (isset($options['mode']) && $options['mode'] == "value") return $this->loginname;
				if (!isset($options['autocomplete'])) $options['autocomplete'] = "off";
				if (!empty($this->loginname))
					$options['value'] = $this->loginname;
				return '<input type="text" name="loginname" id="login"'.inputattrs($options).' />';
				break;
			case "password":
				if (!isset($options['autocomplete'])) $options['autocomplete'] = "off";
				if (isset($options['mode']) && $options['mode'] == "value")
					return strlen($this->password) == 34?str_pad('&bull;',8):$this->password;
				$options['value'] = "";
				return '<input type="password" name="password" id="password"'.inputattrs($options).' />';
				break;
			case "confirm-password":
				if (!isset($options['autocomplete'])) $options['autocomplete'] = "off";
				$options['value'] = "";
				return '<input type="password" name="confirm-password" id="confirm-password"'.inputattrs($options).' />';
				break;
			case "phone":
				if (isset($options['mode']) && $options['mode'] == "value") return $this->phone;
				if (!empty($this->phone))
					$options['value'] = $this->phone;
				return '<input type="text" name="phone" id="phone"'.inputattrs($options).' />';
				break;
			case "hasinfo":
			case "has-info":
				if (!is_object($this->info) || empty($this->info->meta)) return false;
				if (!isset($this->_info_looping)) {
					reset($this->info->meta);
					$this->_info_looping = true;
				} else next($this->info->meta);

				if (current($this->info->meta) !== false) return true;
				else {
					unset($this->_info_looping);
					reset($this->info->meta);
					return false;
				}
				break;
			case "info":
				$defaults = array(
					'mode' => 'input',
					'type' => 'text',
					'name' => false,
					'value' => false
				);
				$options = array_merge($defaults,$options);
				extract($options);

				if ($this->_info_looping)
					$info = current($this->info->meta);
				elseif ($name !== false && is_object($this->info->named[$name]))
					$info = $this->info->named[$name];

				switch ($mode) {
					case "name": return $info->name; break;
					case "value": return $info->value; break;
				}

				if (!$name && !empty($info->name)) $options['name'] = $info->name;
				elseif (!$name) return false;

				if (!$value && !empty($info->value)) $options['value'] = $info->value;

				$allowed_types = array("text","password","hidden","checkbox","radio");
				$type = in_array($type,$allowed_types)?$type:'hidden';
				return '<input type="'.$type.'" name="info['.$options['name'].']" id="customer-info-'.sanitize_title_with_dashes($options['name']).'"'.inputattrs($options).' />';
				break;

			// SHIPPING TAGS
			case "shipping": return $Order->Shipping;
			case "shipping-address":
				if ($options['mode'] == "value") return $Order->Shipping->address;
				if (!empty($Order->Shipping->address))
					$options['value'] = $Order->Shipping->address;
				return '<input type="text" name="shipping[address]" id="shipping-address" '.inputattrs($options).' />';
				break;
			case "shipping-xaddress":
				if ($options['mode'] == "value") return $Order->Shipping->xaddress;
				if (!empty($Order->Shipping->xaddress))
					$options['value'] = $Order->Shipping->xaddress;
				return '<input type="text" name="shipping[xaddress]" id="shipping-xaddress" '.inputattrs($options).' />';
				break;
			case "shipping-city":
				if ($options['mode'] == "value") return $Order->Shipping->city;
				if (!empty($Order->Shipping->city))
					$options['value'] = $Order->Shipping->city;
				return '<input type="text" name="shipping[city]" id="shipping-city" '.inputattrs($options).' />';
				break;
			case "shipping-province":
			case "shipping-state":
				if ($options['mode'] == "value") return $Order->Shipping->state;
				if (!isset($options['selected'])) $options['selected'] = false;
				if (!empty($Order->Shipping->state)) {
					$options['selected'] = $Order->Shipping->state;
					$options['value'] = $Order->Shipping->state;
				}
				$countries = Lookup::countries();
				$output = false;
				$country = $base['country'];
				if (!empty($Order->Shipping->country))
					$country = $Order->Shipping->country;
				if (!array_key_exists($country,$countries)) $country = key($countries);

				if (empty($options['type'])) $options['type'] = "menu";
				$regions = Lookup::country_zones();
				$states = $regions[$country];
				if (is_array($states) && $options['type'] == "menu") {
					$label = (!empty($options['label']))?$options['label']:'';
					$output = '<select name="shipping[state]" id="shipping-state" '.inputattrs($options,$select_attrs).'>';
					$output .= '<option value="" selected="selected">'.$label.'</option>';
				 	$output .= menuoptions($states,$options['selected'],true);
					$output .= '</select>';
				} else if ($options['type'] == "menu") {
					$options['disabled'] = 'disabled';
					$options['class'] = ($options['class']?" ":null).'unavailable';
					$label = (!empty($options['label']))?$options['label']:'';
					$output = '<select name="shipping[state]" id="shipping-state" '.inputattrs($options,$select_attrs).'></select>';
				} else $output .= '<input type="text" name="shipping[state]" id="shipping-state" '.inputattrs($options).'/>';
				return $output;
				break;
			case "shipping-postcode":
				if ($options['mode'] == "value") return $Order->Shipping->postcode;
				if (!empty($Order->Shipping->postcode))
					$options['value'] = $Order->Shipping->postcode;
				return '<input type="text" name="shipping[postcode]" id="shipping-postcode" '.inputattrs($options).' />'; break;
			case "shipping-country":
				if ($options['mode'] == "value") return $Order->Shipping->country;
				$base = $Ecart->Settings->get('base_operations');
				if (!empty($Order->Shipping->country))
					$options['selected'] = $Order->Shipping->country;
				else if (empty($options['selected'])) $options['selected'] = $base['country'];

				$countries = $Ecart->Settings->get('target_markets');

				$output = '<select name="shipping[country]" id="shipping-country" '.inputattrs($options,$select_attrs).'>';
			 	$output .= menuoptions($countries,$options['selected'],true);
				$output .= '</select>';
				return $output;
				break;
			case "same-shipping-address":
				$label = __("Same shipping address","Ecart");
				if (isset($options['label'])) $label = $options['label'];
				$checked = ' checked="checked"';
				if (isset($options['checked']) && !value_is_true($options['checked'])) $checked = '';
				$output = '<label for="same-shipping"><input type="checkbox" name="sameshipaddress" value="on" id="same-shipping" '.$checked.' /> '.$label.'</label>';
				return $output;
				break;
			case "residential-shipping-address":
				$label = __("Residential shipping address","Ecart");
				if (isset($options['label'])) $label = $options['label'];
				if (isset($options['checked']) && value_is_true($options['checked'])) $checked = ' checked="checked"';
				$output = '<label for="residential-shipping"><input type="hidden" name="shipping[residential]" value="no" /><input type="checkbox" name="shipping[residential]" value="yes" id="residential-shipping" '.$checked.' /> '.$label.'</label>';
				return $output;
				break;

			// BILLING TAGS
			case "billing-address":
				if ($options['mode'] == "value") return $Order->Billing->address;
				if (!empty($Order->Billing->address))
					$options['value'] = $Order->Billing->address;
				return '<input type="text" name="billing[address]" id="billing-address" '.inputattrs($options).' />';
				break;
			case "billing-xaddress":
				if ($options['mode'] == "value") return $Order->Billing->xaddress;
				if (!empty($Order->Billing->xaddress))
					$options['value'] = $Order->Billing->xaddress;
				return '<input type="text" name="billing[xaddress]" id="billing-xaddress" '.inputattrs($options).' />';
				break;
			case "billing-city":
				if ($options['mode'] == "value") return $Order->Billing->city;
				if (!empty($Order->Billing->city))
					$options['value'] = $Order->Billing->city;
				return '<input type="text" name="billing[city]" id="billing-city" '.inputattrs($options).' />';
				break;
			case "billing-province":
			case "billing-state":
				if ($options['mode'] == "value") return $Order->Billing->state;
				if (!isset($options['selected'])) $options['selected'] = false;
				if (!empty($Order->Billing->state)) {
					$options['selected'] = $Order->Billing->state;
					$options['value'] = $Order->Billing->state;
				}
				if (empty($options['type'])) $options['type'] = "menu";
				$countries = Lookup::countries();

				$output = false;
				$country = $base['country'];
				if (!empty($Order->Billing->country))
					$country = $Order->Billing->country;
				if (!array_key_exists($country,$countries)) $country = key($countries);

				$regions = Lookup::country_zones();
				$states = $regions[$country];
				if (is_array($states) && $options['type'] == "menu") {
					$label = (!empty($options['label']))?$options['label']:'';
					$output = '<select name="billing[state]" id="billing-state" '.inputattrs($options,$select_attrs).'>';
					$output .= '<option value="" selected="selected">'.$label.'</option>';
				 	$output .= menuoptions($states,$options['selected'],true);
					$output .= '</select>';
				} else if ($options['type'] == "menu") {
					$options['disabled'] = 'disabled';
					$options['class'] = ($options['class']?" ":null).'unavailable';
					$label = (!empty($options['label']))?$options['label']:'';
					$output = '<select name="billing[state]" id="billing-state" '.inputattrs($options,$select_attrs).'></select>';
				} else $output .= '<input type="text" name="billing[state]" id="billing-state" '.inputattrs($options).'/>';
				return $output;
				break;
			case "billing-postcode":
				if ($options['mode'] == "value") return $Order->Billing->postcode;
				if (!empty($Order->Billing->postcode))
					$options['value'] = $Order->Billing->postcode;
				return '<input type="text" name="billing[postcode]" id="billing-postcode" '.inputattrs($options).' />';
				break;
			case "billing-country":
				if ($options['mode'] == "value") return $Order->Billing->country;
				$base = $Ecart->Settings->get('base_operations');

				if (!empty($Order->Billing->country))
					$options['selected'] = $Order->Billing->country;
				else if (empty($options['selected'])) $options['selected'] = $base['country'];

				$countries = $Ecart->Settings->get('target_markets');

				$output = '<select name="billing[country]" id="billing-country" '.inputattrs($options,$select_attrs).'>';
			 	$output .= menuoptions($countries,$options['selected'],true);
				$output .= '</select>';
				return $output;
				break;

			case "save-button":
				if (!isset($options['label'])) $options['label'] = __('Save','Ecart');
				$result = '<input type="hidden" name="customer" value="true" />';
				$result .= '<input type="submit" name="save" id="save-button"'.inputattrs($options).' />';
				return $result;
				break;
			case "marketing":
				if ($options['mode'] == "value") return $this->marketing;
				if (!empty($this->marketing) && value_is_true($this->marketing)) $options['checked'] = true;
				$attrs = array("accesskey","alt","checked","class","disabled","format",
					"minlength","maxlength","readonly","size","src","tabindex",
					"title");
				$input = '<input type="hidden" name="marketing" value="no" />';
				$input .= '<input type="checkbox" name="marketing" id="marketing" value="yes" '.inputattrs($options,$attrs).' />';
				return $input;
				break;


			// Downloads UI tags
			case "hasdownloads":
			case "has-downloads": return (!empty($this->downloads)); break;
			case "downloads":
				if (empty($this->downloads)) return false;
				if (!isset($this->_dowload_looping)) {
					reset($this->downloads);
					$this->_dowload_looping = true;
				} else next($this->downloads);

				if (current($this->downloads) !== false) return true;
				else {
					unset($this->_dowload_looping);
					reset($this->downloads);
					return false;
				}
				break;
			case "download":
				$download = current($this->downloads);
				$df = get_option('date_format');
				$properties = unserialize($download->properties);
				$string = '';
				if (array_key_exists('id',$options)) $string .= $download->download;
				if (array_key_exists('purchase',$options)) $string .= $download->purchase;
				if (array_key_exists('name',$options)) $string .= $download->name;
				if (array_key_exists('variation',$options)) $string .= $download->optionlabel;
				if (array_key_exists('downloads',$options)) $string .= $download->downloads;
				if (array_key_exists('key',$options)) $string .= $download->dkey;
				if (array_key_exists('created',$options)) $string .= $download->created;
				if (array_key_exists('total',$options)) $string .= money($download->total);
				if (array_key_exists('filetype',$options)) $string .= $properties['mimetype'];
				if (array_key_exists('size',$options)) $string .= readableFileSize($download->size);
				if (array_key_exists('date',$options)) $string .= _d($df,mktimestamp($download->created));
				if (array_key_exists('url',$options))
					$string .= ECART_PRETTYURLS?
						ecarturl("download/$download->dkey"):
						ecarturl(array('ecart_download'=>$download->dkey),'account');

				return $string;
				break;

			// Downloads UI tags
			case "haspurchases":
			case "has-purchases":
				$filters = array();
				if (isset($options['daysago']))
					$filters['where'] = "UNIX_TIMESTAMP(o.created) > UNIX_TIMESTAMP()-".($options['daysago']*86400);
				if (empty($Ecart->purchases)) $this->load_orders($filters);
				return (!empty($Ecart->purchases));
				break;
			case "purchases":
				if (!isset($this->_purchaseloop)) {
					reset($Ecart->purchases);
					$Ecart->Purchase = current($Ecart->purchases);
					$this->_purchaseloop = true;
				} else {
					$Ecart->Purchase = next($Ecart->purchases);
				}

				if (current($Ecart->purchases) !== false) return true;
				else {
					unset($this->_purchaseloop);
					return false;
				}
				break;
			case "receipt": // DEPRECATED
			case "order":
				return ecarturl(array('acct'=>'order','id'=>$Ecart->Purchase->id),'account');
				break;

		}
	}
Example #12
0
/**
 * Defines the ecart() 'tag' handler for complete template customization
 *
 * Appropriately routes tag calls to the tag handler for the requested object.
 *
 * @param $object The object to get the tag property from
 * @param $property The property of the object to get/output
 * @param $options Custom options for the property result in query form
 *                   (option1=value&option2=value&...) or alternatively as an associative array
 */
function ecart () {
	global $Ecart;
	$args = func_get_args();

	$object = strtolower($args[0]);
	$property = strtolower($args[1]);
	$options = array();

	if (isset($args[2])) {
		if (is_array($args[2]) && !empty($args[2])) {
			// handle associative array for options
			foreach(array_keys($args[2]) as $key)
				$options[strtolower($key)] = $args[2][$key];
		} else {
			// regular url-compatible arguments
			$paramsets = explode("&",$args[2]);
			foreach ((array)$paramsets as $paramset) {
				if (empty($paramset)) continue;
				$key = $paramset;
				$value = "";
				if (strpos($paramset,"=") !== false)
					list($key,$value) = explode("=",$paramset);
				$options[strtolower($key)] = $value;
			}
		}
	}

	$Object = false; $result = false;
	switch (strtolower($object)) {
		case "cart": if (isset($Ecart->Order->Cart)) $Object =& $Ecart->Order->Cart; break;
		case "cartitem": if (isset($Ecart->Order->Cart)) $Object =& $Ecart->Order->Cart; break;
		case "shipping": if (isset($Ecart->Order->Cart)) $Object =& $Ecart->Order->Cart; break;
		case "category": if (isset($Ecart->Category)) $Object =& $Ecart->Category; break;
		case "subcategory": if (isset($Ecart->Category->child)) $Object =& $Ecart->Category->child; break;
		case "catalog": if (isset($Ecart->Catalog)) $Object =& $Ecart->Catalog; break;
		case "product": if (isset($Ecart->Product)) $Object =& $Ecart->Product; break;
		case "checkout": if (isset($Ecart->Order)) $Object =& $Ecart->Order; break;
		case "purchase": if (isset($Ecart->Purchase)) $Object =& $Ecart->Purchase; break;
		case "customer": if (isset($Ecart->Order->Customer)) $Object =& $Ecart->Order->Customer; break;
		case "error": if (isset($Ecart->Errors)) $Object =& $Ecart->Errors; break;
		default: $Object = apply_filters('ecart_tag_domain',$Object,$object);
	}

	if (!$Object) new EcartError("The ecart('$object') tag cannot be used in this context because the object responsible for handling it doesn't exist.",'ecart_tag_error',ECART_ADMIN_ERR);
	else {
		switch (strtolower($object)) {
			case "cartitem": $result = $Object->itemtag($property,$options); break;
			case "shipping": $result = $Object->shippingtag($property,$options); break;
			default: $result = $Object->tag($property,$options); break;
		}
	}

	// Provide a filter hook for every template tag, includes passed options and the relevant Object as parameters
	$result = apply_filters('ecart_tag_'.strtolower($object).'_'.strtolower($property),$result,$options,$Object);

	// Force boolean result
	if (isset($options['is'])) {
		if (value_is_true($options['is'])) {
			if ($result) return true;
		} else {
			if ($result == false) return true;
		}
		return false;
	}

	// Always return a boolean if the result is boolean
	if (is_bool($result)) return $result;

	// Return the result instead of outputting it
	if ((isset($options['return']) && value_is_true($options['return'])) ||
			isset($options['echo']) && !value_is_true($options['echo']))
		return $result;

	// Output the result
	if (is_scalar($result)) echo $result;
	else return $result;
	return true;
}
    function tag($property, $options = array())
    {
        global $Shopp;
        switch ($property) {
            case "link":
            case "url":
                if (SHOPP_PERMALINKS) {
                    $url = esc_url(add_query_arg($_GET, $Shopp->shopuri . urldecode($this->slug) . "/"));
                } else {
                    $url = add_query_arg('shopp_pid', $this->id, $Shopp->shopuri);
                }
                return $url;
                break;
            case "found":
                if (empty($this->id)) {
                    return false;
                }
                $load = array('prices', 'images', 'specs');
                if (isset($options['load'])) {
                    $load = explode(",", $options['load']);
                }
                $this->load_data($load);
                return true;
                break;
            case "id":
                return $this->id;
                break;
            case "name":
                return $this->name;
                break;
            case "slug":
                return $this->slug;
                break;
            case "summary":
                return $this->summary;
                break;
            case "description":
                return apply_filters('shopp_product_description', $this->description);
            case "isfeatured":
            case "is-featured":
                return $this->featured == "on";
                break;
            case "price":
                if (empty($this->prices)) {
                    $this->load_data(array('prices'));
                }
                if (!isset($options['taxes'])) {
                    $options['taxes'] = null;
                }
                // $taxrate = 0;
                // $taxes = false;
                // $base = $Shopp->Settings->get('base_operations');
                // if ($base['vat']) $taxes = true;
                // if (isset($options['taxes'])) $taxes = (value_is_true($options['taxes']));
                // if ($taxes) $taxrate = $Shopp->Cart->taxrate();
                if (count($this->options) > 0) {
                    $taxrate = shopp_taxrate($options['taxes']);
                    if ($this->pricerange['min']['price'] == $this->pricerange['max']['price']) {
                        return money($this->pricerange['min']['price'] + $this->pricerange['min']['price'] * $taxrate);
                    } else {
                        if (!empty($options['starting'])) {
                            return $options['starting'] . " " . money($this->pricerange['min']['price'] + $this->pricerange['min']['price'] * $taxrate);
                        }
                        return money($this->pricerange['min']['price'] + $this->pricerange['min']['price'] * $taxrate) . " &mdash; " . money($this->pricerange['max']['price'] + $this->pricerange['max']['price'] * $taxrate);
                    }
                } else {
                    $taxrate = shopp_taxrate($options['taxes'], $this->prices[0]->tax);
                    return money($this->prices[0]->price + $this->prices[0]->price * $taxrate);
                }
                break;
            case "weight":
                if (empty($this->prices)) {
                    $this->load_data(array('prices'));
                }
                $unit = isset($options['units']) && !value_is_true($options['units']) ? false : $Shopp->Settings->get('weight_unit');
                if (!$this->weightrange['min']) {
                    return false;
                }
                $string = $this->weightrange['min'] == $this->weightrange['max'] ? round($this->weightrange['min'], 3) : round($this->weightrange['min'], 3) . " - " . round($this->weightrange['max'], 3);
                $string .= $unit ? " {$unit}" : "";
                return $string;
                break;
            case "onsale":
                if (empty($this->prices)) {
                    $this->load_data(array('prices'));
                }
                if (empty($this->prices)) {
                    return false;
                }
                return $this->onsale;
                // if (empty($this->prices)) $this->load_prices();
                $sale = false;
                if (count($this->prices) > 1) {
                    foreach ($this->prices as $pricetag) {
                        if (isset($pricetag->onsale) && $pricetag->onsale == "on") {
                            $sale = true;
                        }
                    }
                    return $sale;
                } else {
                    return $this->prices[0]->onsale == "on" ? true : false;
                }
                break;
            case "saleprice":
                if (empty($this->prices)) {
                    $this->load_data(array('prices'));
                }
                if (!isset($options['taxes'])) {
                    $options['taxes'] = null;
                }
                $pricetag = 'price';
                if ($this->onsale) {
                    $pricetag = 'saleprice';
                }
                if (count($this->options) > 0) {
                    $taxrate = shopp_taxrate($options['taxes']);
                    if ($this->pricerange['min'][$pricetag] == $this->pricerange['max'][$pricetag]) {
                        return money($this->pricerange['min'][$pricetag] + $this->pricerange['min'][$pricetag] * $taxrate);
                    } else {
                        if (!empty($options['starting'])) {
                            return $options['starting'] . " " . money($this->pricerange['min'][$pricetag] + $this->pricerange['min'][$pricetag] * $taxrate);
                        }
                        return money($this->pricerange['min'][$pricetag] + $this->pricerange['min'][$pricetag] * $taxrate) . " &mdash; " . money($this->pricerange['max'][$pricetag] + $this->pricerange['max'][$pricetag] * $taxrate);
                    }
                } else {
                    $taxrate = shopp_taxrate($options['taxes'], $this->prices[0]->tax);
                    return money($this->prices[0]->promoprice + $this->prices[0]->promoprice * $taxrate);
                }
                break;
            case "has-savings":
                return $this->onsale && $this->pricerange['min']['saved'] > 0 ? true : false;
                break;
            case "savings":
                if (empty($this->prices)) {
                    $this->load_data(array('prices'));
                }
                if (!isset($options['taxes'])) {
                    $options['taxes'] = null;
                }
                $taxrate = shopp_taxrate($options['taxes']);
                if (!isset($options['show'])) {
                    $options['show'] = '';
                }
                if ($options['show'] == "%" || $options['show'] == "percent") {
                    if ($this->options > 1) {
                        if (round($this->pricerange['min']['savings']) == round($this->pricerange['max']['savings'])) {
                            return percentage($this->pricerange['min']['savings']);
                        } else {
                            return percentage($this->pricerange['min']['savings']) . " &mdash; " . percentage($this->pricerange['max']['savings']);
                        }
                    } else {
                        return percentage($this->pricerange['max']['savings']);
                    }
                } else {
                    if ($this->options > 1) {
                        if ($this->pricerange['min']['saved'] == $this->pricerange['max']['saved']) {
                            return money($this->pricerange['min']['saved'] + $this->pricerange['min']['saved'] * $taxrate);
                        } else {
                            return money($this->pricerange['min']['saved'] + $this->pricerange['min']['saved'] * $taxrate) . " &mdash; " . money($this->pricerange['max']['saved'] + $this->pricerange['max']['saved'] * $taxrate);
                        }
                    } else {
                        return money($this->pricerange['max']['saved'] + $this->pricerange['max']['saved'] * $taxrate);
                    }
                }
                break;
            case "freeshipping":
                if (empty($this->prices)) {
                    $this->load_data(array('prices'));
                }
                // if (empty($this->prices)) $this->load_prices();
                return $this->freeshipping;
            case "thumbnail":
                if (empty($this->imagesets)) {
                    $this->load_data(array('images'));
                }
                if (empty($options['class'])) {
                    $options['class'] = '';
                } else {
                    $options['class'] = ' class="' . $options['class'] . '"';
                }
                if (isset($this->thumbnail)) {
                    $img = $this->thumbnail;
                    $title = !empty($img->properties['title']) ? ' title="' . attribute_escape($img->properties['title']) . '"' : '';
                    $width = isset($options['width']) ? $options['width'] : $img->properties['width'];
                    $height = isset($options['height']) ? $options['height'] : $img->properties['height'];
                    if (isset($options['width']) && !isset($options['height'])) {
                        $scale = $width / $img->properties['width'];
                        $height = round($img->properties['height'] * $scale);
                    }
                    if (isset($options['height']) && !isset($options['width'])) {
                        $scale = $height / $img->properties['height'];
                        $width = round($img->properties['width'] * $scale);
                    }
                    if (!empty($options['title'])) {
                        $title = ' title="' . attribute_escape($options['title']) . '"';
                    }
                    $alt = attribute_escape(!empty($img->properties['alt']) ? $img->properties['alt'] : $this->name);
                    return '<img src="' . $img->uri . '"' . $title . ' alt="' . $alt . '"  width="' . $width . '" height="' . $height . '" ' . $options['class'] . ' />';
                    break;
                }
                break;
            case "hasimages":
            case "has-images":
                if (empty($options['type'])) {
                    $options['type'] = "thumbnail";
                }
                if (empty($this->images)) {
                    $this->load_data(array('images'));
                }
                if (!empty($this->imagesets[$options['type']])) {
                    $this->imageset =& $this->imagesets[$options['type']];
                    return true;
                } else {
                    return false;
                }
                break;
            case "images":
                if (!$this->imageset) {
                    return false;
                }
                if (!$this->imageloop) {
                    reset($this->imageset);
                    $this->imageloop = true;
                } else {
                    next($this->imageset);
                }
                if (current($this->imageset)) {
                    return true;
                } else {
                    $this->imageloop = false;
                    $this->imageset = false;
                    return false;
                }
                break;
            case "image":
                $img = current($this->imageset);
                if (isset($options['property'])) {
                    switch (strtolower($options['property'])) {
                        case "url":
                            return $img->uri;
                        case "width":
                            return $img->properties['width'];
                        case "height":
                            return $img->properties['height'];
                        case "title":
                            return attribute_escape($img->properties['title']);
                        case "alt":
                            return attribute_escape($img->properties['alt']);
                        default:
                            return $img->id;
                    }
                }
                if (!isset($options['class'])) {
                    $options['class'] = false;
                }
                if (!empty($options['class'])) {
                    $options['class'] = ' class="' . $options['class'] . '"';
                }
                $title = !empty($img->properties['title']) ? ' title="' . attribute_escape($img->properties['title']) . '"' : '';
                $width = isset($options['width']) ? $options['width'] : $img->properties['width'];
                $height = isset($options['height']) ? $options['height'] : $img->properties['height'];
                if (isset($options['width']) && !isset($options['height'])) {
                    $scale = $width / $img->properties['width'];
                    $height = round($img->properties['height'] * $scale);
                }
                if (isset($options['height']) && !isset($options['width'])) {
                    $scale = $height / $img->properties['height'];
                    $width = round($img->properties['width'] * $scale);
                }
                if (!empty($options['title'])) {
                    $title = ' title="' . attribute_escape($options['title']) . '"';
                }
                $alt = attribute_escape(!empty($img->properties['alt']) ? $img->properties['alt'] : $this->name);
                $string = "";
                if (!isset($options['zoomfx'])) {
                    $options['zoomfx'] = "shopp-thickbox";
                }
                if (!empty($options['zoom'])) {
                    $string .= '<a href="' . $Shopp->imguri . $img->src . '/' . str_replace('small_', '', $img->name) . '" class="' . $options['zoomfx'] . '" rel="product-gallery">';
                }
                $string .= '<img src="' . $img->uri . '"' . $title . ' alt="' . $alt . '" width="' . $width . '" height="' . $height . '" ' . $options['class'] . ' />';
                if (!empty($options['zoom'])) {
                    $string .= "</a>";
                }
                return $string;
                break;
            case "gallery":
                if (empty($this->images)) {
                    $this->load_data(array('images'));
                }
                if (!isset($options['zoomfx'])) {
                    $options['zoomfx'] = "shopp-thickbox";
                }
                if (!isset($options['preview'])) {
                    $options['preview'] = "click";
                }
                $previews = '<ul class="previews">';
                $firstPreview = true;
                if (!empty($this->imagesets['small'])) {
                    foreach ($this->imagesets['small'] as $img) {
                        if ($firstPreview) {
                            $previews .= '<li id="preview-fill"' . ($firstPreview ? ' class="fill"' : '') . '>';
                            $previews .= '<img src="' . $Shopp->uri . '/core/ui/icons/clear.png' . '" alt="' . $img->datatype . '" width="' . $img->properties['width'] . '" height="' . $img->properties['height'] . '" />';
                            $previews .= '</li>';
                        }
                        $title = !empty($img->properties['title']) ? ' title="' . attribute_escape($img->properties['title']) . '"' : '';
                        $alt = attribute_escape(!empty($img->properties['alt']) ? $img->properties['alt'] : $img->name);
                        $rel = isset($options['rel']) && $options['rel'] ? ' rel="product_' . $this->id . '_gallery"' : '';
                        $previews .= '<li id="preview-' . $img->src . '"' . ($firstPreview ? ' class="active"' : '') . '>';
                        $previews .= '<a href="' . $Shopp->imguri . $img->src . '/' . str_replace('small_', '', $img->name) . '" class="product_' . $this->id . '_gallery ' . $options['zoomfx'] . '"' . $rel . '>';
                        $previews .= '<img src="' . $Shopp->imguri . $img->id . '"' . $title . ' alt="' . $alt . '" width="' . $img->properties['width'] . '" height="' . $img->properties['height'] . '" />';
                        $previews .= '</a>';
                        $previews .= '</li>';
                        $firstPreview = false;
                    }
                }
                $previews .= '</ul>';
                $thumbs = "";
                if (isset($this->imagesets['thumbnail']) && count($this->imagesets['thumbnail']) > 1) {
                    $thumbsize = 32;
                    if (isset($options['thumbsize'])) {
                        $thumbsize = $options['thumbsize'];
                    }
                    $thumbwidth = $thumbsize;
                    $thumbheight = $thumbsize;
                    if (isset($options['thumbwidth'])) {
                        $thumbwidth = $options['thumbwidth'];
                    }
                    if (isset($options['thumbheight'])) {
                        $thumbheight = $options['thumbheight'];
                    }
                    $firstThumb = true;
                    $thumbs = '<ul class="thumbnails">';
                    foreach ($this->imagesets['thumbnail'] as $img) {
                        if (isset($options['thumbwidth']) && !isset($options['thumbheight'])) {
                            $scale = $thumbwidth / $img->properties['width'];
                            $thumbheight = round($img->properties['height'] * $scale);
                        }
                        if (isset($options['thumbheight']) && !isset($options['thumbwidth'])) {
                            $scale = $thumbheight / $img->properties['height'];
                            $thumbwidth = round($img->properties['width'] * $scale);
                        }
                        $title = !empty($img->properties['title']) ? ' title="' . attribute_escape($img->properties['title']) . '"' : '';
                        $alt = attribute_escape(!empty($img->properties['alt']) ? $img->properties['alt'] : $img->name);
                        $thumbs .= '<li id="thumbnail-' . $img->src . '" class="preview-' . $img->src . ($firstThumb ? ' first' : ' test') . '">';
                        $thumbs .= '<img src="' . $Shopp->imguri . $img->id . '"' . $title . ' alt="' . $alt . '" width="' . $thumbwidth . '" height="' . $thumbheight . '" />';
                        $thumbs .= '</li>';
                        $firstThumb = false;
                    }
                    $thumbs .= '</ul>';
                }
                $result = '<div id="gallery-' . $this->id . '" class="gallery">' . $previews . $thumbs . '</div>';
                $result .= '<script type="text/javascript"><!--
					jQuery(document).ready( function() {  shopp_gallery("#gallery-' . $this->id . '","' . $options['preview'] . '"); }); 
					// --></script>';
                return $result;
                break;
            case "has-categories":
                if (empty($this->categories)) {
                    $this->load_data(array('categories'));
                }
                if (count($this->categories) > 0) {
                    return true;
                } else {
                    return false;
                }
                break;
            case "categories":
                if (!$this->categoryloop) {
                    reset($this->categories);
                    $this->categoryloop = true;
                } else {
                    next($this->categories);
                }
                if (current($this->categories)) {
                    return true;
                } else {
                    $this->categoryloop = false;
                    return false;
                }
                break;
            case "in-category":
                if (empty($this->categories)) {
                    $this->load_data(array('categories'));
                }
                if (isset($options['id'])) {
                    $field = "id";
                }
                if (isset($options['name'])) {
                    $field = "name";
                }
                if (isset($options['slug'])) {
                    $field = "slug";
                }
                foreach ($this->categories as $category) {
                    if ($category->{$field} == $options[$field]) {
                        return true;
                    }
                }
                return false;
            case "category":
                $category = current($this->categories);
                if (isset($options['show'])) {
                    if ($options['show'] == "id") {
                        return $category->id;
                    }
                    if ($options['show'] == "slug") {
                        return $category->slug;
                    }
                }
                return $category->name;
                break;
            case "has-tags":
                if (empty($this->tags)) {
                    $this->load_data(array('tags'));
                }
                if (count($this->tags) > 0) {
                    return true;
                } else {
                    return false;
                }
                break;
            case "tags":
                if (!$this->tagloop) {
                    reset($this->tags);
                    $this->tagloop = true;
                } else {
                    next($this->tags);
                }
                if (current($this->tags)) {
                    return true;
                } else {
                    $this->tagloop = false;
                    return false;
                }
                break;
            case "tagged":
                if (empty($this->tags)) {
                    $this->load_data(array('tags'));
                }
                if (isset($options['id'])) {
                    $field = "id";
                }
                if (isset($options['name'])) {
                    $field = "name";
                }
                foreach ($this->tags as $tag) {
                    if ($tag->{$field} == $options[$field]) {
                        return true;
                    }
                }
                return false;
            case "tag":
                $tag = current($this->tags);
                if (isset($options['show'])) {
                    if ($options['show'] == "id") {
                        return $tag->id;
                    }
                }
                return $tag->name;
                break;
            case "has-specs":
                if (empty($this->specs)) {
                    $this->load_data(array('specs'));
                }
                if (count($this->specs) > 0) {
                    $this->merge_specs();
                    return true;
                } else {
                    return false;
                }
                break;
            case "specs":
                if (!$this->specloop) {
                    reset($this->specs);
                    $this->specloop = true;
                } else {
                    next($this->specs);
                }
                if (current($this->specs)) {
                    return true;
                } else {
                    $this->specloop = false;
                    return false;
                }
                break;
            case "spec":
                $string = "";
                $separator = ": ";
                $delimiter = ", ";
                if (isset($options['separator'])) {
                    $separator = $options['separator'];
                }
                if (isset($options['delimiter'])) {
                    $separator = $options['delimiter'];
                }
                $spec = current($this->specs);
                if (is_array($spec->content)) {
                    $spec->content = join($delimiter, $spec->content);
                }
                if (isset($options['name']) && !empty($options['name']) && isset($this->specskey[$options['name']])) {
                    $spec = $this->specskey[$options['name']];
                    if (is_array($spec)) {
                        if (isset($options['index'])) {
                            foreach ($spec as $index => $entry) {
                                if ($index + 1 == $options['index']) {
                                    $content = $entry->content;
                                }
                            }
                        } else {
                            foreach ($spec as $entry) {
                                $contents[] = $entry->content;
                            }
                            $content = join($delimiter, $contents);
                        }
                    } else {
                        $content = $spec->content;
                    }
                    $string = apply_filters('shopp_product_spec', $content);
                    return $string;
                }
                if (isset($options['name']) && isset($options['content'])) {
                    $string = "{$spec->name}{$separator}" . apply_filters('shopp_product_spec', $spec->content);
                } elseif (isset($options['name'])) {
                    $string = $spec->name;
                } elseif (isset($options['content'])) {
                    $string = apply_filters('shopp_product_spec', $spec->content);
                } else {
                    $string = "{$spec->name}{$separator}" . apply_filters('shopp_product_spec', $spec->content);
                }
                return $string;
                break;
            case "has-variations":
                return $this->variations == "on" && !empty($this->options);
                break;
            case "variations":
                $string = "";
                if (!isset($options['mode'])) {
                    if (!$this->priceloop) {
                        reset($this->prices);
                        $this->priceloop = true;
                    } else {
                        next($this->prices);
                    }
                    $thisprice = current($this->prices);
                    if ($thisprice && $thisprice->type == "N/A") {
                        next($this->prices);
                    }
                    if (current($this->prices)) {
                        return true;
                    } else {
                        $this->priceloop = false;
                        return false;
                    }
                    return true;
                }
                if ($this->outofstock) {
                    return false;
                }
                // Completely out of stock, hide menus
                if (!isset($options['taxes'])) {
                    $options['taxes'] = null;
                }
                $defaults = array('defaults' => '', 'disabled' => 'show', 'before_menu' => '', 'after_menu' => '');
                $options = array_merge($defaults, $options);
                if (!isset($options['label'])) {
                    $options['label'] = "on";
                }
                if (!isset($options['required'])) {
                    $options['required'] = __('You must select the options for this item before you can add it to your shopping cart.', 'Shopp');
                }
                if ($options['mode'] == "single") {
                    if (!empty($options['before_menu'])) {
                        $string .= $options['before_menu'] . "\n";
                    }
                    if (value_is_true($options['label'])) {
                        $string .= '<label for="product-options' . $this->id . '">Options: </label> ' . "\n";
                    }
                    $string .= '<select name="products[' . $this->id . '][price]" id="product-options' . $this->id . '">';
                    if (!empty($options['defaults'])) {
                        $string .= '<option value="">' . $options['defaults'] . '</option>' . "\n";
                    }
                    foreach ($this->prices as $pricetag) {
                        if ($pricetag->context != "variation") {
                            continue;
                        }
                        $taxrate = shopp_taxrate($options['taxes'], $pricetag->tax);
                        $currently = $pricetag->sale == "on" ? $pricetag->promoprice : $pricetag->price;
                        $disabled = $pricetag->inventory == "on" && $pricetag->stock == 0 ? ' disabled="disabled"' : '';
                        $price = '  (' . money($currently) . ')';
                        if ($pricetag->type != "N/A") {
                            $string .= '<option value="' . $pricetag->id . '"' . $disabled . '>' . $pricetag->label . $price . '</option>' . "\n";
                        }
                    }
                    $string .= '</select>';
                    if (!empty($options['after_menu'])) {
                        $string .= $options['after_menu'] . "\n";
                    }
                } else {
                    $taxrate = shopp_taxrate($options['taxes'], true);
                    ob_start();
                    ?>
					<script type="text/javascript">
					<!--
					(function($) {
						$(document).ready(function () {
							productOptions[<?php 
                    echo $this->id;
                    ?>
] = new Array();
							productOptions[<?php 
                    echo $this->id;
                    ?>
]['pricing'] = <?php 
                    echo json_encode($this->pricekey);
                    ?>
;
							options_default = <?php 
                    echo !empty($options['defaults']) ? 'true' : 'false';
                    ?>
;
							options_required = "<?php 
                    echo $options['required'];
                    ?>
";
							
							productOptions[<?php 
                    echo $this->id;
                    ?>
]['menu'] = new ProductOptionsMenus('select<?php 
                    if (isset($Shopp->Category->slug)) {
                        echo ".category-" . $Shopp->Category->slug;
                    }
                    ?>
.product<?php 
                    echo $this->id;
                    ?>
',<?php 
                    echo $options['disabled'] == "hide" ? "true" : "false";
                    ?>
,productOptions[<?php 
                    echo $this->id;
                    ?>
]['pricing'],<?php 
                    echo empty($taxrate) ? '0' : $taxrate;
                    ?>
);
						});
					})(jQuery)
					//-->
					</script>
					<?php 
                    $script = ob_get_contents();
                    ob_end_clean();
                    $options['after_menu'] = $script . $options['after_menu'];
                    if (isset($this->options['variations'])) {
                        foreach ($this->options['variations'] as $id => $menu) {
                            if (!empty($options['before_menu'])) {
                                $string .= $options['before_menu'] . "\n";
                            }
                            if (value_is_true($options['label'])) {
                                $string .= '<label for="options-' . $id . '">' . $menu['menu'] . '</label> ' . "\n";
                            }
                            $string .= '<select name="products[' . $this->id . '][options][]" class="product' . $this->id . ' options">';
                            if (!empty($options['defaults'])) {
                                $string .= '<option value="">' . $options['defaults'] . '</option>' . "\n";
                            }
                            foreach ($menu['label'] as $key => $option) {
                                $string .= '<option value="' . $menu['id'][$key] . '">' . $option . '</option>' . "\n";
                            }
                            $string .= '</select>';
                            if (!empty($options['after_menu'])) {
                                $string .= $options['after_menu'] . "\n";
                            }
                        }
                    } else {
                        foreach ($this->options as $id => $menu) {
                            if (!empty($options['before_menu'])) {
                                $string .= $options['before_menu'] . "\n";
                            }
                            if (value_is_true($options['label'])) {
                                $string .= '<label for="options-' . $menu['id'] . '">' . $menu['name'] . '</label> ' . "\n";
                            }
                            $category_class = isset($Shopp->Category->slug) ? 'category-' . $Shopp->Category->slug : '';
                            $string .= '<select name="products[' . $this->id . '][options][]" class="' . $category_class . ' product' . $this->id . ' options" id="options-' . $menu['id'] . '">';
                            if (!empty($options['defaults'])) {
                                $string .= '<option value="">' . $options['defaults'] . '</option>' . "\n";
                            }
                            foreach ($menu['options'] as $key => $option) {
                                $string .= '<option value="' . $option['id'] . '">' . $option['name'] . '</option>' . "\n";
                            }
                            $string .= '</select>';
                            if (!empty($options['after_menu'])) {
                                $string .= $options['after_menu'] . "\n";
                            }
                        }
                    }
                }
                return $string;
                break;
            case "variation":
                $variation = current($this->prices);
                if (!isset($options['taxes'])) {
                    $options['taxes'] = null;
                }
                $taxrate = shopp_taxrate($options['taxes'], $variation->tax);
                $weightunit = isset($options['units']) && !value_is_true($options['units']) ? false : $Shopp->Settings->get('weight_unit');
                $string = '';
                if (array_key_exists('id', $options)) {
                    $string .= $variation->id;
                }
                if (array_key_exists('label', $options)) {
                    $string .= $variation->label;
                }
                if (array_key_exists('type', $options)) {
                    $string .= $variation->type;
                }
                if (array_key_exists('sku', $options)) {
                    $string .= $variation->sku;
                }
                if (array_key_exists('price', $options)) {
                    $string .= money($variation->price + $variation->price * $taxrate);
                }
                if (array_key_exists('saleprice', $options)) {
                    $string .= money($variation->saleprice + $variation->saleprice * $taxrate);
                }
                if (array_key_exists('stock', $options)) {
                    $string .= $variation->stock;
                }
                if (array_key_exists('weight', $options)) {
                    $string .= round($variation->weight, 3) . ($weightunit ? " {$weightunit}" : false);
                }
                if (array_key_exists('shipfee', $options)) {
                    $string .= money(floatvalue($variation->shipfee));
                }
                if (array_key_exists('sale', $options)) {
                    return $variation->sale == "on";
                }
                if (array_key_exists('shipping', $options)) {
                    return $variation->shipping == "on";
                }
                if (array_key_exists('tax', $options)) {
                    return $variation->tax == "on";
                }
                if (array_key_exists('inventory', $options)) {
                    return $variation->inventory == "on";
                }
                return $string;
                break;
            case "has-addons":
                if (isset($this->options['addons'])) {
                    return true;
                } else {
                    return false;
                }
                break;
                break;
            case "donation":
            case "amount":
            case "quantity":
                if ($this->outofstock) {
                    return false;
                }
                if (!isset($options['value'])) {
                    $options['value'] = 1;
                }
                if (!isset($options['input'])) {
                    $options['input'] = "text";
                }
                if (!isset($options['labelpos'])) {
                    $options['labelpos'] = "before";
                }
                if (!isset($options['label'])) {
                    $label = "";
                } else {
                    $label = '<label for="quantity' . $this->id . '">' . $options['label'] . '</label>';
                }
                $result = "";
                if ($options['labelpos'] == "before") {
                    $result .= "{$label} ";
                }
                if (!$this->priceloop) {
                    reset($this->prices);
                }
                $variation = current($this->prices);
                if (isset($options['input']) && $options['input'] == "menu") {
                    if (!isset($options['options'])) {
                        $values = "1-15,20,25,30,40,50,75,100";
                    } else {
                        $values = $options['options'];
                    }
                    if ($this->inventory && $this->pricerange['max']['stock'] == 0) {
                        return "";
                    }
                    if (strpos($values, ",") !== false) {
                        $values = explode(",", $values);
                    } else {
                        $values = array($values);
                    }
                    $qtys = array();
                    foreach ($values as $value) {
                        if (strpos($value, "-") !== false) {
                            $value = explode("-", $value);
                            if ($value[0] >= $value[1]) {
                                $qtys[] = $value[0];
                            } else {
                                for ($i = $value[0]; $i < $value[1] + 1; $i++) {
                                    $qtys[] = $i;
                                }
                            }
                        } else {
                            $qtys[] = $value;
                        }
                    }
                    $result .= '<select name="products[' . $this->id . '][quantity]" id="quantity-' . $this->id . '">';
                    foreach ($qtys as $qty) {
                        $amount = $qty;
                        $selected = isset($this->quantity) ? $this->quantity : 1;
                        if ($variation->type == "Donation" && $variation->donation['var'] == "on") {
                            if ($variation->donation['min'] == "on" && $amount < $variation->price) {
                                continue;
                            }
                            $amount = money($amount);
                            $selected = $variation->price;
                        } else {
                            if ($this->inventory && $amount > $this->pricerange['max']['stock']) {
                                continue;
                            }
                        }
                        $result .= '<option' . ($qty == $selected ? ' selected="selected"' : '') . ' value="' . $qty . '">' . $amount . '</option>';
                    }
                    $result .= '</select>';
                    if ($options['labelpos'] == "after") {
                        $result .= " {$label}";
                    }
                    return $result;
                }
                if (valid_input($options['input'])) {
                    if (!isset($options['size'])) {
                        $options['size'] = 3;
                    }
                    if ($variation->type == "Donation" && $variation->donation['var'] == "on") {
                        if ($variation->donation['min']) {
                            $options['value'] = $variation->price;
                        }
                        $options['class'] .= " currency";
                    }
                    $result = '<input type="' . $options['input'] . '" name="products[' . $this->id . '][quantity]" id="quantity-' . $this->id . '"' . inputattrs($options) . ' />';
                }
                if ($options['labelpos'] == "after") {
                    $result .= " {$label}";
                }
                return $result;
                break;
            case "input":
                if (!isset($options['type']) || $options['type'] != "menu" && $options['type'] != "textarea" && !valid_input($options['type'])) {
                    $options['type'] = "text";
                }
                if (!isset($options['name'])) {
                    return "";
                }
                if ($options['type'] == "menu") {
                    $result = '<select name="products[' . $this->id . '][data][' . $options['name'] . ']" id="data-' . $options['name'] . '-' . $this->id . '">';
                    if (isset($options['options'])) {
                        $menuoptions = preg_split('/,(?=(?:[^\\"]*\\"[^\\"]*\\")*(?![^\\"]*\\"))/', $options['options']);
                    }
                    if (is_array($menuoptions)) {
                        foreach ($menuoptions as $option) {
                            $selected = "";
                            $option = trim($option, '"');
                            if (isset($options['default']) && $options['default'] == $option) {
                                $selected = ' selected="selected"';
                            }
                            $result .= '<option value="' . $option . '"' . $selected . '>' . $option . '</option>';
                        }
                    }
                    $result .= '</select>';
                } elseif ($options['type'] == "textarea") {
                    if (isset($options['cols'])) {
                        $cols = ' cols="' . $options['cols'] . '"';
                    }
                    if (isset($options['rows'])) {
                        $rows = ' rows="' . $options['rows'] . '"';
                    }
                    $result .= '<textarea  name="products[' . $this->id . '][data][' . $options['name'] . ']" id="data-' . $options['name'] . '-' . $this->id . '"' . $cols . $rows . '>' . $options['value'] . '</textarea>';
                } else {
                    $result = '<input type="' . $options['type'] . '" name="products[' . $this->id . '][data][' . $options['name'] . ']" id="data-' . $options['name'] . '-' . $this->id . '"' . inputattrs($options) . ' />';
                }
                return $result;
                break;
            case "outofstock":
                if ($this->outofstock) {
                    $label = isset($options['label']) ? $options['label'] : $Shopp->Settings->get('outofstock_text');
                    $string = '<span class="outofstock">' . $label . '</span>';
                    return $string;
                } else {
                    return false;
                }
                break;
            case "buynow":
                if (!isset($options['value'])) {
                    $options['value'] = __("Buy Now", "Shopp");
                }
            case "addtocart":
                if (!isset($options['class'])) {
                    $options['class'] = "addtocart";
                } else {
                    $options['class'] .= " addtocart";
                }
                if (!isset($options['value'])) {
                    $options['value'] = __("Add to Cart", "Shopp");
                }
                $string = "";
                if ($this->outofstock) {
                    $string .= '<span class="outofstock">' . $Shopp->Settings->get('outofstock_text') . '</span>';
                    return $string;
                }
                $string .= '<input type="hidden" name="products[' . $this->id . '][product]" value="' . $this->id . '" />';
                if (!empty($this->prices[0]) && $this->prices[0]->type != "N/A") {
                    $string .= '<input type="hidden" name="products[' . $this->id . '][price]" value="' . $this->prices[0]->id . '" />';
                }
                if (!empty($Shopp->Category)) {
                    if (SHOPP_PERMALINKS) {
                        $string .= '<input type="hidden" name="products[' . $this->id . '][category]" value="' . $Shopp->Category->uri . '" />';
                    } else {
                        $string .= '<input type="hidden" name="products[' . $this->id . '][category]" value="' . (!empty($Shopp->Category->id) ? $Shopp->Category->id : $Shopp->Category->slug) . '" />';
                    }
                }
                $string .= '<input type="hidden" name="cart" value="add" />';
                if (isset($options['ajax'])) {
                    $options['class'] .= " ajax";
                    $string .= '<input type="hidden" name="ajax" value="true" />';
                    $string .= '<input type="button" name="addtocart" ' . inputattrs($options) . ' />';
                } else {
                    $string .= '<input type="submit" name="addtocart" ' . inputattrs($options) . ' />';
                }
                return $string;
        }
    }
 function tag($property, $options = array())
 {
     global $Shopp;
     $pages = $Shopp->Settings->get('pages');
     if (SHOPP_PERMALINKS) {
         $path = $Shopp->shopuri;
     } else {
         $page = add_query_arg('page_id', $pages['catalog']['id'], $Shopp->shopuri);
     }
     switch ($property) {
         case "url":
             return $Shopp->link('catalog');
             break;
         case "display":
         case "type":
             return $this->type;
             break;
         case "is-landing":
         case "is-catalog":
             return is_shopp_page('catalog') && $this->type == "catalog";
             break;
         case "is-category":
             return is_shopp_page('catalog') && $this->type == "category";
             break;
         case "is-product":
             return is_shopp_page('catalog') && $this->type == "product";
             break;
         case "is-cart":
             return is_shopp_page('cart');
             break;
         case "is-checkout":
             return is_shopp_page('checkout');
             break;
         case "is-account":
             return is_shopp_page('account');
             break;
         case "tagcloud":
             if (!empty($options['levels'])) {
                 $levels = $options['levels'];
             } else {
                 $levels = 7;
             }
             if (empty($this->tags)) {
                 $this->load_tags();
             }
             $min = -1;
             $max = -1;
             foreach ($this->tags as $tag) {
                 if ($min == -1 || $tag->products < $min) {
                     $min = $tag->products;
                 }
                 if ($max == -1 || $tag->products > $max) {
                     $max = $tag->products;
                 }
             }
             if ($max == 0) {
                 $max = 1;
             }
             $string = '<ul class="shopp tagcloud">';
             foreach ($this->tags as $tag) {
                 $level = floor((1 - $tag->products / $max) * $levels) + 1;
                 if (SHOPP_PERMALINKS) {
                     $link = $path . 'tag/' . urlencode($tag->name) . '/';
                 } else {
                     $link = add_query_arg('shopp_tag', urlencode($tag->name), $page);
                 }
                 $string .= '<li class="level-' . $level . '"><a href="' . $link . '" rel="tag">' . $tag->name . '</a></li> ';
             }
             $string .= '</ul>';
             return $string;
             break;
         case "has-categories":
             if (empty($this->categories)) {
                 $this->load_categories(array('where' => 'true'), $options['showsmart']);
             }
             if (count($this->categories) > 0) {
                 return true;
             } else {
                 return false;
             }
             break;
         case "categories":
             if (!$this->categoryloop) {
                 reset($this->categories);
                 $Shopp->Category = current($this->categories);
                 $this->categoryloop = true;
             } else {
                 $Shopp->Category = next($this->categories);
             }
             if (current($this->categories)) {
                 $Shopp->Category = current($this->categories);
                 return true;
             } else {
                 $this->categoryloop = false;
                 return false;
             }
             break;
         case "category-list":
             $defaults = array('title' => '', 'before' => '', 'after' => '', 'class' => '', 'exclude' => '', 'orderby' => 'name', 'order' => 'ASC', 'depth' => 0, 'childof' => 0, 'parent' => false, 'showall' => false, 'linkall' => false, 'linkcount' => false, 'dropdown' => false, 'hierarchy' => false, 'products' => false, 'wraplist' => true, 'showsmart' => false);
             $options = array_merge($defaults, $options);
             extract($options, EXTR_SKIP);
             $this->load_categories(array("where" => "(pd.published='on' OR pd.id IS NULL)", "orderby" => $orderby, "order" => $order), $showsmart);
             $string = "";
             $depthlimit = $depth;
             $depth = 0;
             $exclude = explode(",", $exclude);
             $classes = ' class="shopp_categories' . (empty($class) ? '' : ' ' . $class) . '"';
             $wraplist = value_is_true($wraplist);
             if (value_is_true($dropdown)) {
                 if (!isset($default)) {
                     $default = __('Select category&hellip;', 'Shopp');
                 }
                 $string .= $title;
                 $string .= '<form><select name="shopp_cats" id="shopp-categories-menu"' . $classes . '>';
                 $string .= '<option value="">' . $default . '</option>';
                 foreach ($this->categories as &$category) {
                     if (!empty($category->id) && in_array($category->id, $exclude)) {
                         continue;
                     }
                     // Skip excluded categories
                     if ($category->total == 0 && !isset($category->smart)) {
                         continue;
                     }
                     // Only show categories with products
                     if ($depthlimit && $category->depth >= $depthlimit) {
                         continue;
                     }
                     if (value_is_true($hierarchy) && $category->depth > $depth) {
                         $parent =& $previous;
                         if (!isset($parent->path)) {
                             $parent->path = '/' . $parent->slug;
                         }
                     }
                     if (value_is_true($hierarchy)) {
                         $padding = str_repeat("&nbsp;", $category->depth * 3);
                     }
                     if (SHOPP_PERMALINKS) {
                         $link = $Shopp->shopuri . 'category/' . $category->uri;
                     } else {
                         $link = add_query_arg('shopp_category', $category->id, $Shopp->shopuri);
                     }
                     $total = '';
                     if (value_is_true($products) && $category->total > 0) {
                         $total = ' (' . $category->total . ')';
                     }
                     $string .= '<option value="' . $link . '">' . $padding . $category->name . $total . '</option>';
                     $previous =& $category;
                     $depth = $category->depth;
                 }
                 $string .= '</select></form>';
                 $string .= '<script type="text/javascript">';
                 $string .= 'var menu = document.getElementById(\'shopp-categories-menu\');';
                 $string .= 'if (menu) {';
                 $string .= '	menu.onchange = function () {';
                 $string .= '		document.location.href = this.options[this.selectedIndex].value;';
                 $string .= '	}';
                 $string .= '}';
                 $string .= '</script>';
             } else {
                 $string .= $title;
                 if ($wraplist) {
                     $string .= '<ul' . $classes . '>';
                 }
                 foreach ($this->categories as &$category) {
                     if (!isset($category->total)) {
                         $category->total = 0;
                     }
                     if (!isset($category->depth)) {
                         $category->depth = 0;
                     }
                     if (!empty($category->id) && in_array($category->id, $exclude)) {
                         continue;
                     }
                     // Skip excluded categories
                     if ($depthlimit && $category->depth >= $depthlimit) {
                         continue;
                     }
                     if (value_is_true($hierarchy) && $category->depth > $depth) {
                         $parent =& $previous;
                         if (!isset($parent->path)) {
                             $parent->path = $parent->slug;
                         }
                         $string = substr($string, 0, -5);
                         // Remove the previous </li>
                         $active = '';
                         if (isset($Shopp->Category) && !empty($parent->slug) && preg_match('/(^|\\/)' . $parent->path . '(\\/|$)/', $Shopp->Category->uri)) {
                             $active = ' active';
                         }
                         $subcategories = '<ul class="children' . $active . '">';
                         $string .= $subcategories;
                     }
                     if (value_is_true($hierarchy) && $category->depth < $depth) {
                         for ($i = $depth; $i > $category->depth; $i--) {
                             if (substr($string, strlen($subcategories) * -1) == $subcategories) {
                                 // If the child menu is empty, remove the <ul> to avoid breaking standards
                                 $string = substr($string, 0, strlen($subcategories) * -1) . '</li>';
                             } else {
                                 $string .= '</ul></li>';
                             }
                         }
                     }
                     if (SHOPP_PERMALINKS) {
                         $link = $Shopp->shopuri . 'category/' . $category->uri;
                     } else {
                         $link = add_query_arg('shopp_category', !empty($category->id) ? $category->id : $category->uri, $Shopp->shopuri);
                     }
                     $total = '';
                     if (value_is_true($products) && $category->total > 0) {
                         $total = ' <span>(' . $category->total . ')</span>';
                     }
                     $current = '';
                     if (isset($Shopp->Category) && $Shopp->Category->slug == $category->slug) {
                         $current = ' class="current"';
                     }
                     $listing = '';
                     if ($category->total > 0 || isset($category->smart) || $linkall) {
                         $listing = '<a href="' . $link . '"' . $current . '>' . $category->name . ($linkcount ? $total : '') . '</a>' . (!$linkcount ? $total : '');
                     } else {
                         $listing = $category->name;
                     }
                     if (value_is_true($showall) || $category->total > 0 || isset($category->smart) || $category->children) {
                         $string .= '<li' . $current . '>' . $listing . '</li>';
                     }
                     $previous =& $category;
                     $depth = $category->depth;
                 }
                 if (value_is_true($hierarchy) && $depth > 0) {
                     for ($i = $depth; $i > 0; $i--) {
                         if (substr($string, strlen($subcategories) * -1) == $subcategories) {
                             // If the child menu is empty, remove the <ul> to avoid breaking standards
                             $string = substr($string, 0, strlen($subcategories) * -1) . '</li>';
                         } else {
                             $string .= '</ul></li>';
                         }
                     }
                 }
                 if ($wraplist) {
                     $string .= '</ul>';
                 }
             }
             return $string;
             break;
         case "views":
             if (isset($Shopp->Category->controls)) {
                 return false;
             }
             $string = "";
             $string .= '<ul class="views">';
             if (isset($options['label'])) {
                 $string .= '<li>' . $options['label'] . '</li>';
             }
             $string .= '<li><button type="button" class="grid"></button></li>';
             $string .= '<li><button type="button" class="list"></button></li>';
             $string .= '</ul>';
             return $string;
         case "orderby-list":
             if (isset($Shopp->Category->controls)) {
                 return false;
             }
             if (isset($Shopp->Category->smart)) {
                 return false;
             }
             $menuoptions = Category::sortoptions();
             $title = "";
             $string = "";
             $default = $Shopp->Settings->get('default_product_order');
             if (empty($default)) {
                 $default = "title";
             }
             if (isset($options['default'])) {
                 $default = $options['default'];
             }
             if (isset($options['title'])) {
                 $title = $options['title'];
             }
             if (value_is_true($options['dropdown'])) {
                 if (isset($Shopp->Cart->data->Category['orderby'])) {
                     $default = $Shopp->Cart->data->Category['orderby'];
                 }
                 $string .= $title;
                 $string .= '<form action="' . esc_url($_SERVER['REQUEST_URI']) . '" method="get" id="shopp-' . $Shopp->Category->slug . '-orderby-menu">';
                 if (!SHOPP_PERMALINKS) {
                     foreach ($_GET as $key => $value) {
                         if ($key != 'shopp_orderby') {
                             $string .= '<input type="hidden" name="' . $key . '" value="' . $value . '" />';
                         }
                     }
                 }
                 $string .= '<select name="shopp_orderby" class="shopp-orderby-menu">';
                 $string .= menuoptions($menuoptions, $default, true);
                 $string .= '</select>';
                 $string .= '</form>';
                 $string .= '<script type="text/javascript">';
                 $string .= "jQuery('#shopp-" . $Shopp->Category->slug . "-orderby-menu select.shopp-orderby-menu').change(function () { this.form.submit(); });";
                 $string .= '</script>';
             } else {
                 if (strpos($_SERVER['REQUEST_URI'], "?") !== false) {
                     list($link, $query) = explode("\\?", $_SERVER['REQUEST_URI']);
                 }
                 $query = $_GET;
                 unset($query['shopp_orderby']);
                 $query = http_build_query($query);
                 if (!empty($query)) {
                     $query .= '&';
                 }
                 foreach ($menuoptions as $value => $option) {
                     $label = $option;
                     $href = esc_url($link . '?' . $query . 'shopp_orderby=' . $value);
                     $string .= '<li><a href="' . $href . '">' . $label . '</a></li>';
                 }
             }
             return $string;
             break;
         case "breadcrumb":
             if (isset($Shopp->Category->controls)) {
                 return false;
             }
             if (empty($this->categories)) {
                 $this->load_categories();
             }
             $separator = "&nbsp;&raquo; ";
             if (isset($options['separator'])) {
                 $separator = $options['separator'];
             }
             $category = false;
             if (isset($Shopp->Cart->data->breadcrumb)) {
                 $category = $Shopp->Cart->data->breadcrumb;
             }
             $trail = false;
             $search = array();
             if (isset($Shopp->Cart->data->Search)) {
                 $search = array('search' => $Shopp->Cart->data->Search);
             }
             $path = explode("/", $category);
             if ($path[0] == "tag") {
                 $category = "tag";
                 $search = array('tag' => urldecode($path[1]));
             }
             $Category = Catalog::load_category($category, $search);
             if (!empty($Category->uri)) {
                 $type = "category";
                 if (isset($Category->tag)) {
                     $type = "tag";
                 }
                 if (SHOPP_PERMALINKS) {
                     $link = esc_url(add_query_arg($_GET, $Shopp->shopuri . $type . '/' . $Category->uri));
                 } else {
                     if (isset($Category->smart)) {
                         $link = esc_url(add_query_arg(array_merge($_GET, array('shopp_category' => $Category->slug, 'shopp_pid' => null)), $Shopp->shopuri));
                     } else {
                         $link = esc_url(add_query_arg(array_merge($_GET, array('shopp_category' => $Category->id, 'shopp_pid' => null)), $Shopp->shopuri));
                     }
                 }
                 $filters = false;
                 if (!empty($Shopp->Cart->data->Category[$Category->slug])) {
                     $filters = ' (<a href="?shopp_catfilters=cancel">' . __('Clear Filters', 'Shopp') . '</a>)';
                 }
                 if (!empty($Shopp->Product)) {
                     $trail .= '<li><a href="' . $link . '">' . $Category->name . (!$trail ? '' : $separator) . '</a></li>';
                 } elseif (!empty($Category->name)) {
                     $trail .= '<li>' . $Category->name . $filters . (!$trail ? '' : $separator) . '</li>';
                 }
                 // Build category names path by going from the target category up the parent chain
                 $parentkey = !empty($Category->id) ? $this->categories[$Category->id]->parent : 0;
                 while ($parentkey != 0) {
                     $tree_category = $this->categories[$parentkey];
                     if (SHOPP_PERMALINKS) {
                         $link = $Shopp->shopuri . 'category/' . $tree_category->uri;
                     } else {
                         $link = esc_url(add_query_arg(array_merge($_GET, array('shopp_category' => $tree_category->id, 'shopp_pid' => null)), $Shopp->shopuri));
                     }
                     $trail = '<li><a href="' . $link . '">' . $tree_category->name . '</a>' . (empty($trail) ? '' : $separator) . '</li>' . $trail;
                     $parentkey = $tree_category->parent;
                 }
             }
             $trail = '<li><a href="' . $Shopp->link('catalog') . '">' . $pages['catalog']['title'] . '</a>' . (empty($trail) ? '' : $separator) . '</li>' . $trail;
             return '<ul class="breadcrumb">' . $trail . '</ul>';
             break;
         case "search":
             global $wp;
             $type = "hidden";
             if (isset($options['type'])) {
                 $type = $options['type'];
             }
             if ($type == "radio") {
                 $option = "shopp";
                 if (isset($options['option'])) {
                     $option = $options['option'];
                 }
                 $default = false;
                 if (isset($options['default'])) {
                     $default = value_is_true($options['default']);
                 }
                 $selected = '';
                 if ($default) {
                     $selected = ' checked="checked"';
                 }
                 if (!empty($wp->query_vars['st'])) {
                     $selected = '';
                     if ($wp->query_vars['st'] == $option) {
                         $selected = ' checked="checked"';
                     }
                 }
                 if ($option == "blog") {
                     return '<input type="radio" name="st" value="blog"' . $selected . ' />';
                 } else {
                     return '<input type="radio" name="st" value="shopp"' . $selected . ' />';
                 }
             } elseif ($type == "menu") {
                 if (empty($options['store'])) {
                     $options['store'] = __('Search the store', 'Shopp');
                 }
                 if (empty($options['blog'])) {
                     $options['blog'] = __('Search the blog', 'Shopp');
                 }
                 if (isset($wp->query_vars['st'])) {
                     $selected = $wp->query_vars['st'];
                 }
                 $menu = '<select name="st">';
                 if (isset($options['default']) && $options['default'] == "blog") {
                     $menu .= '<option value="blog"' . ($selected == "blog" ? ' selected="selected"' : '') . '>' . $options['blog'] . '</option>';
                     $menu .= '<option value="shopp"' . ($selected == "shopp" ? ' selected="selected"' : '') . '>' . $options['store'] . '</option>';
                 } else {
                     $menu .= '<option value="shopp"' . ($selected == "shopp" ? ' selected="selected"' : '') . '>' . $options['store'] . '</option>';
                     $menu .= '<option value="blog"' . ($selected == "blog" ? ' selected="selected"' : '') . '>' . $options['blog'] . '</option>';
                 }
                 $menu .= '</select>';
                 return $menu;
             } else {
                 return '<input type="hidden" name="st" value="shopp" />';
             }
             break;
         case "catalog-products":
             if ($property == "catalog-products") {
                 $Shopp->Category = new CatalogProducts($options);
             }
         case "new-products":
             if ($property == "new-products") {
                 $Shopp->Category = new NewProducts($options);
             }
         case "featured-products":
             if ($property == "featured-products") {
                 $Shopp->Category = new FeaturedProducts($options);
             }
         case "onsale-products":
             if ($property == "onsale-products") {
                 $Shopp->Category = new OnSaleProducts($options);
             }
         case "bestseller-products":
             if ($property == "bestseller-products") {
                 $Shopp->Category = new BestsellerProducts($options);
             }
         case "random-products":
             if ($property == "random-products") {
                 $Shopp->Category = new RandomProducts($options);
             }
         case "tag-products":
             if ($property == "tag-products") {
                 $Shopp->Category = new TagProducts($options);
             }
         case "related-products":
             if ($property == "related-products") {
                 $Shopp->Category = new RelatedProducts($options);
             }
         case "search-products":
             if ($property == "search-products") {
                 $Shopp->Category = new SearchResults($options);
             }
         case "category":
             if ($property == "category") {
                 if (isset($options['name'])) {
                     $Shopp->Category = new Category($options['name'], 'name');
                 } else {
                     if (isset($options['slug'])) {
                         $Shopp->Category = new Category($options['slug'], 'slug');
                     } else {
                         if (isset($options['id'])) {
                             $Shopp->Category = new Category($options['id']);
                         }
                     }
                 }
             }
             if (isset($options['reset'])) {
                 return $Shopp->Category = false;
             }
             if (isset($options['title'])) {
                 $Shopp->Category->name = $options['title'];
             }
             if (isset($options['show'])) {
                 $Shopp->Category->loading['limit'] = $options['show'];
             }
             if (isset($options['pagination'])) {
                 $Shopp->Category->loading['pagination'] = $options['pagination'];
             }
             if (isset($options['order'])) {
                 $Shopp->Category->loading['order'] = $options['order'];
             }
             if (isset($options['load'])) {
                 return true;
             }
             if (isset($options['controls']) && !value_is_true($options['controls'])) {
                 $Shopp->Category->controls = false;
             }
             if (isset($options['view'])) {
                 if ($options['view'] == "grid") {
                     $Shopp->Category->view = "grid";
                 } else {
                     $Shopp->Category->view = "list";
                 }
             }
             ob_start();
             if (isset($Shopp->Category->smart) && file_exists(SHOPP_TEMPLATES . "/category-{$Shopp->Category->slug}.php")) {
                 include SHOPP_TEMPLATES . "/category-{$Shopp->Category->slug}.php";
             } elseif (isset($Shopp->Category->id) && file_exists(SHOPP_TEMPLATES . "/category-{$Shopp->Category->id}.php")) {
                 include SHOPP_TEMPLATES . "/category-{$Shopp->Category->id}.php";
             } else {
                 include SHOPP_TEMPLATES . "/category.php";
             }
             $content = ob_get_contents();
             ob_end_clean();
             $Shopp->Category = false;
             // Reset the current category
             return $content;
             break;
         case "product":
             if (isset($options['name'])) {
                 $Shopp->Product = new Product($options['name'], 'name');
             } else {
                 if (isset($options['slug'])) {
                     $Shopp->Product = new Product($options['slug'], 'slug');
                 } else {
                     if (isset($options['id'])) {
                         $Shopp->Product = new Product($options['id']);
                     }
                 }
             }
             if (isset($options['load'])) {
                 return true;
             }
             ob_start();
             if (file_exists(SHOPP_TEMPLATES . "/product-{$Shopp->Product->id}.php")) {
                 include SHOPP_TEMPLATES . "/product-{$Shopp->Product->id}.php";
             } else {
                 include SHOPP_TEMPLATES . "/product.php";
             }
             $content = ob_get_contents();
             ob_end_clean();
             return $content;
             break;
         case "sideproduct":
             $content = false;
             $source = $options['source'];
             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 Product($product);
                     } else {
                         $Shopp->Product = new Product($product, 'slug');
                     }
                     if (empty($Shopp->Product->id)) {
                         continue;
                     }
                     if (isset($options['load'])) {
                         return true;
                     }
                     ob_start();
                     if (file_exists(SHOPP_TEMPLATES . "/sideproduct-{$Shopp->Product->id}.php")) {
                         include SHOPP_TEMPLATES . "/sideproduct-{$Shopp->Product->id}.php";
                     } else {
                         include SHOPP_TEMPLATES . "/sideproduct.php";
                     }
                     $content .= ob_get_contents();
                     ob_end_clean();
                 }
                 // Restore original requested category
                 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 (empty($options['category'])) {
                     return false;
                 }
                 $Shopp->Category = Catalog::load_category($options['category']);
                 $Shopp->Category->load_products($options);
                 if (isset($options['load'])) {
                     return true;
                 }
                 foreach ($Shopp->Category->products as $product) {
                     $Shopp->Product = $product;
                     ob_start();
                     if (file_exists(SHOPP_TEMPLATES . "/sideproduct-{$Shopp->Product->id}.php")) {
                         include SHOPP_TEMPLATES . "/sideproduct-{$Shopp->Product->id}.php";
                     } else {
                         include SHOPP_TEMPLATES . "/sideproduct.php";
                     }
                     $content .= ob_get_contents();
                     ob_end_clean();
                 }
                 // Restore original requested category
                 if (!empty($Requested)) {
                     $Shopp->Category = $Requested;
                 } else {
                     $Shopp->Category = false;
                 }
             }
             return $content;
             break;
     }
 }
Example #15
0
/**
 * Determines the current taxrate from the store settings and provided options
 *
 * Contextually works out if the tax rate applies or not based on storefront
 * settings and the provided override options
 * 
 * @since 1.0
 *
 * @param string $override (optional) Specifies whether to override the default taxrate behavior
 * @param string $taxprice (optional) Supports a secondary contextual override
 * @return float The determined tax rate
 **/
function ecart_taxrate ($override=null,$taxprice=true,$Item=false) {
	$Settings = &EcartSettings();
	$locale = $Settings->get('base_operations');
	$rated = false;
	$taxrate = 0;
	$Taxes = new CartTax();

	if ($locale['vat']) $rated = true;
	if (!is_null($override)) $rated = $override;
	if (!value_is_true($taxprice)) $rated = false;

	if ($rated) $taxrate = $Taxes->rate($Item);
	return $taxrate;
}
Example #16
0
	/**
	 * Provides ecart('checkout') template API functionality
	 * 
	 * @since 1.0
	 *
	 * @return mixed
	 **/
	function tag ($property,$options=array()) {
		global $Ecart,$wp;

		$pages = $Ecart->Settings->get('pages');
		$base = $Ecart->Settings->get('base_operations');
		$countries = $Ecart->Settings->get('target_markets');
		$process = get_query_var('ecart_proc');

		$select_attrs = array('title','required','class','disabled','required','size','tabindex','accesskey');
		$submit_attrs = array('title','class','value','disabled','tabindex','accesskey');

		if (!isset($options['mode'])) $options['mode'] = "input";

		switch ($property) {
			case "url":
				$link = ecarturl(false,'checkout',$this->security());

				// Pass any arguments along
				$args = $_GET;
				unset($args['page_id'],$args['acct']);
				$link = esc_url(add_query_arg($args,$link));
				if ($process == "confirm-order") $link = apply_filters('ecart_confirm_url',$link);
				else $link = apply_filters('ecart_checkout_url',$link);
				return $link;
				break;
			case "function":
				if (!isset($options['shipcalc'])) $options['shipcalc'] = '<img src="'.ECART_ADMIN_URI.'/icons/updating.gif" alt="'.__('Updating','Ecart').'" width="16" height="16" />';
				$regions = Lookup::country_zones();
				$base = $Ecart->Settings->get('base_operations');

				$js = "var regions = ".json_encode($regions).",".
									"SHIPCALC_STATUS = '".$options['shipcalc']."',".
									"d_pm = '".sanitize_title_with_dashes($this->paymethod)."',".
									"pm_cards = {};";

				foreach ($this->payoptions as $handle => $option) {
					if (empty($option->cards)) continue;
					$js .= "pm_cards['".$handle."'] = ".json_encode($option->cards).";";
				}
				add_storefrontjs($js,true);

				if (!empty($options['value'])) $value = $options['value'];
				else $value = "process";
				$output = '<div><input type="hidden" name="checkout" value="'.$value.'" /></div>';
				if ($value == "confirmed") $output = apply_filters('ecart_confirm_form',$output);
				else $output = apply_filters('ecart_checkout_form',$output);
				return $output;
				break;
			case "errors":
			case "error":
				$Errors = &EcartErrors();
				if (!$Errors->exist(ECART_COMM_ERR)) return false;
				$errors = $Errors->get(ECART_COMM_ERR);
				$defaults = array(
					'before' => '<li>',
					'after' => '</li>'
				);
				$options = array_merge($defaults,$options);
				extract($options);

				$result = "";
				foreach ((array)$errors as $error)
					if (!$error->blank()) $result .= $before.$error->message(true).$after;
				return $result;
				break;
			case "cart-summary":
				ob_start();
				include(ECART_TEMPLATES."/summary.php");
				$content = ob_get_contents();
				ob_end_clean();

				// If inside the checkout form, strip the extra <form> tag so we don't break standards
				// This is ugly, but necessary given the different markup contexts the cart summary is used in
				$Storefront =& EcartStorefront();
				if ($Storefront !== false && $Storefront->checkout)
					$content = preg_replace('/<\/?form.*?>/','',$content);

				return $content;
				break;
			case "loggedin": return $this->Customer->login; break;
			case "notloggedin": return (!$this->Customer->login && $Ecart->Settings->get('account_system') != "none"); break;
			case "email-login":  // Deprecating
			case "loginname-login":  // Deprecating
			case "account-login":
				if (!isset($options['autocomplete'])) $options['autocomplete'] = "off";
				if (!empty($_POST['account-login']))
					$options['value'] = $_POST['account-login'];
				return '<input type="text" name="account-login" id="account-login"'.inputattrs($options).' />';
				break;
			case "password-login":
				if (!isset($options['autocomplete'])) $options['autocomplete'] = "off";
				if (!empty($_POST['password-login']))
					$options['value'] = $_POST['password-login'];
				return '<input type="password" name="password-login" id="password-login" '.inputattrs($options).' />';
				break;
			case "submit-login": // Deprecating
			case "login-button":
				$string = '<input type="hidden" name="process-login" id="process-login" value="false" />';
				$string .= '<input type="submit" name="submit-login" id="submit-login" '.inputattrs($options).' />';
				return $string;
				break;
			case "firstname":
				if ($options['mode'] == "value") return $this->Customer->firstname;
				if (!empty($this->Customer->firstname))
					$options['value'] = $this->Customer->firstname;
				return '<input type="text" name="firstname" id="firstname" '.inputattrs($options).' />';
				break;
			case "lastname":
				if ($options['mode'] == "value") return $this->Customer->lastname;
				if (!empty($this->Customer->lastname))
					$options['value'] = $this->Customer->lastname;
				return '<input type="text" name="lastname" id="lastname" '.inputattrs($options).' />';
				break;
			case "email":
				if ($options['mode'] == "value") return $this->Customer->email;
				if (!empty($this->Customer->email))
					$options['value'] = $this->Customer->email;
				return '<input type="text" name="email" id="email" '.inputattrs($options).' />';
				break;
			case "loginname":
				if (!isset($options['autocomplete'])) $options['autocomplete'] = "off";
				if ($options['mode'] == "value") return $this->Customer->loginname;
				if (!empty($this->Customer->loginname))
					$options['value'] = $this->Customer->loginname;
				return '<input type="text" name="loginname" id="login" '.inputattrs($options).' />';
				break;
			case "password":
				if (!isset($options['autocomplete'])) $options['autocomplete'] = "off";
				if ($options['mode'] == "value")
					return strlen($this->Customer->password) == 34?str_pad('&bull;',8):$this->Customer->password;
				if (!empty($this->Customer->password))
					$options['value'] = $this->Customer->password;
				return '<input type="password" name="password" id="password" '.inputattrs($options).' />';
				break;
			case "confirm-password":
				if (!isset($options['autocomplete'])) $options['autocomplete'] = "off";
				if (!empty($this->Customer->_confirm_password))
					$options['value'] = $this->Customer->_confirm_password;
				return '<input type="password" name="confirm-password" id="confirm-password" '.inputattrs($options).' />';
				break;
			case "phone":
				if ($options['mode'] == "value") return $this->Customer->phone;
				if (!empty($this->Customer->phone))
					$options['value'] = $this->Customer->phone;
				return '<input type="text" name="phone" id="phone" '.inputattrs($options).' />';
				break;
			case "organization":
			case "company":
				if ($options['mode'] == "value") return $this->Customer->company;
				if (!empty($this->Customer->company))
					$options['value'] = $this->Customer->company;
				return '<input type="text" name="company" id="company" '.inputattrs($options).' />';
				break;
			case "marketing":
				if ($options['mode'] == "value") return $this->Customer->marketing;
				if (!empty($this->Customer->marketing))
					$options['value'] = $this->Customer->marketing;
				$attrs = array("accesskey","alt","checked","class","disabled","format",
					"minlength","maxlength","readonly","size","src","tabindex",
					"title");
				$input = '<input type="hidden" name="marketing" value="no" />';
				$input .= '<input type="checkbox" name="marketing" id="marketing" value="yes" '.inputattrs($options,$attrs).' />';
				return $input;
				break;
			case "customer-info":
				$defaults = array(
					'name' => false, // REQUIRED
					'info' => false,
					'mode' => false,
					'title' => '',
					'type' => 'hidden',
					'value' => '',
					'cols' => '30',
					'rows' => '3',
					'options' => ''
				);
				$op = array_merge($defaults,$options);
				extract($op);

				// Allowed input types
				$allowed_types = array("text","hidden","password","checkbox","radio","textarea","menu");

				// Input types that can override option-specified value with the loaded data value
				$value_override = array("text","hidden","password","textarea","menu");

				/// Allowable attributes for textarea inputs
				$textarea_attrs = array('accesskey','title','tabindex','class','disabled','required');

				if (!$name) { // Iterator for order data
					if (!isset($this->_customer_info_loop)) {
						reset($this->Customer->info->named);
						$this->_customer_info_loop = true;
					} else next($this->Customer->info->named);

					if (current($this->Customer->info->named) !== false) return true;
					else {
						unset($this->_customer_info_loop);
						return false;
					}
				}

				if (isset($this->Customer->info->named[$name])) $info = $this->Customer->info->named[$name];
				if ($name && $mode == "value") return $info;

				if (!in_array($type,$allowed_types)) $type = 'hidden';
				if (empty($title)) $title = $name;
				$id = 'customer-info-'.sanitize_title_with_dashes($name);

				if (in_array($type,$value_override) && !empty($info))
					$value = $info;
				switch (strtolower($type)) {
					case "textarea":
						return '<textarea name="info['.$name.']" cols="'.$cols.'" rows="'.$rows.'" id="'.$id.'" '.inputattrs($op,$textarea_attrs).'>'.$value.'</textarea>';
						break;
					case "menu":
						if (is_string($options)) $options = explode(',',$options);
						return '<select name="info['.$name.']" id="'.$id.'" '.inputattrs($op,$select_attrs).'>'.menuoptions($options,$value).'</select>';
						break;
					default:
						return '<input type="'.$type.'" name="info['.$name.']" id="'.$id.'" '.inputattrs($op).' />';
						break;
				}
				break;

			// SHIPPING TAGS
			case "shipping": return (!empty($this->shipped)); break;
			case "shipping-address":
				if ($options['mode'] == "value") return $this->Shipping->address;
				if (!empty($this->Shipping->address))
					$options['value'] = $this->Shipping->address;
				return '<input type="text" name="shipping[address]" id="shipping-address" '.inputattrs($options).' />';
				break;
			case "shipping-xaddress":
				if ($options['mode'] == "value") return $this->Shipping->xaddress;
				if (!empty($this->Shipping->xaddress))
					$options['value'] = $this->Shipping->xaddress;
				return '<input type="text" name="shipping[xaddress]" id="shipping-xaddress" '.inputattrs($options).' />';
				break;
			case "shipping-city":
				if ($options['mode'] == "value") return $this->Shipping->city;
				if (!empty($this->Shipping->city))
					$options['value'] = $this->Shipping->city;
				return '<input type="text" name="shipping[city]" id="shipping-city" '.inputattrs($options).' />';
				break;
			case "shipping-province":
			case "shipping-state":
				if ($options['mode'] == "value") return $this->Shipping->state;
				if (!isset($options['selected'])) $options['selected'] = false;
				if (!empty($this->Shipping->state)) {
					$options['selected'] = $this->Shipping->state;
					$options['value'] = $this->Shipping->state;
				}

				$output = false;
				$country = $base['country'];
				if (!empty($this->Shipping->country))
					$country = $this->Shipping->country;
				if (!array_key_exists($country,$countries)) $country = key($countries);

				$regions = Lookup::country_zones();
				$states = $regions[$country];

				if (isset($options['options']) && empty($states)) $states = explode(",",$options['options']);

				if (isset($options['type']) && $options['type'] == "text")
					return '<input type="text" name="shipping[state]" id="shipping-state" '.inputattrs($options).'/>';

				$classname = isset($options['class'])?$options['class']:'';
				$label = (!empty($options['label']))?$options['label']:'';
				$options['disabled'] = 'disabled';
				$options['class'] = ($classname?"$classname ":"").'disabled hidden';

				$output .= '<select name="shipping[state]" id="shipping-state-menu" '.inputattrs($options,$select_attrs).'>';
				$output .= '<option value="">'.$label.'</option>';
				if (is_array($states) && !empty($states)) $output .= menuoptions($states,$options['selected'],true);
				$output .= '</select>';
				unset($options['disabled']);
				$options['class'] = $classname;
				$output .= '<input type="text" name="shipping[state]" id="shipping-state" '.inputattrs($options).'/>';

				return $output;
				break;
			case "shipping-postcode":
				if ($options['mode'] == "value") return $this->Shipping->postcode;
				if (!empty($this->Shipping->postcode))
					$options['value'] = $this->Shipping->postcode;
				return '<input type="text" name="shipping[postcode]" id="shipping-postcode" '.inputattrs($options).' />'; break;
			case "shipping-country":
				if ($options['mode'] == "value") return $this->Shipping->country;
				if (!empty($this->Shipping->country))
					$options['selected'] = $this->Shipping->country;
				else if (empty($options['selected'])) $options['selected'] = $base['country'];
				$output = '<select name="shipping[country]" id="shipping-country" '.inputattrs($options,$select_attrs).'>';
			 	$output .= menuoptions($countries,$options['selected'],true);
				$output .= '</select>';
				return $output;
				break;
			case "same-shipping-address":
				$label = __("Same shipping address","Ecart");
				if (isset($options['label'])) $label = $options['label'];
				$checked = ' checked="checked"';
				if (isset($options['checked']) && !value_is_true($options['checked'])) $checked = '';
				$output = '<label for="same-shipping"><input type="checkbox" name="sameshipaddress" value="on" id="same-shipping" '.$checked.' /> '.$label.'</label>';
				return $output;
				break;
			case "residential-shipping-address":
				$label = __("Residential shipping address","Ecart");
				if (isset($options['label'])) $label = $options['label'];
				if (isset($options['checked']) && value_is_true($options['checked'])) $checked = ' checked="checked"';
				$output = '<label for="residential-shipping"><input type="hidden" name="shipping[residential]" value="no" /><input type="checkbox" name="shipping[residential]" value="yes" id="residential-shipping" '.$checked.' /> '.$label.'</label>';
				return $output;
				break;

			// BILLING TAGS
			case "billing-required": // DEPRECATED
			case "card-required":
				if ($this->Cart->Totals->total == 0) return false;
				foreach ($Ecart->Gateways->active as $gateway)
					if (!empty($gateway->cards)) return true;
				return false;
				break;
			case "billing-address":
				if ($options['mode'] == "value") return $this->Billing->address;
				if (!empty($this->Billing->address))
					$options['value'] = $this->Billing->address;
				return '<input type="text" name="billing[address]" id="billing-address" '.inputattrs($options).' />';
				break;
			case "billing-xaddress":
				if ($options['mode'] == "value") return $this->Billing->xaddress;
				if (!empty($this->Billing->xaddress))
					$options['value'] = $this->Billing->xaddress;
				return '<input type="text" name="billing[xaddress]" id="billing-xaddress" '.inputattrs($options).' />';
				break;
			case "billing-city":
				if ($options['mode'] == "value") return $this->Billing->city;
				if (!empty($this->Billing->city))
					$options['value'] = $this->Billing->city;
				return '<input type="text" name="billing[city]" id="billing-city" '.inputattrs($options).' />';
				break;
			case "billing-province":
			case "billing-state":
				if ($options['mode'] == "value") return $this->Billing->state;
				if (!isset($options['selected'])) $options['selected'] = false;
				if (!empty($this->Billing->state)) {
					$options['selected'] = $this->Billing->state;
					$options['value'] = $this->Billing->state;
				}

				$output = false;
				$country = $base['country'];
				if (!empty($this->Billing->country))
					$country = $this->Billing->country;
				if (!array_key_exists($country,$countries)) $country = key($countries);

				$regions = Lookup::country_zones();
				$states = $regions[$country];

				if (isset($options['options']) && empty($states)) $states = explode(",",$options['options']);

				if (isset($options['type']) && $options['type'] == "text")
					return '<input type="text" name="billing[state]" id="billing-state" '.inputattrs($options).'/>';

				$classname = isset($options['class'])?$options['class']:'';
				$label = (!empty($options['label']))?$options['label']:'';
				$options['disabled'] = 'disabled';
				$options['class'] = ($classname?"$classname ":"").'disabled hidden';

				$output .= '<select name="billing[state]" id="billing-state-menu" '.inputattrs($options,$select_attrs).'>';
				$output .= '<option value="">'.$label.'</option>';
				if (is_array($states) && !empty($states)) $output .= menuoptions($states,$options['selected'],true);
				$output .= '</select>';
				unset($options['disabled']);
				$options['class'] = $classname;
				$output .= '<input type="text" name="billing[state]" id="billing-state" '.inputattrs($options).'/>';

				return $output;
				break;
			case "billing-postcode":
				if ($options['mode'] == "value") return $this->Billing->postcode;
				if (!empty($this->Billing->postcode))
					$options['value'] = $this->Billing->postcode;
				return '<input type="text" name="billing[postcode]" id="billing-postcode" '.inputattrs($options).' />';
				break;
			case "billing-country":
				if ($options['mode'] == "value") return $this->Billing->country;
				if (!empty($this->Billing->country))
					$options['selected'] = $this->Billing->country;
				else if (empty($options['selected'])) $options['selected'] = $base['country'];
				$output = '<select name="billing[country]" id="billing-country" '.inputattrs($options,$select_attrs).'>';
			 	$output .= menuoptions($countries,$options['selected'],true);
				$output .= '</select>';
				return $output;
				break;
			case "billing-card":
				if ($options['mode'] == "value")
					return str_repeat('X',strlen($this->Billing->card)-4)
						.substr($this->Billing->card,-4);
				$options['class'] = isset($options['class']) ? $options['class'].' paycard':'paycard';
				if (!empty($this->Billing->card)) {
					$options['value'] = $this->Billing->card;
					$this->Billing->card = "";
				}
				if (!isset($options['autocomplete'])) $options['autocomplete'] = "off";
				return '<input type="text" name="billing[card]" id="billing-card" '.inputattrs($options).' />';
				break;
			case "billing-cardexpires-mm":
				if ($options['mode'] == "value") return date("m",$this->Billing->cardexpires);
				$options['class'] = isset($options['class']) ? $options['class'].' paycard':'paycard';
				if (!isset($options['autocomplete'])) $options['autocomplete'] = "off";
				if (!empty($this->Billing->cardexpires))
					$options['value'] = date("m",$this->Billing->cardexpires);
				return '<input type="text" name="billing[cardexpires-mm]" id="billing-cardexpires-mm" '.inputattrs($options).' />';
				break;
			case "billing-cardexpires-yy":
				if ($options['mode'] == "value") return date("y",$this->Billing->cardexpires);
				$options['class'] = isset($options['class']) ? $options['class'].' paycard':'paycard';
				if (!isset($options['autocomplete'])) $options['autocomplete'] = "off";
				if (!empty($this->Billing->cardexpires))
					$options['value'] = date("y",$this->Billing->cardexpires);
				return '<input type="text" name="billing[cardexpires-yy]" id="billing-cardexpires-yy" '.inputattrs($options).' />';
				break;
			case "billing-cardtype":
				if ($options['mode'] == "value") return $this->Billing->cardtype;
				$options['class'] = isset($options['class']) ? $options['class'].' paycard':'paycard';
				if (!isset($options['selected'])) $options['selected'] = false;
				if (!empty($this->Billing->cardtype))
					$options['selected'] = $this->Billing->cardtype;

				$cards = array();
				foreach ($this->paycards as $paycard)
					$cards[$paycard->symbol] = $paycard->name;

				$label = (!empty($options['label']))?$options['label']:'';
				$output = '<select name="billing[cardtype]" id="billing-cardtype" '.inputattrs($options,$select_attrs).'>';
				$output .= '<option value="" selected="selected">'.$label.'</option>';
			 	$output .= menuoptions($cards,$options['selected'],true);
				$output .= '</select>';

				$js = array();
				$js[] = "var paycards = {};";
				foreach ($this->paycards as $handle => $paycard) {
					$js[] = "paycards['".$handle."'] = ".json_encode($paycard).";";
				}
				add_storefrontjs(join("",$js), true);

				return $output;
				break;
			case "billing-cardholder":
				if ($options['mode'] == "value") return $this->Billing->cardholder;
				$options['class'] = isset($options['class']) ? $options['class'].' paycard':'paycard';
				if (!isset($options['autocomplete'])) $options['autocomplete'] = "off";
				if (!empty($this->Billing->cardholder))
					$options['value'] = $this->Billing->cardholder;
				return '<input type="text" name="billing[cardholder]" id="billing-cardholder" '.inputattrs($options).' />';
				break;
			case "billing-cvv":
				if (!isset($options['autocomplete'])) $options['autocomplete'] = "off";
				if (!empty($_POST['billing']['cvv']))
					$options['value'] = $_POST['billing']['cvv'];
				$options['class'] = isset($options['class']) ? $options['class'].' paycard':'paycard';
				return '<input type="text" name="billing[cvv]" id="billing-cvv" '.inputattrs($options).' />';
				break;
			case "billing-xcsc-required":
				$Gateways = $Ecart->Gateways->active;
				foreach ($Gateways as $Gateway) {
					foreach ((array)$Gateway->settings['cards'] as $card) {
						$PayCard = Lookup::paycard($card);
						if (!empty($PayCard->inputs)) return true;
					}
				}
				return false;
				break;
			case "billing-xcsc":
				if (empty($options['input'])) return;
				$input = $options['input'];

				$cards = array();
				$valid = array();
				// Collect valid card inputs for all gateways
				foreach ($this->payoptions as $payoption) {
					foreach ($payoption->cards as $card) {
						$PayCard = Lookup::paycard($card);
						if (empty($PayCard->inputs)) continue;
						$cards[] = $PayCard->symbol;
						foreach ($PayCard->inputs as $field => $size)
							$valid[$field] = $size;
					}
				}

				if (!array_key_exists($input,$valid)) return;

				if (!empty($_POST['billing']['xcsc'][$input]))
					$options['value'] = $_POST['billing']['xcsc'][$input];
				$options['class'] = isset($options['class']) ? $options['class'].' paycard xcsc':'paycard xcsc';

				if (!isset($options['autocomplete'])) $options['autocomplete'] = "off";
				$string = '<input type="text" name="billing[xcsc]['.$input.']" id="billing-xcsc-'.$input.'" '.inputattrs($options).' />';
				return $string;
				break;
			case "billing-xco": return; break; // DEPRECATED
			case "billing-localities":
				$rates = $Ecart->Settings->get("taxrates");
				foreach ((array)$rates as $rate) if (isset($rate['locals']) && is_array($rate['locals'])) return true;
				return false;
				break;
			case "billing-locale":
				if ($options['mode'] == "value") return $this->Billing->locale;
				if (!isset($options['selected'])) $options['selected'] = false;
				if (!empty($this->Billing->locale)) {
					$options['selected'] = $this->Billing->locale;
					$options['value'] = $this->Billing->locale;
				}
				if (empty($options['type'])) $options['type'] = "menu";
				$output = false;


				$rates = $Ecart->Settings->get("taxrates");
				foreach ($rates as $rate) if (is_array($rate['locals']))
					$locales[$rate['country'].$rate['zone']] = array_keys($rate['locals']);

				add_storefrontjs('var locales = '.json_encode($locales).';',true);

				$Taxes = new CartTax();
				$rate = $Taxes->rate(false,true);

				$localities = array_keys($rate['locals']);
				$label = (!empty($options['label']))?$options['label']:'';
				$output = '<select name="billing[locale]" id="billing-locale" '.inputattrs($options,$select_attrs).'>';
			 	$output .= menuoptions($localities,$options['selected']);
				$output .= '</select>';
				return $output;
				break;
			case "has-data":
			case "hasdata": return (is_array($this->data) && count($this->data) > 0); break;
			case "order-data":
			case "orderdata":
				$defaults = array(
					'name' => false, // REQUIRED
					'data' => false,
					'mode' => false,
					'title' => '',
					'type' => 'hidden',
					'value' => '',
					'cols' => '30',
					'rows' => '3',
					'options' => ''
				);
				$op = array_merge($defaults,$options);
				extract($op);

				// Allowed input types
				$allowed_types = array("text","hidden","password","checkbox","radio","textarea","menu");

				// Input types that can override option-specified value with the loaded data value
				$value_override = array("text","hidden","password","textarea","menu");

				/// Allowable attributes for textarea inputs
				$textarea_attrs = array('accesskey','title','tabindex','class','disabled','required');

				if (!$name) { // Iterator for order data
					if (!isset($this->_data_loop)) {
						reset($this->data);
						$this->_data_loop = true;
					} else next($this->data);

					if (current($this->data) !== false) return true;
					else {
						unset($this->_data_loop);
						return false;
					}
				}

				if (isset($this->data[$name])) $data = $this->data[$name];
				if ($name && $mode == "value") return $data;

				if (!in_array($type,$allowed_types)) $type = 'hidden';
				if (empty($title)) $title = $name;
				$id = 'order-data-'.sanitize_title_with_dashes($name);

				if (in_array($type,$value_override) && !empty($data))
					$value = $data;
				switch (strtolower($type)) {
					case "textarea":
						return '<textarea name="data['.$name.']" cols="'.$cols.'" rows="'.$rows.'" id="'.$id.'" '.inputattrs($op,$textarea_attrs).'>'.$value.'</textarea>';
						break;
					case "menu":
						if (is_string($options)) $options = explode(',',$options);
						return '<select name="data['.$name.']" id="'.$id.'" '.inputattrs($op,$select_attrs).'>'.menuoptions($options,$value).'</select>';
						break;
					default:
						return '<input type="'.$type.'" name="data['.$name.']" id="'.$id.'" '.inputattrs($op).' />';
						break;
				}
				break;
			case "data":
				if (!is_array($this->data)) return false;
				$data = current($this->data);
				$name = key($this->data);
				if (isset($options['name'])) return $name;
				return $data;
				break;
			case "submit":
				if (!isset($options['value'])) $options['value'] = __('Submit Order','Ecart');
				$options['class'] = isset($options['class'])?$options['class'].' checkout-button':'checkout-button';

				$wrapclass = '';
				if (isset($options['wrapclass'])) $wrapclass = ' '.$options['wrapclass'];

				$buttons = array('<input type="submit" name="process" id="checkout-button" '.inputattrs($options,$submit_attrs).' />');

				if (!$this->Cart->orderisfree())
					$buttons = apply_filters('ecart_checkout_submit_button',$buttons,$options,$submit_attrs);

				$_ = array();
				foreach ($buttons as $label => $button)
					$_[] = '<span class="payoption-button payoption-'.sanitize_title_with_dashes($label).($label === 0?$wrapclass:'').'">'.$button.'</span>';

				return join("\n",$_);
				break;
			case "confirm-button":
				if (empty($options['errorlabel'])) $options['errorlabel'] = __('Return to Checkout','Ecart');
				if (empty($options['value'])) $options['value'] = __('Confirm Order','Ecart');

				$button = '<input type="submit" name="confirmed" id="confirm-button" '.inputattrs($options,$submit_attrs).' />';
				$return = '<a href="'.ecarturl(false,'checkout',$this->security()).'"'.inputattrs($options,array('class')).'>'.
								$options['errorlabel'].'</a>';

				if (!$this->validated) $markup = $return;
				else $markup = $button;
				return apply_filters('ecart_checkout_confirm_button',$markup,$options,$submit_attrs);
				break;
			case "local-payment": return true; break; // DEPRECATED
			case "xco-buttons": return;	break; // DEPRECATED
			case "payoptions":
			case "payment-options":
			case "paymentoptions":
				if ($this->Cart->orderisfree()) return false;
				$payment_methods = apply_filters('ecart_payment_methods',count($this->payoptions));
				if ($payment_methods <= 1) return false; // Skip if only one gateway is active
				$defaults = array(
					'default' => false,
					'exclude' => false,
					'type' => 'menu',
					'mode' => false
				);
				$options = array_merge($defaults,$options);
				extract($options);
				unset($options['type']);

				if ("loop" == $mode) {
					if (!isset($this->_pay_loop)) {
						reset($this->payoptions);
						$this->_pay_loop = true;
					} else next($this->payoptions);

					if (current($this->payoptions) !== false) return true;
					else {
						unset($this->_pay_loop);
						return false;
					}
					return true;
				}

				$excludes = array_map('sanitize_title_with_dashes',explode(",",$exclude));
				$payoptions = array_keys($this->payoptions);

				$payoptions = array_diff($payoptions,$excludes);
				$paymethod = current($payoptions);

				if ($default !== false && !isset($this->_paymethod_selected)) {
					$default = sanitize_title_with_dashes($default);
					if (in_array($default,$payoptions)) $paymethod = $default;
				}

				if ($this->paymethod != $paymethod) {
					$this->paymethod = $paymethod;
					$processor = $this->payoptions[$this->paymethod]->processor;
					if (!empty($processor)) $this->processor($processor);
				}

				$output = '';
				switch ($type) {
					case "list":
						$output .= '<span><ul>';
						foreach ($payoptions as $value) {
							if (in_array($value,$excludes)) continue;
							$payoption = $this->payoptions[$value];
							$options['value'] = $value;
							$options['checked'] = ($this->paymethod == $value)?'checked':false;
							if ($options['checked'] === false) unset($options['checked']);
							$output .= '<li><label><input type="radio" name="paymethod" '.inputattrs($options).' /> '.$payoption->label.'</label></li>';
						}
						$output .= '</ul></span>';
						break;
					case "hidden":
						if (!isset($options['value']) && $default) $options['value'] = $this->paymethod;
						$output .= '<input type="hidden" name="paymethod"'.inputattrs($options).' />';
						break;
					default:
						$output .= '<select name="paymethod" '.inputattrs($options,$select_attrs).'>';
						foreach ($payoptions as $value) {
							if (in_array($value,$excludes)) continue;
							$payoption = $this->payoptions[$value];
							$selected = ($this->paymethod == $value)?' selected="selected"':'';
							$output .= '<option value="'.$value.'"'.$selected.'>'.$payoption->label.'</option>';
						}
						$output .= '</select>';
						break;
				}

				return $output;
				break;
			case "payoption":
			case "payment-option":
			case "paymentoption":
				$payoption = current($this->payoptions);
				$defaults = array(
					'labelpos' => 'after',
					'labeling' => false,
					'type' => 'hidden',
				);
				$options = array_merge($defaults,$options);
				extract($options);

				if (value_is_true($return)) return $payoption;

				$types = array('radio','checkbox','hidden');
				if (!in_array($type,$types)) $type = 'hidden';

				if (empty($options['value'])) $options['value'] = key($this->payoptions);

				$_ = array();
				if (value_is_true($labeling))
					$_[] = '<label>';
				if ($labelpos == "before") $_[] = $payoption->label;
				$_[] = '<input type="'.$type.'" name="paymethod"'.inputattrs($options).' />';
				if ($labelpos == "after") $_[] = $payoption->label;
				if (value_is_true($labeling))
					$_[] = '</label>';

				return join("",$_);
				break;
			case "gatewayinputs":
			case "gateway-inputs":
				return apply_filters('ecart_checkout_gateway_inputs',false);
				break;
			case "completed":
				if (empty($Ecart->Purchase->id) && $this->purchase !== false) {
					$Ecart->Purchase = new Purchase($this->purchase);
					$Ecart->Purchase->load_purchased();
					return (!empty($Ecart->Purchase->id));
				}
				return false;
				break;
			case "receipt":
				if (!empty($Ecart->Purchase->id))
					return $Ecart->Purchase->receipt();
				break;
		}
	}
Example #17
0
	/**
	 * ecart('catalog','...') tags
	 * 
	 * @since 1.0
	 * @version 1.1
	 * @see http://docs.ecartlugin.net/Catalog_Tags
	 *
	 * @param string $property The property to handle
	 * @param array $options (optional) The tag options to process
	 * @return mixed
	 **/
	function tag ($property,$options=array()) {
		global $Ecart;

		$Storefront =& EcartStorefront();

		switch ($property) {
			case "url": return ecarturl(false,'catalog'); break;
			case "display":
			case "type": return $this->type; break;
			case "is-landing":
			case "is-catalog": return (is_ecart_page('catalog') && $this->type == "catalog"); break;
			case "is-category": return (is_ecart_page('catalog') && $this->type == "category"); break;
			case "is-product": return (is_ecart_page('catalog') && $this->type == "product"); break;
			case "is-cart": return (is_ecart_page('cart')); break;
			case "is-checkout": return (is_ecart_page('checkout')); break;
			case "is-account": return (is_ecart_page('account')); break;
			case "tagcloud":
				if (!empty($options['levels'])) $levels = $options['levels'];
				else $levels = 7;
				if (empty($this->tags)) $this->load_tags();
				$min = -1; $max = -1;
				foreach ($this->tags as $tag) {
					if ($min == -1 || $tag->products < $min) $min = $tag->products;
					if ($max == -1 || $tag->products > $max) $max = $tag->products;
				}
				if ($max == 0) $max = 1;
				$string = '<ul class="ecart tagcloud">';
				foreach ($this->tags as $tag) {
					$level = floor((1-$tag->products/$max)*$levels)+1;
					$link = ECART_PRETTYURLS?ecarturl("tag/$tag->name"):ecarturl(array('ecart_tag'=>$tag->name));
					$string .= '<li class="level-'.$level.'"><a href="'.$link.'" rel="tag">'.$tag->name.'</a></li> ';
				}
				$string .= '</ul>';
				return $string;
				break;
			case "hascategories":
			case "has-categories":
				$showsmart = isset($options['showsmart'])?$options['showsmart']:false;
				if (empty($this->categories)) $this->load_categories(array('where'=>'true'),$showsmart);
				if (count($this->categories) > 0) return true; else return false; break;
			case "categories":
				if (!isset($this->_category_loop)) {
					reset($this->categories);
					$Ecart->Category = current($this->categories);
					$this->_category_loop = true;
				} else {
					$Ecart->Category = next($this->categories);
				}

				if (current($this->categories) !== false) return true;
				else {
					unset($this->_category_loop);
					reset($this->categories);
					return false;
				}
				break;
			case "category-list":
				$defaults = array(
					'title' => '',
					'before' => '',
					'after' => '',
					'class' => '',
					'exclude' => '',
					'orderby' => 'name',
					'order' => 'ASC',
					'depth' => 0,
					'childof' => 0,
					'parent' => false,
					'showall' => false,
					'linkall' => false,
					'linkcount' => false,
					'dropdown' => false,
					'hierarchy' => false,
					'products' => false,
					'wraplist' => true,
					'showsmart' => false
					);

				$options = array_merge($defaults,$options);
				extract($options, EXTR_SKIP);

				$this->load_categories(array("ancestry"=>true,"where"=>array("(pd.status='publish' OR pd.id IS NULL)"),"orderby"=>$orderby,"order"=>$order),$showsmart);

				$string = "";
				$depthlimit = $depth;
				$depth = 0;
				$exclude = explode(",",$exclude);
				$classes = ' class="ecart_categories'.(empty($class)?'':' '.$class).'"';
				$wraplist = value_is_true($wraplist);

				if (value_is_true($dropdown)) {
					if (!isset($default)) $default = __('Select category&hellip;','Ecart');
					$string .= $title;
					$string .= '<form><select name="ecart_cats" id="ecart-categories-menu"'.$classes.'>';
					$string .= '<option value="">'.$default.'</option>';
					foreach ($this->categories as &$category) {
						// If the parent of this category was excluded, add this to the excludes and skip
						if (!empty($category->parent) && in_array($category->parent,$exclude)) {
							$exclude[] = $category->id;
							continue;
						}
						if (!empty($category->id) && in_array($category->id,$exclude)) continue; // Skip excluded categories
						if ($category->total == 0 && !isset($category->smart) && !$category->_children) continue; // Only show categories with products
						if ($depthlimit && $category->depth >= $depthlimit) continue;

						if (value_is_true($hierarchy) && $category->depth > $depth) {
							$parent = &$previous;
							if (!isset($parent->path)) $parent->path = '/'.$parent->slug;
						}

						if (value_is_true($hierarchy))
							$padding = str_repeat("&nbsp;",$category->depth*3);

						$category_uri = empty($category->id)?$category->uri:$category->id;
						$link = ECART_PRETTYURLS?ecarturl("category/$category->uri"):ecarturl(array('ecart_category'=>$category_uri));

						$total = '';
						if (value_is_true($products) && $category->total > 0) $total = ' ('.$category->total.')';

						$string .= '<option value="'.$link.'">'.$padding.$category->name.$total.'</option>';
						$previous = &$category;
						$depth = $category->depth;

					}
					$string .= '</select></form>';

					$script = "$('#ecart-categories-menu').change(function (){";
					$script .= "document.location.href = $(this).val();";
					$script .= "});";
					add_storefrontjs($script);

				} else {
					$string .= $title;
					if ($wraplist) $string .= '<ul'.$classes.'>';
					foreach ($this->categories as &$category) {
						if (!isset($category->total)) $category->total = 0;
						if (!isset($category->depth)) $category->depth = 0;

						// If the parent of this category was excluded, add this to the excludes and skip
						if (!empty($category->parent) && in_array($category->parent,$exclude)) {
							$exclude[] = $category->id;
							continue;
						}

						if (!empty($category->id) && in_array($category->id,$exclude)) continue; // Skip excluded categories
						if ($depthlimit && $category->depth >= $depthlimit) continue;
						if (value_is_true($hierarchy) && $category->depth > $depth) {
							$parent = &$previous;
							if (!isset($parent->path)) $parent->path = $parent->slug;
							if (substr($string,-5,5) == "</li>") // Keep everything but the
								$string = substr($string,0,-5);  // last </li> to re-open the entry
							$active = '';

							if (isset($Ecart->Category->uri) && !empty($parent->slug)
									&& preg_match('/(^|\/)'.$parent->path.'(\/|$)/',$Ecart->Category->uri)) {
								$active = ' active';
							}

							$subcategories = '<ul class="children'.$active.'">';
							$string .= $subcategories;
						}

						if (value_is_true($hierarchy) && $category->depth < $depth) {
							for ($i = $depth; $i > $category->depth; $i--) {
								if (substr($string,strlen($subcategories)*-1) == $subcategories) {
									// If the child menu is empty, remove the <ul> to avoid breaking standards
									$string = substr($string,0,strlen($subcategories)*-1).'</li>';
								} else $string .= '</ul></li>';
							}
						}

						$category_uri = empty($category->id)?$category->uri:$category->id;
						$link = ECART_PRETTYURLS?ecarturl("category/$category->uri"):ecarturl(array('ecart_category'=>$category_uri));

						$total = '';
						if (value_is_true($products) && $category->total > 0) $total = ' <span>('.$category->total.')</span>';

						$current = '';
						if (isset($Ecart->Category->slug) && $Ecart->Category->slug == $category->slug)
							$current = ' class="current"';

						$listing = '';
						if ($category->total > 0 || isset($category->smart) || $linkall)
							$listing = '<a href="'.$link.'"'.$current.'>'.$category->name.($linkcount?$total:'').'</a>'.(!$linkcount?$total:'');
						else $listing = $category->name;

						if (value_is_true($showall) ||
							$category->total > 0 ||
							isset($category->smart) ||
							$category->_children)
							$string .= '<li'.$current.'>'.$listing.'</li>';

						$previous = &$category;
						$depth = $category->depth;
					}
					if (value_is_true($hierarchy) && $depth > 0)
						for ($i = $depth; $i > 0; $i--) {
							if (substr($string,strlen($subcategories)*-1) == $subcategories) {
								// If the child menu is empty, remove the <ul> to avoid breaking standards
								$string = substr($string,0,strlen($subcategories)*-1).'</li>';
							} else $string .= '</ul></li>';
						}
					if ($wraplist) $string .= '</ul>';
				}
				return $string;
				break;
			case "views":
				if (isset($Ecart->Category->controls)) return false;
				$string = "";
				$string .= '<ul class="views">';
				if (isset($options['label'])) $string .= '<li>'.$options['label'].'</li>';
				$string .= '<li><button type="button" class="grid"></button></li>';
				$string .= '<li><button type="button" class="list"></button></li>';
				$string .= '</ul>';
				return $string;
			case "orderby-list":
				if (isset($Ecart->Category->controls)) return false;
				if (isset($Ecart->Category->loading['order']) || isset($Ecart->Category->loading['orderby'])) return false;

				$menuoptions = Category::sortoptions();
				// Don't show custom product order for smart categories
				if (isset($Ecart->Category->smart)) unset($menuoptions['custom']);

				$title = "";
				$string = "";
				$dropdown = isset($options['dropdown'])?$options['dropdown']:true;
				$default = $Ecart->Settings->get('default_product_order');
				if (empty($default)) $default = "title";

				if (isset($options['default'])) $default = $options['default'];
				if (isset($options['title'])) $title = $options['title'];

				if (value_is_true($dropdown)) {
					if (isset($Ecart->Flow->Controller->browsing['orderby']))
						$default = $Ecart->Flow->Controller->browsing['orderby'];
					$string .= $title;
					$string .= '<form action="'.esc_url($_SERVER['REQUEST_URI']).'" method="get" id="ecart-'.$Ecart->Category->slug.'-orderby-menu">';
					if (!ECART_PRETTYURLS) {
						foreach ($_GET as $key => $value)
							if ($key != 'ecart_orderby') $string .= '<input type="hidden" name="'.$key.'" value="'.$value.'" />';
					}
					$string .= '<select name="ecart_orderby" class="ecart-orderby-menu">';
					$string .= menuoptions($menuoptions,$default,true);
					$string .= '</select>';
					$string .= '</form>';
				} else {
					$link = "";
					$query = "";
					if (strpos($_SERVER['REQUEST_URI'],"?") !== false)
						list($link,$query) = explode("\?",$_SERVER['REQUEST_URI']);
					$query = $_GET;
					unset($query['ecart_orderby']);
 					$query = http_build_query($query);
					if (!empty($query)) $query .= '&';

					foreach($menuoptions as $value => $option) {
						$label = $option;
						$href = esc_url($link.'?'.$query.'ecart_orderby='.$value);
						$string .= '<li><a href="'.$href.'">'.$label.'</a></li>';
					}

				}
				return $string;
				break;
			case "breadcrumb":

				$defaults = array(
					'separator' => '&nbsp;&raquo; ',
					'depth'		=> 7
				);
				$options = array_merge($defaults,$options);
				extract($options);

				if (isset($Ecart->Category->controls)) return false;
				if (empty($this->categories)) $this->load_categories(array('outofstock' => true));

				$category = false;
				if (isset($Ecart->Flow->Controller->breadcrumb))
					$category = $Ecart->Flow->Controller->breadcrumb;

				$trail = false;
				$search = array();
				if (isset($Ecart->Flow->Controller->search)) $search = array('search'=>$Ecart->Flow->Controller->search);
				$path = explode("/",$category);
				if ($path[0] == "tag") {
					$category = "tag";
					$search = array('tag'=>urldecode($path[1]));
				}
				$Category = Catalog::load_category($category,$search);

				if (!empty($Category->uri)) {
					$type = "category";
					if (isset($Category->tag)) $type = "tag";

					$category_uri = isset($Category->smart)?$Category->slug:$Category->id;

					$link = ECART_PRETTYURLS?
						ecarturl("$type/$Category->uri") :
						ecarturl(array_merge($_GET,array('ecart_category'=>$category_uri,'ecart_pid'=>null)));

					$filters = false;
					if (!empty($Ecart->Cart->data->Category[$Category->slug]))
						$filters = ' (<a href="?ecart_catfilters=cancel">'.__('Clear Filters','Ecart').'</a>)';

					if (!empty($Ecart->Product))
						$trail .= '<li><a href="'.$link.'">'.$Category->name.(!$trail?'':$separator).'</a></li>';
					elseif (!empty($Category->name))
						$trail .= '<li>'.$Category->name.$filters.(!$trail?'':$separator).'</li>';

					// Build category names path by going from the target category up the parent chain
					$parentkey = (!empty($Category->id)
						&& isset($this->categories['_'.$Category->id]->parent)?
							'_'.$this->categories['_'.$Category->id]->parent:'_0');

					while ($parentkey != '_0' && $depth-- > 0) {
						$tree_category = $this->categories[$parentkey];

						$link = ECART_PRETTYURLS?
							ecarturl("category/$tree_category->uri"):
							ecarturl(array_merge($_GET,array('ecart_category'=>$tree_category->id,'ecart_pid'=>null)));

						$trail = '<li><a href="'.$link.'">'.$tree_category->name.'</a>'.
							(empty($trail)?'':$separator).'</li>'.$trail;

						$parentkey = '_'.$tree_category->parent;
					}
				}
				$pages = $Ecart->Settings->get('pages');

				$trail = '<li><a href="'.ecarturl().'">'.$pages['catalog']['title'].'</a>'.(empty($trail)?'':$separator).'</li>'.$trail;
				return '<ul class="breadcrumb">'.$trail.'</ul>';
				break;
			case "searchform":
				ob_start();
				get_search_form();
				$content = ob_get_contents();
				ob_end_clean();

				preg_match('/^(.*?<form[^>]*>)(.*?)(<\/form>.*?)$/is',$content,$_);
				list($all,$open,$content,$close) = $_;

				$markup = array(
					$open,
					$content,
					'<div><input type="hidden" name="catalog" value="true" /></div>',
					$close
				);

				return join('',$markup);
				break;
			case "search":
				global $wp;

				$defaults = array(
					'type' => 'hidden',
					'option' => 'ecart',
					'blog_option' => __('Search the blog','Ecart'),
					'shop_option' => __('Search the shop','Ecart'),
					'label_before' => '',
					'label_after' => '',
					'checked' => false
				);
				$options = array_merge($defaults,$options);
				extract($options);

				$searching = is_search(); // Flag when searching (the blog or ecart)
				$shopsearch = ($Storefront !== false && $Storefront->searching); // Flag when searching ecart

				$allowed = array("accesskey","alt","checked","class","disabled","format", "id",
					"minlength","maxlength","readonly","required","size","src","tabindex","title","value");

				$options['value'] = ($option == "ecart");

				// Reset the checked option
				unset($options['checked']);

				// If searching the blog, check the non-store search option
				if ($searching && !$shopsearch && $option != "ecart") $options['checked'] = "checked";

				// If searching the storefront, mark the store search option
				if ($shopsearch && $option == "ecart") $options['checked'] = "checked";

				// Override any other settings with the supplied default 'checked' option
				if (!$searching && $checked) $options['checked'] = $checked;

				switch ($type) {
					case "checkbox":
						$input =  '<input type="checkbox" name="catalog"'.inputattrs($options,$allowed).' />';
						break;
					case "radio":
						$input =  '<input type="radio" name="catalog"'.inputattrs($options,$allowed).' />';
						break;
					case "menu":
						$allowed = array("accesskey","alt","class","disabled","format", "id",
							"readonly","required","size","tabindex","title");

						$input = '<select name="catalog"'.inputattrs($options,$allowed).'>';
						$input .= '<option value="">'.$blog_option.'</option>';
						$input .= '<option value="1"'.($shopsearch || (!$searching && $option == 'ecart')?' selected="selected"':'').'>'.$shop_option.'</option>';
						$input .= '</select>';
						break;
					default:
						$allowed = array("alt","class","disabled","format","id","readonly","title","value");
						$input =  '<input type="hidden" name="catalog"'.inputattrs($options,$allowed).' />';
						break;
				}

				$before = (!empty($label_before))?'<label>'.$label_before:'<label>';
				$after = (!empty($label_after))?$label_after.'</label>':'</label>';
				return $before.$input.$after;
				break;
			case "zoom-options":
				$defaults = array(				// Colorbox 1.3.15
					'transition' => 'elastic',	// The transition type. Can be set to 'elastic', 'fade', or 'none'.
					'speed' => 350,				// Sets the speed of the fade and elastic transitions, in milliseconds.
					'href' => false,			// This can be used as an alternative anchor URL or to associate a URL for non-anchor elements such as images or form buttons. Example: $('h1').colorbox({href:'welcome.html'})
					'title' => false,			// This can be used as an anchor title alternative for ColorBox.
					'rel' => false,				// This can be used as an anchor rel alternative for ColorBox. This allows the user to group any combination of elements together for a gallery, or to override an existing rel so elements are not grouped together. Example: $('#example a').colorbox({rel:'group1'}) Note: The value can also be set to 'nofollow' to disable grouping.
					'width' => false,			// Set a fixed total width. This includes borders and buttons. Example: '100%', '500px', or 500
					'height' => false,			// Set a fixed total height. This includes borders and buttons. Example: '100%', '500px', or 500
					'innerWidth' => false,		// This is an alternative to 'width' used to set a fixed inner width. This excludes borders and buttons. Example: '50%', '500px', or 500
					'innerHeight' => false,		// This is an alternative to 'height' used to set a fixed inner height. This excludes borders and buttons. Example: '50%', '500px', or 500
					'initialWidth' => 300,		// Set the initial width, prior to any content being loaded.
					'initialHeight' => 100,		// Set the initial height, prior to any content being loaded.
					'maxWidth' => false,		// Set a maximum width for loaded content. Example: '100%', 500, '500px'
					'maxHeight' => false,		// Set a maximum height for loaded content. Example: '100%', 500, '500px'
					'scalePhotos' => true,		// If 'true' and if maxWidth, maxHeight, innerWidth, innerHeight, width, or height have been defined, ColorBox will scale photos to fit within the those values.
					'scrolling' => true,		// If 'false' ColorBox will hide scrollbars for overflowing content. This could be used on conjunction with the resize method (see below) for a smoother transition if you are appending content to an already open instance of ColorBox.
					'iframe' => false,			// If 'true' specifies that content should be displayed in an iFrame.
					'inline' => false,			// If 'true' a jQuery selector can be used to display content from the current page. Example:  $('#inline').colorbox({inline:true, href:'#myForm'});
					'html' => false,			// This allows an HTML string to be used directly instead of pulling content from another source (ajax, inline, or iframe). Example: $.colorbox({html:'<p>Hello</p>'});
					'photo' => false,			// If true, this setting forces ColorBox to display a link as a photo. Use this when automatic photo detection fails (such as using a url like 'photo.php' instead of 'photo.jpg', 'photo.jpg#1', or 'photo.jpg?pic=1')
					'opacity' => 0.85,			// The overlay opacity level. Range: 0 to 1.
					'open' => false,			// If true, the lightbox will automatically open with no input from the visitor.
					'returnFocus' => true,		// If true, focus will be returned when ColorBox exits to the element it was launched from.
					'preloading' => true,		// Allows for preloading of 'Next' and 'Previous' content in a shared relation group (same values for the 'rel' attribute), after the current content has finished loading. Set to 'false' to disable.
					'overlayClose' => true,		// If false, disables closing ColorBox by clicking on the background overlay.
					'escKey' => true, 			// If false, will disable closing colorbox on esc key press.
					'arrowKey' => true, 		// If false, will disable the left and right arrow keys from navigating between the items in a group.
					'loop' => true, 			// If false, will disable the ability to loop back to the beginning of the group when on the last element.
					'slideshow' => false, 		// If true, adds an automatic slideshow to a content group / gallery.
					'slideshowSpeed' => 2500, 	// Sets the speed of the slideshow, in milliseconds.
					'slideshowAuto' => true, 	// If true, the slideshow will automatically start to play.

					'slideshowStart' => __('start slideshow','Ecart'),	// Text for the slideshow start button.
					'slideshowStop' => __('stop slideshow','Ecart'),	// Text for the slideshow stop button
					'previous' => __('previous','Ecart'), 				// Text for the previous button in a shared relation group (same values for 'rel' attribute).
					'next' => __('next','Ecart'), 						// Text for the next button in a shared relation group (same values for 'rel' attribute).
					'close' => __('close','Ecart'),						// Text for the close button. The 'Esc' key will also close ColorBox.

					// Text format for the content group / gallery count. {current} and {total} are detected and replaced with actual numbers while ColorBox runs.
					'current' => sprintf(__('image %s of %s','Ecart'),'{current}','{total}'),

					'onOpen' => false,			// Callback that fires right before ColorBox begins to open.
					'onLoad' => false,			// Callback that fires right before attempting to load the target content.
					'onComplete' => false,		// Callback that fires right after loaded content is displayed.
					'onCleanup' => false,		// Callback that fires at the start of the close process.
					'onClosed' => false			// Callback that fires once ColorBox is closed.
				);
				$options = array_diff($options, $defaults);

				$js = 'var cbo = '.json_encode($options).';';
				add_storefrontjs($js,true);
				break;
			case "catalog-products":
				if ($property == "catalog-products") $Ecart->Category = new CatalogProducts($options);
			case "new-products":
				if ($property == "new-products") $Ecart->Category = new NewProducts($options);
			case "featured-products":
				if ($property == "featured-products") $Ecart->Category = new FeaturedProducts($options);
			case "onsale-products":
				if ($property == "onsale-products") $Ecart->Category = new OnSaleProducts($options);
			case "bestsellers-products":
				if ($property == "bestsellers-products") $Ecart->Category = new BestsellerProducts($options);
			case "bestseller-products":
				if ($property == "bestseller-products") $Ecart->Category = new BestsellerProducts($options);
			case "bestselling-products":
				if ($property == "bestselling-products") $Ecart->Category = new BestsellerProducts($options);
			case "random-products":
				if ($property == "random-products") $Ecart->Category = new RandomProducts($options);
			case "tag-products":
				if ($property == "tag-products") $Ecart->Category = new TagProducts($options);
			case "related-products":
				if ($property == "related-products") $Ecart->Category = new RelatedProducts($options);
			case "search-products":
				if ($property == "search-products") $Ecart->Category = new SearchResults($options);
			case "category":
				if ($property == "category") {
					if (isset($options['name'])) $Ecart->Category = new Category($options['name'],'name');
					else if (isset($options['slug'])) $Ecart->Category = new Category($options['slug'],'slug');
					else if (isset($options['id'])) $Ecart->Category = new Category($options['id']);
				}
				if (isset($options['reset']))
					return (get_class($Ecart->Requested) == "Category"?($Ecart->Category = $Ecart->Requested):false);
				if (isset($options['title'])) $Ecart->Category->name = $options['title'];
				if (isset($options['show'])) $Ecart->Category->loading['limit'] = $options['show'];
				if (isset($options['pagination'])) $Ecart->Category->loading['pagination'] = $options['pagination'];
				if (isset($options['order'])) $Ecart->Category->loading['order'] = $options['order'];

				if (isset($options['load'])) return true;
				if (isset($options['controls']) && !value_is_true($options['controls']))
					$Ecart->Category->controls = false;
				if (isset($options['view'])) {
					if ($options['view'] == "grid") $Ecart->Category->view = "grid";
					else $Ecart->Category->view = "list";
				}
				ob_start();
				if (isset($Ecart->Category->slug) &&
						file_exists(ECART_TEMPLATES."/category-{$Ecart->Category->slug}.php"))
					include(ECART_TEMPLATES."/category-{$Ecart->Category->slug}.php");
				elseif (isset($Ecart->Category->id) &&
					file_exists(ECART_TEMPLATES."/category-{$Ecart->Category->id}.php"))
					include(ECART_TEMPLATES."/category-{$Ecart->Category->id}.php");
				else include(ECART_TEMPLATES."/category.php");
				$content = ob_get_contents();
				ob_end_clean();
				$Ecart->Category = false; // Reset the current category

				if (isset($options['wrap']) && value_is_true($options['wrap'])) $content = ecartdiv($content);
				return $content;
				break;
			case "product":
				if (isset($options['name'])) $Ecart->Product = new Product($options['name'],'name');
				else if (isset($options['slug'])) $Ecart->Product = new Product($options['slug'],'slug');
				else if (isset($options['id'])) $Ecart->Product = new Product($options['id']);

				if (isset($options['reset']))
					return (get_class($Ecart->Requested) == "Product"?($Ecart->Product = $Ecart->Requested):false);

				if (isset($Ecart->Product->id) && isset($Ecart->Category->slug)) {
					$Category = clone($Ecart->Category);

					if (isset($options['load'])) {
						if ($options['load'] == "next") $Ecart->Product = $Category->adjacent_product(1);
						elseif ($options['load'] == "previous") $Ecart->Product = $Category->adjacent_product(-1);
					} else {
						if (isset($options['next']) && value_is_true($options['next']))
							$Ecart->Product = $Category->adjacent_product(1);
						elseif (isset($options['previous']) && value_is_true($options['previous']))
							$Ecart->Product = $Category->adjacent_product(-1);
					}
				}

				if (isset($options['load'])) return true;
				ob_start();
				if (file_exists(ECART_TEMPLATES."/product-{$Ecart->Product->id}.php"))
					include(ECART_TEMPLATES."/product-{$Ecart->Product->id}.php");
				else include(ECART_TEMPLATES."/product.php");
				$content = ob_get_contents();
				ob_end_clean();
				return $content;
				break;
			case "sideproduct":
				$content = false;
				$source = isset($options['source'])?$options['source']:'product';
				if ($source == "product" && isset($options['product'])) {
					 // Save original requested product
					if ($Ecart->Product) $Requested = $Ecart->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))
							$Ecart->Product = new Product($product);
						else $Ecart->Product = new Product($product,'slug');

						if (empty($Ecart->Product->id)) continue;
						if (isset($options['load'])) return true;
						ob_start();
						if (file_exists(ECART_TEMPLATES."/sideproduct-{$Ecart->Product->id}.php"))
							include(ECART_TEMPLATES."/sideproduct-{$Ecart->Product->id}.php");
						else include(ECART_TEMPLATES."/sideproduct.php");
						$content .= ob_get_contents();
						ob_end_clean();
					}
					 // Restore original requested Product
					if (!empty($Requested)) $Ecart->Product = $Requested;
					else $Ecart->Product = false;
				}

				if ($source == "category" && isset($options['category'])) {
					 // Save original requested category
					if ($Ecart->Category) $Requested = $Ecart->Category;
					if ($Ecart->Product) $RequestedProduct = $Ecart->Product;
					if (empty($options['category'])) return false;
					$Ecart->Category = Catalog::load_category($options['category']);
					$Ecart->Category->load_products($options);
					if (isset($options['load'])) return true;
					foreach ($Ecart->Category->products as $product) {
						$Ecart->Product = $product;
						ob_start();
						if (file_exists(ECART_TEMPLATES."/sideproduct-{$Ecart->Product->id}.php"))
							include(ECART_TEMPLATES."/sideproduct-{$Ecart->Product->id}.php");
						else include(ECART_TEMPLATES."/sideproduct.php");
						$content .= ob_get_contents();
						ob_end_clean();
					}
					 // Restore original requested category
					if (!empty($Requested)) $Ecart->Category = $Requested;
					else $Ecart->Category = false;
					if (!empty($RequestedProduct)) $Ecart->Product = $RequestedProduct;
					else $Ecart->Product = false;
				}

				return $content;
				break;
		}
	}
Example #18
0
	/**
	 * Provides support for the ecart('cartitem') tags
	 * 
	 * @since 1.1
	 *
	 * @return mixed
	 **/
	function tag ($id,$property,$options=array()) {
		global $Ecart;

		// Return strings with no options
		switch ($property) {
			case "id": return $id;
			case "product": return $this->product;
			case "name": return $this->name;
			case "type": return $this->type;
			case "link":
			case "url":
				return ecarturl(ECART_PRETTYURLS?$this->slug:array('ecart_pid'=>$this->product));
			case "sku": return $this->sku;
		}

		$taxes = isset($options['taxes'])?value_is_true($options['taxes']):null;
		if (in_array($property,array('price','newprice','unitprice','total','tax','options')))
			$taxes = ecart_taxrate($taxes,$this->taxable,$this) > 0?true:false;

		// Handle currency values
		$result = "";
		switch ($property) {
			case "discount": $result = (float)$this->discount; break;
			case "unitprice": $result = (float)$this->unitprice+($taxes?$this->unittax:0); break;
			case "unittax": $result = (float)$this->unittax; break;
			case "discounts": $result = (float)$this->discounts; break;
			case "tax": $result = (float)$this->tax; break;
			case "total": $result = (float)$this->total+($taxes?($this->unittax*$this->quantity):0); break;
		}
		if (is_float($result)) {
			if (isset($options['currency']) && !value_is_true($options['currency'])) return $result;
			else return money($result);
		}

		// Handle values with complex options
		switch ($property) {
			case "taxrate": return percentage($this->taxrate*100,array('precision' => 1)); break;
			case "quantity":
				$result = $this->quantity;
				if ($this->type == "Donation" && $this->donation['var'] == "on") return $result;
				if (isset($options['input']) && $options['input'] == "menu") {
					if (!isset($options['value'])) $options['value'] = $this->quantity;
					if (!isset($options['options']))
						$values = "1-15,20,25,30,35,40,45,50,60,70,80,90,100";
					else $values = $options['options'];

					if (strpos($values,",") !== false) $values = explode(",",$values);
					else $values = array($values);
					$qtys = array();
					foreach ($values as $value) {
						if (strpos($value,"-") !== false) {
							$value = explode("-",$value);
							if ($value[0] >= $value[1]) $qtys[] = $value[0];
							else for ($i = $value[0]; $i < $value[1]+1; $i++) $qtys[] = $i;
						} else $qtys[] = $value;
					}
					$result = '<select name="items['.$id.']['.$property.']">';
					foreach ($qtys as $qty)
						$result .= '<option'.(($qty == $this->quantity)?' selected="selected"':'').' value="'.$qty.'">'.$qty.'</option>';
					$result .= '</select>';
				} elseif (isset($options['input']) && valid_input($options['input'])) {
					if (!isset($options['size'])) $options['size'] = 5;
					if (!isset($options['value'])) $options['value'] = $this->quantity;
					$result = '<input type="'.$options['input'].'" name="items['.$id.']['.$property.']" id="items-'.$id.'-'.$property.'" '.inputattrs($options).'/>';
				} else $result = $this->quantity;
				break;
			case "remove":
				$label = __("Remove");
				if (isset($options['label'])) $label = $options['label'];
				if (isset($options['class'])) $class = ' class="'.$options['class'].'"';
				else $class = ' class="remove"';
				if (isset($options['input'])) {
					switch ($options['input']) {
						case "button":
							$result = '<button type="submit" name="remove['.$id.']" value="'.$id.'"'.$class.' tabindex="">'.$label.'</button>'; break;
						case "checkbox":
						    $result = '<input type="checkbox" name="remove['.$id.']" value="'.$id.'"'.$class.' tabindex="" title="'.$label.'"/>'; break;
					}
				} else {
					$result = '<a href="'.href_add_query_arg(array('cart'=>'update','item'=>$id,'quantity'=>0),ecarturl(false,'cart')).'"'.$class.'>'.$label.'</a>';
				}
				break;
			case "optionlabel": $result = $this->option->label; break;
			case "options":
				$class = "";
				if (!isset($options['before'])) $options['before'] = '';
				if (!isset($options['after'])) $options['after'] = '';
				if (isset($options['show']) &&
					strtolower($options['show']) == "selected")
					return (!empty($this->option->label))?
						$options['before'].$this->option->label.$options['after']:'';

				if (isset($options['class'])) $class = ' class="'.$options['class'].'" ';
				if (count($this->variations) > 1) {
					$result .= $options['before'];
					$result .= '<input type="hidden" name="items['.$id.'][product]" value="'.$this->product.'"/>';
					$result .= ' <select name="items['.$id.'][price]" id="items-'.$id.'-price"'.$class.'>';
					$result .= $this->options($this->priceline);
					$result .= '</select>';
					$result .= $options['after'];
				}
				break;
			case "addons-list":
			case "addonslist":
				if (empty($this->addons)) return false;
				$defaults = array(
					'before' => '',
					'after' => '',
					'class' => '',
					'exclude' => '',
					'prices' => true,

				);
				$options = array_merge($defaults,$options);
				extract($options);

				$classes = !empty($class)?' class="'.join(' ',$class).'"':'';
				$excludes = explode(',',$exclude);
				$prices = value_is_true($prices);

				$result .= $before.'<ul'.$classes.'>';
				foreach ($this->addons as $id => $addon) {
					if (in_array($addon->label,$excludes)) continue;

					$price = ($addon->onsale?$addon->promoprice:$addon->price);
					if ($this->taxrate > 0) $price = $price+($price*$this->taxrate);

					if ($prices) $pricing = " (".($addon->unitprice < 0?'-':'+').money($price).")";
					$result .= '<li>'.$addon->label.$pricing.'</li>';
				}
				$result .= '</ul>'.$after;
				return $result;
				break;
			case "hasinputs":
			case "has-inputs": return (count($this->data) > 0); break;
			case "inputs":
				if (!isset($this->_data_loop)) {
					reset($this->data);
					$this->_data_loop = true;
				} else next($this->data);

				if (current($this->data) !== false) return true;
				else {
					unset($this->_data_loop);
					reset($this->data);
					return false;
				}
				break;
			case "input":
				$data = current($this->data);
				$name = key($this->data);
				if (isset($options['name'])) return $name;
				return $data;
				break;
			case "inputs-list":
			case "inputslist":
				if (empty($this->data)) return false;
				$before = ""; $after = ""; $classes = ""; $excludes = array();
				if (!empty($options['class'])) $classes = ' class="'.$options['class'].'"';
				if (!empty($options['exclude'])) $excludes = explode(",",$options['exclude']);
				if (!empty($options['before'])) $before = $options['before'];
				if (!empty($options['after'])) $after = $options['after'];

				$result .= $before.'<ul'.$classes.'>';
				foreach ($this->data as $name => $data) {
					if (in_array($name,$excludes)) continue;
					$result .= '<li><strong>'.$name.'</strong>: '.$data.'</li>';
				}
				$result .= '</ul>'.$after;
				return $result;
				break;
			case "coverimage":
			case "thumbnail":
				$defaults = array(
					'class' => '',
					'width' => 48,
					'height' => 48,
					'size' => false,
					'fit' => false,
					'sharpen' => false,
					'quality' => false,
					'bg' => false,
					'alt' => false,
					'title' => false
				);

				$options = array_merge($defaults,$options);
				extract($options);

				if ($this->image !== false) {
					$img = $this->image;

					if ($size !== false) $width = $height = $size;
					$scale = (!$fit)?false:esc_attr(array_search($fit,$img->_scaling));
					$sharpen = (!$sharpen)?false:esc_attr(min($sharpen,$img->_sharpen));
					$quality = (!$quality)?false:esc_attr(min($quality,$img->_quality));
					$fill = (!$bg)?false:esc_attr(hexdec(ltrim($bg,'#')));
					$scaled = $img->scaled($width,$height,$scale);

					$alt = empty($alt)?$img->alt:$alt;
					$title = empty($title)?$img->title:$title;
					$title = empty($title)?'':' title="'.esc_attr($title).'"';
					$class = !empty($class)?' class="'.esc_attr($class).'"':'';

					if (!empty($options['title'])) $title = ' title="'.esc_attr($options['title']).'"';
					$alt = esc_attr(!empty($img->alt)?$img->alt:$this->name);
					return '<img src="'.add_query_string($img->resizing($width,$height,$scale,$sharpen,$quality,$fill),ecarturl($img->id,'images')).'"'.$title.' alt="'.$alt.'" width="'.$scaled['width'].'" height="'.$scaled['height'].'"'.$class.' />';
				}
				break;

		}
		if (!empty($result)) return $result;

		return false;
	}
 function checkouttag($property, $options = array())
 {
     global $Shopp, $wp;
     $gateway = $Shopp->Settings->get('payment_gateway');
     $xcos = $Shopp->Settings->get('xco_gateways');
     $pages = $Shopp->Settings->get('pages');
     $base = $Shopp->Settings->get('base_operations');
     $countries = $Shopp->Settings->get('target_markets');
     $process = get_query_var('shopp_proc');
     $xco = get_query_var('shopp_xco');
     $select_attrs = array('title', 'required', 'class', 'disabled', 'required', 'size', 'tabindex', 'accesskey');
     $submit_attrs = array('title', 'class', 'value', 'disabled', 'tabindex', 'accesskey');
     if (!isset($options['mode'])) {
         $options['mode'] = "input";
     }
     switch ($property) {
         case "url":
             $ssl = true;
             // Test Mode will not require encrypted checkout
             if (strpos($gateway, "TestMode.php") !== false || isset($_GET['shopp_xco']) || $this->orderisfree() || SHOPP_NOSSL) {
                 $ssl = false;
             }
             $link = $Shopp->link('checkout', $ssl);
             // Pass any arguments along
             $args = $_GET;
             if (isset($args['page_id'])) {
                 unset($args['page_id']);
             }
             $link = esc_url(add_query_arg($args, $link));
             if ($process == "confirm-order") {
                 $link = apply_filters('shopp_confirm_url', $link);
             } else {
                 $link = apply_filters('shopp_checkout_url', $link);
             }
             return $link;
             break;
         case "function":
             if (!isset($options['shipcalc'])) {
                 $options['shipcalc'] = '<img src="' . SHOPP_PLUGINURI . '/core/ui/icons/updating.gif" width="16" height="16" />';
             }
             $regions = $Shopp->Settings->get('zones');
             $base = $Shopp->Settings->get('base_operations');
             $output = '<script type="text/javascript">' . "\n";
             $output .= '//<![CDATA[' . "\n";
             $output .= 'var currencyFormat = ' . json_encode($base['currency']['format']) . ';' . "\n";
             $output .= 'var regions = ' . json_encode($regions) . ';' . "\n";
             $output .= 'var SHIPCALC_STATUS = \'' . $options['shipcalc'] . '\'';
             $output .= '//]]>' . "\n";
             $output .= '</script>' . "\n";
             if (!empty($options['value'])) {
                 $value = $options['value'];
             } else {
                 $value = "process";
             }
             $output .= '<div><input type="hidden" name="checkout" value="' . $value . '" /></div>';
             if ($value == "confirmed") {
                 $output = apply_filters('shopp_confirm_form', $output);
             } else {
                 $output = apply_filters('shopp_checkout_form', $output);
             }
             return $output;
             break;
         case "error":
             $result = "";
             if (!$this->data->Errors->exist(SHOPP_COMM_ERR)) {
                 return false;
             }
             $errors = $this->data->Errors->get(SHOPP_COMM_ERR);
             foreach ((array) $errors as $error) {
                 if (!empty($error)) {
                     $result .= $error->message();
                 }
             }
             return $result;
             // if (isset($options['show']) && $options['show'] == "code") return $this->data->OrderError->code;
             // return $this->data->OrderError->message;
             break;
         case "cart-summary":
             ob_start();
             include SHOPP_TEMPLATES . "/summary.php";
             $content = ob_get_contents();
             ob_end_clean();
             return $content;
             break;
         case "loggedin":
             return $this->data->login;
             break;
         case "notloggedin":
             return !$this->data->login && $Shopp->Settings->get('account_system') != "none";
             break;
         case "email-login":
             // Deprecating
         // Deprecating
         case "loginname-login":
             // Deprecating
         // Deprecating
         case "account-login":
             if (!empty($_POST['account-login'])) {
                 $options['value'] = $_POST['account-login'];
             }
             return '<input type="text" name="account-login" id="account-login"' . inputattrs($options) . ' />';
             break;
         case "password-login":
             if (!empty($_POST['password-login'])) {
                 $options['value'] = $_POST['password-login'];
             }
             return '<input type="password" name="password-login" id="password-login" ' . inputattrs($options) . ' />';
             break;
         case "submit-login":
             // Deprecating
         // Deprecating
         case "login-button":
             $string = '<input type="hidden" name="process-login" id="process-login" value="false" />';
             $string .= '<input type="submit" name="submit-login" id="submit-login" ' . inputattrs($options) . ' />';
             return $string;
             break;
         case "firstname":
             if ($options['mode'] == "value") {
                 return $this->data->Order->Customer->firstname;
             }
             if (!empty($this->data->Order->Customer->firstname)) {
                 $options['value'] = $this->data->Order->Customer->firstname;
             }
             return '<input type="text" name="firstname" id="firstname" ' . inputattrs($options) . ' />';
             break;
         case "lastname":
             if ($options['mode'] == "value") {
                 return $this->data->Order->Customer->lastname;
             }
             if (!empty($this->data->Order->Customer->lastname)) {
                 $options['value'] = $this->data->Order->Customer->lastname;
             }
             return '<input type="text" name="lastname" id="lastname" ' . inputattrs($options) . ' />';
             break;
         case "email":
             if ($options['mode'] == "value") {
                 return $this->data->Order->Customer->email;
             }
             if (!empty($this->data->Order->Customer->email)) {
                 $options['value'] = $this->data->Order->Customer->email;
             }
             return '<input type="text" name="email" id="email" ' . inputattrs($options) . ' />';
             break;
         case "loginname":
             if ($options['mode'] == "value") {
                 return $this->data->Order->Customer->login;
             }
             if (!empty($this->data->Order->Customer->login)) {
                 $options['value'] = $this->data->Order->Customer->login;
             }
             return '<input type="text" name="login" id="login" ' . inputattrs($options) . ' />';
             break;
         case "password":
             if ($options['mode'] == "value") {
                 return $this->data->Order->Customer->password;
             }
             if (!empty($this->data->Order->Customer->password)) {
                 $options['value'] = $this->data->Order->Customer->password;
             }
             return '<input type="password" name="password" id="password" ' . inputattrs($options) . ' />';
             break;
         case "confirm-password":
             if (!empty($this->data->Order->Customer->confirm_password)) {
                 $options['value'] = $this->data->Order->Customer->confirm_password;
             }
             return '<input type="password" name="confirm-password" id="confirm-password" ' . inputattrs($options) . ' />';
             break;
         case "phone":
             if ($options['mode'] == "value") {
                 return $this->data->Order->Customer->phone;
             }
             if (!empty($this->data->Order->Customer->phone)) {
                 $options['value'] = $this->data->Order->Customer->phone;
             }
             return '<input type="text" name="phone" id="phone" ' . inputattrs($options) . ' />';
             break;
         case "organization":
         case "company":
             if ($options['mode'] == "value") {
                 return $this->data->Order->Customer->company;
             }
             if (!empty($this->data->Order->Customer->company)) {
                 $options['value'] = $this->data->Order->Customer->company;
             }
             return '<input type="text" name="company" id="company" ' . inputattrs($options) . ' />';
             break;
         case "customer-info":
             $allowed_types = array("text", "password", "hidden", "checkbox", "radio");
             if (empty($options['type'])) {
                 $options['type'] = "hidden";
             }
             if (isset($options['name']) && $options['mode'] == "value") {
                 return $this->data->Order->Customer->info[$options['name']];
             }
             if (isset($options['name']) && in_array($options['type'], $allowed_types)) {
                 if (isset($this->data->Order->Customer->info[$options['name']])) {
                     $options['value'] = $this->data->Order->Customer->info[$options['name']];
                 }
                 return '<input type="text" name="info[' . $options['name'] . ']" id="customer-info-' . $options['name'] . '" ' . inputattrs($options) . ' />';
             }
             break;
             // SHIPPING TAGS
         // SHIPPING TAGS
         case "shipping":
             return $this->data->Shipping;
         case "shipping-address":
             if ($options['mode'] == "value") {
                 return $this->data->Order->Shipping->address;
             }
             if (!empty($this->data->Order->Shipping->address)) {
                 $options['value'] = $this->data->Order->Shipping->address;
             }
             return '<input type="text" name="shipping[address]" id="shipping-address" ' . inputattrs($options) . ' />';
             break;
         case "shipping-xaddress":
             if ($options['mode'] == "value") {
                 return $this->data->Order->Shipping->xaddress;
             }
             if (!empty($this->data->Order->Shipping->xaddress)) {
                 $options['value'] = $this->data->Order->Shipping->xaddress;
             }
             return '<input type="text" name="shipping[xaddress]" id="shipping-xaddress" ' . inputattrs($options) . ' />';
             break;
         case "shipping-city":
             if ($options['mode'] == "value") {
                 return $this->data->Order->Shipping->city;
             }
             if (!empty($this->data->Order->Shipping->city)) {
                 $options['value'] = $this->data->Order->Shipping->city;
             }
             return '<input type="text" name="shipping[city]" id="shipping-city" ' . inputattrs($options) . ' />';
             break;
         case "shipping-province":
         case "shipping-state":
             if ($options['mode'] == "value") {
                 return $this->data->Order->Shipping->state;
             }
             if (!isset($options['selected'])) {
                 $options['selected'] = false;
             }
             if (!empty($this->data->Order->Shipping->state)) {
                 $options['selected'] = $this->data->Order->Shipping->state;
                 $options['value'] = $this->data->Order->Shipping->state;
             }
             $country = $base['country'];
             if (!empty($this->data->Order->Shipping->country)) {
                 $country = $this->data->Order->Shipping->country;
             }
             if (!array_key_exists($country, $countries)) {
                 $country = key($countries);
             }
             if (empty($options['type'])) {
                 $options['type'] = "menu";
             }
             $regions = $Shopp->Settings->get('zones');
             $states = $regions[$country];
             if (is_array($states) && $options['type'] == "menu") {
                 $label = !empty($options['label']) ? $options['label'] : '';
                 $output = '<select name="shipping[state]" id="shipping-state" ' . inputattrs($options, $select_attrs) . '>';
                 $output .= '<option value="" selected="selected">' . $label . '</option>';
                 $output .= menuoptions($states, $options['selected'], true);
                 $output .= '</select>';
             } else {
                 $output .= '<input type="text" name="shipping[state]" id="shipping-state" ' . inputattrs($options) . '/>';
             }
             return $output;
             break;
         case "shipping-postcode":
             if ($options['mode'] == "value") {
                 return $this->data->Order->Shipping->postcode;
             }
             if (!empty($this->data->Order->Shipping->postcode)) {
                 $options['value'] = $this->data->Order->Shipping->postcode;
             }
             return '<input type="text" name="shipping[postcode]" id="shipping-postcode" ' . inputattrs($options) . ' />';
             break;
         case "shipping-country":
             if ($options['mode'] == "value") {
                 return $this->data->Order->Shipping->country;
             }
             if (!empty($this->data->Order->Shipping->country)) {
                 $options['selected'] = $this->data->Order->Shipping->country;
             } else {
                 if (empty($options['selected'])) {
                     $options['selected'] = $base['country'];
                 }
             }
             $output = '<select name="shipping[country]" id="shipping-country" ' . inputattrs($options, $select_attrs) . '>';
             $output .= menuoptions($countries, $options['selected'], true);
             $output .= '</select>';
             return $output;
             break;
         case "same-shipping-address":
             $label = __("Same shipping address", "Shopp");
             if (isset($options['label'])) {
                 $label = $options['label'];
             }
             $checked = ' checked="checked"';
             if (isset($options['checked']) && !value_is_true($options['checked'])) {
                 $checked = '';
             }
             $output = '<label for="same-shipping"><input type="checkbox" name="sameshipaddress" value="on" id="same-shipping" ' . $checked . ' /> ' . $label . '</label>';
             return $output;
             break;
             // BILLING TAGS
         // BILLING TAGS
         case "billing-required":
             if ($this->data->Totals->total == 0) {
                 return false;
             }
             if (isset($_GET['shopp_xco'])) {
                 $xco = join(DIRECTORY_SEPARATOR, array($Shopp->path, 'gateways', $_GET['shopp_xco'] . ".php"));
                 if (file_exists($xco)) {
                     $meta = $Shopp->Flow->scan_gateway_meta($xco);
                     $PaymentSettings = $Shopp->Settings->get($meta->tags['class']);
                     return $PaymentSettings['billing-required'] != "off";
                 }
             }
             return $this->data->Totals->total > 0;
             break;
         case "billing-address":
             if ($options['mode'] == "value") {
                 return $this->data->Order->Billing->address;
             }
             if (!empty($this->data->Order->Billing->address)) {
                 $options['value'] = $this->data->Order->Billing->address;
             }
             return '<input type="text" name="billing[address]" id="billing-address" ' . inputattrs($options) . ' />';
             break;
         case "billing-xaddress":
             if ($options['mode'] == "value") {
                 return $this->data->Order->Billing->xaddress;
             }
             if (!empty($this->data->Order->Billing->xaddress)) {
                 $options['value'] = $this->data->Order->Billing->xaddress;
             }
             return '<input type="text" name="billing[xaddress]" id="billing-xaddress" ' . inputattrs($options) . ' />';
             break;
         case "billing-city":
             if (!empty($this->data->Order->Billing->city)) {
                 $options['value'] = $this->data->Order->Billing->city;
             }
             return '<input type="text" name="billing[city]" id="billing-city" ' . inputattrs($options) . ' />';
             break;
         case "billing-province":
         case "billing-state":
             if ($options['mode'] == "value") {
                 return $this->data->Order->Billing->state;
             }
             if (!isset($options['selected'])) {
                 $options['selected'] = false;
             }
             if (!empty($this->data->Order->Billing->state)) {
                 $options['selected'] = $this->data->Order->Billing->state;
                 $options['value'] = $this->data->Order->Billing->state;
             }
             if (empty($options['type'])) {
                 $options['type'] = "menu";
             }
             $country = $base['country'];
             if (!empty($this->data->Order->Billing->country)) {
                 $country = $this->data->Order->Billing->country;
             }
             if (!array_key_exists($country, $countries)) {
                 $country = key($countries);
             }
             $regions = $Shopp->Settings->get('zones');
             $states = $regions[$country];
             if (is_array($states) && $options['type'] == "menu") {
                 $label = !empty($options['label']) ? $options['label'] : '';
                 $output = '<select name="billing[state]" id="billing-state" ' . inputattrs($options, $select_attrs) . '>';
                 $output .= '<option value="" selected="selected">' . $label . '</option>';
                 $output .= menuoptions($states, $options['selected'], true);
                 $output .= '</select>';
             } else {
                 $output .= '<input type="text" name="billing[state]" id="billing-state" ' . inputattrs($options) . '/>';
             }
             return $output;
             break;
         case "billing-postcode":
             if ($options['mode'] == "value") {
                 return $this->data->Order->Billing->postcode;
             }
             if (!empty($this->data->Order->Billing->postcode)) {
                 $options['value'] = $this->data->Order->Billing->postcode;
             }
             return '<input type="text" name="billing[postcode]" id="billing-postcode" ' . inputattrs($options) . ' />';
             break;
         case "billing-country":
             if ($options['mode'] == "value") {
                 return $this->data->Order->Billing->country;
             }
             if (!empty($this->data->Order->Billing->country)) {
                 $options['selected'] = $this->data->Order->Billing->country;
             } else {
                 if (empty($options['selected'])) {
                     $options['selected'] = $base['country'];
                 }
             }
             $output = '<select name="billing[country]" id="billing-country" ' . inputattrs($options, $select_attrs) . '>';
             $output .= menuoptions($countries, $options['selected'], true);
             $output .= '</select>';
             return $output;
             break;
         case "billing-card":
             if ($options['mode'] == "value") {
                 return str_repeat('X', strlen($this->data->Order->Billing->card) - 4) . substr($this->data->Order->Billing->card, -4);
             }
             if (!empty($this->data->Order->Billing->card)) {
                 $options['value'] = $this->data->Order->Billing->card;
                 $this->data->Order->Billing->card = "";
             }
             return '<input type="text" name="billing[card]" id="billing-card" ' . inputattrs($options) . ' />';
             break;
         case "billing-cardexpires-mm":
             if ($options['mode'] == "value") {
                 return date("m", $this->data->Order->Billing->cardexpires);
             }
             if (!empty($this->data->Order->Billing->cardexpires)) {
                 $options['value'] = date("m", $this->data->Order->Billing->cardexpires);
             }
             return '<input type="text" name="billing[cardexpires-mm]" id="billing-cardexpires-mm" ' . inputattrs($options) . ' />';
             break;
         case "billing-cardexpires-yy":
             if ($options['mode'] == "value") {
                 return date("y", $this->data->Order->Billing->cardexpires);
             }
             if (!empty($this->data->Order->Billing->cardexpires)) {
                 $options['value'] = date("y", $this->data->Order->Billing->cardexpires);
             }
             return '<input type="text" name="billing[cardexpires-yy]" id="billing-cardexpires-yy" ' . inputattrs($options) . ' />';
             break;
         case "billing-cardtype":
             if ($options['mode'] == "value") {
                 return $this->data->Order->Billing->cardtype;
             }
             if (!isset($options['selected'])) {
                 $options['selected'] = false;
             }
             if (!empty($this->data->Order->Billing->cardtype)) {
                 $options['selected'] = $this->data->Order->Billing->cardtype;
             }
             $cards = $Shopp->Settings->get('gateway_cardtypes');
             $label = !empty($options['label']) ? $options['label'] : '';
             $output = '<select name="billing[cardtype]" id="billing-cardtype" ' . inputattrs($options, $select_attrs) . '>';
             $output .= '<option value="" selected="selected">' . $label . '</option>';
             $output .= menuoptions($cards, $options['selected']);
             $output .= '</select>';
             return $output;
             break;
         case "billing-cardholder":
             if ($options['mode'] == "value") {
                 return $this->data->Order->Billing->cardholder;
             }
             if (!empty($this->data->Order->Billing->cardholder)) {
                 $options['value'] = $this->data->Order->Billing->cardholder;
             }
             return '<input type="text" name="billing[cardholder]" id="billing-cardholder" ' . inputattrs($options) . ' />';
             break;
         case "billing-cvv":
             if (!empty($this->data->Order->Billing->cardholder)) {
                 $options['value'] = $_POST['billing']['cvv'];
             }
             return '<input type="text" name="billing[cvv]" id="billing-cvv" ' . inputattrs($options) . ' />';
             break;
         case "billing-xco":
             if (isset($_GET['shopp_xco'])) {
                 if ($this->data->Totals->total == 0) {
                     return false;
                 }
                 $xco = join(DIRECTORY_SEPARATOR, array($Shopp->path, 'gateways', $_GET['shopp_xco'] . ".php"));
                 if (file_exists($xco)) {
                     $meta = $Shopp->Flow->scan_gateway_meta($xco);
                     $ProcessorClass = $meta->tags['class'];
                     include_once $xco;
                     $Payment = new $ProcessorClass();
                     if (method_exists($Payment, 'billing')) {
                         return $Payment->billing($options);
                     }
                 }
             }
             break;
         case "has-data":
         case "hasdata":
             return is_array($this->data->Order->data) && count($this->data->Order->data) > 0;
             break;
         case "order-data":
         case "orderdata":
             if (isset($options['name']) && $options['mode'] == "value") {
                 return $this->data->Order->data[$options['name']];
             }
             $allowed_types = array("text", "hidden", 'password', 'checkbox', 'radio', 'textarea');
             $value_override = array("text", "hidden", "password", "textarea");
             if (empty($options['type'])) {
                 $options['type'] = "hidden";
             }
             if (isset($options['name']) && in_array($options['type'], $allowed_types)) {
                 if (!isset($options['title'])) {
                     $options['title'] = $options['name'];
                 }
                 if (in_array($options['type'], $value_override) && isset($this->data->Order->data[$options['name']])) {
                     $options['value'] = $this->data->Order->data[$options['name']];
                 }
                 if (!isset($options['cols'])) {
                     $options['cols'] = "30";
                 }
                 if (!isset($options['rows'])) {
                     $options['rows'] = "3";
                 }
                 if ($options['type'] == "textarea") {
                     return '<textarea name="data[' . $options['name'] . ']" cols="' . $options['cols'] . '" rows="' . $options['rows'] . '" id="order-data-' . $options['name'] . '" ' . inputattrs($options, array('accesskey', 'title', 'tabindex', 'class', 'disabled', 'required')) . '>' . $options['value'] . '</textarea>';
                 }
                 return '<input type="' . $options['type'] . '" name="data[' . $options['name'] . ']" id="order-data-' . $options['name'] . '" ' . inputattrs($options) . ' />';
             }
             // Looping for data value output
             if (!$this->dataloop) {
                 reset($this->data->Order->data);
                 $this->dataloop = true;
             } else {
                 next($this->data->Order->data);
             }
             if (current($this->data->Order->data) !== false) {
                 return true;
             } else {
                 $this->dataloop = false;
                 return false;
             }
             break;
         case "data":
             if (!is_array($this->data->Order->data)) {
                 return false;
             }
             $data = current($this->data->Order->data);
             $name = key($this->data->Order->data);
             if (isset($options['name'])) {
                 return $name;
             }
             return $data;
             break;
         case "submit":
             if (!isset($options['value'])) {
                 $options['value'] = __('Submit Order', 'Shopp');
             }
             return '<input type="submit" name="process" id="checkout-button" ' . inputattrs($options, $submit_attrs) . ' />';
             break;
         case "confirm-button":
             if (!isset($options['value'])) {
                 $options['value'] = __('Confirm Order', 'Shopp');
             }
             return '<input type="submit" name="confirmed" id="confirm-button" ' . inputattrs($options, $submit_attrs) . ' />';
             break;
         case "local-payment":
             return !empty($gateway);
             break;
         case "xco-buttons":
             if (!is_array($xcos)) {
                 return false;
             }
             $buttons = "";
             foreach ($xcos as $xco) {
                 $xco = str_replace('/', DIRECTORY_SEPARATOR, $xco);
                 $xcopath = join(DIRECTORY_SEPARATOR, array($Shopp->path, 'gateways', $xco));
                 if (!file_exists($xcopath)) {
                     continue;
                 }
                 $meta = $Shopp->Flow->scan_gateway_meta($xcopath);
                 $ProcessorClass = $meta->tags['class'];
                 if (!empty($ProcessorClass)) {
                     $PaymentSettings = $Shopp->Settings->get($ProcessorClass);
                     if ($PaymentSettings['enabled'] == "on") {
                         include_once $xcopath;
                         $Payment = new $ProcessorClass();
                         $buttons .= $Payment->tag('button', $options);
                     }
                 }
             }
             return $buttons;
             break;
     }
 }