public function loadAttrToValModel($condition)
 {
     $model = Attribute2value::model()->findAll($condition);
     if ($model === null)
         throw new CHttpException(404, 'The requested page does not exist.');
     return $model;
 }
Example #2
0
 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));
 }