setManager example

try {
            /** @var self $resource */
            $resource = $this->getContainer()->get('shopware.api.' . strtolower($name));
        } catch (ServiceNotFoundException $e) {
            $name = ucfirst($name);
            /** @var class-string<self> $class */
            $class = __NAMESPACE__ . '\\Resource\\' . $name;

            $resource = new $class();
        }

        $resource->setManager($this->getManager());

        if ($this->getAcl() !== null) {
            $resource->setAcl($this->getAcl());
        }

        if ($this->getRole() !== null) {
            $resource->setRole($this->getRole());
        }

        return $resource;
    }

    


    /** * Registers the given plugin namespace. The instance of the Enlight_Plugin_PluginManager is * set into the namespace by using the Enlight_Plugin_Namespace::setManager() function. * The namespace name is used as array key. * * @return Enlight_Plugin_PluginManager */
    public function registerNamespace(Enlight_Plugin_Namespace $namespace)
    {
        $namespace->setManager($this);
        $this->plugins[$namespace->getName()] = $namespace;

        return $this;
    }

    /** * Setter for the application property. * * @return Enlight_Plugin_PluginManager */
    public function setApplication(Shopware $application)
    {
trigger_error(sprintf('The requested service with id %s is deprecated. Please use CamelCased service id instead.', $name), E_USER_DEPRECATED);
                $resource = $container->get('shopware.api.' . strtolower($name));
            }
        } catch (ServiceNotFoundException $e) {
            $name = ucfirst($name);
            $class = __NAMESPACE__ . '\\Resource\\' . $name;

            /** @var Resource\Resource $resource */
            $resource = new $class();

            $resource->setContainer($container);
            $resource->setManager($container->get(\Shopware\Components\Model\ModelManager::class));
        }

        if ($container->initialized('auth')) {
            $resource->setAcl($container->get('acl'));
            $resource->setRole($container->get('auth')->getIdentity()->role);
        }

        return $resource;
    }
}
/** * @var MediaServiceInterface */
    protected $mediaService;

    public function __construct(MediaServiceInterface $mediaService, MediaResource $mediaResource, Container $container)
    {
        $this->mediaService = $mediaService;
        $this->mediaResource = $mediaResource;
        $this->mediaResource->setContainer($container);
        $modelManager = $container->get(ModelManager::class);
        $this->mediaResource->setManager($modelManager);
    }

    /** * @param string $assetPath * @param int $albumId * * @return Media */
    protected function doAssetImport($assetPath$albumId = -3)
    {
        $media = $this->mediaResource->internalCreateMediaByFileLink($assetPath$albumId);

        
private $slugService;

    public function __construct(
        Connection $connection,
        ModelManager $models,
        SlugInterface $slugService
    ) {
        $this->connection = $connection;
        $this->models = $models;
        $this->slugService = $slugService;

        $this->setManager($models);
    }

    /** * @param string $locale * @param bool $fetchAll * * @return array[] */
    public function getList($locale = 'de_DE', $fetchAll = true)
    {
        return $this->hydrate($this->fetch($fetchAll)$locale);
    }

        $id = \is_null($this->Request()->getParam('Detail_id')) ? null : (int) $this->Request()->getParam('Detail_id');

        /** @var Detail $variant */
        $variant = $this->getDetailRepository()->find($id);
        if (!\is_object($variant)) {
            $this->View()->assign([
                'success' => false,
            ]);
        } else {
            $articleResource = new ArticleResource();
            $articleResource->setManager($this->get(ModelManager::class));

            if ($variant->getKind() == 1) {
                $articleResource->delete($variant->getArticle()->getId());
            } else {
                $this->get('models')->remove($variant);
            }

            $this->get('models')->flush();

            $this->View()->assign([
                'success' => true,
            ]);
Home | Imprint | This part of the site doesn't use cookies.