Skip to content

Commit 6741b4a

Browse files
JanSuchanekBarvoj
authored andcommitted
Add Float Basket and Cart Service
1 parent 1e036d3 commit 6741b4a

File tree

12 files changed

+374
-27
lines changed

12 files changed

+374
-27
lines changed

app/Resources/views/base.html.twig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@
101101
<li>
102102
<a href="{{ path("user_logout") }}" class="navbar-link">Odhlásit</a>
103103
</li>
104+
{% if cartItems %}
104105
<li class="dropdown">
105106
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false"> <span class="glyphicon glyphicon-shopping-cart"></span> {{ cartItems|length }} ks - {{ totalPrice }} Kč<span class="caret"></span></a>
106107
<ul class="dropdown-menu dropdown-cart" role="menu">
@@ -124,6 +125,7 @@
124125
<li><a class="text-center" href="{{ path("cart_detail") }}">Zobrazit košík</a></li>
125126
</ul>
126127
</li>
128+
{% endif %}
127129
{% else %}
128130
<li>
129131
<a href="{{ path("user_login") }}" class="navbar-link">Přihlásit</a>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
a

app/config/services.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,4 +116,4 @@ services:
116116
encoder:
117117
class: Symfony\Component\Security\Core\Encoder\BCryptPasswordEncoder
118118
arguments:
119-
- 13
119+
- 13

src/AppBundle/Controller/CartController.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use AppBundle\FormType\CartFormType;
1111
use AppBundle\FormType\VO\CartItemVO;
1212
use AppBundle\FormType\VO\CartVO;
13+
use AppBundle\Service\Cart;
1314
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
1415
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
1516
use Symfony\Component\Form\FormFactory;
@@ -43,13 +44,17 @@ class CartController
4344
/** @var FormFactory */
4445
private $formFactory;
4546

47+
/** @var Cart */
48+
private $cartService;
49+
4650
public function __construct(
4751
UserFacade $userFacade,
4852
CartFacade $cartFacade,
4953
CartItemFacade $cartItemFacade,
5054
ProductFacade $productFacade,
5155
FormFactory $formFactory,
52-
RouterInterface $router
56+
RouterInterface $router,
57+
Cart $cartService
5358
) {
5459

5560
$this->userFacade = $userFacade;
@@ -58,6 +63,7 @@ public function __construct(
5863
$this->productFacade = $productFacade;
5964
$this->formFactory = $formFactory;
6065
$this->router = $router;
66+
$this->cartService = $cartService;
6167
}
6268

6369
/**
@@ -87,12 +93,13 @@ public function actionDetail(Request $request)
8793
return RedirectResponse::create($this->router->generate("cart_detail"));
8894
}
8995

90-
return [
96+
$template = [
9197
"form" => $form->createView(),
92-
'totalPrice' => $totalPrice,
93-
'cartItems' => $cartItems,
9498
"user" => $this->userFacade->getUser(),
9599
];
100+
$template = $this->cartService->create($template);
101+
102+
return $template;
96103
}
97104
/**
98105
* @Route("/kosik/remove/{id}", name="cart_remove_item", requirements={"id": "\d+"})

src/AppBundle/Controller/CategoryController.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace AppBundle\Controller;
44

5+
use AppBundle\Service\Cart;
56
use AppBundle\Facade\CategoryFacade;
67
use AppBundle\Facade\ProductFacade;
78
use AppBundle\Facade\WarehouseProductFacade;
@@ -21,15 +22,20 @@ class CategoryController
2122
private $productFacade;
2223
private $warehouseProductFacade;
2324

25+
/** @var Cart */
26+
private $cartService;
27+
2428
public function __construct(
2529
CategoryFacade $categoryFacade,
2630
ProductFacade $productFacade,
27-
WarehouseProductFacade $warehouseProductFacade
31+
WarehouseProductFacade $warehouseProductFacade,
32+
Cart $cartService
2833
) {
2934

3035
$this->categoryFacade = $categoryFacade;
3136
$this->productFacade = $productFacade;
3237
$this->warehouseProductFacade = $warehouseProductFacade;
38+
$this->cartService = $cartService;
3339
}
3440
/**
3541
* @Route("/vyber/{slug}/{page}", name="category_detail", requirements={"page": "\d+"}, defaults={"page": 1})
@@ -50,7 +56,7 @@ public function categoryDetail($slug, $page)
5056
$products = $this->productFacade->findByCategory($category, $paginator->getLimit(), $paginator->getOffset());
5157
$stockCounts = $this->warehouseProductFacade->getQuantityByProduct($products);
5258

53-
return [
59+
$template = [
5460
"products" => $products,
5561
"categories" => $this->categoryFacade->getParentCategories($category),
5662
"category" => $category,
@@ -59,6 +65,10 @@ public function categoryDetail($slug, $page)
5965
"pageRange" => $paginator->getPageRange(5),
6066
"stockCounts" => $stockCounts,
6167
];
68+
69+
$template = $this->cartService->create($template);
70+
71+
return $template;
6272
}
6373

6474
}

src/AppBundle/Controller/HelpController.php

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22
namespace AppBundle\Controller;
3+
4+
use AppBundle\Service\Cart;
35
use AppBundle\Entity\SupportTicket;
46
use AppBundle\Facade\HelpFacade;
57
use AppBundle\Facade\UserFacade;
@@ -22,16 +24,21 @@ class HelpController
2224
private $helpFacade;
2325
private $userFacade;
2426

27+
/** @var Cart */
28+
private $cartService;
29+
2530
public function __construct(
2631
FaqRepository $faqRepository,
2732
FormFactory $formFactory,
2833
HelpFacade $helpFacade,
29-
UserFacade $userFacade
34+
UserFacade $userFacade,
35+
Cart $cartService
3036
) {
3137
$this->faqRepository = $faqRepository;
3238
$this->formFactory = $formFactory;
3339
$this->helpFacade = $helpFacade;
3440
$this->userFacade = $userFacade;
41+
$this->cartService = $cartService;
3542
}
3643

3744
/**
@@ -42,9 +49,13 @@ public function __construct(
4249
*/
4350
public function faqAction()
4451
{
45-
return [
52+
$template = [
4653
"faqs" => $this->faqRepository->findAll(),
4754
];
55+
56+
$template = $this->cartService->create($template);
57+
58+
return $template;
4859
}
4960

5061
/**
@@ -68,10 +79,14 @@ public function contactAction(Request $request)
6879
$this->helpFacade->saveSupportTicket($ticket);
6980
$saved = true;
7081
}
71-
return [
82+
$template = [
7283
"saved" => $saved,
7384
"form" => $form->createView(),
7485
];
86+
87+
$template = $this->cartService->create($template);
88+
89+
return $template;
7590
}
7691

7792
}

src/AppBundle/Controller/HomepageController.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22
namespace AppBundle\Controller;
3+
4+
use AppBundle\Service\Cart;
35
use AppBundle\Facade\CategoryFacade;
46
use AppBundle\Facade\ProductFacade;
57
use AppBundle\Facade\UserFacade;
@@ -22,17 +24,22 @@ class HomepageController
2224
private $userFacade;
2325
private $warehouseProductFacade;
2426

27+
/** @var Cart */
28+
private $cartService;
29+
2530
public function __construct(
2631
ProductFacade $productFacade,
2732
CategoryFacade $categoryFacade,
2833
UserFacade $userFacade,
29-
WarehouseProductFacade $warehouseProductFacade
34+
WarehouseProductFacade $warehouseProductFacade,
35+
Cart $cartService
3036
) {
3137

3238
$this->productFacade = $productFacade;
3339
$this->categoryFacade = $categoryFacade;
3440
$this->userFacade = $userFacade;
3541
$this->warehouseProductFacade = $warehouseProductFacade;
42+
$this->cartService = $cartService;
3643
}
3744

3845
/**
@@ -48,7 +55,7 @@ public function homepageAction(Request $request)
4855
$products = $this->productFacade->getAll($paginator->getLimit(), $paginator->getOffset());
4956
$stockCounts = $this->warehouseProductFacade->getQuantityByProduct($products);
5057

51-
return [
58+
$template = [
5259
"products" => $products,
5360
"categories" => $this->categoryFacade->getTopLevelCategories(),
5461
"currentPage" => $page,
@@ -57,6 +64,10 @@ public function homepageAction(Request $request)
5764
"user" => $this->userFacade->getUser(),
5865
"stockCounts" => $stockCounts
5966
];
67+
68+
$template = $this->cartService->create($template);
69+
70+
return $template;
6071
}
6172

6273
}

src/AppBundle/Controller/OrderController.php

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
2-
32
namespace AppBundle\Controller;
43

4+
use AppBundle\Service\Cart;
55
use AppBundle\Facade\OrderFacade;
66
use AppBundle\Facade\UserFacade;
77
use AppBundle\Facade\WarehouseFacade;
@@ -38,18 +38,23 @@ class OrderController
3838
/** @var FormFactory */
3939
private $formFactory;
4040

41+
/** @var Cart */
42+
private $cartService;
43+
4144
public function __construct(
4245
UserFacade $userFacade,
4346
OrderFacade $orderFacade,
4447
FormFactory $formFactory,
4548
WarehouseFacade $warehouseFacade,
46-
RouterInterface $router
49+
RouterInterface $router,
50+
Cart $cartService
4751
) {
4852
$this->userFacade = $userFacade;
4953
$this->orderFacade = $orderFacade;
5054
$this->formFactory = $formFactory;
5155
$this->warehouseFacade = $warehouseFacade;
5256
$this->router = $router;
57+
$this->cartService = $cartService;
5358
}
5459

5560
/**
@@ -84,10 +89,14 @@ public function actionDetail(Request $request)
8489
return RedirectResponse::create($this->router->generate("order_thanks", ['id' => $order->getId()]));
8590
}
8691

87-
return [
92+
$template = [
8893
"form" => $form->createView(),
8994
"user" => $user,
9095
];
96+
97+
$template = $this->cartService->create($template);
98+
99+
return $template;
91100
}
92101

93102
/**
@@ -97,9 +106,13 @@ public function actionDetail(Request $request)
97106
public function actionThanks($id)
98107
{
99108

100-
return [
109+
$template = [
101110
"user" => $this->userFacade->getUser(),
102111
];
112+
113+
$template = $this->cartService->create($template);
114+
115+
return $template;
103116
}
104117

105118
}

src/AppBundle/Controller/ProductController.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22
namespace AppBundle\Controller;
33

4+
use AppBundle\Service\Cart;
45
use AppBundle\Facade\ProductFacade;
56
use AppBundle\Facade\WarehouseProductFacade;
67
use AppBundle\FormType\CartAddFormType;
@@ -25,17 +26,22 @@ class ProductController
2526
private $formFactory;
2627
private $router;
2728

29+
/** @var Cart */
30+
private $cartService;
31+
2832
public function __construct(
2933
ProductFacade $productFacade,
3034
WarehouseProductFacade $warehouseProductFacade,
3135
FormFactory $formFactory,
32-
RouterInterface $router
36+
RouterInterface $router,
37+
Cart $cartService
3338
)
3439
{
3540
$this->productFacade = $productFacade;
3641
$this->warehouseProductFacade = $warehouseProductFacade;
3742
$this->formFactory = $formFactory;
3843
$this->router = $router;
44+
$this->cartService = $cartService;
3945
}
4046
/**
4147
* @Route("/product/{slug}", name="product_detail")
@@ -67,11 +73,15 @@ public function productDetailAction(Request $request, $slug)
6773
return RedirectResponse::create($this->router->generate("cart_add_item", $item));
6874
}
6975

70-
return [
76+
$template = [
7177
"product" => $product,
7278
"warehouseProducts" => $warehouseProducts,
7379
"form" => $form->createView(),
7480
];
81+
82+
$template = $this->cartService->create($template);
83+
84+
return $template;
7585
}
7686

7787
}

0 commit comments

Comments
 (0)