getShopContext example

private $contextService;

    public function __construct(MediaServiceInterface $mediaService, LegacyStructConverter $structConverter, ContextServiceInterface $contextService)
    {
        $this->mediaService = $mediaService;
        $this->structConverter = $structConverter;
        $this->contextService = $contextService;
    }

    public function resolve(): void
    {
        $medias = $this->mediaService->getList($this->resolveIds, $this->contextService->getShopContext());

        foreach ($medias as $id => $media) {
            $this->storage[$id] = $this->structConverter->convertMediaStruct($media);
        }

        $this->resolveIds = [];
    }
}
return;
        }

        $this->View()->loadTemplate('frontend/search/fuzzy.tpl');

        $minLengthSearchTerm = $this->get(Shopware_Components_Config::class)->get('minSearchLenght');
        if (\strlen($term) < (int) $minLengthSearchTerm) {
            return;
        }

        $context = $this->get(ContextServiceInterface::class)->getShopContext();

        $criteria = Shopware()->Container()->get(StoreFrontCriteriaFactoryInterface::class)
            ->createSearchCriteria($this->Request()$context);

        $result = $this->get(ProductSearchInterface::class)->search($criteria$context);
        $products = $this->convertProducts($result);

        if ($this->get(Shopware_Components_Config::class)->get('traceSearch', true)) {
            $this->get('shopware_searchdbal.search_term_logger')->logResult(
                $criteria,
                $result,
                

    public function saveRegisterAction()
    {
        if (!$this->request->isPost()) {
            $this->forward('index');

            return;
        }

        /** @var ShopContextInterface $context */
        $context = $this->get(ContextServiceInterface::class)->getShopContext();

        /** @var Enlight_Components_Session_Namespace $session */
        $session = $this->get('session');

        /** @var RegisterServiceInterface $registerService */
        $registerService = $this->get(RegisterServiceInterface::class);

        $data = $this->getPostData();

        $customerForm = $this->createCustomerForm($data['register']['personal']);
        $billingForm = $this->createBillingForm($data['register']['billing']);

        
$numbers = [];
        foreach ($positions as $product) {
            if (empty($product['modus'])) {
                $numbers[] = $product['articleordernumber'];
            }
        }

        $container = Shopware()->Container();
        /** @var ContextServiceInterface $context */
        $context = $container->get('shopware_storefront.context_service');
        $additionalDetails = $container->get(OrderListProductServiceInterface::class)->getList($numbers$context->getShopContext());
        foreach ($positions as &$product) {
            if (empty($product['modus'])) {
                $product['meta'] = $additionalDetails[$product['articleordernumber']];
            }
        }
        unset($product);

        if (!empty($this->_config['_previewForcePagebreak'])) {
            $positions = array_merge($positions$positions);
        }

        
/** * @param string[] $numbers * * @return array[] */
    private function getPromotions($numbers)
    {
        if (empty($numbers)) {
            return [];
        }

        $context = $this->get(ContextServiceInterface::class)->getShopContext();
        $products = $this->get(ListProductServiceInterface::class)
            ->getList($numbers$context);

        return $this->get(LegacyStructConverter::class)->convertListProductStructList($products);
    }
}
private function getListProductData(ListProduct $product): array
    {
        $createDate = null;
        if ($product->getCreatedAt()) {
            $createDate = $product->getCreatedAt()->format('Y-m-d');
        }
        $updateDate = null;
        if ($product->getUpdatedAt()) {
            $updateDate = $product->getUpdatedAt()->format('Y-m-d');
        }
        $tax = $product->getTax();
        $taxRule = $this->contextService->getShopContext()->getTaxRule($product->getTax()->getId());
        if ($taxRule instanceof Tax) {
            $tax = $taxRule;
        }

        $data = [
            'articleID' => $product->getId(),
            'articleDetailsID' => $product->getVariantId(),
            'ordernumber' => $product->getNumber(),
            'highlight' => $product->highlight(),
            'description' => $product->getShortDescription(),
            'description_long' => $product->getLongDescription(),
            
if ($this->Request()->get('type') === 'slider') {
            $this->View()->loadTemplate('frontend/_includes/product_slider.tpl');
        } else {
            $this->View()->loadTemplate('frontend/listing/listing_ajax.tpl');
        }

        if (!\is_array($numbers)) {
            return;
        }

        $context = $this->container->get(ContextServiceInterface::class)->getShopContext();

        $products = $this->container->get(ListProductServiceInterface::class)->getList($numbers$context);

        $convertedProducts = $this->container->get(LegacyStructConverter::class)->convertListProductStructList($products);

        $this->View()->assign(['sArticles' => $convertedProducts, 'articles' => $convertedProducts]);
    }

    /** * @return void */
    

        $this->View()->loadTemplate('frontend/home/index.tpl');
    }

    public function indexAction()
    {
        if ($this->handleThemeHash()) {
            return;
        }

        /** @var ShopContextInterface $context */
        $context = Shopware()->Container()->get(\Shopware\Bundle\StoreFrontBundle\Service\ContextServiceInterface::class)->getShopContext();
        $categoryId = $context->getShop()->getCategory()->getId();

        /** @var StoreFrontEmotionDeviceConfiguration $service */
        $service = $this->get(\Shopware\Bundle\EmotionBundle\Service\StoreFrontEmotionDeviceConfigurationInterface::class);
        $emotions = $service->getCategoryConfiguration($categoryId$context);

        $categoryContent = Shopware()->Modules()->Categories()->sGetCategoryContent($categoryId);

        $this->View()->assign([
            'hasCustomerStreamEmotion' => $this->container->get(\Shopware\Models\CustomerStream\CustomerStreamRepositoryInterface::class)->hasCustomerStreamEmotions($categoryId),
            'emotions' => $emotions,
            
/** * @deprecated in 5.7, will be private in 5.8 * * @param int $categoryId * @param bool $withStreams * @param int $streamId * * @return array{emotions: array<array<string, mixed>>, hasEmotion: bool, showListing: bool, isHomePage: bool, showListingButton: bool} */
    protected function getEmotionConfiguration($categoryId$withStreams = false, $streamId = null)
    {
        $context = $this->contextService->getShopContext();

        $emotions = $this->storeFrontEmotionDeviceConfiguration->getCategoryConfiguration($categoryId$context$withStreams);

        $emotions = $this->filterListingEmotions($emotions);

        $isHomePage = $context->getShop()->getCategory()->getId() === $categoryId;

        $devicesWithListing = $this->getDevicesWithListing($emotions);
        if ($isHomePage) {
            $devicesWithListing = [];
        }

        
public function indexAction()
    {
        $addresses = $this->addressRepository->getListArray(
            $this->container->get('session')->get('sUserId')
        );

        // Create a list of ids of occurring countries and states         $countryIds = array_unique(array_filter(array_column($addresses, 'countryId')));
        $stateIds = array_unique(array_filter(array_column($addresses, 'stateId')));

        $countryRepository = $this->container->get(CountryGatewayInterface::class);
        $context = $this->container->get(ContextServiceInterface::class)->getShopContext();

        $countries = $countryRepository->getCountries($countryIds$context);
        $states = $countryRepository->getStates($stateIds$context);

        // Apply translations for countries and states to address array, converting them from structs to arrays in the process         foreach ($addresses as &$address) {
            if (\array_key_exists($address['countryId']$countries)) {
                $address['country'] = json_decode(json_encode($countries[$address['countryId']]), true);
            }
            if (\array_key_exists($address['stateId']$states)) {
                $address['state'] = json_decode(json_encode($states[$address['stateId']]), true);
            }

        $criteria = new Criteria();
        $criteria->addBaseCondition(new CategoryCondition([$categoryId]));
        $criteria->addSorting(new ManualSorting());
        $criteria->offset($start);
        $criteria->limit($limit);

        foreach ($customSorting->getSortings() as $sorting) {
            $criteria->addSorting($sorting);
        }

        $query = $this->queryBuilderFactory->createQueryWithSorting($criteria$this->contextService->getShopContext());

        $data = [];
        $query
            ->leftJoin('variant', 's_articles_prices', 'price', 'price.articledetailsID = variant.id AND price.from = 1 AND price.pricegroup = \'EK\'')
            ->leftJoin('product', 's_core_tax', 'tax', 'tax.id = product.taxID')
            ->leftJoin('product', 's_articles_img', 'img', 'img.articleID = product.id AND img.main = 1')
            ->leftJoin('img', 's_media', 'media', 'media.id = img.media_id')
            ->addSelect('SQL_CALC_FOUND_ROWS product.id as id')
            ->addSelect('product.name')
            
ModelManager $modelManager = null,
        ?MediaServiceInterface $mediaService = null,
        ?StorefrontMediaServiceInterface $storefrontMediaService = null,
        ?LegacyStructConverter $legacyStructConverter = null,
        ?ContainerAwareEventManager $eventManager = null
    ) {
        $container = Shopware()->Container();

        $category = $container->get('shop')->getCategory();
        $this->categoryId = (int) ($category ? $category->getId() : 0);
        $this->contextService = $contextService ?? $container->get(ContextServiceInterface::class);
        $this->customerGroupId = (int) $this->contextService->getShopContext()->getCurrentCustomerGroup()->getId();

        $this->additionalTextService = $additionalTextService ?? $container->get(AdditionalTextServiceInterface::class);

        $this->config = $config ?? $container->get('config');
        $this->productModule = $productModule ?? $container->get('modules')->Articles();
        $this->basketModule = $basketModule ?? $container->get('modules')->Basket();
        $this->front = $front ?: $container->get('front');
        $this->connection = $connection ?: $container->get(Connection::class);
        $this->modelManager = $modelManager ?: $container->get(ModelManager::class);
        $this->mediaService = $mediaService ?: $container->get(MediaServiceInterface::class);
        $this->storefrontMediaService = $storefrontMediaService ?: $container->get(StorefrontMediaServiceInterface::class);
        
public function __construct(ListProductServiceInterface $listProductService, LegacyStructConverter $converter, ContextServiceInterface $contextService)
    {
        $this->listProductService = $listProductService;
        $this->converter = $converter;
        $this->contextService = $contextService;
    }

    public function resolve(): void
    {
        if (!empty($this->resolveIds)) {
            $products = $this->listProductService->getList($this->resolveIds, $this->contextService->getShopContext());

            foreach ($products as $product) {
                $this->storage[$product->getNumber()] = $this->converter->convertListProductStruct($product);
            }

            $this->resolveIds = [];
        }
    }
}
// Returns the blog article data         $blogArticles = iterator_to_array($paginator);

        $blogArticles = $this->translateBlogArticles($blogArticles);

        $mediaIds = array_map(function D$blogArticle) {
            if (isset($blogArticle['media']) && $blogArticle['media'][0]['mediaId']) {
                return $blogArticle['media'][0]['mediaId'];
            }
        }$blogArticles);

        $context = $this->get(ContextServiceInterface::class)->getShopContext();
        $medias = $this->get(MediaServiceInterface::class)->getList($mediaIds$context);

        foreach ($blogArticles as $key => $blogArticle) {
            // Adding number of comments to the blog article             $blogArticles[$key]['numberOfComments'] = \count($blogArticle['comments']);

            // Adding tags and tag filter links to the blog article             $tagsData = $this->repository->getTagsByBlogId($blogArticle['id'])->getArrayResult();
            $blogArticles[$key]['tags'] = $this->addLinksToFilter($tagsData, 'sFilterTags', 'name', false);

            // Adding average vote data to the blog article
if (!$this->checkRequest($request)) {
            throw new CSRFTokenValidationException(sprintf('The provided X-CSRF-Token for path "%s" is invalid. Please go back, reload the page and try again.', $request->getRequestUri()));
        }

        // mark request as validated to avoid double validation         $request->setAttribute(self::CSRF_WAS_VALIDATED, true);
    }

    public function clearExistingCookie(): void
    {
        $shop = $this->contextService->getShopContext()->getShop();
        $name = $this->getCsrfName();

        $response = $this->container->get('front')->Response();
        $response->headers->setCookie(new Cookie(
            $name,
            Random::getAlphanumericString(30),
            0,
            sprintf('%s/', $shop->getPath() ?: ''),
            '',
            $shop->getSecure(),
            false
        ));
Home | Imprint | This part of the site doesn't use cookies.