getActiveById example



        $shops = Shopware()->Db()->fetchCol('SELECT id FROM s_core_shops WHERE active = 1');

        $currentTime = new DateTime();

        $this->SeoIndex()->registerShop($shops[0]);
        $this->RewriteTable()->sCreateRewriteTableCleanup();

        foreach ($shops as $shopId) {
            $repository = Shopware()->Models()->getRepository(Shop::class);
            $shop = $repository->getActiveById($shopId);
            if ($shop === null) {
                throw new Exception('No valid shop id passed');
            }

            $this->get(ShopRegistrationServiceInterface::class)->registerShop($shop);
            Shopware()->Modules()->Categories()->baseId = $shop->getCategory()->getId();

            [$elementId$shopId] = $this->SeoIndex()->getCachedTime();
            $this->SeoIndex()->setCachedTime($currentTime->format('Y-m-d H:i:s')$elementId$shopId);

            $this->RewriteTable()->baseSetup();

            
return $this->addSortingById($sort);
    }

    /** * @throws ModelNotFoundException if the specified shop couldn't be found */
    private function createContext(int $shopId, int $currencyId, ?string $customerGroupKey = null): ShopContextInterface
    {
        $repo = Shopware()->Container()->get(ModelManager::class)->getRepository(Shop::class);

        $shop = $repo->getActiveById($shopId);

        if (!$shop instanceof Shop) {
            throw new ModelNotFoundException(Shop::class$shopId);
        }

        $shopId = $shop->getId();

        if ($currencyId === 0) {
            $currencyId = $shop->getCurrency()->getId();
        }

        
$user = $this->get(Connection::class)->fetchAssoc(
            'SELECT id, email, password, subshopID, language FROM s_user WHERE id = :userId',
            [
                ':userId' => $userId,
            ]
        );

        if (empty($user['email'])) {
            return;
        }

        $shop = $this->getShopRepository()->getActiveById($user['language']);
        if ($shop === null) {
            return;
        }

        session_write_close();

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

        $session = $this->get('session');
        $session->clear();
        $session->migrate(true);

        
$fallbackShopId = $fallbackShop->getId();
            }
            // Make sure a template is available             $module->baseSetup();
            $module->sCreateRewriteTableForSingleCampaign($translator$shop->getId()$fallbackShopId$emotionData$routerCampaignTemplate);
        }
    }

    private function getSeoUrlFromRouter(int $emotionId, int $shopId): ?string
    {
        $repository = Shopware()->Container()->get(ModelManager::class)->getRepository(Shop::class);
        $shop = $repository->getActiveById($shopId);
        if (empty($shop)) {
            return null;
        }
        $parent = $shop;
        if ($shop->getFallback()) {
            $parent = $shop->getFallback();
        }

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

        return $this->Front()->ensureRouter()->assemble([
            
$cookieValue = $request->getQuery('__shop');
                break;
            case $request->getPost('__currency') !== null:
                $cookieKey = 'currency';
                $cookieValue = $request->getPost('__currency');
                break;
        }

        if ($cookieKey === 'shop' && $this->shouldRedirect($request$shop)) {
            $repository = $this->get(ModelManager::class)->getRepository(Shop::class);

            $newShop = $repository->getActiveById($cookieValue);

            if ($newShop !== null) {
                $redirectUrl = $this->getNewShopUrl($request$newShop);
                $response->setRedirect($redirectUrl);

                if ($newShop->getBasePath()) {
                    $cookiePath = $newShop->getBasePath();
                } else {
                    $cookiePath = $request->getBasePath();
                }

                
$shopPositionImages = $this->getPositionImages($shopPositionBaseProducts);

        $count = 0;
        foreach ($orders as $orderId => $order) {
            if (empty($customers[$orderId]['email']) || empty($orderPositions[$orderId])) {
                continue;
            }

            $repository = Shopware()->Models()->getRepository(Shop::class);

            $shopId = is_numeric($order['language']) ? $order['language'] : $order['subshopID'];
            $shop = $repository->getActiveById($shopId);
            if ($shop === null) {
                continue;
            }

            $repository = Shopware()->Models()->getRepository(Currency::class);
            $shop->setCurrency($repository->find($order['currencyID']));
            $this->get(ShopRegistrationServiceInterface::class)->registerShop($shop);

            foreach ($orderPositions[$orderId] as &$position) {
                $position['link'] = $this->get(RouterInterface::class)->assemble([
                    'module' => 'frontend', 'sViewport' => 'detail',
                    

    public function initMailing($mailingID = null)
    {
        $mailing = $this->getMailing($mailingID);
        if (empty($mailing)) {
            return null;
        }
        $repository = $this->get('models')->getRepository(Shop::class);
        $shop = $repository->getActiveById($mailing['languageID']);
        if ($shop === null) {
            throw new ModelNotFoundException(Shop::class$mailing['languageID']);
        }

        $this->Request()
            ->setHttpHost((string) $shop->getHost())
            ->setBasePath($shop->getBasePath())
            ->setBaseUrl($shop->getBasePath());

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

        
empty($product)   // No product associated with the specified order number (empty result set)                 || empty($product['articleID']) // or empty articleID                 || empty($product['notification']) // or notification disabled on product                 || empty($product['active']) // or product is not active             ) {
                continue;
            }

            $attributeLoader = $this->get(DataLoaderInterface::class);
            $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']);

            

    private function getRouterContext(Shop $mainShop): array
    {
        $config = $this->container->get(Shopware_Components_Config::class);

        $shopRepository = $this->container->get(ModelManager::class)->getRepository(Shop::class);
        $context = [];
        $allShops = $mainShop->getChildren();
        $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;
    }
$result = $result->rowCount();
            } catch (Zend_Db_Exception $e) {
                continue;
            }

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

            $repository = Shopware()->Models()->getRepository(Shop::class);
            $shopId = is_numeric($user['language']) ? $user['language'] : $user['subshopID'];
            $shop = $repository->getActiveById($shopId);
            $this->get(ShopRegistrationServiceInterface::class)->registerShop($shop);

            // language subshopID             $context = [
                'sUser' => $user,
                'sVoucher' => $voucher,
                'sData' => $job['data'],
            ];

            $mail = Shopware()->TemplateMail()->createMail('sBIRTHDAY', $context);
            $mail->addTo($user['email']);
            

    public function previewAction()
    {
        $themeId = $this->Request()->getParam('themeId');
        $shopId = $this->Request()->getParam('shopId');

        $theme = $this->getRepository()->find($themeId);
        if (!$theme instanceof Template) {
            throw new ModelNotFoundException(Template::class$themeId);
        }

        $shop = $this->getManager()->getRepository(Shop::class)->getActiveById($shopId);

        session_write_close();

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

        $session = $this->get('session');

        $session->template = $theme->getTemplate();
        $session->Admin = true;

        if (!$this->Request()->isXmlHttpRequest()) {
            
/** * Event listener function of the backend module. Fired when the user select a shop in the shop combo in the option * panel of the sidebar and clicks on the "preview" button to display the product details in the store front. */
    public function previewDetailAction()
    {
        $shopId = (int) $this->Request()->getParam('shopId');
        $productId = (int) $this->Request()->getParam('articleId');

        $repository = $this->get('models')->getRepository(Shop::class);
        $shop = $repository->getActiveById($shopId);

        if (!$shop instanceof Shop) {
            throw new Exception('Invalid shop provided.');
        }

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

        Shopware()->Session()->set('Admin', true);

        $url = $this->Front()->ensureRouter()->assemble(
            [
                
$this->sSettings['encoding'] = 'UTF-8';
        } else {
            $this->sSettings['encoding'] = 'ISO-8859-1';
        }

        if (empty($this->sSettings['languageID'])) {
            $defaultShop = $shopRepository->getDefault();
            // Just a fall back for update reasons             $this->sSettings['languageID'] = $defaultShop->getId();
        }

        $shop = $shopRepository->getActiveById($this->sSettings['languageID']);
        if (!$shop instanceof Shop) {
            throw new ModelNotFoundException(Shop::class$this->sSettings['languageID']);
        }

        $this->shopData = $this->getShopData($this->sSettings['languageID']);

        if (empty($this->sSettings['categoryID'])) {
            $this->sSettings['categoryID'] = $this->shopData['category_id'];
        }
        if (empty($this->sSettings['customergroupID'])) {
            $this->sSettings['customergroupID'] = (int) $shop->getCustomerGroup()->getId();
        }
->fetchAll(PDO::FETCH_COLUMN);
        }

        $currentTime = new DateTime();

        $this->rewriteTable->sCreateRewriteTableCleanup();

        foreach ($shops as $shopId) {
            $output->writeln('Rebuilding SEO index for shop ' . $shopId);

            $repository = $this->modelManager->getRepository(Shop::class);
            $shop = $repository->getActiveById($shopId);

            if ($shop === null) {
                throw new ModelNotFoundException(Shop::class$shopId);
            }

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

            $this->modules->Categories()->baseId = $shop->getCategory()->getId();

            [$elementId$shopId] = $this->seoIndex->getCachedTime();

            
/** * Sets the correct context for e.g. validation * * @throws CustomValidationException */
    private function setupContext(?int $shopId = null): void
    {
        $shopRepository = $this->getContainer()->get(ModelManager::class)->getRepository(ShopModel::class);

        if ($shopId) {
            $shop = $shopRepository->getActiveById($shopId);
            if (!$shop) {
                throw new CustomValidationException(sprintf('Shop by id %s not found', $shopId));
            }
        } else {
            $shop = $shopRepository->getActiveDefault();
        }

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

    /** * @param array<string, mixed> $data * * @throws CustomValidationException */
Home | Imprint | This part of the site doesn't use cookies.