Example #1
0
function sellplanstate_value_PRIV($fieldvalue, $fields, $i)
{
    global $db;
    global $tablename;
    global $html_etc;
    global $common_html;
    $SYSTEM_STOP_ROW['shenhe_priv'] = 1;
    $SYSTEM_STOP_ROW['flow_priv'] = 1;
    $SYSTEM_STOP_ROW['delete_priv'] = 1;
    $SYSTEM_STOP_ROW['edit_priv'] = 1;
    $fieldvalue = $fields['value'][$i]['fahuostate'];
    if ($fields['value'][$i]['user_flag'] > -1) {
        switch ($fieldvalue) {
            case "0":
                //--
                $id = returntablefield("sellplanmain_detail", "mainrowid", $fields['value'][$i]['billid'], "id");
                if (floatvalue($fields['value'][$i]['totalmoney']) != 0 || $id != '') {
                    $SYSTEM_STOP_ROW['flow_priv'] = 0;
                }
                if (floatvalue($fields['value'][$i]['kaipiaostate']) == 0 && floatvalue($fields['value'][$i]['ifpay']) == 0) {
                    $SYSTEM_STOP_ROW['delete_priv'] = 0;
                    $SYSTEM_STOP_ROW['edit_priv'] = 0;
                }
                break;
            case "1":
                //待出库
                //$SYSTEM_STOP_ROW['delete_priv'] = 0;
                break;
            case "2":
                //需发货
                $SYSTEM_STOP_ROW['shenhe_priv'] = 0;
                break;
            case "3":
                //部分
                $SYSTEM_STOP_ROW['flow_priv'] = 0;
                break;
            case "4":
                //全部
                break;
        }
    }
    return $SYSTEM_STOP_ROW;
}
Example #2
0
function sellonePriv_value_PRIV($fieldvalue, $fields, $i)
{
    global $db;
    $SYSTEM_STOP_ROW['shenhe_priv'] = 0;
    $SYSTEM_STOP_ROW['flow_priv'] = 0;
    $SYSTEM_STOP_ROW['delete_priv'] = 0;
    $SYSTEM_STOP_ROW['edit_priv'] = 0;
    $SYSTEM_STOP_ROW['next_priv'] = 1;
    if (floatvalue($fields['value'][$i]['totalmoney']) == 0) {
        $SYSTEM_STOP_ROW['flow_priv'] = 1;
    }
    if ($fields['value'][$i]['user_flag'] > 0) {
        $SYSTEM_STOP_ROW['shenhe_priv'] = 1;
        $SYSTEM_STOP_ROW['flow_priv'] = 1;
        $SYSTEM_STOP_ROW['edit_priv'] = 1;
        $SYSTEM_STOP_ROW['delete_priv'] = 1;
        $SYSTEM_STOP_ROW['next_priv'] = 0;
    }
    return $SYSTEM_STOP_ROW;
}
Example #3
0
	/**
	 * Calculates total taxes
	 *	 
	 * @since 1.1
	 *
	 * @return float Total tax amount
	 **/
	function calculate () {
		$Totals =& $this->Order->Cart->Totals;

		$tiers = array();
		$taxes = 0;
		foreach ($this->Order->Cart->contents as $id => &$Item) {
			if (!$Item->taxable) continue;
			$Item->taxrate = $this->rate($Item);

			if (!isset($tiers[$Item->taxrate])) $tiers[$Item->taxrate] = $Item->total;
			else $tiers[$Item->taxrate] += $Item->total;

			$taxes += $Item->tax;
		}

		if ($this->shipping) {
			if ($this->vat) // Remove the taxes from the shipping amount for inclusive-tax calculations
				$Totals->shipping = (floatvalue($Totals->shipping)/(1+$Totals->taxrate));
			$taxes += roundprice($Totals->shipping*$Totals->taxrate);
		}

		return $taxes;
	}
 function save_category($Category)
 {
     global $Shopp;
     $db = DB::get();
     check_admin_referer('shopp-save-category');
     if (!current_user_can(SHOPP_USERLEVEL)) {
         wp_die(__('You do not have sufficient permissions to access this page.'));
     }
     $this->settings_save();
     // Save workflow setting
     $Shopp->Catalog = new Catalog();
     $Shopp->Catalog->load_categories(array('where' => 'true'));
     if (!isset($_POST['slug']) && empty($Category->slug)) {
         $Category->slug = sanitize_title_with_dashes($_POST['name']);
     }
     if (isset($_POST['slug'])) {
         unset($_POST['slug']);
     }
     // Work out pathing
     $paths = array();
     if (!empty($Category->slug)) {
         $paths = array($Category->slug);
     }
     // Include self
     $parentkey = -1;
     // If we're saving a new category, lookup the parent
     if ($_POST['parent'] > 0) {
         array_unshift($paths, $Shopp->Catalog->categories[$_POST['parent']]->slug);
         $parentkey = $Shopp->Catalog->categories[$_POST['parent']]->parent;
     }
     while ($category_tree = $Shopp->Catalog->categories[$parentkey]) {
         array_unshift($paths, $category_tree->slug);
         $parentkey = $category_tree->parent;
     }
     if (count($paths) > 1) {
         $_POST['uri'] = join("/", $paths);
     } else {
         $_POST['uri'] = $paths[0];
     }
     if (!empty($_POST['deleteImages'])) {
         $deletes = array();
         if (strpos($_POST['deleteImages'], ",")) {
             $deletes = explode(',', $_POST['deleteImages']);
         } else {
             $deletes = array($_POST['deleteImages']);
         }
         $Category->delete_images($deletes);
     }
     if (!empty($_POST['images']) && is_array($_POST['images'])) {
         $Category->link_images($_POST['images']);
         $Category->save_imageorder($_POST['images']);
         if (!empty($_POST['imagedetails']) && is_array($_POST['imagedetails'])) {
             foreach ($_POST['imagedetails'] as $i => $data) {
                 $Image = new Asset();
                 unset($Image->_datatypes['data'], $Image->data);
                 $Image->load($data['id']);
                 $Image->properties['title'] = $data['title'];
                 $Image->properties['alt'] = $data['alt'];
                 $Image->save();
             }
         }
     }
     // Variation price templates
     if (!empty($_POST['price']) && is_array($_POST['price'])) {
         foreach ($_POST['price'] as &$pricing) {
             $pricing['price'] = floatvalue($pricing['price']);
             $pricing['saleprice'] = floatvalue($pricing['saleprice']);
             $pricing['shipfee'] = floatvalue($pricing['shipfee']);
         }
         $Category->prices = stripslashes_deep($_POST['price']);
     } else {
         $Category->prices = array();
     }
     if (empty($_POST['specs'])) {
         $Category->specs = array();
     } else {
         $_POST['specs'] = stripslashes_deep($_POST['specs']);
     }
     if (empty($_POST['options']) || count($_POST['options']) == 1 && !isset($_POST['options'][1]['options'])) {
         $_POST['options'] = $Category->options = array();
         $_POST['prices'] = $Category->prices = array();
     } else {
         $_POST['options'] = stripslashes_deep($_POST['options']);
     }
     if (isset($_POST['content'])) {
         $_POST['description'] = $_POST['content'];
     }
     $Category->updates($_POST);
     $Category->save();
     do_action_ref_array('shopp_category_saved', array(&$Category));
     $updated = '<strong>' . $Category->name . '</strong> ' . __('category saved.', 'Shopp');
 }
Example #5
0
	/**
	 * Parse price matching queries into a processing object
	 *	 
	 * @since 1.1
	 *
	 * @param string $query A search query string
	 * @return object The price matching object
	 **/
	static function PriceMatching ($query) {
		$pricematch = self::_pricematch_regex();
		preg_match_all("/$pricematch/",$query,$matches,PREG_SET_ORDER);
		if (empty($matches)) return false;
		$_->op = $matches[0][0][0];
		$_->op = (in_array($_->op,array("<",">")))?$_->op:'';
		$_->min = floatvalue($matches[0][1]);
		$_->max = floatvalue($matches[0][4]);
		$_->target = $_->min;
		if ($_->max > 0) $_->op = "-"; // Range matching

		// Roundabout price match
		if (empty($_->op) && empty($_->max)) {
			$_->min = $_->target-($_->target/2);
			$_->max = $_->target+($_->target/2);
		}

		return $_;
	}
Example #6
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;
		}


	}
}
//确认发货
if ($_GET['action'] == "edit_default2_data") {
    //print_r($_SESSION);exit;
    $Store = new Store($db);
    $CaiWu = new CaiWu($db);
    $db->StartTrans();
    $return = $_POST['url'];
    $yunfei = floatvalue($_POST['yunfei']);
    $jiesuantype = floatvalue($_POST['jiesuantype']);
    //先付运费生成费用
    if ($yunfei != 0 && $jiesuantype == 1) {
        $CaiWu->insertFeiYongAccount(6, $yunfei, 1, $_SESSION['LOGIN_USER_ID'], -1);
    }
    //确认发货
    $dingdanid = $Store->confirmFaHuo($_POST['billid'], $_POST['fahuodan'], $_POST['shouhuoren'], $_POST['address'], $_POST['tel'], $_POST['mailcode'], $_POST['fahuotype'], floatvalue($_POST['package']), floatvalue($_POST['weight']), $yunfei, $_POST['jiesuantype'], $_POST['beizhu']);
    //是否事务出现错误
    if ($db->HasFailedTrans()) {
        print "<script language=javascript>alert('错误:" . str_replace("'", "\\'", $db->ErrorMsg()) . "');window.history.back(-1);</script>";
    } else {
        if ($_POST[duanxintongzhi] == 'yes') {
            //给客户发送提示短信
            $sql = "select a.package,a.weight,b.name as fahuotype,a.tel FROM fahuodan a left join fahuotype b on a.fahuotype=b.id  WHERE a.billid=" . trim($_POST['billid']);
            $rs = $db->Execute($sql);
            $rs_a = $rs->GetArray();
            $yunfei = $jiesuantype == 2 ? $yunfei . '元' : '0元(包邮)';
            $message = "【发货提醒】" . $_SESSION[UNIT_NAME] . date("Y-m-d H:i:s") . "向你单位发货" . $rs_a[0][package] . "件,发货人:" . $_SESSION[LOGIN_USER_NAME] . ',物流公司:' . $rs_a[0][fahuotype];
            //$sql = 'INSERT INTO sms_sendlist(msg,nowtime,destcount,userid,destid,result) VALUES("'.$message.'",now(),1,"'.$_SESSION[LOGIN_USER_ID].'","'.$rs_a[0][tel].'","待发")';
            //$rs=$db->Execute($sql);
            print "\n<script type=\"text/javascript\" language=\"javascript\" src=\"" . ROOT_DIR . "general/ERP/Enginee/jquery/jquery.js\"></script>\n";
            print "<script type=\"text/javascript\" language=\"javascript\">\n\t\t\t\$.post('../Framework/sms_getContents.php?action=send', {\n\t\t\t    mobiles:'" . $rs_a[0][tel] . "',\n\t\t\t    msg:'" . cutStr($message, 70) . "'\n\t\t\t}, function(data) {\t\n\t\t\t});\n\t\t</script>";
<?php

ini_set('display_errors', 1);
ini_set('error_reporting', E_ALL);
error_reporting(E_WARNING | E_ERROR);
require_once 'lib.inc.php';
$GLOBAL_SESSION = returnsession();
validateMenuPriv("收票记录");
if ($_GET['action'] == "add_default_data") {
    try {
        $piaojujine = floatvalue($_POST['piaojujine']);
        $billinfo = returntablefield("buyplanmain", "billid", $_POST['caigoubillid'], "totalmoney,shoupiaomoney");
        $maxjine = $billinfo['totalmoney'] - $billinfo['shoupiaomoney'];
        if ($maxjine > 0 && $piaojujine > $maxjine) {
            throw new Exception("本次收票金额不能大于{$maxjine}");
        }
        if ($maxjine < 0 && $piaojujine < $maxjine) {
            throw new Exception("本次收票金额不能小于{$maxjine}");
        }
        if ($piaojujine == 0) {
            throw new Exception("本次收票金额不能为0");
        }
        global $db;
        $db->StartTrans();
        $CaiWu = new CaiWu($db);
        $CaiWu->insertShouPiao($_POST['supplyid'], $_POST['caigoubillid'], $_POST['kaipiaoneirong'], $_POST['piaojutype'], $_POST['fapiaono'], $_POST['piaojujine'], $_SESSION['LOGIN_USER_ID'], $_POST['qici'], $_POST['beizhu'], $_POST['kaipiaodate']);
        $db->CompleteTrans();
        page_css("收票记录");
        //是否事务出现错误
        if ($db->HasFailedTrans()) {
            throw new Exception($db->ErrorMsg());
Example #9
0
	/**
	 * Handles saving updated category information from the category editor
	 *	 
	 * @since 1.0
	 * @return void
	 **/
	function save ($Category) {
		global $Ecart;
		$Settings = &EcartSettings();
		$db = DB::get();
		check_admin_referer('ecart-save-category');

		if ( !(is_ecart_userlevel() || current_user_can('ecart_categories')) )
			wp_die(__('You do not have sufficient permissions to access this page.'));

		$Settings->saveform(); // Save workflow setting

		$Ecart->Catalog = new Catalog();
		$Ecart->Catalog->load_categories(array(
			'columns' => "cat.id,cat.parent,cat.name,cat.description,cat.uri,cat.slug",
			'where' => array(),
			'joins' => array(),
			'orderby' => false,
			'order' => false,
			'outofstock' => true
		));

		$Category->update_slug();

		if (!empty($_POST['deleteImages'])) {
			$deletes = array();
			if (strpos($_POST['deleteImages'],","))	$deletes = explode(',',$_POST['deleteImages']);
			else $deletes = array($_POST['deleteImages']);
			$Category->delete_images($deletes);
		}

		// Variation price templates
		if (!empty($_POST['price']) && is_array($_POST['price'])) {
			foreach ($_POST['price'] as &$pricing) {
				$pricing['price'] = floatvalue($pricing['price'],false);
				$pricing['saleprice'] = floatvalue($pricing['saleprice'],false);
				$pricing['shipfee'] = floatvalue($pricing['shipfee'],false);
			}
			$Category->prices = stripslashes_deep($_POST['price']);
		} else $Category->prices = array();

		if (empty($_POST['specs'])) $Category->specs = array();
		else $_POST['specs'] = stripslashes_deep($_POST['specs']);

		if (empty($_POST['options'])
			|| (count($_POST['options']['v'])) == 1 && !isset($_POST['options']['v'][1]['options'])) {
				$_POST['options'] = $Category->options = array();
				$_POST['prices'] = $Category->prices = array();
		} else $_POST['options'] = stripslashes_deep($_POST['options']);
		if (isset($_POST['content'])) $_POST['description'] = $_POST['content'];

		$Category->updates($_POST);
		$Category->save();

		if (!empty($_POST['images']) && is_array($_POST['images'])) {
			$Category->link_images($_POST['images']);
			$Category->save_imageorder($_POST['images']);
			if (!empty($_POST['imagedetails']) && is_array($_POST['imagedetails'])) {
				foreach($_POST['imagedetails'] as $i => $data) {
					$Image = new CategoryImage($data['id']);
					$Image->title = $data['title'];
					$Image->alt = $data['alt'];
					$Image->save();
				}
			}
		}

		do_action_ref_array('ecart_category_saved',array(&$Category));

		$updated = '<strong>'.$Category->name.'</strong> '.__('category saved.','Ecart');

	}
Example #10
0
	/**
	 * match_rule ()
	 * Determines if the value of a given subject matches the rule based
	 * on the specified operation */
	function match_rule ($subject,$op,$value,$property=false) {
		switch($op) {
			// String or Numeric operations
			case "Is equal to":
			 	if($property && Promotion::$values[$property] == 'price') {
					return ( floatvalue($subject) != 0
					&& floatvalue($value) != 0
					&& floatvalue($subject) == floatvalue($value));
				} else {
					if (is_array($subject)) return (in_array($value,$subject));
					return ("$subject" === "$value");
				}
				break;
			case "Is not equal to":
				if (is_array($subject)) return (!in_array($value,$subject));
				return ("$subject" !== "$value"
						|| (floatvalue($subject) != 0
						&& floatvalue($value) != 0
						&& floatvalue($subject) != floatvalue($value)));
						break;

			// String operations
			case "Contains":
				if (is_array($subject)) {
					foreach ($subject as $s)
						if (stripos($s,$value) !== false) return true;
					return false;
				}
				return (stripos($subject,$value) !== false); break;
			case "Does not contain":
				if (is_array($subject)) {
					foreach ($subject as $s)
						if (stripos($s,$value) !== false) return false;
					return true;
				}
				return (stripos($subject,$value) === false); break;
			case "Begins with":
				if (is_array($subject)) {
					foreach ($subject as $s)
						if (stripos($s,$value) === 0) return true;
					return false;
				}
				return (stripos($subject,$value) === 0); break;
			case "Ends with":
				if (is_array($subject)) {
					foreach ($subject as $s)
						if (stripos($s,$value) === strlen($s) - strlen($value)) return true;
					return false;
				}
				return  (stripos($subject,$value) === strlen($subject) - strlen($value)); break;

			// Numeric operations
			case "Is greater than":
				return (floatvalue($subject,false) > floatvalue($value,false));
				break;
			case "Is greater than or equal to":
				return (floatvalue($subject,false) >= floatvalue($value,false));
				break;
			case "Is less than":
				return (floatvalue($subject,false) < floatvalue($value,false));
				break;
			case "Is less than or equal to":
				return (floatvalue($subject,false) <= floatvalue($value,false));
				break;
		}

		return false;
	}
<?php

ini_set('display_errors', 1);
ini_set('error_reporting', E_ALL);
error_reporting(E_WARNING | E_ERROR);
require_once 'lib.inc.php';
$GLOBAL_SESSION = returnsession();
validateMenuPriv("付款记录");
if ($_GET['action'] == "add_default_data") {
    try {
        global $db;
        $oddment = floatvalue($_POST['oddment']);
        $accountid = $_POST['accountid'];
        $shoukuan = floatvalue($_POST['jine']);
        $billinfo = returntablefield("buyplanmain", "billid", $_POST['caigoubillid'], "totalmoney,paymoney,oddment");
        $maxjine = $billinfo['totalmoney'] - $billinfo['paymoney'] - $billinfo['oddment'];
        if ($maxjine > 0 && $shoukuan + $oddment > $maxjine) {
            throw new Exception("本次付款和去零合计不能大于{$maxjine}");
        }
        if ($maxjine < 0 && $shoukuan + $oddment < $maxjine) {
            throw new Exception("本次付款和去零合计不能小于{$maxjine}");
        }
        if ($shoukuan + $oddment == 0) {
            throw new Exception("本次付款+去零合计不能为0");
        }
        //开启事务
        //$db->debug=1;
        $CaiWu = new CaiWu($db);
        $db->StartTrans();
        //插入付款记录
        $accesstype = "货款支付";
 function load_products($loading = false)
 {
     global $Shopp, $wp;
     $db = DB::get();
     $catalogtable = DatabaseObject::tablename(Catalog::$table);
     $producttable = DatabaseObject::tablename(Product::$table);
     $pricetable = DatabaseObject::tablename(Price::$table);
     $discounttable = DatabaseObject::tablename(Discount::$table);
     $promotable = DatabaseObject::tablename(Promotion::$table);
     $assettable = DatabaseObject::tablename(Asset::$table);
     $this->paged = false;
     $this->pagination = $Shopp->Settings->get('catalog_pagination');
     $this->page = isset($wp->query_vars['paged']) ? $wp->query_vars['paged'] : 1;
     if (empty($this->page)) {
         $this->page = 1;
     }
     $limit = 1000;
     // Hard product limit per category to keep resources "reasonable"
     if (!$loading) {
         $loading = $this->loading;
     } else {
         $loading = array_merge($this->loading, $loading);
     }
     if (!empty($loading['columns'])) {
         $loading['columns'] = ", " . $loading['columns'];
     } else {
         $loading['columns'] = '';
     }
     $where = array();
     if (!empty($loading['where'])) {
         $where[] = "({$loading['where']})";
     }
     // Handle default WHERE clause matching this category id
     if (empty($loading['where']) && !empty($this->id)) {
         $where[] = "p.id in (SELECT product FROM {$catalogtable} WHERE category={$this->id})";
     }
     if (!isset($loading['nostock']) && $Shopp->Settings->get('outofstock_catalog') == "off") {
         $where[] = "p.id in (SELECT product FROM {$pricetable} WHERE type != 'N/A' AND inventory='off' OR (inventory='on' AND stock > 0))";
     } else {
         $where[] = "p.id in (SELECT product FROM {$pricetable} WHERE type != 'N/A')";
     }
     if (!isset($loading['joins'])) {
         $loading['joins'] = '';
     }
     if (!empty($Shopp->Cart->data->Category[$this->slug])) {
         $spectable = DatabaseObject::tablename(Spec::$table);
         $f = 1;
         $filters = "";
         foreach ($Shopp->Cart->data->Category[$this->slug] as $facet => $value) {
             if (empty($value)) {
                 continue;
             }
             $specalias = "spec" . $f++;
             // Handle Number Range filtering
             $match = "";
             if (!is_array($value) && preg_match('/^.*?(\\d+[\\.\\,\\d]*).*?\\-.*?(\\d+[\\.\\,\\d]*).*$/', $value, $matches)) {
                 if ($facet == "Price") {
                     // Prices require complex matching on price line entries
                     $min = floatvalue($matches[1]);
                     $max = floatvalue($matches[2]);
                     if ($matches[1] > 0) {
                         $match .= " ((onsale=0 AND (minprice >= {$min} OR maxprice >= {$min})) OR (onsale=1 AND (minsaleprice >= {$min} OR maxsaleprice >= {$min})))";
                     }
                     if ($matches[2] > 0) {
                         $match .= (empty($match) ? "" : " AND ") . " ((onsale=0 AND (minprice <= {$max} OR maxprice <= {$max})) OR (onsale=1 AND (minsaleprice <= {$max} OR maxsaleprice <= {$max})))";
                     }
                 } else {
                     // Spec-based numbers are somewhat more straightforward
                     if ($matches[1] > 0) {
                         $match .= "{$specalias}.numeral >= {$matches[1]}";
                     }
                     if ($matches[2] > 0) {
                         $match .= (empty($match) ? "" : " AND ") . "{$specalias}.numeral <= {$matches[2]}";
                     }
                 }
             } else {
                 $match = "{$specalias}.content='{$value}'";
             }
             // No range, direct value match
             // Use HAVING clause for filtering by pricing information
             // because of data aggregation
             if ($facet == "Price") {
                 $loading['having'] .= (empty($loading['having']) ? 'HAVING ' : ' AND ') . $match;
                 continue;
             }
             $loading['joins'] .= " LEFT JOIN {$spectable} AS {$specalias} ON {$specalias}.product=p.id AND {$specalias}.name='{$facet}'";
             $filters .= empty($filters) ? $match : " AND " . $match;
         }
         if (!empty($filters)) {
             $where[] = $filters;
         }
     }
     $where[] = "p.published='on'";
     $loading['where'] = join(" AND ", $where);
     $defaultOrder = $Shopp->Settings->get('default_product_order');
     if (empty($defaultOrder)) {
         $defaultOrder = "title";
     }
     $ordering = isset($Shopp->Cart->data->Category['orderby']) ? $Shopp->Cart->data->Category['orderby'] : $defaultOrder;
     if (!empty($loading['order'])) {
         $ordering = $loading['order'];
     }
     switch ($ordering) {
         case "bestselling":
             $purchasedtable = DatabaseObject::tablename(Purchased::$table);
             $loading['columns'] .= ',count(DISTINCT pur.id) AS sold';
             $loading['joins'] .= " LEFT JOIN {$purchasedtable} AS pur ON p.id=pur.product";
             $loading['order'] = "sold DESC";
             break;
         case "highprice":
             $loading['order'] = "pd.price DESC";
             break;
         case "lowprice":
             $loading['order'] = "pd.price ASC";
             break;
         case "newest":
             $loading['order'] = "pd.created DESC";
             break;
         case "oldest":
             $loading['order'] = "pd.created ASC";
             break;
         case "random":
             $loading['order'] = "RAND()";
             break;
         case "":
         case "title":
         default:
             $loading['order'] = "p.name ASC";
             break;
     }
     if (!empty($loading['orderby'])) {
         $loading['order'] = $loading['orderby'];
     }
     if (empty($loading['limit'])) {
         if ($this->pagination > 0 && is_numeric($this->page)) {
             if (!$this->pagination || $this->pagination < 0) {
                 $this->pagination = $limit;
             }
             $start = $this->pagination * ($this->page - 1);
             $loading['limit'] = "{$start},{$this->pagination}";
         } else {
             $loading['limit'] = $limit;
         }
     } else {
         $limit = (int) $loading['limit'];
     }
     $columns = "p.*,\n\t\t\t\t\timg.id AS thumbnail,img.properties AS thumbnail_properties,MAX(pr.status) as promos,\n\t\t\t\t\tSUM(DISTINCT IF(pr.type='Percentage Off',pr.discount,0))AS percentoff,\n\t\t\t\t\tSUM(DISTINCT IF(pr.type='Amount Off',pr.discount,0)) AS amountoff,\n\t\t\t\t\tif (pr.type='Free Shipping',1,0) AS freeshipping,\n\t\t\t\t\tif (pr.type='Buy X Get Y Free',pr.buyqty,0) AS buyqty,\n\t\t\t\t\tif (pr.type='Buy X Get Y Free',pr.getqty,0) AS getqty,\n\t\t\t\t\tMAX(pd.price) AS maxprice,MIN(pd.price) AS minprice,\n\t\t\t\t\tIF(pd.sale='on',1,IF (pr.discount > 0,1,0)) AS onsale,\n\t\t\t\t\tMAX(pd.saleprice) as maxsaleprice,MIN(pd.saleprice) AS minsaleprice,\n\t\t\t\t\tIF(pd.inventory='on',1,0) AS inventory,\n\t\t\t\t\tSUM(pd.stock) as stock";
     // Query without promotions for MySQL servers prior to 5
     if (version_compare($db->version, '5.0', '<')) {
         $columns = "p.*,\n\t\t\t\t\t\timg.id AS thumbnail,img.properties AS thumbnail_properties,\n\t\t\t\t\t\tMAX(pd.price) AS maxprice,MIN(pd.price) AS minprice,\n\t\t\t\t\t\tIF(pd.sale='on',1,0) AS onsale,\n\t\t\t\t\t\tMAX(pd.saleprice) as maxsaleprice,MIN(pd.saleprice) AS minsaleprice,\n\t\t\t\t\t\tIF(pd.inventory='on',1,0) AS inventory,\n\t\t\t\t\t\tSUM(pd.stock) as stock";
     }
     // Handle alphabetic page requests
     if ((!isset($Shopp->Category->controls) || isset($Shopp->Category->controls) && $Shopp->Category->controls !== false) && (isset($loading['pagination']) && $loading['pagination'] == "alpha" || !is_numeric($this->page))) {
         $alphanav = range('A', 'Z');
         $ac = "SELECT count(DISTINCT p.id) AS total,IF(LEFT(p.name,1) REGEXP '[0-9]',LEFT(p.name,1),LEFT(SOUNDEX(p.name),1)) AS letter,AVG(IF(pd.sale='on',pd.saleprice,pd.price)) as avgprice \n\t\t\t\t\t\tFROM {$producttable} AS p \n\t\t\t\t\t\tLEFT JOIN {$pricetable} AS pd ON pd.product=p.id AND pd.type != 'N/A' \n\t\t\t\t\t\tLEFT JOIN {$discounttable} AS dc ON dc.product=p.id AND dc.price=pd.id\n\t\t\t\t\t\tLEFT JOIN {$promotable} AS pr ON pr.id=dc.promo \n\t\t\t\t\t\tLEFT JOIN {$assettable} AS img ON img.parent=p.id AND img.context='product' AND img.datatype='thumbnail' AND img.sortorder=0 \n\t\t\t\t\t\t{$loading['joins']}\n\t\t\t\t\t\tWHERE {$loading['where']}\n\t\t\t\t\t\tGROUP BY letter";
         $alpha = $db->query($ac);
         $existing = current($alpha);
         if (!isset($this->alpha['0-9'])) {
             $this->alpha['0-9'] = new stdClass();
             $this->alpha['0-9']->letter = '0-9';
             $this->alpha['0-9']->total = 0;
             $this->alpha['0-9']->avg = 0;
         }
         while (is_numeric($existing->letter)) {
             $this->alpha['0-9']->total += $existing->total;
             $this->alpha['0-9']->avg = ($this->alpha['0-9']->avg + $existing->avg) / 2;
             $this->alpha['0-9']->letter = '0-9';
             $existing = next($alpha);
         }
         foreach ($alphanav as $letter) {
             if ($existing->letter == $letter) {
                 $this->alpha[$letter] = $existing;
                 $existing = next($alpha);
             } else {
                 $entry = new stdClass();
                 $entry->letter = $letter;
                 $entry->total = 0;
                 $entry->avg = 0;
                 $this->alpha[$letter] = $entry;
             }
         }
         $this->paged = true;
         if (!is_numeric($this->page)) {
             $alphafilter = $this->page == "0-9" ? "(LEFT(p.name,1) REGEXP '[0-9]') = 1" : "IF(LEFT(p.name,1) REGEXP '[0-9]',LEFT(p.name,1),LEFT(SOUNDEX(p.name),1))='{$this->page}'";
             $loading['where'] .= (empty($loading['where']) ? "" : " AND ") . $alphafilter;
         }
     }
     $query = "SELECT SQL_CALC_FOUND_ROWS {$columns}{$loading['columns']}\n\t\t\t\t\tFROM {$producttable} AS p \n\t\t\t\t\tLEFT JOIN {$pricetable} AS pd ON pd.product=p.id AND pd.type != 'N/A' \n\t\t\t\t\tLEFT JOIN {$discounttable} AS dc ON dc.product=p.id AND dc.price=pd.id\n\t\t\t\t\tLEFT JOIN {$promotable} AS pr ON pr.id=dc.promo \n\t\t\t\t\tLEFT JOIN {$assettable} AS img ON img.parent=p.id AND img.context='product' AND img.datatype='thumbnail' AND img.sortorder=0 \n\t\t\t\t\t{$loading['joins']}\n\t\t\t\t\tWHERE {$loading['where']}\n\t\t\t\t\tGROUP BY p.id {$loading['having']}\n\t\t\t\t\tORDER BY {$loading['order']} \n\t\t\t\t\tLIMIT {$loading['limit']}";
     // Execute the main category products query
     $products = $db->query($query, AS_ARRAY);
     if ($this->pagination > 0 && $limit > $this->pagination) {
         $total = $db->query("SELECT FOUND_ROWS() as count");
         $this->total = $total->count;
         $this->pages = ceil($this->total / $this->pagination);
         if ($this->pages > 1) {
             $this->paged = true;
         }
     }
     if ($this->pagination == 0 || $limit < $this->pagination) {
         $this->total = count($this->products);
     }
     $this->pricing['min'] = 0;
     $this->pricing['max'] = 0;
     $prices = array();
     foreach ($products as &$product) {
         if ($product->maxsaleprice == 0) {
             $product->maxsaleprice = $product->maxprice;
         }
         if ($product->minsaleprice == 0) {
             $product->minsaleprice = $product->minprice;
         }
         $prices[] = $product->onsale ? $product->minsaleprice : $product->minprice;
         if (!empty($product->percentoff)) {
             $product->maxsaleprice = $product->maxsaleprice - $product->maxsaleprice * ($product->percentoff / 100);
             $product->minsaleprice = $product->minsaleprice - $product->minsaleprice * ($product->percentoff / 100);
         }
         if (!empty($product->amountoff)) {
             $product->maxsaleprice = $product->maxsaleprice - $product->amountoff;
             $product->minsaleprice = $product->minsaleprice - $product->amountoff;
         }
         if ($this->pricing['max'] == 0 || $product->maxsaleprice > $this->pricing['max']) {
             $this->pricing['max'] = $product->maxsaleprice;
         }
         if ($this->pricing['min'] == 0 || $product->minsaleprice < $this->pricing['min']) {
             $this->pricing['min'] = $product->minsaleprice;
         }
         $this->products[$product->id] = new Product();
         $this->products[$product->id]->populate($product);
         // Special property for Bestseller category
         if (isset($product->sold) && $product->sold) {
             $this->products[$product->id]->sold = $product->sold;
         }
         // Special property Promotions
         if (isset($product->promos)) {
             $this->products[$product->id]->promos = $product->promos;
         }
         if (!empty($product->thumbnail)) {
             $image = new stdClass();
             $image->properties = unserialize($product->thumbnail_properties);
             if (SHOPP_PERMALINKS) {
                 $image->uri = $Shopp->imguri . $product->thumbnail;
             } else {
                 $image->uri = add_query_arg('shopp_image', $product->thumbnail, $Shopp->imguri);
             }
             $this->products[$product->id]->imagesets['thumbnail'] = array();
             $this->products[$product->id]->imagesets['thumbnail'][] = $image;
             $this->products[$product->id]->thumbnail =& $this->products[$product->id]->imagesets['thumbnail'][0];
         }
     }
     $this->pricing['average'] = 0;
     if (count($prices) > 0) {
         $this->pricing['average'] = array_sum($prices) / count($prices);
     }
     if (!isset($loading['load'])) {
         $loading['load'] = array('prices');
     }
     if (count($this->products) > 0) {
         $Processing = new Product();
         $Processing->load_data($loading['load'], $this->products);
     }
     $this->loaded = true;
 }
<?php

ini_set('display_errors', 1);
ini_set('error_reporting', E_ALL);
error_reporting(E_WARNING | E_ERROR);
require_once 'lib.inc.php';
$GLOBAL_SESSION = returnsession();
$SYSTEM_PRIV_STOP = "1";
validateMenuPriv("预付款");
if ($_GET['action'] == "add_default_data") {
    global $db;
    $supplyid = $_POST['supplyid'];
    $linkmanid = $_POST['linkmanid'];
    $accountid = $_POST['accountid'];
    $beizhu = $_POST['beizhu'];
    $jine = floatvalue($_POST['yufukuan']);
    if ($jine == 0) {
        print "<script language=javascript>alert('错误:预付款金额不能等于0');window.history.back(-1);</script>";
        exit;
    }
    //开启事务
    //$db->debug=1;
    $CaiWu = new CaiWu($db);
    $db->StartTrans();
    $CaiWu->insertYuFukuanReocord($supplyid, $linkmanid, $jine, $accountid, $_SESSION['LOGIN_USER_ID'], "预付货款", $beizhu);
    //是否事务出现错误
    if ($db->HasFailedTrans()) {
        print "<script language=javascript>alert('错误:" . str_replace("'", "\\'", $db->ErrorMsg()) . "');window.history.back(-1);</script>";
    } else {
        page_css("预付款记录");
        $return = $_POST['url'];
     $allmoney = $allmoney + $jine;
 }
 if ($allnum == 0) {
     throw new Exception("总数量必须大于0");
 }
 //开启事务
 $db->StartTrans();
 //获取入库单号
 $billid = returnAutoIncrement("billid", "stockinmain");
 //插入新入库单
 $sql = "insert into stockinmain (billid,zhuti,storeid,createman,createtime,caigoubillid,state,totalnum,totalmoney,instoreshenhe,indate,intype) values(" . $billid . ",'库存初始化'," . $storeid . ",'" . $_SESSION['LOGIN_USER_ID'] . "','" . date("Y-m-d H:i:s") . "',0,'已入库',{$allnum},{$allmoney},'" . $_SESSION['LOGIN_USER_ID'] . "','" . date("Y-m-d H:i:s") . "','初始化入库')";
 $db->Execute($sql);
 for ($i = 0; $i < sizeof($rs_detail); $i++) {
     $num = intval($_POST["num_" . $rs_detail[$i]['id']]);
     $price = floatvalue($_POST["price_" . $rs_detail[$i]['id']]);
     $jine = floatvalue($_POST["jine_" . $rs_detail[$i]['id']]);
     $memo = $_POST["beizhu_" . $rs_detail[$i]['id']];
     //插入库存
     if ($num != 0) {
         $sql = "select max(id) as maxid from stockinmain_detail";
         $rs = $db->Execute($sql);
         $rs_a = $rs->GetArray();
         $maxid = $rs_a[0]['maxid'] + 1;
         $sql = "insert into stockinmain_detail (id,prodid,prodname,prodguige,prodxinghao,proddanwei,price,zhekou,num,mainrowid,jine) values('{$maxid}','" . $rs_detail[$i]['prodid'] . "','" . $rs_detail[$i]['prodname'] . "','" . $rs_detail[$i]['guige'] . "','" . $rs_detail[$i]['xinghao'] . "','" . $rs_detail[$i]['danwei'] . "'," . $price . ",1," . $num . "," . $billid . "," . $jine . ")";
         $db->Execute($sql);
         $sql = "update store_init set num={$num},price={$price},jine={$jine},memo='{$memo}' where id=" . $rs_detail[$i]['id'];
         $db->Execute($sql);
         $maxid = returnAutoIncrement("id", "store");
         $sql = "insert into store (id,prodid,num,price,storeid,memo) values({$maxid},'" . $rs_detail[$i]['prodid'] . "',{$num},{$price},{$storeid},'{$memo}')";
         $db->Execute($sql);
     }
    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;
        }
    }
Example #16
0
	/**
	 * Generates an RSS feed of products for this category
	 *
	 * NOTE: To modify the output of the RSS generator, use
	 * the filter hooks provided in a separate plugin or
	 * in the theme functions.php file.
	 * 
	 * @since 1.0
	 * @version 1.1
	 *
	 * @return string The final RSS markup
	 **/
	function rss () {
		global $Ecart;
		$db = DB::get();

		add_filter('ecart_rss_description','wptexturize');
		add_filter('ecart_rss_description','convert_chars');
		add_filter('ecart_rss_description','make_clickable',9);
		add_filter('ecart_rss_description','force_balance_tags', 25);
		add_filter('ecart_rss_description','convert_smilies',20);
		add_filter('ecart_rss_description','wpautop',30);

		do_action_ref_array('ecart_category_rss',array(&$this));

		if (!$this->products) $this->load_products(array('limit'=>500,'load'=>array('images','prices')));

		$rss = array('title' => get_bloginfo('name')." ".$this->name,
			 			'link' => $this->tag('feed-url'),
					 	'description' => $this->description,
						'sitename' => get_bloginfo('name').' ('.get_bloginfo('url').')',
						'xmlns' => array('ecart'=>'http://ecartlugin.net/xmlns',
							'g'=>'http://base.google.com/ns/1.0',
							'atom'=>'http://www.w3.org/2005/Atom',
							'content'=>'http://purl.org/rss/1.0/modules/content/')
						);
		$rss = apply_filters('ecart_rss_meta',$rss);

		$items = array();
		foreach ($this->products as $product) {
			$item = array();
			$item['guid'] = $product->tag('url','return=1');
			$item['title'] = $product->name;
			$item['link'] =  $product->tag('url','return=1');

			// Item Description
			$item['description'] = '';

			$Image = current($product->images);
			if (!empty($Image)) {
				$item['description'] .= '<a href="'.$item['link'].'" title="'.$product->name.'">';
				$item['description'] .= '<img src="'.esc_attr(add_query_string($Image->resizing(96,96,0),ecarturl($Image->id,'images'))).'" alt="'.$product->name.'" width="96" height="96" style="float: left; margin: 0 10px 0 0;" />';
				$item['description'] .= '</a>';
			}

			$pricing = "";
			if ($product->onsale) {
				if ($product->min['saleprice'] != $product->max['saleprice'])
					$pricing .= "from ";
				$pricing .= money($product->min['saleprice']);
			} else {
				if ($product->min['price'] != $product->max['price'])
					$pricing .= "from ";
				$pricing .= money($product->min['price']);
			}
			$item['description'] .= "<p><big><strong>$pricing</strong></big></p>";

			$item['description'] .= $product->description;
			$item['description'] =
			 	'<![CDATA['.apply_filters('ecart_rss_description',($item['description']),$product).']]>';

			// Google Base Namespace
			if ($Image) $item['g:image_link'] = add_query_string($Image->resizing(400,400,0),ecarturl($Image->id,'images'));
			$item['g:condition'] = "new";

			$price = floatvalue($product->onsale?$product->min['saleprice']:$product->min['price']);
			if (!empty($price))	{
				$item['g:price'] = $price;
				$item['g:price_type'] = "starting";
			}

			$item = apply_filters('ecart_rss_item',$item,$product);
			$items[] = $item;
		}
		$rss['items'] = $items;

		return $rss;
	}
 /**
  * match_rule ()
  * Determines if the value of a given subject matches the rule based 
  * on the specified operation */
 function match_rule($subject, $op, $value, $property = false)
 {
     switch ($op) {
         // String or Numeric operations
         case "Is equal to":
             if ($property && $this->values[$property] == 'price') {
                 return floatvalue($subject) != 0 && floatvalue($value) != 0 && floatvalue($subject) == floatvalue($value);
             } else {
                 return $subject === $value;
             }
             break;
         case "Is not equal to":
             return $subject !== $value || floatvalue($subject) != 0 && floatvalue($value) != 0 && floatvalue($subject) != floatvalue($value);
             break;
             // String operations
         // String operations
         case "Contains":
             return stripos($subject, $value) !== false;
             break;
         case "Does not contain":
             return stripos($subject, $value) === false;
             break;
         case "Begins with":
             return stripos($subject, $value) === 0;
             break;
         case "Ends with":
             return stripos($subject, $value) === strlen($subject) - strlen($value);
             break;
             // Numeric operations
         // Numeric operations
         case "Is greater than":
             return floatvalue($subject, false) > floatvalue($value, false);
             break;
         case "Is greater than or equal to":
             return floatvalue($subject, false) >= floatvalue($value, false);
             break;
         case "Is less than":
             return floatvalue($subject, false) < floatvalue($value, false);
             break;
         case "Is less than or equal to":
             return floatvalue($subject, false) <= floatvalue($value, false);
             break;
     }
     return false;
 }
Example #18
0
	/**
	 * Prepares a DatabaseObject for entry into the database
	 *
	 * Iterates the properties of a DatabaseObject and formats the data
	 * according to the datatype meta available for the property to create
	 * an array of key/value pairs that are easy concatenate into a valid
	 * SQL query
	 *
	 * @since 1.0
	 *
	 * @param DatabaseObject $object The object to be prepared
	 * @return array Data structure ready for query building
	 **/
	function prepare ($object) {
		$data = array();

		// Go through each data property of the object
		foreach(get_object_vars($object) as $property => $value) {
			if (!isset($object->_datatypes[$property])) continue;

			// If the property is has a _datatype
			// it belongs in the database and needs
			// to be prepared

			// Process the data
			switch ($object->_datatypes[$property]) {
				case "string":
					// Escape characters in strings as needed
					if (is_array($value) || is_object($value)) $data[$property] = "'".addslashes(serialize($this->escape($value)))."'";
					else $data[$property] = "'".$this->escape($value)."'";
					break;
				case "list":
					// If value is empty, skip setting the field
					// so it inherits the default value in the db
					if (!empty($value))
						$data[$property] = "'$value'";
					break;
				case "date":
					// If it's an empty date, set it to now()'s timestamp
					if (is_null($value)) {
						$data[$property] = "now()";
					// If the date is an integer, convert it to an
					// sql YYYY-MM-DD HH:MM:SS format
					} elseif (!empty($value) && is_int(intval($value))) {
						$data[$property] = "'".mkdatetime(intval($value))."'";
					// Otherwise it's already ready, so pass it through
					} else {
						$data[$property] = "'$value'";
					}
					break;
				case "int":
				case "float":
					// Sanitize without rounding to protect precision
					$value = floatvalue($value,false);

					$data[$property] = "'$value'";

					if (empty($value)) $data[$property] = "'0'";

					// Special exception for id fields
					if ($property == "id" && empty($value)) $data[$property] = "NULL";

					break;
				default:
					// Anything not needing processing
					// passes through into the structure
					$data[$property] = "'$value'";
			}

		}

		return $data;
	}
Example #19
0
	/**
	 * Renders the shipping settings screen and processes updates
	 *	 
	 * @since 1.1
	 *
	 * @return void
	 **/
	function shipping () {
		global $Ecart;

		if ( !(current_user_can('manage_options') && current_user_can('ecart_settings_shipping')) )
			wp_die(__('You do not have sufficient permissions to access this page.'));

		if (!empty($_POST['save'])) {
			check_admin_referer('ecart-settings-shipping');

			// Sterilize $values
			foreach ($_POST['settings']['shipping_rates'] as $i => &$method) {
				$method['name'] = stripslashes($method['name']);
				foreach ($method as $key => &$mr) {
					if (!is_array($mr)) continue;
					foreach ($mr as $id => &$v) {
						if ($v == ">" || $v == "+" || $key == "services") continue;
						$v = floatvalue($v);
					}
				}
			}

			$_POST['settings']['order_shipfee'] = floatvalue($_POST['settings']['order_shipfee']);

	 		$this->settings_save();
			$updated = __('Shipping settings saved.','Ecart');

			// Reload the currently active shipping modules
			$active = $Ecart->Shipping->activated();
			$Ecart->Shipping->settings();

			$Errors = &EcartErrors();
			do_action('ecart_verify_shipping_services');

			if ($Errors->exist()) {
				// Get all addon related errors
				$failures = $Errors->level(ECART_ADDON_ERR);
				if (!empty($failures)) {
					$updated = __('Shipping settings saved but there were errors: ','Ecart');
					foreach ($failures as $error)
						$updated .= '<p>'.$error->message(true,true).'</p>';
				}
			}

		}

		$Ecart->Shipping->settings();

		$methods = $Ecart->Shipping->methods;
		$base = $Ecart->Settings->get('base_operations');
		$regions = Lookup::regions();
		$region = $regions[$base['region']];
		$useRegions = $Ecart->Settings->get('shipping_regions');

		$areas = Lookup::country_areas();
		if (is_array($areas[$base['country']]) && $useRegions == "on")
			$areas = array_keys($areas[$base['country']]);
		else $areas = array($base['country'] => $base['name']);
		unset($countries,$regions);

		$rates = $Ecart->Settings->get('shipping_rates');
		if (!empty($rates)) ksort($rates);

		$lowstock = $Ecart->Settings->get('lowstock_level');
		if (empty($lowstock)) $lowstock = 0;

		include(ECART_ADMIN_PATH."/settings/shipping.php");
	}
Example #20
0
 function insertYuShoukuanReocord($customerid, $linkmanid, $jine, $accountid, $createman, $opertype, $beizhu)
 {
     $id = returnAutoIncrementUnitBillid("preshoubillid");
     $curchuzhi = floatvalue(returntablefield("customer", "ROWID", $customerid, "yuchuzhi"));
     $sql = "insert into accesspreshou (id,customerid,linkman,curchuzhi,jine,accountid,createman,createtime,opertype,beizhu)\n\t\tvalues(" . $id . "," . $customerid . ",'" . $linkmanid . "'," . $curchuzhi . "," . $jine . "," . $accountid . ",'" . $createman . "','" . date("Y-m-d H:i:s") . "','{$opertype}','{$beizhu}')";
     $this->db->Execute($sql);
     //账户金额增加
     $oldjine = returntablefield("bank", "rowid", $accountid, "jine");
     $sql = "update bank set jine=jine+(" . $jine . ") where rowid=" . $accountid;
     $this->db->Execute($sql);
     $sql = "insert into accessbank (bankid,oldjine,jine,opertype,guanlianbillid,createman,createtime) values(\n\t\t" . $accountid . "," . $oldjine . "," . $jine . ",'{$opertype}'," . $id . ",'" . $createman . "','" . date("Y-m-d H:i:s") . "')";
     $this->db->Execute($sql);
     $sql = "update customer set yuchuzhi=yuchuzhi+({$jine}) where rowid=" . $customerid;
     $this->db->Execute($sql);
 }
Example #21
0
	/**
	 * Handles saving updates from the product editor
	 *
	 * Saves all product related information which includes core product data
	 * and supporting elements such as images, digital downloads, tags,
	 * assigned categories, specs and pricing variations.
	 *	 
	 * @return void
	 **/
	function save_product ($Product) {
		$db = DB::get();
		$Settings = &EcartSettings();
		check_admin_referer('ecart-save-product');

		if ( !(is_ecart_userlevel() || current_user_can('ecart_products')) )
			wp_die(__('You do not have sufficient permissions to access this page.'));

		$Settings->saveform(); // Save workflow setting

		$base = $Settings->get('base_operations');
		$taxrate = 0;
		if ($base['vat']) $taxrate = ecart_taxrate(null,true,$Product);

		if (empty($_POST['options'])) $Product->options = array();
		else $_POST['options'] = stripslashes_deep($_POST['options']);

		if (empty($Product->slug)) $Product->slug = sanitize_title_with_dashes($_POST['name']);

		// Check for an existing product slug
		$exclude_product = !empty($Product->id)?"AND id != $Product->id":"";
		$existing = $db->query("SELECT slug FROM $Product->_table WHERE slug='$Product->slug' $exclude_product LIMIT 1");
		if ($existing) {
			$suffix = 2;
			while($existing) {
				$altslug = substr($Product->slug, 0, 200-(strlen($suffix)+1)). "-".$suffix++;
				$existing = $db->query("SELECT slug FROM $Product->_table WHERE slug='$altslug' $exclude_product LIMIT 1");
			}
			$Product->slug = $altslug;
		}

		if ($_POST['status'] == "publish") {
			$publishfields = array('month' => '','date' => '','year' => '','hour'=>'','minute'=>'','meridiem'=>'');
			$publishdate = join('',array_merge($publishfields,$_POST['publish']));
			if (!empty($publishdate)) {
				if ($_POST['publish']['meridiem'] == "PM" && $_POST['publish']['hour'] < 12)
					$_POST['publish']['hour'] += 12;
				$_POST['publish'] = mktime($_POST['publish']['hour'],$_POST['publish']['minute'],0,$_POST['publish']['month'],$_POST['publish']['date'],$_POST['publish']['year']);
			} else {
				unset($_POST['publish']);
				// Auto set the publish date if not set (or more accurately, if set to an irrelevant timestamp)
				if ($Product->publish <= 86400) $Product->publish = time();
			}
		} else {
			unset($_POST['publish']);
			$Product->publish = 0;
		}

		if (isset($_POST['content'])) $_POST['description'] = $_POST['content'];

		$Product->updates($_POST,array('categories','prices'));
		$Product->save();

		$Product->save_categories($_POST['categories']);
		$Product->save_tags(explode(",",$_POST['taglist']));

		if (!empty($_POST['price']) && is_array($_POST['price'])) {

			// Delete prices that were marked for removal
			if (!empty($_POST['deletePrices'])) {
				$deletes = array();
				if (strpos($_POST['deletePrices'],","))	$deletes = explode(',',$_POST['deletePrices']);
				else $deletes = array($_POST['deletePrices']);

				foreach($deletes as $option) {
					$Price = new Price($option);
					$Price->delete();
				}
			}

			// Save prices that there are updates for
			foreach($_POST['price'] as $i => $option) {
				if (empty($option['id'])) {
					$Price = new Price();
					$option['product'] = $Product->id;
				} else $Price = new Price($option['id']);
				$option['sortorder'] = array_search($i,$_POST['sortorder'])+1;

				// Remove VAT amount to save in DB
				if ($base['vat'] && isset($option['tax']) && $option['tax'] == "on") {
					$option['price'] = (floatvalue($option['price'])/(1+$taxrate));
					$option['saleprice'] = (floatvalue($option['saleprice'])/(1+$taxrate));
				}
				$option['shipfee'] = floatvalue($option['shipfee']);

				$option['weight'] = floatvalue($option['weight']);
				if (isset($options['dimensions']) && is_array($options['dimensions']))
					foreach ($option['dimensions'] as &$dimension)
						$dimension = floatvalue($dimension);

				$Price->updates($option);
				$Price->save();

				if (!empty($option['download'])) $Price->attach_download($option['download']);

				if (!empty($option['downloadpath'])) { // Attach file specified by URI/path
					if (!empty($Price->download->id) || (empty($Price->download) && $Price->load_download())) {
						$File = $Price->download;
					} else $File = new ProductDownload();

					$stored = false;
					$tmpfile = sanitize_path($option['downloadpath']);

					$File->storage = false;
					$Engine = $File->_engine(); // Set engine from storage settings

					$File->parent = $Price->id;
					$File->context = "price";
					$File->type = "download";
					$File->name = !empty($option['downloadfile'])?$option['downloadfile']:basename($tmpfile);
					$File->filename = $File->name;

					if ($File->found($tmpfile)) {
						$File->uri = $tmpfile;
						$stored = true;
					} else $stored = $File->store($tmpfile,'file');

					if ($stored) {
						$File->readmeta();
						$File->save();
					}

				} // END attach file by path/uri
			}
			unset($Price);
		}

		// No variation options at all, delete all variation-pricelines
		if (!empty($Product->prices) && is_array($Product->prices)
				&& (empty($_POST['options']['v']) || empty($_POST['options']['a']))) {
			foreach ($Product->prices as $priceline) {
				// Skip if not tied to variation options
				if ($priceline->optionkey == 0) continue;
				if ((empty($_POST['options']['v']) && $priceline->context == "variation")
					|| (empty($_POST['options']['a']) && $priceline->context == "addon")) {
						$Price = new Price($priceline->id);
						$Price->delete();
				}
			}
		}

		if (!empty($_POST['details']) || !empty($_POST['deletedSpecs'])) {
			$deletes = array();
			if (!empty($_POST['deletedSpecs'])) {
				if (strpos($_POST['deletedSpecs'],","))	$deletes = explode(',',$_POST['deletedSpecs']);
				else $deletes = array($_POST['deletedSpecs']);
				foreach($deletes as $option) {
					$Spec = new Spec($option);
					$Spec->delete();
				}
				unset($Spec);
			}

			if (is_array($_POST['details'])) {
				foreach ($_POST['details'] as $i => $spec) {
					if (in_array($spec['id'],$deletes)) continue;
					if (isset($spec['new'])) {
						$Spec = new Spec();
						$spec['id'] = '';
						$spec['parent'] = $Product->id;
					} else $Spec = new Spec($spec['id']);
					$spec['sortorder'] = array_search($i,$_POST['details-sortorder'])+1;

					$Spec->updates($spec);
					$Spec->save();
				}
			}
		}

		if (!empty($_POST['deleteImages'])) {
			$deletes = array();
			if (strpos($_POST['deleteImages'],","))	$deletes = explode(',',$_POST['deleteImages']);
			else $deletes = array($_POST['deleteImages']);
			$Product->delete_images($deletes);
		}

		if (!empty($_POST['images']) && is_array($_POST['images'])) {
			$Product->link_images($_POST['images']);
			$Product->save_imageorder($_POST['images']);
			if (!empty($_POST['imagedetails']))
				$Product->update_images($_POST['imagedetails']);
		}

		do_action_ref_array('ecart_product_saved',array(&$Product));

		unset($Product);
		return true;
	}
Example #22
0
	/**
	 * Adds a specified quantity to the line item
	 *	 
	 * @since 1.1
	 *
	 * @return void
	 **/
	function add ($qty) {
		if ($this->type == "Donation" && $this->donation['var'] == "on") {
			$qty = floatvalue($qty);
			$this->quantity = $this->unitprice;
		}
		$this->quantity($this->quantity+$qty);
	}
Example #23
0
 function updatehetongfahuo($dingdanid)
 {
     $sql = "select sum(jine) as jine from sellcontract_jiaofu where hetongid={$dingdanid}";
     $rs = $this->db->Execute($sql);
     $rs_a = $rs->GetArray();
     $jine = floatvalue($rs_a[0]['jine']);
     $sql = "update sellplanmain set fahuojine={$jine} where billid={$dingdanid}";
     $rs = $this->db->Execute($sql);
     $sellplaninfo = returntablefield("sellplanmain", "billid", $dingdanid, "fahuostate,totalmoney,ifpay,fahuojine,kaipiaostate,user_flag");
     $fahuostate = $sellplaninfo['fahuostate'];
     $ifpay = $sellplaninfo['ifpay'];
     $kaipiaostate = $sellplaninfo['kaipiaostate'];
     $fahuojine = $sellplaninfo['fahuojine'];
     $totalmoney = $sellplaninfo['totalmoney'];
     $user_flag = $sellplaninfo['user_flag'];
     if ($totalmoney == $fahuojine) {
         $fahuostate = 4;
     } else {
         if ($totalmoney > $fahuojine) {
             if ($fahuojine > 0) {
                 $fahuostate = 3;
             } else {
                 $fahuostate = 0;
             }
             //发货状态=需发货
         }
     }
     if ($ifpay == 2 && $fahuostate == 4) {
         //订单状态=完成
         $user_flag = 2;
     } else {
         if ($ifpay == 0 && $fahuostate == 0 && $kaipiaostate <= 2) {
             //订单状态=临时单
             $user_flag = 0;
         } else {
             //订单状态=执行中
             $user_flag = 1;
         }
     }
     $sql = "update sellplanmain set fahuostate={$fahuostate},user_flag={$user_flag} where billid={$dingdanid}";
     $this->db->Execute($sql);
 }