|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace OroCRM\Bundle\MagentoBundle\Controller; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
|
6
|
|
|
use Symfony\Component\HttpFoundation\JsonResponse; |
|
7
|
|
|
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; |
|
8
|
|
|
|
|
9
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; |
|
10
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; |
|
11
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter; |
|
12
|
|
|
|
|
13
|
|
|
use Oro\Bundle\SecurityBundle\Annotation\Acl; |
|
14
|
|
|
use Oro\Bundle\SecurityBundle\Annotation\AclAncestor; |
|
15
|
|
|
use Oro\Bundle\SecurityBundle\SecurityFacade; |
|
16
|
|
|
|
|
17
|
|
|
use OroCRM\Bundle\MagentoBundle\Entity\Customer; |
|
18
|
|
|
use OroCRM\Bundle\AccountBundle\Entity\Account; |
|
19
|
|
|
use OroCRM\Bundle\ChannelBundle\Entity\Channel; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @Route("/customer") |
|
23
|
|
|
*/ |
|
24
|
|
|
class CustomerController extends Controller |
|
25
|
|
|
{ |
|
26
|
|
|
/** |
|
27
|
|
|
* @Route("/", name="orocrm_magento_customer_index") |
|
28
|
|
|
* @AclAncestor("orocrm_magento_customer_view") |
|
29
|
|
|
* @Template |
|
30
|
|
|
*/ |
|
31
|
|
|
public function indexAction() |
|
32
|
|
|
{ |
|
33
|
|
|
return [ |
|
34
|
|
|
'entity_class' => $this->container->getParameter('orocrm_magento.customer.entity.class') |
|
35
|
|
|
]; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @param Customer $customer |
|
40
|
|
|
* @return array |
|
41
|
|
|
* |
|
42
|
|
|
* @Route("/view/{id}", name="orocrm_magento_customer_view", requirements={"id"="\d+"})) |
|
43
|
|
|
* @Acl( |
|
44
|
|
|
* id="orocrm_magento_customer_view", |
|
45
|
|
|
* type="entity", |
|
46
|
|
|
* permission="VIEW", |
|
47
|
|
|
* class="OroCRMMagentoBundle:Customer" |
|
48
|
|
|
* ) |
|
49
|
|
|
* @Template |
|
50
|
|
|
*/ |
|
51
|
|
|
public function viewAction(Customer $customer) |
|
52
|
|
|
{ |
|
53
|
|
|
return ['entity' => $customer]; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @param Customer $customer |
|
58
|
|
|
* @return array |
|
59
|
|
|
* |
|
60
|
|
|
* @Route("/update/{id}", name="orocrm_magento_customer_update", requirements={"id"="\d+"})) |
|
61
|
|
|
* @Acl( |
|
62
|
|
|
* id="orocrm_magento_customer_update", |
|
63
|
|
|
* type="entity", |
|
64
|
|
|
* permission="EDIT", |
|
65
|
|
|
* class="OroCRMMagentoBundle:Customer" |
|
66
|
|
|
* ) |
|
67
|
|
|
* @Template("OroCRMMagentoBundle:Customer:update.html.twig") |
|
68
|
|
|
*/ |
|
69
|
|
|
public function updateAction(Customer $customer) |
|
70
|
|
|
{ |
|
71
|
|
|
return $this->update($customer); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* @Route("/create", name="orocrm_magento_customer_create")) |
|
76
|
|
|
* @Acl( |
|
77
|
|
|
* id="orocrm_magento_customer_create", |
|
78
|
|
|
* type="entity", |
|
79
|
|
|
* permission="CREATE", |
|
80
|
|
|
* class="OroCRMMagentoBundle:Customer" |
|
81
|
|
|
* ) |
|
82
|
|
|
* @Template("OroCRMMagentoBundle:Customer:update.html.twig") |
|
83
|
|
|
*/ |
|
84
|
|
|
public function createAction() |
|
85
|
|
|
{ |
|
86
|
|
|
if (!$this->getSecurityFacade()->isGranted('oro_integration_assign')) { |
|
87
|
|
|
throw new AccessDeniedHttpException(); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
return $this->update(new Customer()); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* @param Customer $customer |
|
95
|
|
|
* @return JsonResponse |
|
96
|
|
|
* |
|
97
|
|
|
* @Route("/register/{id}", name="orocrm_magento_customer_register", requirements={"id"="\d+"})) |
|
98
|
|
|
* @AclAncestor("orocrm_magento_customer_update") |
|
99
|
|
|
*/ |
|
100
|
|
|
public function registerAction(Customer $customer) |
|
101
|
|
|
{ |
|
102
|
|
|
return new JsonResponse([ |
|
103
|
|
|
'successful' => $this->get('orocrm_magento.form.handler.customer')->handleRegister($customer), |
|
104
|
|
|
]); |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* @param Customer $customer |
|
109
|
|
|
* @return array |
|
110
|
|
|
*/ |
|
111
|
|
|
protected function update(Customer $customer) |
|
112
|
|
|
{ |
|
113
|
|
|
return $this->get('orocrm_magento.form.handler.customer')->handleUpdate( |
|
114
|
|
|
$customer, |
|
115
|
|
|
$this->createForm('orocrm_magento_customer', $customer), |
|
116
|
|
|
function (Customer $customer) { |
|
117
|
|
|
return [ |
|
118
|
|
|
'route' => 'orocrm_magento_customer_update', |
|
119
|
|
|
'parameters' => ['id' => $customer->getId()] |
|
120
|
|
|
]; |
|
121
|
|
|
}, |
|
122
|
|
|
function (Customer $customer) { |
|
123
|
|
|
return [ |
|
124
|
|
|
'route' => 'orocrm_magento_customer_view', |
|
125
|
|
|
'parameters' => ['id' => $customer->getId()] |
|
126
|
|
|
]; |
|
127
|
|
|
}, |
|
128
|
|
|
$this->get('translator')->trans('orocrm.magento.customer.saved.message') |
|
129
|
|
|
); |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
/** |
|
133
|
|
|
* @param Customer $customer |
|
134
|
|
|
* @return array |
|
135
|
|
|
* |
|
136
|
|
|
* @Route("/info/{id}", name="orocrm_magento_customer_info", requirements={"id"="\d+"})) |
|
137
|
|
|
* @AclAncestor("orocrm_magento_customer_view") |
|
138
|
|
|
* @Template |
|
139
|
|
|
*/ |
|
140
|
|
|
public function infoAction(Customer $customer) |
|
141
|
|
|
{ |
|
142
|
|
|
return ['entity' => $customer]; |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
/** |
|
146
|
|
|
* @param Account $account |
|
147
|
|
|
* @param Channel $channel |
|
148
|
|
|
* @return array |
|
149
|
|
|
* |
|
150
|
|
|
* @Route( |
|
151
|
|
|
* "/widget/customers-info/{accountId}/{channelId}", |
|
152
|
|
|
* name="orocrm_magento_widget_account_customers_info", |
|
153
|
|
|
* requirements={"accountId"="\d+", "channelId"="\d+"} |
|
154
|
|
|
* ) |
|
155
|
|
|
* @ParamConverter("account", class="OroCRMAccountBundle:Account", options={"id" = "accountId"}) |
|
156
|
|
|
* @ParamConverter("channel", class="OroCRMChannelBundle:Channel", options={"id" = "channelId"}) |
|
157
|
|
|
* @AclAncestor("orocrm_magento_customer_view") |
|
158
|
|
|
* @Template |
|
159
|
|
|
*/ |
|
160
|
|
|
public function accountCustomersInfoAction(Account $account, Channel $channel) |
|
161
|
|
|
{ |
|
162
|
|
|
$customers = $this->getDoctrine() |
|
163
|
|
|
->getRepository('OroCRM\\Bundle\\MagentoBundle\\Entity\\Customer') |
|
164
|
|
|
->findBy(['account' => $account, 'dataChannel' => $channel]); |
|
165
|
|
|
$customers = array_filter( |
|
166
|
|
|
$customers, |
|
167
|
|
|
function ($item) { |
|
168
|
|
|
return $this->getSecurityFacade()->isGranted('VIEW', $item); |
|
169
|
|
|
} |
|
170
|
|
|
); |
|
171
|
|
|
|
|
172
|
|
|
return ['customers' => $customers, 'channel' => $channel, 'account' => $account]; |
|
173
|
|
|
} |
|
174
|
|
|
|
|
175
|
|
|
/** |
|
176
|
|
|
* @param Customer $customer |
|
177
|
|
|
* @param Channel $channel |
|
178
|
|
|
* @return array |
|
179
|
|
|
* |
|
180
|
|
|
* @Route( |
|
181
|
|
|
* "/widget/customer-info/{id}/{channelId}", |
|
182
|
|
|
* name="orocrm_magento_widget_customer_info", |
|
183
|
|
|
* requirements={"id"="\d+", "channelId"="\d+"} |
|
184
|
|
|
* ) |
|
185
|
|
|
* @ParamConverter("channel", class="OroCRMChannelBundle:Channel", options={"id" = "channelId"}) |
|
186
|
|
|
* @AclAncestor("orocrm_magento_customer_view") |
|
187
|
|
|
* @Template |
|
188
|
|
|
*/ |
|
189
|
|
|
public function customerInfoAction(Customer $customer, Channel $channel) |
|
190
|
|
|
{ |
|
191
|
|
|
return [ |
|
192
|
|
|
'customer' => $customer, |
|
193
|
|
|
'channel' => $channel, |
|
194
|
|
|
'orderClassName' => $this->container->getParameter('orocrm_magento.entity.order.class'), |
|
195
|
|
|
'cartClassName' => $this->container->getParameter('orocrm_magento.entity.cart.class'), |
|
196
|
|
|
]; |
|
197
|
|
|
} |
|
198
|
|
|
|
|
199
|
|
|
/** |
|
200
|
|
|
* @param Customer $customer |
|
201
|
|
|
* @return array |
|
202
|
|
|
* |
|
203
|
|
|
* @Route("/order/{id}", name="orocrm_magento_customer_orderplace", requirements={"id"="\d+"})) |
|
204
|
|
|
* @AclAncestor("orocrm_magento_customer_view") |
|
205
|
|
|
* @Template |
|
206
|
|
|
*/ |
|
207
|
|
|
public function placeOrderAction(Customer $customer) |
|
208
|
|
|
{ |
|
209
|
|
|
return ['entity' => $customer]; |
|
210
|
|
|
} |
|
211
|
|
|
|
|
212
|
|
|
/** |
|
213
|
|
|
* @param Customer $customer |
|
214
|
|
|
* @return array |
|
215
|
|
|
* |
|
216
|
|
|
* @Route("/addressBook/{id}", name="orocrm_magento_customer_address_book", requirements={"id"="\d+"})) |
|
217
|
|
|
* @AclAncestor("orocrm_magento_customer_view") |
|
218
|
|
|
* @Template |
|
219
|
|
|
*/ |
|
220
|
|
|
public function addressBookAction(Customer $customer) |
|
221
|
|
|
{ |
|
222
|
|
|
return ['entity' => $customer]; |
|
223
|
|
|
} |
|
224
|
|
|
|
|
225
|
|
|
/** |
|
226
|
|
|
* @return SecurityFacade |
|
227
|
|
|
*/ |
|
228
|
|
|
protected function getSecurityFacade() |
|
229
|
|
|
{ |
|
230
|
|
|
return $this->get('oro_security.security_facade'); |
|
231
|
|
|
} |
|
232
|
|
|
} |
|
233
|
|
|
|