Skip to content

Commit

Permalink
added support for duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
sanderha committed May 9, 2019
1 parent efecf0d commit e96a9aa
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
13 changes: 13 additions & 0 deletions code/extensions/ProductOptionsExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,17 @@ public function contentcontrollerInit($controller)
$controller->formclass = 'SimpleOptionsForm';
}
}

public function onAfterDuplicate($original, $doWrite)
{
$options = $original->ProductOptions();
if(!$options->exists()){
return;
}

foreach ($options as $option){
$clonedOption = $option->duplicate();
$this->owner->ProductOptions()->add($clonedOption);
}
}
}
17 changes: 17 additions & 0 deletions code/model/SimpleProductOption.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,21 @@ public static function getFormFieldName($id)
{
return 'ProductOptions_' . $id;
}

public function duplicate($doWrite = true)
{
$clone = parent::duplicate($doWrite);

$values = $this->Values();
if ($values->exists()) {
foreach ($values as $value) {
$clonedVal = $value->duplicate();
$clone->Values()->add($clonedVal);
}
}

$clone->invokeWithExtensions('onAfterDuplicate', $this, $doWrite);

return $clone;
}
}

0 comments on commit e96a9aa

Please sign in to comment.