getManager example

public function __construct()
    {
        $this->addressService = $this->getContainer()->get(AddressServiceInterface::class);
    }

    /** * @return AddressRepository */
    public function getRepository()
    {
        return $this->getManager()->getRepository(AddressModel::class);
    }

    /** * @param int $id * * @throws NotFoundException * @throws ParameterMissingException * * @return array|AddressModel */
    public function getOne($id)
    {

    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()) {
            
/** * Property API Resource */
class PropertyGroup extends Resource
{
    /** * @return \Shopware\Models\Property\Repository */
    public function getRepository()
    {
        return $this->getManager()->getRepository(\Shopware\Models\Property\Group::class);
    }

    /** * @param int $id * * @throws \Shopware\Components\Api\Exception\ParameterMissingException * @throws \Shopware\Components\Api\Exception\NotFoundException * * @return array|\Shopware\Models\Property\Group */
    public function getOne($id)
    {
public function __construct(?Shopware_Components_Translation $translationComponent = null)
    {
        $this->translationComponent = $translationComponent ?: Shopware()->Container()->get(Shopware_Components_Translation::class);
    }

    /** * @return Repository */
    public function getRepository()
    {
        return $this->getManager()->getRepository(ProductModel::class);
    }

    /** * @return Repository */
    public function getDetailRepository()
    {
        return $this->getManager()->getRepository(Detail::class);
    }

    /** * Little helper function for the ...ByNumber methods * * @param string $number * * @throws NotFoundException * @throws ParameterMissingException * * @return int */


    /** * @deprecated - Will be private in Shopware 5.8 * Helper Method to get access to the shop repository. * * @return ShopRepository */
    public function getShopRepository()
    {
        if ($this->shopRepository === null) {
            $this->shopRepository = $this->getManager()->getRepository(Shop::class);
        }

        return $this->shopRepository;
    }

    /** * @return AnalyticsRepository * * @deprecated - Will be private in Shopware 5.8 */
    public function getRepository()
    {
public function __construct(EmotionPreset $presetResource, SlugInterface $slugService)
    {
        $this->presetResource = $presetResource;
        $this->slugService = $slugService;
    }

    /** * @param PresetMetaDataInterface[] $presetMetaData */
    public function installOrUpdate(array $presetMetaData)
    {
        $modelManager = $this->presetResource->getManager();

        /** @var PresetMetaDataInterface $metaData */
        foreach ($presetMetaData as $metaData) {
            $presetData = [
                'name' => $metaData->getName(),
                'premium' => $metaData->getPremium(),
                'custom' => $metaData->getCustom(),
                'thumbnail' => $metaData->getThumbnail(),
                'preview' => $metaData->getPreview(),
                'translations' => $metaData->getTranslations(),
                'presetData' => json_encode($metaData->getPresetData()),
                
/** * Country API Resource */
class Country extends Resource
{
    /** * @return Repository */
    public function getRepository()
    {
        return $this->getManager()->getRepository(CountryModel::class);
    }

    /** * Returns the data of the Country with the given ID. * * @param int $id * * @throws NotFoundException * @throws ParameterMissingException * * @return array|CountryModel */
if (empty($data['id'])) {
                throw new NotFoundException('The emotion must exist before previewing it.');
            }

            $data['previewId'] = $data['id'];
            $data['previewSecret'] = Random::getAlphanumericString(32);
            $data['active'] = false;

            $previewEmotion = $this->findPreviewEmotion((int) $data['id']);
            if ($previewEmotion) {
                $previewEmotion->getElements()->clear();
                $this->getManager()->flush($previewEmotion);

                $data['id'] = $previewEmotion->getId();
            } else {
                unset($data['id']);
            }

            $emotion = $this->saveEmotion($data);

            if ($emotion === null) {
                $this->View()->assign([
                    'data' => $this->Request()->getParams(),
                    

class Media extends Resource
{
    public const FILENAME_LENGTH = 200;

    /** * @return Repository */
    public function getRepository()
    {
        return $this->getManager()->getRepository(MediaModel::class);
    }

    /** * @param int $id * * @throws ParameterMissingException * @throws NotFoundException * * @return array|MediaModel */
    public function getOne($id)
    {
/** * @deprecated - Will be private in Shopware 5.8 * Get documents of a specific type for the given orders * * @param int[] $orderIds * @param string $docType * * @return Query<Order> */
    public function getOrderDocumentsQuery($orderIds$docType)
    {
        $builder = $this->getManager()->createQueryBuilder();
        $builder->select([
            'orders',
            'documents',
        ]);

        $builder->from(Order::class, 'orders');
        $builder->leftJoin('orders.documents', 'documents')
            ->where('documents.typeId = :type')
            ->andWhere('orders.id IN (:orderIds)')
            ->setParameter('orderIds', $orderIds, Connection::PARAM_INT_ARRAY)
            ->setParameter(':type', $docType);

        
/** * 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);

        

        if (\is_object($request->attributes->get($argument->getName()))) {
            return [];
        }

        $options = $argument->getAttributes(MapEntity::class, ArgumentMetadata::IS_INSTANCEOF);
        $options = ($options[0] ?? $this->defaults)->withDefaults($this->defaults, $argument->getType());

        if (!$options->class || $options->disabled) {
            return [];
        }
        if (!$manager = $this->getManager($options->objectManager, $options->class)) {
            return [];
        }

        $message = '';
        if (null !== $options->expr) {
            if (null === $object = $this->findViaExpression($manager$request$options)) {
                $message = sprintf(' The expression "%s" returned null.', $options->expr);
            }
        // find by identifier?         } elseif (false === $object = $this->find($manager$request$options$argument->getName())) {
            // find by criteria

    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) {
            $errors[] = [
                'message' => $violation->getMessage(),
                'property' => $violation->getPropertyPath(),
            ];
/** * @param string $assetPath * @param int $albumId * * @return Media */
    protected function doAssetImport($assetPath$albumId = -3)
    {
        $media = $this->mediaResource->internalCreateMediaByFileLink($assetPath$albumId);

        $this->mediaResource->getManager()->flush($media);

        return $media;
    }

    /** * @param int $id * * @return object|null */
    protected function getMediaById($id)
    {
        
protected ?string $entityManagerName;

    public function __construct(ManagerRegistry $managerRegistry, string $entityManagerName = null)
    {
        $this->managerRegistry = $managerRegistry;
        $this->entityManagerName = $entityManagerName;
    }

    final public function handle(Envelope $envelope, StackInterface $stack): Envelope
    {
        try {
            $entityManager = $this->managerRegistry->getManager($this->entityManagerName);
        } catch (\InvalidArgumentException $e) {
            throw new UnrecoverableMessageHandlingException($e->getMessage(), 0, $e);
        }

        return $this->handleForManager($entityManager$envelope$stack);
    }

    abstract protected function handleForManager(EntityManagerInterface $entityManager, Envelope $envelope, StackInterface $stack): Envelope;
}
Home | Imprint | This part of the site doesn't use cookies.