protected function findModel($id)
 {
     if (($model = Element::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Beispiel #2
0
 public function search($params)
 {
     $query = Element::find()->orderBy('id DESC');
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => 'id ASC', 'attributes' => ['id']], 'pagination' => false]);
     $this->load($params);
     if (!$this->validate()) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'order_id' => $this->order_id]);
     return $dataProvider;
 }
 public function actionPushElements($id, $push_cart = false)
 {
     $model = $this->findModel($id);
     if ($elements = yii::$app->cart->elements) {
         foreach ($elements as $element) {
             $count = $element->getCount();
             $orderElementModel = new Element();
             $orderElementModel->order_id = $model->id;
             $orderElementModel->is_assigment = $model->is_assigment;
             $orderElementModel->model = $element->getModel(false);
             $orderElementModel->item_id = $element->getItemId();
             $orderElementModel->count = $count;
             $orderElementModel->base_price = $element->getPrice(false);
             $orderElementModel->price = $element->getPrice();
             $orderElementModel->options = json_encode($element->getOptions());
             $orderElementModel->description = '';
             $orderElementModel->save();
             $element->getModel()->minusAmount($count);
         }
         yii::$app->cart->truncate();
     }
     $this->redirect(['/order/order/view', 'id' => $id]);
 }
Beispiel #4
0
 public static function editField($id, $name, $value)
 {
     $setting = Element::findOne($id);
     $setting->{$name} = $value;
     $setting->save();
 }
Beispiel #5
0
 public function beforeDelete()
 {
     foreach ($this->hasMany(Element::className(), ['order_id' => 'id'])->all() as $elem) {
         $elem->delete();
     }
     foreach ($this->hasMany(FieldValue::className(), ['order_id' => 'id'])->all() as $val) {
         $val->delete();
     }
     return parent::beforeDelete();
 }