Skip to content

Commit

Permalink
start work with orders
Browse files Browse the repository at this point in the history
  • Loading branch information
nik3n1984 committed Aug 28, 2020
1 parent ef3e743 commit a664959
Show file tree
Hide file tree
Showing 14 changed files with 356 additions and 31 deletions.
58 changes: 58 additions & 0 deletions app/controllers/CartController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@


use app\models\Cart;
use app\models\User;
use ishop\BreadcrumbsRender;

class CartController extends AppController
{
Expand Down Expand Up @@ -70,6 +72,7 @@ public function deleteAction(){
}
}else{
if(Cart::deleteProductFromCart()){

$this->setMeta("hockers","escort",'pussy,foxy');
$this->view = 'cart_modal';
}else{
Expand All @@ -81,4 +84,59 @@ public function deleteAction(){

}


public function viewAction(){
$this->setMeta("hockers","escort",'pussy,foxy');
$breadCrumbs = BreadcrumbsRender::getBreadcrumbs("home","КОРЗИНА");
$this->set(compact('breadCrumbs'));
}
public function checkoutAction(){

if($_POST){

if(!isset($_SESSION["user"])){
if(isset($_POST['user'])){
$instModel = new User();
$data = $_POST['user'];
$instModel->load($data);

if(!$instModel->validate($data) || !$instModel->checkUniq()){
$_SESSION['formData'] = $data;
$instModel->setSessionErrors();
redirect();

}else{
$instModel->attributes['password'] = password_hash($instModel->attributes['password'],
PASSWORD_DEFAULT);
if($user_id = $instModel->saveInBD("user")){
$_SESSION['success'] = "Регистрация прошла успешна!";
foreach ($data as $key=>$value){
if($key != "password"){
$_SESSION["user"][$key] = $value;
}
}

}else{
$_SESSION['errors'] = "Бд временно не доступна";
redirect();
}

}


}
}
$data['id'] = isset($_SESSION["user"]['id']) ? $_SESSION["user"]['id'] : $user_id;
$data['note'] = isset($_POST['note']) ? $_POST['note'] : "";
//TODO
debug($data,1);
}



}




}
2 changes: 1 addition & 1 deletion app/controllers/CategoryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function indexAction(){
$idAlias = $category->id;
$recursCategory($idAlias);

$breadCrumbs = BreadcrumbsRender::getBreadcrumbs($idAlias);
$breadCrumbs = BreadcrumbsRender::getBreadcrumbs($idAlias,"","view");


$arrCategoryProducts = Pagination::getCurrentProducts($arrCategoryProducts,App::$app->getProperty("pagination"));
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/ProductController.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function viewAction(){
$visitedProducts = $productModelInst->getDataProducts(3);
$productModelInst->setProductId($product["id"]);

$breadCrumbs = BreadcrumbsRender::getBreadcrumbs($product["category_id"],$product["title"]);
$breadCrumbs = BreadcrumbsRender::getBreadcrumbs($product["category_id"],$product["title"],"view");

// $breadCrumbs = array_reverse(BreadCrumbs::getBreadCrumbs($product["category_id"], $product["title"]));

Expand Down
39 changes: 34 additions & 5 deletions app/controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,26 @@ class UserController extends AppController
{

public function loginAction(){
if(isset($_POST['user'])){
debug($_POST,1);

if(!empty($_POST['user']['login']) && !empty($_POST['user']['password'])){

$modUser = new User();

if($modUser->login()){
$_SESSION["success"] = "Вход выполнен успешно";
redirect('/');
}

$_SESSION["errors"] = "Введеный логин или пароль не верны";
redirect();


}
$breadCrumbs = BreadcrumbsRender::getBreadcrumbs('home','login','viewLogAndReg');




$breadCrumbs = BreadcrumbsRender::getBreadcrumbs('home','login');
$this->set(compact('breadCrumbs'));

}
Expand All @@ -34,18 +50,31 @@ public function signupAction(){
PASSWORD_DEFAULT);
if($instModel->saveInBD("user")){
$_SESSION['success'] = "Регистрация прошла успешна!";
foreach ($data as $key=>$value){
if($key != "password"){
$_SESSION["user"][$key] = $value;
}
}
redirect('/');
}else{
$_SESSION['errors'] = "Бд временно не доступна";
}

}
redirect();

}
$breadCrumbs = BreadcrumbsRender::getBreadcrumbs('home','signup','viewLogAndReg');
}

$breadCrumbs = BreadcrumbsRender::getBreadcrumbs('home','signup');
$this->set(compact('breadCrumbs'));
}
public function logoutAction(){
$name = $_SESSION['user']['name'];

unset($_SESSION['user']);
$_SESSION['success'] = "Пользователь $name вышел из аккаунта";

redirect();

}

Expand Down
32 changes: 32 additions & 0 deletions app/models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,38 @@ public function checkUniq(){
return true;
}

public function login($isAdmin = false){
$login = $_POST['user']['login'] ;
$password = $_POST['user']['password'] ;

if($isAdmin){
$user = \R::findOne("user","login = ? AND role = 'admin'",[$login]);
}else{
$user = \R::findOne("user","login = ? ",[$login]);
}


if($user){
if(password_verify($password, $user['password'])){

foreach ($user as $key=>$value){

if($key != 'password'){

$_SESSION['user'][$key] = $value;
}

}
return true;
}
}

return false;



}




Expand Down
File renamed without changes.
5 changes: 1 addition & 4 deletions app/views/Cart/cart_modal.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@

<?php $curr = \ishop\App::$app->getProperty('currency'); ?>

<?php //debug($_SESSION['productsInCart.currency']); ?>
<?php //debug($curr,1); ?>

<?php if(!empty($_SESSION['productsInCart'])): ?>
<div class="table-responsive">
<table class="table table-hover table-striped">
Expand Down Expand Up @@ -46,5 +43,5 @@ class="glyphicon glyphicon-remove text-danger del-item" aria-hidden="true"></a>
</table>
</div>
<?php else: ?>
<h3>Корзина пуста</h3>
<?php $cartEmpty = '<h3>Корзина пуста</h3>'; echo $cartEmpty?>
<?php endif; ?>
50 changes: 50 additions & 0 deletions app/views/Cart/view.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<!--start-breadcrumbs-->
<?= $breadCrumbs ?>
<!--end-breadcrumbs-->
<div class="cart-order">

<div class="container">
<?php require VIEWS ."/Cart/cart_modal.php"?>
<form method="post" action="cart/checkout" role="form" data-toggle="validator">
<?php if(!isset($_SESSION['user'])): ?>
<div class="form-group has-feedback">
<label for="login">Login</label>
<input type="text" name="user[login]" class="form-control" id="login" placeholder="Login" value="<?= isset($_SESSION['form_data']['login']) ? $_SESSION['form_data']['login'] : '' ?>" required>
<span class="glyphicon form-control-feedback" aria-hidden="true"></span>
</div>
<div class="form-group has-feedback">
<label for="pasword">Password</label>
<input type="password" name="user[password]" class="form-control" id="pasword" placeholder="Password" value="<?= isset($_SESSION['form_data']['password']) ? $_SESSION['form_data']['password'] : '' ?>" data-minlength="6" data-error="Пароль должен включать не менее 6 символов" required>
<span class="glyphicon form-control-feedback" aria-hidden="true"></span>
<div class="help-block with-errors"></div>
</div>
<div class="form-group has-feedback">
<label for="name">Имя</label>
<input type="text" name="user[name]" class="form-control" id="name" placeholder="Имя" value="<?= isset($_SESSION['form_data']['name']) ? $_SESSION['form_data']['name'] : '' ?>" required>
<span class="glyphicon form-control-feedback" aria-hidden="true"></span>
</div>
<div class="form-group has-feedback">
<label for="email">Email</label>
<input type="email" name="user[email]" class="form-control" id="email" placeholder="Email" value="<?= isset($_SESSION['form_data']['email']) ? $_SESSION['form_data']['email'] : '' ?>" required>
<span class="glyphicon form-control-feedback" aria-hidden="true"></span>
</div>
<div class="form-group has-feedback">
<label for="address">Address</label>
<input type="text" name="user[address]" class="form-control" id="address" placeholder="Address" value="<?= isset($_SESSION['form_data']['address']) ? $_SESSION['form_data']['address'] : '' ?>" required>
<span class="glyphicon form-control-feedback" aria-hidden="true"></span>
</div>
<?php endif; ?>
<?php if(!isset($cartEmpty)):?>

<div class="form-group cart-note">
<label for="address">Note</label>
<textarea name="note" class="form-control"></textarea>
</div>
<button type="submit" class="btn btn-default cart-note">Оформить</button>
<?php endif; ?>
</form>
</div>

</div>


2 changes: 1 addition & 1 deletion public/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -3071,7 +3071,7 @@ ul.tag-men {
margin-bottom: 20px;
}

#cart img{
#cart img, .cart-order img{
height: 50px;
}
.del-item{
Expand Down
37 changes: 21 additions & 16 deletions public/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,6 @@ $('#typeahead').bind('typeahead:select', function(ev, suggestion) {



















function showCart(cart){

$(".modal-body").html(cart);
Expand Down Expand Up @@ -175,6 +159,27 @@ $("#cart").on('click','.del-item', function (e) {
}
})
})
$(".cart-order").on('click','.del-item', function (e) {
var data = $(e.target).data('id');
e.preventDefault();
$.ajax({
type: 'GET',
url: '/cart/delete',
data: {deleteFromCart:data},
success: function(resp) {
$(".table-responsive").html(resp);



if(resp.trim() == "<h3>Корзина пуста</h3>"){
console.log('resp');
$(".cart-note").remove();
}

},
error: function() {
console.log("Product not exist");
}
})
})

2 changes: 1 addition & 1 deletion tmp/cache/0832c1202da8d382318e329a7c133ea0.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
a:2:{s:4:"data";a:14:{i:1;a:5:{s:5:"title";s:3:"Men";s:5:"alias";s:3:"men";s:9:"parent_id";s:1:"0";s:8:"keywords";s:3:"Men";s:11:"description";s:3:"Men";}i:2;a:5:{s:5:"title";s:5:"Women";s:5:"alias";s:5:"women";s:9:"parent_id";s:1:"0";s:8:"keywords";s:5:"Women";s:11:"description";s:5:"Women";}i:3;a:5:{s:5:"title";s:4:"Kids";s:5:"alias";s:4:"kids";s:9:"parent_id";s:1:"0";s:8:"keywords";s:4:"Kids";s:11:"description";s:4:"Kids";}i:4;a:5:{s:5:"title";s:22:"Электронные";s:5:"alias";s:11:"elektronnye";s:9:"parent_id";s:1:"1";s:8:"keywords";s:22:"Электронные";s:11:"description";s:22:"Электронные";}i:5;a:5:{s:5:"title";s:24:"Механические";s:5:"alias";s:13:"mehanicheskie";s:9:"parent_id";s:1:"1";s:8:"keywords";s:13:"mehanicheskie";s:11:"description";s:13:"mehanicheskie";}i:6;a:5:{s:5:"title";s:5:"Casio";s:5:"alias";s:5:"casio";s:9:"parent_id";s:1:"4";s:8:"keywords";s:5:"Casio";s:11:"description";s:5:"Casio";}i:7;a:5:{s:5:"title";s:7:"Citizen";s:5:"alias";s:7:"citizen";s:9:"parent_id";s:1:"4";s:8:"keywords";s:7:"Citizen";s:11:"description";s:7:"Citizen";}i:8;a:5:{s:5:"title";s:12:"Royal London";s:5:"alias";s:12:"royal-london";s:9:"parent_id";s:1:"5";s:8:"keywords";s:12:"Royal London";s:11:"description";s:12:"Royal London";}i:9;a:5:{s:5:"title";s:5:"Seiko";s:5:"alias";s:5:"seiko";s:9:"parent_id";s:1:"5";s:8:"keywords";s:5:"Seiko";s:11:"description";s:5:"Seiko";}i:10;a:5:{s:5:"title";s:4:"Epos";s:5:"alias";s:4:"epos";s:9:"parent_id";s:1:"5";s:8:"keywords";s:4:"Epos";s:11:"description";s:4:"Epos";}i:11;a:5:{s:5:"title";s:22:"Электронные";s:5:"alias";s:14:"elektronnye-11";s:9:"parent_id";s:1:"2";s:8:"keywords";s:22:"Электронные";s:11:"description";s:22:"Электронные";}i:12;a:5:{s:5:"title";s:24:"Механические";s:5:"alias";s:16:"mehanicheskie-12";s:9:"parent_id";s:1:"2";s:8:"keywords";s:24:"Механические";s:11:"description";s:24:"Механические";}i:13;a:5:{s:5:"title";s:9:"Adriatica";s:5:"alias";s:9:"adriatica";s:9:"parent_id";s:2:"11";s:8:"keywords";s:9:"Adriatica";s:11:"description";s:9:"Adriatica";}i:14;a:5:{s:5:"title";s:10:"Anne Klein";s:5:"alias";s:10:"anne-klein";s:9:"parent_id";s:2:"12";s:8:"keywords";s:10:"Anne Klein";s:11:"description";s:10:"Anne Klein";}}s:8:"time_end";i:1598530690;}
a:2:{s:4:"data";a:14:{i:1;a:5:{s:5:"title";s:3:"Men";s:5:"alias";s:3:"men";s:9:"parent_id";s:1:"0";s:8:"keywords";s:3:"Men";s:11:"description";s:3:"Men";}i:2;a:5:{s:5:"title";s:5:"Women";s:5:"alias";s:5:"women";s:9:"parent_id";s:1:"0";s:8:"keywords";s:5:"Women";s:11:"description";s:5:"Women";}i:3;a:5:{s:5:"title";s:4:"Kids";s:5:"alias";s:4:"kids";s:9:"parent_id";s:1:"0";s:8:"keywords";s:4:"Kids";s:11:"description";s:4:"Kids";}i:4;a:5:{s:5:"title";s:22:"Электронные";s:5:"alias";s:11:"elektronnye";s:9:"parent_id";s:1:"1";s:8:"keywords";s:22:"Электронные";s:11:"description";s:22:"Электронные";}i:5;a:5:{s:5:"title";s:24:"Механические";s:5:"alias";s:13:"mehanicheskie";s:9:"parent_id";s:1:"1";s:8:"keywords";s:13:"mehanicheskie";s:11:"description";s:13:"mehanicheskie";}i:6;a:5:{s:5:"title";s:5:"Casio";s:5:"alias";s:5:"casio";s:9:"parent_id";s:1:"4";s:8:"keywords";s:5:"Casio";s:11:"description";s:5:"Casio";}i:7;a:5:{s:5:"title";s:7:"Citizen";s:5:"alias";s:7:"citizen";s:9:"parent_id";s:1:"4";s:8:"keywords";s:7:"Citizen";s:11:"description";s:7:"Citizen";}i:8;a:5:{s:5:"title";s:12:"Royal London";s:5:"alias";s:12:"royal-london";s:9:"parent_id";s:1:"5";s:8:"keywords";s:12:"Royal London";s:11:"description";s:12:"Royal London";}i:9;a:5:{s:5:"title";s:5:"Seiko";s:5:"alias";s:5:"seiko";s:9:"parent_id";s:1:"5";s:8:"keywords";s:5:"Seiko";s:11:"description";s:5:"Seiko";}i:10;a:5:{s:5:"title";s:4:"Epos";s:5:"alias";s:4:"epos";s:9:"parent_id";s:1:"5";s:8:"keywords";s:4:"Epos";s:11:"description";s:4:"Epos";}i:11;a:5:{s:5:"title";s:22:"Электронные";s:5:"alias";s:14:"elektronnye-11";s:9:"parent_id";s:1:"2";s:8:"keywords";s:22:"Электронные";s:11:"description";s:22:"Электронные";}i:12;a:5:{s:5:"title";s:24:"Механические";s:5:"alias";s:16:"mehanicheskie-12";s:9:"parent_id";s:1:"2";s:8:"keywords";s:24:"Механические";s:11:"description";s:24:"Механические";}i:13;a:5:{s:5:"title";s:9:"Adriatica";s:5:"alias";s:9:"adriatica";s:9:"parent_id";s:2:"11";s:8:"keywords";s:9:"Adriatica";s:11:"description";s:9:"Adriatica";}i:14;a:5:{s:5:"title";s:10:"Anne Klein";s:5:"alias";s:10:"anne-klein";s:9:"parent_id";s:2:"12";s:8:"keywords";s:10:"Anne Klein";s:11:"description";s:10:"Anne Klein";}}s:8:"time_end";i:1598617088;}
2 changes: 1 addition & 1 deletion tmp/cache/9297fd88a237b4c249515d1022b29f09.txt
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,4 @@ a:2:{s:4:"data";s:1590:"


</li>
";s:8:"time_end";i:1598530690;}
";s:8:"time_end";i:1598617088;}
Loading

0 comments on commit a664959

Please sign in to comment.