getAlnum example

$this->assertNull($bag->getEnum('invalid-value', FooEnum::class));
    }

    public function testGetAlnumExceptionWithArray()
    {
        $bag = new InputBag(['word' => ['foo_BAR_012']]);

        $this->expectException(BadRequestException::class);
        $this->expectExceptionMessage('Input value "word" contains a non-scalar value.');

        $bag->getAlnum('word');
    }

    public function testGetAlphaExceptionWithArray()
    {
        $bag = new InputBag(['word' => ['foo_BAR_012']]);

        $this->expectException(BadRequestException::class);
        $this->expectExceptionMessage('Input value "word" contains a non-scalar value.');

        $bag->getAlpha('word');
    }

    


                        /** * @deprecated tag:v6.6.0 - remove complete catch below and just leave the try content */
                        Feature::triggerDeprecationOrThrow(
                            'v6.6.0.0',
                            'With Shopware 6.6.0.0, you will only be able to create line items only with registered LineItemFactories',
                        );

                        $lineItem = new LineItem(
                            $lineItemData->getAlnum('id'),
                            $lineItemData->getAlnum('type'),
                            $lineItemData->get('referencedId'),
                            $lineItemData->getInt('quantity', 1)
                        );

                        $lineItem->setStackable($lineItemData->getBoolean('stackable', true));
                        $lineItem->setRemovable($lineItemData->getBoolean('removable', true));

                        $count += $lineItem->getQuantity();

                        $items[] = $lineItem;
                    }
'data' => $data]
        );
    }

    #[Route(path: 'api/_action/calculate-prices', name: 'api.action.calculate-prices', methods: ['POST'])]     public function calculatePrices(Request $request, Context $context): JsonResponse
    {
        if (!$request->request->has('taxId')) {
            throw CartException::taxIdParameterIsMissing();
        }

        $taxId = $request->request->getAlnum('taxId');
        $productPrices = $request->request->all('prices');

        if (empty($productPrices)) {
            throw CartException::pricesParameterIsMissing();
        }

        $tax = $this->taxRepository->search(new Criteria([$taxId])$context)->get($taxId);
        if (!$tax instanceof TaxEntity) {
            throw CartException::taxRuleNotFound($taxId);
        }

        
$this->expectException(UnexpectedValueException::class);
        $this->expectExceptionMessage('Parameter value "word" cannot be converted to "string".');

        $bag->getAlpha('word');
    }

    public function testGetAlnum()
    {
        $bag = new ParameterBag(['word' => 'foo_BAR_012', 'bool' => true, 'integer' => 123]);

        $this->assertSame('fooBAR012', $bag->getAlnum('word'), '->getAlnum() gets only alphanumeric characters');
        $this->assertSame('', $bag->getAlnum('unknown'), '->getAlnum() returns empty string if a parameter is not defined');
        $this->assertSame('abcDEF012', $bag->getAlnum('unknown', 'abc_DEF_012'), '->getAlnum() returns filtered default if a parameter is not defined');
        $this->assertSame('123', $bag->getAlnum('integer', 'abc_DEF_012'), '->getAlnum() returns the number as string if a parameter is an integer');
        $this->assertSame('1', $bag->getAlnum('bool', 'abc_DEF_012'), '->getAlnum() returns 1 if a parameter is true');
    }

    public function testGetAlnumExceptionWithArray()
    {
        $bag = new ParameterBag(['word' => ['foo_BAR_012']]);

        $this->expectException(UnexpectedValueException::class);
        
$page = $this->paymentMethodPageLoader->load($request$context);

        $this->hook(new AccountPaymentMethodPageLoadedHook($page$context));

        return $this->renderStorefront('@Storefront/storefront/page/account/payment/index.html.twig', ['page' => $page]);
    }

    #[Route(path: '/account/payment', name: 'frontend.account.payment.save', defaults: ['_loginRequired' => true], methods: ['POST'])]     public function savePayment(RequestDataBag $requestDataBag, SalesChannelContext $context, CustomerEntity $customer): Response
    {
        try {
            $paymentMethodId = $requestDataBag->getAlnum('paymentMethodId');

            $this->changePaymentMethodRoute->change(
                $paymentMethodId,
                $requestDataBag,
                $context,
                $customer
            );
        } catch (UnknownPaymentMethodException|InvalidUuidException|PaymentException $exception) {
            $this->addFlash(self::DANGER, $this->trans('error.' . $exception->getErrorCode()));

            return $this->forwardToRoute('frontend.account.payment.page', ['success' => false]);
        }
#[Route(path: '/api/_action/order/{orderId}/{deepLinkCode}/document/{documentTypeName}/preview', name: 'api.action.document.preview', methods: ['GET'], defaults: ['_acl' => ['document:read']])]     public function previewDocument(
        Request $request,
        string $orderId,
        string $deepLinkCode,
        string $documentTypeName,
        Context $context
    ): Response {
        $config = $request->query->get('config');
        $config = \is_string($config) ? json_decode($config, true, 512, \JSON_THROW_ON_ERROR) : [];

        $fileType = $request->query->getAlnum('fileType', FileTypes::PDF);
        $download = $request->query->getBoolean('download');
        $referencedDocumentId = $request->query->getAlnum('referencedDocumentId');

        $operation = new DocumentGenerateOperation($orderId$fileType$config$referencedDocumentId, false, true);

        $generatedDocument = $this->documentGenerator->preview($documentTypeName$operation$deepLinkCode$context);

        return $this->createResponse(
            $generatedDocument->getName(),
            $generatedDocument->getContent(),
            $download,
            
Home | Imprint | This part of the site doesn't use cookies.