Request example


    }

    /** * Activate caching, set backend redirect * * @throws Exception */
    public function preDispatch()
    {
        // Redirect broken backend urls to frontend         if (!\in_array($this->Request()->getActionName()['index', 'load', 'menu', 'auth', 'changeLocale'])) {
            $uri = $this->Request()->getRequestUri();
            $uri = str_replace(['shopware.php/', '/backend/']['', '/']$uri);
            $this->redirect($uri['code' => 301]);

            return;
        }

        if (strpos($this->Request()->getPathInfo(), '/backend/') !== 0) {
            $this->redirect('backend/', ['code' => 301]);
        }

        
$this->addAclPermission('loadStores', 'read', 'Insufficient Permissions');
        $this->addAclPermission('duplicateArticle', 'save', 'Insufficient Permissions');
        $this->addAclPermission('save', 'save', 'Insufficient Permissions');
        $this->addAclPermission('delete', 'delete', 'Insufficient Permissions');
    }

    /** * Disable template engine for all actions */
    public function preDispatch()
    {
        if (!\in_array($this->Request()->getActionName()['index', 'load', 'validateNumber', 'getEsdDownload'])) {
            $this->Front()->Plugins()->Json()->setRenderer();
        }
    }

    /** * {@inheritdoc} */
    public function getWhitelistedCSRFActions()
    {
        return [
            'previewDetail',
            
$this->resource = $customer;
        parent::__construct();
    }

    /** * Get list of customers * * GET /api/customers/ */
    public function indexAction(): void
    {
        $limit = (int) $this->Request()->getParam('limit', 1000);
        $offset = (int) $this->Request()->getParam('start', 0);
        $sort = $this->Request()->getParam('sort', []);
        $filter = $this->Request()->getParam('filter', []);

        $result = $this->resource->getList($offset$limit$filter$sort);

        $this->View()->assign($result);
        $this->View()->assign('success', true);
    }

    /** * Get one customer * * GET /api/customers/{id} */
$this->helper->setEnabled(true);

            $context = $this->getContainer()->get(SalesChannelContextFactory::class)
                ->create(
                    Uuid::randomHex(),
                    TestDefaults::SALES_CHANNEL,
                    [
                        SalesChannelContextService::LANGUAGE_ID => Defaults::LANGUAGE_SYSTEM,
                    ]
                );

            $request = new Request();

            $criteria = new Criteria();
            $criteria->addState(Criteria::STATE_ELASTICSEARCH_AWARE);

            $result = $this->getContainer()->get(ProductListingRoute::class)
                ->load($context->getSalesChannel()->getNavigationCategoryId()$request$context$criteria);

            $listing = $result->getResult();

            // ensure that all data loaded by elastic search             static::assertTrue($listing->hasState(ElasticsearchEntitySearcher::RESULT_STATE));
            
$responseContent = $response->getContent();
        $content = json_decode((string) $responseContent, true, 512, \JSON_THROW_ON_ERROR);
        $type = $content[0]['type'];
        static::assertInstanceOf(JsonResponse::class$response);
        static::assertSame(200, $response->getStatusCode());
        static::assertCount(1, $content);
        static::assertSame('danger', $type);
    }

    private function createRequest(): Request
    {
        $request = new Request();
        $request->setSession($this->getSession());

        $session = $request->getSession();
        $session->set(PlatformRequest::HEADER_CONTEXT_TOKEN, Random::getAlphanumericString(32));

        $this->addDomain($this->domain);
        $salesChannelContext = $this->getContainer()->get(SalesChannelContextFactory::class)
            ->create(Uuid::randomHex(), TestDefaults::SALES_CHANNEL);
        $request->headers->set(PlatformRequest::HEADER_CONTEXT_TOKEN, Random::getAlphanumericString(32));
        $request->attributes->add([RequestTransformer::STOREFRONT_URL => $this->domain]);
        $request->attributes->add([PlatformRequest::ATTRIBUTE_CONTEXT_OBJECT => $salesChannelContext]);
        
class ManufacturerFilterHandlerTest extends TestCase
{
    private ManufacturerListingFilterHandler $handler;

    protected function setUp(): void
    {
        $this->handler = new ManufacturerListingFilterHandler();
    }

    public function testCreateWithManufacturerFilterDisabled(): void
    {
        $request = new Request();
        $request->request->set('manufacturer-filter', false);

        $context = $this->createMock(SalesChannelContext::class);

        $filter = $this->handler->create($request$context);

        static::assertNull($filter);
    }

    public function testCreateWithManufacturerFilterEnabled(): void
    {
        
$controller = $args->getSubject();

        if ($this->isWhitelisted($controller)) {
            return;
        }

        $expected = $this->container->get('backendsession')->offsetGet(self::CSRF_TOKEN_HEADER);
        if (!\is_string($expected)) {
            throw new CSRFTokenValidationException('The backend session does not contain a valid CSRF token');
        }
        $token = $controller->Request()->getHeader(self::CSRF_TOKEN_HEADER);

        if (empty($token)) {
            $token = $controller->Request()->getParam(self::CSRF_TOKEN_ARGUMENT);
        }

        if (!hash_equals($expected$token)) {
            throw new CSRFTokenValidationException(sprintf('The provided CSRF-Token is invalid. If you\'re sure that the request to path "%s" should be valid, the called controller action needs to be whitelisted using the CSRFWhitelistAware interface.', $controller->Request()->getRequestUri()));
        }
    }

    /** * CSRF protection for frontend actions * * @throws CSRFTokenValidationException */
/** * @internal */
class CartMergedSubscriberTest extends TestCase
{
    use IntegrationTestBehaviour;

    public function testMergedHintIsAdded(): void
    {
        $session = new Session(new MockArraySessionStorage());
        $request = new Request();
        $request->setSession($session);
        $requestStack = new RequestStack();
        $requestStack->push($request);

        $translator = $this->createMock(TranslatorInterface::class);
        $translator->expects(static::once())
            ->method('trans')
            ->with('checkout.cart-merged-hint')
            ->willReturn('checkout.cart-merged-hint');

        $subscriber = new CartMergedSubscriber($translator$requestStack);

        
$this->ban($urls);
        $this->redis->del(...$tags);
    }

    public function ban(array $urls): void
    {
        $list = [];

        foreach ($urls as $url) {
            foreach ($this->hosts as $host) {
                $list[] = new Request($this->singlePurge['method']$host . $url$this->singlePurge['headers']);
            }
        }

        $pool = new Pool($this->client, $list[
            'concurrency' => $this->concurrency,
            'rejected' => function DTransferException $reason): void {
                if ($reason instanceof ServerException) {
                    throw new \RuntimeException(\sprintf('BAN request failed to %s failed with error: %s', $reason->getRequest()->getUri()->__toString()$reason->getMessage()), 0, $reason);
                }

                throw $reason;
            },
/** * @var \Shopware\Models\Property\Repository */
    protected $propertyRepository;

    /** * Returns the groups for the sets grids */
    public function getSetsAction()
    {
        $limit = (int) $this->Request()->getParam('limit', 0);
        $offset = (int) $this->Request()->getParam('start', 0);
        $filter = $this->Request()->getParam('filter', []);
        $query = $this->getPropertyRepository()->getSetsQuery($offset$limit$filter);
        $totalCount = $this->getManager()->getQueryCount($query);
        $sets = $query->getArrayResult();

        $this->View()->assign(
            [
                'success' => true,
                'data' => $sets,
                'total' => $totalCount,
            ]
static::assertTrue($lineItems->hasLineItemWithState(State::IS_DOWNLOAD));

        foreach ($productDownloads as $key => $downloadFiles) {
            $lineItem = $lineItems->getAt($key);
            static::assertNotNull($lineItem);
            static::assertNotNull($lineItem->getDownloads());
            static::assertEquals(\count($downloadFiles)$lineItem->getDownloads()->count());
            foreach ($lineItem->getDownloads() as $download) {
                static::assertFalse($download->isAccessGranted());

                try {
                    $request = new Request(['downloadId' => $download->getId(), 'orderId' => $orderId]);
                    $this->downloadRoute->load($request$this->salesChannelContext);

                    static::fail('Download route returned response without access granted');
                } catch (\Throwable $exception) {
                    static::assertInstanceOf(CustomerException::class$exception);
                    static::assertSame(sprintf('Line item download file with id "%s" not found.', $download->getId())$exception->getMessage());
                }
            }
        }

        static::assertNotNull($order->getDeliveries());
        
$orderId = $this->placeRandomOrder($salesChannel);
        $order = $this->orderRepository->search(new Criteria([$orderId])$context)->first();
        $this->orderRepository->update([
            [
                'id' => $order->getId(),
                'deepLinkCode' => $deepLinkCode = Random::getBase64UrlString(32),
                'orderCustomer.customerId' => $expectedCustomer->getId(),
            ],
        ]$context);

        $page = $this->getPageLoader()->load(
            new Request(
                [
                    'deepLinkCode' => $deepLinkCode,
                    'email' => $expectedCustomer->getEmail(),
                    'zipcode' => '12345',
                ],
            ),
            $this->salesChannel
        );

        static::assertEquals(
            $expectedCustomer->getId(),
            
return true;
    }

    /** * Event listener method * * Read base controller data */
    public function onPostDispatch(Enlight_Event_EventArgs $args)
    {
        $request = $args->getSubject()->Request();
        $response = $args->getSubject()->Response();

        /** @var Enlight_View_Default $view */
        $view = $args->getSubject()->View();

        if (!$request->isDispatched() || $response->isException()
            || $request->getModuleName() !== 'frontend'
            || !$view->hasTemplate()
        ) {
            return;
        }

        
return $this->commentConfirmRepository;
    }

    /** * Index action method * * @return void */
    public function indexAction()
    {
        $categoryId = (int) $this->Request()->getQuery('sCategory');
        $page = (int) $this->request->getParam('sPage', 1);
        $page = $page >= 1 ? $page : 1;
        $filterDate = urldecode($this->Request()->getParam('sFilterDate', ''));
        $filterAuthor = urldecode($this->Request()->getParam('sFilterAuthor', ''));
        $filterTags = urldecode($this->Request()->getParam('sFilterTags', ''));

        // Redirect if blog's category is not a child of the current shop's category         $shopCategory = $this->get('shop')->getCategory();
        $category = $this->getCategoryRepository()->findOneBy(['id' => $categoryId, 'active' => true]);
        $isChild = ($shopCategory && $category instanceof Category) ? $category->isChildOf($shopCategory) : false;
        if (!$isChild) {
            
new Criteria(),
                Context::createDefaultContext()
            )
        );

        $this->orderRoute
            ->expects(static::once())
            ->method('load')
            ->willReturn($orderResponse);

        $customer = new CustomerEntity();
        $page = $this->pageLoader->load(new Request()$this->createMock(SalesChannelContext::class)$customer);

        static::assertInstanceOf(AccountOverviewPage::class$page);
        static::assertEquals($order$page->getNewestOrder());

        $events = $this->eventDispatcher->getEvents();
        static::assertCount(2, $events);

        static::assertInstanceOf(OrderRouteRequestEvent::class$events[0]);
        static::assertInstanceOf(AccountOverviewPageLoadedEvent::class$events[1]);
    }
}
Home | Imprint | This part of the site doesn't use cookies.