Example #1
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));
 }
Example #2
0
 public function actionDelete($id)
 {
     $this->loadModel($id)->delete();
     ProductDescription::model()->deleteAll('product_id=' . $id);
     Category2product::model()->deleteAll('product_id=' . $id);
     $aVariations = Product2variation::model()->findAll('product_id=' . $id);
     foreach ($aVariations as $variation) {
         Variation::model()->deleteAll('variation_id=' . $variation['variation_id']);
         VariationDescription::model()->deleteAll('variation_id=' . $variation['variation_id']);
         Variation2attribute::model()->deleteAll('variation_id=' . $variation['variation_id']);
         Variation2value::model()->deleteAll('variation_id=' . $variation['variation_id']);
     }
     Product2variation::model()->deleteAll('product_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'));
 }