예제 #1
0
 /**
  * Saves generated stats to the product record
  *
  * @author Jonathan Davis
  * @since 1.2
  *
  * @param array $stats The stat properties to update
  * @return void
  **/
 public function sumup()
 {
     if (empty($this->id)) {
         return;
     }
     $Summary = new ProductSummary();
     $properties = array_keys($Summary->_datatypes);
     $minmax = array('min', 'max');
     $ignore = array('product', 'modified');
     $checksum = false;
     foreach ($properties as $property) {
         if ($property[0] == '_') {
             continue;
         }
         if (in_array($property, $ignore)) {
             continue;
         }
         switch ($property) {
             case 'minprice':
                 $this->minprice = (double) $this->min[Shopp::str_true($this->sale) ? 'saleprice' : 'price'];
                 break;
             case 'maxprice':
                 $this->maxprice = (double) $this->max[Shopp::str_true($this->sale) ? 'saleprice' : 'price'];
                 break;
             case 'ranges':
                 $ranges = array();
                 foreach ($minmax as $m) {
                     $attr = $this->{$m};
                     foreach (ProductSummary::$_ranges as $name) {
                         if (isset($attr[$name])) {
                             $ranges[] = (double) $attr[$name];
                         }
                     }
                 }
                 break;
             case 'taxed':
                 $taxable = array('price', 'saleprice');
                 $taxed = array();
                 foreach ($minmax as $m) {
                     $attr = $this->{$m};
                     foreach ($taxable as $name) {
                         if (isset($attr[$name . '_tax']) && $attr[$name . '_tax']) {
                             $taxed[] = "{$m} {$name}";
                         }
                     }
                 }
                 break;
             default:
         }
         if (isset($this->{$property})) {
             if ('float' == $Summary->_datatypes[$property]) {
                 $checksum .= (double) $this->{$property};
             } else {
                 $checksum .= $this->{$property};
             }
         }
     }
     if (md5($checksum) == $this->checksum) {
         return;
     }
     $Summary->copydata($this);
     if (isset($this->summed)) {
         $Summary->modified = $this->summed;
     }
     $Summary->product = $this->id;
     $Summary->ranges = join(',', $ranges);
     $Summary->taxed = join(',', $taxed);
     $Summary->save();
 }