Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
13 changes: 13 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"require": {
"twig/twig": "^3.0"
},
"autoload": {
"psr-4": {
"services\\": "services",
"app\\": "\\",
"controllers\\": "controllers",
"models\\": "models"
}
}
}
244 changes: 244 additions & 0 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added composer.phar
Binary file not shown.
52 changes: 52 additions & 0 deletions controllers/CartController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php


namespace app\controllers;


use app\entities\Cart;
use app\services\Session;

class CartController extends MainController
{

public function allAction()
{
$arr = Session::get('cart');
$carts = new Cart();
foreach ($arr as $key => $value) {
$carts->id = $key;
$carts->qty = $value;
echo $this->renderer->render('cartAll', ['carts' => $carts]);
}
// return $this->renderer->render('cartAll', ['carts' => $carts]);
// foreach ($ids as $key => $qty) {
// $arr[] = $key;
// foreach ($arr as $id) {
// $cart = (new ProductRepository())->getOne($id);
// var_dump($cart);
// }
// }

}


public function addAction()
{
$productId = $this->request->post('id');
$productQty = $this->request->post('qty');
$arr = Session::get('cart');
Session::push($arr, $productId, $productQty);
return header('Location: /product/');
}

public function delAction()
{
$deleteId = $this->request->post('id');
$res = Session::get('cart', $deleteId);
Session::delete($res, $deleteId);
header("Location: /cart/");
}


}
54 changes: 54 additions & 0 deletions controllers/MainController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php


namespace app\controllers;


use app\services\RenderI;
use app\services\Request;

class MainController
{
protected $pathsToViews = [__DIR__ . '/../views/',
__DIR__ . '/../views/layouts'
];

protected $path = __DIR__ . '/../views/';
protected $actionDefault = 'all';

/**
* @var RenderServices
*/
protected $renderer;
/**
* @var Request
*/
protected $request;

public function __construct(RenderI $renderer, Request $request)
{
$this->renderer = $renderer;
$this->request = $request;
}


public function run($action)
{
if (empty($action)) {
$action = $this->actionDefault;
}

$action .= "Action";
if (!method_exists($this, $action)) {
return '404';
}
return $this->$action();
}



protected function getId()
{
return $this->request->getId();
}
}
Loading