Passed
Push — master ( 7e874c...f67e1e )
by Christian
14:45 queued 02:54
created

PromotionActionController::generateCodeFixed()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
c 0
b 0
f 0
nc 2
nop 0
dl 0
loc 7
rs 10
1
<?php declare(strict_types=1);
2
3
namespace Shopware\Core\Checkout\Promotion\Api;
4
5
use Shopware\Core\Checkout\Cart\LineItem\Group\LineItemGroupPackagerInterface;
6
use Shopware\Core\Checkout\Cart\LineItem\Group\LineItemGroupServiceRegistry;
7
use Shopware\Core\Checkout\Cart\LineItem\Group\LineItemGroupSorterInterface;
8
use Shopware\Core\Checkout\Promotion\Cart\Discount\Filter\FilterPickerInterface;
9
use Shopware\Core\Checkout\Promotion\Cart\Discount\Filter\FilterServiceRegistry;
10
use Shopware\Core\Checkout\Promotion\Util\PromotionCodesLoader;
11
use Shopware\Core\Checkout\Promotion\Util\PromotionCodesRemover;
12
use Shopware\Core\Framework\Context;
13
use Shopware\Core\Framework\Feature;
14
use Shopware\Core\Framework\Routing\Annotation\Acl;
15
use Shopware\Core\Framework\Routing\Annotation\RouteScope;
16
use Shopware\Core\Framework\Routing\Annotation\Since;
17
use Shopware\Core\Framework\Uuid\Exception\InvalidUuidException;
18
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
19
use Symfony\Component\HttpFoundation\JsonResponse;
20
use Symfony\Component\HttpFoundation\Response;
21
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
22
use Symfony\Component\Routing\Annotation\Route;
23
24
/**
25
 * @RouteScope(scopes={"api"})
26
 */
27
class PromotionActionController extends AbstractController
28
{
29
    /**
30
     * @var PromotionCodesLoader
31
     */
32
    private $codesLoader;
33
34
    /**
35
     * @var PromotionCodesRemover
36
     */
37
    private $codesRemover;
38
39
    /**
40
     * @var LineItemGroupServiceRegistry
41
     */
42
    private $serviceRegistry;
43
44
    /**
45
     * @var FilterServiceRegistry
46
     */
47
    private $filterServiceRegistry;
48
49
    public function __construct(PromotionCodesLoader $codesLoader, PromotionCodesRemover $codesRemover, LineItemGroupServiceRegistry $serviceRegistry, FilterServiceRegistry $filterServiceRegistry)
50
    {
51
        $this->codesLoader = $codesLoader;
52
        $this->codesRemover = $codesRemover;
53
        $this->serviceRegistry = $serviceRegistry;
54
        $this->filterServiceRegistry = $filterServiceRegistry;
55
    }
56
57
    /**
58
     * @Since("6.3.5.0")
59
     * @Route("/api/v{version}/_action/promotion/codes/generate-fixed", name="api.action.promotion.codes.generate-fixed", methods={"GET"})
60
     * @Acl({"promotion.editor"})
61
     *
62
     * @throws NotFoundHttpException
63
     */
64
    public function generateCodeFixed(): Response
65
    {
66
        if (!Feature::isActive('FEATURE_NEXT_12016')) {
67
            throw new NotFoundHttpException('Route not found, due to inactive flag FEATURE_NEXT_12016');
68
        }
69
70
        return new JsonResponse($this->codesLoader->generateCodeFixed());
71
    }
72
73
    /**
74
     * @Since("6.0.0.0")
75
     * @Route("/api/v{version}/_action/promotion/{promotionId}/codes/individual", name="api.action.promotion.codes", methods={"GET"})
76
     * @Acl({"promotion.viewer"})
77
     *
78
     * @throws InvalidUuidException
79
     */
80
    public function getIndividualCodes(string $promotionId, Context $context): JsonResponse
0 ignored issues
show
Unused Code introduced by
The parameter $context is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

80
    public function getIndividualCodes(string $promotionId, /** @scrutinizer ignore-unused */ Context $context): JsonResponse

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
81
    {
82
        return new JsonResponse($this->codesLoader->loadIndividualCodes($promotionId));
83
    }
84
85
    /**
86
     * @Since("6.0.0.0")
87
     * @Route("/api/v{version}/_action/promotion/{promotionId}/codes/individual", name="api.action.promotion.codes.remove", methods={"DELETE"})
88
     * @Acl({"promotion.deleter"})
89
     *
90
     * @throws InvalidUuidException
91
     */
92
    public function deleteIndividualCodes(string $promotionId, Context $context): Response
93
    {
94
        $this->codesRemover->removeIndividualCodes($promotionId, $context);
95
96
        return new Response(null, Response::HTTP_NO_CONTENT);
97
    }
98
99
    /**
100
     * @Since("6.0.0.0")
101
     * @Route("/api/v{version}/_action/promotion/setgroup/packager", name="api.action.promotion.setgroup.packager", methods={"GET"})
102
     * @Acl({"promotion.viewer"})
103
     *
104
     * @throws InvalidUuidException
105
     */
106
    public function getSetGroupPackagers(): JsonResponse
107
    {
108
        $packagerKeys = [];
109
110
        /** @var LineItemGroupPackagerInterface $packager */
111
        foreach ($this->serviceRegistry->getPackagers() as $packager) {
112
            $packagerKeys[] = $packager->getKey();
113
        }
114
115
        return new JsonResponse($packagerKeys);
116
    }
117
118
    /**
119
     * @Since("6.0.0.0")
120
     * @Route("/api/v{version}/_action/promotion/setgroup/sorter", name="api.action.promotion.setgroup.sorter", methods={"GET"})
121
     * @Acl({"promotion.viewer"})
122
     *
123
     * @throws InvalidUuidException
124
     */
125
    public function getSetGroupSorters(): JsonResponse
126
    {
127
        $sorterKeys = [];
128
129
        /** @var LineItemGroupSorterInterface $sorter */
130
        foreach ($this->serviceRegistry->getSorters() as $sorter) {
131
            $sorterKeys[] = $sorter->getKey();
132
        }
133
134
        return new JsonResponse($sorterKeys);
135
    }
136
137
    /**
138
     * @Since("6.3.4.0")
139
     * @Route("/api/v{version}/_action/promotion/discount/picker", name="api.action.promotion.discount.picker", methods={"GET"})
140
     * @Acl({"promotion.viewer"})
141
     *
142
     * @throws InvalidUuidException
143
     */
144
    public function getDiscountFilterPickers(): JsonResponse
145
    {
146
        $pickerKeys = [];
147
148
        /** @var FilterPickerInterface $picker */
149
        foreach ($this->filterServiceRegistry->getPickers() as $picker) {
150
            $pickerKeys[] = $picker->getKey();
151
        }
152
153
        return new JsonResponse($pickerKeys);
154
    }
155
}
156