function duplicate () { $db =& DB::get(); $this->load_data(array('prices','specs','categories','tags','images','taxes'=>'false')); $this->id = ''; $this->name = $this->name.' '.__('copy','Ecart'); $this->slug = sanitize_title_with_dashes($this->name); // Check for an existing product slug $existing = $db->query("SELECT slug FROM $this->_table WHERE slug='$this->slug' LIMIT 1"); if ($existing) { $suffix = 2; while($existing) { $altslug = substr($this->slug, 0, 200-(strlen($suffix)+1)). "-$suffix"; $existing = $db->query("SELECT slug FROM $this->_table WHERE slug='$altslug' LIMIT 1"); $suffix++; } $this->slug = $altslug; } $this->created = ''; $this->modified = ''; $this->save(); // Copy prices foreach ($this->prices as $price) { $Price = new Price(); $Price->updates($price,array('id','product','created','modified')); $Price->product = $this->id; $Price->save(); } // Copy sepcs foreach ($this->specs as $spec) { $Spec = new Spec(); $Spec->updates($spec,array('id','parent','created','modified')); $Spec->parent = $this->id; $Spec->save(); } // Copy categories $categories = array(); foreach ($this->categories as $category) $categories[] = $category->id; $this->categories = array(); $this->save_categories($categories); // Copy tags $taglist = array(); foreach ($this->tags as $tag) $taglist[] = $tag->name; $this->tags = array(); $this->save_tags($taglist); // Copy product images foreach ($this->images as $ProductImage) { $Image = new ProductImage(); $Image->updates($ProductImage,array('id','parent','created','modified')); $Image->parent = $this->id; $Image->save(); } }