Ejemplo n.º 1
0
 public function __clone()
 {
     parent::__clone();
     $original = $this->originalRecord;
     $original->loadSpecification();
     $this->specificationInstance = clone $original->getSpecification();
     $this->specificationInstance->setOwner($this);
     $original->loadPricing();
     $this->pricingHandlerInstance = clone $original->pricingHandlerInstance;
     $this->pricingHandlerInstance->setProduct($this);
     $this->save();
     // images
     if ($original->defaultImage->get()) {
         foreach ($original->getRelatedRecordSet('ProductImage', $original->getImageFilter()) as $image) {
             $image->_clone($this);
         }
     }
     // options
     foreach (ProductOption::getProductOptions($original) as $option) {
         $clonedOpt = clone $option;
         $clonedOpt->product->set($this);
         $clonedOpt->save();
     }
     // related products
     $groups[] = array();
     foreach ($original->getRelationships() as $relationship) {
         $group = $relationship->productRelationshipGroup->get();
         $id = $group ? $group->getID() : null;
         if ($id) {
             $groups[$id] = clone $group;
             $groups[$id]->product->set($this);
             $groups[$id]->save();
         }
         $cloned = ProductRelationship::getNewInstance($this, $relationship->relatedProduct->get(), $id ? $groups[$id] : null);
         $cloned->save();
     }
 }
Ejemplo n.º 2
0
 public function __clone()
 {
     parent::__clone();
     $this->choices = null;
     $this->save();
     $defaultChoice = $this->originalRecord->defaultChoice->get();
     foreach ($this->originalRecord->getChoiceSet() as $choice) {
         $newChoice = clone $choice;
         $newChoice->option->set($this);
         $newChoice->save();
         if ($defaultChoice && $choice->getID() == $defaultChoice->getID()) {
             $this->defaultChoice->set($newChoice);
         }
     }
     $this->save();
 }
Ejemplo n.º 3
0
 public function __clone()
 {
     parent::__clone();
     $original = $this->originalRecord;
     $original->loadSpecification();
     $this->specificationInstance = clone $original->getSpecification();
     $this->specificationInstance->setOwner($this);
     $original->loadPricing();
     $this->pricingHandlerInstance = clone $original->pricingHandlerInstance;
     $this->pricingHandlerInstance->setProduct($this);
     $this->save();
     // images
     if ($original->defaultImage->get()) {
         foreach ($original->getRelatedRecordSet('ProductImage', $original->getImageFilter()) as $image) {
             $image->_clone($this);
         }
     }
     // options
     foreach (ProductOption::getProductOptions($original) as $option) {
         $clonedOpt = clone $option;
         $clonedOpt->product->set($this);
         $clonedOpt->save();
     }
     // variations
     $variations = $original->getRelatedRecordSet('Product');
     if ($variations->size()) {
         $idMap = array();
         foreach ($original->getRelatedRecordSet('ProductVariationType') as $type) {
             $newType = clone $type;
             $newType->product->set($this);
             $newType->save();
             foreach ($type->getRelatedRecordSet('ProductVariation') as $var) {
                 $newVar = clone $var;
                 $newVar->type->set($newType);
                 $newVar->save();
                 $idMap[$var->getID()] = $newVar->getID();
             }
         }
         foreach ($variations as $variation) {
             $newVariation = clone $variation;
             $newVariation->parent->set($this);
             $newVariation->save();
             foreach ($variation->getRelatedRecordSet('ProductVariationValue') as $value) {
                 $newValue = clone $value;
                 $newValue->product->set($newVariation);
                 $newValue->variation->set(ActiveRecordModel::getInstanceByID('ProductVariation', $idMap[$value->variation->get()->getID()], true));
                 $newValue->save();
             }
         }
     }
     // additional categories
     foreach ($original->getRelatedRecordSet('ProductCategory') as $additionalCat) {
         $newCat = clone $additionalCat;
         $newCat->product->set($this);
         $newCat->save();
     }
     // related products
     $groups[] = array();
     foreach ($original->getRelationships() as $relationship) {
         $group = $relationship->productRelationshipGroup->get();
         $id = $group ? $group->getID() : null;
         if ($id) {
             $groups[$id] = clone $group;
             $groups[$id]->product->set($this);
             $groups[$id]->save();
         }
         $cloned = ProductRelationship::getNewInstance($this, $relationship->relatedProduct->get(), $id ? $groups[$id] : null);
         $cloned->save();
     }
 }
Ejemplo n.º 4
0
 public function __clone()
 {
     parent::__clone();
     foreach ($this->optionChoices as $key => $option) {
         $newOpt = clone $option;
         $newOpt->orderedItem->set($this);
         $newOpt->choice->setAsModified();
         $this->optionChoices[$key] = $newOpt;
     }
 }