ModelNotFoundException example



    /** * @param int $resourceId * * @return Privilege */
    public function setResourceId($resourceId)
    {
        $resource = Shopware()->Models()->find(UserResource::class$resourceId);
        if (!$resource instanceof UserResource) {
            throw new ModelNotFoundException(UserResource::class$resourceId);
        }
        $this->resource = $resource;
        $this->resourceId = $resourceId;

        return $this;
    }

    /** * @return int */
    public function getResourceId()
    {
throw new RuntimeException('Plugin name not initialized correctly');
        }

        return $this->Collection()->getConfig($this->name);
    }

    final public function Plugin(): Plugin
    {
        if ($this->plugin === null) {
            $plugin = Shopware()->Models()->getRepository(Plugin::class)->findOneBy(['id' => $this->getId()]);
            if (!$plugin instanceof Plugin) {
                throw new ModelNotFoundException(Plugin::class$this->getId());
            }
            $this->plugin = $plugin;
        }

        return $this->plugin;
    }

    /** * @return ModelRepository<Form> */
    final public function Forms(): EntityRepository
    {

    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();
        
/** * @throws Exception */
    protected function setOrder(Shopware_Models_Document_Order $order)
    {
        $this->_order = $order;

        $repository = Shopware()->Models()->getRepository(Shop::class);
        // "language" actually refers to a language-shop and not to a locale         $shop = $repository->getById($this->_order->order->language);
        if ($shop === null) {
            throw new ModelNotFoundException(Shop::class$this->_order->order->language);
        }

        if (!empty($this->_order->order->currencyID)) {
            $repository = Shopware()->Models()->getRepository(Currency::class);
            $currency = $repository->find($this->_order->order->currencyID);
            if ($currency === null) {
                throw new ModelNotFoundException(Currency::class$this->_order->order->currencyID);
            }
            $shop->setCurrency($currency);
        }

        


    /** * @param string $technicalName * * @return Plugin */
    public function getPluginModel($technicalName)
    {
        $plugin = $this->getRepository()->findOneBy(['name' => $technicalName]);
        if ($plugin === null) {
            throw new ModelNotFoundException(Plugin::class$technicalName, 'name');
        }

        return $plugin;
    }

    /** * @return ModelRepository<Plugin> */
    private function getRepository()
    {
        return $this->get(ModelManager::class)->getRepository(Plugin::class);
    }
$data = false;
        }
        if ($data === false || !isset($data['customerId'])) {
            throw new InvalidArgumentException(sprintf('The data for hash \'%s\' is corrupted.', $hash));
        }
        $customerId = (int) $data['customerId'];

        $date = new DateTime();

        $customer = $modelManager->find(Customer::class$customerId);
        if (!$customer instanceof Customer) {
            throw new ModelNotFoundException(Customer::class$customerId);
        }

        // One-Time-Account         if ($data['fromCheckout'] === true || $customer->getAccountMode() === 1) {
            $redirection = [
                'controller' => 'checkout',
                'action' => 'confirm',
            ];
        } else {
            $redirection = [
                'controller' => 'account',
                
private const PLACEHOLDER_UP_TO = 'beliebig';

    public function getProductVariantsAction(): void
    {
        $orderId = (int) $this->Request()->getParam('orderId');
        if ($orderId === 0) {
            throw new RuntimeException('The parameter orderId is not set');
        }

        $order = $this->container->get(ModelManager::class)->find(Order::class$orderId);
        if (!$order instanceof Order) {
            throw new ModelNotFoundException(Order::class$orderId);
        }

        $customer = $order->getCustomer();
        if (!$customer instanceof Customer) {
            throw new ModelNotFoundException(Customer::class$orderId);
        }

        $orderShippingAddress = $order->getShipping();
        if (!$orderShippingAddress instanceof Shipping) {
            throw new ModelNotFoundException(Shipping::class$orderId);
        }

        

        $repository = $this->container->get(ModelManager::class)->getRepository(Shop::class);

        $shops = null;
        $shopId = (int) $input->getOption('shopId');

        if ($shopId > 0) {
            $shop = $repository->getById($shopId);
            if ($shop instanceof Shop) {
                $shops = [$shop];
            } else {
                throw new ModelNotFoundException(Shop::class$shopId);
            }
        }

        if (empty($shops)) {
            $shops = $repository->getActiveShopsFixed();
        }

        $sitemapExporter = $this->container->get(SitemapExporter::class);
        foreach ($shops as $shop) {
            $output->writeln(sprintf('Generating sitemaps for shop #%d (%s)...', $shop->getId()$shop->getName()));

            
$shopIds = $input->getOption('shopId');
        }

        $shopRepository = $this->container->get(ModelManager::class)->getRepository(Shop::class);
        $shops = null;

        if (!empty($shopIds)) {
            foreach ($shopIds as $shopId) {
                $shop = $shopRepository->getById($shopId);

                if (!$shop) {
                    throw new ModelNotFoundException(Shop::class$shopId);
                }

                $shops[] = $shop;
            }
        } else {
            $shops = $shopRepository->getActiveShopsFixed();
        }

        $io = new SymfonyStyle($input$output);
        $options = $this->prepareOptions($input->getOptions()$urlProviderFactory);

        
        $params['validFrom'] = $this->prepareDateAndTime($this->Request()->get('validFromDate')$this->Request()->get('validFromTime'));
        // Build a single till date instead of two dates         $params['validTo'] = $this->prepareDateAndTime($this->Request()->get('validToDate')$this->Request()->get('validToTime'));
        // Get media manager         $mediaManagerData = $this->Request()->get('media-manager-selection');

        // Update database entries         if (!$createMode) {
            // Load model from db             $bannerModel = $this->repository->find($id);
            if (!$bannerModel instanceof Banner) {
                throw new ModelNotFoundException(Banner::class(int) $id);
            }
        } else {
            // Check if there are none files submitted             if (empty($mediaManagerData)) {
                $this->View()->assign([
                    'success' => false,
                    'errorMsg' => $this->namespace->get('no_banner_selected', 'No banner has been selected.')]);

                return;
            }
            $bannerModel = new Banner();
        }
$translation['shopId'] = $shop['id'];
                    $product['translations'][$shop['id']] = $translation;
                }
            }

            if (isset($options['language']) && !empty($options['language'])) {
                $shop = $this->findEntityByConditions(Shop::class[
                    ['id' => $options['language']],
                    ['shop' => $options['language']],
                ]);
                if (!$shop instanceof Shop) {
                    throw new ModelNotFoundException(Shop::class$options['language']);
                }

                $product = $this->translateArticle($product$shop);
            }
        }

        return $product;
    }

    /** * Helper function which calculates formats the variant prices for each customer group. * If the customer group configured "taxInput" as true, the price will be formatted as gross. * * @param array $prices Array of the variant prices * @param float $taxRate Float value of the product tax (example: 19.00) * * @return array */
$this->sSettings['encoding'] = 'ISO-8859-1';
        }

        if (empty($this->sSettings['languageID'])) {
            $defaultShop = $shopRepository->getDefault();
            // Just a fall back for update reasons             $this->sSettings['languageID'] = $defaultShop->getId();
        }

        $shop = $shopRepository->getActiveById($this->sSettings['languageID']);
        if (!$shop instanceof Shop) {
            throw new ModelNotFoundException(Shop::class$this->sSettings['languageID']);
        }

        $this->shopData = $this->getShopData($this->sSettings['languageID']);

        if (empty($this->sSettings['categoryID'])) {
            $this->sSettings['categoryID'] = $this->shopData['category_id'];
        }
        if (empty($this->sSettings['customergroupID'])) {
            $this->sSettings['customergroupID'] = (int) $shop->getCustomerGroup()->getId();
        } else {
            $this->sSettings['customergroupID'] = (int) $this->sSettings['customergroupID'];
        }

    public function saveAction()
    {
        $data = $this->Request()->getParams();

        if ($this->Request()->has('id')) {
            $productId = (int) $this->Request()->getParam('id');
            $product = $this->getRepository()->find($productId);
            if (!$product instanceof Product) {
                throw new ModelNotFoundException(Product::class$productId);
            }

            // Check whether the product has been modified in the meantime             try {
                $lastChanged = new DateTime($data['changed']);
            } catch (Exception $e) {
                // If we have a invalid date caused by product imports                 $lastChanged = $product->getChanged();
            }

            if ($lastChanged->getTimestamp() < 0 && $product->getChanged()->getTimestamp() < 0) {
                


        $shop = $shopRepository->find($shopId);
        if (!$shop instanceof Shop) {
            $shop = $shopRepository->getDefault();
        }

        $shopId = $shop->getId();

        $element = $modelManager->getRepository(ConfigElement::class)->findOneBy(['name' => $name]);
        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);

            


    /** * @param array<string, mixed> $elementData */
    private function saveElement(array $elementData, Shop $defaultShop): void
    {
        $shopRepository = $this->getRepository('shop');

        $element = $this->get('models')->find(ConfigElement::class$elementData['id']);
        if (!$element instanceof ConfigElement) {
            throw new ModelNotFoundException(ConfigElement::class$elementData['id']);
        }

        $removedValues = [];
        $modelManager = $this->get('models');
        foreach ($element->getValues() as $value) {
            $modelManager->remove($value);
            $removedValues[] = $value;
        }
        $modelManager->flush($removedValues);

        $values = [];
        
Home | Imprint | This part of the site doesn't use cookies.