/** * Updates an existing Coupon model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id * @return mixed */ public function actionUpdate($id) { $model = new CouponForm(); $model->scenario = 'update'; if ($model->load(Yii::$app->request->post()) && $model->updateCoupon($id)) { return $this->redirect(['index']); } else { return $this->render('update', ['model' => $model]); } }
/** * get Order's validate attributes and save them in CouponForm model. * @param $category_id * @param $cartItems * @return CouponForm */ public function getOrderModel($category_id, $cartItems) { if ($category_id) { $tmp = []; foreach ($cartItems as $key => $cartItem) { if (is_array($category_id)) { if (in_array($cartItem->sku->item->category_id, $category_id)) { $tmp[$key] = $cartItem; } } else { if ($cartItem->sku->item->category_id == $category_id) { $tmp[$key] = $cartItem; } } } $cartItems = $tmp; } $orderModel = Yii::createObject(CouponForm::className()); if ($cartItems) { //todo $shippingFee $totalPrice = $qty = $shippingFee = 0; foreach ($cartItems as $carItem) { $sku = $carItem->sku; $totalPrice += $carItem->qty * $sku->getPrice(); $qty += $carItem->qty; } } $orderModel->total_price = isset($totalPrice) ? $totalPrice : 0; $orderModel->qty = isset($qty) ? $qty : 0; $orderModel->shippingFee = isset($shippingFee) ? $shippingFee : 0; return $orderModel; }