public function removeFromCart(Request $request, $itemId) { if ($request->session()->has(self::CART_ID)) { $cart = Cart::find($request->session()->get(self::CART_ID)); $item = $cart->items()->where('id', $itemId)->first(); $item->delete(); } return $this->success(); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Cart::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'user_id' => $this->user_id, 'product_id' => $this->product_id, 'number' => $this->number, 'price' => $this->price, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]); $query->andFilterWhere(['like', 'session_id', $this->session_id])->andFilterWhere(['like', 'name', $this->name]); return $dataProvider; }
public function actionCheckout() { $userId = Yii::$app->user->id; $addresses = Address::find()->where(['user_id' => $userId])->all(); $model = new Order(); $products = Cart::find()->where(['session_id' => Yii::$app->session->id])->all(); if (!count($products)) { return $this->redirect('/cart'); } if (count($addresses)) { return $this->render('checkout', ['model' => $model, 'addresses' => $addresses, 'products' => $products]); } else { return $this->redirect(['cart/address']); } }
public function thankYou(Request $request) { $cartId = $request->input('cart-id'); $cart = Cart::find($cartId); $token = $request->input('token-id'); if (!$cartId || !$cart || !$token) { Log::error("Thank you page accessed with no token-id or invalid cart"); return redirect('/'); } if ($cart->status != Cart::STATUS_CLOSED) { $util = new PaylineUtility(); $errors = $util->stepThree($token); if (!is_null($errors)) { return redirect('/my-cart?section=billing&error=' . urlencode($errors)); } $cart->status = Cart::STATUS_CLOSED; $cart->save(); $mailer = new EmailUtil(); $mailer->sendReceipt($cart); } return response()->view('thankYou', array('cartId' => $cartId, 'cartItemCount' => 0)); }