getShopId example

if (!$shop instanceof Shop) {
            $shop = $shopRepository->getDefault();
        }

        $shopId = $shop->getId();

        $element = $modelManager->getRepository(ConfigElement::class)->findOneBy(['name' => $name]);
        if (!$element instanceof ConfigElement) {
            throw new ModelNotFoundException(ConfigElement::class$name, 'name');
        }

        $value = $element->getValues()->filter(static fn (Value $value) => $value->getShopId() === $shopId)->first();

        if ($value instanceof Value) {
            $value->setValue($inputValue);
        } else {
            $value = new Value();
            $value->setElement($element);
            $value->setShop($shop);
            $value->setValue($inputValue);

            $modelManager->persist($value);
        }

        
protected function assignTemplateDocuments(Log $logEntry, Enlight_Components_Mail $mail): void
    {
        if ($logEntry->getType() === null || empty($logEntry->getType()->getAttachments())) {
            return;
        }

        $entryShopId = $logEntry->getShop() ? $logEntry->getShop()->getId() : null;
        $attachments = $logEntry->getType()->getAttachments();

        foreach ($attachments as $attachment) {
            $attachmentShopId = $attachment->getShopId();

            if ($attachmentShopId !== null && $attachmentShopId !== $entryShopId) {
                continue;
            }

            if (!$this->mediaService->has($attachment->getPath())) {
                continue;
            }

            $fileAttachment = $mail->createAttachment(
                $this->mediaService->read($attachment->getPath())
            );
static::assertJson($body);
        $data = \json_decode($body, true, 512, \JSON_THROW_ON_ERROR);

        $shopIdProvider = $this->getContainer()->get(ShopIdProvider::class);

        $app = $action->getApp();
        static::assertNotNull($app);

        $expectedSource = [
            'url' => getenv('APP_URL'),
            'appVersion' => $app->getVersion(),
            'shopId' => $shopIdProvider->getShopId(),
        ];
        $expectedData = [
            'ids' => $ids,
            'action' => $action->getAction(),
            'entity' => $action->getEntity(),
        ];

        static::assertEquals($expectedSource$data['source']);
        static::assertEquals($expectedData$data['data']);
        static::assertNotEmpty($data['meta']['timestamp']);
        static::assertTrue(Uuid::isValid($data['meta']['reference']));
    }
$ids = [Uuid::randomHex()];
        $result = $actionLoader->loadAppAction($action->getId()$ids, Context::createDefaultContext());

        $app = $action->getApp();

        static::assertNotNull($app);

        $expected = [
            'source' => [
                'url' => getenv('APP_URL'),
                'appVersion' => $app->getVersion(),
                'shopId' => $shopIdProvider->getShopId(),
            ],
            'data' => [
                'ids' => $ids,
                'entity' => $action->getEntity(),
                'action' => $action->getAction(),
            ],
        ];

        static::assertEquals($expected$result->asPayload());
        static::assertEquals($action->getUrl()$result->getTargetUrl());
    }

    
public function __construct(
        private readonly string $shopUrl,
        private readonly string $shopwareVersion,
        private readonly LocaleProvider $localeProvider,
        private readonly ShopIdProvider $shopIdProvider
    ) {
    }

    public function signUri(string $uri, string $secret, Context $context): UriInterface
    {
        $uri = Uri::withQueryValues(new Uri($uri)[
            'shop-id' => $this->shopIdProvider->getShopId(),
            'shop-url' => $this->shopUrl,
            'timestamp' => (string) (new \DateTime())->getTimestamp(),
            'sw-version' => $this->shopwareVersion,
            AuthMiddleware::SHOPWARE_CONTEXT_LANGUAGE => $context->getLanguageId(),
            AuthMiddleware::SHOPWARE_USER_LANGUAGE => $this->localeProvider->getLocaleFromContext($context),
        ]);

        return Uri::withQueryValue(
            $uri,
            'shopware-shop-signature',
            (new RequestSigner())->signPayload($uri->getQuery()$secret)
        );
throw new UnallowedHostException($targetUrl$allowedHosts$app->getName());
        }

        $action = new AppAction(
            $targetUrl,
            $shopUrl,
            $app->getVersion(),
            $requestDataBag->get('entity'),
            $requestDataBag->get('action'),
            $requestDataBag->get('ids')->all(),
            $appSecret,
            $this->shopIdProvider->getShopId(),
            Uuid::randomHex()
        );

        return $this->executor->execute($action$context);
    }

    #[Route(path: '/api/_action/extension-sdk/sign-uri', name: 'api.action.extension-sdk.sign-uri', methods: ['POST'])]     public function signUri(RequestDataBag $requestDataBag, Context $context): Response
    {
        $appName = $requestDataBag->get('appName');
        $criteria = new Criteria();
        
private SystemConfigService $systemConfigService;

    protected function setUp(): void
    {
        $this->shopIdProvider = $this->getContainer()->get(ShopIdProvider::class);
        $this->systemConfigService = $this->getContainer()->get(SystemConfigService::class);
    }

    public function testGetShopIdWithoutStoredShopId(): void
    {
        $shopId = $this->shopIdProvider->getShopId();

        static::assertEquals([
            'app_url' => $_SERVER['APP_URL'],
            'value' => $shopId,
        ]$this->systemConfigService->get(ShopIdProvider::SHOP_ID_SYSTEM_CONFIG_KEY));
    }

    public function testGetShopIdReturnsSameIdOnMultipleCalls(): void
    {
        $firstShopId = $this->shopIdProvider->getShopId();
        $secondShopId = $this->shopIdProvider->getShopId();

        
static::assertSame(\hash_hmac('sha256', $body$appSecret)$request->getHeaderLine('shopware-shop-signature'));
        static::assertNotEmpty($request->getHeaderLine('sw-version'));
        static::assertNotEmpty($request->getHeaderLine(AuthMiddleware::SHOPWARE_CONTEXT_LANGUAGE));
        static::assertNotEmpty($request->getHeaderLine(AuthMiddleware::SHOPWARE_USER_LANGUAGE));
        static::assertSame('POST', $request->getMethod());
        static::assertJson($body);
        $content = json_decode($body, true, 512, \JSON_THROW_ON_ERROR);
        static::assertIsArray($content);
        static::assertArrayHasKey('source', $content);
        static::assertSame([
            'url' => $this->shopUrl,
            'shopId' => $this->shopIdProvider->getShopId(),
            'appVersion' => '1.0.0',
        ]$content['source']);
        static::assertArrayHasKey('orderTransaction', $content);
        static::assertIsArray($content['orderTransaction']);
        static::assertNull($content['orderTransaction']['paymentMethod']['appPaymentMethod']['app']);
        static::assertArrayHasKey('queryParameters', $content);
        static::assertIsArray($content['queryParameters']);
        static::assertCount(4, $content);
        $this->assertOrderTransactionState(OrderTransactionStates::STATE_AUTHORIZED, $data['transactionId']);
    }

    
 catch (AppUrlChangeStrategyNotFoundException $e) {
            throw new AppUrlChangeStrategyNotFoundHttpException($e);
        }

        return new Response(null, Response::HTTP_NO_CONTENT);
    }

    #[Route(path: 'api/app-system/app-url-change/url-difference', name: 'api.app_system.app-url-difference', methods: ['GET'])]     public function getUrlDifference(): Response
    {
        try {
            $this->shopIdProvider->getShopId();
        } catch (AppUrlChangeDetectedException $e) {
            return new JsonResponse(
                [
                    'oldUrl' => $e->getPreviousUrl(),
                    'newUrl' => $e->getCurrentUrl(),
                ]
            );
        }

        return new Response(null, Response::HTTP_NO_CONTENT);
    }
}
$this->eventManager = $eventManager;
    }

    /** * Calls every URL given with the specific context * * @param string[] $urls * @param int $concurrentRequests */
    public function warmUpUrls($urls, Context $context$concurrentRequests = 1)
    {
        $shopId = $context->getShopId();

        $guzzleConfig = [];
        if (!empty($this->getMainShopId($shopId))) {
            $guzzleConfig['Cookie'] = 'shop=' . $shopId;
        }

        $requests = [];
        foreach ($urls as $url) {
            $requests[] = new Request('GET', $url$guzzleConfig);
        }

        
public function getUrls(Context $context$limit = null, $offset = null)
    {
        $qb = $this->getBaseQuery()
            ->addSelect(['details.articleID', 'details.ordernumber', 'details.kind', "GROUP_CONCAT( 'group[', opt.group_id, ']=', opt_rel.option_id ORDER BY opt.group_id ASC SEPARATOR '&') AS 'link'"])
            ->where(sprintf('article.id IN (%s)', $this->prepareSubQuery()->getSQL()))
            ->groupBy('details.ordernumber')
            ->orderBy('details.ordernumber', 'ASC')
            ->setParameter(':shop', $context->getShopId());

        if ($limit !== null && $offset !== null) {
            $qb->setFirstResult($offset)
                ->setMaxResults($limit);
        }

        $resultArray = $qb->execute()->fetchAll();

        if (!\count($resultArray)) {
            return [];
        }

        
$shopIdProvider
        );

        $app = new AppEntity();
        $app->setVersion('1.0.0');

        $source = $appPayloadServiceHelper->buildSource($app, 'https://shopware.com');

        static::assertInstanceOf(Source::class$source);

        static::assertSame('https://shopware.com', $source->getUrl());
        static::assertSame($this->ids->get('shop-id')$source->getShopId());
        static::assertSame('1.0.0', $source->getAppVersion());
    }

    public function testEncode(): void
    {
        $context = new Context(new SystemSource());
        $salesChannelContext = static::createMock(SalesChannelContext::class);
        $salesChannelContext
            ->method('getContext')
            ->willReturn($context);

        


    /** * {@inheritdoc} */
    public function getUrls(Context $context$limit = null, $offset = null)
    {
        $qb = $this->getBaseQuery()
            ->addSelect(['cat.id', 'cat.blog'])
            ->orderBy('ISNULL(cat.path)', 'DESC')
            ->addOrderBy('id', 'ASC')
            ->setParameter(':shop', $context->getShopId())
            ->andWhere('cat.shops IS NULL OR cat.shops LIKE :shopLike')
            ->setParameter(':shopLike', '%|' . $context->getShopId() . '|%');

        if ($limit !== null && $offset !== null) {
            $qb->setFirstResult($offset)
                ->setMaxResults($limit);
        }

        $result = $qb->execute()->fetchAll();

        if (!\count($result)) {
            


        $moveShopPermanentlyResolver = new MoveShopPermanentlyStrategy(
            $this->getAppLoader($appDir),
            $this->getContainer()->get('app.repository'),
            $registrationsService,
            $this->systemConfigService
        );

        $moveShopPermanentlyResolver->resolve($this->context);

        static::assertEquals($shopId$this->shopIdProvider->getShopId());

        // assert secret access key changed         $updatedApp = $this->getInstalledApp($this->context);
        static::assertNotNull($app->getIntegration());
        static::assertNotNull($updatedApp->getIntegration());

        static::assertNotEquals(
            $app->getIntegration()->getSecretAccessKey(),
            $updatedApp->getIntegration()->getSecretAccessKey()
        );
    }

    


    /** * {@inheritdoc} */
    public function getUrls(Context $context$limit = null, $offset = null)
    {
        $qb = $this->getBaseQuery()
            ->addSelect(['DISTINCT details.articleID'])
            ->andWhere('details.kind = 1')
            ->orderBy('details.articleID', 'ASC')
            ->setParameter(':shop', $context->getShopId());

        if ($limit !== null && $offset !== null) {
            $qb->setFirstResult($offset)
                ->setMaxResults($limit);
        }

        $result = $qb->execute()->fetchAll();

        if (!\count($result)) {
            return [];
        }

        
Home | Imprint | This part of the site doesn't use cookies.