public function doSave($con = null) { $pk = $this->getQuery()->execute()->getPrimaryKeys(); Doctrine_Query::create()->delete('ParameterProductOption ppo')->where('product_id = ?', $this->getObject()->getId())->whereIn('option_id', $pk)->execute(); if (is_array($this->getValue('parameter_options_list'))) { foreach ($this->getValue('parameter_options_list') as $paramOptionID) { $ppo = new ParameterProductOption(); $ppo->fromArray(array('product_id' => $this->getObject()->id, 'option_id' => $paramOptionID)); $ppo->save(); } } else { $ppo = new ParameterProductOption(); $ppo->fromArray(array('product_id' => $this->getObject()->id, 'option_id' => $this->getValue('parameter_options_list'))); $ppo->save(); } }
public function executeCopyProduct($request) { $product = $this->getRoute()->getObject(); # copy product main information $newProduct = $product->copy(); $newProduct['code'] = $product['code'] . '_new_' . rand(1, 100000); ## copy product Translations $transArr = $product->Translation->toArray(); foreach ($transArr as $index => &$transVal) { unset($transVal['id']); } $newProduct->Translation->fromArray($transArr); $newProduct->save(); # copy product connections with ProductGroups foreach ($product->ProductGroups as $prodGroup) { $rel = new ProductVsProductGroup(); $rel['group_id'] = $prodGroup['group_id']; $rel['product_id'] = $newProduct['id']; $rel->save(); } # copy product connections with ParameterProductOptions foreach ($product->ParameterProductOptions as $prodGroup) { $rel = new ParameterProductOption(); $rel['option_id'] = $prodGroup['option_id']; $rel['product_id'] = $newProduct['id']; $rel->save(); } # copy product connections with ParameterProductValues and their Translations foreach ($product->ParameterProductValues as $prodValue) { $rel = new ParameterProductValue(); $arr = $prodValue->toArray(); $arr['Translation'] = $prodValue->Translation->toArray(); foreach ($arr['Translation'] as $lang => &$transArr) { unset($transArr['id']); } unset($arr['id']); $rel->fromArray($arr); $rel['product_id'] = $newProduct['id']; $rel->save(); } $this->redirect(array('sf_route' => $this->helper->getEditRoute(), 'sf_subject' => $newProduct)); }