getRepository example


    public function save($data)
    {
        $model = $this->getRepository()->find((int) ($data['id'] ?? 0));
        if ($model === null) {
            $model = new $this->model();
            $this->getManager()->persist($model);
        }

        $data = $this->resolveExtJsData($data);
        $model->fromArray($data);

        $violations = $this->getManager()->validate($model);
        $errors = [];
        foreach ($violations as $violation) {
            
/** * Print category urls * * @param int $parentId * * @return array */
    private function readCategoryUrls($parentId)
    {
        /** @var array<array<string, mixed>> $categories */
        $categories = $this->em
            ->getRepository(Category::class)
            ->getActiveChildrenList($parentId$this->contextService->getShopContext()->getFallbackCustomerGroup()->getId());

        foreach ($categories as &$category) {
            $category['show'] = empty($category['external']);

            $category['urlParams'] = [
                'sViewport' => 'cat',
                'sCategory' => $category['id'],
                'title' => $category['name'],
            ];

            

    public function getCampaignsRepository()
    {
        trigger_error(sprintf('%s:%s is deprecated since Shopware 5.6 and will be private with 5.8.', __CLASS__, __METHOD__), E_USER_DEPRECATED);

        if ($this->campaignsRepository === null) {
            $this->campaignsRepository = $this->get('models')->getRepository(Newsletter::class);
        }

        return $this->campaignsRepository;
    }

    /** * Gets a list of the custom newsletter groups (s_campaigns_groups) */
    public function getNewsletterGroupsAction()
    {
        $filter = $this->Request()->getParam('filter');
        
return 0;
    }

    /** * Handles cleaning process and returns the number of deleted media objects */
    private function handleCleanup(SymfonyStyle $io): int
    {
        $em = $this->getContainer()->get(ModelManager::class);

        $query = $em->getRepository(Media::class)->getAlbumMediaQuery(Album::ALBUM_GARBAGE);
        $query->setHydrationMode(AbstractQuery::HYDRATE_OBJECT);

        $count = (int) $em->getQueryCount($query);
        $iterableResult = $query->toIterable();

        $progressBar = $io->createProgressBar($count);

        try {
            foreach ($iterableResult as $key => $media) {
                $em->remove($media);
                if ($key % 100 === 0) {
                    
$params
        );

        return $data['secret'];
    }

    /** * Returns the domain of the shop */
    private function getDomain(): string
    {
        $default = $this->modelManager->getRepository(Shop::class)->getActiveDefault();

        return (string) $default->getHost();
    }

    /** * Check the date of the last subscription-check var */
    private function isPluginsSubscriptionCookieValid(Request $request): bool
    {
        if ($request->getParam('force')) {
            return true;
        }
$request = $this->container->get('front')->Request();

        if ($request && $request->getHttpHost()) {
            return ($request->isSecure() ? 'https' : 'http') . '://' . $request->getHttpHost() . $request->getBasePath() . '/' . $this->createPublicPath();
        }

        if ($this->container->initialized('shop')) {
            /** @var Shop $shop */
            $shop = $this->container->get('shop');
        } else {
            /** @var Shop $shop */
            $shop = $this->container->get(\Shopware\Components\Model\ModelManager::class)->getRepository(Shop::class)->getActiveDefault();
        }

        if ($shop->getMain()) {
            $shop = $shop->getMain();
        }

        if ($shop->getSecure()) {
            return 'https://' . $shop->getHost() . $shop->getBasePath() . '/' . $this->createPublicPath();
        }

        return 'http://' . $shop->getHost() . $shop->getBasePath() . '/' . $this->createPublicPath();
    }
/** * @var \Shopware\Models\Shop\Repository */
    protected $shopRepository;

    /** * Returns a JSON string to the view containing all Product Feeds */
    public function getFeedsAction()
    {
        try {
            $repository = $this->get('models')->getRepository(ProductFeed::class);
            $dataQuery = $repository->getListQuery(
                $this->Request()->getParam('sort', []),
                $this->Request()->getParam('start'),
                $this->Request()->getParam('limit')
            );

            $totalCount = $this->get('models')->getQueryCount($dataQuery);
            $feeds = $dataQuery->getArrayResult();

            $this->View()->assign(['success' => true, 'data' => $feeds, 'totalCount' => $totalCount]);
        } catch (Exception $e) {
            
/** * @return void */
    public function configureOptions(OptionsResolver $resolver)
    {
        parent::configureOptions($resolver);

        // Invoke the query builder closure so that we can cache choice lists         // for equal query builders         $queryBuilderNormalizer = function DOptions $options$queryBuilder) {
            if (\is_callable($queryBuilder)) {
                $queryBuilder = $queryBuilder($options['em']->getRepository($options['class']));

                if (null !== $queryBuilder && !$queryBuilder instanceof QueryBuilder) {
                    throw new UnexpectedTypeException($queryBuilder, QueryBuilder::class);
                }
            }

            return $queryBuilder;
        };

        $resolver->setNormalizer('query_builder', $queryBuilderNormalizer);
        $resolver->setAllowedTypes('query_builder', ['null', 'callable', QueryBuilder::class]);
    }
if ($input->getOption('shop')) {
            $io = new SymfonyStyle($input$output);
            $io->warning('Option "--shop" will be replaced by option "--shopId" in the next major version');
            $shopId = $input->getOption('shop');
        } elseif ($input->getOption('shopId')) {
            $shopId = $input->getOption('shopId');
        }

        if ($shopId) {
            /** @var Shop|null $shop */
            $shop = $em->getRepository(Shop::class)->find($shopId);
            if (!$shop) {
                $output->writeln(sprintf('Could not find shop with id %s.', $shopId));

                return 1;
            }
            $shops = [$shop];
        } else {
            $shops = $em->getRepository(Shop::class)->findAll();
        }

        /** @var Shop $shop */
        
/** * Variant API Resource */
class Variant extends Resource implements BatchInterface
{
    /** * @return Repository */
    public function getRepository()
    {
        return $this->getManager()->getRepository(Detail::class);
    }

    /** * @param string $number * * @return array|Detail */
    public function getOneByNumber($number, array $options = [])
    {
        $id = $this->getIdFromNumber($number);

        


        return [];
    }

    /** * {@inheritdoc} */
    public function completeArgumentValues($argumentName, CompletionContext $context)
    {
        if ($argumentName === 'plugin') {
            $repository = $this->getContainer()->get(ModelManager::class)->getRepository(Plugin::class);
            $queryBuilder = $repository->createQueryBuilder('plugin');
            $result = $queryBuilder->andWhere($queryBuilder->expr()->eq('plugin.capabilityEnable', 'true'))
                ->select(['plugin.name'])
                ->getQuery()
                ->getArrayResult();

            return array_column($result, 'name');
        }

        if ($argumentName === 'key') {
            $pluginName = $context->getWordAtIndex($context->getWordIndex() - 1);
            
$this->evaluationHelper = $evaluationHelper;
        $this->identifierSelector = $identifierSelector;
        $this->shopGateway = $shopGateway;
    }

    /** * {@inheritdoc} */
    public function completeOptionValues($optionName, CompletionContext $context)
    {
        if ($optionName === 'shopId') {
            $queryBuilder = $this->modelManager->getRepository(ShopModel::class)->createQueryBuilder('shop');

            if (is_numeric($context->getCurrentWord())) {
                $queryBuilder->andWhere($queryBuilder->expr()->like('shop.id', ':id'))
                    ->setParameter('id', addcslashes($context->getCurrentWord(), '%_') . '%');
            }

            $result = $queryBuilder->select(['shop.id'])
                ->addOrderBy($queryBuilder->expr()->asc('shop.id'))
                ->getQuery()
                ->getArrayResult();

            
/** * Order API Resource */
class Order extends Resource
{
    /** * @return Repository */
    public function getRepository()
    {
        return $this->getManager()->getRepository(OrderModel::class);
    }

    /** * Little helper function for the ...ByNumber methods * * @param string $number * * @throws NotFoundException * @throws ParameterMissingException * * @return int */
/** * Starts a template preview for the passed theme and shop id. * * @return void */
    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');

        
return true;
        }

        $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);

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