Skip to content

Commit

Permalink
[framework] improved rendering information about eshop required setti…
Browse files Browse the repository at this point in the history
…ngs (#3658)
  • Loading branch information
grossmannmartin authored Dec 18, 2024
2 parents 9031568 + 4d0b51d commit a71ad58
Show file tree
Hide file tree
Showing 15 changed files with 340 additions and 149 deletions.
7 changes: 7 additions & 0 deletions src/Component/Router/FriendlyUrl/FriendlyUrlMatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

class FriendlyUrlMatcher
{
protected const string IGNORED_INTERNAL_ROUTE = '_fragment';

/**
* @param \Shopsys\FrameworkBundle\Component\Router\FriendlyUrl\FriendlyUrlRepository $friendlyUrlRepository
* @param \Shopsys\FrameworkBundle\Model\CategorySeo\ReadyCategorySeoMixRepository $readyCategorySeoMixRepository
Expand All @@ -32,6 +34,11 @@ public function __construct(
public function match(string $pathinfo, RouteCollection $routeCollection, DomainConfig $domainConfig): array
{
$pathWithoutSlash = substr($pathinfo, 1);

if ($pathWithoutSlash === self::IGNORED_INTERNAL_ROUTE) {
throw new ResourceNotFoundException();
}

$friendlyUrl = $this->friendlyUrlRepository->findByDomainIdAndSlug($domainConfig->getId(), $pathWithoutSlash);

if ($friendlyUrl === null) {
Expand Down
125 changes: 0 additions & 125 deletions src/Controller/Admin/DefaultController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,13 @@
use Shopsys\FrameworkBundle\Component\Cron\Config\CronConfig;
use Shopsys\FrameworkBundle\Component\Cron\CronFacade;
use Shopsys\FrameworkBundle\Component\Cron\CronModuleFacade;
use Shopsys\FrameworkBundle\Component\Domain\Domain;
use Shopsys\FrameworkBundle\Component\Grid\ArrayDataSource;
use Shopsys\FrameworkBundle\Component\Grid\GridFactory;
use Shopsys\FrameworkBundle\Component\Grid\GridView;
use Shopsys\FrameworkBundle\Component\Grid\QueryBuilderDataSource;
use Shopsys\FrameworkBundle\Component\Setting\Setting;
use Shopsys\FrameworkBundle\Form\Admin\QuickSearch\QuickSearchFormData;
use Shopsys\FrameworkBundle\Form\Admin\QuickSearch\QuickSearchFormType;
use Shopsys\FrameworkBundle\Model\AdminNavigation\BreadcrumbOverrider;
use Shopsys\FrameworkBundle\Model\Mail\MailTemplateFacade;
use Shopsys\FrameworkBundle\Model\Product\Parameter\ParameterFacade;
use Shopsys\FrameworkBundle\Model\Product\Unit\UnitFacade;
use Shopsys\FrameworkBundle\Model\Security\Roles;
use Shopsys\FrameworkBundle\Model\Statistics\StatisticsFacade;
use Shopsys\FrameworkBundle\Model\Statistics\StatisticsProcessingFacade;
Expand All @@ -34,34 +29,24 @@ class DefaultController extends AdminBaseController
/**
* @param \Shopsys\FrameworkBundle\Model\Statistics\StatisticsFacade $statisticsFacade
* @param \Shopsys\FrameworkBundle\Model\Statistics\StatisticsProcessingFacade $statisticsProcessingFacade
* @param \Shopsys\FrameworkBundle\Model\Mail\MailTemplateFacade $mailTemplateFacade
* @param \Shopsys\FrameworkBundle\Model\Product\Unit\UnitFacade $unitFacade
* @param \Shopsys\FrameworkBundle\Component\Setting\Setting $setting
* @param \Shopsys\FrameworkBundle\Component\Cron\CronModuleFacade $cronModuleFacade
* @param \Shopsys\FrameworkBundle\Component\Grid\GridFactory $gridFactory
* @param \Shopsys\FrameworkBundle\Component\Cron\Config\CronConfig $cronConfig
* @param \Shopsys\FrameworkBundle\Component\Cron\CronFacade $cronFacade
* @param \Shopsys\FrameworkBundle\Model\AdminNavigation\BreadcrumbOverrider $breadcrumbOverrider
* @param \Shopsys\FrameworkBundle\Twig\DateTimeFormatterExtension $dateTimeFormatterExtension
* @param \Shopsys\FrameworkBundle\Model\Transfer\Issue\TransferIssueFacade $transferIssueFacade
* @param \Shopsys\FrameworkBundle\Component\Domain\Domain $domain
* @param \Shopsys\FrameworkBundle\Model\Product\Parameter\ParameterFacade $parameterFacade
*/
public function __construct(
protected readonly StatisticsFacade $statisticsFacade,
protected readonly StatisticsProcessingFacade $statisticsProcessingFacade,
protected readonly MailTemplateFacade $mailTemplateFacade,
protected readonly UnitFacade $unitFacade,
protected readonly Setting $setting,
protected readonly CronModuleFacade $cronModuleFacade,
protected readonly GridFactory $gridFactory,
protected readonly CronConfig $cronConfig,
protected readonly CronFacade $cronFacade,
protected readonly BreadcrumbOverrider $breadcrumbOverrider,
protected readonly DateTimeFormatterExtension $dateTimeFormatterExtension,
protected readonly TransferIssueFacade $transferIssueFacade,
protected readonly Domain $domain,
protected readonly ParameterFacade $parameterFacade,
) {
}

Expand Down Expand Up @@ -116,8 +101,6 @@ public function dashboardAction(): Response

$ordersValueTrend = $this->getTrendDifference($previousValueOfOrders, $currentValueOfOrders);

$this->addWarningMessagesOnDashboard();

return $this->render(
'@ShopsysFramework/Admin/Content/Default/index.html.twig',
[
Expand All @@ -138,15 +121,6 @@ public function dashboardAction(): Response
);
}

protected function addWarningMessagesOnDashboard(): void
{
$this->checkEnabledMailTemplatesHaveTheirBodyAndSubjectFilled();
$this->checkAtLeastOneUnitExists();
$this->checkDefaultUnitIsSet();
$this->checkMandatoryArticlesExist();
$this->checkAllSliderNumericValuesAreSet();
}

/**
* @param int $previous
* @param int $current
Expand Down Expand Up @@ -377,103 +351,4 @@ function ($data) {
],
);
}

protected function checkEnabledMailTemplatesHaveTheirBodyAndSubjectFilled(): void
{
if ($this->mailTemplateFacade->existsTemplateWithEnabledSendingHavingEmptyBodyOrSubject()) {
$this->addErrorFlashTwig(
t('<a href="{{ url }}">Some required email templates are not fully set.</a>'),
[
'url' => $this->generateUrl('admin_mail_template'),
],
);
}
}

protected function checkAtLeastOneUnitExists(): void
{
if (count($this->unitFacade->getAll()) === 0) {
$this->addErrorFlashTwig(
t('<a href="{{ url }}">There are no units, you need to create some.</a>'),
[
'url' => $this->generateUrl('admin_unit_list'),
],
);
}
}

protected function checkDefaultUnitIsSet(): void
{
if ($this->setting->get(Setting::DEFAULT_UNIT) === 0) {
$this->addErrorFlashTwig(
t('<a href="{{ url }}">Default unit is not set.</a>'),
[
'url' => $this->generateUrl('admin_unit_list'),
],
);
}
}

protected function checkMandatoryArticlesExist(): void
{
foreach ($this->domain->getAdminEnabledDomainIds() as $domainId) {
$domainConfig = $this->domain->getDomainConfigById($domainId);

if ($this->setting->getForDomain(Setting::TERMS_AND_CONDITIONS_ARTICLE_ID, $domainConfig->getId()) === null) {
$this->addErrorFlashTwig(
t('<a href="{{ url }}">Terms and conditions article for domain {{ domainName }} is not set.</a>'),
[
'url' => $this->generateUrl('admin_legalconditions_termsandconditions'),
'domainName' => $domainConfig->getName(),
],
);
}

if ($this->setting->getForDomain(Setting::PRIVACY_POLICY_ARTICLE_ID, $domainConfig->getId()) === null) {
$this->addErrorFlashTwig(
t('<a href="{{ url }}">Privacy policy article for domain {{ domainName }} is not set.</a>'),
[
'url' => $this->generateUrl('admin_legalconditions_privacypolicy'),
'domainName' => $domainConfig->getName(),
],
);
}

if ($this->setting->getForDomain(Setting::USER_CONSENT_POLICY_ARTICLE_ID, $domainConfig->getId()) === null) {
$this->addErrorFlashTwig(
t('<a href="{{ url }}">User consent policy article for domain {{ domainName }} is not set.</a>'),
[
'url' => $this->generateUrl('admin_userconsentpolicy_setting'),
'domainName' => $domainConfig->getName(),
],
);
}
}
}

protected function checkAllSliderNumericValuesAreSet(): void
{
$countOfSliderParametersWithoutNumericValueSet = $this->parameterFacade->getCountOfSliderParametersWithoutTheirsNumericValueFilled();

if ($countOfSliderParametersWithoutNumericValueSet <= 0) {
return;
}

$this->addErrorFlashTwig(
t(
'{1} There is one parameter slider that does not have its numeric values filled in.|[2,Inf] There are %count% parameter sliders that does not have its numeric values filled in.',
[
'%count%' => $countOfSliderParametersWithoutNumericValueSet,
],
),
);

$sliderParametersWithoutTheirsNumericValueFilled = $this->parameterFacade->getSliderParametersWithoutTheirsNumericValueFilled();

foreach ($sliderParametersWithoutTheirsNumericValueFilled as $parameter) {
$this->addErrorFlashTwig(
sprintf('<a href="%s">%s</a>', $this->generateUrl('admin_parametervalues_edit', ['id' => $parameter->getId()]), $parameter->getName()),
);
}
}
}
8 changes: 8 additions & 0 deletions src/Model/Country/CountryFacade.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,12 @@ public function findByCode(string $countryCode): ?Country
{
return $this->countryRepository->findByCode($countryCode);
}

/**
* @return int
*/
public function getCount(): int
{
return $this->countryRepository->getCount();
}
}
11 changes: 11 additions & 0 deletions src/Model/Country/CountryRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,15 @@ public function findByCode(string $countryCode): ?Country
{
return $this->getCountryRepository()->findOneBy(['code' => $countryCode]);
}

/**
* @return int
*/
public function getCount(): int
{
return $this->getCountryRepository()->createQueryBuilder('c')
->select('COUNT(c.id)')
->getQuery()
->getSingleScalarResult();
}
}
8 changes: 8 additions & 0 deletions src/Model/Product/Unit/UnitFacade.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,4 +168,12 @@ protected function dispatchUnitEvent(Unit $unit, string $eventType): void
{
$this->eventDispatcher->dispatch(new UnitEvent($unit), $eventType);
}

/**
* @return int
*/
public function getCount(): int
{
return $this->unitRepository->getCount();
}
}
11 changes: 11 additions & 0 deletions src/Model/Product/Unit/UnitRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,15 @@ public function replaceUnit(Unit $oldUnit, Unit $newUnit)
->where('p.unit = :oldUnit')->setParameter('oldUnit', $oldUnit)
->getQuery()->execute();
}

/**
* @return int
*/
public function getCount(): int
{
return $this->getUnitRepository()->createQueryBuilder('u')
->select('COUNT(u.id)')
->getQuery()
->getSingleScalarResult();
}
}
3 changes: 3 additions & 0 deletions src/Model/Security/MenuItemsGrantedRolesSetting.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ protected function getPagesGrantedRoles(): array
'products' . static::MENU_ITEM_PATH_SEPARATOR . 'categories' => [
Roles::ROLE_CATEGORY_VIEW,
],
'files' => [
Roles::ROLE_FILES_VIEW,
],
'pricing' . static::MENU_ITEM_PATH_SEPARATOR . 'pricing_groups' => [
Roles::ROLE_PRICING_GROUP_VIEW,
],
Expand Down
8 changes: 8 additions & 0 deletions src/Model/Stock/StockFacade.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,12 @@ public function getStocksEnabledOnDomainIndexedByStockId(int $domainId): array

return $stocksById;
}

/**
* @return int
*/
public function getCount(): int
{
return $this->stockRepository->getCount();
}
}
11 changes: 11 additions & 0 deletions src/Model/Stock/StockRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,15 @@ public function changeDefaultStock(Stock $stock): void
$stock->setDefault();
$this->em->flush();
}

/**
* @return int
*/
public function getCount(): int
{
return $this->getQueryBuilder()
->select('count(s.id)')
->getQuery()
->getSingleScalarResult();
}
}
34 changes: 20 additions & 14 deletions src/Resources/translations/messages.cs.po
Original file line number Diff line number Diff line change
Expand Up @@ -52,23 +52,29 @@ msgstr "301 (Trvalé přesměrování)"
msgid "302 (Temporary redirect)"
msgstr "302 (Dočasné přesměrování)"

msgid "<a href=\"{{ url }}\">Default unit is not set.</a>"
msgstr "<a href=\"{{ url }}\">Není nastavena výchozí jednotka.</a>"
msgid "<a href=\"%url%\">Default unit is not set.</a>"
msgstr "<a href=\"%url%\">Není nastavena výchozí jednotka.</a>"

msgid "<a href=\"{{ url }}\">Privacy policy article for domain {{ domainName }} is not set.</a>"
msgstr "<a href=\"{{ url }}\">Není nastaven článek zásady ochrany osobních údajů pro doménu {{ domainName }}.</a>"
msgid "<a href=\"%url%\">Privacy policy article for domain %domainName% is not set.</a>"
msgstr "<a href=\"%url%\">Není nastaven článek zásady ochrany osobních údajů pro doménu %domainName%.</a>"

msgid "<a href=\"{{ url }}\">Some required email templates are not fully set.</a>"
msgstr "<a href=\"{{ url }}\">Některé povinné e-mailové šablony nejsou vyplněny.</a>"
msgid "<a href=\"%url%\">Some required email templates are not fully set.</a>"
msgstr "<a href=\"%url%\">Některé povinné e-mailové šablony nejsou vyplněny.</a>"

msgid "<a href=\"{{ url }}\">Terms and conditions article for domain {{ domainName }} is not set.</a>"
msgstr "<a href=\"{{ url }}\">Není nastaven článek obchodní podmínky pro doménu {{ domainName }}.</a>"
msgid "<a href=\"%url%\">Term and conditions article for domain %domainName% is not set.</a>"
msgstr "<a href=\"%url%\">Není nastaven článek obchodní podmínky pro doménu %domainName%.</a>"

msgid "<a href=\"{{ url }}\">There are no units, you need to create some.</a>"
msgstr "<a href=\"{{ url }}\">Neexistují žádné jednotky, musíte nějakou vytvořit.</a>"
msgid "<a href=\"%url%\">There are no countries, you need to create some.</a>"
msgstr "<a href=\"%url%\">Neexistují žádné státy, musíte nějaký vytvořit.</a>"

msgid "<a href=\"{{ url }}\">User consent policy article for domain {{ domainName }} is not set.</a>"
msgstr "<a href=\"{{ url }}\">Není nastaven článek správa osobních údajů pro doménu {{ domainName }}.</a>"
msgid "<a href=\"%url%\">There are no units, you need to create some.</a>"
msgstr "<a href=\"%url%\">Neexistují žádné jednotky, musíte nějakou vytvořit.</a>"

msgid "<a href=\"%url%\">There are no warehouses, you need to create some.</a>"
msgstr "<a href=\"%url%\">Neexistují žádné sklady, musíte nějaký vytvořit.</a>"

msgid "<a href=\"%url%\">User consent policy article for domain %domainName% is not set.</a>"
msgstr "<a href=\"%url%\">Není nastaven článek správa osobních údajů pro doménu %domainName%.</a>"

msgid "<strong><a href=\"{{ url }}\">SEO category</a></strong> has been saved"
msgstr "<strong><a href=\"{{ url }}\">SEO kombinace kategorie</a></strong> byla uložena"
Expand Down Expand Up @@ -1903,8 +1909,8 @@ msgstr "Vyplňte také URL pro zvolenou doménu"
msgid "Fill URL only for selected domain"
msgstr "Vyplňte pouze URL pro zvolenou doménu"

msgid "Fill missing settings to enable creating products. More information here."
msgstr "Pro vytvoření produktu doplňte chybějící nastavení. Více informací zde."
msgid "Fill missing settings to enable creating products."
msgstr "Pro vytvoření produktu doplňte chybějící nastavení."

msgid "Filter by"
msgstr "Filtrovat podle"
Expand Down
20 changes: 13 additions & 7 deletions src/Resources/translations/messages.en.po
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,28 @@ msgstr ""
msgid "302 (Temporary redirect)"
msgstr ""

msgid "<a href=\"{{ url }}\">Default unit is not set.</a>"
msgid "<a href=\"%url%\">Default unit is not set.</a>"
msgstr ""

msgid "<a href=\"{{ url }}\">Privacy policy article for domain {{ domainName }} is not set.</a>"
msgid "<a href=\"%url%\">Privacy policy article for domain %domainName% is not set.</a>"
msgstr ""

msgid "<a href=\"{{ url }}\">Some required email templates are not fully set.</a>"
msgid "<a href=\"%url%\">Some required email templates are not fully set.</a>"
msgstr ""

msgid "<a href=\"{{ url }}\">Terms and conditions article for domain {{ domainName }} is not set.</a>"
msgid "<a href=\"%url%\">Term and conditions article for domain %domainName% is not set.</a>"
msgstr ""

msgid "<a href=\"{{ url }}\">There are no units, you need to create some.</a>"
msgid "<a href=\"%url%\">There are no countries, you need to create some.</a>"
msgstr ""

msgid "<a href=\"{{ url }}\">User consent policy article for domain {{ domainName }} is not set.</a>"
msgid "<a href=\"%url%\">There are no units, you need to create some.</a>"
msgstr ""

msgid "<a href=\"%url%\">There are no warehouses, you need to create some.</a>"
msgstr ""

msgid "<a href=\"%url%\">User consent policy article for domain %domainName% is not set.</a>"
msgstr ""

msgid "<strong><a href=\"{{ url }}\">SEO category</a></strong> has been saved"
Expand Down Expand Up @@ -1903,7 +1909,7 @@ msgstr ""
msgid "Fill URL only for selected domain"
msgstr ""

msgid "Fill missing settings to enable creating products. More information here."
msgid "Fill missing settings to enable creating products."
msgstr ""

msgid "Filter by"
Expand Down
Loading

0 comments on commit a71ad58

Please sign in to comment.