Completed
Push — master ( bcc24a...e5ccd4 )
by Adam
07:54
created

ProducerController::updateAction()   A

Complexity

Conditions 3
Paths 7

Duplication

Lines 0
Ratio 0 %

Size

Total Lines 18
Code Lines 12

Importance

Changes 0
Metric Value
dl 0
loc 18
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 12
nc 7
nop 1
1
<?php
2
/*
3
 * WellCommerce Open-Source E-Commerce Platform
4
 *
5
 * This file is part of the WellCommerce package.
6
 *
7
 * (c) Adam Piotrowski <adam@wellcommerce.org>
8
 *
9
 * For the full copyright and license information,
10
 * please view the LICENSE file that was distributed with this source code.
11
 */
12
13
namespace WellCommerce\Bundle\CatalogBundle\Controller\Admin;
14
15
use Symfony\Component\HttpFoundation\JsonResponse;
16
use Symfony\Component\HttpFoundation\Request;
17
use WellCommerce\Bundle\CatalogBundle\Entity\Producer;
18
use WellCommerce\Bundle\CoreBundle\Controller\Admin\AbstractAdminController;
19
20
/**
21
 * Class ProducerController
22
 *
23
 * @author  Adam Piotrowski <adam@wellcommerce.org>
24
 */
25
class ProducerController extends AbstractAdminController
26
{
27
    public function updateAction(Request $request): JsonResponse
28
    {
29
        $id   = $request->request->get('id');
30
        $data = $request->request->get('product');
31
        
32
        try {
33
            $producer = $this->manager->getRepository()->find($id);
34
            if ($producer instanceof Producer) {
35
                $producer->setHierarchy($data['hierarchy']);
36
                $this->manager->updateResource($producer);
37
            }
38
            $result = ['success' => $this->trans('producer.flash.success.saved')];
39
        } catch (\Exception $e) {
40
            $result = ['error' => $e->getMessage()];
41
        }
42
        
43
        return $this->jsonResponse($result);
44
    }
45
}
46