getModelManager example


    protected function getContent($formId)
    {
        $fields = [];
        $labels = [];

        $shopId = $this->container->get(ContextServiceInterface::class)->getShopContext()->getShop()->getId();

        $modelManager = $this->getModelManager();
        $query = $modelManager->getRepository(Form::class)->getActiveFormQuery($formId$shopId);

        $form = $query->getOneOrNullResult(AbstractQuery::HYDRATE_OBJECT);

        if (!$form instanceof Form) {
            throw new Enlight_Controller_Exception(
                'Form not found',
                Enlight_Controller_Exception::Controller_Dispatcher_Controller_Not_Found
            );
        }

        
if (\is_array($filter) && isset($filter[0]['value'])) {
            $filter = $filter[0]['value'];
        }

        if ($dispatchID === null) {
            $dispatchID = $this->Request()->getParam('id');
        }

        $query = $this->getRepository()->getShippingCostsQuery($dispatchID$filter$sort$limit$offset);
        $query->setHydrationMode(AbstractQuery::HYDRATE_ARRAY);

        $paginator = $this->getModelManager()->createPaginator($query);
        // Returns the total count of the query         $totalResult = $paginator->count();
        $shippingCosts = iterator_to_array($paginator);
        $shippingCosts = $this->convertShippingCostsDates($shippingCosts);

        if ($totalResult > 0) {
            $shippingCosts = $this->translateDispatchMethods($shippingCosts);
        }

        $this->View()->assign(['success' => true, 'data' => $shippingCosts, 'total' => $totalResult]);
    }

    
$namespace = Shopware()->Snippets()->getNamespace('backend/mail/view/navigation');

            return $namespace->get('mails_documents_default', 'Default template');
        }

        $documentEmailsNamePrefix = 'document_';
        if (mb_strpos($mailName$documentEmailsNamePrefix) !== 0) {
            return $mailName;
        }
        $documentTypeKey = str_replace($documentEmailsNamePrefix, '', $mailName);
        /** @var Document|null $documentType */
        $documentType = $this->getModelManager()->getRepository(Document::class)->findOneBy([
            'key' => $documentTypeKey,
        ]);
        if (!$documentType) {
            return $mailName;
        }

        return $documentType->getName();
    }
}

    public function createMail($mailModel$context = []$shop = null, $overrideConfig = [])
    {
        if ($shop !== null) {
            $this->setShop($shop);
        }

        if (!($mailModel instanceof Mail)) {
            $modelName = $mailModel;
            $mailModel = $this->getModelManager()->getRepository(Mail::class)->findOneBy(
                ['name' => $modelName]
            );
            if (!$mailModel instanceof Mail) {
                throw new Enlight_Exception(sprintf('Mail-Template with name "%s" could not be found.', $modelName));
            }
        }

        $config = Shopware()->Config();
        $inheritance = Shopware()->Container()->get('theme_inheritance');
        $eventManager = Shopware()->Container()->get('events');

        

    public function getMailTemplatesAction()
    {
        $limit = (int) $this->Request()->getParam('limit', 100);
        $offset = (int) $this->Request()->getParam('start', 0);
        $order = $this->Request()->getParam('sort', []);
        $filter = $this->Request()->getParam('filter', []);

        $mailTemplatesQuery = $this->getModelManager()->getRepository(Mail::class)->getMailsListQueryBuilder(
            $filter,
            $order,
            $offset,
            $limit
        );

        $mailTemplates = $mailTemplatesQuery->getQuery()->getResult(AbstractQuery::HYDRATE_ARRAY);

        // Add a display name to the mail templates         $documentTypes = $this->getModelManager()->getRepository(DocumentType::class)->findAll();
        $documentTypeNames = [];

        

    public function listRecipientsAction()
    {
        $filter = $this->Request()->getParam('filter');
        $sort = $this->Request()->getParam('sort');
        $limit = $this->Request()->getParam('limit', 10);
        $offset = $this->Request()->getParam('start', 0);

        $query = $this->getCampaignsRepository()->getListAddressesQuery($filter$sort$limit$offset);
        $query->setHydrationMode(AbstractQuery::HYDRATE_ARRAY);

        $paginator = $this->getModelManager()->createPaginator($query);
        // Returns the total count of the query         $totalResult = $paginator->count();
        // Returns the customer data         $result = iterator_to_array($paginator);

        $this->View()->assign([
            'success' => true,
            'data' => $result,
            'total' => $totalResult,
        ]);
    }

    
$validTypes = explode('|', $validTypes);

        if ($albumID === null || $albumID === 0) {
            // If no albumId is given load the unsorted album             $albumID = self::UNSORTED_ALBUM_ID;
        }

        /** @var Repository $repository */
        $repository = $this->get(ModelManager::class)->getRepository(Media::class);
        $query = $repository->getAlbumMediaQuery($albumID$filter$order$offset$limit$validTypes);

        $paginator = $this->getModelManager()->createPaginator($query);

        // Returns the total count of the query         $totalResult = $paginator->count();

        $mediaList = $query->getResult(AbstractQuery::HYDRATE_ARRAY);
        $mediaService = $this->get(MediaServiceInterface::class);

        foreach ($mediaList as &$media) {
            $media['path'] = $mediaService->getUrl($media['path']);
            $media['virtualPath'] = $mediaService->normalize($media['path']);

            
if ($sort !== null) {
            $builder->addOrderBy($sort);
        }

        $builder->setFirstResult($offset)
                ->setMaxResults($limit);

        /** @var Query<array<string, mixed>> $query */
        $query = $builder->getQuery();
        $query->setHydrationMode(AbstractQuery::HYDRATE_ARRAY);
        $paginator = $this->getModelManager()->createPaginator($query);
        $total = $paginator->count();
        $orders = iterator_to_array($paginator);

        // Translate payment and dispatch method names.         $translationComponent = $this->get(Shopware_Components_Translation::class);
        $orders = $translationComponent->translateOrders($orders);

        $this->View()->assign([
            'success' => true,
            'data' => $orders,
            'total' => $total,
        ]);
$this->View()->assign([
            'success' => true,
            'data' => ['count' => \count($urls)],
        ]);
    }

    /** * Regenerate sitemap cache */
    public function buildSitemapCacheAction()
    {
        $shops = $this->getModelManager()->getRepository(Shop::class)->getActiveShopsFixed();

        foreach ($shops as $shop) {
            $this->container->get(SitemapExporter::class)->generate($shop);
        }

        $this->View()->assign('success', true);
    }

    protected function initAcl()
    {
    }

    
$this->addressService->setDefaultBillingAddress($address);

        $this->redirect(['action' => 'index', 'success' => 'default_billing']);
    }

    /** * Selection of addresses for the current logged-in customer */
    public function ajaxSelectionAction()
    {
        $extraData = $this->Request()->getParam('extraData', []);
        $addresses = $this->getModelManager()
            ->getRepository(Address::class)
            ->getListArray($this->get('session')->get('sUserId'));
        $activeAddressId = $this->Request()->getParam('id');

        if (!empty($activeAddressId)) {
            foreach ($addresses as $key => $address) {
                if ($address['id'] == $activeAddressId) {
                    unset($addresses[$key]);
                }
            }
        }

        
'hasResolver' => $hasResolver,
            ];
        }

        $this->View()->assign('data', $data);
    }

    public function createAction(Request $request): void
    {
        $type = $this->convertExtJsToStruct($request->request->all());

        $this->getModelManager()->getConnection()->insert('s_content_types', [
            'internalName' => $type->getInternalName(),
            'name' => $type->getName(),
            'source' => $type->getSource(),
            'config' => json_encode($type, JSON_THROW_ON_ERROR),
        ]);

        $this->typeProvider->addType($type->getInternalName()$type);
        $this->clearCacheAndSync();

        $this->View()->assign([
            'success' => true,
            


    /** * @param Query<Template> $query * * @return Paginator<Template> */
    private function getQueryPaginator(Query $query): Paginator
    {
        $query->setHydrationMode(AbstractQuery::HYDRATE_ARRAY);

        return $this->getModelManager()->createPaginator($query);
    }

    /** * Collects all media related x_types which needs to be normalized * * @return array<string> */
    private function getMediaXTypes(): array
    {
        $mediaFields = new ArrayCollection([
            'mediaselectionfield',
            
$rules = [];
            foreach ($data['rules'] as $ruleData) {
                $rule = new Rule();
                $rule->fromArray($ruleData);
                $rule->setGroup($model);
                $rules[] = $rule;
            }
            $data['rules'] = $rules;

            $model->fromArray($data);

            $this->getModelManager()->persist($model);
            $this->getModelManager()->flush();
        }

        $this->View()->assign(['success' => true]);
    }

    private function beforeSaveElement(array $elementData): void
    {
        if ($elementData['name'] === 'shopsalutations') {
            $this->createSalutationSnippets($elementData);
        }
    }
namespace Shopware\Controllers\Backend;

use Shopware\Bundle\StoreFrontBundle\Struct\Search\CustomSorting;
use Shopware\Models\Shop\Shop;
use Shopware_Controllers_Backend_ExtJs;

class ManualSorting extends Shopware_Controllers_Backend_ExtJs
{
    public function preDispatch()
    {
        parent::preDispatch();
        $this->get(\Shopware\Components\ShopRegistrationServiceInterface::class)->registerShop($this->getModelManager()->getRepository(Shop::class)->getActiveDefault());
    }

    public function listAction(int $start = 0, int $limit = 25, int $categoryId = 3, int $sortingId = 1): void
    {
        $sorting = $this->getSorting($categoryId$sortingId);

        $products = $this->get(\Shopware\Components\ManualSorting\ProductLoaderInterface::class)->load($categoryId$start$limit$sorting);

        $this->View()->assign($products);
    }

    


    /** * return the customerId for the customer mapping * * @return void */
    public function mapCustomerAccountAction()
    {
        $mapCustomerAccountValue = $this->Request()->request->getInt('mapCustomerAccountValue');

        $repository = $this->getModelManager()->getRepository(Customer::class);
        $customer = $repository->find($mapCustomerAccountValue);

        if (!$customer) {
            return;
        }

        echo sprintf(
            '%s %s %s %s|%d',
            $customer->getNumber(),
            $customer->getFirstname() . ' ' . $customer->getLastname(),
            $customer->getDefaultBillingAddress() ? $customer->getDefaultBillingAddress()->getCompany() : '',
            
Home | Imprint | This part of the site doesn't use cookies.