Skip to content

Commit

Permalink
improved rendering of the warning about required setting
Browse files Browse the repository at this point in the history
- required setting info moved into a separate class
- required setting info is now displayed on every page
- added warehouse and country check
- improved performance of checking the unit presence
- fixed checking the default unit
  • Loading branch information
grossmannmartin committed Dec 18, 2024
1 parent 88488de commit 4d0b51d
Show file tree
Hide file tree
Showing 13 changed files with 330 additions and 149 deletions.
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();
}
}
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
6 changes: 3 additions & 3 deletions src/Resources/views/Admin/Content/Product/list.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
<span class="btn btn--primary btn--plus wrap-bar__btn btn--disabled">
<i class="btn__icon">+</i>{{ 'Create variant'|trans }}
</span>
<a href="{{ url('admin_default_dashboard') }}" class="btn-link-style wrap-bar__btn">
{{ 'Fill missing settings to enable creating products. More information here.'|trans }}
</a>
<span class="btn-link-style wrap-bar__btn">
{{ 'Fill missing settings to enable creating products.'|trans }}
</span>
{% endif %}
</div>
{% endblock %}
Expand Down
2 changes: 2 additions & 0 deletions src/Resources/views/Admin/Layout/layoutWithPanel.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
{{ render(controller('Shopsys\\FrameworkBundle\\Controller\\Admin\\FlashMessageController::indexAction')) }}
</div>

{{ render_required_settings() }}

{% if showHeading is not defined or showHeading %}
<div class="wrap-bar">
<h1 class="wrap-bar__heading">
Expand Down
Loading

0 comments on commit 4d0b51d

Please sign in to comment.