|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
namespace PTS\SyliusReferralPlugin\Controller; |
|
5
|
|
|
|
|
6
|
|
|
use PTS\SyliusReferralPlugin\Entity\Customer; |
|
7
|
|
|
use PTS\SyliusReferralPlugin\Service\CustomerManager; |
|
8
|
|
|
use Sylius\Component\Core\Model\ShopUser; |
|
9
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
|
10
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
11
|
|
|
use Symfony\Component\HttpFoundation\Session\Session; |
|
12
|
|
|
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; |
|
13
|
|
|
|
|
14
|
|
|
class AccountController extends Controller |
|
|
|
|
|
|
15
|
|
|
{ |
|
16
|
|
|
public function referralAction(Request $request) |
|
17
|
|
|
{ |
|
18
|
|
|
$token = $this->get('security.token_storage')->getToken(); |
|
19
|
|
|
$customerManager = $this->get('app.customer.manager'); |
|
20
|
|
|
if ($token) { |
|
21
|
|
|
/** @var ShopUser $user */ |
|
22
|
|
|
$user = $token->getUser(); |
|
23
|
|
|
if ($user && $user instanceof ShopUser) { |
|
|
|
|
|
|
24
|
|
|
$page = $request->get('page'); |
|
25
|
|
|
$enroller = $user->getCustomer(); |
|
26
|
|
|
$routeName = $request->get('_route'); |
|
27
|
|
|
$data = $customerManager->getPaginatedCustomers($enroller, $page, $routeName); |
|
28
|
|
|
return $this->render( |
|
29
|
|
|
'Account\customers.html.twig', |
|
30
|
|
|
[ |
|
31
|
|
|
'customers' => $data['customers'], |
|
32
|
|
|
'pagination' => $data['pagination'] |
|
33
|
|
|
] |
|
34
|
|
|
); |
|
35
|
|
|
} |
|
36
|
|
|
} |
|
37
|
|
|
throw new BadRequestHttpException('Unauthorized to view this resource'); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public function redirectAction(Request $request) |
|
41
|
|
|
{ |
|
42
|
|
|
$token = $request->get('redirectToken'); |
|
43
|
|
|
$url = $request->get('redirectUrl'); |
|
44
|
|
|
if ($token) { |
|
45
|
|
|
$user = $this->get('sylius.repository.shop_user')->findOneBy(['redirectToken' => $token]); |
|
46
|
|
|
if ($user) { |
|
47
|
|
|
$user->setRedirectToken(''); |
|
48
|
|
|
$this->get('doctrine.orm.default_entity_manager')->flush($user); |
|
49
|
|
|
$this->get('sylius.security.user_login')->login($user, 'shop'); |
|
50
|
|
|
$currentChannel = $this->get('sylius.context.channel')->getChannel(); |
|
51
|
|
|
$this->get('app.manager.cart')->checkCart($user->getCustomer(), $currentChannel, $request->getSession()); |
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
if ($url) { |
|
55
|
|
|
return $this->redirect($url); |
|
56
|
|
|
} else { |
|
57
|
|
|
return $this->redirectToRoute('sylius_shop_homepage'); |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
|