/** * 新商品 */ public function save() { $item = new Attribute(); $item->cat_id = Input::get('cat_id'); $item->name = Input::get('name'); $item->save(); return redirect()->route('admin.attribute.index'); }
/** * Создает новую модель атрибута. * Если создание прошло успешно - перенаправляет на просмотр. * * @return void */ public function actionCreate() { $model = new Attribute(); if (($data = Yii::app()->getRequest()->getPost('Attribute')) !== null) { $model->setAttributes($data); if ($model->save() && $model->setTypes(Yii::app()->getRequest()->getPost('types', [])) && $model->setMultipleValuesAttributes(explode(PHP_EOL, $model->rawOptions))) { Yii::app()->getUser()->setFlash(yupe\widgets\YFlashMessages::SUCCESS_MESSAGE, Yii::t('StoreModule.store', 'Attribute created')); $this->redirect((array) Yii::app()->getRequest()->getPost('submit-type', ['create'])); } } $this->render('create', ['model' => $model, 'types' => Type::model()->findAll()]); }
/** * Создает новую модель атрибута. * Если создание прошло успешно - перенаправляет на просмотр. * * @return void */ public function actionCreate() { $model = new Attribute(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (($data = Yii::app()->getRequest()->getPost('Attribute')) !== null) { $model->setAttributes($data); if ($model->save()) { Yii::app()->user->setFlash(yupe\widgets\YFlashMessages::SUCCESS_MESSAGE, Yii::t('StoreModule.attribute', 'Атрибут создан.')); $this->redirect((array) Yii::app()->getRequest()->getPost('submit-type', ['create'])); } } $this->render('create', ['model' => $model]); }
public function save() { $attribute = Attribute::model()->findByPk($this->id); if (is_null($attribute)) { // is insert $attribute = new Attribute(); $attribute->attribute_group_id = $this->group; $attribute->sort_order = $this->sortOrder; $attribute->save(); $attributeDescription = new AttributeDescription(); $attributeDescription->attribute_id = $attribute->attribute_id; $attributeDescription->language_id = 1; // TODO: read locale $attributeDescription->name = $this->name; $attributeDescription->save(); } else { $attribute->attribute_group_id = $this->group; $attribute->sort_order = $this->sortOrder; $attribute->save(); $attribute->description->name = $this->name; $attribute->description->save(); } }
public function actionCreate() { $model = new Attribute(); if (isset($_POST['Attribute'])) { $model->setAttributes($_POST['Attribute']); if ($model->save()) { if (Yii::app()->getRequest()->getIsAjaxRequest()) { Yii::app()->end(); } else { $this->redirect(array('view', 'id' => $model->id)); } } } $this->render('create', array('model' => $model)); }
/** * Performs the work of inserting or updating the row in the database. * * If the object is new, it inserts it; otherwise an update is performed. * All related objects are also updated in this method. * * @param ConnectionInterface $con * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. * @throws PropelException * @see save() */ protected function doSave(ConnectionInterface $con) { $affectedRows = 0; // initialize var to track total num of affected rows if (!$this->alreadyInSave) { $this->alreadyInSave = true; // We call the save method on the following object(s) if they // were passed to this object by their corresponding set // method. This object relates to these object(s) by a // foreign key reference. if ($this->aCartItem !== null) { if ($this->aCartItem->isModified() || $this->aCartItem->isNew()) { $affectedRows += $this->aCartItem->save($con); } $this->setCartItem($this->aCartItem); } if ($this->aAttribute !== null) { if ($this->aAttribute->isModified() || $this->aAttribute->isNew()) { $affectedRows += $this->aAttribute->save($con); } $this->setAttribute($this->aAttribute); } if ($this->aAttributeAv !== null) { if ($this->aAttributeAv->isModified() || $this->aAttributeAv->isNew()) { $affectedRows += $this->aAttributeAv->save($con); } $this->setAttributeAv($this->aAttributeAv); } if ($this->isNew() || $this->isModified()) { // persist changes if ($this->isNew()) { $this->doInsert($con); } else { $this->doUpdate($con); } $affectedRows += 1; $this->resetModified(); } $this->alreadyInSave = false; } return $affectedRows; }
public function actionCreate() { $model = new DatasetAttributes(); $att = Attribute::model()->findByAttributes(array('attribute_name' => Attribute::FUP)); if (!$att) { $att = new Attribute(); $att->attribute_name = Attribute::FUP; $att->definition = ''; $att->save(); } $model->attribute_id = $att->id; $image = new Images(); if (isset($_POST['DatasetAttributes'])) { $args = $_POST['DatasetAttributes']; $exist = DatasetAttributes::model()->findByAttributes(array('dataset_id' => $args['dataset_id'], 'attribute_id' => $att->id)); if ($exist) { $model = $exist; } $model->attributes = $args; $model->value = ''; //$image->attributes = $_POST['Images']; $image->license = "no license"; $image->photographer = "no author"; $image->source = "gigadb"; if ($image->validate()) { $image->save(); } else { Yii::log(print_r($image->getErrors(), true), 'debug'); } if ($image) { $model->image_id = $image->id; } if ($model->validate()) { $model->save(); $this->redirect('/dataset/' . $model->dataset->identifier); } else { Yii::log(print_r($model->getErrors(), true), 'debug'); } } $this->render('create', array('model' => $model, 'image' => $image)); }
public function actionCreate() { $model = new Attribute(); $description = new AttributeDescription(); $this->performAjaxValidation(array($model, $description), 'attribute-form'); if (isset($_POST[$this->modelName])) { $model->setAttributes($_POST[$this->modelName]); $description->setAttributes($_POST[$this->modelName . 'Description']); $suc = Yii::t('info', 'Attribute was successfully created'); $err = Yii::t('info', 'Could not update Attribute'); $description->attribute_id = 0; $description->locale_code = Yii::app()->getLanguage(); if ($model->validate() && $description->validate()) { if ($model->save()) { $description->attribute_id = $model->id; $description->save(); Yii::app()->user->setFlash(TbHtml::ALERT_COLOR_SUCCESS, $suc); if (Yii::app()->getRequest()->getIsAjaxRequest()) { $this->renderPartial('_view', array('model' => $model, 'description' => $description), false, true); Yii::app()->end(); } else { $this->redirect(array('view', 'id' => $model->id)); } } else { Yii::app()->user->setFlash(TbHtml::ALERT_COLOR_ERROR, $err); } } else { $description->validate(); } } if (Yii::app()->getRequest()->getIsAjaxRequest()) { $this->renderPartial('_form', array('model' => $model, 'description' => $description), false, true); Yii::app()->end(); } $this->render('create', array('model' => $model, 'description' => $description)); }
public function actionCreate() { $model = new Attribute; $lang_model = new LanguageModel; $AttrDescModel = new AttributeDescription; $ValueModel = new Value; // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); $allLangs = $lang_model->findAll('1', array('order' => 'id ASC')); $allLangsJS = array(); foreach ($allLangs as $language) { $allLangsJS[$language['id']] = $language['code']; } if (isset($_POST['Attribute'])) { $model->attributes = $_POST['Attribute']; if ($model->save()) { $pk = $model->getPrimaryKey(); foreach ($_POST['AttributeDescription']['attribute_name'] as $langId => $attrName) { $attr_desc_model = new AttributeDescription; $attr_desc_model->attributes = array( 'attribute_id' => $pk, 'attribute_name' => $attrName, 'language_id' => $langId, ); $attr_desc_model->save(); } if (isset($_POST['NewAttrValue'])) { foreach ($_POST['NewAttrValue'] as $spec_id => $new_val) { $ValueModel = new Value; $ValueModel->attributes = array( 'status' => 1, ); $ValueModel->save(); $v_id = $ValueModel->getPrimaryKey(); foreach ($new_val as $lang_id => $value) { if ($value != '') { $ValueDescription = new ValueDescription; $ValueDescription->attributes = array( 'value_id' => $v_id, 'language_id' => $lang_id, 'value_name' => $value, ); $ValueDescription->save(); } } $Attribute2value = new Attribute2value; $Attribute2value->attributes = array('attribute_id' => $pk, 'value_id' => $v_id); $Attribute2value->save(); } } $this->redirect(array('index')); } } $this->render('create', array( 'model' => $model, 'allLangs' => $allLangs, 'AttrDescModel' => $AttrDescModel, 'allLangsJS' => json_encode($allLangsJS), )); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionAttributeCreate($class) { $model = new Attribute(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); $class = $this->loadModel($class); $model->id_class = $class->id_class; if (isset($_POST['Attribute'])) { $model->attributes = $_POST['Attribute']; if ($model->save()) { $this->redirect(array('attributeview', 'id' => $model->id_attribute)); } } $this->render('attribute/create', array('model' => $model, 'class' => $class)); }
public function actionAddSampleAttr() { if (isset($_POST['sample_id']) && isset($_POST['attr_id']) && isset($_POST['attr_value']) && isset($_POST['attr_unit'])) { if (strlen($_POST['attr_id']) < 3) { Util::returnJSON(array("success" => false, "message" => Yii::t("app", "Please enter an Attribute name with more than 3 characters."))); } $lastSa = SampleAttribute::model()->find(array('order' => 'id desc')); $sa = new SampleAttribute(); if ($lastSa) { $sa->id = $lastSa->id + 1; } // try to find attribute, if not found, create a new one $attr = Attribute::model()->findByAttributes(array('attribute_name' => $_POST['attr_id'])); if (!$attr) { #create new attribute $attr = new Attribute(); $attr->attribute_name = $_POST['attr_id']; $attr->save(false); } $sa->sample_id = $_POST['sample_id']; $sa->attribute_id = $attr->id; $sa->value = $_POST['attr_value']; if (isset($_POST['attr_unit']) && $_POST['attr_unit'] != "") { $sa->unit_id = $_POST['attr_unit']; } if ($sa->save()) { Util::returnJSON(array("success" => true)); } Util::returnJSON(array("success" => false, "message" => Yii::t("app", "Cannot add sample attr."))); } }
/** * Upate sample attribute * * @param Sample $model */ private function updateSampleAttributes($model) { // delete first all the sample Attribute SampleAttribute::model()->deleteAllByAttributes(array('sample_id' => $model->id)); if (trim($model->attributesList)) { // From a model we will clone $sampleAttr = new SampleAttribute(); $sampleAttr->sample_id = $model->id; foreach (explode(',', $model->attributesList) as $sAttr) { $sAttr = str_replace('"', '', $sAttr); $data = explode('=', $sAttr); if (count($data) == 2) { // Get attribute, if not exist we create $attribute = Attribute::model()->findByAttributes(array('structured_comment_name' => trim($data[0]))); if (!$attribute) { $attribute = new Attribute(); $attribute->structured_comment_name = trim($data[0]); $attribute->attribute_name = str_replace('_', ' ', trim($data[0])); $attribute->definition = str_replace('_', ' ', trim($data[0])); $attribute->save(); } // Let's save the new sample attribute $sampleAttribute = clone $sampleAttr; $sampleAttribute->value = trim($data[1]); $sampleAttribute->attribute_id = $attribute->id; $sampleAttribute->save(); } } } }
public function saveSpec($spec, $product_id, $category_id, $type_id) { $name = \yupe\helpers\YText::translit($spec['name']); if (!in_array($name, $this->attr_name)) { if ($category_id) { // добавим в характеристику id категории $name = $name . $category_id; } else { print_r(" Error: can`t find StoreCategory for {$spec['id_product']} \n"); return; } } $model = Attribute::model()->findByAttributes(['name' => $name]); if (!$model) { $model = new Attribute(); $model->group_id = 1; $model->name = $name; $model->title = $spec['name']; $model->type = Attribute::TYPE_DROPDOWN; if ($model->save()) { $option = new AttributeOption(); $option->attribute_id = $model->id; $option->position = 0; $option->value = $spec['value']; if (!$option->save()) { echo "\n"; echo "Error: save AttributeOption for {$name} \n"; echo "\n"; } $TypeAttribute = new TypeAttribute(); $TypeAttribute->type_id = $type_id; $TypeAttribute->attribute_id = $model->id; if (!$TypeAttribute->save()) { echo "\n"; echo "Error: save TypeAttribute for {$name} \n"; echo "\n"; } } else { echo "\n"; echo "Error: save Attribute for {$name} \n"; echo "\n"; return; } } else { $this->addOption($spec, $model); } // свяжем продукт со значением характеристики $option = AttributeOption::model()->findByAttributes(['attribute_id' => $model->id, 'value' => $spec['value']]); if ($option) { $id = $option->id; $name = $model->name; $command = \Yii::app()->db->createCommand("\n INSERT INTO `site_store_product_attribute_eav` (`product_id`, `attribute`, `value`) \n VALUES ({$product_id}, '{$name}', {$id})\n ")->execute(); } }