setShop example



    /** * Allows to set a Shopware config * * @param bool|float|int|string|null $value */
    protected function setConfig(string $name$value): void
    {
        Shopware()->Container()->get('config_writer')->save($name$value);
        Shopware()->Container()->get(Zend_Cache_Core::class)->clean();
        Shopware()->Container()->get(Shopware_Components_Config::class)->setShop(Shopware()->Shop());
    }
}
$container->load('mailtransport');

        $stringCompiler = new Shopware_Components_StringCompiler(
            $container->get(Enlight_Template_Manager::class)
        );
        $mailer = new Shopware_Components_TemplateMail();
        if ($container->initialized('shop')) {
            $shop = $container->get('shop');
            if (!$shop instanceof Shop) {
                throw new RuntimeException('Shop object not found in DI container');
            }
            $mailer->setShop($shop);
        }
        $mailer->setModelManager($container->get(ModelManager::class));
        $mailer->setStringCompiler($stringCompiler);

        return $mailer;
    }
}
return;
            }
        }

        $attachment = $this->get('models')->getRepository(Attachment::class)->find($attachmentId);
        if (!$attachment) {
            $this->View()->assign(['success' => false, 'message' => 'Attachment not found']);

            return;
        }

        $attachment->setShop($shop);

        try {
            $this->get('models')->flush();
        } catch (Exception $e) {
            $this->View()->assign(['success' => false, 'message' => $e->getMessage()]);

            return;
        }

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

    
$this->release = $config['release'];

        if (isset($config['cache'])
            && $config['cache'] instanceof Zend_Cache_Core) {
            $this->_cache = $config['cache'];
        }
        if (isset($config['db'])
            && $config['db'] instanceof Connection) {
            $this->_db = $config['db'];
        }
        if (isset($config['shop'])) {
            $this->setShop($config['shop']);
        } else {
            $this->load();
        }
    }

    /** * Magic getter * * @param string $name * * @return bool */
$shop = $this->getModelManager()->getReference(Shop::class$this->get('shop')->getId());

        $blogCommentModel->setBlog($blog);
        $blogCommentModel->setCreationDate(new DateTime());
        $blogCommentModel->setActive(false);

        $blogCommentModel->setName($commentData['name']);
        $blogCommentModel->setEmail($commentData['eMail']);
        $blogCommentModel->setHeadline($commentData['headline']);
        $blogCommentModel->setComment($commentData['comment']);
        $blogCommentModel->setPoints($commentData['points']);
        $blogCommentModel->setShop($shop);

        $this->get('models')->persist($blogCommentModel);
        $this->get('models')->flush();
    }

    /** * Returns all data needed to display the pager * * @param int $totalResult * @param int $limitEnd * @param int $page * @param int $categoryId * * @return array */
if (isset($categoryData['shopId'])) {
                $shop = $this->manager->find(
                    Shop::class,
                    $categoryData['shopId']
                );

                if (!$shop instanceof Shop) {
                    throw new CustomValidationException(sprintf('Could not find shop by id: %s.', $categoryData['shopId']));
                }

                $seoCategory->setShop($shop);
            }

            if (!$seoCategory->getShop()) {
                throw new CustomValidationException(sprintf('A product seo category requires a configured shop'));
            }

            if (isset($categoryData['categoryId'])) {
                $category = $this->manager->find(Category::class$categoryData['categoryId']);

                if (!$category instanceof Category) {
                    throw new CustomValidationException(sprintf('Could not find category by id: %s.', $categoryData['categoryId']));
                }
$licences = [];

        foreach ($data as $row) {
            if (!isset($row['plugin'])) {
                continue;
            }

            $licence = new LicenceStruct();

            $licence->setLabel($row['description']);
            $licence->setTechnicalName($row['plugin']['name']);
            $licence->setShop($row['shop']);
            if ($row['domain']) {
                $licence->setShop($row['domain']);
            }
            $licence->setIconPath($row['plugin']['iconPath']);

            if (isset($row['creationDate'])) {
                $date = new DateTime($row['creationDate']);
                $licence->setCreationDate($date);
            }

            $subscription = null;
            
foreach ($element->getValues() as $valueModel) {
            $removedValues[] = $valueModel;
            $modelManager->remove($valueModel);
        }
        $modelManager->flush($removedValues);

        $values = [];
        // Do not save default value         if ($value !== $element->getValue()) {
            $valueModel = new Shopware\Models\Config\Value();
            $valueModel->setElement($element);
            $valueModel->setShop($shop);
            $valueModel->setValue($value);
            $values[$shop->getId()] = $valueModel;
        }

        $element->setValues(new ArrayCollection($values));
        $modelManager->flush($element);
    }

    /** * @deprecated in 5.6, will be private in 5.8 * * Read a given config by name * * @param string $configName * @param string $defaultValue * * @return array<array-key, mixed>|bool|float|int|string|null */
$context = [];
        $allShops = $mainShop->getChildren();
        $allShops[] = $mainShop;

        foreach ($allShops as $shop) {
            $detachedShop = $shopRepository->getActiveById($shop->getId());
            if ($detachedShop === null) {
                continue;
            }

            $newConfig = clone $config;
            $newConfig->setShop($detachedShop);

            $context[$detachedShop->getId()] = Context::createFromShop($detachedShop$newConfig);
        }

        return $context;
    }
}


            // Simple data validation             if (!$this->validateData($elementData$valueData['value'])) {
                continue;
            }

            $valueData['value'] = $this->prepareValue($elementData$valueData['value']);

            $value = new Value();
            $value->setElement($element);
            $value->setShop($shop);
            $value->setValue($valueData['value']);
            $values[$shop->getId()] = $value;
        }

        $this->beforeSaveElement($elementData);

        $values = Shopware()->Events()->filter(
            'Shopware_Controllers_Backend_Config_Before_Save_Config_Element',
            $values,
            [
                'subject' => $this,
                

        $this->container->set('shop', $shop);

        $locale = $this->container->get(Zend_Locale::class);
        $locale->setLocale($shop->getLocale()->toString());

        $currency = $this->container->get(Zend_Currency::class);
        $currency->setLocale($locale);
        $currency->setFormat($shop->getCurrency()->toArray());

        $config = $this->container->get(Shopware_Components_Config::class);
        $config->setShop($shop);

        $snippets = $this->container->get(Shopware_Components_Snippet_Manager::class);
        $snippets->setShop($shop);

        $plugins = $this->container->get(Enlight_Plugin_PluginManager::class);

        foreach ($plugins as $pluginNamespace) {
            if ($pluginNamespace instanceof Shopware_Components_Plugin_Namespace) {
                $pluginNamespace->setShop($shop);
            }
        }

        
if ($element->getType() === 'theme-media-selection') {
                $data['value'] = $this->mediaService->normalize($data['value']);
            }

            // Don't save default values             if ($element->getDefaultValue() === $data['value']) {
                $element->getValues()->removeElement($value);
                continue;
            }

            $value->setShop($shop);
            $value->setElement($element);
            $value->setValue($data['value']);
        }

        $this->entityManager->flush();
    }

    /** * Translates the theme meta data. * * @return array */
if (!$element instanceof ConfigElement) {
            throw new ModelNotFoundException(ConfigElement::class$name, 'name');
        }

        $value = $element->getValues()->filter(static fn (Value $value) => $value->getShopId() === $shopId)->first();

        if ($value instanceof Value) {
            $value->setValue($inputValue);
        } else {
            $value = new Value();
            $value->setElement($element);
            $value->setShop($shop);
            $value->setValue($inputValue);

            $modelManager->persist($value);
        }

        $modelManager->flush($value);

        return 0;
    }
}

    public function setPriceGroup($priceGroup)
    {
        $this->priceGroup = $priceGroup;
    }

    public function setLanguageSubShop(Shop $languageSubShop)
    {
        $this->languageSubShop = $languageSubShop;

        $subShop = $languageSubShop->getMain() ?: $languageSubShop;
        $this->setShop($subShop);
    }

    /** * @return Shop */
    public function getLanguageSubShop()
    {
        return $this->languageSubShop;
    }

    public function setLanguageId(string $languageId): void
    {
public function onAfterRegisterShop(Enlight_Event_EventArgs $args)
    {
        /** @var Container $container */
        $container = $args->getSubject();
        /** @var RouterInterface $router */
        $router = $container->get(\Shopware\Components\Routing\RouterInterface::class);
        /** @var \Shopware\Models\Shop\Shop $shop */
        $shop = $container->get('shop');
        /** @var Shopware_Components_Config $config */
        $config = $container->get(Shopware_Components_Config::class);
        // Register the shop (we're too soon)         $config->setShop($shop);

        $context = $router->getContext();
        $newContext = Context::createFromShop($shop$config);
        // Reuse the host         if ($newContext->getHost() === null) {
            $newContext->setHost($context->getHost());
            $newContext->setBaseUrl($context->getBaseUrl());
            $newContext->setSecure($context->isSecure());
        }
        // Reuse the global params like controller and action         $globalParams = $context->getGlobalParams();
        
Home | Imprint | This part of the site doesn't use cookies.