createFromShop example


    public function getHttpURLsAction()
    {
        $shopId = (int) $this->Request()->getParam('shopId', 1);

        $shopModel = $this->container->get(ModelManager::class)->getRepository(Shop::class)->getById($shopId);
        if ($shopModel === null) {
            throw new ModelNotFoundException(Shop::class$shopId);
        }

        $context = Context::createFromShop(
            $shopModel,
            $this->container->get(Shopware_Components_Config::class)
        );

        $providers = $this->get('shopware_cache_warmer.url_provider_factory')->getAllProviders();

        // Count for each provider, if enabled         $config = json_decode($this->Request()->getParam('config', '{}'), true);
        $counts = [];
        foreach ($providers as $provider) {
            if ($config[$provider->getName()]) {
                
$container = $args->getSubject();
        /** @var RouterInterface $router */
        $router = $container->get(\Shopware\Components\Routing\RouterInterface::class);
        /** @var \Shopware\Models\Shop\Shop $shop */
        $shop = $container->get('shop');
        /** @var Shopware_Components_Config $config */
        $config = $container->get(Shopware_Components_Config::class);
        // Register the shop (we're too soon)         $config->setShop($shop);

        $context = $router->getContext();
        $newContext = Context::createFromShop($shop$config);
        // Reuse the host         if ($newContext->getHost() === null) {
            $newContext->setHost($context->getHost());
            $newContext->setBaseUrl($context->getBaseUrl());
            $newContext->setSecure($context->isSecure());
        }
        // Reuse the global params like controller and action         $globalParams = $context->getGlobalParams();
        $newContext->setGlobalParams($globalParams);
        $router->setContext($newContext);
    }

    
private function doubleOptInVerificationMail(ShopStruct $shop, Customer $customer, string $hash): void
    {
        $container = Shopware()->Container();
        $router = Shopware()->Front()->ensureRouter();

        $shopModel = $this->modelManager->getRepository(ShopModel::class)->getById($shop->getId());
        if ($shopModel === null) {
            throw new ModelNotFoundException(ShopModel::class$shop->getId());
        }
        $router->setContext(
            Context::createFromShop(
                $shopModel,
                $this->config
            )
        );
        $link = $router->assemble([
            'sViewport' => 'register',
            'action' => 'confirmValidation',
            'sConfirmation' => $hash,
        ]);

        // Should be compatible with the sREGISTERCONFIRMATION context
$this->View()->assign('sGroup', $this->Request()->getParam('group'));
        $plugin = Shopware()->Plugins()->Core()->ControllerBase();
        $this->View()->assign('sMenu', $plugin->getMenu());
    }

    /** * Get shop menu */
    public function shopMenuAction(): void
    {
        $shop = Shopware()->Shop();
        $main = DetachedShop::createFromShop($shop->getMain() ?? $shop);

        $this->View()->assign('shop', $shop);
        if (!$this->Request()->getParam('hideCurrency', false)) {
            $this->View()->assign('currencies', $shop->getCurrencies());
        }
        $languages = $shop->getChildren()->toArray();
        foreach ($languages as $languageKey => $language) {
            $language = DetachedShop::createFromShop($language);
            if (!$language->getActive()) {
                unset($languages[$languageKey]);
            }
        }
$notify['attribute'] = $attributeLoader->load('s_articles_notification_attributes', $notify['id']);

            $shop = $modelManager->getRepository(Shop::class)->getActiveById($notify['language']);

            // Continue if shop is inactive or deleted             if ($shop === null) {
                continue;
            }

            $this->get(ShopRegistrationServiceInterface::class)->registerShop($shop);

            $shopContext = Context::createFromShop($shop$this->get(Shopware_Components_Config::class));
            $this->get(RouterInterface::class)->setContext($shopContext);
            $sContext = $this->get(ContextServiceInterface::class)->createShopContext($notify['language']);

            $productInformation = $this->get(ListProductServiceInterface::class)->get($notify['ordernumber']$sContext);

            if (empty($productInformation)) {
                continue;
            }

            $productInformation = $this->get('legacy_struct_converter')->convertListProductStruct($productInformation);

            
->where('shop.id = :shopId')
            ->orWhere('shop.main_id = :shopId')
            ->andWhere('active=1')
            ->setParameter('shopId', $parentId)
            ->execute()
            ->fetchAll();
    }

    private function getContext(ShopModel $shop, Config $config): Context
    {
        if (!isset($this->contextCache[$shop->getId()])) {
            $this->contextCache[$shop->getId()] = Context::createFromShop($shop$config);
        }

        return $this->contextCache[$shop->getId()];
    }

    private function getDetachedShop(int $languageShopId): ShopModel
    {
        $shopModel = $this->modelManager->getRepository(ShopModel::class)->getById($languageShopId);
        if ($shopModel === null) {
            throw new ModelNotFoundException(ShopModel::class$languageShopId);
        }

        
$optionsKeys = array_keys($optionsfunction D$setting) {
                return $setting;
            });
            $optionsKeys = array_map('ucfirst', $optionsKeys);

            $io->write('Specific warmup - Warming only the following url types: ' . implode(', ', $optionsKeys));
        }
        $io->newLine();

        /** @var Shop $shop */
        foreach ($shops as $shop) {
            $context = Context::createFromShop(
                $shop,
                $this->container->get(Shopware_Components_Config::class)
            );

            // Gathering URLs             $urls = [];
            $totalResultCount = 0;
            $offset = 0;
            foreach ($options as $resource => $active) {
                if ($active) {
                    $provider = $urlProviderFactory->getProvider($resource);
                    
public function getActiveQueryBuilder()
    {
        return $this->getQueryBuilder()
            ->where('shop.active = 1');
    }

    /** * @return DetachedShop */
    protected function fixActive(Shop $shop)
    {
        $shop = DetachedShop::createFromShop($shop);

        $main = $shop->getMain();
        if ($main !== null) {
            $main = DetachedShop::createFromShop($main);
            $shop->setHost($main->getHost());
            $shop->setSecure($main->getSecure());
            $shop->setBasePath($shop->getBasePath() ?: $main->getBasePath());
            $shop->setTemplate($main->getTemplate());
            $shop->setCurrencies($main->getCurrencies());
            $shop->setChildren($main->getChildren());
            $shop->setCustomerScope($main->getCustomerScope());
        }
$allShops[] = $mainShop;

        foreach ($allShops as $shop) {
            $detachedShop = $shopRepository->getActiveById($shop->getId());
            if ($detachedShop === null) {
                continue;
            }

            $newConfig = clone $config;
            $newConfig->setShop($detachedShop);

            $context[$detachedShop->getId()] = Context::createFromShop($detachedShop$newConfig);
        }

        return $context;
    }
}


    /** * {@inheritdoc} */
    public function generate(Shop $shop)
    {
        if (!$this->sitemapLock->doLock($shop$this->shopwareConfig->get('sitemapRefreshTime'))) {
            throw new AlreadyLockedException(sprintf('Cannot acquire lock for shop %d', $shop->getId()));
        }

        $routerContext = Context::createFromShop($shop$this->shopwareConfig);
        $shopContext = $this->contextService->createShopContext($shop->getId()$shop->getCurrency()->getId()$shop->getCustomerGroup()->getKey());

        foreach ($this->urlProvider as $urlProvider) {
            $urlProvider->reset();
            while ($urls = $urlProvider->getUrls($routerContext$shopContext)) {
                $urls = $this->urlFilter->filter($urls(int) $shop->getId());

                if (!$urls) {
                    continue;
                }

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