From 17435a0ef9d1f9b36a4d53152bd560fae9c9cb39 Mon Sep 17 00:00:00 2001 From: Etienne Gutbub Date: Thu, 14 Dec 2023 11:58:10 +0100 Subject: [PATCH 1/2] feat(Twig): add twig function to simplify the way to know if no commerce is enabled --- src/Twig/Extension/NoCommerceExtension.php | 41 ++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/Twig/Extension/NoCommerceExtension.php diff --git a/src/Twig/Extension/NoCommerceExtension.php b/src/Twig/Extension/NoCommerceExtension.php new file mode 100644 index 0000000..61fe4fa --- /dev/null +++ b/src/Twig/Extension/NoCommerceExtension.php @@ -0,0 +1,41 @@ + + * + * For the full copyright and license information, please view the LICENSE.txt + * file that was distributed with this source code. + */ + +declare(strict_types=1); + +namespace MonsieurBiz\SyliusNoCommercePlugin\Twig\Extension; + +use MonsieurBiz\SyliusSettingsPlugin\Provider\SettingsProviderInterface; +use Twig\Extension\AbstractExtension; +use Twig\TwigFunction; + +final class NoCommerceExtension extends AbstractExtension +{ + private SettingsProviderInterface $settingProvider; + + public function __construct( + SettingsProviderInterface $settingProvider + ) { + $this->settingProvider = $settingProvider; + } + + public function getFunctions(): array + { + return [ + new TwigFunction('is_no_commerce_enabled', [$this, 'isNoCommerceEnabled']), + ]; + } + + public function isNoCommerceEnabled(): bool + { + return (bool) $this->settingProvider->getSettingValue('monsieurbiz.nocommerce', 'enabled'); + } +} From ed710ddf66f1a412ea32636bf9034981732de6cd Mon Sep 17 00:00:00 2001 From: Etienne Gutbub Date: Thu, 14 Dec 2023 14:29:54 +0100 Subject: [PATCH 2/2] fix(dist): Add Migration file in dist to fix CI --- dist/src/Migrations/Version20231214131617.php | 40 +++++++++++++++++++ src/Twig/Extension/NoCommerceExtension.php | 10 ++--- 2 files changed, 45 insertions(+), 5 deletions(-) create mode 100644 dist/src/Migrations/Version20231214131617.php diff --git a/dist/src/Migrations/Version20231214131617.php b/dist/src/Migrations/Version20231214131617.php new file mode 100644 index 0000000..d509206 --- /dev/null +++ b/dist/src/Migrations/Version20231214131617.php @@ -0,0 +1,40 @@ + + * + * For the full copyright and license information, please view the LICENSE.txt + * file that was distributed with this source code. + */ + +declare(strict_types=1); + +namespace App\Migrations; + +use Doctrine\DBAL\Schema\Schema; +use Doctrine\Migrations\AbstractMigration; + +/** + * Auto-generated Migration: Please modify to your needs! + */ +final class Version20231214131617 extends AbstractMigration +{ + public function getDescription(): string + { + return ''; + } + + public function up(Schema $schema): void + { + // this up() migration is auto-generated, please modify it to your needs + $this->addSql('ALTER TABLE mbiz_settings_setting CHANGE json_value json_value JSON DEFAULT NULL'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('ALTER TABLE mbiz_settings_setting CHANGE json_value json_value JSON DEFAULT NULL'); + } +} diff --git a/src/Twig/Extension/NoCommerceExtension.php b/src/Twig/Extension/NoCommerceExtension.php index 61fe4fa..90b05bd 100644 --- a/src/Twig/Extension/NoCommerceExtension.php +++ b/src/Twig/Extension/NoCommerceExtension.php @@ -13,18 +13,18 @@ namespace MonsieurBiz\SyliusNoCommercePlugin\Twig\Extension; -use MonsieurBiz\SyliusSettingsPlugin\Provider\SettingsProviderInterface; +use MonsieurBiz\SyliusNoCommercePlugin\Provider\FeaturesProviderInterface; use Twig\Extension\AbstractExtension; use Twig\TwigFunction; final class NoCommerceExtension extends AbstractExtension { - private SettingsProviderInterface $settingProvider; + private FeaturesProviderInterface $featuresProvider; public function __construct( - SettingsProviderInterface $settingProvider + FeaturesProviderInterface $featuresProvider ) { - $this->settingProvider = $settingProvider; + $this->featuresProvider = $featuresProvider; } public function getFunctions(): array @@ -36,6 +36,6 @@ public function getFunctions(): array public function isNoCommerceEnabled(): bool { - return (bool) $this->settingProvider->getSettingValue('monsieurbiz.nocommerce', 'enabled'); + return $this->featuresProvider->isNoCommerceEnabledForChannel(); } }