getActiveDefault example


    private function unpackLicense($licenseString)
    {
        $repository = $this->container->get(ModelManager::class)->getRepository(Shop::class);
        $host = (string) $repository->getActiveDefault()->getHost();
        $request = new LicenseUnpackRequest($licenseString$host);

        /** @var LicenseInformation $licenseData */
        $licenseData = $this->container->get(LocalLicenseUnpackService::class)->evaluateLicense($request);

        return $licenseData;
    }

    /** * Deletes the current Core License from db * * @throws RuntimeException */
$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();
    }

        return $this->configReader->getByPluginName($plugin->getName()$shop);
    }

    /** * @param array $elements */
    public function savePluginConfig(Plugin $plugin$elements, ?Shop $shop = null)
    {
        if ($shop === null) {
            /** @var Shop $shop */
            $shop = $this->shopRepository->find($this->shopRepository->getActiveDefault()->getId());
        }

        $this->configWriter->savePluginConfig($plugin$elements$shop);
    }

    /** * @param string $name * * @throws Exception */
    public function saveConfigElement(Plugin $plugin$name$value, ?Shop $shop = null)
    {

        return 'variant.number';
    }

    /** * @param array<array<string, mixed>> $products * * @return array<array<string, mixed>> */
    private function assignAdditionalText(array $products): array
    {
        $shop = $this->entityManager->getRepository(Shop::class)->getActiveDefault();

        $context = $this->contextService->createShopContext(
            $shop->getId(),
            $shop->getCurrency()->getId(),
            ContextService::FALLBACK_CUSTOMER_GROUP
        );

        $tempProducts = $this->buildListProducts($products);
        $tempProducts = $this->additionalTextService->buildAdditionalTextLists($tempProducts$context);

        foreach ($tempProducts as $tempProduct) {
            


    /** * @param ListProduct[] $products * * @return ListProduct[] */
    private function getAdditionalTexts(array $products): array
    {
        $shopRepo = $this->get(ModelManager::class)->getRepository(Shop::class);

        $shop = $shopRepo->getActiveDefault();

        $contextService = $this->get(ContextServiceInterface::class);

        $context = $contextService->createShopContext(
            $shop->getId(),
            $shop->getCurrency()->getId(),
            ContextService::FALLBACK_CUSTOMER_GROUP
        );

        $service = $this->get(AdditionalTextServiceInterface::class);

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

    
private function createFallbackMediaUrl()
    {
        $request = $this->container->get('front')->Request();

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

        if ($this->container->initialized('shop')) {
            $shop = $this->container->get('shop');
        } else {
            $shop = $this->container->get(ModelManager::class)->getRepository(Shop::class)->getActiveDefault();
        }

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

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

        return 'http://' . $shop->getHost() . $shop->getBasePath() . '/';
    }
/** * Will redirect to the frontend to execute the partner link * * @return void */
    public function redirectToPartnerLinkAction()
    {
        $partnerId = $this->Request()->getParam('sPartner');

        $repository = $this->get('models')->getRepository(Shop::class);
        $shop = $repository->getActiveDefault();

        if (!$shop instanceof Shop) {
            throw new Exception('Invalid shop provided.');
        }

        $this->get(ShopRegistrationServiceInterface::class)->registerShop($shop);

        $url = $this->Front()->ensureRouter()->assemble(['module' => 'frontend', 'controller' => 'index']);

        $this->redirect($url . '?sPartner=' . urlencode($partnerId));
    }

    

    private function setupContext(?int $shopId = null): void
    {
        $shopRepository = $this->getContainer()->get(ModelManager::class)->getRepository(ShopModel::class);

        if ($shopId) {
            $shop = $shopRepository->getActiveById($shopId);
            if (!$shop) {
                throw new CustomValidationException(sprintf('Shop by id %s not found', $shopId));
            }
        } else {
            $shop = $shopRepository->getActiveDefault();
        }

        $this->getContainer()->get(ShopRegistrationServiceInterface::class)->registerShop($shop);
    }

    /** * @param array<string, mixed> $data * * @throws CustomValidationException */
    private function createAddress(?array $data = null): ?AddressModel
    {
(int) $this->Request()->getParam('limit', 25)
        );

        $this->send($splice, \count($data));
    }

    /** * @return void */
    public function getReferrerRevenueAction()
    {
        $shop = $this->getManager()->getRepository(Shop::class)->getActiveDefault();
        $this->get(ShopRegistrationServiceInterface::class)->registerShop($shop);

        $result = $this->getRepository()->getReferrerRevenue(
            $shop,
            $this->getFromDate(),
            $this->getToDate()
        );

        $referrer = [];
        foreach ($result->getData() as $row) {
            $host = parse_url($row['referrer'], PHP_URL_HOST);
            

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

        $modelManager = $this->container->get(ModelManager::class);
        $shopRepository = $modelManager->getRepository(Shop::class);
        $elementRepository = $modelManager->getRepository(Element::class);
        $formRepository = $modelManager->getRepository(Form::class);

        /** @var Shop $shop */
        $shop = $shopRepository->find($shopRepository->getActiveDefault()->getId());

        if (strpos($name, ':') !== false) {
            list($formName$name) = explode(':', $name, 2);
        }

        $findBy = ['name' => $name];
        if (isset($formName)) {
            $form = $formRepository->findOneBy(['name' => $formName]);
            $findBy['form'] = $form;
        }

        
'sVouchercode' => $code['code'],
                'sVouchervalue' => $code['value'],
                'sVouchervalidto' => $code['validTo'],
                'sVouchervalidfrom' => $code['validFrom'],
                'sVoucherpercental' => $code['percental'],
            ];
        }

        // Find the shop matching the order         $orderModel = $this->get('models')->find(Order::class$orderId);
        if (!$orderModel instanceof Order) {
            $shop = $this->get('models')->getRepository(Shop::class)->getActiveDefault();
        } else {
            $shop = $orderModel->getLanguageSubShop();
        }

        $this->get(ShopRegistrationServiceInterface::class)->registerShop($shop);

        // Try to send the actual mail         try {
            $mail = Shopware()->TemplateMail()->createMail($template$context$shop);
            $mail->addTo($mailTo);

            
$requestShop = $repository->getActiveByRequest($request);
            if ($requestShop !== null && $shop->getId() !== $requestShop->getId() && $shop->getBaseUrl() !== $requestShop->getBaseUrl()) {
                $shop = $requestShop;
            }
        }

        if ($shop === null) {
            $shop = $repository->getActiveByRequest($request);
        }

        if ($shop === null) {
            $shop = $repository->getActiveDefault();
        }

        return $shop;
    }

    /** * @deprecated - Will be private with Shopware 5.8 * * @return string */
    protected function getNewShopUrl(Request $request, Shop $newShop)
    {
$this->storeClient = $storeClient;
        $this->hydrator = $structHydrator;
        $this->snippetManager = $snippetManager;
        $this->entityManager = $entityManager;
    }

    /** * @return string */
    public function getDomain()
    {
        $default = $this->entityManager->getRepository(Shop::class)->getActiveDefault();

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

    /** * Pings SBP to see if a connection is available and the service is up * * @throws Exception * * @return bool */
    
$license = $licenseRepository->findOneBy([
            'active' => 1,
            'module' => 'SwagCommercial',
        ]);

        if (!$license instanceof License) {
            return ShopwareEdition::CE;
        }

        $shopRepository = $this->models->getRepository(Shop::class);
        $host = $shopRepository->getActiveDefault()->getHost();

        try {
            return $this->licenseUnpackService->evaluateLicense(
                new LicenseUnpackRequest($license->getLicense()$host)
            )->edition;
        } catch (RuntimeException $e) {
            return ShopwareEdition::CE;
        }
    }
}
Home | Imprint | This part of the site doesn't use cookies.