public function loadModel($id) { if (($model = AttributeDescription::model()->findByPk($id)) === null) { throw new CHttpException(404, 'Страница не найдена'); } return $model; }
public function actionAutocomplete($query) { // TODO: add locale $descriptions = AttributeDescription::model()->findAll("name LIKE '%{$query}%' "); foreach ($descriptions as $description) { $json[] = array('id' => $description->attribute_id, 'value' => $description->name); } echo CJSON::encode($json); }
public function actionAutocomplete($query) { $json = array(); // TODO: add locale $language_id = 1; $descriptions = AttributeDescription::model()->findAll("name LIKE '%{$query}%' AND language_id={$language_id}"); foreach ($descriptions as $description) { $json[] = array('id' => $description->attribute_id, 'value' => $description->attribute->getName(true)); } echo CJSON::encode($json); }
/** * Deletes a particular model. * If deletion is successful, the browser will be redirected to the 'admin' page. * @param integer $id the ID of the model to be deleted */ public function actionDelete($id) { $this->loadModel($id)->delete(); AttributeDescription::model()->deleteAll('attribute_id=' . $id); $Attribute2value = $this->loadAttrToValModel('attribute_id=' . $id); foreach ($Attribute2value as $record) { Value::model()->deleteAll('value_id=' . $record['value_id']); ValueDescription::model()->deleteAll('value_id=' . $record['value_id']); } Attribute2value::model()->deleteAll('attribute_id=' . $id); // if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser if (!isset($_GET['ajax'])) $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('index')); }
public function afterDelete() { // delete dependencies AttributeDescription::model()->deleteAll("attribute_id={$this->cacheId}"); parent::afterDelete(); }
public function actionGetProductDetails() { $c = new CDbCriteria(); if ($_GET['product_id']) { // make a record counter + 1 that product was viewed one more time $temp_product = Product::model()->findByPk($_GET['product_id']); $temp_product->attributes = array('viewed_counter' => $temp_product->attributes['viewed_counter'] + 1); $temp_product->save(); //end //get details $c->with = array('product_description', 'variations' => array('with' => array('variation_description')), 'category2product'); //$c->together = true; $c->compare('t.product_id', $_GET['product_id']); $c->compare('t.status', 1); } $product = Product::model()->find($c); if ($product['variations']) { foreach ($product['variations'] as &$variation) { $attrs = array(); $attributes = Variation2attribute::model()->findAllByAttributes(array('variation_id' => $variation->variation_id)); $values = Variation2value::model()->findAllByAttributes(array('variation_id' => $variation->variation_id)); foreach ($attributes as $attribute) { //get attribute name $c = new CDbCriteria(); $c->together = true; $c->compare('t.attribute_id', $attribute->attribute_id); $c->compare('language_id', LanguageModel::getLanguageIdByCode(Yii::app()->language)); $attribute_desc = AttributeDescription::model()->find($c); $attrs[$attribute->attribute_id] = array('name' => $attribute_desc->attribute_name); } foreach ($values as $value) { //get attribute id for current value $c = new CDbCriteria(); $c->compare('value_id', $value->value_id); $attr2value = Attribute2value::model()->find($c); //get value name $c = new CDbCriteria(); $c->together = true; $c->compare('`t`.value_id', $value->value_id); $c->compare('language_id', LanguageModel::getLanguageIdByCode(Yii::app()->language)); $value_desc = ValueDescription::model()->find($c); $attrs[$attr2value->attribute_id]['value'] = $value_desc->value_name; } $variation->attributes = $attrs; } } $this->renderPartial('product_details', array('data' => $product)); }