protected function refreshEavAttributes() { $attachedEavAttributes = $this->attachedEavAttributes; $oldEavAttributes = EavAttributeToSet::model()->findAllByAttributes(array('eav_set_id' => $this->id)); $orderArray = CHtml::listData($oldEavAttributes, 'eav_attribute_id', 'weight'); EavAttributeToSet::model()->deleteAllByAttributes(array('eav_set_id' => $this->id)); if (is_array($attachedEavAttributes)) { $counter = end($orderArray) + 10; //var_dump($counter); //exit(); foreach ($attachedEavAttributes as $key => $id) { if (EavAttribute::model()->exists('t.id = :id', array(':id' => $id))) { $rel = new EavAttributeToSet(); $rel->eav_set_id = $this->id; $rel->eav_attribute_id = $id; if (key_exists($id, $orderArray)) { $rel->weight = $orderArray[$id]; } else { $rel->weight = $counter; $counter += 10; } $rel->save(); } } } }
protected function refreshEavAttributes() { $attachedEavAttributes = $this->attachedEavAttributes; $oldEavAttributes = EavAttributeToSet::model()->findAllByAttributes(['eav_set_id' => $this->id], ['order' => 't.weight ASC']); $orderArray = CHtml::listData($oldEavAttributes, 'eav_attribute_id', 'weight'); $oldList = CHtml::listData($oldEavAttributes, 'eav_attribute_id', function ($data) { return $data; }); EavAttributeToSet::model()->deleteAllByAttributes(['eav_set_id' => $this->id]); if (is_array($attachedEavAttributes)) { $counter = end($orderArray) + 10; foreach ($attachedEavAttributes as $key => $id) { if (EavAttribute::model()->exists('t.id = :id', [':id' => $id])) { $rel = new EavAttributeToSet(); $rel->eav_set_id = $this->id; $rel->eav_attribute_id = $id; if (key_exists($id, $oldList)) { $rel->attributes = $oldList[$id]->attributes; } else { $rel->weight = $counter; $counter += 10; } //var_dump($rel); //echo '<hr>'; $rel->save(); } } } }
protected function refreshEavAttributes() { $attachedEavAttributes = $this->attachedEavAttributes; EavAttributeToSet::model()->deleteAllByAttributes(array('set_id' => $this->id)); if (is_array($attachedEavAttributes)) { foreach ($attachedEavAttributes as $id) { if (EavAttribute::model()->exists('t.id = :id', array(':id' => $id))) { $rel = new EavAttributeToSet(); $rel->set_id = $this->id; $rel->attribute_id = $id; $rel->save(); } } } }