From 98d547a5baec5b3f80d4446d1a396a62f9a93f95 Mon Sep 17 00:00:00 2001 From: FajeSu Date: Wed, 7 Dec 2016 17:13:11 +0300 Subject: [PATCH] =?UTF-8?q?Bug=20#217:=20=D0=98=D1=81=D0=BF=D1=80=D0=B0?= =?UTF-8?q?=D0=B2=D0=BB=D0=B5=D0=BD=20=D0=B1=D0=B0=D0=B3=20=D0=BE=D0=B1?= =?UTF-8?q?=D0=BD=D0=BE=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=BF=D1=80?= =?UTF-8?q?=D0=B8=D0=B2=D1=8F=D0=B7=D0=BE=D0=BA=20=D0=BC=D0=BE=D0=B4=D0=B8?= =?UTF-8?q?=D1=84=D0=B8=D0=BA=D0=B0=D1=86=D0=B8=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../behaviors/BModificationBehavior.php | 30 ++++++++++++++----- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/backend/protected/modules/product/models/behaviors/BModificationBehavior.php b/backend/protected/modules/product/models/behaviors/BModificationBehavior.php index 27fb7694..26e9d168 100644 --- a/backend/protected/modules/product/models/behaviors/BModificationBehavior.php +++ b/backend/protected/modules/product/models/behaviors/BModificationBehavior.php @@ -61,16 +61,16 @@ public function beforeSave($event) { $this->owner->detachEventHandler('onAfterSave', array(Yii::app()->controller, 'saveProductAssignment')); - $model = BProductAssignment::model(); - - $assignments = array(); - foreach($model->getFields() as $field) - { - $attribute = $field->name; - $assignments[$attribute] = $this->getParentModel()->{$attribute}; + if( $this->owner->isNewRecord ) { + $this->owner->getEventHandlers('onAfterSave')->insertAt(1, array($this, 'saveModificationAssignment')); } + } + } - $model->saveAssignments($this->owner, $assignments); + public function afterSave($event) + { + foreach($this->getModifications() as $modification) { + $modification->saveModificationAssignment(); } } @@ -140,6 +140,20 @@ private function attachRelations() )); } + protected function saveModificationAssignment() + { + $model = BProductAssignment::model(); + + $assignments = array(); + foreach($model->getFields() as $field) + { + $attribute = $field->name; + $assignments[$attribute] = $this->getParentModel()->{$attribute}; + } + + $model->saveAssignments($this->owner, $assignments); + } + protected function onAfterRenderTableRow(CEvent $event) { if( empty($this->owner->modifications) || Yii::app()->controller->popup)