From b213c447f6c88388e358e66aa6a4757a0a1b7152 Mon Sep 17 00:00:00 2001 From: suseendhiran17 <58357088+suseendhiran17@users.noreply.github.com> Date: Sat, 3 Jun 2023 16:06:04 +0530 Subject: [PATCH] suseendhiran --- app/Config/Routes.php | 1 + app/Controllers/Cart_controller.php | 41 +++++++++++++++++- app/Controllers/Test_controller.php | 19 ++++++++- app/Views/cart.php | 19 ++++++--- app/Views/layout/header.php | 1 - app/Views/member_layout/header.php | 64 +++++++++++++++++------------ app/Views/membership.php | 3 +- 7 files changed, 109 insertions(+), 39 deletions(-) diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 936c3fb..2dc95bb 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -110,6 +110,7 @@ $routes->match(['get','post'],'/add_package_cartdata','Cart_controller::add_pack $routes->match(['get','post'],'/view_cart/(:any)','Cart_controller::view_cart/$1'); $routes->match(['get','post'],'/continue_shopping/(:any)','Cart_controller::continue_shopping/$1'); $routes->match(['get','post'],'/remove_product/(:any)','Cart_controller::remove_product/$1'); +$routes->match(['get','post'],'/change_count_onclick','Cart_controller::change_count_onclick'); $routes->match(['get','post'],'/test/(:any)','Test_controller::index/$1'); diff --git a/app/Controllers/Cart_controller.php b/app/Controllers/Cart_controller.php index 4f62228..ddf932f 100644 --- a/app/Controllers/Cart_controller.php +++ b/app/Controllers/Cart_controller.php @@ -48,13 +48,38 @@ class Cart_controller extends BaseController if ($this->request->getVar('c_token')) { $tokendata = $this->Cart_token_model->where('md5(token)', $this->request->getVar('c_token') )->find(); $data['token'] = $tokendata[0]['token']; + + foreach ($tokendata as $key => $value) + { + if ($value['primary_id'] == $this->request->getVar('id')) + { + $count = $tokendata[$key]['count'] + 1; + $this->Cart_token_model->where('id', $tokendata[$key]['id'] )->set(array( 'count' => $count ))->update(); + } + else + { + if (count($tokendata) == 1) + { + $data['primary_id'] = $this->request->getVar('id'); + $data['table_name'] = 'packages_and_pricing'; + $data['count'] = 1; + $this->Cart_token_model->save($data); + } + } + } } - else { + else + { $data['token'] = $token; - } + $data['primary_id'] = $this->request->getVar('id'); $data['table_name'] = 'packages_and_pricing'; + $data['count'] = 1; $this->Cart_token_model->save($data); + + } + + if ($this->request->getVar('c_token')) { $tokendata = $this->Cart_token_model->where('md5(token)', $this->request->getVar('c_token') )->find(); $data['token'] = md5($tokendata[0]['token']); @@ -102,6 +127,18 @@ class Cart_controller extends BaseController $deletedata = $this->Cart_token_model->where('md5(id)', $id )->delete(); return redirect()->to(base_url()."view_cart/".md5($tokendata[0]['token'])); } + + public function change_count_onclick() + { + try { + $this->Cart_token_model->where('id', $this->request->getVar('id') )->set(array( 'count' => $this->request->getVar('count') ))->update(); + echo true; + } catch (\Exception $e) { + echo $e->getMessage(); + } + + + } diff --git a/app/Controllers/Test_controller.php b/app/Controllers/Test_controller.php index 33e8061..d6dbe1d 100644 --- a/app/Controllers/Test_controller.php +++ b/app/Controllers/Test_controller.php @@ -11,6 +11,7 @@ use App\Models\Email_template_model; use App\Models\Variable_model; use App\Models\Rule_model; use App\Models\Cart_token_model; +use App\Models\Cart_model; class Test_controller extends BaseController { public $session; @@ -27,6 +28,7 @@ class Test_controller extends BaseController $this->VariableModel = new Variable_model(); $this->RuleModel = new Rule_model(); $this->Cart_token_model = new Cart_token_model(); + $this->cartModel = new Cart_model(); helper(['form', 'url']); } public function index($token = null) @@ -43,7 +45,22 @@ class Test_controller extends BaseController } else { - echo 'gop'; + if ($token) + { + $tokendata = $this->Cart_token_model->where('md5(token)', $token )->findAll(); + foreach ($tokendata as $value) + { + $data['member_id'] = $this->session->get('logged_user',); + $data['pack_id'] = $value['primary_id']; + $data['count'] = $value['count']; + $successdata = $this->cartModel->save($data); + if ($successdata) + { + $deletedata = $this->Cart_token_model->where('id', $value['id'] )->delete(); + } + } + // return redirect()->to(base_url().'payment'); + } } diff --git a/app/Views/cart.php b/app/Views/cart.php index 9109546..8e5d0a3 100644 --- a/app/Views/cart.php +++ b/app/Views/cart.php @@ -26,10 +26,12 @@

Cart

- $value) { ?> + $value) { ?> - +
@@ -44,18 +46,23 @@
- +
-
$
+
$
- +
@@ -65,7 +72,7 @@
Subtotal
- +
$
diff --git a/app/Views/layout/header.php b/app/Views/layout/header.php index dfba2ec..6e32ea3 100644 --- a/app/Views/layout/header.php +++ b/app/Views/layout/header.php @@ -87,7 +87,6 @@ $('.city').html(''); } }); -}); diff --git a/app/Views/member_layout/header.php b/app/Views/member_layout/header.php index b9dcfcd..05f7131 100644 --- a/app/Views/member_layout/header.php +++ b/app/Views/member_layout/header.php @@ -1,18 +1,30 @@
@@ -21,8 +33,8 @@
- @@ -32,20 +44,18 @@
-
diff --git a/app/Views/membership.php b/app/Views/membership.php index 42502fb..68104e6 100644 --- a/app/Views/membership.php +++ b/app/Views/membership.php @@ -16,7 +16,7 @@ - + @@ -116,7 +116,6 @@

It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout.

- Get Now